19 #include <ndb_global.h>
20 #include <ndb_limits.h>
21 #include <ndb_version.h>
25 #include "Configuration.hpp"
27 #include <signaldata/BlockCommitOrd.hpp>
28 #include <signaldata/CheckNodeGroups.hpp>
29 #include <signaldata/CopyActive.hpp>
30 #include <signaldata/CopyFrag.hpp>
31 #include <signaldata/CopyGCIReq.hpp>
32 #include <signaldata/DiAddTab.hpp>
33 #include <signaldata/DictStart.hpp>
34 #include <signaldata/DiGetNodes.hpp>
35 #include <signaldata/DihContinueB.hpp>
36 #include <signaldata/DihSwitchReplica.hpp>
37 #include <signaldata/DumpStateOrd.hpp>
38 #include <signaldata/EmptyLcp.hpp>
39 #include <signaldata/EventReport.hpp>
40 #include <signaldata/GCP.hpp>
41 #include <signaldata/HotSpareRep.hpp>
42 #include <signaldata/MasterGCP.hpp>
43 #include <signaldata/MasterLCP.hpp>
44 #include <signaldata/NFCompleteRep.hpp>
45 #include <signaldata/NodeFailRep.hpp>
46 #include <signaldata/ReadNodesConf.hpp>
47 #include <signaldata/StartFragReq.hpp>
48 #include <signaldata/StartInfo.hpp>
49 #include <signaldata/StartMe.hpp>
50 #include <signaldata/StartPerm.hpp>
51 #include <signaldata/StartRec.hpp>
52 #include <signaldata/StopPerm.hpp>
53 #include <signaldata/StopMe.hpp>
54 #include <signaldata/TestOrd.hpp>
55 #include <signaldata/WaitGCP.hpp>
56 #include <signaldata/DihStartTab.hpp>
57 #include <signaldata/LCP.hpp>
58 #include <signaldata/SystemError.hpp>
60 #include <signaldata/TakeOver.hpp>
62 #include <signaldata/DropTab.hpp>
63 #include <signaldata/AlterTab.hpp>
64 #include <signaldata/AlterTable.hpp>
65 #include <signaldata/PrepDropTab.hpp>
66 #include <signaldata/SumaImpl.hpp>
67 #include <signaldata/DictTabInfo.hpp>
68 #include <signaldata/CreateFragmentation.hpp>
69 #include <signaldata/LqhFrag.hpp>
70 #include <signaldata/FsOpenReq.hpp>
71 #include <signaldata/DihScanTab.hpp>
72 #include <signaldata/DictLock.hpp>
73 #include <DebuggerNames.hpp>
74 #include <signaldata/Upgrade.hpp>
76 #include <signaldata/CreateNodegroup.hpp>
77 #include <signaldata/CreateNodegroupImpl.hpp>
78 #include <signaldata/DropNodegroup.hpp>
79 #include <signaldata/DropNodegroupImpl.hpp>
80 #include <signaldata/DihGetTabInfo.hpp>
81 #include <SectionReader.hpp>
82 #include <signaldata/DihRestart.hpp>
84 #include <EventLogger.hpp>
87 #define SYSFILE ((Sysfile *)&sysfileData[0])
88 #define MAX_CRASHED_REPLICAS 8
89 #define ZINIT_CREATE_GCI Uint32(0)
90 #define ZINIT_REPLICA_LAST_GCI Uint32(-1)
92 #define RETURN_IF_NODE_NOT_ALIVE(node) \
93 if (!checkNodeAlive((node))) { \
98 #define receiveLoopMacro(sigName, receiveNodeId)\
100 c_##sigName##_Counter.clearWaitingFor(receiveNodeId); \
101 if(c_##sigName##_Counter.done() == false){ \
107 #define sendLoopMacro(sigName, signalRoutine, extra) \
109 c_##sigName##_Counter.clearWaitingFor(); \
110 NodeRecordPtr specNodePtr; \
111 specNodePtr.i = cfirstAliveNode; \
114 ptrCheckGuard(specNodePtr, MAX_NDB_NODES, nodeRecord); \
115 c_##sigName##_Counter.setWaitingFor(specNodePtr.i); \
116 signalRoutine(signal, specNodePtr.i, extra); \
117 specNodePtr.i = specNodePtr.p->nextNode; \
118 } while (specNodePtr.i != RNIL); \
123 prevLcpNo(Uint32 lcpNo){
125 return MAX_LCP_USED - 1;
131 nextLcpNo(Uint32 lcpNo){
133 if(lcpNo >= MAX_LCP_USED)
138 void Dbdih::nullRoutine(
Signal* signal, Uint32 nodeId, Uint32
extra)
142 void Dbdih::sendCOPY_GCIREQ(
Signal* signal, Uint32 nodeId, Uint32
extra)
144 ndbrequire(c_copyGCIMaster.m_copyReason != CopyGCIReq::IDLE);
146 const BlockReference ref = calcDihBlockRef(nodeId);
147 const Uint32 wordPerSignal = CopyGCIReq::DATA_SIZE;
148 const Uint32 noOfSignals = ((Sysfile::SYSFILE_SIZE32 + (wordPerSignal - 1)) /
152 copyGCI->anyData = nodeId;
153 copyGCI->copyReason = c_copyGCIMaster.m_copyReason;
154 copyGCI->startWord = 0;
156 for(Uint32
i = 0;
i < noOfSignals;
i++) {
159 const int startWord = copyGCI->startWord;
160 for(Uint32 j = 0; j < wordPerSignal; j++) {
161 copyGCI->data[j] = sysfileData[j+startWord];
164 sendSignal(ref, GSN_COPY_GCIREQ, signal, 25, JBB);
165 copyGCI->startWord += wordPerSignal;
170 void Dbdih::sendDIH_SWITCH_REPLICA_REQ(
Signal* signal, Uint32 nodeId,
173 const BlockReference ref = calcDihBlockRef(nodeId);
174 sendSignal(ref, GSN_DIH_SWITCH_REPLICA_REQ, signal,
175 DihSwitchReplicaReq::SignalLength, JBB);
178 void Dbdih::sendEMPTY_LCP_REQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
180 BlockReference ref = calcLqhBlockRef(nodeId);
181 sendSignal(ref, GSN_EMPTY_LCP_REQ, signal, EmptyLcpReq::SignalLength, JBB);
184 void Dbdih::sendGCP_COMMIT(
Signal* signal, Uint32 nodeId, Uint32 extra)
186 BlockReference ref = calcDihBlockRef(nodeId);
188 req->nodeId = cownNodeId;
189 req->gci_hi = Uint32(m_micro_gcp.m_master.m_new_gci >> 32);
190 req->gci_lo = Uint32(m_micro_gcp.m_master.m_new_gci);
191 sendSignal(ref, GSN_GCP_COMMIT, signal, GCPCommit::SignalLength, JBA);
193 ndbassert(m_micro_gcp.m_enabled || Uint32(m_micro_gcp.m_new_gci) == 0);
196 void Dbdih::sendGCP_PREPARE(
Signal* signal, Uint32 nodeId, Uint32 extra)
198 BlockReference ref = calcDihBlockRef(nodeId);
200 req->nodeId = cownNodeId;
201 req->gci_hi = Uint32(m_micro_gcp.m_master.m_new_gci >> 32);
202 req->gci_lo = Uint32(m_micro_gcp.m_master.m_new_gci);
204 if (! (ERROR_INSERTED(7201) || ERROR_INSERTED(7202)))
206 sendSignal(ref, GSN_GCP_PREPARE, signal, GCPPrepare::SignalLength, JBA);
208 else if (ERROR_INSERTED(7201))
210 sendSignal(ref, GSN_GCP_PREPARE, signal, GCPPrepare::SignalLength, JBB);
212 else if (ERROR_INSERTED(7202))
214 ndbrequire(nodeId == getOwnNodeId());
215 sendSignalWithDelay(ref, GSN_GCP_PREPARE, signal, 2000,
216 GCPPrepare::SignalLength);
223 ndbassert(m_micro_gcp.m_enabled || Uint32(m_micro_gcp.m_new_gci) == 0);
227 Dbdih::sendSUB_GCP_COMPLETE_REP(
Signal* signal, Uint32 nodeId, Uint32 extra)
229 ndbassert(m_micro_gcp.m_enabled || Uint32(m_micro_gcp.m_new_gci) == 0);
230 if (!ndbd_dih_sub_gcp_complete_ack(
getNodeInfo(nodeId).m_version))
233 c_SUB_GCP_COMPLETE_REP_Counter.clearWaitingFor(nodeId);
235 BlockReference ref = calcDihBlockRef(nodeId);
236 sendSignal(ref, GSN_SUB_GCP_COMPLETE_REP, signal,
237 SubGcpCompleteRep::SignalLength, JBA);
240 void Dbdih::sendGCP_SAVEREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
243 BlockReference ref = calcDihBlockRef(nodeId);
244 saveReq->dihBlockRef = reference();
245 saveReq->dihPtr = nodeId;
246 saveReq->gci = m_gcp_save.m_master.m_new_gci;
247 sendSignal(ref, GSN_GCP_SAVEREQ, signal, GCPSaveReq::SignalLength, JBB);
250 void Dbdih::sendINCL_NODEREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
252 BlockReference nodeDihRef = calcDihBlockRef(nodeId);
253 signal->theData[0] = reference();
254 signal->theData[1] = c_nodeStartMaster.startNode;
255 signal->theData[2] = c_nodeStartMaster.failNr;
256 signal->theData[3] = 0;
257 signal->theData[4] = (Uint32)(m_micro_gcp.m_current_gci >> 32);
258 signal->theData[5] = (Uint32)(m_micro_gcp.m_current_gci & 0xFFFFFFFF);
259 sendSignal(nodeDihRef, GSN_INCL_NODEREQ, signal, 6, JBA);
262 void Dbdih::sendMASTER_GCPREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
264 BlockReference ref = calcDihBlockRef(nodeId);
265 sendSignal(ref, GSN_MASTER_GCPREQ, signal, MasterGCPReq::SignalLength, JBB);
268 void Dbdih::sendMASTER_LCPREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
270 BlockReference ref = calcDihBlockRef(nodeId);
271 sendSignal(ref, GSN_MASTER_LCPREQ, signal, MasterLCPReq::SignalLength, JBB);
274 void Dbdih::sendSTART_INFOREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
276 const BlockReference ref = calcDihBlockRef(nodeId);
277 sendSignal(ref, GSN_START_INFOREQ, signal, StartInfoReq::SignalLength, JBB);
280 void Dbdih::sendSTART_RECREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
282 if (!m_sr_nodes.
get(nodeId))
285 c_START_RECREQ_Counter.clearWaitingFor(nodeId);
289 Uint32 keepGCI = SYSFILE->keepGCI;
290 Uint32 lastCompletedGCI = SYSFILE->lastCompletedGCI[nodeId];
291 if (keepGCI > lastCompletedGCI)
294 keepGCI = lastCompletedGCI;
298 BlockReference ref = calcLqhBlockRef(nodeId);
299 req->receivingNodeId = nodeId;
300 req->senderRef = reference();
301 req->keepGci = keepGCI;
302 req->lastCompletedGci = lastCompletedGCI;
303 req->newestGci = SYSFILE->newestRestorableGCI;
304 req->senderData = extra;
305 m_sr_nodes.
copyto(NdbNodeBitmask::Size, req->sr_nodes);
306 sendSignal(ref, GSN_START_RECREQ, signal, StartRecReq::SignalLength, JBB);
309 signal->theData[1] = nodeId;
310 signal->theData[2] = keepGCI;
311 signal->theData[3] = lastCompletedGCI;
312 signal->theData[4] = SYSFILE->newestRestorableGCI;
313 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 5, JBB);
316 void Dbdih::sendSTART_TOREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
318 BlockReference ref = calcDihBlockRef(nodeId);
319 sendSignal(ref, GSN_START_TOREQ, signal, StartToReq::SignalLength, JBB);
322 void Dbdih::sendSTOP_ME_REQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
324 if (nodeId != getOwnNodeId()) {
326 const BlockReference ref = calcDihBlockRef(nodeId);
327 sendSignal(ref, GSN_STOP_ME_REQ, signal, StopMeReq::SignalLength, JBB);
331 void Dbdih::sendTC_CLOPSIZEREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
333 BlockReference ref = calcTcBlockRef(nodeId);
334 signal->theData[0] = nodeId;
335 signal->theData[1] = reference();
336 sendSignal(ref, GSN_TC_CLOPSIZEREQ, signal, 2, JBB);
339 void Dbdih::sendTCGETOPSIZEREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
341 BlockReference ref = calcTcBlockRef(nodeId);
342 signal->theData[0] = nodeId;
343 signal->theData[1] = reference();
344 sendSignal(ref, GSN_TCGETOPSIZEREQ, signal, 2, JBB);
347 void Dbdih::sendUPDATE_TOREQ(
Signal* signal, Uint32 nodeId, Uint32 extra)
349 const BlockReference ref = calcDihBlockRef(nodeId);
350 sendSignal(ref, GSN_UPDATE_TOREQ, signal, UpdateToReq::SignalLength, JBB);
353 void Dbdih::execCONTINUEB(
Signal* signal)
356 switch ((DihContinueB::Type)signal->theData[0]) {
357 case DihContinueB::ZPACK_TABLE_INTO_PAGES:
360 Uint32 tableId = signal->theData[1];
361 packTableIntoPagesLab(signal, tableId);
365 case DihContinueB::ZPACK_FRAG_INTO_PAGES:
369 wf.rwfTabPtr.i = signal->theData[1];
370 ptrCheckGuard(wf.rwfTabPtr, ctabFileSize, tabRecord);
371 wf.fragId = signal->theData[2];
372 wf.pageIndex = signal->theData[3];
373 wf.wordIndex = signal->theData[4];
374 wf.totalfragments = signal->theData[5];
375 packFragIntoPagesLab(signal, &wf);
379 case DihContinueB::ZREAD_PAGES_INTO_TABLE:
382 Uint32 tableId = signal->theData[1];
383 readPagesIntoTableLab(signal, tableId);
387 case DihContinueB::ZREAD_PAGES_INTO_FRAG:
391 rf.rwfTabPtr.i = signal->theData[1];
392 ptrCheckGuard(rf.rwfTabPtr, ctabFileSize, tabRecord);
393 rf.fragId = signal->theData[2];
394 rf.pageIndex = signal->theData[3];
395 rf.wordIndex = signal->theData[4];
396 readPagesIntoFragLab(signal, &rf);
400 case DihContinueB::ZCOPY_TABLE:
403 Uint32 tableId = signal->theData[1];
404 copyTableLab(signal, tableId);
407 case DihContinueB::ZCOPY_TABLE_NODE:
409 NodeRecordPtr nodePtr;
412 ctn.ctnTabPtr.i = signal->theData[1];
413 ptrCheckGuard(ctn.ctnTabPtr, ctabFileSize, tabRecord);
414 nodePtr.i = signal->theData[2];
415 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
416 ctn.pageIndex = signal->theData[3];
417 ctn.wordIndex = signal->theData[4];
418 ctn.noOfWords = signal->theData[5];
419 copyTableNode(signal, &ctn, nodePtr);
422 case DihContinueB::ZSTART_FRAGMENT:
425 Uint32 tableId = signal->theData[1];
426 Uint32 fragId = signal->theData[2];
427 startFragment(signal, tableId, fragId);
430 case DihContinueB::ZCOMPLETE_RESTART:
432 completeRestartLab(signal);
434 case DihContinueB::ZREAD_TABLE_FROM_PAGES:
438 tabPtr.i = signal->theData[1];
439 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
440 readTableFromPagesLab(signal, tabPtr);
443 case DihContinueB::ZSR_PHASE2_READ_TABLE:
447 tabPtr.i = signal->theData[1];
448 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
449 srPhase2ReadTableLab(signal, tabPtr);
452 case DihContinueB::ZCHECK_TC_COUNTER:
455 checkTcCounterLab(signal);
458 case DihContinueB::ZCALCULATE_KEEP_GCI:
461 Uint32 tableId = signal->theData[1];
462 Uint32 fragId = signal->theData[2];
463 calculateKeepGciLab(signal, tableId, fragId);
466 case DihContinueB::ZSTORE_NEW_LCP_ID:
468 storeNewLcpIdLab(signal);
470 case DihContinueB::ZTABLE_UPDATE:
474 tabPtr.i = signal->theData[1];
475 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
476 tableUpdateLab(signal, tabPtr);
479 case DihContinueB::ZCHECK_LCP_COMPLETED:
482 checkLcpCompletedLab(signal);
485 case DihContinueB::ZINIT_LCP:
488 Uint32 senderRef = signal->theData[1];
489 Uint32 tableId = signal->theData[2];
490 initLcpLab(signal, senderRef, tableId);
493 case DihContinueB::ZADD_TABLE_MASTER_PAGES:
497 tabPtr.i = signal->theData[1];
498 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
499 tabPtr.p->tabUpdateState = TabRecord::US_ADD_TABLE_MASTER;
500 tableUpdateLab(signal, tabPtr);
504 case DihContinueB::ZDIH_ADD_TABLE_MASTER:
507 addTable_closeConf(signal, signal->theData[1]);
510 case DihContinueB::ZADD_TABLE_SLAVE_PAGES:
514 tabPtr.i = signal->theData[1];
515 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
516 tabPtr.p->tabUpdateState = TabRecord::US_ADD_TABLE_SLAVE;
517 tableUpdateLab(signal, tabPtr);
520 case DihContinueB::ZDIH_ADD_TABLE_SLAVE:
525 case DihContinueB::ZSTART_GCP:
528 startGcpLab(signal, signal->theData[1]);
532 case DihContinueB::ZCOPY_GCI:{
534 CopyGCIReq::CopyReason reason = (CopyGCIReq::CopyReason)signal->theData[1];
535 ndbrequire(c_copyGCIMaster.m_copyReason == reason);
538 c_copyGCIMaster.m_copyReason = CopyGCIReq::IDLE;
539 copyGciLab(signal, reason);
543 case DihContinueB::ZEMPTY_VERIFY_QUEUE:
545 emptyverificbuffer(signal, signal->theData[1],
true);
548 case DihContinueB::ZCHECK_GCP_STOP:
551 checkGcpStopLab(signal);
555 case DihContinueB::ZREMOVE_NODE_FROM_TABLE:
558 Uint32 nodeId = signal->theData[1];
559 Uint32 tableId = signal->theData[2];
560 removeNodeFromTables(signal, nodeId, tableId);
563 case DihContinueB::ZCOPY_NODE:
566 Uint32 tableId = signal->theData[1];
567 copyNodeLab(signal, tableId);
570 case DihContinueB::ZTO_START_COPY_FRAG:
573 Uint32 takeOverPtrI = signal->theData[1];
574 startNextCopyFragment(signal, takeOverPtrI);
577 case DihContinueB::ZINVALIDATE_NODE_LCP:
580 const Uint32 nodeId = signal->theData[1];
581 const Uint32 tableId = signal->theData[2];
582 invalidateNodeLCP(signal, nodeId, tableId);
585 case DihContinueB::ZINITIALISE_RECORDS:
587 initialiseRecordsLab(signal,
593 case DihContinueB::ZSTART_PERMREQ_AGAIN:
595 nodeRestartPh2Lab2(signal);
598 case DihContinueB::SwitchReplica:
601 const Uint32 nodeId = signal->theData[1];
602 const Uint32 tableId = signal->theData[2];
603 const Uint32 fragNo = signal->theData[3];
604 switchReplica(signal, nodeId, tableId, fragNo);
607 case DihContinueB::ZSEND_ADD_FRAG:
610 Uint32 takeOverPtrI = signal->theData[1];
611 toCopyFragLab(signal, takeOverPtrI);
614 case DihContinueB::ZSEND_START_TO:
618 c_takeOverPool.
getPtr(takeOverPtr, signal->theData[1]);
619 sendStartTo(signal, takeOverPtr);
622 case DihContinueB::ZSEND_UPDATE_TO:
626 c_takeOverPool.
getPtr(takeOverPtr, signal->theData[1]);
627 sendUpdateTo(signal, takeOverPtr);
630 case DihContinueB::WAIT_DROP_TAB_WRITING_TO_FILE:{
633 tabPtr.i = signal->theData[1];
634 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
635 waitDropTabWritingToFile(signal, tabPtr);
638 case DihContinueB::ZTO_START_FRAGMENTS:
640 TakeOverRecordPtr takeOverPtr;
641 c_takeOverPool.
getPtr(takeOverPtr, signal->theData[1]);
642 nr_start_fragments(signal, takeOverPtr);
645 case DihContinueB::ZCOPY_NODE_WAIT_CREATE_FRAG:
648 lcpBlockedLab(signal,
true, signal->theData[1]);
651 case DihContinueB::ZWAIT_OLD_SCAN:
654 wait_old_scan(signal);
657 case DihContinueB::ZLCP_TRY_LOCK:
660 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
661 Callback c = { safe_cast(&Dbdih::lcpFragmentMutex_locked),
662 signal->theData[1] };
663 ndbrequire(mutex.trylock(c,
false));
666 case DihContinueB::ZDELAY_RELEASE_FRAGMENT_INFO_MUTEX:
670 mh.setHandle(signal->theData[1]);
671 Mutex mutex(signal, c_mutexMgr, mh);
675 case DihContinueB::ZTO_START_LOGGING:
678 TakeOverRecordPtr takeOverPtr;
679 c_takeOverPool.
getPtr(takeOverPtr, signal->theData[1]);
680 nr_start_logging(signal, takeOverPtr);
683 case DihContinueB::ZGET_TABINFO:
689 case DihContinueB::ZGET_TABINFO_SEND:
694 tabPtr.i = signal->theData[1];
695 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
696 getTabInfo_send(signal, tabPtr);
705 void Dbdih::execCOPY_GCIREQ(
Signal* signal)
709 CopyGCIReq::CopyReason reason = (CopyGCIReq::CopyReason)copyGCI->copyReason;
710 const Uint32 tstart = copyGCI->startWord;
712 ndbrequire(cmasterdihref == signal->senderBlockRef()) ;
713 ndbrequire((reason == CopyGCIReq::GLOBAL_CHECKPOINT &&
714 c_copyGCISlave.m_copyReason == CopyGCIReq::GLOBAL_CHECKPOINT) ||
715 c_copyGCISlave.m_copyReason == CopyGCIReq::IDLE);
716 ndbrequire(c_copyGCISlave.m_expectedNextWord == tstart);
717 ndbrequire(reason != CopyGCIReq::IDLE);
718 bool isdone = (tstart + CopyGCIReq::DATA_SIZE) >= Sysfile::SYSFILE_SIZE32;
720 if (ERROR_INSERTED(7177))
724 if (signal->getLength() == 3)
731 arrGuard(tstart + CopyGCIReq::DATA_SIZE,
sizeof(sysfileData)/4);
732 for(Uint32
i = 0;
i<CopyGCIReq::DATA_SIZE;
i++)
733 cdata[tstart+
i] = copyGCI->data[
i];
735 if (ERROR_INSERTED(7177) && isMaster() && isdone)
737 sendSignalWithDelay(reference(), GSN_COPY_GCIREQ, signal, 1000, 3);
745 c_copyGCISlave.m_expectedNextWord = 0;
750 c_copyGCISlave.m_expectedNextWord += CopyGCIReq::DATA_SIZE;
754 if (cmasterdihref != reference())
757 Uint32 tmp= SYSFILE->m_restart_seq;
758 memcpy(sysfileData, cdata,
sizeof(sysfileData));
759 SYSFILE->m_restart_seq = tmp;
761 if (c_set_initial_start_flag)
764 Sysfile::setInitialStartOngoing(SYSFILE->systemRestartBits);
768 c_copyGCISlave.m_copyReason = reason;
769 c_copyGCISlave.m_senderRef = signal->senderBlockRef();
770 c_copyGCISlave.m_senderData = copyGCI->anyData;
772 CRASH_INSERTION2(7020, reason==CopyGCIReq::LOCAL_CHECKPOINT);
773 CRASH_INSERTION2(7008, reason==CopyGCIReq::GLOBAL_CHECKPOINT);
775 if (m_local_lcp_state.check_cut_log_tail(c_newest_restorable_gci))
781 rep->nodeId = getOwnNodeId();
783 rep->lcpId = m_local_lcp_state.m_start_lcp_req.lcpId;
784 rep->keepGci = m_local_lcp_state.m_keep_gci;
785 sendSignal(DBLQH_REF, GSN_LCP_COMPLETE_REP, signal,
786 LcpCompleteRep::SignalLength, JBB);
788 warningEvent(
"CUT LOG TAIL: reason: %u lcp: %u m_keep_gci: %u stop: %u",
790 m_local_lcp_state.m_start_lcp_req.lcpId,
791 m_local_lcp_state.m_keep_gci,
792 m_local_lcp_state.m_stop_gci);
794 m_local_lcp_state.reset();
804 case CopyGCIReq::IDLE:
809 case CopyGCIReq::LOCAL_CHECKPOINT: {
812 c_lcpState.setLcpStatus(LCP_COPY_GCI, __LINE__);
813 c_lcpState.m_masterLcpDihRef = cmasterdihref;
814 setNodeActiveStatus();
817 case CopyGCIReq::RESTART: {
820 Uint32 newest = SYSFILE->newestRestorableGCI;
821 m_micro_gcp.m_old_gci = Uint64(newest) << 32;
822 crestartGci = newest;
823 c_newest_restorable_gci = newest;
824 Sysfile::setRestartOngoing(SYSFILE->systemRestartBits);
825 m_micro_gcp.m_current_gci = Uint64(newest + 1) << 32;
826 setNodeActiveStatus();
828 if ((Sysfile::getLCPOngoing(SYSFILE->systemRestartBits))) {
834 invalidateLcpInfoAfterSr(signal);
837 if (m_micro_gcp.m_enabled ==
false &&
838 m_micro_gcp.m_master.m_time_between_gcp)
844 m_micro_gcp.m_enabled =
true;
846 ord->type = UpgradeProtocolOrd::UPO_ENABLE_MICRO_GCP;
847 EXECUTE_DIRECT(QMGR,GSN_UPGRADE_PROTOCOL_ORD,signal,signal->getLength());
851 case CopyGCIReq::GLOBAL_CHECKPOINT: {
855 if (m_gcp_save.m_state == GcpSave::GCP_SAVE_COPY_GCI)
861 ndbrequire(c_newest_restorable_gci == SYSFILE->newestRestorableGCI);
862 m_gcp_save.m_master_ref = c_copyGCISlave.m_senderRef;
866 if (c_newest_restorable_gci == SYSFILE->newestRestorableGCI)
873 m_gcp_save.m_master_ref = c_copyGCISlave.m_senderRef;
874 c_copyGCISlave.m_copyReason = CopyGCIReq::IDLE;
875 signal->theData[0] = c_copyGCISlave.m_senderData;
876 sendSignal(m_gcp_save.m_master_ref, GSN_COPY_GCICONF, signal, 1, JBB);
880 ndbrequire(m_gcp_save.m_state == GcpSave::GCP_SAVE_CONF);
881 m_gcp_save.m_state = GcpSave::GCP_SAVE_COPY_GCI;
882 m_gcp_save.m_master_ref = c_copyGCISlave.m_senderRef;
883 c_newest_restorable_gci = SYSFILE->newestRestorableGCI;
884 setNodeActiveStatus();
887 case CopyGCIReq::INITIAL_START_COMPLETED:
891 case CopyGCIReq::RESTART_NR:
897 c_copyGCISlave.m_copyReason = CopyGCIReq::IDLE;
898 signal->theData[0] = c_copyGCISlave.m_senderData;
899 sendSignal(c_copyGCISlave.m_senderRef, GSN_COPY_GCICONF, signal, 1, JBB);
904 CRASH_INSERTION(7183);
906 if (ERROR_INSERTED(7185) && reason==CopyGCIReq::GLOBAL_CHECKPOINT)
911 #ifdef GCP_TIMER_HACK
912 if (reason == CopyGCIReq::GLOBAL_CHECKPOINT) {
914 NdbTick_getMicroTimer(&globalData.gcp_timer_copygci[0]);
921 FileRecordPtr filePtr;
922 filePtr.i = crestartInfoFile[0];
923 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
924 if (filePtr.p->fileStatus == FileRecord::OPEN) {
926 openingCopyGciSkipInitLab(signal, filePtr);
929 openFileRw(signal, filePtr);
930 filePtr.p->reqStatus = FileRecord::OPENING_COPY_GCI;
934 void Dbdih::execDICTSTARTCONF(
Signal* signal)
937 Uint32 nodeId = refToNode(signal->getSendersBlockRef());
938 if (nodeId != getOwnNodeId()) {
940 nodeDictStartConfLab(signal);
943 dictStartConfLab(signal);
947 void Dbdih::execFSCLOSECONF(
Signal* signal)
949 FileRecordPtr filePtr;
951 filePtr.i = signal->theData[0];
952 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
953 filePtr.p->fileStatus = FileRecord::CLOSED;
954 FileRecord::ReqStatus status = filePtr.p->reqStatus;
955 filePtr.p->reqStatus = FileRecord::IDLE;
957 case FileRecord::CLOSING_GCP:
959 closingGcpLab(signal, filePtr);
961 case FileRecord::CLOSING_GCP_CRASH:
963 closingGcpCrashLab(signal, filePtr);
965 case FileRecord::CLOSING_TABLE_CRASH:
967 closingTableCrashLab(signal, filePtr);
969 case FileRecord::CLOSING_TABLE_SR:
971 closingTableSrLab(signal, filePtr);
973 case FileRecord::TABLE_CLOSE:
975 tableCloseLab(signal, filePtr);
977 case FileRecord::TABLE_CLOSE_DELETE:
979 tableDeleteLab(signal, filePtr);
988 void Dbdih::execFSCLOSEREF(
Signal* signal)
990 FileRecordPtr filePtr;
992 filePtr.i = signal->theData[0];
993 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
994 FileRecord::ReqStatus status = filePtr.p->reqStatus;
995 filePtr.p->reqStatus = FileRecord::IDLE;
997 case FileRecord::CLOSING_GCP:
1000 case FileRecord::CLOSING_GCP_CRASH:
1002 closingGcpCrashLab(signal, filePtr);
1004 case FileRecord::CLOSING_TABLE_CRASH:
1006 closingTableCrashLab(signal, filePtr);
1008 case FileRecord::CLOSING_TABLE_SR:
1011 case FileRecord::TABLE_CLOSE:
1014 case FileRecord::TABLE_CLOSE_DELETE:
1024 sprintf(msg,
"File system close failed during FileRecord status %d", (Uint32)status);
1025 fsRefError(signal,__LINE__,msg);
1030 void Dbdih::execFSOPENCONF(
Signal* signal)
1032 FileRecordPtr filePtr;
1034 filePtr.i = signal->theData[0];
1035 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
1036 filePtr.p->fileRef = signal->theData[1];
1037 filePtr.p->fileStatus = FileRecord::OPEN;
1038 FileRecord::ReqStatus status = filePtr.p->reqStatus;
1039 filePtr.p->reqStatus = FileRecord::IDLE;
1041 case FileRecord::CREATING_GCP:
1043 creatingGcpLab(signal, filePtr);
1045 case FileRecord::OPENING_COPY_GCI:
1047 openingCopyGciSkipInitLab(signal, filePtr);
1049 case FileRecord::CREATING_COPY_GCI:
1051 openingCopyGciSkipInitLab(signal, filePtr);
1053 case FileRecord::OPENING_GCP:
1055 openingGcpLab(signal, filePtr);
1057 case FileRecord::OPENING_TABLE:
1059 openingTableLab(signal, filePtr);
1061 case FileRecord::TABLE_CREATE:
1063 tableCreateLab(signal, filePtr);
1065 case FileRecord::TABLE_OPEN_FOR_DELETE:
1067 tableOpenLab(signal, filePtr);
1076 void Dbdih::execFSOPENREF(
Signal* signal)
1078 FileRecordPtr filePtr;
1080 filePtr.i = signal->theData[0];
1081 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
1082 FileRecord::ReqStatus status = filePtr.p->reqStatus;
1083 filePtr.p->reqStatus = FileRecord::IDLE;
1085 case FileRecord::CREATING_GCP:
1092 case FileRecord::OPENING_COPY_GCI:
1094 openingCopyGciErrorLab(signal, filePtr);
1096 case FileRecord::CREATING_COPY_GCI:
1099 case FileRecord::OPENING_GCP:
1101 openingGcpErrorLab(signal, filePtr);
1103 case FileRecord::OPENING_TABLE:
1105 openingTableErrorLab(signal, filePtr);
1107 case FileRecord::TABLE_CREATE:
1110 case FileRecord::TABLE_OPEN_FOR_DELETE:
1112 tableDeleteLab(signal, filePtr);
1120 sprintf(msg,
"File system open failed during FileRecord status %d", (Uint32)status);
1121 fsRefError(signal,__LINE__,msg);
1126 void Dbdih::execFSREADCONF(
Signal* signal)
1128 FileRecordPtr filePtr;
1130 filePtr.i = signal->theData[0];
1131 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
1132 FileRecord::ReqStatus status = filePtr.p->reqStatus;
1133 filePtr.p->reqStatus = FileRecord::IDLE;
1135 case FileRecord::READING_GCP:
1137 readingGcpLab(signal, filePtr);
1139 case FileRecord::READING_TABLE:
1141 readingTableLab(signal, filePtr);
1150 void Dbdih::execFSREADREF(
Signal* signal)
1152 FileRecordPtr filePtr;
1154 filePtr.i = signal->theData[0];
1155 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
1156 FileRecord::ReqStatus status = filePtr.p->reqStatus;
1157 filePtr.p->reqStatus = FileRecord::IDLE;
1159 case FileRecord::READING_GCP:
1161 readingGcpErrorLab(signal, filePtr);
1163 case FileRecord::READING_TABLE:
1165 readingTableErrorLab(signal, filePtr);
1172 sprintf(msg,
"File system read failed during FileRecord status %d", (Uint32)status);
1173 fsRefError(signal,__LINE__,msg);
1177 void Dbdih::execFSWRITECONF(
Signal* signal)
1179 FileRecordPtr filePtr;
1181 filePtr.i = signal->theData[0];
1182 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
1183 FileRecord::ReqStatus status = filePtr.p->reqStatus;
1184 filePtr.p->reqStatus = FileRecord::IDLE;
1186 case FileRecord::WRITING_COPY_GCI:
1188 writingCopyGciLab(signal, filePtr);
1190 case FileRecord::WRITE_INIT_GCP:
1192 writeInitGcpLab(signal, filePtr);
1194 case FileRecord::TABLE_WRITE:
1196 tableWriteLab(signal, filePtr);
1205 void Dbdih::execFSWRITEREF(
Signal* signal)
1207 FileRecordPtr filePtr;
1209 filePtr.i = signal->theData[0];
1210 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
1211 FileRecord::ReqStatus status = filePtr.p->reqStatus;
1212 filePtr.p->reqStatus = FileRecord::IDLE;
1214 case FileRecord::WRITING_COPY_GCI:
1221 case FileRecord::WRITE_INIT_GCP:
1228 case FileRecord::TABLE_WRITE:
1237 sprintf(msg,
"File system write failed during FileRecord status %d", (Uint32)status);
1238 fsRefError(signal,__LINE__,msg);
1243 void Dbdih::execGETGCIREQ(
Signal* signal)
1247 Uint32 userPtr = signal->theData[0];
1248 BlockReference userRef = signal->theData[1];
1249 Uint32
type = signal->theData[2];
1256 gci_hi = SYSFILE->newestRestorableGCI;
1260 gci_hi = Uint32(m_micro_gcp.m_current_gci >> 32);
1261 gci_lo = Uint32(m_micro_gcp.m_current_gci);
1265 signal->theData[0] = userPtr;
1266 signal->theData[1] = gci_hi;
1267 signal->theData[2] = gci_lo;
1272 sendSignal(userRef, GSN_GETGCICONF, signal, 3, JBB);
1281 void Dbdih::execREAD_CONFIG_REQ(
Signal* signal)
1284 Uint32 ref = req->senderRef;
1285 Uint32 senderData = req->senderData;
1286 ndbrequire(req->noOfParameters == 0);
1291 m_ctx.m_config.getOwnConfigIterator();
1292 ndbrequireErr(p != 0, NDBD_EXIT_INVALID_CONFIG);
1296 cconnectFileSize = 256;
1298 ndbrequireErr(!ndb_mgm_get_int_parameter(p, CFG_DIH_API_CONNECT,
1299 &capiConnectFileSize),
1300 NDBD_EXIT_INVALID_CONFIG);
1301 capiConnectFileSize++;
1303 ndbrequireErr(!ndb_mgm_get_int_parameter(p, CFG_DIH_FRAG_CONNECT,
1304 &cfragstoreFileSize),
1305 NDBD_EXIT_INVALID_CONFIG);
1306 ndbrequireErr(!ndb_mgm_get_int_parameter(p, CFG_DIH_REPLICAS,
1308 NDBD_EXIT_INVALID_CONFIG);
1309 ndbrequireErr(!ndb_mgm_get_int_parameter(p, CFG_DIH_TABLE, &ctabFileSize),
1310 NDBD_EXIT_INVALID_CONFIG);
1315 c_fragments_per_node = getLqhWorkers();
1317 if (ERROR_INSERTED(7215)) {
1318 c_fragments_per_node = 1;
1321 ndbout_c(
"Using %u fragments per node", c_fragments_per_node);
1323 ndb_mgm_get_int_parameter(p, CFG_DB_LCP_TRY_LOCK_TIMEOUT,
1324 &c_lcpState.m_lcp_trylock_timeout);
1326 cfileFileSize = (2 * ctabFileSize) + 2;
1328 initialiseRecordsLab(signal, 0, ref, senderData);
1332 ndb_mgm_get_int_parameter(p, CFG_DB_2PASS_INR,
1334 c_2pass_inr = val ?
true :
false;
1341 NodeRecordPtr nodePtr;
1342 for (nodePtr.i = 0; nodePtr.i < MAX_NDB_NODES; nodePtr.i++)
1344 ptrAss(nodePtr, nodeRecord);
1345 new (nodePtr.p) NodeRecord();
1346 nodePtr.p->nodeGroup = RNIL;
1350 m_ctx.m_config.getClusterConfigIterator();
1351 for(ndb_mgm_first(iter); ndb_mgm_valid(iter); ndb_mgm_next(iter))
1357 ndbrequire(!ndb_mgm_get_int_parameter(iter,CFG_NODE_ID, &nodeId));
1358 ndbrequire(!ndb_mgm_get_int_parameter(iter,CFG_TYPE_OF_SECTION,
1366 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
1367 if (ndb_mgm_get_int_parameter(iter, CFG_DB_NODEGROUP, &ng) == 0)
1370 nodePtr.p->nodeGroup = ng;
1375 nodePtr.p->nodeGroup = RNIL;
1383 void Dbdih::execSTART_COPYREF(
Signal* signal)
1389 void Dbdih::execSTART_FRAGCONF(
Signal* signal)
1401 void Dbdih::execSTART_FRAGREF(
Signal* signal)
1408 Uint32 errCode = signal->theData[1];
1409 Uint32 nodeId = signal->theData[2];
1412 sysErr->errorCode = SystemError::StartFragRefError;
1413 sysErr->errorRef = reference();
1414 sysErr->data[0] = errCode;
1415 sysErr->data[1] = 0;
1416 sendSignal(calcNdbCntrBlockRef(nodeId), GSN_SYSTEM_ERROR, signal,
1417 SystemError::SignalLength, JBB);
1421 void Dbdih::execSTART_MEREF(
Signal* signal)
1427 void Dbdih::execTAB_COMMITREQ(
Signal* signal)
1429 TabRecordPtr tabPtr;
1431 Uint32 tdictPtr = signal->theData[0];
1432 BlockReference tdictBlockref = signal->theData[1];
1433 tabPtr.i = signal->theData[2];
1434 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
1436 ndbrequire(tabPtr.p->tabStatus == TabRecord::TS_CREATING);
1437 tabPtr.p->tabStatus = TabRecord::TS_ACTIVE;
1438 tabPtr.p->schemaTransId = 0;
1439 signal->theData[0] = tdictPtr;
1440 signal->theData[1] = cownNodeId;
1441 signal->theData[2] = tabPtr.i;
1442 sendSignal(tdictBlockref, GSN_TAB_COMMITCONF, signal, 3, JBB);
1461 void Dbdih::execDIH_RESTARTREQ(
Signal* signal)
1465 signal->getDataPtr());
1466 if (req->senderRef != 0)
1469 cntrlblockref = req->senderRef;
1470 if(m_ctx.m_config.getInitialStart())
1472 sendDihRestartRef(signal);
1474 readGciFileLab(signal);
1485 mask.
assign(NdbNodeBitmask::Size, req->nodemask);
1486 const Uint32 *node_gcis = req->node_gcis;
1487 Uint32 node_group_gcis[MAX_NDB_NODES+1];
1488 memset(node_group_gcis, 0,
sizeof(node_group_gcis));
1489 for (i = 0; i<MAX_NDB_NODES; i++)
1494 Uint32 ng = Sysfile::getNodeGroup(i, SYSFILE->nodeGroups);
1495 if (ng != NO_NODE_GROUP_ID)
1497 ndbrequire(ng < MAX_NDB_NODES);
1498 Uint32 gci = node_gcis[
i];
1499 if (gci < SYSFILE->lastCompletedGCI[i])
1507 gci = SYSFILE->lastCompletedGCI[
i];
1510 if (gci > node_group_gcis[ng])
1513 node_group_gcis[ng] = gci;
1518 for (i = 0; i<MAX_NDB_NODES && node_group_gcis[
i] == 0; i++);
1520 Uint32 gci = node_group_gcis[
i];
1521 for (i++ ; i<MAX_NDB_NODES; i++)
1524 if (node_group_gcis[i] && node_group_gcis[i] != gci)
1527 signal->theData[0] =
i;
1531 signal->theData[0] = MAX_NDB_NODES;
1537 void Dbdih::execSTTOR(
Signal* signal)
1541 Callback c = { safe_cast(&Dbdih::sendSTTORRY), 0 };
1544 switch(signal->theData[1]){
1546 createMutexes(signal, 0);
1551 signal->theData[0] = reference();
1552 sendSignal(NDBCNTR_REF, GSN_READ_NODESREQ, signal, 1, JBB);
1556 sendSTTORRY(signal);
1560 Dbdih::sendSTTORRY(
Signal* signal, Uint32 senderData, Uint32 retVal)
1562 signal->theData[0] = 0;
1563 signal->theData[1] = 0;
1564 signal->theData[2] = 0;
1565 signal->theData[3] = 1;
1566 signal->theData[4] = 2;
1567 signal->theData[5] = 3;
1568 signal->theData[6] = 255;
1569 sendSignal(NDBCNTR_REF, GSN_STTORRY, signal, 7, JBB);
1573 void Dbdih::initialStartCompletedLab(
Signal* signal)
1586 void Dbdih::ndbsttorry10Lab(
Signal* signal, Uint32 _line)
1592 signal->theData[0] = reference();
1593 sendSignal(cntrlblockref, GSN_NDB_STTORRY, signal, 1, JBB);
1605 void Dbdih::execNDB_STTOR(
Signal* signal)
1608 BlockReference cntrRef = signal->theData[0];
1609 Uint32 ownNodeId = signal->theData[1];
1610 Uint32 phase = signal->theData[2];
1611 Uint32 typestart = signal->theData[3];
1613 cstarttype = typestart;
1614 cstartPhase = phase;
1622 cownNodeId = ownNodeId;
1627 cntrlblockref = cntrRef;
1628 clocaltcblockref = calcTcBlockRef(ownNodeId);
1629 clocallqhblockref = calcLqhBlockRef(ownNodeId);
1630 cdictblockref = calcDictBlockRef(ownNodeId);
1631 ndbsttorry10Lab(signal, __LINE__);
1646 if (cstarttype == NodeState::ST_INITIAL_NODE_RESTART)
1649 c_set_initial_start_flag = TRUE;
1652 if (cstarttype == NodeState::ST_INITIAL_START) {
1655 }
else if (cstarttype == NodeState::ST_SYSTEM_RESTART) {
1658 }
else if ((cstarttype == NodeState::ST_NODE_RESTART) ||
1659 (cstarttype == NodeState::ST_INITIAL_NODE_RESTART)) {
1661 nodeRestartPh2Lab(signal);
1666 ndbsttorry10Lab(signal, __LINE__);
1679 cmasterState = MASTER_IDLE;
1680 if(cstarttype == NodeState::ST_INITIAL_START ||
1681 cstarttype == NodeState::ST_SYSTEM_RESTART){
1683 cmasterState = isMaster() ? MASTER_ACTIVE : MASTER_IDLE;
1685 if (!isMaster() && cstarttype == NodeState::ST_INITIAL_START) {
1687 ndbStartReqLab(signal, cntrRef);
1690 ndbsttorry10Lab(signal, __LINE__);
1695 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
1696 cmasterTakeOverNode = ZNIL;
1698 case NodeState::ST_INITIAL_START:
1700 ndbsttorry10Lab(signal, __LINE__);
1702 case NodeState::ST_SYSTEM_RESTART:
1704 ndbsttorry10Lab(signal, __LINE__);
1706 case NodeState::ST_INITIAL_NODE_RESTART:
1707 case NodeState::ST_NODE_RESTART:
1717 req->startingRef = reference();
1718 req->startingVersion = 0;
1719 sendSignal(cmasterdihref, GSN_START_MEREQ, signal,
1720 StartMeReq::SignalLength, JBB);
1727 if (m_gcp_monitor.m_micro_gcp.m_max_lag > 0)
1729 infoEvent(
"GCP Monitor: Computed max GCP_SAVE lag to %u seconds",
1730 m_gcp_monitor.m_gcp_save.m_max_lag / 10);
1731 infoEvent(
"GCP Monitor: Computed max GCP_COMMIT lag to %u seconds",
1732 m_gcp_monitor.m_micro_gcp.m_max_lag / 10);
1736 infoEvent(
"GCP Monitor: unlimited lags allowed");
1739 case NodeState::ST_INITIAL_START:
1740 case NodeState::ST_SYSTEM_RESTART:
1755 ndbsttorry10Lab(signal, __LINE__);
1759 c_lcpState.immediateLcpStart =
true;
1761 checkLcpStart(signal, __LINE__);
1763 case NodeState::ST_NODE_RESTART:
1764 case NodeState::ST_INITIAL_NODE_RESTART:
1768 req->senderRef = reference();
1769 req->senderData = RNIL;
1770 req->flags = StartCopyReq::WAIT_LCP;
1771 req->startingNodeId = getOwnNodeId();
1772 if (!ndb_pnr(
getNodeInfo(refToNode(cmasterdihref)).m_version))
1775 infoEvent(
"Detecting upgrade: Master(%u) does not support parallel node recovery",
1776 refToNode(cmasterdihref));
1777 sendSignal(cmasterdihref, GSN_START_COPYREQ, signal,
1778 StartCopyReq::SignalLength, JBB);
1782 sendSignal(reference(), GSN_START_COPYREQ, signal,
1783 StartCopyReq::SignalLength, JBB);
1792 case NodeState::ST_INITIAL_START:
1793 case NodeState::ST_SYSTEM_RESTART:
1799 ndbsttorry10Lab(signal, __LINE__);
1801 case NodeState::ST_NODE_RESTART:
1802 case NodeState::ST_INITIAL_NODE_RESTART:
1803 ndbsttorry10Lab(signal, __LINE__);
1810 ndbsttorry10Lab(signal, __LINE__);
1816 Dbdih::execNODE_START_REP(
Signal* signal)
1830 if (signal->theData[0] == getOwnNodeId())
1837 if (c_dictLockSlavePtrI_nodeRestart != RNIL) {
1838 sendDictUnlockOrd(signal, c_dictLockSlavePtrI_nodeRestart);
1839 c_dictLockSlavePtrI_nodeRestart = RNIL;
1845 Dbdih::createMutexes(
Signal * signal, Uint32 count){
1846 Callback c = { safe_cast(&Dbdih::createMutex_done), count };
1850 Mutex mutex(signal, c_mutexMgr, c_startLcpMutexHandle);
1855 Mutex mutex(signal, c_mutexMgr, c_switchPrimaryMutexHandle);
1860 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
1866 execute(signal, m_sendSTTORRY, 0);
1870 Dbdih::createMutex_done(
Signal* signal, Uint32 senderData, Uint32 retVal){
1872 ndbrequire(retVal == 0);
1876 Mutex mutex(signal, c_mutexMgr, c_startLcpMutexHandle);
1881 Mutex mutex(signal, c_mutexMgr, c_switchPrimaryMutexHandle);
1886 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
1892 createMutexes(signal, senderData + 1);
1904 void Dbdih::execNDB_STARTREQ(
Signal* signal)
1907 BlockReference ref = signal->theData[0];
1908 cstarttype = signal->theData[1];
1909 ndbStartReqLab(signal, ref);
1912 void Dbdih::ndbStartReqLab(
Signal* signal, BlockReference ref)
1914 cndbStartReqBlockref = ref;
1915 if (cstarttype == NodeState::ST_INITIAL_START) {
1917 initRestartInfo(signal);
1918 initGciFilesLab(signal);
1922 NodeRecordPtr nodePtr;
1923 Uint32 gci = SYSFILE->lastCompletedGCI[getOwnNodeId()];
1924 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++)
1927 ptrAss(nodePtr, nodeRecord);
1928 if (SYSFILE->lastCompletedGCI[nodePtr.i] > gci)
1938 SYSFILE->lastCompletedGCI[nodePtr.i] = 0;
1939 ndbrequire(nodePtr.p->nodeStatus != NodeRecord::ALIVE);
1940 warningEvent(
"Making filesystem for node %d unusable (need --initial)",
1943 else if (nodePtr.p->nodeStatus == NodeRecord::ALIVE &&
1944 SYSFILE->lastCompletedGCI[nodePtr.i] == 0)
1947 CRASH_INSERTION(7170);
1950 "Cluster requires this node to be started "
1951 " with --initial as partial start has been performed"
1952 " and this filesystem is unusable");
1954 NDBD_EXIT_SR_RESTARTCONFLICT,
1963 SYSFILE->newestRestorableGCI = gci;
1964 infoEvent(
"Restarting cluster to GCI: %u", gci);
1966 ndbrequire(isMaster());
1967 copyGciLab(signal, CopyGCIReq::RESTART);
1970 void Dbdih::execREAD_NODESCONF(
Signal* signal)
1975 Uint32 nodeArray[MAX_NDB_NODES+1];
1977 csystemnodes = readNodes->noOfNodes;
1978 cmasterNodeId = readNodes->masterNodeId;
1981 for (i = 1; i < MAX_NDB_NODES; i++){
1993 nodeArray[
index] = RNIL;
1999 printf(
"Checking 2-pass initial node restart: ");
2000 for (i = 0; i<
index; i++)
2005 if (!ndbd_non_trans_copy_frag_req(
getNodeInfo(nodeArray[i]).m_version))
2008 c_2pass_inr =
false;
2009 printf(
"not ok (version node %u) => disabled\n", nodeArray[i]);
2014 workers !=
getNodeInfo(nodeArray[i]).m_lqh_workers)
2016 c_2pass_inr =
false;
2017 printf(
"not ok (different worker cnt node %u) => disabled\n",
2034 if(cstarttype == NodeState::ST_SYSTEM_RESTART ||
2035 cstarttype == NodeState::ST_NODE_RESTART)
2038 for(i = 1; i<MAX_NDB_NODES; i++){
2039 const Uint32 stat = Sysfile::getNodeStatus(i, SYSFILE->nodeStatus);
2040 if(stat == Sysfile::NS_NotDefined && !tmp.
get(i))
2046 if(tmp.
get(i) && stat != Sysfile::NS_NotDefined)
2052 if (stat == Sysfile::NS_NotDefined && tmp.
get(i))
2059 if (stat == Sysfile::NS_Configured && !tmp.
get(i))
2062 infoEvent(
"Configured node %u not present, ignoring",
2069 "Illegal configuration change."
2070 " Initial start needs to be performed "
2071 " when removing nodes with nodegroup (node %d)", i);
2072 progError(__LINE__, NDBD_EXIT_INVALID_CONFIG, buf);
2076 ndbrequire(csystemnodes >= 1 && csystemnodes < MAX_NDB_NODES);
2078 cmasterdihref = calcDihBlockRef(cmasterNodeId);
2082 makePrnList(readNodes, nodeArray);
2083 if (cstarttype == NodeState::ST_INITIAL_START) {
2094 makeNodeGroups(nodeArray);
2096 ndbrequire(checkNodeAlive(cmasterNodeId));
2108 NodeRecordPtr specNodePtr;
2109 specNodePtr.i = cfirstAliveNode;
2112 m_sr_nodes.
set(specNodePtr.i);
2113 ptrCheckGuard(specNodePtr, MAX_NDB_NODES, nodeRecord);
2114 specNodePtr.i = specNodePtr.p->nextNode;
2115 }
while (specNodePtr.i != RNIL);
2118 execute(signal, m_sendSTTORRY, 0);
2124 void Dbdih::nodeRestartPh2Lab(
Signal* signal)
2134 ndbrequire(c_dictLockSlavePtrI_nodeRestart == RNIL);
2137 CRASH_INSERTION(7174);
2139 Uint32 lockType = DictLockReq::NodeRestartLock;
2140 Callback c = { safe_cast(&Dbdih::recvDictLockConf_nodeRestart), 0 };
2141 sendDictLockReq(signal, lockType, c);
2144 void Dbdih::recvDictLockConf_nodeRestart(
Signal* signal, Uint32 data, Uint32
ret)
2146 ndbrequire(c_dictLockSlavePtrI_nodeRestart == RNIL);
2147 ndbrequire(data != RNIL);
2148 c_dictLockSlavePtrI_nodeRestart = data;
2150 nodeRestartPh2Lab2(signal);
2153 void Dbdih::nodeRestartPh2Lab2(
Signal* signal)
2161 req->blockRef = reference();
2162 req->nodeId = cownNodeId;
2163 req->startType = cstarttype;
2164 sendSignal(cmasterdihref, GSN_START_PERMREQ, signal, 3, JBB);
2166 if (ERROR_INSERTED(7203))
2168 signal->theData[0] = 9999;
2169 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 200, 1);
2173 void Dbdih::execSTART_PERMCONF(
Signal* signal)
2176 CRASH_INSERTION(7121);
2177 Uint32 nodeId = signal->theData[0];
2178 cfailurenr = signal->theData[1];
2180 bool microGCP = signal->theData[2];
2181 if (signal->getLength() < StartPermConf::SignalLength)
2185 m_micro_gcp.m_enabled = microGCP;
2186 ndbrequire(nodeId == cownNodeId);
2187 ndbsttorry10Lab(signal, __LINE__);
2189 if (m_micro_gcp.m_enabled)
2193 ord->type = UpgradeProtocolOrd::UPO_ENABLE_MICRO_GCP;
2194 EXECUTE_DIRECT(QMGR,GSN_UPGRADE_PROTOCOL_ORD,signal,signal->getLength());
2196 else if(isMultiThreaded())
2202 progError(__LINE__, NDBD_EXIT_SR_RESTARTCONFLICT,
2203 "Cluster requires that all old data nodes are upgraded "
2204 "while running single-threaded ndbd before starting "
2205 "multi-threaded ndbmtd data nodes.");
2209 void Dbdih::execSTART_PERMREF(
Signal* signal)
2212 Uint32 errorCode = signal->theData[1];
2213 if (errorCode == StartPermRef::ZNODE_ALREADY_STARTING_ERROR ||
2214 errorCode == StartPermRef::ZNODE_START_DISALLOWED_ERROR) {
2220 infoEvent(
"Did not get permission to start (%u) retry in 3s",
2222 signal->theData[0] = DihContinueB::ZSTART_PERMREQ_AGAIN;
2223 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 3000, 1);
2227 if (errorCode == StartPermRef::InitialStartRequired)
2229 CRASH_INSERTION(7170);
2232 "Cluster requires this node to be started "
2233 " with --initial as partial start has been performed"
2234 " and this filesystem is unusable");
2236 NDBD_EXIT_SR_RESTARTCONFLICT,
2255 void Dbdih::execSTART_MECONF(
Signal* signal)
2259 Uint32 nodeId = startMe->startingNodeId;
2260 const Uint32 startWord = startMe->startWord;
2263 CRASH_INSERTION(7130);
2264 ndbrequire(nodeId == cownNodeId);
2265 arrGuard(startWord + StartMeConf::DATA_SIZE,
sizeof(cdata)/4);
2266 for(i = 0; i < StartMeConf::DATA_SIZE; i++)
2267 cdata[startWord+i] = startMe->data[i];
2269 if(startWord + StartMeConf::DATA_SIZE < Sysfile::SYSFILE_SIZE32){
2283 Uint32 key = SYSFILE->m_restart_seq;
2284 Uint32 tempGCP[MAX_NDB_NODES];
2285 for(i = 0; i < MAX_NDB_NODES; i++)
2286 tempGCP[i] = SYSFILE->lastCompletedGCI[i];
2288 for(i = 0; i < Sysfile::SYSFILE_SIZE32; i++)
2289 sysfileData[
i] = cdata[
i];
2291 SYSFILE->m_restart_seq = key;
2292 for(i = 0; i < MAX_NDB_NODES; i++)
2293 SYSFILE->lastCompletedGCI[i] = tempGCP[i];
2295 setNodeActiveStatus();
2297 ndbsttorry10Lab(signal, __LINE__);
2299 if (getNodeActiveStatus(getOwnNodeId()) == Sysfile::NS_Configured)
2302 c_set_initial_start_flag = FALSE;
2306 void Dbdih::execSTART_COPYCONF(
Signal* signal)
2311 Uint32 nodeId = conf->startingNodeId;
2312 Uint32 senderData = conf->senderData;
2320 if (senderData == RNIL)
2326 ndbrequire(nodeId == cownNodeId);
2327 CRASH_INSERTION(7132);
2328 ndbsttorry10Lab(signal, __LINE__);
2335 infoEvent(
"Take-over of %u complete", nodeId);
2337 ndbrequire(senderData == getOwnNodeId());
2338 ndbrequire(m_to_nodes.
get(nodeId));
2339 m_to_nodes.
clear(nodeId);
2340 m_sr_nodes.
set(nodeId);
2347 signal->theData[0] = reference();
2348 m_sr_nodes.
copyto(NdbNodeBitmask::Size, signal->theData+1);
2349 sendSignal(cntrlblockref, GSN_NDB_STARTCONF, signal,
2350 1 + NdbNodeBitmask::Size, JBB);
2365 void Dbdih::execSTART_PERMREQ(
Signal* signal)
2369 const BlockReference retRef = req->blockRef;
2370 const Uint32 nodeId = req->nodeId;
2371 const Uint32 typeStart = req->startType;
2372 CRASH_INSERTION(7122);
2373 ndbrequire(isMaster());
2374 ndbrequire(refToNode(retRef) == nodeId);
2375 if ((c_nodeStartMaster.activeState) ||
2376 (c_nodeStartMaster.wait != ZFALSE) ||
2377 ERROR_INSERTED_CLEAR(7175)) {
2379 signal->theData[0] = nodeId;
2380 signal->theData[1] = StartPermRef::ZNODE_ALREADY_STARTING_ERROR;
2381 sendSignal(retRef, GSN_START_PERMREF, signal, 2, JBB);
2385 if (!getAllowNodeStart(nodeId))
2389 signal->theData[0] = nodeId;
2390 signal->theData[1] = StartPermRef::ZNODE_START_DISALLOWED_ERROR;
2391 sendSignal(retRef, GSN_START_PERMREF, signal, 2, JBB);
2394 if (getNodeStatus(nodeId) != NodeRecord::DEAD)
2397 g_eventLogger->
error(
"nodeStatus in START_PERMREQ = %u",
2398 (Uint32) getNodeStatus(nodeId));
2402 if (SYSFILE->lastCompletedGCI[nodeId] == 0 &&
2403 typeStart != NodeState::ST_INITIAL_NODE_RESTART)
2406 signal->theData[0] = nodeId;
2407 signal->theData[1] = StartPermRef::InitialStartRequired;
2408 sendSignal(retRef, GSN_START_PERMREF, signal, 2, JBB);
2415 c_nodeStartMaster.failNr = cfailurenr;
2416 c_nodeStartMaster.wait = ZFALSE;
2417 c_nodeStartMaster.startInfoErrorCode = 0;
2418 c_nodeStartMaster.startNode = nodeId;
2419 c_nodeStartMaster.activeState =
true;
2420 c_nodeStartMaster.m_outstandingGsn = GSN_START_INFOREQ;
2422 setNodeStatus(nodeId, NodeRecord::STARTING);
2431 r->startingNodeId = nodeId;
2432 r->typeStart = typeStart;
2433 r->systemFailureNo = cfailurenr;
2434 sendLoopMacro(START_INFOREQ, sendSTART_INFOREQ, RNIL);
2437 void Dbdih::execSTART_INFOREF(
Signal* signal)
2440 if (getNodeStatus(ref->startingNodeId) != NodeRecord::STARTING) {
2444 ndbrequire(c_nodeStartMaster.startNode == ref->startingNodeId);
2445 c_nodeStartMaster.startInfoErrorCode = ref->errorCode;
2446 startInfoReply(signal, ref->sendingNodeId);
2449 void Dbdih::execSTART_INFOCONF(
Signal* signal)
2453 if (getNodeStatus(conf->startingNodeId) != NodeRecord::STARTING) {
2457 ndbrequire(c_nodeStartMaster.startNode == conf->startingNodeId);
2458 startInfoReply(signal, conf->sendingNodeId);
2461 void Dbdih::startInfoReply(
Signal* signal, Uint32 nodeId)
2463 receiveLoopMacro(START_INFOREQ, nodeId);
2467 if (c_nodeStartMaster.startInfoErrorCode == 0) {
2473 conf->startingNodeId = c_nodeStartMaster.startNode;
2474 conf->systemFailureNo = cfailurenr;
2475 conf->microGCP = m_micro_gcp.m_enabled;
2476 sendSignal(calcDihBlockRef(c_nodeStartMaster.startNode),
2477 GSN_START_PERMCONF, signal, StartPermConf::SignalLength, JBB);
2478 c_nodeStartMaster.m_outstandingGsn = GSN_START_PERMCONF;
2482 ref->startingNodeId = c_nodeStartMaster.startNode;
2483 ref->errorCode = c_nodeStartMaster.startInfoErrorCode;
2484 sendSignal(calcDihBlockRef(c_nodeStartMaster.startNode),
2485 GSN_START_PERMREF, signal, StartPermRef::SignalLength, JBB);
2486 nodeResetStart(signal);
2497 void Dbdih::execSTART_MEREQ(
Signal* signal)
2501 const BlockReference Tblockref = req->startingRef;
2502 const Uint32 Tnodeid = refToNode(Tblockref);
2504 ndbrequire(isMaster());
2505 ndbrequire(c_nodeStartMaster.startNode == Tnodeid);
2506 ndbrequire(getNodeStatus(Tnodeid) == NodeRecord::STARTING);
2508 if (
getNodeInfo(Tnodeid).m_version >= NDBD_COPY_GCI_RESTART_NR)
2520 c_nodeStartMaster.m_outstandingGsn = GSN_COPY_GCIREQ;
2521 copyGciLab(signal, CopyGCIReq::RESTART_NR);
2526 startme_copygci_conf(signal);
2531 Dbdih::startme_copygci_conf(
Signal* signal)
2534 Callback c = { safe_cast(&Dbdih::lcpBlockedLab),
2535 c_nodeStartMaster.startNode };
2536 Mutex mutex(signal, c_mutexMgr, c_nodeStartMaster.m_fragmentInfoMutex);
2537 mutex.lock(c,
true,
true);
2540 void Dbdih::lcpBlockedLab(
Signal* signal, Uint32 nodeId, Uint32 retVal)
2543 if (c_nodeStartMaster.startNode != nodeId)
2546 if (retVal == 0 || retVal == UtilLockRef::InLockQueue)
2548 infoEvent(
"Releasing table/fragment info lock for node %u", nodeId);
2550 Mutex mutex(signal, c_mutexMgr, c_nodeStartMaster.m_fragmentInfoMutex);
2557 if (retVal == UtilLockRef::InLockQueue)
2560 infoEvent(
"Node %u enqueued is waiting to copy table/fragment info",
2561 c_nodeStartMaster.startNode);
2565 ndbrequire(retVal == 0);
2566 ndbrequire(getNodeStatus(c_nodeStartMaster.startNode)==NodeRecord::STARTING);
2572 c_nodeStartMaster.wait = 10;
2573 signal->theData[0] = DihContinueB::ZCOPY_NODE;
2574 signal->theData[1] = 0;
2575 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
2576 c_nodeStartMaster.m_outstandingGsn = GSN_COPY_TABREQ;
2579 void Dbdih::nodeDictStartConfLab(
Signal* signal)
2585 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 1, JBB);
2592 c_nodeStartMaster.wait = ZFALSE;
2593 c_nodeStartMaster.blockGcp = 1;
2598 void Dbdih::dihCopyCompletedLab(
Signal* signal)
2600 BlockReference ref = calcDictBlockRef(c_nodeStartMaster.startNode);
2602 req->restartGci = (Uint32)(m_micro_gcp.m_new_gci >> 32);
2603 req->senderRef = reference();
2604 sendSignal(ref, GSN_DICTSTARTREQ,
2605 signal, DictStartReq::SignalLength, JBB);
2606 c_nodeStartMaster.m_outstandingGsn = GSN_DICTSTARTREQ;
2607 c_nodeStartMaster.wait = 0;
2610 void Dbdih::gcpBlockedLab(
Signal* signal)
2615 NodeRecordPtr nodePtr;
2616 nodePtr.i = c_nodeStartMaster.startNode;
2617 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
2618 nodePtr.p->m_inclDihLcp =
true;
2624 if (getNodeActiveStatus(nodePtr.i) == Sysfile::NS_NotDefined)
2627 infoEvent(
"Adding node %d to sysfile, NS_Configured",
2629 setNodeActiveStatus(nodePtr.i, Sysfile::NS_Configured);
2630 Sysfile::setNodeGroup(nodePtr.i, SYSFILE->nodeGroups,
2632 Sysfile::setNodeStatus(nodePtr.i,
2633 SYSFILE->nodeStatus, Sysfile::NS_Configured);
2640 sendLoopMacro(INCL_NODEREQ, sendINCL_NODEREQ, RNIL);
2648 if ((getMajor(startVersion) == 4 &&
2649 startVersion >= NDBD_INCL_NODECONF_VERSION_4) ||
2650 (getMajor(startVersion) == 5 &&
2651 startVersion >= NDBD_INCL_NODECONF_VERSION_5) ||
2652 (getMajor(startVersion) > 5))
2654 c_INCL_NODEREQ_Counter.
setWaitingFor(c_nodeStartMaster.startNode);
2657 sendINCL_NODEREQ(signal, c_nodeStartMaster.startNode, RNIL);
2663 void Dbdih::execINCL_NODECONF(
Signal* signal)
2666 Uint32 TstartNode = signal->theData[0];
2667 Uint32 TsendNodeId_or_blockref = signal->theData[1];
2669 Uint32 blocklist[7];
2670 blocklist[0] = clocallqhblockref;
2671 blocklist[1] = clocaltcblockref;
2672 blocklist[2] = cdictblockref;
2673 blocklist[3] = numberToRef(BACKUP, getOwnNodeId());
2674 blocklist[4] = numberToRef(SUMA, getOwnNodeId());
2675 blocklist[5] = numberToRef(DBSPJ, getOwnNodeId());
2678 for (Uint32 i = 0; blocklist[
i] != 0; i++)
2680 if (TsendNodeId_or_blockref == blocklist[i])
2684 if (TstartNode != c_nodeStartSlave.nodeId)
2688 " while %u is starting",
2690 getBlockName(refToBlock(TsendNodeId_or_blockref)),
2691 c_nodeStartSlave.nodeId);
2695 if (getNodeStatus(c_nodeStartSlave.nodeId) == NodeRecord::ALIVE &&
2696 blocklist[i+1] != 0)
2702 signal->theData[0] = reference();
2703 signal->theData[1] = c_nodeStartSlave.nodeId;
2704 sendSignal(blocklist[i+1], GSN_INCL_NODEREQ, signal, 2, JBB);
2713 signal->theData[0] = c_nodeStartSlave.nodeId;
2714 signal->theData[1] = cownNodeId;
2715 sendSignal(cmasterdihref, GSN_INCL_NODECONF, signal, 2, JBB);
2717 c_nodeStartSlave.nodeId = 0;
2723 if (c_nodeStartMaster.startNode != TstartNode)
2727 " while %u is starting",
2729 TsendNodeId_or_blockref,
2730 c_nodeStartMaster.startNode);
2734 ndbrequire(reference() == cmasterdihref);
2735 receiveLoopMacro(INCL_NODEREQ, TsendNodeId_or_blockref);
2737 CRASH_INSERTION(7128);
2742 c_nodeStartMaster.wait = 11;
2743 c_nodeStartMaster.blockGcp = 0;
2748 signal->theData[0] = reference();
2749 sendSignal(reference(), GSN_UNBLO_DICTCONF, signal, 1, JBB);
2751 signal->theData[0] = DihContinueB::ZSTART_GCP;
2752 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
2760 signal->theData[0] = DihContinueB::ZDELAY_RELEASE_FRAGMENT_INFO_MUTEX;
2761 signal->theData[1] = c_nodeStartMaster.m_fragmentInfoMutex.getHandle();
2762 c_nodeStartMaster.m_fragmentInfoMutex.clear();
2763 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 500, 2);
2766 void Dbdih::execUNBLO_DICTCONF(
Signal* signal)
2769 c_nodeStartMaster.wait = ZFALSE;
2770 if (!c_nodeStartMaster.activeState) {
2775 CRASH_INSERTION(7129);
2786 const Uint32 wordPerSignal = StartMeConf::DATA_SIZE;
2787 const int noOfSignals = ((Sysfile::SYSFILE_SIZE32 + (wordPerSignal - 1)) /
2790 Uint32 nodeId = startMe->startingNodeId = c_nodeStartMaster.startNode;
2791 startMe->startWord = 0;
2793 const Uint32 ref = calcDihBlockRef(c_nodeStartMaster.startNode);
2794 for(
int i = 0; i < noOfSignals; i++){
2797 const int startWord = startMe->startWord;
2798 for(Uint32 j = 0; j < wordPerSignal; j++){
2799 startMe->data[j] = sysfileData[j+startWord];
2802 sendSignal(ref, GSN_START_MECONF, signal, StartMeConf::SignalLength, JBB);
2803 startMe->startWord += wordPerSignal;
2805 c_nodeStartMaster.m_outstandingGsn = GSN_START_MECONF;
2806 nodeResetStart(signal);
2811 signal->theData[0] = nodeId;
2812 sendSignal(NDBCNTR_REF, GSN_START_PERMREP, signal, 1, JBB);
2821 void Dbdih::execSTART_COPYREQ(
Signal* signal)
2826 Uint32 startNodeId = req.startingNodeId;
2832 signal->theData[1] = req.startingNodeId;
2833 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
2835 CRASH_INSERTION(7131);
2837 switch (getNodeActiveStatus(startNodeId)) {
2838 case Sysfile::NS_Active:
2839 case Sysfile::NS_ActiveMissed_1:
2840 case Sysfile::NS_ActiveMissed_2:
2841 case Sysfile::NS_NotActive_NotTakenOver:
2842 case Sysfile::NS_Configured:
2850 startTakeOver(signal, startNodeId, startNodeId, &req);
2852 case Sysfile::NS_TakeOver:{
2858 Uint32 takeOverNode = Sysfile::getTakeOverNode(startNodeId,
2860 if(takeOverNode == 0){
2863 takeOverNode = startNodeId;
2866 startTakeOver(signal, startNodeId, takeOverNode, &req);
2878 void Dbdih::execSTART_INFOREQ(
Signal* signal)
2882 Uint32 startNode = req->startingNodeId;
2883 if (cfailurenr != req->systemFailureNo) {
2891 CRASH_INSERTION(7123);
2894 ndbrequire(getNodeStatus(startNode) == NodeRecord::STARTING);
2897 ndbrequire(getNodeStatus(startNode) == NodeRecord::DEAD);
2899 if ((!getAllowNodeStart(startNode)) ||
2900 (c_nodeStartSlave.nodeId != 0) ||
2901 (ERROR_INSERTED(7124))) {
2904 ref->startingNodeId = startNode;
2905 ref->sendingNodeId = cownNodeId;
2906 ref->errorCode = StartPermRef::ZNODE_START_DISALLOWED_ERROR;
2907 sendSignal(cmasterdihref, GSN_START_INFOREF, signal,
2908 StartInfoRef::SignalLength, JBB);
2911 setNodeStatus(startNode, NodeRecord::STARTING);
2912 if (req->typeStart == NodeState::ST_INITIAL_NODE_RESTART) {
2914 setAllowNodeStart(startNode,
false);
2915 invalidateNodeLCP(signal, startNode, 0);
2919 c->sendingNodeId = cownNodeId;
2920 c->startingNodeId = startNode;
2921 sendSignal(cmasterdihref, GSN_START_INFOCONF, signal,
2922 StartInfoConf::SignalLength, JBB);
2927 void Dbdih::execINCL_NODEREQ(
Signal* signal)
2930 Uint32 retRef = signal->theData[0];
2931 Uint32 nodeId = signal->theData[1];
2932 if (nodeId == getOwnNodeId() && ERROR_INSERTED(7165))
2934 CLEAR_ERROR_INSERT_VALUE;
2935 sendSignalWithDelay(reference(), GSN_INCL_NODEREQ, signal, 5000,
2936 signal->getLength());
2940 Uint32 tnodeStartFailNr = signal->theData[2];
2941 Uint32 gci_hi = signal->theData[4];
2942 Uint32 gci_lo = signal->theData[5];
2943 if (unlikely(signal->getLength() < 6))
2949 Uint64 gci = gci_lo | (Uint64(gci_hi) << 32);
2950 CRASH_INSERTION(7127);
2951 m_micro_gcp.m_current_gci = gci;
2952 m_micro_gcp.m_old_gci = gci - 1;
2959 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
2968 if (getOwnNodeId() == nodeId) {
2974 CRASH_INSERTION(7171);
2977 if ((NDB_VERSION_MAJOR == 4 &&
2978 masterVersion >= NDBD_INCL_NODECONF_VERSION_4) ||
2979 (NDB_VERSION_MAJOR == 5 &&
2980 masterVersion >= NDBD_INCL_NODECONF_VERSION_5) ||
2981 (NDB_VERSION_MAJOR > 5))
2983 signal->theData[0] = getOwnNodeId();
2984 signal->theData[1] = getOwnNodeId();
2985 sendSignal(cmasterdihref, GSN_INCL_NODECONF, signal, 2, JBB);
2989 if (getNodeStatus(nodeId) != NodeRecord::STARTING) {
2993 ndbrequire(cfailurenr == tnodeStartFailNr);
2994 ndbrequire (c_nodeStartSlave.nodeId == 0);
2995 c_nodeStartSlave.nodeId = nodeId;
2997 ndbrequire (retRef == cmasterdihref);
2999 NodeRecordPtr nodePtr;
3001 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3004 Uint32 TnodeGroup = nodePtr.p->nodeGroup;
3006 new (nodePtr.p) NodeRecord();
3007 nodePtr.p->nodeGroup = TnodeGroup;
3008 nodePtr.p->activeStatus = TsaveState;
3009 nodePtr.p->nodeStatus = NodeRecord::ALIVE;
3010 nodePtr.p->useInTransactions =
true;
3011 nodePtr.p->m_inclDihLcp =
true;
3013 removeDeadNode(nodePtr);
3014 insertAlive(nodePtr);
3020 signal->theData[0] = reference();
3021 signal->theData[1] = nodeId;
3022 signal->theData[2] = Uint32(m_micro_gcp.m_current_gci >> 32);
3023 sendSignal(clocallqhblockref, GSN_INCL_NODEREQ, signal, 3, JBB);
3031 void Dbdih::execSTART_TOREQ(
Signal* signal)
3040 TakeOverRecordPtr takeOverPtr;
3042 c_activeTakeOverList.
seize(takeOverPtr);
3043 takeOverPtr.p->toStartingNode = req.startingNodeId;
3044 takeOverPtr.p->m_senderRef = req.senderRef;
3045 takeOverPtr.p->m_senderData = req.senderData;
3046 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MASTER_IDLE;
3047 takeOverPtr.p->toStartTime = c_current_time;
3051 conf->senderData = req.senderData;
3052 conf->sendingNodeId = cownNodeId;
3053 conf->startingNodeId = req.startingNodeId;
3054 sendSignal(req.senderRef, GSN_START_TOCONF,
3055 signal, StartToConf::SignalLength, JBB);
3058 void Dbdih::execUPDATE_TOREQ(
Signal* signal)
3071 TakeOverRecordPtr takeOverPtr;
3072 if (findTakeOver(takeOverPtr, req.startingNodeId) ==
false)
3074 errCode = UpdateToRef::UnknownTakeOver;
3079 CRASH_INSERTION(7141);
3081 takeOverPtr.p->toCopyNode = req.copyNodeId;
3082 takeOverPtr.p->toCurrentTabref = req.tableId;
3083 takeOverPtr.p->toCurrentFragid = req.fragmentNo;
3085 NodeRecordPtr nodePtr;
3086 NodeGroupRecordPtr NGPtr;
3087 nodePtr.i = req.copyNodeId;
3088 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3089 NGPtr.i = nodePtr.p->nodeGroup;
3090 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
3092 Mutex mutex(signal, c_mutexMgr, takeOverPtr.p->m_fragmentInfoMutex);
3093 Callback c = { safe_cast(&Dbdih::updateToReq_fragmentMutex_locked),
3096 switch(req.requestType){
3097 case UpdateToReq::BEFORE_STORED:
3100 if (NGPtr.p->activeTakeOver == 0)
3103 NGPtr.p->activeTakeOver = req.startingNodeId;
3108 errCode = UpdateToRef::CopyFragInProgress;
3109 extra = NGPtr.p->activeTakeOver;
3113 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MUTEX_BEFORE_STORED;
3114 mutex.lock(c,
false,
true);
3116 case UpdateToReq::AFTER_STORED:
3120 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_AFTER_STORED;
3124 case UpdateToReq::BEFORE_COMMIT_STORED:
3126 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MUTEX_BEFORE_COMMIT;
3127 mutex.lock(c,
false,
true);
3129 case UpdateToReq::AFTER_COMMIT_STORED:
3134 Mutex mutex2(signal, c_mutexMgr,
3135 takeOverPtr.p->m_switchPrimaryMutexHandle);
3137 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MASTER_IDLE;
3144 CRASH_INSERTION(7154);
3145 RETURN_IF_NODE_NOT_ALIVE(req.startingNodeId);
3150 conf->senderData = req.senderData;
3151 conf->sendingNodeId = cownNodeId;
3152 conf->startingNodeId = req.startingNodeId;
3153 sendSignal(req.senderRef, GSN_UPDATE_TOCONF, signal,
3154 UpdateToConf::SignalLength, JBB);
3160 ref->senderData = req.senderData;
3161 ref->senderRef = reference();
3162 ref->errorCode = errCode;
3164 sendSignal(req.senderRef, GSN_UPDATE_TOREF, signal,
3165 UpdateToRef::SignalLength, JBB);
3169 Dbdih::updateToReq_fragmentMutex_locked(
Signal * signal,
3170 Uint32 toPtrI, Uint32 retVal)
3173 TakeOverRecordPtr takeOverPtr;
3174 c_takeOverPool.
getPtr(takeOverPtr, toPtrI);
3176 Uint32 nodeId = takeOverPtr.p->toStartingNode;
3178 if (retVal == UtilLockRef::InLockQueue)
3181 infoEvent(
"Node %u waiting to continue copying table %u fragment: %u (%s)",
3183 takeOverPtr.p->toCurrentTabref,
3184 takeOverPtr.p->toCurrentFragid,
3185 takeOverPtr.p->toMasterStatus == TakeOverRecord::TO_MUTEX_BEFORE_STORED ?
"STORED" :
"COMMIT");
3192 NodeRecordPtr nodePtr;
3194 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3195 if (unlikely(nodePtr.p->nodeStatus != NodeRecord::ALIVE))
3201 abortTakeOver(signal, takeOverPtr);
3205 switch(takeOverPtr.p->toMasterStatus){
3206 case TakeOverRecord::TO_MUTEX_BEFORE_STORED:
3210 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MUTEX_BEFORE_LOCKED;
3213 case TakeOverRecord::TO_MUTEX_BEFORE_COMMIT:
3217 NodeRecordPtr nodePtr;
3218 NodeGroupRecordPtr NGPtr;
3219 nodePtr.i = takeOverPtr.p->toCopyNode;
3220 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3221 NGPtr.i = nodePtr.p->nodeGroup;
3222 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
3224 if (NGPtr.p->activeTakeOver != nodeId)
3227 errCode = UpdateToRef::InvalidRequest;
3228 extra = NGPtr.p->activeTakeOver;
3231 NGPtr.p->activeTakeOver = 0;
3232 takeOverPtr.p->toCopyNode = RNIL;
3233 Mutex mutex(signal, c_mutexMgr,
3234 takeOverPtr.p->m_switchPrimaryMutexHandle);
3235 Callback c = { safe_cast(&Dbdih::switchPrimaryMutex_locked),
3237 ndbrequire(mutex.lock(c));
3238 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MUTEX_BEFORE_SWITCH_REPLICA;
3243 jamLine(takeOverPtr.p->toMasterStatus);
3249 conf->senderData = takeOverPtr.p->m_senderData;
3250 conf->sendingNodeId = cownNodeId;
3251 conf->startingNodeId = takeOverPtr.p->toStartingNode;
3252 sendSignal(takeOverPtr.p->m_senderRef, GSN_UPDATE_TOCONF, signal,
3253 UpdateToConf::SignalLength, JBB);
3259 Mutex mutex(signal, c_mutexMgr, takeOverPtr.p->m_fragmentInfoMutex);
3263 ref->senderData = takeOverPtr.p->m_senderData;
3264 ref->senderRef = reference();
3265 ref->errorCode = errCode;
3267 sendSignal(takeOverPtr.p->m_senderRef, GSN_UPDATE_TOREF, signal,
3268 UpdateToRef::SignalLength, JBB);
3274 Dbdih::switchPrimaryMutex_locked(
Signal* signal, Uint32 toPtrI, Uint32 retVal)
3277 ndbrequire(retVal == 0);
3279 TakeOverRecordPtr takeOverPtr;
3280 c_takeOverPool.
getPtr(takeOverPtr, toPtrI);
3282 Uint32 nodeId = takeOverPtr.p->toStartingNode;
3283 NodeRecordPtr nodePtr;
3285 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3287 if (unlikely(nodePtr.p->nodeStatus != NodeRecord::ALIVE))
3293 abortTakeOver(signal, takeOverPtr);
3297 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MUTEX_AFTER_SWITCH_REPLICA;
3300 conf->senderData = takeOverPtr.p->m_senderData;
3301 conf->sendingNodeId = cownNodeId;
3302 conf->startingNodeId = takeOverPtr.p->toStartingNode;
3303 sendSignal(takeOverPtr.p->m_senderRef, GSN_UPDATE_TOCONF, signal,
3304 UpdateToConf::SignalLength, JBB);
3308 Dbdih::switchPrimaryMutex_unlocked(
Signal* signal, Uint32 toPtrI, Uint32 retVal)
3311 ndbrequire(retVal == 0);
3313 TakeOverRecordPtr takeOverPtr;
3314 c_takeOverPool.
getPtr(takeOverPtr, toPtrI);
3317 conf->senderData = takeOverPtr.p->m_senderData;
3318 conf->sendingNodeId = cownNodeId;
3319 conf->startingNodeId = takeOverPtr.p->toStartingNode;
3320 sendSignal(takeOverPtr.p->m_senderRef, GSN_UPDATE_TOCONF, signal,
3321 UpdateToConf::SignalLength, JBB);
3325 Dbdih::abortTakeOver(
Signal* signal, TakeOverRecordPtr takeOverPtr)
3327 if (!takeOverPtr.p->m_switchPrimaryMutexHandle.isNull())
3330 Mutex mutex(signal, c_mutexMgr,
3331 takeOverPtr.p->m_switchPrimaryMutexHandle);
3336 if (!takeOverPtr.p->m_fragmentInfoMutex.isNull())
3339 Mutex mutex(signal, c_mutexMgr,
3340 takeOverPtr.p->m_fragmentInfoMutex);
3344 NodeRecordPtr nodePtr;
3345 nodePtr.i = takeOverPtr.p->toCopyNode;
3346 if (nodePtr.i != RNIL)
3348 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3349 NodeGroupRecordPtr NGPtr;
3350 NGPtr.i = nodePtr.p->nodeGroup;
3351 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
3352 if (NGPtr.p->activeTakeOver == takeOverPtr.p->toStartingNode)
3355 NGPtr.p->activeTakeOver = 0;
3359 releaseTakeOver(takeOverPtr);
3364 add_lcp_counter(Uint32 * counter, Uint32 add)
3366 Uint64 tmp = * counter;
3368 if (tmp > 0xFFFFFFFF)
3370 * counter = Uint32(tmp);
3376 Uint64 duration = c_current_time - takeOverPtr.p->toStartTime;
3377 Uint64 lcp_time = c_lcpState.m_lcp_time;
3380 for (c_activeTakeOverList.
first(tmp); !tmp.isNull();
3381 c_activeTakeOverList.
next(tmp))
3384 if (tmp.p->toMasterStatus != TakeOverRecord::TO_WAIT_LCP)
3388 Uint64 elapsed = c_current_time - tmp.p->toStartTime;
3389 if (elapsed >= duration)
3397 infoEvent(
"Node %u not forcing LCP start(1 %llu >= %llu), wait on %u",
3398 takeOverPtr.p->toStartingNode,
3400 tmp.p->toStartingNode);
3404 Uint64 left = duration - elapsed;
3405 if (left < lcp_time)
3412 infoEvent(
"Node %u not forcing LCP start(2 %llu < %llu), wait on %u",
3413 takeOverPtr.p->toStartingNode,
3415 tmp.p->toStartingNode);
3420 add_lcp_counter(&c_lcpState.ctimer, (1 << 31));
3423 void Dbdih::execEND_TOREQ(
Signal* signal)
3428 Uint32 nodeId = refToNode(req.senderRef);
3429 TakeOverRecordPtr takeOverPtr;
3437 ndbrequire(findTakeOver(takeOverPtr, nodeId));
3438 NodeRecordPtr nodePtr;
3440 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
3442 if (req.flags & StartCopyReq::WAIT_LCP)
3449 nodePtr.p->copyCompleted = 2;
3450 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_WAIT_LCP;
3457 c_lcpState.lcpStopGcp = c_newest_restorable_gci;
3459 check_force_lcp(takeOverPtr);
3462 nodePtr.p->copyCompleted = 1;
3463 releaseTakeOver(takeOverPtr);
3467 conf->senderData = req.senderData;
3468 conf->sendingNodeId = cownNodeId;
3469 conf->startingNodeId = req.startingNodeId;
3470 sendSignal(req.senderRef, GSN_END_TOCONF, signal,
3471 EndToConf::SignalLength, JBB);
3474 #define DIH_TAB_WRITE_LOCK(tabPtrP) \
3475 do { assertOwnThread(); tabPtrP->m_lock.write_lock(); } while (0)
3477 #define DIH_TAB_WRITE_UNLOCK(tabPtrP) \
3478 do { assertOwnThread(); tabPtrP->m_lock.write_unlock(); } while (0)
3484 void Dbdih::execCREATE_FRAGREQ(
Signal* signal)
3489 Uint32 senderData = req->senderData;
3490 Uint32 senderRef = req->senderRef;
3492 TabRecordPtr tabPtr;
3493 tabPtr.i = req->tableId;
3494 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
3496 Uint32 fragId = req->fragId;
3497 Uint32 tdestNodeid = req->startingNodeId;
3499 Uint32 startGci = req->startGci;
3500 Uint32 replicaType = req->replicaType;
3501 Uint32 tFailedNodeId = req->failedNodeId;
3503 if (!ndb_pnr(
getNodeInfo(refToNode(senderRef)).m_version))
3506 tFailedNodeId = tdestNodeid;
3509 FragmentstorePtr fragPtr;
3510 getFragstore(tabPtr.p, fragId, fragPtr);
3511 RETURN_IF_NODE_NOT_ALIVE(tdestNodeid);
3512 ReplicaRecordPtr frReplicaPtr;
3513 findReplica(frReplicaPtr, fragPtr.p, tFailedNodeId,
3514 replicaType == CreateFragReq::START_LOGGING ?
false :
true);
3515 if (frReplicaPtr.i == RNIL)
3517 dump_replica_info(fragPtr.p);
3519 ndbrequire(frReplicaPtr.i != RNIL);
3521 DIH_TAB_WRITE_LOCK(tabPtr.p);
3522 switch (replicaType) {
3523 case CreateFragReq::STORED:
3525 CRASH_INSERTION(7138);
3531 insertBackup(fragPtr, tdestNodeid);
3533 fragPtr.p->distributionKey++;
3534 fragPtr.p->distributionKey &= 255;
3536 case CreateFragReq::COMMIT_STORED:
3538 CRASH_INSERTION(7139);
3545 removeOldStoredReplica(fragPtr, frReplicaPtr);
3546 linkStoredReplica(fragPtr, frReplicaPtr);
3547 updateNodeInfo(fragPtr);
3549 case CreateFragReq::START_LOGGING:
3556 DIH_TAB_WRITE_UNLOCK(tabPtr.p);
3561 if (tFailedNodeId != tdestNodeid)
3571 frReplicaPtr.p->procNode = tdestNodeid;
3572 frReplicaPtr.p->noCrashedReplicas = 0;
3573 frReplicaPtr.p->createGci[0] = startGci;
3574 frReplicaPtr.p->replicaLastGci[0] = (Uint32)-1;
3575 for (Uint32 i = 0; i < MAX_LCP_STORED; i++)
3577 frReplicaPtr.p->lcpStatus[
i] = ZINVALID;
3583 const Uint32 noCrashed = frReplicaPtr.p->noCrashedReplicas;
3584 arrGuard(noCrashed, 8);
3585 frReplicaPtr.p->createGci[noCrashed] = startGci;
3586 frReplicaPtr.p->replicaLastGci[noCrashed] = (Uint32)-1;
3590 conf->senderData = senderData;
3591 conf->tableId = tabPtr.i;
3592 conf->fragId = fragId;
3593 conf->sendingNodeId = cownNodeId;
3594 conf->startingNodeId = tdestNodeid;
3595 conf->failedNodeId = tFailedNodeId;
3596 sendSignal(senderRef, GSN_CREATE_FRAGCONF, signal,
3597 CreateFragConf::SignalLength, JBB);
3618 void Dbdih::startTakeOver(
Signal* signal,
3620 Uint32 nodeTakenOver,
3625 TakeOverRecordPtr takeOverPtr;
3626 ndbrequire(c_activeTakeOverList.
seize(takeOverPtr));
3627 takeOverPtr.p->startGci = SYSFILE->lastCompletedGCI[startNode];
3628 takeOverPtr.p->restorableGci = SYSFILE->lastCompletedGCI[startNode];
3629 takeOverPtr.p->toStartingNode = startNode;
3630 takeOverPtr.p->toFailedNode = nodeTakenOver;
3631 takeOverPtr.p->toCurrentTabref = 0;
3632 takeOverPtr.p->toCurrentFragid = 0;
3637 takeOverPtr.p->m_flags = req->flags;
3638 takeOverPtr.p->m_senderData = req->senderData;
3639 takeOverPtr.p->m_senderRef = req->senderRef;
3642 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_START_FRAGMENTS;
3643 nr_start_fragments(signal, takeOverPtr);
3647 Dbdih::nr_start_fragments(
Signal* signal,
3648 TakeOverRecordPtr takeOverPtr)
3650 Uint32 loopCount = 0 ;
3651 TabRecordPtr tabPtr;
3652 while (loopCount++ < 100) {
3653 tabPtr.i = takeOverPtr.p->toCurrentTabref;
3654 if (tabPtr.i >= ctabFileSize) {
3656 nr_run_redo(signal, takeOverPtr);
3659 ptrAss(tabPtr, tabRecord);
3660 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE ||
3661 tabPtr.p->tabStorage != TabRecord::ST_NORMAL)
3664 takeOverPtr.p->toCurrentFragid = 0;
3665 takeOverPtr.p->toCurrentTabref++;
3668 Uint32 fragId = takeOverPtr.p->toCurrentFragid;
3669 if (fragId >= tabPtr.p->totalfragments) {
3671 takeOverPtr.p->toCurrentFragid = 0;
3672 takeOverPtr.p->toCurrentTabref++;
3675 FragmentstorePtr fragPtr;
3676 getFragstore(tabPtr.p, fragId, fragPtr);
3677 ReplicaRecordPtr loopReplicaPtr;
3678 loopReplicaPtr.i = fragPtr.p->oldStoredReplicas;
3679 while (loopReplicaPtr.i != RNIL) {
3680 ptrCheckGuard(loopReplicaPtr, creplicaFileSize, replicaRecord);
3681 if (loopReplicaPtr.p->procNode == takeOverPtr.p->toStartingNode) {
3683 nr_start_fragment(signal, takeOverPtr, loopReplicaPtr);
3687 loopReplicaPtr.i = loopReplicaPtr.p->nextReplica;
3690 takeOverPtr.p->toCurrentFragid++;
3692 signal->theData[0] = DihContinueB::ZTO_START_FRAGMENTS;
3693 signal->theData[1] = takeOverPtr.i;
3694 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
3698 Dbdih::nr_start_fragment(
Signal* signal,
3699 TakeOverRecordPtr takeOverPtr,
3700 ReplicaRecordPtr replicaPtr)
3703 Uint32 maxLcpId = 0;
3704 Uint32 maxLcpIndex = ~0;
3707 Uint32 restorableGCI = takeOverPtr.p->restorableGci;
3709 #if defined VM_TRACE || defined ERROR_INSERT
3710 ndbout_c(
"tab: %d frag: %d replicaP->nextLcp: %d",
3711 takeOverPtr.p->toCurrentTabref,
3712 takeOverPtr.p->toCurrentFragid,
3713 replicaPtr.p->nextLcp);
3716 Int32 j = replicaPtr.p->noCrashedReplicas - 1;
3717 Uint32 idx = prevLcpNo(replicaPtr.p->nextLcp);
3718 for(i = 0; i<MAX_LCP_USED; i++, idx = prevLcpNo(idx))
3720 #if defined VM_TRACE || defined ERROR_INSERT
3721 printf(
"scanning idx: %d lcpId: %d crashed replicas: %u %s",
3722 idx, replicaPtr.p->lcpId[idx],
3723 replicaPtr.p->noCrashedReplicas,
3724 replicaPtr.p->lcpStatus[idx] == ZVALID ?
"VALID" :
"NOT VALID");
3726 if (replicaPtr.p->lcpStatus[idx] == ZVALID)
3728 Uint32 startGci = replicaPtr.p->maxGciCompleted[idx] + 1;
3729 Uint32 stopGci = replicaPtr.p->maxGciStarted[idx];
3730 #if defined VM_TRACE || defined ERROR_INSERT
3731 ndbout_c(
" maxGciCompleted: %u maxGciStarted: %u", startGci - 1, stopGci);
3735 #if defined VM_TRACE || defined ERROR_INSERT
3736 ndbout_c(
"crashed replica: %d(%d) replica(createGci: %u lastGci: %d )",
3738 replicaPtr.p->noCrashedReplicas,
3739 replicaPtr.p->createGci[j],
3740 replicaPtr.p->replicaLastGci[j]);
3742 if (replicaPtr.p->createGci[j] <= startGci &&
3743 replicaPtr.p->replicaLastGci[j] >= stopGci)
3745 maxLcpId = replicaPtr.p->lcpId[idx];
3747 gci = replicaPtr.p->replicaLastGci[j];
3754 #if defined VM_TRACE || defined ERROR_INSERT
3761 #if defined VM_TRACE || defined ERROR_INSERT
3762 ndbout_c(
"- scanning idx: %d lcpId: %d", idx, replicaPtr.p->lcpId[idx]);
3764 if (replicaPtr.p->lcpStatus[idx] == ZVALID)
3766 Uint32 startGci = replicaPtr.p->maxGciCompleted[idx] + 1;
3767 Uint32 stopGci = replicaPtr.p->maxGciStarted[idx];
3770 #if defined VM_TRACE || defined ERROR_INSERT
3771 ndbout_c(
"crashed replica: %d(%d) replica(createGci: %u lastGci: %d )",
3773 replicaPtr.p->noCrashedReplicas,
3774 replicaPtr.p->createGci[j],
3775 replicaPtr.p->replicaLastGci[j]);
3777 if (replicaPtr.p->createGci[j] <= startGci &&
3778 replicaPtr.p->replicaLastGci[j] >= stopGci)
3780 maxLcpId = replicaPtr.p->lcpId[idx];
3782 gci = replicaPtr.p->replicaLastGci[j];
3791 req->requestInfo = StartFragReq::SFR_RESTORE_LCP;
3792 if (maxLcpIndex == ~ (Uint32) 0)
3798 ndbassert(gci == 0);
3799 replicaPtr.p->m_restorable_gci = gci;
3802 req->userRef = reference();
3805 req->tableId = takeOverPtr.p->toCurrentTabref;
3806 req->fragId = takeOverPtr.p->toCurrentFragid;
3807 req->noOfLogNodes = 0;
3809 if (c_2pass_inr && cstarttype == NodeState::ST_INITIAL_NODE_RESTART)
3821 if (takeOverPtr.p->startGci == 0)
3829 takeOverPtr.p->startGci = SYSFILE->lastCompletedGCI[cmasterNodeId];
3832 TabRecordPtr tabPtr;
3833 tabPtr.i = takeOverPtr.p->toCurrentTabref;
3834 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
3836 FragmentstorePtr fragPtr;
3837 getFragstore(tabPtr.p, takeOverPtr.p->toCurrentFragid, fragPtr);
3838 Uint32 nodes[MAX_REPLICAS];
3839 extractNodeInfo(fragPtr.p, nodes);
3841 req->lqhLogNode[0] = nodes[0];
3842 req->requestInfo = StartFragReq::SFR_COPY_FRAG;
3843 replicaPtr.p->m_restorable_gci = takeOverPtr.p->startGci;
3846 if (req->requestInfo == StartFragReq::SFR_RESTORE_LCP)
3848 ndbout_c(
"node: %d tab: %d frag: %d no lcp to restore",
3849 takeOverPtr.p->toStartingNode,
3850 takeOverPtr.p->toCurrentTabref,
3851 takeOverPtr.p->toCurrentFragid);
3855 ndbout_c(
"node: %d tab: %d frag: %d copying data from %u (gci: %u)",
3856 takeOverPtr.p->toStartingNode,
3857 takeOverPtr.p->toCurrentTabref,
3858 takeOverPtr.p->toCurrentFragid,
3860 takeOverPtr.p->startGci);
3863 BlockReference ref = numberToRef(DBLQH, takeOverPtr.p->toStartingNode);
3864 sendSignal(ref, GSN_START_FRAGREQ, signal,
3865 StartFragReq::SignalLength, JBB);
3870 if (gci != restorableGCI)
3873 tabPtr.i = takeOverPtr.p->toCurrentTabref;
3874 ptrAss(tabPtr, tabRecord);
3876 FragmentstorePtr fragPtr;
3877 getFragstore(tabPtr.p, takeOverPtr.p->toCurrentFragid, fragPtr);
3878 dump_replica_info(fragPtr.p);
3880 ndbassert(gci == restorableGCI);
3881 replicaPtr.p->m_restorable_gci = gci;
3882 Uint32 startGci = replicaPtr.p->maxGciCompleted[maxLcpIndex] + 1;
3885 ndbout_c(
"node: %d tab: %d frag: %d restore lcp: %u(idx: %u) maxGciStarted: %u maxGciCompleted: %u (restorable: %u(%u) newestRestorableGCI: %u)",
3886 takeOverPtr.p->toStartingNode,
3887 takeOverPtr.p->toCurrentTabref,
3888 takeOverPtr.p->toCurrentFragid,
3891 replicaPtr.p->maxGciStarted[maxLcpIndex],
3892 replicaPtr.p->maxGciCompleted[maxLcpIndex],
3894 SYSFILE->lastCompletedGCI[takeOverPtr.p->toStartingNode],
3895 SYSFILE->newestRestorableGCI);
3899 req->userRef = reference();
3900 req->lcpNo = maxLcpIndex;
3901 req->lcpId = maxLcpId;
3902 req->tableId = takeOverPtr.p->toCurrentTabref;
3903 req->fragId = takeOverPtr.p->toCurrentFragid;
3904 req->noOfLogNodes = 1;
3905 req->lqhLogNode[0] = takeOverPtr.p->toStartingNode;
3906 req->startGci[0] = startGci;
3907 req->lastGci[0] = gci;
3909 BlockReference ref = numberToRef(DBLQH, takeOverPtr.p->toStartingNode);
3910 sendSignal(ref, GSN_START_FRAGREQ, signal,
3911 StartFragReq::SignalLength, JBB);
3913 if (startGci < takeOverPtr.p->startGci)
3916 takeOverPtr.p->startGci = startGci;
3922 Dbdih::nr_run_redo(
Signal* signal, TakeOverRecordPtr takeOverPtr)
3931 m_sr_nodes.
set(takeOverPtr.p->toStartingNode);
3933 Uint32 save_keepGCI = SYSFILE->keepGCI;
3934 if (takeOverPtr.p->startGci < SYSFILE->keepGCI)
3937 SYSFILE->keepGCI = takeOverPtr.p->startGci;
3938 ndbout_c(
"GSN_START_RECREQ keepGci: %u (%u)",
3939 takeOverPtr.p->startGci, save_keepGCI);
3942 takeOverPtr.p->toCurrentTabref = 0;
3943 takeOverPtr.p->toCurrentFragid = 0;
3944 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_RUN_REDO;
3945 sendSTART_RECREQ(signal, takeOverPtr.p->toStartingNode, takeOverPtr.i);
3948 SYSFILE->keepGCI = save_keepGCI;
3952 Dbdih::nr_start_logging(
Signal* signal, TakeOverRecordPtr takeOverPtr)
3954 Uint32 loopCount = 0 ;
3955 TabRecordPtr tabPtr;
3956 while (loopCount++ < 100)
3958 tabPtr.i = takeOverPtr.p->toCurrentTabref;
3959 if (tabPtr.i >= ctabFileSize)
3962 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_END_TO;
3964 req->senderData = takeOverPtr.i;
3965 req->senderRef = reference();
3966 req->flags = takeOverPtr.p->m_flags;
3967 sendSignal(cmasterdihref, GSN_END_TOREQ,
3968 signal, EndToReq::SignalLength, JBB);
3972 ptrAss(tabPtr, tabRecord);
3973 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE ||
3974 tabPtr.p->tabStorage != TabRecord::ST_NORMAL)
3977 takeOverPtr.p->toCurrentFragid = 0;
3978 takeOverPtr.p->toCurrentTabref++;
3982 Uint32 fragId = takeOverPtr.p->toCurrentFragid;
3983 if (fragId >= tabPtr.p->totalfragments)
3986 takeOverPtr.p->toCurrentFragid = 0;
3987 takeOverPtr.p->toCurrentTabref++;
3991 FragmentstorePtr fragPtr;
3992 getFragstore(tabPtr.p, fragId, fragPtr);
3993 ReplicaRecordPtr loopReplicaPtr;
3994 loopReplicaPtr.i = fragPtr.p->storedReplicas;
3995 while (loopReplicaPtr.i != RNIL)
3997 ptrCheckGuard(loopReplicaPtr, creplicaFileSize, replicaRecord);
3998 if (loopReplicaPtr.p->procNode == takeOverPtr.p->toStartingNode)
4001 ndbrequire(loopReplicaPtr.p->procNode == getOwnNodeId());
4002 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_SL_COPY_ACTIVE;
4004 Uint32 instanceKey = dihGetInstanceKey(fragPtr);
4005 BlockReference lqhRef = numberToRef(DBLQH, instanceKey,
4006 takeOverPtr.p->toStartingNode);
4009 req->userPtr = takeOverPtr.i;
4010 req->userRef = reference();
4011 req->tableId = takeOverPtr.p->toCurrentTabref;
4012 req->fragId = takeOverPtr.p->toCurrentFragid;
4013 req->distributionKey = fragPtr.p->distributionKey;
4015 sendSignal(lqhRef,GSN_COPY_ACTIVEREQ, signal,
4016 CopyActiveReq::SignalLength, JBB);
4022 loopReplicaPtr.i = loopReplicaPtr.p->nextReplica;
4025 takeOverPtr.p->toCurrentFragid++;
4027 signal->theData[0] = DihContinueB::ZTO_START_LOGGING;
4028 signal->theData[1] = takeOverPtr.i;
4029 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
4033 Dbdih::sendStartTo(
Signal* signal, TakeOverRecordPtr takeOverPtr)
4035 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_START_TO;
4038 req->senderData = takeOverPtr.i;
4039 req->senderRef = reference();
4040 req->startingNodeId = takeOverPtr.p->toStartingNode;
4041 sendSignal(cmasterdihref, GSN_START_TOREQ,
4042 signal, StartToReq::SignalLength, JBB);
4046 Dbdih::execSTART_TOREF(
Signal* signal)
4051 Uint32 errCode = ref->errorCode;
4054 TakeOverRecordPtr takeOverPtr;
4055 c_takeOverPool.
getPtr(takeOverPtr, ref->senderData);
4057 signal->theData[0] = DihContinueB::ZSEND_START_TO;
4058 signal->theData[1] = takeOverPtr.i;
4060 sendSignalWithDelay(reference(), GSN_CONTINUEB,
4065 Dbdih::execSTART_TOCONF(
Signal* signal)
4070 TakeOverRecordPtr takeOverPtr;
4071 c_takeOverPool.
getPtr(takeOverPtr, conf->senderData);
4073 CRASH_INSERTION(7133);
4078 startNextCopyFragment(signal, takeOverPtr.i);
4081 void Dbdih::startNextCopyFragment(
Signal* signal, Uint32 takeOverPtrI)
4083 TabRecordPtr tabPtr;
4084 TakeOverRecordPtr takeOverPtr;
4085 c_takeOverPool.
getPtr(takeOverPtr, takeOverPtrI);
4089 if (ERROR_INSERTED(7159)) {
4092 while (loopCount++ < 100) {
4093 tabPtr.i = takeOverPtr.p->toCurrentTabref;
4094 if (tabPtr.i >= ctabFileSize) {
4096 CRASH_INSERTION(7136);
4097 toCopyCompletedLab(signal, takeOverPtr);
4100 ptrAss(tabPtr, tabRecord);
4101 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE){
4103 takeOverPtr.p->toCurrentFragid = 0;
4104 takeOverPtr.p->toCurrentTabref++;
4107 Uint32 fragId = takeOverPtr.p->toCurrentFragid;
4108 if (fragId >= tabPtr.p->totalfragments) {
4110 takeOverPtr.p->toCurrentFragid = 0;
4111 takeOverPtr.p->toCurrentTabref++;
4112 if (ERROR_INSERTED(7135)) {
4113 if (takeOverPtr.p->toCurrentTabref == 1) {
4119 FragmentstorePtr fragPtr;
4120 getFragstore(tabPtr.p, fragId, fragPtr);
4121 ReplicaRecordPtr loopReplicaPtr;
4122 loopReplicaPtr.i = fragPtr.p->oldStoredReplicas;
4123 while (loopReplicaPtr.i != RNIL) {
4124 ptrCheckGuard(loopReplicaPtr, creplicaFileSize, replicaRecord);
4125 if (loopReplicaPtr.p->procNode == takeOverPtr.p->toFailedNode) {
4131 takeOverPtr.p->toCurrentReplica = loopReplicaPtr.i;
4132 toCopyFragLab(signal, takeOverPtr.i);
4134 }
else if (loopReplicaPtr.p->procNode == takeOverPtr.p->toStartingNode) {
4141 takeOverPtr.p->toCurrentReplica = loopReplicaPtr.i;
4142 toCopyFragLab(signal, takeOverPtr.i);
4146 loopReplicaPtr.i = loopReplicaPtr.p->nextReplica;
4149 takeOverPtr.p->toCurrentFragid++;
4151 signal->theData[0] = DihContinueB::ZTO_START_COPY_FRAG;
4152 signal->theData[1] = takeOverPtr.i;
4153 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
4156 void Dbdih::toCopyFragLab(
Signal* signal,
4157 Uint32 takeOverPtrI)
4159 TakeOverRecordPtr takeOverPtr;
4160 c_takeOverPool.
getPtr(takeOverPtr, takeOverPtrI);
4165 TabRecordPtr tabPtr;
4166 tabPtr.i = takeOverPtr.p->toCurrentTabref;
4167 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
4169 FragmentstorePtr fragPtr;
4170 getFragstore(tabPtr.p, takeOverPtr.p->toCurrentFragid, fragPtr);
4171 Uint32 nodes[MAX_REPLICAS];
4172 extractNodeInfo(fragPtr.p, nodes);
4173 takeOverPtr.p->toCopyNode = nodes[0];
4176 req->senderRef = reference();
4177 req->senderData = takeOverPtrI;
4178 req->tableId = takeOverPtr.p->toCurrentTabref;
4179 req->fragId = takeOverPtr.p->toCurrentFragid;
4180 req->copyNodeId = takeOverPtr.p->toCopyNode;
4181 req->startingNodeId = takeOverPtr.p->toStartingNode;
4183 Uint32 instanceKey = dihGetInstanceKey(req->tableId, req->fragId);
4184 Uint32 ref = numberToRef(DBLQH, instanceKey, takeOverPtr.p->toStartingNode);
4186 sendSignal(ref, GSN_PREPARE_COPY_FRAG_REQ, signal,
4187 PrepareCopyFragReq::SignalLength, JBB);
4189 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_PREPARE_COPY;
4193 Dbdih::execPREPARE_COPY_FRAG_REF(
Signal* signal)
4198 TakeOverRecordPtr takeOverPtr;
4199 c_takeOverPool.
getPtr(takeOverPtr, ref.senderData);
4201 ndbrequire(takeOverPtr.p->toSlaveStatus == TakeOverRecord::TO_PREPARE_COPY);
4207 cfref->userPtr = ref.senderData;
4208 cfref->startingNodeId = ref.startingNodeId;
4209 cfref->errorCode = ref.errorCode;
4210 cfref->tableId = ref.tableId;
4211 cfref->fragId = ref.fragId;
4212 cfref->sendingNodeId = ref.copyNodeId;
4213 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_COPY_FRAG;
4214 execCOPY_FRAGREF(signal);
4218 Dbdih::execPREPARE_COPY_FRAG_CONF(
Signal* signal)
4223 TakeOverRecordPtr takeOverPtr;
4224 c_takeOverPool.
getPtr(takeOverPtr, conf.senderData);
4227 ndbrequire(ndb_check_prep_copy_frag_version(version) >= 2);
4228 takeOverPtr.p->maxPage = conf.maxPageNo;
4233 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_UPDATE_BEFORE_STORED;
4234 sendUpdateTo(signal, takeOverPtr);
4238 Dbdih::sendUpdateTo(
Signal* signal, TakeOverRecordPtr takeOverPtr)
4241 req->senderData = takeOverPtr.i;
4242 req->senderRef = reference();
4243 req->startingNodeId = takeOverPtr.p->toStartingNode;
4244 req->copyNodeId = takeOverPtr.p->toCopyNode;
4245 req->tableId = takeOverPtr.p->toCurrentTabref;
4246 req->fragmentNo = takeOverPtr.p->toCurrentFragid;
4247 switch(takeOverPtr.p->toSlaveStatus){
4248 case TakeOverRecord::TO_UPDATE_BEFORE_STORED:
4250 req->requestType = UpdateToReq::BEFORE_STORED;
4252 case TakeOverRecord::TO_UPDATE_AFTER_STORED:
4253 req->requestType = UpdateToReq::AFTER_STORED;
4255 case TakeOverRecord::TO_UPDATE_BEFORE_COMMIT:
4257 req->requestType = UpdateToReq::BEFORE_COMMIT_STORED;
4259 case TakeOverRecord::TO_UPDATE_AFTER_COMMIT:
4261 req->requestType = UpdateToReq::AFTER_COMMIT_STORED;
4264 jamLine(takeOverPtr.p->toSlaveStatus);
4267 sendSignal(cmasterdihref, GSN_UPDATE_TOREQ,
4268 signal, UpdateToReq::SignalLength, JBB);
4272 Dbdih::execUPDATE_TOREF(
Signal* signal)
4276 Uint32 errCode = ref->errorCode;
4279 TakeOverRecordPtr takeOverPtr;
4280 c_takeOverPool.
getPtr(takeOverPtr, ref->senderData);
4282 signal->theData[0] = DihContinueB::ZSEND_UPDATE_TO;
4283 signal->theData[1] = takeOverPtr.i;
4285 sendSignalWithDelay(reference(), GSN_CONTINUEB,
4290 Dbdih::execUPDATE_TOCONF(
Signal* signal)
4296 TakeOverRecordPtr takeOverPtr;
4297 c_takeOverPool.
getPtr(takeOverPtr, conf->senderData);
4299 switch(takeOverPtr.p->toSlaveStatus){
4300 case TakeOverRecord::TO_UPDATE_BEFORE_STORED:
4303 CRASH_INSERTION(7154);
4305 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_CREATE_FRAG_STORED;
4306 sendCreateFragReq(signal, ZINIT_CREATE_GCI, CreateFragReq::STORED, takeOverPtr.i);
4308 case TakeOverRecord::TO_UPDATE_AFTER_STORED:
4311 CRASH_INSERTION(7195);
4313 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_COPY_FRAG;
4314 toStartCopyFrag(signal, takeOverPtr);
4316 case TakeOverRecord::TO_UPDATE_BEFORE_COMMIT:
4319 CRASH_INSERTION(7196);
4321 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_CREATE_FRAG_COMMIT;
4322 sendCreateFragReq(signal, takeOverPtr.p->startGci,
4323 CreateFragReq::COMMIT_STORED, takeOverPtr.i);
4325 case TakeOverRecord::TO_UPDATE_AFTER_COMMIT:
4328 CRASH_INSERTION(7197);
4330 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_SELECTING_NEXT;
4331 startNextCopyFragment(signal, takeOverPtr.i);
4339 Dbdih::toStartCopyFrag(
Signal* signal, TakeOverRecordPtr takeOverPtr)
4341 TabRecordPtr tabPtr;
4342 tabPtr.i = takeOverPtr.p->toCurrentTabref;
4343 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
4345 Uint32 fragId = takeOverPtr.p->toCurrentFragid;
4347 FragmentstorePtr fragPtr;
4348 getFragstore(tabPtr.p, fragId, fragPtr);
4350 ReplicaRecordPtr replicaPtr;
4351 findReplica(replicaPtr, fragPtr.p, getOwnNodeId(),
true);
4353 Uint32 gci = replicaPtr.p->m_restorable_gci;
4354 replicaPtr.p->m_restorable_gci = 0;
4356 Uint32 instanceKey = dihGetInstanceKey(tabPtr.i, fragId);
4357 BlockReference ref = numberToRef(DBLQH, instanceKey,
4358 takeOverPtr.p->toCopyNode);
4360 copyFragReq->userPtr = takeOverPtr.i;
4361 copyFragReq->userRef = reference();
4362 copyFragReq->tableId = tabPtr.i;
4363 copyFragReq->fragId = fragId;
4364 copyFragReq->nodeId = takeOverPtr.p->toStartingNode;
4365 copyFragReq->schemaVersion = tabPtr.p->schemaVersion;
4366 copyFragReq->distributionKey = fragPtr.p->distributionKey;
4367 copyFragReq->gci = gci;
4368 Uint32 len = copyFragReq->nodeCount =
4369 extractNodeInfo(fragPtr.p,
4370 copyFragReq->nodeList);
4371 copyFragReq->nodeList[len] = takeOverPtr.p->maxPage;
4372 copyFragReq->nodeList[len+1] = CopyFragReq::CFR_TRANSACTIONAL;
4373 sendSignal(ref, GSN_COPY_FRAGREQ, signal,
4374 CopyFragReq::SignalLength + len, JBB);
4377 void Dbdih::sendCreateFragReq(
Signal* signal,
4380 Uint32 takeOverPtrI)
4383 c_takeOverPool.
getPtr(takeOverPtr, takeOverPtrI);
4385 sendLoopMacro(CREATE_FRAGREQ, nullRoutine, RNIL);
4388 req->senderData = takeOverPtr.i;
4389 req->senderRef = reference();
4390 req->tableId = takeOverPtr.p->toCurrentTabref;
4391 req->fragId = takeOverPtr.p->toCurrentFragid;
4392 req->startingNodeId = takeOverPtr.p->toStartingNode;
4393 req->copyNodeId = takeOverPtr.p->toCopyNode;
4394 req->failedNodeId = takeOverPtr.p->toFailedNode;
4395 req->startGci = startGci;
4396 req->replicaType = replicaType;
4398 NodeRecordPtr nodePtr;
4399 nodePtr.i = cfirstAliveNode;
4401 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
4402 BlockReference ref = calcDihBlockRef(nodePtr.i);
4403 sendSignal(ref, GSN_CREATE_FRAGREQ, signal,
4404 CreateFragReq::SignalLength, JBB);
4405 nodePtr.i = nodePtr.p->nextNode;
4406 }
while (nodePtr.i != RNIL);
4409 void Dbdih::execCREATE_FRAGCONF(
Signal* signal)
4412 CRASH_INSERTION(7148);
4415 TakeOverRecordPtr takeOverPtr;
4416 c_takeOverPool.
getPtr(takeOverPtr, conf->senderData);
4418 receiveLoopMacro(CREATE_FRAGREQ, conf->sendingNodeId);
4420 switch(takeOverPtr.p->toSlaveStatus){
4421 case TakeOverRecord::TO_CREATE_FRAG_STORED:
4423 CRASH_INSERTION(7198);
4424 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_UPDATE_AFTER_STORED;
4426 case TakeOverRecord::TO_CREATE_FRAG_COMMIT:
4428 CRASH_INSERTION(7199);
4429 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_UPDATE_AFTER_COMMIT;
4431 case TakeOverRecord::TO_SL_CREATE_FRAG:
4434 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_START_LOGGING;
4435 takeOverPtr.p->toCurrentFragid++;
4436 signal->theData[0] = DihContinueB::ZTO_START_LOGGING;
4437 signal->theData[1] = takeOverPtr.i;
4438 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
4441 jamLine(takeOverPtr.p->toSlaveStatus);
4445 sendUpdateTo(signal, takeOverPtr);
4448 void Dbdih::execCOPY_FRAGREF(
Signal* signal)
4452 Uint32 takeOverPtrI = ref->userPtr;
4453 Uint32 startingNodeId = ref->startingNodeId;
4454 Uint32 errorCode = ref->errorCode;
4456 TakeOverRecordPtr takeOverPtr;
4457 c_takeOverPool.
getPtr(takeOverPtr, takeOverPtrI);
4458 ndbrequire(ref->tableId == takeOverPtr.p->toCurrentTabref);
4459 ndbrequire(ref->fragId == takeOverPtr.p->toCurrentFragid);
4460 ndbrequire(ref->startingNodeId == takeOverPtr.p->toStartingNode);
4461 ndbrequire(ref->sendingNodeId == takeOverPtr.p->toCopyNode);
4462 ndbrequire(takeOverPtr.p->toSlaveStatus == TakeOverRecord::TO_COPY_FRAG);
4468 BlockReference cntrRef = calcNdbCntrBlockRef(startingNodeId);
4470 sysErr->errorCode = SystemError::CopyFragRefError;
4471 sysErr->errorRef = reference();
4472 sysErr->data[0] = errorCode;
4473 sysErr->data[1] = 0;
4474 sendSignal(cntrRef, GSN_SYSTEM_ERROR, signal,
4475 SystemError::SignalLength, JBB);
4479 void Dbdih::execCOPY_FRAGCONF(
Signal* signal)
4483 CRASH_INSERTION(7142);
4485 TakeOverRecordPtr takeOverPtr;
4486 c_takeOverPool.
getPtr(takeOverPtr, conf->userPtr);
4488 Uint32 rows_lo = conf->rows_lo;
4489 Uint32 bytes_lo = conf->bytes_lo;
4491 ndbrequire(conf->tableId == takeOverPtr.p->toCurrentTabref);
4492 ndbrequire(conf->fragId == takeOverPtr.p->toCurrentFragid);
4493 ndbrequire(conf->startingNodeId == takeOverPtr.p->toStartingNode);
4494 ndbrequire(conf->sendingNodeId == takeOverPtr.p->toCopyNode);
4495 ndbrequire(takeOverPtr.p->toSlaveStatus == TakeOverRecord::TO_COPY_FRAG);
4497 TabRecordPtr tabPtr;
4498 tabPtr.i = takeOverPtr.p->toCurrentTabref;
4499 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
4501 FragmentstorePtr fragPtr;
4502 getFragstore(tabPtr.p, takeOverPtr.p->toCurrentFragid, fragPtr);
4503 Uint32 instanceKey = dihGetInstanceKey(fragPtr);
4504 BlockReference lqhRef = numberToRef(DBLQH, instanceKey,
4505 takeOverPtr.p->toStartingNode);
4507 req->userPtr = takeOverPtr.i;
4508 req->userRef = reference();
4509 req->tableId = takeOverPtr.p->toCurrentTabref;
4510 req->fragId = takeOverPtr.p->toCurrentFragid;
4511 req->distributionKey = fragPtr.p->distributionKey;
4514 Uint32 min_version = getNodeVersionInfo().m_type[
NodeInfo::DB].m_min_version;
4515 if (ndb_delayed_copy_active_req(min_version))
4523 req->flags |= CopyActiveReq::CAR_NO_WAIT | CopyActiveReq::CAR_NO_LOGGING;
4526 sendSignal(lqhRef, GSN_COPY_ACTIVEREQ, signal,
4527 CopyActiveReq::SignalLength, JBB);
4529 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_COPY_ACTIVE;
4532 signal->theData[1] = getOwnNodeId();
4533 signal->theData[2] = takeOverPtr.p->toCurrentTabref;
4534 signal->theData[3] = takeOverPtr.p->toCurrentFragid;
4535 signal->theData[4] = rows_lo;
4536 signal->theData[5] = 0;
4537 signal->theData[6] = bytes_lo;
4538 signal->theData[7] = 0;
4539 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 8, JBB);
4542 void Dbdih::execCOPY_ACTIVECONF(
Signal* signal)
4546 CRASH_INSERTION(7143);
4548 TakeOverRecordPtr takeOverPtr;
4549 c_takeOverPool.
getPtr(takeOverPtr, conf->userPtr);
4551 ndbrequire(conf->tableId == takeOverPtr.p->toCurrentTabref);
4552 ndbrequire(conf->fragId == takeOverPtr.p->toCurrentFragid);
4553 ndbrequire(checkNodeAlive(conf->startingNodeId));
4555 takeOverPtr.p->startGci = conf->startGci;
4557 if (takeOverPtr.p->toSlaveStatus == TakeOverRecord::TO_COPY_ACTIVE)
4560 ndbrequire(takeOverPtr.p->toSlaveStatus == TakeOverRecord::TO_COPY_ACTIVE);
4561 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_UPDATE_BEFORE_COMMIT;
4562 sendUpdateTo(signal, takeOverPtr);
4567 ndbrequire(takeOverPtr.p->toSlaveStatus==TakeOverRecord::TO_SL_COPY_ACTIVE);
4568 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_SL_CREATE_FRAG;
4569 sendCreateFragReq(signal, takeOverPtr.p->startGci,
4570 CreateFragReq::START_LOGGING, takeOverPtr.i);
4574 void Dbdih::toCopyCompletedLab(
Signal * signal, TakeOverRecordPtr takeOverPtr)
4577 signal->theData[1] = takeOverPtr.p->toStartingNode;
4578 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
4580 Uint32 min_version = getNodeVersionInfo().m_type[
NodeInfo::DB].m_min_version;
4581 if (ndb_delayed_copy_active_req(min_version))
4584 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_START_LOGGING;
4585 takeOverPtr.p->toCurrentTabref = 0;
4586 takeOverPtr.p->toCurrentFragid = 0;
4587 takeOverPtr.p->toCurrentReplica = RNIL;
4588 nr_start_logging(signal, takeOverPtr);
4595 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_END_TO;
4598 req->senderData = takeOverPtr.i;
4599 req->senderRef = reference();
4600 req->flags = takeOverPtr.p->m_flags;
4601 sendSignal(cmasterdihref, GSN_END_TOREQ,
4602 signal, EndToReq::SignalLength, JBB);
4608 Dbdih::execEND_TOREF(
Signal* signal)
4613 TakeOverRecordPtr takeOverPtr;
4614 c_takeOverPool.
getPtr(takeOverPtr, ref->senderData);
4620 Dbdih::execEND_TOCONF(
Signal* signal)
4625 CRASH_INSERTION(7144);
4627 TakeOverRecordPtr takeOverPtr;
4628 c_takeOverPool.
getPtr(takeOverPtr, conf->senderData);
4630 Uint32 senderData = takeOverPtr.p->m_senderData;
4631 Uint32 senderRef = takeOverPtr.p->m_senderRef;
4632 Uint32 nodeId = takeOverPtr.p->toStartingNode;
4634 releaseTakeOver(takeOverPtr);
4637 ret->startingNodeId = nodeId;
4638 ret->senderData = senderData;
4639 ret->senderRef = reference();
4640 sendSignal(senderRef, GSN_START_COPYCONF, signal,
4641 StartCopyConf::SignalLength, JBB);
4644 void Dbdih::releaseTakeOver(TakeOverRecordPtr takeOverPtr)
4646 takeOverPtr.p->toCopyNode = RNIL;
4647 takeOverPtr.p->toCurrentFragid = RNIL;
4648 takeOverPtr.p->toCurrentReplica = RNIL;
4649 takeOverPtr.p->toCurrentTabref = RNIL;
4650 takeOverPtr.p->toFailedNode = RNIL;
4651 takeOverPtr.p->toStartingNode = RNIL;
4652 takeOverPtr.p->toStartTime = 0;
4653 takeOverPtr.p->toSlaveStatus = TakeOverRecord::TO_SLAVE_IDLE;
4654 takeOverPtr.p->toMasterStatus = TakeOverRecord::TO_MASTER_IDLE;
4656 c_activeTakeOverList.
release(takeOverPtr);
4669 void Dbdih::readGciFileLab(
Signal* signal)
4671 FileRecordPtr filePtr;
4672 filePtr.i = crestartInfoFile[0];
4673 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4674 filePtr.p->reqStatus = FileRecord::OPENING_GCP;
4676 openFileRo(signal, filePtr);
4679 void Dbdih::openingGcpLab(
Signal* signal, FileRecordPtr filePtr)
4685 readRestorableGci(signal, filePtr);
4686 filePtr.p->reqStatus = FileRecord::READING_GCP;
4689 void Dbdih::readingGcpLab(
Signal* signal, FileRecordPtr filePtr)
4702 globalData.m_restart_seq = ++SYSFILE->m_restart_seq;
4703 closeFile(signal, filePtr);
4704 filePtr.p->reqStatus = FileRecord::CLOSING_GCP;
4707 void Dbdih::closingGcpLab(
Signal* signal, FileRecordPtr filePtr)
4711 selectMasterCandidateAndSend(signal);
4715 sendDihRestartRef(signal);
4721 Dbdih::sendDihRestartRef(
Signal* signal)
4732 m_ctx.m_config.getClusterConfigIterator();
4733 for(ndb_mgm_first(iter); ndb_mgm_valid(iter); ndb_mgm_next(iter))
4739 ndbrequire(!ndb_mgm_get_int_parameter(iter,CFG_NODE_ID, &nodeId));
4740 ndbrequire(!ndb_mgm_get_int_parameter(iter,CFG_TYPE_OF_SECTION,
4747 if (ndb_mgm_get_int_parameter(iter, CFG_DB_NODEGROUP, &ng) == 0)
4752 no_nodegroup_mask.
set(nodeId);
4758 no_nodegroup_mask.
copyto(NdbNodeBitmask::Size, ref->no_nodegroup_mask);
4759 sendSignal(cntrlblockref, GSN_DIH_RESTARTREF, signal,
4760 DihRestartRef::SignalLength, JBB);
4766 void Dbdih::selectMasterCandidateAndSend(
Signal* signal)
4770 NodeRecordPtr nodePtr;
4771 Uint32 node_groups[MAX_NDB_NODES];
4772 memset(node_groups, 0,
sizeof(node_groups));
4774 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
4776 if (Sysfile::getNodeStatus(nodePtr.i, SYSFILE->nodeStatus) == Sysfile::NS_NotDefined)
4781 const Uint32 ng = Sysfile::getNodeGroup(nodePtr.i, SYSFILE->nodeGroups);
4782 if(ng != NO_NODE_GROUP_ID)
4784 ndbrequire(ng < MAX_NDB_NODES);
4789 no_nodegroup_mask.
set(nodePtr.i);
4794 conf->unused = getOwnNodeId();
4795 conf->latest_gci = SYSFILE->lastCompletedGCI[getOwnNodeId()];
4796 no_nodegroup_mask.
copyto(NdbNodeBitmask::Size, conf->no_nodegroup_mask);
4797 sendSignal(cntrlblockref, GSN_DIH_RESTARTCONF, signal,
4798 DihRestartConf::SignalLength, JBB);
4800 for (nodePtr.i = 0; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
4802 Uint32 count = node_groups[nodePtr.i];
4803 if(count != 0 && count != cnoReplicas){
4806 "Illegal configuration change."
4807 " Initial start needs to be performed "
4808 " when changing no of replicas (%d != %d)",
4809 node_groups[nodePtr.i], cnoReplicas);
4810 progError(__LINE__, NDBD_EXIT_INVALID_CONFIG, buf);
4818 void Dbdih::openingGcpErrorLab(
Signal* signal, FileRecordPtr filePtr)
4820 filePtr.p->fileStatus = FileRecord::CRASHED;
4821 filePtr.p->reqStatus = FileRecord::IDLE;
4822 if (crestartInfoFile[0] == filePtr.i) {
4828 filePtr.i = crestartInfoFile[1];
4829 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4830 openFileRo(signal, filePtr);
4831 filePtr.p->reqStatus = FileRecord::OPENING_GCP;
4839 sendDihRestartRef(signal);
4844 void Dbdih::readingGcpErrorLab(
Signal* signal, FileRecordPtr filePtr)
4846 filePtr.p->fileStatus = FileRecord::CRASHED;
4850 closeFile(signal, filePtr);
4851 filePtr.p->reqStatus = FileRecord::CLOSING_GCP_CRASH;
4854 void Dbdih::closingGcpCrashLab(
Signal* signal, FileRecordPtr filePtr)
4856 if (crestartInfoFile[0] == filePtr.i) {
4861 filePtr.i = crestartInfoFile[1];
4862 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4863 openFileRw(signal, filePtr);
4864 filePtr.p->reqStatus = FileRecord::OPENING_GCP;
4871 sendDihRestartRef(signal);
4880 void Dbdih::initGciFilesLab(
Signal* signal)
4882 FileRecordPtr filePtr;
4883 filePtr.i = crestartInfoFile[0];
4884 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4885 createFileRw(signal, filePtr);
4886 filePtr.p->reqStatus = FileRecord::CREATING_GCP;
4892 void Dbdih::creatingGcpLab(
Signal* signal, FileRecordPtr filePtr)
4894 if (filePtr.i == crestartInfoFile[0]) {
4899 filePtr.i = crestartInfoFile[1];
4900 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4901 createFileRw(signal, filePtr);
4902 filePtr.p->reqStatus = FileRecord::CREATING_GCP;
4909 filePtr.i = crestartInfoFile[0];
4910 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4911 writeRestorableGci(signal, filePtr);
4912 filePtr.p->reqStatus = FileRecord::WRITE_INIT_GCP;
4919 void Dbdih::writeInitGcpLab(
Signal* signal, FileRecordPtr filePtr)
4921 filePtr.p->reqStatus = FileRecord::IDLE;
4922 if (filePtr.i == crestartInfoFile[0]) {
4927 filePtr.i = crestartInfoFile[1];
4928 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
4929 writeRestorableGci(signal, filePtr);
4930 filePtr.p->reqStatus = FileRecord::WRITE_INIT_GCP;
4942 signal->theData[0] = reference();
4943 sendSignal(cndbStartReqBlockref, GSN_NDB_STARTCONF, signal, 1, JBB);
4946 ndbsttorry10Lab(signal, __LINE__);
4958 void Dbdih::execNODE_FAILREP(
Signal* signal)
4961 Uint32 failedNodes[MAX_NDB_NODES];
4965 cfailurenr = nodeFail->failNo;
4967 const Uint32 noOfFailedNodes = nodeFail->noOfNodes;
4969 if (ERROR_INSERTED(7179) || ERROR_INSERTED(7217))
4971 CLEAR_ERROR_INSERT_VALUE;
4974 if (ERROR_INSERTED(7184))
4976 SET_ERROR_INSERT_VALUE(7000);
4985 for (i = 1; i < MAX_NDB_NODES; i++) {
4993 ndbrequire(noOfFailedNodes == index);
4994 ndbrequire(noOfFailedNodes - 1 < MAX_NDB_NODES);
5003 for (i = 0; i < noOfFailedNodes; i++) {
5005 NodeRecordPtr TNodePtr;
5006 TNodePtr.i = failedNodes[
i];
5007 ptrCheckGuard(TNodePtr, MAX_NDB_NODES, nodeRecord);
5008 TNodePtr.p->useInTransactions =
false;
5009 TNodePtr.p->m_inclDihLcp =
false;
5010 TNodePtr.p->recNODE_FAILREP = ZTRUE;
5011 if (TNodePtr.p->nodeStatus == NodeRecord::ALIVE) {
5014 TNodePtr.p->nodeStatus = NodeRecord::DIED_NOW;
5015 removeAlive(TNodePtr);
5016 insertDeadNode(TNodePtr);
5034 if (
false && c_nodeStartMaster.startNode != RNIL && getNodeStatus(c_nodeStartMaster.startNode) == NodeRecord::ALIVE)
5036 BlockReference cntrRef = calcNdbCntrBlockRef(c_nodeStartMaster.startNode);
5038 sysErr->errorCode = SystemError::StartInProgressError;
5039 sysErr->errorRef = reference();
5041 sysErr->data[1]= __LINE__;
5042 sendSignal(cntrRef, GSN_SYSTEM_ERROR, signal, SystemError::SignalLength, JBA);
5043 nodeResetStart(signal);
5052 Uint32 oldMasterId = cmasterNodeId;
5053 BlockReference oldMasterRef = cmasterdihref;
5054 cmasterdihref = calcDihBlockRef(newMasterId);
5055 cmasterNodeId = newMasterId;
5057 const bool masterTakeOver = (oldMasterId != newMasterId);
5059 for(i = 0; i < noOfFailedNodes; i++) {
5060 NodeRecordPtr failedNodePtr;
5061 failedNodePtr.i = failedNodes[
i];
5062 ptrCheckGuard(failedNodePtr, MAX_NDB_NODES, nodeRecord);
5063 if (oldMasterRef == reference()) {
5067 checkCopyTab(signal, failedNodePtr);
5068 checkStopPermMaster(signal, failedNodePtr);
5069 checkWaitGCPMaster(signal, failedNodes[i]);
5073 if (findTakeOver(takeOverPtr, failedNodePtr.i))
5075 handleTakeOver(signal, takeOverPtr);
5078 checkGcpOutstanding(signal, failedNodePtr.i);
5085 checkStopPermProxy(signal, failedNodes[i]);
5086 checkWaitGCPProxy(signal, failedNodes[i]);
5091 checkStopMe(signal, failedNodePtr);
5092 failedNodeLcpHandling(signal, failedNodePtr);
5093 startRemoveFailedNode(signal, failedNodePtr);
5099 failedNodeSynchHandling(signal, failedNodePtr);
5104 startLcpMasterTakeOver(signal, oldMasterId);
5105 startGcpMasterTakeOver(signal, oldMasterId);
5109 progError(__LINE__, NDBD_EXIT_MASTER_FAILURE_DURING_NR);
5116 setNodeRestartInfoBits(signal);
5120 void Dbdih::checkCopyTab(
Signal* signal, NodeRecordPtr failedNodePtr)
5124 if(c_nodeStartMaster.startNode != failedNodePtr.i){
5129 switch(c_nodeStartMaster.m_outstandingGsn){
5130 case GSN_COPY_TABREQ:
5132 ndbrequire(c_COPY_TABREQ_Counter.isWaitingFor(failedNodePtr.i));
5133 releaseTabPages(failedNodePtr.p->activeTabptr);
5134 c_COPY_TABREQ_Counter.clearWaitingFor(failedNodePtr.i);
5135 c_nodeStartMaster.wait = ZFALSE;
5137 case GSN_START_INFOREQ:
5138 case GSN_START_PERMCONF:
5139 case GSN_DICTSTARTREQ:
5140 case GSN_START_MECONF:
5141 case GSN_COPY_GCIREQ:
5145 g_eventLogger->
error(
"outstanding gsn: %s(%d)",
5146 getSignalName(c_nodeStartMaster.m_outstandingGsn),
5147 c_nodeStartMaster.m_outstandingGsn);
5151 if (!c_nodeStartMaster.m_fragmentInfoMutex.isNull())
5154 Mutex mutex(signal, c_mutexMgr, c_nodeStartMaster.m_fragmentInfoMutex);
5158 nodeResetStart(signal);
5161 void Dbdih::checkStopMe(
Signal* signal, NodeRecordPtr failedNodePtr)
5164 if (c_STOP_ME_REQ_Counter.isWaitingFor(failedNodePtr.i)){
5166 ndbrequire(c_stopMe.clientRef != 0);
5168 stopMeConf->senderRef = calcDihBlockRef(failedNodePtr.i);
5169 stopMeConf->senderData = c_stopMe.clientData;
5170 sendSignal(reference(), GSN_STOP_ME_CONF, signal,
5171 StopMeConf::SignalLength, JBB);
5175 void Dbdih::checkStopPermMaster(
Signal* signal, NodeRecordPtr failedNodePtr)
5179 if (c_DIH_SWITCH_REPLICA_REQ_Counter.isWaitingFor(failedNodePtr.i)){
5181 ndbrequire(c_stopPermMaster.clientRef != 0);
5182 ref->senderNode = failedNodePtr.i;
5183 ref->errorCode = StopPermRef::NF_CausedAbortOfStopProcedure;
5184 sendSignal(reference(), GSN_DIH_SWITCH_REPLICA_REF, signal,
5185 DihSwitchReplicaRef::SignalLength, JBB);
5190 void Dbdih::checkStopPermProxy(
Signal* signal, NodeId failedNodeId)
5193 if(c_stopPermProxy.clientRef != 0 &&
5194 refToNode(c_stopPermProxy.masterRef) == failedNodeId){
5202 ref->senderData = c_stopPermProxy.clientData;
5203 ref->errorCode = StopPermRef::NF_CausedAbortOfStopProcedure;
5204 sendSignal(c_stopPermProxy.clientRef, GSN_STOP_PERM_REF, signal, 2, JBB);
5205 c_stopPermProxy.clientRef = 0;
5210 Dbdih::handleTakeOver(
Signal* signal, TakeOverRecordPtr takeOverPtr)
5213 switch(takeOverPtr.p->toMasterStatus){
5214 case TakeOverRecord::TO_MASTER_IDLE:
5216 releaseTakeOver(takeOverPtr);
5218 case TakeOverRecord::TO_MUTEX_BEFORE_STORED:
5225 case TakeOverRecord::TO_MUTEX_BEFORE_LOCKED:
5230 abortTakeOver(signal, takeOverPtr);
5232 case TakeOverRecord::TO_AFTER_STORED:{
5237 NodeRecordPtr nodePtr;
5238 NodeGroupRecordPtr NGPtr;
5239 nodePtr.i = takeOverPtr.p->toCopyNode;
5240 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
5241 NGPtr.i = nodePtr.p->nodeGroup;
5242 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
5244 ndbassert(NGPtr.p->activeTakeOver == takeOverPtr.p->toStartingNode);
5245 if (NGPtr.p->activeTakeOver == takeOverPtr.p->toStartingNode)
5248 NGPtr.p->activeTakeOver = 0;
5250 releaseTakeOver(takeOverPtr);
5253 case TakeOverRecord::TO_MUTEX_BEFORE_COMMIT:
5260 case TakeOverRecord::TO_MUTEX_BEFORE_SWITCH_REPLICA:
5267 case TakeOverRecord::TO_MUTEX_AFTER_SWITCH_REPLICA:
5269 abortTakeOver(signal, takeOverPtr);
5271 case TakeOverRecord::TO_WAIT_LCP:{
5276 NodeRecordPtr nodePtr;
5277 nodePtr.i = takeOverPtr.p->toStartingNode;
5278 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
5279 nodePtr.p->copyCompleted = 0;
5280 releaseTakeOver(takeOverPtr);
5284 jamLine(takeOverPtr.p->toMasterStatus);
5289 void Dbdih::failedNodeSynchHandling(
Signal* signal,
5290 NodeRecordPtr failedNodePtr)
5297 failedNodePtr.p->dbdictFailCompleted = ZFALSE;
5298 failedNodePtr.p->dbtcFailCompleted = ZFALSE;
5299 failedNodePtr.p->dbdihFailCompleted = ZFALSE;
5300 failedNodePtr.p->dblqhFailCompleted = ZFALSE;
5302 failedNodePtr.p->m_NF_COMPLETE_REP.clearWaitingFor();
5304 NodeRecordPtr nodePtr;
5305 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
5306 ptrAss(nodePtr, nodeRecord);
5307 if (nodePtr.p->nodeStatus == NodeRecord::ALIVE) {
5314 failedNodePtr.p->m_NF_COMPLETE_REP.setWaitingFor(nodePtr.i);
5317 if ((nodePtr.p->nodeStatus == NodeRecord::DYING) &&
5318 (nodePtr.p->m_NF_COMPLETE_REP.isWaitingFor(failedNodePtr.i))){
5329 nf->
nodeId = failedNodePtr.i;
5331 nf->from = __LINE__;
5332 sendSignal(reference(), GSN_NF_COMPLETEREP, signal,
5333 NFCompleteRep::SignalLength, JBB);
5337 if (failedNodePtr.p->nodeStatus == NodeRecord::DIED_NOW) {
5339 failedNodePtr.p->nodeStatus = NodeRecord::DYING;
5349 failedNodePtr.p->nodeStatus = NodeRecord::DEAD;
5358 nf->from = __LINE__;
5359 sendSignal(reference(), GSN_NF_COMPLETEREP, signal,
5360 NFCompleteRep::SignalLength, JBB);
5367 for (c_activeTakeOverList.
first(ptr); !ptr.isNull();
5368 c_activeTakeOverList.
next(ptr))
5371 if (ptr.p->toStartingNode == failedNodeId)
5381 void Dbdih::failedNodeLcpHandling(
Signal* signal, NodeRecordPtr failedNodePtr)
5384 const Uint32 nodeId = failedNodePtr.i;
5386 if (isMaster() && c_lcpState.m_participatingLQH.get(failedNodePtr.i))
5398 switch (failedNodePtr.p->activeStatus) {
5399 case Sysfile::NS_Active:
5401 failedNodePtr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
5403 case Sysfile::NS_ActiveMissed_1:
5405 failedNodePtr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
5407 case Sysfile::NS_ActiveMissed_2:
5409 failedNodePtr.p->activeStatus = Sysfile::NS_NotActive_NotTakenOver;
5411 case Sysfile::NS_TakeOver:
5413 failedNodePtr.p->activeStatus = Sysfile::NS_NotActive_NotTakenOver;
5415 case Sysfile::NS_Configured:
5419 g_eventLogger->
error(
"activeStatus = %u "
5420 "at failure after NODE_FAILREP of node = %u",
5421 (Uint32) failedNodePtr.p->activeStatus,
5428 c_lcpState.m_participatingDIH.clear(failedNodePtr.i);
5429 c_lcpState.m_participatingLQH.clear(failedNodePtr.i);
5431 bool wf = c_MASTER_LCPREQ_Counter.isWaitingFor(failedNodePtr.i);
5433 if(c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH.isWaitingFor(failedNodePtr.i))
5437 rep->nodeId = failedNodePtr.i;
5438 rep->lcpId = SYSFILE->latestLCP_ID;
5439 rep->blockNo = DBDIH;
5440 sendSignal(reference(), GSN_LCP_COMPLETE_REP, signal,
5441 LcpCompleteRep::SignalLength, JBB);
5444 bool lcp_complete_rep =
false;
5454 if(c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.isWaitingFor(nodeId)){
5457 lcp_complete_rep =
true;
5459 rep->nodeId = nodeId;
5460 rep->lcpId = SYSFILE->latestLCP_ID;
5461 rep->blockNo = DBLQH;
5462 sendSignal(reference(), GSN_LCP_COMPLETE_REP, signal,
5463 LcpCompleteRep::SignalLength, JBB);
5465 if(c_lcpState.m_LAST_LCP_FRAG_ORD.isWaitingFor(nodeId)){
5470 c_lcpState.m_LAST_LCP_FRAG_ORD.clearWaitingFor(nodeId);
5475 if (c_TCGETOPSIZEREQ_Counter.isWaitingFor(failedNodePtr.i)) {
5477 signal->theData[0] = failedNodePtr.i;
5478 signal->theData[1] = 0;
5479 sendSignal(reference(), GSN_TCGETOPSIZECONF, signal, 2, JBB);
5482 if (c_TC_CLOPSIZEREQ_Counter.isWaitingFor(failedNodePtr.i)) {
5484 signal->theData[0] = failedNodePtr.i;
5485 sendSignal(reference(), GSN_TC_CLOPSIZECONF, signal, 1, JBB);
5488 if (c_START_LCP_REQ_Counter.isWaitingFor(failedNodePtr.i)) {
5491 conf->senderRef = numberToRef(DBLQH, failedNodePtr.i);
5492 conf->lcpId = SYSFILE->latestLCP_ID;
5493 sendSignal(reference(), GSN_START_LCP_CONF, signal,
5494 StartLcpConf::SignalLength, JBB);
5498 if (c_EMPTY_LCP_REQ_Counter.isWaitingFor(failedNodePtr.i))
5502 rep->senderNodeId = failedNodePtr.i;
5504 rep->fragmentId = ~0;
5506 rep->lcpId = SYSFILE->latestLCP_ID;
5508 sendSignal(reference(), GSN_EMPTY_LCP_CONF, signal,
5509 EmptyLcpConf::SignalLength, JBB);
5511 else if (!c_EMPTY_LCP_REQ_Counter.done() && lcp_complete_rep)
5518 if (c_MASTER_LCPREQ_Counter.isWaitingFor(failedNodePtr.i)) {
5521 ref->senderNodeId = failedNodePtr.i;
5522 ref->failedNodeId = cmasterTakeOverNode;
5523 sendSignal(reference(), GSN_MASTER_LCPREF, signal,
5524 MasterLCPRef::SignalLength, JBB);
5529 void Dbdih::checkGcpOutstanding(
Signal* signal, Uint32 failedNodeId){
5530 if (c_GCP_PREPARE_Counter.isWaitingFor(failedNodeId)){
5533 conf->nodeId = failedNodeId;
5534 conf->gci_hi = Uint32(m_micro_gcp.m_master.m_new_gci >> 32);
5535 conf->gci_lo = Uint32(m_micro_gcp.m_master.m_new_gci);
5536 sendSignal(reference(), GSN_GCP_PREPARECONF, signal,
5537 GCPPrepareConf::SignalLength, JBB);
5540 if (c_GCP_COMMIT_Counter.isWaitingFor(failedNodeId))
5551 c_GCP_COMMIT_Counter.clearWaitingFor(failedNodeId);
5552 if (!c_GCP_COMMIT_Counter.isWaitingFor(getOwnNodeId()))
5556 m_micro_gcp.m_state = MicroGcp::M_GCP_COMMIT;
5560 req->senderRef = reference();
5561 req->senderData = m_micro_gcp.m_master_ref;
5562 req->gci_hi = Uint32(m_micro_gcp.m_old_gci >> 32);
5563 req->gci_lo = Uint32(m_micro_gcp.m_old_gci);
5564 sendSignal(clocaltcblockref, GSN_GCP_NOMORETRANS, signal,
5565 GCPNoMoreTrans::SignalLength, JBB);
5568 if (c_GCP_SAVEREQ_Counter.isWaitingFor(failedNodeId)) {
5571 saveRef->dihPtr = failedNodeId;
5572 saveRef->nodeId = failedNodeId;
5573 saveRef->gci = m_gcp_save.m_master.m_new_gci;
5574 saveRef->errorCode = GCPSaveRef::FakedSignalDueToNodeFailure;
5575 sendSignal(reference(), GSN_GCP_SAVEREF, signal,
5576 GCPSaveRef::SignalLength, JBB);
5579 if (c_COPY_GCIREQ_Counter.isWaitingFor(failedNodeId)) {
5581 signal->theData[0] = failedNodeId;
5582 sendSignal(reference(), GSN_COPY_GCICONF, signal, 1, JBB);
5585 if (c_MASTER_GCPREQ_Counter.isWaitingFor(failedNodeId)){
5588 ref->senderNodeId = failedNodeId;
5589 ref->failedNodeId = cmasterTakeOverNode;
5590 sendSignal(reference(), GSN_MASTER_GCPREF, signal,
5591 MasterGCPRef::SignalLength, JBB);
5594 if (c_SUB_GCP_COMPLETE_REP_Counter.isWaitingFor(failedNodeId))
5598 signal->getDataPtrSend());
5599 ack->rep.senderRef = numberToRef(DBDIH, failedNodeId);
5600 sendSignal(reference(), GSN_SUB_GCP_COMPLETE_ACK, signal,
5601 SubGcpCompleteAck::SignalLength, JBB);
5607 Dbdih::startLcpMasterTakeOver(
Signal* signal, Uint32 nodeId){
5610 Uint32 oldNode = c_lcpMasterTakeOverState.failedNodeId;
5612 c_lcpMasterTakeOverState.minTableId = ~0;
5613 c_lcpMasterTakeOverState.minFragId = ~0;
5614 c_lcpMasterTakeOverState.failedNodeId = nodeId;
5616 c_lcpMasterTakeOverState.set(LMTOS_WAIT_EMPTY_LCP, __LINE__);
5619 req->senderRef = reference();
5621 NodeRecordPtr specNodePtr;
5622 specNodePtr.i = cfirstAliveNode;
5625 ptrCheckGuard(specNodePtr, MAX_NDB_NODES, nodeRecord);
5626 if (!c_EMPTY_LCP_REQ_Counter.isWaitingFor(specNodePtr.i))
5630 if (!(ERROR_INSERTED(7209) && specNodePtr.i == getOwnNodeId()))
5632 sendEMPTY_LCP_REQ(signal, specNodePtr.i, 0);
5636 ndbout_c(
"NOT sending EMPTY_LCP_REQ to %u", specNodePtr.i);
5639 if (c_lcpState.m_LAST_LCP_FRAG_ORD.isWaitingFor(specNodePtr.i))
5642 c_lcpState.m_LAST_LCP_FRAG_ORD.clearWaitingFor();
5645 specNodePtr.i = specNodePtr.p->nextNode;
5646 }
while (specNodePtr.i != RNIL);
5649 NodeRecordPtr nodePtr;
5650 nodePtr.i = oldNode;
5651 if (oldNode > 0 && oldNode < MAX_NDB_NODES)
5654 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
5655 if (nodePtr.p->m_nodefailSteps.get(NF_LCP_TAKE_OVER))
5658 checkLocalNodefailComplete(signal, oldNode, NF_LCP_TAKE_OVER);
5662 setLocalNodefailHandling(signal, nodeId, NF_LCP_TAKE_OVER);
5665 void Dbdih::startGcpMasterTakeOver(
Signal* signal, Uint32 oldMasterId){
5680 cmasterState = MASTER_TAKE_OVER_GCP;
5681 cmasterTakeOverNode = oldMasterId;
5683 req->masterRef = reference();
5684 req->failedNodeId = oldMasterId;
5685 sendLoopMacro(MASTER_GCPREQ, sendMASTER_GCPREQ, RNIL);
5688 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 1, JBB);
5694 m_gcp_save.m_master.m_new_gci = m_gcp_save.m_gci;
5696 setLocalNodefailHandling(signal, oldMasterId, NF_GCP_TAKE_OVER);
5699 void Dbdih::startRemoveFailedNode(
Signal* signal, NodeRecordPtr failedNodePtr)
5701 Uint32 nodeId = failedNodePtr.i;
5702 if(failedNodePtr.p->nodeStatus != NodeRecord::DIED_NOW){
5707 ndbrequire(!c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.isWaitingFor(nodeId));
5721 failedNodePtr.p->m_remove_node_from_table_lcp_id = RNIL;
5722 if (c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.isWaitingFor(failedNodePtr.i))
5725 failedNodePtr.p->m_remove_node_from_table_lcp_id = SYSFILE->latestLCP_ID;
5730 if (!ERROR_INSERTED(7194) && !ERROR_INSERTED(7221))
5732 signal->theData[0] = DihContinueB::ZREMOVE_NODE_FROM_TABLE;
5733 signal->theData[1] = failedNodePtr.i;
5734 signal->theData[2] = 0;
5735 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
5739 if (ERROR_INSERTED(7194))
5741 ndbout_c(
"7194 Not starting ZREMOVE_NODE_FROM_TABLE");
5743 else if (ERROR_INSERTED(7221))
5745 ndbout_c(
"7221 Not starting ZREMOVE_NODE_FROM_TABLE");
5749 setLocalNodefailHandling(signal, failedNodePtr.i, NF_REMOVE_NODE_FROM_TABLE);
5757 void Dbdih::execMASTER_GCPREQ(
Signal* signal)
5759 NodeRecordPtr failedNodePtr;
5762 const BlockReference newMasterBlockref = masterGCPReq->masterRef;
5763 const Uint32 failedNodeId = masterGCPReq->failedNodeId;
5765 failedNodePtr.i = failedNodeId;
5766 ptrCheckGuard(failedNodePtr, MAX_NDB_NODES, nodeRecord);
5767 if (failedNodePtr.p->nodeStatus == NodeRecord::ALIVE) {
5776 sendSignalWithDelay(reference(), GSN_MASTER_GCPREQ,
5777 signal, 10, MasterGCPReq::SignalLength);
5780 ndbrequire(failedNodePtr.p->nodeStatus == NodeRecord::DYING);
5783 if (ERROR_INSERTED(7181))
5785 ndbout_c(
"execGCP_TCFINISHED in MASTER_GCPREQ");
5786 CLEAR_ERROR_INSERT_VALUE;
5787 signal->theData[0] = c_error_7181_ref;
5788 signal->theData[1] = (Uint32)(m_micro_gcp.m_old_gci >> 32);
5789 signal->theData[2] = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
5790 execGCP_TCFINISHED(signal);
5794 switch(m_micro_gcp.m_state){
5795 case MicroGcp::M_GCP_IDLE:
5797 gcpState = MasterGCPConf::GCP_READY;
5799 case MicroGcp::M_GCP_PREPARE:
5803 case MicroGcp::M_GCP_COMMIT:
5807 case MicroGcp::M_GCP_COMMITTED:
5815 m_micro_gcp.m_state = MicroGcp::M_GCP_COMMIT;
5819 req2->senderRef = reference();
5820 req2->senderData = m_micro_gcp.m_master_ref;
5821 req2->gci_hi = (Uint32)(m_micro_gcp.m_old_gci >> 32);
5822 req2->gci_lo = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
5823 sendSignal(clocaltcblockref, GSN_GCP_NOMORETRANS, signal,
5824 GCPNoMoreTrans::SignalLength, JBB);
5827 case MicroGcp::M_GCP_COMPLETE:
5835 switch(m_gcp_save.m_state){
5836 case GcpSave::GCP_SAVE_IDLE:
5838 saveState = MasterGCPConf::GCP_SAVE_IDLE;
5840 case GcpSave::GCP_SAVE_REQ:
5844 case GcpSave::GCP_SAVE_CONF:
5848 case GcpSave::GCP_SAVE_COPY_GCI:
5855 masterGCPConf->gcpState = gcpState;
5856 masterGCPConf->senderNodeId = cownNodeId;
5857 masterGCPConf->failedNodeId = failedNodeId;
5858 masterGCPConf->newGCP_hi = (Uint32)(m_micro_gcp.m_new_gci >> 32);
5859 masterGCPConf->latestLCP = SYSFILE->latestLCP_ID;
5860 masterGCPConf->oldestRestorableGCI = SYSFILE->oldestRestorableGCI;
5861 masterGCPConf->keepGCI = SYSFILE->keepGCI;
5862 masterGCPConf->newGCP_lo = Uint32(m_micro_gcp.m_new_gci);
5863 masterGCPConf->saveState = saveState;
5864 masterGCPConf->saveGCI = m_gcp_save.m_gci;
5865 for(Uint32 i = 0; i < NdbNodeBitmask::Size; i++)
5866 masterGCPConf->lcpActive[i] = SYSFILE->lcpActive[i];
5868 if (ERROR_INSERTED(7225))
5870 CLEAR_ERROR_INSERT_VALUE;
5871 ndbrequire(refToNode(newMasterBlockref) == getOwnNodeId());
5872 sendSignalWithDelay(newMasterBlockref, GSN_MASTER_GCPCONF, signal,
5873 500, MasterGCPConf::SignalLength);
5877 sendSignal(newMasterBlockref, GSN_MASTER_GCPCONF, signal,
5878 MasterGCPConf::SignalLength, JBB);
5881 if (ERROR_INSERTED(7182))
5883 ndbout_c(
"execGCP_TCFINISHED in MASTER_GCPREQ");
5884 CLEAR_ERROR_INSERT_VALUE;
5885 signal->theData[0] = c_error_7181_ref;
5886 signal->theData[1] = (Uint32)(m_micro_gcp.m_old_gci >> 32);
5887 signal->theData[2] = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
5888 execGCP_TCFINISHED(signal);
5891 if (c_copyGCISlave.m_expectedNextWord != 0)
5894 c_copyGCISlave.m_expectedNextWord = 0;
5895 c_copyGCISlave.m_copyReason = CopyGCIReq::IDLE;
5899 void Dbdih::execMASTER_GCPCONF(
Signal* signal)
5901 NodeRecordPtr senderNodePtr;
5904 senderNodePtr.i = masterGCPConf->senderNodeId;
5905 ptrCheckGuard(senderNodePtr, MAX_NDB_NODES, nodeRecord);
5910 const Uint32 failedNodeId = masterGCPConf->failedNodeId;
5911 const Uint32 newGcp_hi = masterGCPConf->newGCP_hi;
5912 const Uint32 newGcp_lo = masterGCPConf->newGCP_lo;
5913 Uint64 newGCI = newGcp_lo | (Uint64(newGcp_hi) << 32);
5914 const Uint32 latestLcpId = masterGCPConf->latestLCP;
5915 const Uint32 oldestRestorableGci = masterGCPConf->oldestRestorableGCI;
5916 const Uint32 oldestKeepGci = masterGCPConf->keepGCI;
5917 const Uint32 saveGCI = masterGCPConf->saveGCI;
5919 if (latestLcpId > SYSFILE->latestLCP_ID) {
5922 g_eventLogger->
info(
"Dbdih: Setting SYSFILE->latestLCP_ID to %d",
5924 SYSFILE->latestLCP_ID = latestLcpId;
5926 SYSFILE->keepGCI = oldestKeepGci;
5927 SYSFILE->oldestRestorableGCI = oldestRestorableGci;
5928 for(Uint32 i = 0; i < NdbNodeBitmask::Size; i++)
5929 SYSFILE->lcpActive[i] = masterGCPConf->lcpActive[i];
5934 case MasterGCPConf::GCP_READY:
5942 if (m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_IDLE)
5945 m_micro_gcp.m_master.m_state = MicroGcp::M_GCP_PREPARE;
5946 m_micro_gcp.m_master.m_new_gci = newGCI;
5951 ndbrequire(m_micro_gcp.m_master.m_new_gci == newGCI);
5959 if (m_micro_gcp.m_master.m_state != MicroGcp::M_GCP_IDLE)
5961 ndbrequire(m_micro_gcp.m_master.m_new_gci == newGCI);
5963 m_micro_gcp.m_master.m_new_gci = newGCI;
5964 m_micro_gcp.m_master.m_state = MicroGcp::M_GCP_COMMIT;
5978 ndbrequire(saveGCI == m_gcp_save.m_gci ||
5979 saveGCI == m_gcp_save.m_gci + 1 ||
5980 saveGCI + 1 == m_gcp_save.m_gci);
5981 if (saveGCI > m_gcp_save.m_master.m_new_gci)
5984 m_gcp_save.m_master.m_new_gci = saveGCI;
5987 case MasterGCPConf::GCP_SAVE_IDLE:
5992 if (m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE)
5995 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_REQ;
6000 if (m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE)
6003 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_REQ;
6008 if (m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE)
6011 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_COPY_GCI;
6022 receiveLoopMacro(MASTER_GCPREQ, senderNodePtr.i);
6027 MASTER_GCPhandling(signal, failedNodeId);
6032 void Dbdih::execMASTER_GCPREF(
Signal* signal)
6036 receiveLoopMacro(MASTER_GCPREQ, ref->senderNodeId);
6041 MASTER_GCPhandling(signal, ref->failedNodeId);
6044 void Dbdih::MASTER_GCPhandling(
Signal* signal, Uint32 failedNodeId)
6046 cmasterState = MASTER_ACTIVE;
6048 m_micro_gcp.m_master.m_start_time = 0;
6049 m_gcp_save.m_master.m_start_time = 0;
6050 if (m_gcp_monitor.m_micro_gcp.m_max_lag > 0)
6052 infoEvent(
"GCP Monitor: Computed max GCP_SAVE lag to %u seconds",
6053 m_gcp_monitor.m_gcp_save.m_max_lag / 10);
6054 infoEvent(
"GCP Monitor: Computed max GCP_COMMIT lag to %u seconds",
6055 m_gcp_monitor.m_micro_gcp.m_max_lag / 10);
6059 infoEvent(
"GCP Monitor: unlimited lags allowed");
6063 switch(m_micro_gcp.m_master.m_state){
6064 case MicroGcp::M_GCP_IDLE:
6067 signal->theData[0] = DihContinueB::ZSTART_GCP;
6068 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
6070 case MicroGcp::M_GCP_PREPARE:
6078 sendLoopMacro(GCP_PREPARE, sendGCP_PREPARE, RNIL);
6081 case MicroGcp::M_GCP_COMMIT:
6089 sendLoopMacro(GCP_COMMIT, sendGCP_COMMIT, RNIL);
6092 case MicroGcp::M_GCP_COMMITTED:
6095 case MicroGcp::M_GCP_COMPLETE:
6100 jamLine(m_micro_gcp.m_master.m_state);
6106 if (m_micro_gcp.m_enabled ==
false)
6109 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_IDLE;
6114 switch(m_gcp_save.m_master.m_state){
6115 case GcpSave::GCP_SAVE_IDLE:
6119 case GcpSave::GCP_SAVE_REQ:
6127 sendLoopMacro(GCP_SAVEREQ, sendGCP_SAVEREQ, RNIL);
6130 case GcpSave::GCP_SAVE_CONF:
6132 case GcpSave::GCP_SAVE_COPY_GCI:
6135 copyGciLab(signal, CopyGCIReq::GLOBAL_CHECKPOINT);
6136 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_COPY_GCI;
6140 jamLine(m_gcp_save.m_master.m_state);
6148 signal->theData[1] = m_micro_gcp.m_master.m_state;
6149 signal->theData[2] = m_gcp_save.m_master.m_state;
6150 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 1, JBB);
6153 Uint32(m_micro_gcp.m_current_gci >> 32),
6154 Uint32(m_micro_gcp.m_current_gci),
6155 m_micro_gcp.m_master.m_state,
6156 m_gcp_save.m_master.m_state);
6164 checkLocalNodefailComplete(signal, failedNodeId, NF_GCP_TAKE_OVER);
6166 startGcpMonitor(signal);
6172 Dbdih::invalidateNodeLCP(
Signal* signal, Uint32 nodeId, Uint32 tableId)
6175 TabRecordPtr tabPtr;
6177 const Uint32 RT_BREAK = 64;
6178 if (ERROR_INSERTED(7125)) {
6181 for (Uint32 i = 0; i<RT_BREAK; i++) {
6183 if (tabPtr.i >= ctabFileSize){
6189 if (ERROR_INSERTED(7204))
6191 CLEAR_ERROR_INSERT_VALUE;
6193 setAllowNodeStart(nodeId,
true);
6194 if (getNodeStatus(nodeId) == NodeRecord::STARTING) {
6197 conf->sendingNodeId = cownNodeId;
6198 conf->startingNodeId = nodeId;
6199 sendSignal(cmasterdihref, GSN_START_INFOCONF, signal,
6200 StartInfoConf::SignalLength, JBB);
6204 ptrAss(tabPtr, tabRecord);
6205 if (tabPtr.p->tabStatus == TabRecord::TS_ACTIVE) {
6207 invalidateNodeLCP(signal, nodeId, tabPtr);
6212 signal->theData[0] = DihContinueB::ZINVALIDATE_NODE_LCP;
6213 signal->theData[1] = nodeId;
6214 signal->theData[2] = tabPtr.i;
6215 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
6219 Dbdih::invalidateNodeLCP(
Signal* signal, Uint32 nodeId, TabRecordPtr tabPtr)
6224 if (tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE) {
6226 signal->theData[0] = DihContinueB::ZINVALIDATE_NODE_LCP;
6227 signal->theData[1] = nodeId;
6228 signal->theData[2] = tabPtr.i;
6229 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 20, 3);
6236 bool modified =
false;
6237 FragmentstorePtr fragPtr;
6238 for(Uint32 fragNo = 0; fragNo < tabPtr.p->totalfragments; fragNo++){
6240 getFragstore(tabPtr.p, fragNo, fragPtr);
6244 ReplicaRecordPtr replicaPtr;
6245 for(replicaPtr.i = fragPtr.p->oldStoredReplicas; replicaPtr.i != RNIL;
6246 replicaPtr.i = replicaPtr.p->nextReplica) {
6248 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
6249 if(replicaPtr.p->procNode == nodeId){
6258 for(
int i = 0; i < MAX_LCP_STORED; i++) {
6259 replicaPtr.p->lcpStatus[
i] = ZINVALID;
6264 replicaPtr.p->nextLcp = 0;
6265 replicaPtr.p->noCrashedReplicas = 0;
6275 tabPtr.p->tabCopyStatus = TabRecord::CS_INVALIDATE_NODE_LCP;
6276 tabPtr.p->tabUpdateState = TabRecord::US_INVALIDATE_NODE_LCP;
6277 tabPtr.p->tabRemoveNode = nodeId;
6278 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
6279 signal->theData[1] = tabPtr.i;
6280 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
6289 signal->theData[0] = DihContinueB::ZINVALIDATE_NODE_LCP;
6290 signal->theData[1] = nodeId;
6291 signal->theData[2] = tabPtr.i;
6293 if (ERROR_INSERTED(7204))
6295 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 2000, 3);
6299 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
6308 void Dbdih::removeNodeFromTables(
Signal* signal,
6309 Uint32 nodeId, Uint32 tableId)
6312 TabRecordPtr tabPtr;
6314 const Uint32 RT_BREAK = 64;
6315 for (Uint32 i = 0; i<RT_BREAK; i++) {
6317 if (tabPtr.i >= ctabFileSize){
6319 removeNodeFromTablesComplete(signal, nodeId);
6323 ptrAss(tabPtr, tabRecord);
6324 if (tabPtr.p->tabStatus == TabRecord::TS_ACTIVE) {
6326 removeNodeFromTable(signal, nodeId, tabPtr);
6331 signal->theData[0] = DihContinueB::ZREMOVE_NODE_FROM_TABLE;
6332 signal->theData[1] = nodeId;
6333 signal->theData[2] = tabPtr.i;
6334 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
6337 void Dbdih::removeNodeFromTable(
Signal* signal,
6338 Uint32 nodeId, TabRecordPtr tabPtr){
6343 if (tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE) {
6345 signal->theData[0] = DihContinueB::ZREMOVE_NODE_FROM_TABLE;
6346 signal->theData[1] = nodeId;
6347 signal->theData[2] = tabPtr.i;
6348 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 20, 3);
6352 NodeRecordPtr nodePtr;
6354 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
6355 const Uint32 lcpId = nodePtr.p->m_remove_node_from_table_lcp_id;
6360 Uint32 noOfRemovedReplicas = 0;
6361 Uint32 noOfRemovedLcpReplicas = 0;
6362 Uint32 noOfRemainingLcpReplicas = 0;
6364 const bool lcpOngoingFlag = (tabPtr.p->tabLcpStatus== TabRecord::TLS_ACTIVE);
6365 const bool unlogged = (tabPtr.p->tabStorage != TabRecord::ST_NORMAL);
6367 FragmentstorePtr fragPtr;
6368 for(Uint32 fragNo = 0; fragNo < tabPtr.p->totalfragments; fragNo++){
6370 getFragstore(tabPtr.p, fragNo, fragPtr);
6376 ReplicaRecordPtr replicaPtr;
6377 for(replicaPtr.i = fragPtr.p->storedReplicas; replicaPtr.i != RNIL;
6378 replicaPtr.i = replicaPtr.p->nextReplica) {
6381 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
6382 if(replicaPtr.p->procNode == nodeId){
6385 noOfRemovedReplicas++;
6386 removeNodeFromStored(nodeId, fragPtr, replicaPtr, unlogged);
6387 if(replicaPtr.p->lcpOngoingFlag){
6392 ndbrequire(fragPtr.p->noLcpReplicas > 0);
6393 fragPtr.p->noLcpReplicas --;
6395 noOfRemovedLcpReplicas ++;
6396 replicaPtr.p->lcpOngoingFlag =
false;
6402 Uint32 lcpNo = prevLcpNo(replicaPtr.p->nextLcp);
6403 if (replicaPtr.p->lcpStatus[lcpNo] == ZVALID &&
6404 replicaPtr.p->lcpId[lcpNo] == lcpId)
6407 replicaPtr.p->lcpStatus[lcpNo] = ZINVALID;
6408 replicaPtr.p->lcpId[lcpNo] = 0;
6409 replicaPtr.p->nextLcp = lcpNo;
6410 ndbout_c(
"REMOVING lcp: %u from table: %u frag: %u node: %u",
6411 SYSFILE->latestLCP_ID,
6412 tabPtr.i, fragNo, nodeId);
6422 updateNodeInfo(fragPtr);
6423 noOfRemainingLcpReplicas += fragPtr.p->noLcpReplicas;
6426 if (noOfRemovedReplicas == 0)
6434 signal->theData[0] = DihContinueB::ZREMOVE_NODE_FROM_TABLE;
6435 signal->theData[1] = nodeId;
6436 signal->theData[2] = tabPtr.i;
6437 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
6445 switch(tabPtr.p->tabLcpStatus){
6446 case TabRecord::TLS_COMPLETED:
6456 ndbrequire(noOfRemovedLcpReplicas == 0);
6458 tabPtr.p->tabCopyStatus = TabRecord::CS_REMOVE_NODE;
6459 tabPtr.p->tabUpdateState = TabRecord::US_REMOVE_NODE;
6460 tabPtr.p->tabRemoveNode = nodeId;
6461 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
6462 signal->theData[1] = tabPtr.i;
6463 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
6466 case TabRecord::TLS_ACTIVE:
6474 case TabRecord::TLS_WRITING_TO_FILE:
6481 ndbrequire(lcpOngoingFlag);
6491 ndbrequire(c_lcpState.lcpStatus != LCP_STATUS_IDLE);
6492 ndbrequire(tabPtr.p->tabLcpStatus == TabRecord::TLS_ACTIVE);
6497 tabPtr.p->tabCopyStatus = TabRecord::CS_REMOVE_NODE;
6498 tabPtr.p->tabUpdateState = TabRecord::US_REMOVE_NODE;
6499 tabPtr.p->tabRemoveNode = nodeId;
6500 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
6501 signal->theData[1] = tabPtr.i;
6502 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
6504 if(noOfRemainingLcpReplicas == 0){
6509 tabPtr.p->tabLcpStatus = TabRecord::TLS_WRITING_TO_FILE;
6510 checkLcpAllTablesDoneInLqh(__LINE__);
6515 Dbdih::removeNodeFromTablesComplete(
Signal* signal, Uint32 nodeId){
6521 checkLcpCompletedLab(signal);
6526 checkLocalNodefailComplete(signal, nodeId, NF_REMOVE_NODE_FROM_TABLE);
6530 Dbdih::checkLocalNodefailComplete(
Signal* signal, Uint32 failedNodeId,
6531 NodefailHandlingStep step){
6534 NodeRecordPtr nodePtr;
6535 nodePtr.i = failedNodeId;
6536 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
6538 ndbrequire(nodePtr.p->m_nodefailSteps.get(step));
6539 nodePtr.p->m_nodefailSteps.clear(step);
6541 if(nodePtr.p->m_nodefailSteps.count() > 0){
6546 if (ERROR_INSERTED(7030))
6548 g_eventLogger->
info(
"Reenable GCP_PREPARE");
6549 CLEAR_ERROR_INSERT_VALUE;
6556 nf->from = __LINE__;
6557 sendSignal(reference(), GSN_NF_COMPLETEREP, signal,
6558 NFCompleteRep::SignalLength, JBB);
6563 Dbdih::setLocalNodefailHandling(
Signal* signal, Uint32 failedNodeId,
6564 NodefailHandlingStep step){
6567 NodeRecordPtr nodePtr;
6568 nodePtr.i = failedNodeId;
6569 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
6571 ndbrequire(!nodePtr.p->m_nodefailSteps.get(step));
6572 nodePtr.p->m_nodefailSteps.set(step);
6575 void Dbdih::startLcpTakeOverLab(
Signal* signal, Uint32 failedNodeId)
6590 Dbdih::execEMPTY_LCP_REP(
Signal* signal)
6595 Uint32 len = signal->getLength();
6596 ndbrequire(len > EmptyLcpRep::SignalLength);
6597 len -= EmptyLcpRep::SignalLength;
6600 nodes.
assign(NdbNodeBitmask::Size, rep->receiverGroup);
6602 memmove(signal->getDataPtrSend(),
6603 signal->getDataPtr()+EmptyLcpRep::SignalLength, 4*len);
6605 sendSignal(rg, GSN_EMPTY_LCP_CONF, signal, len, JBB);
6608 void Dbdih::execEMPTY_LCP_CONF(
Signal* signal)
6612 ndbrequire(c_lcpMasterTakeOverState.state == LMTOS_WAIT_EMPTY_LCP);
6615 Uint32 nodeId = conf->senderNodeId;
6617 CRASH_INSERTION(7206);
6622 if (conf->tableId < c_lcpMasterTakeOverState.minTableId) {
6624 c_lcpMasterTakeOverState.minTableId = conf->tableId;
6625 c_lcpMasterTakeOverState.minFragId = conf->fragmentId;
6626 }
else if (conf->tableId == c_lcpMasterTakeOverState.minTableId &&
6627 conf->fragmentId < c_lcpMasterTakeOverState.minFragId) {
6629 c_lcpMasterTakeOverState.minFragId = conf->fragmentId;
6633 c_lcpState.m_LAST_LCP_FRAG_ORD.setWaitingFor(nodeId);
6637 receiveLoopMacro(EMPTY_LCP_REQ, nodeId);
6642 c_lcpMasterTakeOverState.set(LMTOS_WAIT_LCP_FRAG_REP, __LINE__);
6643 checkEmptyLcpComplete(signal);
6648 Dbdih::checkEmptyLcpComplete(
Signal *signal){
6650 ndbrequire(c_lcpMasterTakeOverState.state == LMTOS_WAIT_LCP_FRAG_REP);
6652 if(c_lcpState.noOfLcpFragRepOutstanding > 0){
6661 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 1, JBB);
6663 signal->theData[0] = 7012;
6664 execDUMP_STATE_ORD(signal);
6666 if (ERROR_INSERTED(7194))
6668 ndbout_c(
"7194 starting ZREMOVE_NODE_FROM_TABLE");
6669 signal->theData[0] = DihContinueB::ZREMOVE_NODE_FROM_TABLE;
6670 signal->theData[1] = c_lcpMasterTakeOverState.failedNodeId;
6671 signal->theData[2] = 0;
6672 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
6675 c_current_time = NdbTick_CurrentMillisecond();
6676 c_lcpState.m_start_time = c_current_time;
6677 c_lcpMasterTakeOverState.set(LMTOS_INITIAL, __LINE__);
6679 req->masterRef = reference();
6680 req->failedNodeId = c_lcpMasterTakeOverState.failedNodeId;
6681 sendLoopMacro(MASTER_LCPREQ, sendMASTER_LCPREQ, RNIL);
6684 sendMASTER_LCPCONF(signal);
6693 void Dbdih::execMASTER_LCPREQ(
Signal* signal)
6697 const BlockReference newMasterBlockref = req->masterRef;
6699 CRASH_INSERTION(7205);
6701 if (ERROR_INSERTED(7207))
6704 SET_ERROR_INSERT_VALUE(7208);
6705 sendSignalWithDelay(reference(), GSN_MASTER_LCPREQ, signal,
6706 500, signal->getLength());
6710 if (ERROR_INSERTED(7208))
6713 signal->theData[0] = 9999;
6714 sendSignal(numberToRef(CMVMI, refToNode(newMasterBlockref)),
6715 GSN_NDB_TAMPER, signal, 1, JBB);
6718 if (newMasterBlockref != cmasterdihref)
6721 ndbout_c(
"resending GSN_MASTER_LCPREQ");
6722 sendSignalWithDelay(reference(), GSN_MASTER_LCPREQ, signal,
6723 50, signal->getLength());
6726 Uint32 failedNodeId = req->failedNodeId;
6731 ndbrequire(c_lcpState.m_masterLcpDihRef != newMasterBlockref);
6732 c_lcpState.m_masterLcpDihRef = newMasterBlockref;
6733 c_lcpState.m_MASTER_LCPREQ_Received =
true;
6734 c_lcpState.m_MASTER_LCPREQ_FailedNodeId = failedNodeId;
6736 if(newMasterBlockref != cmasterdihref){
6741 if (ERROR_INSERTED(7209))
6743 SET_ERROR_INSERT_VALUE(7210);
6746 sendMASTER_LCPCONF(signal);
6750 Dbdih::sendMASTER_LCPCONF(
Signal * signal){
6752 if(!c_EMPTY_LCP_REQ_Counter.done()){
6761 if(!c_lcpState.m_MASTER_LCPREQ_Received){
6769 if(c_lcpState.lcpStatus == LCP_INIT_TABLES){
6777 if(c_lcpState.lcpStatus == LCP_COPY_GCI)
6784 SYSFILE->latestLCP_ID--;
6785 Sysfile::clearLCPOngoing(SYSFILE->systemRestartBits);
6786 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
6788 if(c_copyGCISlave.m_copyReason == CopyGCIReq::LOCAL_CHECKPOINT){
6789 g_eventLogger->
info(
"Dbdih: Also resetting c_copyGCISlave");
6790 c_copyGCISlave.m_copyReason = CopyGCIReq::IDLE;
6791 c_copyGCISlave.m_expectedNextWord = 0;
6796 MasterLCPConf::State lcpState;
6797 switch (c_lcpState.lcpStatus) {
6798 case LCP_STATUS_IDLE:
6806 lcpState = MasterLCPConf::LCP_STATUS_IDLE;
6808 case LCP_STATUS_ACTIVE:
6814 lcpState = MasterLCPConf::LCP_STATUS_ACTIVE;
6816 case LCP_TAB_COMPLETED:
6823 lcpState = MasterLCPConf::LCP_TAB_COMPLETED;
6833 lcpState = MasterLCPConf::LCP_TAB_SAVED;
6836 case LCP_CALCULATE_KEEP_GCI:
6837 case LCP_TC_CLOPSIZE:
6838 case LCP_START_LCP_ROUND:
6845 lcpState= MasterLCPConf::LCP_STATUS_IDLE;
6848 case LCP_INIT_TABLES:
6853 lcpState= MasterLCPConf::LCP_STATUS_IDLE;
6857 lcpState= MasterLCPConf::LCP_STATUS_IDLE;
6860 Uint32 failedNodeId = c_lcpState.m_MASTER_LCPREQ_FailedNodeId;
6862 conf->senderNodeId = cownNodeId;
6863 conf->lcpState = lcpState;
6864 conf->failedNodeId = failedNodeId;
6865 sendSignal(c_lcpState.m_masterLcpDihRef, GSN_MASTER_LCPCONF,
6866 signal, MasterLCPConf::SignalLength, JBB);
6870 c_lcpState.m_MASTER_LCPREQ_Received =
false;
6872 if(c_lcpState.lcpStatus == LCP_TAB_SAVED){
6874 g_eventLogger->
info(
"Sending extra GSN_LCP_COMPLETE_REP to new master");
6876 sendLCP_COMPLETE_REP(signal);
6880 c_lcpMasterTakeOverState.set(LMTOS_IDLE, __LINE__);
6881 checkLocalNodefailComplete(signal, failedNodeId, NF_LCP_TAKE_OVER);
6888 operator<<(NdbOut& out,
const Dbdih::LcpMasterTakeOverState state){
6890 case Dbdih::LMTOS_IDLE:
6891 out <<
"LMTOS_IDLE";
6893 case Dbdih::LMTOS_WAIT_EMPTY_LCP:
6894 out <<
"LMTOS_WAIT_EMPTY_LCP";
6896 case Dbdih::LMTOS_WAIT_LCP_FRAG_REP:
6897 out <<
"LMTOS_WAIT_EMPTY_LCP";
6899 case Dbdih::LMTOS_INITIAL:
6900 out <<
"LMTOS_INITIAL";
6902 case Dbdih::LMTOS_ALL_IDLE:
6903 out <<
"LMTOS_ALL_IDLE";
6905 case Dbdih::LMTOS_ALL_ACTIVE:
6906 out <<
"LMTOS_ALL_ACTIVE";
6908 case Dbdih::LMTOS_LCP_CONCLUDING:
6909 out <<
"LMTOS_LCP_CONCLUDING";
6911 case Dbdih::LMTOS_COPY_ONGOING:
6912 out <<
"LMTOS_COPY_ONGOING";
6919 Dbdih::LcpMasterTakeOverState CurrentState;
6920 MasterLCPConf::State ParticipantState;
6921 Dbdih::LcpMasterTakeOverState NewState;
6929 { Dbdih::LMTOS_INITIAL,
6930 MasterLCPConf::LCP_STATUS_IDLE,
6931 Dbdih::LMTOS_ALL_IDLE },
6933 { Dbdih::LMTOS_INITIAL,
6934 MasterLCPConf::LCP_STATUS_ACTIVE,
6935 Dbdih::LMTOS_ALL_ACTIVE },
6937 { Dbdih::LMTOS_INITIAL,
6938 MasterLCPConf::LCP_TAB_COMPLETED,
6939 Dbdih::LMTOS_LCP_CONCLUDING },
6941 { Dbdih::LMTOS_INITIAL,
6942 MasterLCPConf::LCP_TAB_SAVED,
6943 Dbdih::LMTOS_LCP_CONCLUDING },
6948 { Dbdih::LMTOS_ALL_IDLE,
6949 MasterLCPConf::LCP_STATUS_IDLE,
6950 Dbdih::LMTOS_ALL_IDLE },
6952 { Dbdih::LMTOS_ALL_IDLE,
6953 MasterLCPConf::LCP_STATUS_ACTIVE,
6954 Dbdih::LMTOS_COPY_ONGOING },
6956 { Dbdih::LMTOS_ALL_IDLE,
6957 MasterLCPConf::LCP_TAB_COMPLETED,
6958 Dbdih::LMTOS_LCP_CONCLUDING },
6960 { Dbdih::LMTOS_ALL_IDLE,
6961 MasterLCPConf::LCP_TAB_SAVED,
6962 Dbdih::LMTOS_LCP_CONCLUDING },
6967 { Dbdih::LMTOS_COPY_ONGOING,
6968 MasterLCPConf::LCP_STATUS_IDLE,
6969 Dbdih::LMTOS_COPY_ONGOING },
6971 { Dbdih::LMTOS_COPY_ONGOING,
6972 MasterLCPConf::LCP_STATUS_ACTIVE,
6973 Dbdih::LMTOS_COPY_ONGOING },
6978 { Dbdih::LMTOS_ALL_ACTIVE,
6979 MasterLCPConf::LCP_STATUS_IDLE,
6980 Dbdih::LMTOS_COPY_ONGOING },
6982 { Dbdih::LMTOS_ALL_ACTIVE,
6983 MasterLCPConf::LCP_STATUS_ACTIVE,
6984 Dbdih::LMTOS_ALL_ACTIVE },
6986 { Dbdih::LMTOS_ALL_ACTIVE,
6987 MasterLCPConf::LCP_TAB_COMPLETED,
6988 Dbdih::LMTOS_LCP_CONCLUDING },
6990 { Dbdih::LMTOS_ALL_ACTIVE,
6991 MasterLCPConf::LCP_TAB_SAVED,
6992 Dbdih::LMTOS_LCP_CONCLUDING },
6997 { Dbdih::LMTOS_LCP_CONCLUDING,
6998 MasterLCPConf::LCP_STATUS_IDLE,
6999 Dbdih::LMTOS_LCP_CONCLUDING },
7001 { Dbdih::LMTOS_LCP_CONCLUDING,
7002 MasterLCPConf::LCP_STATUS_ACTIVE,
7003 Dbdih::LMTOS_LCP_CONCLUDING },
7005 { Dbdih::LMTOS_LCP_CONCLUDING,
7006 MasterLCPConf::LCP_TAB_COMPLETED,
7007 Dbdih::LMTOS_LCP_CONCLUDING },
7009 { Dbdih::LMTOS_LCP_CONCLUDING,
7010 MasterLCPConf::LCP_TAB_SAVED,
7011 Dbdih::LMTOS_LCP_CONCLUDING }
7014 const Uint32 g_masterLCPTakeoverStateTransitionsRows =
7017 void Dbdih::execMASTER_LCPCONF(
Signal* signal)
7022 if (ERROR_INSERTED(7194))
7024 ndbout_c(
"delaying MASTER_LCPCONF due to error 7194");
7025 sendSignalWithDelay(reference(), GSN_MASTER_LCPCONF, signal,
7026 300, signal->getLength());
7030 Uint32 senderNodeId = conf->senderNodeId;
7031 MasterLCPConf::State lcpState = (MasterLCPConf::State)conf->lcpState;
7032 const Uint32 failedNodeId = conf->failedNodeId;
7033 NodeRecordPtr nodePtr;
7034 nodePtr.i = senderNodeId;
7035 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
7036 nodePtr.p->lcpStateAtTakeOver = lcpState;
7038 CRASH_INSERTION(7180);
7041 g_eventLogger->
info(
"MASTER_LCPCONF");
7042 printMASTER_LCP_CONF(stdout, &signal->theData[0], 0, 0);
7046 for(Uint32 i = 0; i<g_masterLCPTakeoverStateTransitionsRows; i++){
7048 &g_masterLCPTakeoverStateTransitions[
i];
7050 if(valid->CurrentState == c_lcpMasterTakeOverState.state &&
7051 valid->ParticipantState == lcpState){
7054 c_lcpMasterTakeOverState.set(valid->NewState, __LINE__);
7062 case MasterLCPConf::LCP_STATUS_IDLE:
7065 case MasterLCPConf::LCP_STATUS_ACTIVE:
7066 case MasterLCPConf::LCP_TAB_COMPLETED:
7067 case MasterLCPConf::LCP_TAB_SAVED:
7069 c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH.setWaitingFor(nodePtr.i);
7074 receiveLoopMacro(MASTER_LCPREQ, senderNodeId);
7079 MASTER_LCPhandling(signal, failedNodeId);
7082 void Dbdih::execMASTER_LCPREF(
Signal* signal)
7087 Uint32 senderNodeId = ref->senderNodeId;
7088 Uint32 failedNodeId = ref->failedNodeId;
7090 if (c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.isWaitingFor(senderNodeId))
7093 c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.clearWaitingFor(senderNodeId);
7096 receiveLoopMacro(MASTER_LCPREQ, senderNodeId);
7101 MASTER_LCPhandling(signal, failedNodeId);
7104 void Dbdih::MASTER_LCPhandling(
Signal* signal, Uint32 failedNodeId)
7112 c_lcpState.currentFragment.tableId = c_lcpMasterTakeOverState.minTableId;
7113 c_lcpState.currentFragment.fragmentId = c_lcpMasterTakeOverState.minFragId;
7114 c_lcpState.m_LAST_LCP_FRAG_ORD = c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH;
7116 NodeRecordPtr failedNodePtr;
7117 failedNodePtr.i = failedNodeId;
7118 ptrCheckGuard(failedNodePtr, MAX_NDB_NODES, nodeRecord);
7120 switch (c_lcpMasterTakeOverState.state) {
7121 case LMTOS_ALL_IDLE:
7128 g_eventLogger->
info(
"MASTER_LCPhandling:: LMTOS_ALL_IDLE -> checkLcpStart");
7130 checkLcpStart(signal, __LINE__);
7132 case LMTOS_COPY_ONGOING:
7139 g_eventLogger->
info(
"MASTER_LCPhandling:: LMTOS_COPY_ONGOING -> storeNewLcpId");
7141 if (c_lcpState.lcpStatus == LCP_STATUS_ACTIVE) {
7148 Uint32 lcpId = SYSFILE->latestLCP_ID;
7150 g_eventLogger->
info(
"Decreasing latestLCP_ID from %d to %d", lcpId, lcpId - 1);
7152 SYSFILE->latestLCP_ID--;
7156 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
7157 Callback c = { safe_cast(&Dbdih::lcpFragmentMutex_locked), 0 };
7158 ndbrequire(mutex.lock(c,
false));
7161 case LMTOS_ALL_ACTIVE:
7172 g_eventLogger->
info(
"MASTER_LCPhandling:: LMTOS_ALL_ACTIVE -> "
7173 "startLcpRoundLoopLab(table=%u, fragment=%u)",
7174 c_lcpMasterTakeOverState.minTableId,
7175 c_lcpMasterTakeOverState.minFragId);
7178 c_lcpState.keepGci = SYSFILE->keepGCI;
7183 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
7185 { safe_cast(&Dbdih::master_lcp_fragmentMutex_locked), failedNodePtr.i };
7186 ndbrequire(mutex.lock(c,
false));
7189 case LMTOS_LCP_CONCLUDING:
7198 ndbrequire(c_lcpState.lcpStatus != LCP_STATUS_IDLE);
7203 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
7205 { safe_cast(&Dbdih::master_lcp_fragmentMutex_locked), failedNodePtr.i };
7206 ndbrequire(mutex.lock(c,
false));
7214 signal->theData[1] = c_lcpMasterTakeOverState.state;
7215 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
7217 signal->theData[0] = 7012;
7218 execDUMP_STATE_ORD(signal);
7220 c_lcpMasterTakeOverState.set(LMTOS_IDLE, __LINE__);
7222 checkLocalNodefailComplete(signal, failedNodePtr.i, NF_LCP_TAKE_OVER);
7228 void Dbdih::execNF_COMPLETEREP(
Signal* signal)
7230 NodeRecordPtr failedNodePtr;
7233 const Uint32 blockNo = nfCompleteRep->
blockNo;
7234 Uint32 nodeId = nfCompleteRep->
nodeId;
7237 ptrCheckGuard(failedNodePtr, MAX_NDB_NODES, nodeRecord);
7241 ndbrequire(failedNodePtr.p->dbtcFailCompleted == ZFALSE);
7246 signal->theData[1] = DBTC;
7247 signal->theData[2] = failedNodePtr.i;
7248 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 3, JBB);
7250 failedNodePtr.p->dbtcFailCompleted = ZTRUE;
7254 ndbrequire(failedNodePtr.p->dbdictFailCompleted == ZFALSE);
7259 signal->theData[1] = DBDICT;
7260 signal->theData[2] = failedNodePtr.i;
7261 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 3, JBB);
7263 failedNodePtr.p->dbdictFailCompleted = ZTRUE;
7267 ndbrequire(failedNodePtr.p->dbdihFailCompleted == ZFALSE);
7272 signal->theData[1] = DBDIH;
7273 signal->theData[2] = failedNodePtr.i;
7274 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 3, JBB);
7276 failedNodePtr.p->dbdihFailCompleted = ZTRUE;
7280 ndbrequire(failedNodePtr.p->dblqhFailCompleted == ZFALSE);
7285 signal->theData[1] = DBLQH;
7286 signal->theData[2] = failedNodePtr.i;
7287 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 3, JBB);
7289 failedNodePtr.p->dblqhFailCompleted = ZTRUE;
7293 ndbrequire(nodeId < MAX_NDB_NODES);
7295 if (failedNodePtr.p->recNODE_FAILREP == ZFALSE) {
7304 sendSignalWithDelay(reference(), GSN_NF_COMPLETEREP, signal, 10,
7309 if (!failedNodePtr.p->m_NF_COMPLETE_REP.isWaitingFor(nodeId)){
7314 failedNodePtr.p->m_NF_COMPLETE_REP.clearWaitingFor(nodeId);;
7320 signal->theData[1] = 0;
7321 signal->theData[2] = failedNodePtr.i;
7322 signal->theData[3] = nodeId;
7323 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 4, JBB);
7325 nodeFailCompletedCheckLab(signal, failedNodePtr);
7333 if (failedNodePtr.p->dbtcFailCompleted == ZFALSE) {
7337 if (failedNodePtr.p->dbdictFailCompleted == ZFALSE) {
7341 if (failedNodePtr.p->dbdihFailCompleted == ZFALSE) {
7345 if (failedNodePtr.p->dblqhFailCompleted == ZFALSE) {
7353 NodeRecordPtr nodePtr;
7354 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
7356 ptrAss(nodePtr, nodeRecord);
7357 if (nodePtr.p->nodeStatus == NodeRecord::ALIVE) {
7359 BlockReference ref = calcDihBlockRef(nodePtr.i);
7364 nf->from = __LINE__;
7365 sendSignal(ref, GSN_NF_COMPLETEREP, signal,
7366 NFCompleteRep::SignalLength, JBB);
7372 void Dbdih::nodeFailCompletedCheckLab(
Signal* signal,
7373 NodeRecordPtr failedNodePtr)
7376 if (!failedNodePtr.p->m_NF_COMPLETE_REP.done()){
7386 failedNodePtr.p->nodeStatus = NodeRecord::DEAD;
7387 failedNodePtr.p->recNODE_FAILREP = ZFALSE;
7393 signal->theData[1] = 0;
7394 signal->theData[2] = failedNodePtr.i;
7395 signal->theData[3] = 0;
7396 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 4, JBB);
7401 signal->theData[0] = failedNodePtr.i;
7402 sendSignal(QMGR_REF, GSN_NDB_FAILCONF, signal, 1, JBB);
7426 static inline void inc_node_or_group(Uint32 &node, Uint32 max_node)
7428 Uint32 next = node + 1;
7429 node = (next == max_node ? 0 : next);
7435 static void set_default_node_groups(
Signal *signal, Uint32 noFrags)
7437 Uint16 *node_group_array = (Uint16*)&signal->theData[25];
7439 node_group_array[0] = 0;
7440 for (i = 1; i < noFrags; i++)
7441 node_group_array[i] = NDB_UNDEF_NODEGROUP;
7444 static Uint32 find_min_index(
const Uint32* array, Uint32 cnt)
7447 Uint32 mv = array[0];
7448 for (Uint32 i = 1; i<cnt; i++)
7459 void Dbdih::execCREATE_FRAGMENTATION_REQ(
Signal * signal)
7461 Uint16 node_group_id[MAX_NDB_PARTITIONS];
7466 const Uint32 senderRef = req->senderRef;
7467 const Uint32 senderData = req->senderData;
7468 Uint32 noOfFragments = req->noOfFragments;
7469 const Uint32 fragType = req->fragmentationType;
7470 const Uint32 primaryTableId = req->primaryTableId;
7471 const Uint32 map_ptr_i = req->map_ptr_i;
7472 const Uint32
flags = req->requestInfo;
7475 const Uint32 defaultFragments =
7476 c_fragments_per_node * cnoOfNodeGroups * cnoReplicas;
7479 NodeGroupRecordPtr NGPtr;
7480 TabRecordPtr primTabPtr;
7482 Uint16 noOfReplicas = cnoReplicas;
7483 Uint16 *fragments = (Uint16*)(signal->theData+25);
7484 if (primaryTableId == RNIL) {
7486 switch ((DictTabInfo::FragmentType)fragType){
7490 case DictTabInfo::AllNodesSmallTable:
7492 noOfFragments = defaultFragments;
7493 set_default_node_groups(signal, noOfFragments);
7495 case DictTabInfo::AllNodesMediumTable:
7497 noOfFragments = 2 * defaultFragments;
7498 set_default_node_groups(signal, noOfFragments);
7500 case DictTabInfo::AllNodesLargeTable:
7502 noOfFragments = 4 * defaultFragments;
7503 set_default_node_groups(signal, noOfFragments);
7505 case DictTabInfo::SingleFragment:
7508 set_default_node_groups(signal, noOfFragments);
7510 case DictTabInfo::DistrKeyHash:
7512 case DictTabInfo::DistrKeyLin:
7514 if (noOfFragments == 0)
7517 noOfFragments = defaultFragments;
7518 set_default_node_groups(signal, noOfFragments);
7521 case DictTabInfo::HashMapPartition:
7524 ndbrequire(map_ptr_i != RNIL);
7526 g_hash_map.getPtr(ptr, map_ptr_i);
7527 if (noOfFragments == 0)
7530 noOfFragments = ptr.p->m_fragments;
7532 else if (noOfFragments != ptr.p->m_fragments)
7535 err = CreateFragmentationRef::InvalidFragmentationType;
7538 set_default_node_groups(signal, noOfFragments);
7543 if (noOfFragments == 0)
7546 err = CreateFragmentationRef::InvalidFragmentationType;
7556 memcpy(&node_group_id[0], &signal->theData[25], 2 * noOfFragments);
7557 Uint16 next_replica_node[MAX_NDB_NODES];
7558 memset(next_replica_node,0,
sizeof(next_replica_node));
7559 Uint32 default_node_group= c_nextNodeGroup;
7560 for(Uint32 fragNo = 0; fragNo < noOfFragments; fragNo++)
7563 NGPtr.i = node_group_id[fragNo];
7564 if (NGPtr.i == NDB_UNDEF_NODEGROUP)
7567 NGPtr.i = c_node_groups[default_node_group];
7569 if (NGPtr.i >= MAX_NDB_NODES)
7572 err = CreateFragmentationRef::InvalidNodeGroup;
7575 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
7576 if (NGPtr.p->nodegroupIndex == RNIL)
7579 err = CreateFragmentationRef::InvalidNodeGroup;
7582 const Uint32 max = NGPtr.p->nodeCount;
7584 fragments[count++] = (NGPtr.p->m_next_log_part++ / cnoReplicas);
7585 Uint32 tmp= next_replica_node[NGPtr.i];
7586 for(Uint32 replicaNo = 0; replicaNo < noOfReplicas; replicaNo++)
7589 const Uint16 nodeId = NGPtr.p->nodesInGroup[tmp];
7590 fragments[count++]= nodeId;
7591 inc_node_or_group(tmp, max);
7593 inc_node_or_group(tmp, max);
7594 next_replica_node[NGPtr.i]= tmp;
7599 inc_node_or_group(default_node_group, cnoOfNodeGroups);
7609 c_nextNodeGroup = default_node_group;
7612 if (primaryTableId >= ctabFileSize) {
7614 err = CreateFragmentationRef::InvalidPrimaryTable;
7617 primTabPtr.i = primaryTableId;
7618 ptrAss(primTabPtr, tabRecord);
7619 if (primTabPtr.p->tabStatus != TabRecord::TS_ACTIVE) {
7621 err = CreateFragmentationRef::InvalidPrimaryTable;
7624 Uint32 fragments_per_node[MAX_NDB_NODES];
7625 bzero(fragments_per_node,
sizeof(fragments_per_node));
7626 for (Uint32 fragNo = 0; fragNo < primTabPtr.p->totalfragments; fragNo++) {
7628 FragmentstorePtr fragPtr;
7629 ReplicaRecordPtr replicaPtr;
7630 getFragstore(primTabPtr.p, fragNo, fragPtr);
7631 fragments[count++] = fragPtr.p->m_log_part_id;
7632 fragments[count++] = fragPtr.p->preferredPrimary;
7633 fragments_per_node[fragPtr.p->preferredPrimary]++;
7634 for (replicaPtr.i = fragPtr.p->storedReplicas;
7635 replicaPtr.i != RNIL;
7636 replicaPtr.i = replicaPtr.p->nextReplica) {
7638 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
7639 if (replicaPtr.p->procNode != fragPtr.p->preferredPrimary) {
7641 fragments[count++]= replicaPtr.p->procNode;
7644 for (replicaPtr.i = fragPtr.p->oldStoredReplicas;
7645 replicaPtr.i != RNIL;
7646 replicaPtr.i = replicaPtr.p->nextReplica) {
7648 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
7649 if (replicaPtr.p->procNode != fragPtr.p->preferredPrimary) {
7651 fragments[count++]= replicaPtr.p->procNode;
7656 if (flags & CreateFragmentationReq::RI_GET_FRAGMENTATION)
7659 noOfFragments = primTabPtr.p->totalfragments;
7661 else if (flags & CreateFragmentationReq::RI_ADD_PARTITION)
7668 for (Uint32 i = 0; i<MAX_NDB_NODES; i++)
7670 if (getNodeStatus(i) == NodeRecord::NOT_IN_CLUSTER ||
7671 getNodeGroup(i) >= cnoOfNodeGroups)
7674 ndbassert(fragments_per_node[i] == 0);
7675 fragments_per_node[
i] = ~(Uint32)0;
7678 for (Uint32 i = primTabPtr.p->totalfragments; i<noOfFragments; i++)
7681 Uint32 node = find_min_index(fragments_per_node,
7682 NDB_ARRAY_SIZE(fragments_per_node));
7683 NGPtr.i = getNodeGroup(node);
7684 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
7685 fragments[count++] = NGPtr.p->m_next_log_part++;
7686 fragments[count++] = node;
7687 fragments_per_node[node]++;
7688 for (Uint32 r = 0; r<noOfReplicas; r++)
7691 if (NGPtr.p->nodesInGroup[r] != node)
7694 fragments[count++] = NGPtr.p->nodesInGroup[r];
7700 if(count != (2
U + (1 + noOfReplicas) * noOfFragments)){
7703 "Illegal configuration change: NoOfReplicas."
7704 " Can't be applied online ");
7705 progError(__LINE__, NDBD_EXIT_INVALID_CONFIG, buf);
7710 conf->senderRef = reference();
7711 conf->senderData = senderData;
7712 conf->noOfReplicas = (Uint32)noOfReplicas;
7713 conf->noOfFragments = (Uint32)noOfFragments;
7715 fragments[0]= noOfReplicas;
7716 fragments[1]= noOfFragments;
7722 ptr[0].p = (Uint32*)&fragments[0];
7723 ptr[0].sz = (count + 1) / 2;
7724 sendSignal(senderRef,
7725 GSN_CREATE_FRAGMENTATION_CONF,
7727 CreateFragmentationConf::SignalLength,
7733 signal->theData[0] = 0;
7737 signal->theData[0] = err;
7740 void Dbdih::execDIADDTABREQ(
Signal* signal)
7748 ndbrequire(cfirstconnect != RNIL);
7749 ConnectRecordPtr connectPtr;
7750 connectPtr.i = cfirstconnect;
7751 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
7752 cfirstconnect = connectPtr.p->nextPool;
7754 const Uint32 userPtr = req->connectPtr;
7755 const BlockReference userRef = signal->getSendersBlockRef();
7756 connectPtr.p->nextPool = RNIL;
7757 connectPtr.p->userpointer = userPtr;
7758 connectPtr.p->userblockref = userRef;
7759 connectPtr.p->connectState = ConnectRecord::INUSE;
7760 connectPtr.p->table = req->tableId;
7761 connectPtr.p->m_alter.m_changeMask = 0;
7762 connectPtr.p->m_create.m_map_ptr_i = req->hashMapPtrI;
7764 TabRecordPtr tabPtr;
7765 tabPtr.i = req->tableId;
7766 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
7767 tabPtr.p->connectrec = connectPtr.i;
7768 tabPtr.p->tableType = req->tableType;
7769 fragType= req->fragType;
7770 tabPtr.p->schemaVersion = req->schemaVersion;
7771 tabPtr.p->primaryTableId = req->primaryTableId;
7772 tabPtr.p->schemaTransId = req->schemaTransId;
7773 tabPtr.p->m_scan_count[0] = 0;
7774 tabPtr.p->m_scan_count[1] = 0;
7775 tabPtr.p->m_scan_reorg_flag = 0;
7777 if (tabPtr.p->tabStatus == TabRecord::TS_ACTIVE)
7780 tabPtr.p->tabStatus = TabRecord::TS_CREATING;
7781 connectPtr.p->m_alter.m_totalfragments = tabPtr.p->totalfragments;
7782 sendAddFragreq(signal, connectPtr, tabPtr, 0);
7787 tabPtr.p->tabStatus == TabRecord::TS_IDLE)
7791 ndbrequire(cmasterNodeId == getOwnNodeId());
7792 tabPtr.p->tabStatus = TabRecord::TS_CREATING;
7794 initTableFile(tabPtr);
7795 FileRecordPtr filePtr;
7796 filePtr.i = tabPtr.p->tabFile[0];
7797 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
7798 openFileRw(signal, filePtr);
7799 filePtr.p->reqStatus = FileRecord::OPENING_TABLE;
7811 tabPtr.p->tabStatus = TabRecord::TS_CREATING;
7812 if(req->loggedTable)
7813 tabPtr.p->tabStorage= TabRecord::ST_NORMAL;
7814 else if(req->temporaryTable)
7815 tabPtr.p->tabStorage= TabRecord::ST_TEMPORARY;
7817 tabPtr.p->tabStorage= TabRecord::ST_NOLOGGING;
7818 tabPtr.p->kvalue = req->kValue;
7820 switch ((DictTabInfo::FragmentType)fragType){
7821 case DictTabInfo::HashMapPartition:
7822 tabPtr.p->method = TabRecord::HASH_MAP;
7824 case DictTabInfo::AllNodesSmallTable:
7825 case DictTabInfo::AllNodesMediumTable:
7826 case DictTabInfo::AllNodesLargeTable:
7827 case DictTabInfo::SingleFragment:
7829 case DictTabInfo::DistrKeyLin:
7831 tabPtr.p->method = TabRecord::LINEAR_HASH;
7833 case DictTabInfo::DistrKeyHash:
7835 tabPtr.p->method = TabRecord::NORMAL_HASH;
7837 case DictTabInfo::DistrKeyOrderedIndex:
7839 TabRecordPtr primTabPtr;
7840 primTabPtr.i = req->primaryTableId;
7841 ptrCheckGuard(primTabPtr, ctabFileSize, tabRecord);
7842 tabPtr.p->method = primTabPtr.p->method;
7843 req->hashMapPtrI = primTabPtr.p->m_map_ptr_i;
7846 case DictTabInfo::UserDefined:
7848 tabPtr.p->method = TabRecord::USER_DEFINED;
7855 Uint16 fragments[2 + MAX_FRAG_PER_NODE*MAX_REPLICAS*MAX_NDB_NODES];
7861 ndbrequire(handle.getSection(fragDataPtr, DiAddTabReq::FRAGMENTATION));
7862 copy((Uint32*)fragments, fragDataPtr);
7863 releaseSections(handle);
7865 const Uint32 noReplicas = fragments[0];
7866 const Uint32 noFragments = fragments[1];
7868 tabPtr.p->noOfBackups = noReplicas - 1;
7869 tabPtr.p->totalfragments = noFragments;
7870 ndbrequire(noReplicas == cnoReplicas);
7872 if (ERROR_INSERTED(7173)) {
7873 CLEAR_ERROR_INSERT_VALUE;
7874 addtabrefuseLab(signal, connectPtr, ZREPLERROR1);
7877 if ((noReplicas * noFragments) > cnoFreeReplicaRec) {
7879 addtabrefuseLab(signal, connectPtr, ZREPLERROR1);
7882 if (noFragments > cremainingfrags) {
7884 addtabrefuseLab(signal, connectPtr, ZREPLERROR2);
7888 Uint32 logTotalFragments = 1;
7889 while (logTotalFragments <= tabPtr.p->totalfragments) {
7891 logTotalFragments <<= 1;
7893 logTotalFragments >>= 1;
7894 tabPtr.p->mask = logTotalFragments - 1;
7895 tabPtr.p->hashpointer = tabPtr.p->totalfragments - logTotalFragments;
7896 allocFragments(tabPtr.p->totalfragments, tabPtr);
7898 if (tabPtr.p->method == TabRecord::HASH_MAP)
7901 tabPtr.p->m_map_ptr_i = req->hashMapPtrI;
7902 tabPtr.p->m_new_map_ptr_i = RNIL;
7904 g_hash_map.getPtr(mapPtr, tabPtr.p->m_map_ptr_i);
7905 ndbrequire(tabPtr.p->totalfragments >= mapPtr.p->m_fragments);
7909 for (Uint32 fragId = 0; fragId < noFragments; fragId++) {
7911 FragmentstorePtr fragPtr;
7912 Uint32 activeIndex = 0;
7913 getFragstore(tabPtr.p, fragId, fragPtr);
7914 fragPtr.p->m_log_part_id = fragments[index++];
7915 fragPtr.p->preferredPrimary = fragments[
index];
7917 inc_ng_refcount(getNodeGroup(fragPtr.p->preferredPrimary));
7919 for (Uint32 i = 0; i<noReplicas; i++) {
7920 const Uint32 nodeId = fragments[index++];
7921 ReplicaRecordPtr replicaPtr;
7922 allocStoredReplica(fragPtr, replicaPtr, nodeId);
7923 if (getNodeStatus(nodeId) == NodeRecord::ALIVE) {
7925 ndbrequire(activeIndex < MAX_REPLICAS);
7926 fragPtr.p->activeNodes[activeIndex] = nodeId;
7930 removeStoredReplica(fragPtr, replicaPtr);
7931 linkOldStoredReplica(fragPtr, replicaPtr);
7934 fragPtr.p->fragReplicas = activeIndex;
7935 ndbrequire(activeIndex > 0 && fragPtr.p->storedReplicas != RNIL);
7937 initTableFile(tabPtr);
7938 tabPtr.p->tabCopyStatus = TabRecord::CS_ADD_TABLE_MASTER;
7939 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
7940 signal->theData[1] = tabPtr.i;
7941 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
7945 Dbdih::addTable_closeConf(
Signal * signal, Uint32 tabPtrI){
7946 TabRecordPtr tabPtr;
7948 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
7950 ConnectRecordPtr connectPtr;
7951 connectPtr.i = tabPtr.p->connectrec;
7952 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
7953 connectPtr.p->m_alter.m_totalfragments = tabPtr.p->totalfragments;
7955 sendAddFragreq(signal, connectPtr, tabPtr, 0);
7959 Dbdih::sendAddFragreq(
Signal* signal, ConnectRecordPtr connectPtr,
7960 TabRecordPtr tabPtr, Uint32 fragId){
7962 const Uint32 fragCount = connectPtr.p->m_alter.m_totalfragments;
7963 ReplicaRecordPtr replicaPtr;
7964 LINT_INIT(replicaPtr.p);
7965 replicaPtr.i = RNIL;
7966 FragmentstorePtr fragPtr;
7967 for(; fragId<fragCount; fragId++){
7969 getFragstore(tabPtr.p, fragId, fragPtr);
7971 replicaPtr.i = fragPtr.p->storedReplicas;
7972 while(replicaPtr.i != RNIL){
7974 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
7975 if(replicaPtr.p->procNode == getOwnNodeId()){
7978 replicaPtr.i = replicaPtr.p->nextReplica;
7981 if(replicaPtr.i != RNIL){
7986 replicaPtr.i = fragPtr.p->oldStoredReplicas;
7987 while(replicaPtr.i != RNIL){
7989 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
7990 if(replicaPtr.p->procNode == getOwnNodeId()){
7993 replicaPtr.i = replicaPtr.p->nextReplica;
7996 if(replicaPtr.i != RNIL){
8002 if(replicaPtr.i != RNIL){
8004 ndbrequire(fragId < fragCount);
8005 ndbrequire(replicaPtr.p->procNode == getOwnNodeId());
8007 Uint32 requestInfo = 0;
8008 if(tabPtr.p->tabStorage != TabRecord::ST_NORMAL){
8009 requestInfo |= LqhFragReq::TemporaryTable;
8013 requestInfo |= LqhFragReq::CreateInRunning;
8017 req->dihPtr = connectPtr.i;
8018 req->senderData = connectPtr.p->userpointer;
8019 req->fragmentId = fragId;
8020 req->requestInfo = requestInfo;
8021 req->tableId = tabPtr.i;
8023 req->nodeId = getOwnNodeId();
8024 req->totalFragments = fragCount;
8025 req->startGci = SYSFILE->newestRestorableGCI;
8026 req->logPartId = fragPtr.p->m_log_part_id;
8027 req->changeMask = 0;
8029 if (connectPtr.p->connectState == ConnectRecord::ALTER_TABLE)
8032 req->changeMask = connectPtr.p->m_alter.m_changeMask;
8035 sendSignal(DBDICT_REF, GSN_ADD_FRAGREQ, signal,
8036 AddFragReq::SignalLength, JBB);
8040 if (connectPtr.p->connectState == ConnectRecord::ALTER_TABLE)
8045 if (AlterTableReq::getReorgFragFlag(connectPtr.p->m_alter.m_changeMask))
8048 DIH_TAB_WRITE_LOCK(tabPtr.p);
8049 tabPtr.p->m_new_map_ptr_i = connectPtr.p->m_alter.m_new_map_ptr_i;
8050 DIH_TAB_WRITE_UNLOCK(tabPtr.p);
8053 if (AlterTableReq::getAddFragFlag(connectPtr.p->m_alter.m_changeMask))
8057 cb.m_callbackData = connectPtr.i;
8058 cb.m_callbackFunction = safe_cast(&Dbdih::alter_table_writeTable_conf);
8059 saveTableFile(signal, connectPtr, tabPtr, TabRecord::CS_ALTER_TABLE, cb);
8063 send_alter_tab_conf(signal, connectPtr);
8069 conf->senderData = connectPtr.p->userpointer;
8070 sendSignal(connectPtr.p->userblockref, GSN_DIADDTABCONF, signal,
8071 DiAddTabConf::SignalLength, JBB);
8074 if (tabPtr.p->method == TabRecord::HASH_MAP)
8076 Uint32 newValue = RNIL;
8077 if (DictTabInfo::isOrderedIndex(tabPtr.p->tableType))
8080 TabRecordPtr primTabPtr;
8081 primTabPtr.i = tabPtr.p->primaryTableId;
8082 ptrCheckGuard(primTabPtr, ctabFileSize, tabRecord);
8083 newValue = primTabPtr.p->m_map_ptr_i;
8088 newValue = connectPtr.p->m_create.m_map_ptr_i;
8091 tabPtr.p->m_map_ptr_i = newValue;
8094 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8095 tabPtr.p->connectrec = RNIL;
8096 release_connect(connectPtr);
8101 Dbdih::release_connect(ConnectRecordPtr ptr)
8103 TabRecordPtr tabPtr;
8104 tabPtr.i = ptr.p->table;
8105 if (tabPtr.i != RNIL)
8108 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8109 if (tabPtr.p->connectrec == ptr.i)
8112 tabPtr.p->connectrec = RNIL;
8116 ptr.p->table = RNIL;
8117 ptr.p->userblockref = ZNIL;
8118 ptr.p->userpointer = RNIL;
8119 ptr.p->connectState = ConnectRecord::FREE;
8120 ptr.p->nextPool = cfirstconnect;
8121 cfirstconnect = ptr.i;
8125 Dbdih::execADD_FRAGCONF(
Signal* signal){
8129 ConnectRecordPtr connectPtr;
8130 connectPtr.i = conf->dihPtr;
8131 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8133 TabRecordPtr tabPtr;
8134 tabPtr.i = connectPtr.p->table;
8135 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8137 sendAddFragreq(signal, connectPtr, tabPtr, conf->fragId + 1);
8141 Dbdih::execADD_FRAGREF(
Signal* signal){
8145 ConnectRecordPtr connectPtr;
8146 connectPtr.i = ref->dihPtr;
8147 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8149 if (connectPtr.p->connectState == ConnectRecord::ALTER_TABLE)
8153 connectPtr.p->connectState = ConnectRecord::ALTER_TABLE_ABORT;
8154 drop_fragments(signal, connectPtr, connectPtr.p->m_alter.m_totalfragments);
8160 ref->senderData = connectPtr.p->userpointer;
8161 ref->errorCode = ~0;
8162 sendSignal(connectPtr.p->userblockref, GSN_DIADDTABREF, signal,
8163 DiAddTabRef::SignalLength, JBB);
8167 tabPtr.i = connectPtr.p->table;
8168 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8169 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8170 tabPtr.p->connectrec = RNIL;
8171 release_connect(connectPtr);
8180 Dbdih::addtabrefuseLab(
Signal* signal,
8181 ConnectRecordPtr connectPtr, Uint32 errorCode)
8183 signal->theData[0] = connectPtr.p->userpointer;
8184 signal->theData[1] = errorCode;
8185 sendSignal(connectPtr.p->userblockref, GSN_DIADDTABREF, signal, 2, JBB);
8188 tabPtr.i = connectPtr.p->table;
8189 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8190 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8191 tabPtr.p->connectrec = RNIL;
8193 release_connect(connectPtr);
8214 Dbdih::execDROP_TAB_REQ(
Signal* signal)
8219 TabRecordPtr tabPtr;
8220 tabPtr.i = req->tableId;
8221 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8223 tabPtr.p->m_dropTab.tabUserRef = req->senderRef;
8224 tabPtr.p->m_dropTab.tabUserPtr = req->senderData;
8226 DropTabReq::RequestType rt = (DropTabReq::RequestType)req->requestType;
8229 case DropTabReq::OnlineDropTab:
8231 ndbrequire(tabPtr.p->tabStatus == TabRecord::TS_DROPPING);
8233 case DropTabReq::CreateTabDrop:
8236 case DropTabReq::RestartDropTab:
8245 NodeRecordPtr nodePtr;
8246 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
8248 ptrAss(nodePtr, nodeRecord);
8249 if (c_lcpState.m_participatingLQH.get(nodePtr.i))
8253 Uint32 count = nodePtr.p->noOfQueuedChkpt;
8254 while(index < count){
8255 if(nodePtr.p->queuedChkpt[index].tableId == tabPtr.i){
8260 for(Uint32 i = index; i<count; i++){
8262 nodePtr.p->queuedChkpt[
i] = nodePtr.p->queuedChkpt[i + 1];
8268 nodePtr.p->noOfQueuedChkpt = count;
8278 switch(tabPtr.p->tabLcpStatus){
8279 case TabRecord::TLS_COMPLETED:
8280 case TabRecord::TLS_WRITING_TO_FILE:
8285 case TabRecord::TLS_ACTIVE:
8289 tabPtr.p->tabLcpStatus = TabRecord::TLS_COMPLETED;
8294 if (checkLcpAllTablesDoneInLqh(__LINE__))
8298 g_eventLogger->
info(
"This is the last table");
8303 LcpStatus a = c_lcpState.lcpStatus;
8304 checkLcpCompletedLab(signal);
8306 if(a != c_lcpState.lcpStatus)
8308 g_eventLogger->
info(
"And all tables are written to already written disk");
8316 waitDropTabWritingToFile(signal, tabPtr);
8319 void Dbdih::startDeleteFile(
Signal* signal, TabRecordPtr tabPtr)
8321 if (tabPtr.p->tabFile[0] == RNIL) {
8323 initTableFile(tabPtr);
8325 openTableFileForDelete(signal, tabPtr.p->tabFile[0]);
8328 void Dbdih::openTableFileForDelete(
Signal* signal, Uint32 fileIndex)
8330 FileRecordPtr filePtr;
8331 filePtr.i = fileIndex;
8332 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
8333 openFileRw(signal, filePtr);
8334 filePtr.p->reqStatus = FileRecord::TABLE_OPEN_FOR_DELETE;
8337 void Dbdih::tableOpenLab(
Signal* signal, FileRecordPtr filePtr)
8339 closeFileDelete(signal, filePtr);
8340 filePtr.p->reqStatus = FileRecord::TABLE_CLOSE_DELETE;
8344 void Dbdih::tableDeleteLab(
Signal* signal, FileRecordPtr filePtr)
8346 TabRecordPtr tabPtr;
8347 tabPtr.i = filePtr.p->tabRef;
8348 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8349 if (filePtr.i == tabPtr.p->tabFile[0]) {
8351 openTableFileForDelete(signal, tabPtr.p->tabFile[1]);
8354 ndbrequire(filePtr.i == tabPtr.p->tabFile[1]);
8356 releaseFile(tabPtr.p->tabFile[0]);
8357 releaseFile(tabPtr.p->tabFile[1]);
8358 tabPtr.p->tabFile[0] = tabPtr.p->tabFile[1] = RNIL;
8360 tabPtr.p->tabStatus = TabRecord::TS_IDLE;
8363 dropConf->senderRef = reference();
8364 dropConf->senderData = tabPtr.p->m_dropTab.tabUserPtr;
8365 dropConf->tableId = tabPtr.i;
8366 sendSignal(tabPtr.p->m_dropTab.tabUserRef, GSN_DROP_TAB_CONF,
8367 signal, DropTabConf::SignalLength, JBB);
8369 tabPtr.p->m_dropTab.tabUserPtr = RNIL;
8370 tabPtr.p->m_dropTab.tabUserRef = 0;
8371 releaseTable(tabPtr);
8375 void Dbdih::releaseTable(TabRecordPtr tabPtr)
8377 FragmentstorePtr fragPtr;
8378 if (tabPtr.p->noOfFragChunks > 0) {
8379 for (Uint32 fragId = 0; fragId < tabPtr.p->totalfragments; fragId++) {
8381 getFragstore(tabPtr.p, fragId, fragPtr);
8382 dec_ng_refcount(getNodeGroup(fragPtr.p->preferredPrimary));
8383 releaseReplicas(& fragPtr.p->storedReplicas);
8384 releaseReplicas(& fragPtr.p->oldStoredReplicas);
8386 releaseFragments(tabPtr);
8388 if (tabPtr.p->tabFile[0] != RNIL) {
8390 releaseFile(tabPtr.p->tabFile[0]);
8391 releaseFile(tabPtr.p->tabFile[1]);
8392 tabPtr.p->tabFile[0] = tabPtr.p->tabFile[1] = RNIL;
8396 void Dbdih::releaseReplicas(Uint32 * replicaPtrI)
8398 ReplicaRecordPtr replicaPtr;
8399 replicaPtr.i = * replicaPtrI;
8401 while (replicaPtr.i != RNIL) {
8403 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
8404 Uint32 tmp = replicaPtr.p->nextReplica;
8405 replicaPtr.p->nextReplica = cfirstfreeReplica;
8406 cfirstfreeReplica = replicaPtr.i;
8408 cnoFreeReplicaRec++;
8411 * replicaPtrI = RNIL;
8414 void Dbdih::seizeReplicaRec(ReplicaRecordPtr& replicaPtr)
8416 replicaPtr.i = cfirstfreeReplica;
8417 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
8418 cfirstfreeReplica = replicaPtr.p->nextReplica;
8419 cnoFreeReplicaRec--;
8420 replicaPtr.p->nextReplica = RNIL;
8423 void Dbdih::releaseFile(Uint32 fileIndex)
8425 FileRecordPtr filePtr;
8426 filePtr.i = fileIndex;
8427 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
8428 filePtr.p->nextFile = cfirstfreeFile;
8429 cfirstfreeFile = filePtr.i;
8433 void Dbdih::execALTER_TAB_REQ(
Signal * signal)
8436 const Uint32 senderRef = req->senderRef;
8437 const Uint32 senderData = req->senderData;
8438 const Uint32 tableId = req->tableId;
8439 const Uint32 tableVersion = req->tableVersion;
8440 const Uint32 newTableVersion = req->newTableVersion;
8441 AlterTabReq::RequestType requestType =
8442 (AlterTabReq::RequestType) req->requestType;
8444 TabRecordPtr tabPtr;
8446 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8448 switch(requestType){
8449 case AlterTabReq::AlterTablePrepare:
8452 case AlterTabReq::AlterTableRevert:
8454 if (AlterTableReq::getAddFragFlag(req->changeMask) &&
8455 tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE)
8459 sendSignalWithDelay(reference(), GSN_ALTER_TAB_REQ, signal, 100,
8460 signal->getLength(), &handle);
8463 case AlterTabReq::AlterTableCommit:
8465 case AlterTabReq::AlterTableComplete:
8467 case AlterTabReq::AlterTableWaitScan:
8471 jamLine(requestType);
8474 ConnectRecordPtr connectPtr;
8475 connectPtr.i = RNIL;
8476 switch (requestType) {
8477 case AlterTabReq::AlterTablePrepare:
8480 ndbrequire(cfirstconnect != RNIL);
8481 connectPtr.i = cfirstconnect;
8482 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8483 cfirstconnect = connectPtr.p->nextPool;
8485 connectPtr.p->m_alter.m_totalfragments = tabPtr.p->totalfragments;
8486 connectPtr.p->m_alter.m_org_totalfragments = tabPtr.p->totalfragments;
8487 connectPtr.p->m_alter.m_changeMask = req->changeMask;
8488 connectPtr.p->m_alter.m_new_map_ptr_i = req->new_map_ptr_i;
8489 connectPtr.p->userpointer = senderData;
8490 connectPtr.p->userblockref = senderRef;
8491 connectPtr.p->connectState = ConnectRecord::ALTER_TABLE;
8492 connectPtr.p->table = tabPtr.i;
8493 tabPtr.p->connectrec = connectPtr.i;
8495 case AlterTabReq::AlterTableRevert:
8497 tabPtr.p->schemaVersion = tableVersion;
8499 connectPtr.i = req->connectPtr;
8500 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8502 ndbrequire(connectPtr.p->connectState == ConnectRecord::ALTER_TABLE);
8504 connectPtr.p->userpointer = senderData;
8505 connectPtr.p->userblockref = senderRef;
8507 if (AlterTableReq::getAddFragFlag(req->changeMask))
8510 tabPtr.p->tabCopyStatus = TabRecord::CS_ALTER_TABLE;
8511 connectPtr.p->connectState = ConnectRecord::ALTER_TABLE_REVERT;
8512 drop_fragments(signal, connectPtr,
8513 connectPtr.p->m_alter.m_totalfragments);
8517 send_alter_tab_conf(signal, connectPtr);
8519 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8520 tabPtr.p->connectrec = RNIL;
8521 release_connect(connectPtr);
8524 case AlterTabReq::AlterTableCommit:
8526 tabPtr.p->schemaVersion = newTableVersion;
8528 connectPtr.i = req->connectPtr;
8529 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8530 connectPtr.p->userpointer = senderData;
8531 connectPtr.p->userblockref = senderRef;
8532 ndbrequire(connectPtr.p->connectState == ConnectRecord::ALTER_TABLE);
8534 tabPtr.p->totalfragments = connectPtr.p->m_alter.m_totalfragments;
8535 if (AlterTableReq::getReorgFragFlag(connectPtr.p->m_alter.m_changeMask))
8538 DIH_TAB_WRITE_LOCK(tabPtr.p);
8539 Uint32 save = tabPtr.p->m_map_ptr_i;
8540 tabPtr.p->m_map_ptr_i = tabPtr.p->m_new_map_ptr_i;
8541 tabPtr.p->m_new_map_ptr_i = save;
8543 for (Uint32 i = 0; i<tabPtr.p->totalfragments; i++)
8546 FragmentstorePtr fragPtr;
8547 getFragstore(tabPtr.p, i, fragPtr);
8548 fragPtr.p->distributionKey = (fragPtr.p->distributionKey + 1) & 0xFF;
8550 DIH_TAB_WRITE_UNLOCK(tabPtr.p);
8552 ndbassert(tabPtr.p->m_scan_count[1] == 0);
8553 tabPtr.p->m_scan_count[1] = tabPtr.p->m_scan_count[0];
8554 tabPtr.p->m_scan_count[0] = 0;
8555 tabPtr.p->m_scan_reorg_flag = 1;
8557 send_alter_tab_conf(signal, connectPtr);
8561 send_alter_tab_conf(signal, connectPtr);
8562 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8563 tabPtr.p->connectrec = RNIL;
8564 release_connect(connectPtr);
8566 case AlterTabReq::AlterTableComplete:
8568 connectPtr.i = req->connectPtr;
8569 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8570 connectPtr.p->userpointer = senderData;
8571 connectPtr.p->userblockref = senderRef;
8573 send_alter_tab_conf(signal, connectPtr);
8575 DIH_TAB_WRITE_LOCK(tabPtr.p);
8576 tabPtr.p->m_new_map_ptr_i = RNIL;
8577 tabPtr.p->m_scan_reorg_flag = 0;
8578 DIH_TAB_WRITE_UNLOCK(tabPtr.p);
8580 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8581 tabPtr.p->connectrec = RNIL;
8582 release_connect(connectPtr);
8584 case AlterTabReq::AlterTableWaitScan:{
8586 Uint64 now = NdbTick_CurrentMillisecond();
8588 signal->theData[0] = DihContinueB::ZWAIT_OLD_SCAN;
8589 signal->theData[1] = tabPtr.i;
8590 signal->theData[2] = senderRef;
8591 signal->theData[3] = senderData;
8592 signal->theData[4] = connectPtr.i;
8593 signal->theData[5] = Uint32(now >> 32);
8594 signal->theData[6] = Uint32(now);
8595 signal->theData[7] = 3;
8596 sendSignal(reference(), GSN_CONTINUEB, signal, 8, JBB);
8604 if (AlterTableReq::getAddFragFlag(req->changeMask))
8609 handle.getSection(ptr, 0);
8611 Uint16 buf[2+2*MAX_NDB_PARTITIONS];
8615 releaseSections(handle);
8617 Uint32 save = tabPtr.p->totalfragments;
8618 if ((err = add_fragments_to_table(tabPtr, buf)))
8621 ndbrequire(tabPtr.p->totalfragments == save);
8622 ndbrequire(connectPtr.p->m_alter.m_org_totalfragments == save);
8623 send_alter_tab_ref(signal, tabPtr, connectPtr, err);
8625 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8626 tabPtr.p->connectrec = RNIL;
8627 release_connect(connectPtr);
8631 tabPtr.p->tabCopyStatus = TabRecord::CS_ALTER_TABLE;
8632 connectPtr.p->m_alter.m_totalfragments = tabPtr.p->totalfragments;
8633 tabPtr.p->totalfragments = save;
8634 sendAddFragreq(signal, connectPtr, tabPtr,
8635 connectPtr.p->m_alter.m_org_totalfragments);
8639 send_alter_tab_conf(signal, connectPtr);
8643 Dbdih::add_fragments_to_table(
Ptr<TabRecord> tabPtr,
const Uint16 buf[])
8645 Uint32 replicas = buf[0];
8646 Uint32 cnt = buf[1];
8650 Uint32 current = tabPtr.p->totalfragments;
8651 for (i = 0; i<cnt; i++)
8653 FragmentstorePtr fragPtr;
8654 if (ERROR_INSERTED(7212) && cnt)
8657 CLEAR_ERROR_INSERT_VALUE;
8661 if ((err = add_fragment_to_table(tabPtr, current + i, fragPtr)))
8664 fragPtr.p->m_log_part_id = buf[2+(1 + replicas)*i];
8665 fragPtr.p->preferredPrimary = buf[2+(1 + replicas)*i + 1];
8667 inc_ng_refcount(getNodeGroup(fragPtr.p->preferredPrimary));
8669 Uint32 activeIndex = 0;
8670 for (Uint32 j = 0; j<replicas; j++)
8672 const Uint32 nodeId = buf[2+(1 + replicas)*i + 1 + j];
8673 ReplicaRecordPtr replicaPtr;
8674 allocStoredReplica(fragPtr, replicaPtr, nodeId);
8675 if (getNodeStatus(nodeId) == NodeRecord::ALIVE) {
8677 ndbrequire(activeIndex < MAX_REPLICAS);
8678 fragPtr.p->activeNodes[activeIndex] = nodeId;
8682 removeStoredReplica(fragPtr, replicaPtr);
8683 linkOldStoredReplica(fragPtr, replicaPtr);
8686 fragPtr.p->fragReplicas = activeIndex;
8691 for(i = i + current; i != current; i--)
8693 release_fragment_from_table(tabPtr, i);
8700 Dbdih::wait_old_scan(
Signal* signal)
8704 TabRecordPtr tabPtr;
8705 tabPtr.i = signal->theData[1];
8706 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8708 if (tabPtr.p->m_scan_count[1] == 0)
8711 Uint32 senderRef = signal->theData[2];
8712 Uint32 senderData = signal->theData[3];
8713 Uint32 connectPtrI = signal->theData[4];
8716 conf->senderRef = reference();
8717 conf->senderData = senderData;
8718 conf->connectPtr = connectPtrI;
8719 sendSignal(senderRef, GSN_ALTER_TAB_CONF, signal,
8720 AlterTabConf::SignalLength, JBB);
8724 Uint32 start_hi = signal->theData[5];
8725 Uint32 start_lo = signal->theData[6];
8726 Uint64 start = (Uint64(start_hi) << 32) + start_lo;
8727 Uint32 wait = signal->theData[7];
8728 Uint64 now = NdbTick_CurrentMillisecond() / 1000;
8729 if (now > start + wait)
8731 infoEvent(
"Waiting(%u) for scans(%u) to complete on table %u",
8732 Uint32(now - start),
8733 tabPtr.p->m_scan_count[1],
8738 signal->theData[7] = 3 + 7;
8742 signal->theData[7] = 2 * wait;
8746 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 1000, 7);
8754 Uint32 fragments = tabPtr.p->totalfragments;
8755 Uint32 chunks = tabPtr.p->noOfFragChunks;
8757 ndbrequire(fragId == fragments);
8759 if (ERROR_INSERTED(7211))
8761 CLEAR_ERROR_INSERT_VALUE;
8765 Uint32 allocated = chunks << LOG_NO_OF_FRAGS_PER_CHUNK;
8766 if (fragId < allocated)
8769 tabPtr.p->totalfragments++;
8770 getFragstore(tabPtr.p, fragId, fragPtr);
8777 fragPtr.i = cfirstfragstore;
8778 if (fragPtr.i == RNIL)
8784 ptrCheckGuard(fragPtr, cfragstoreFileSize, fragmentstore);
8785 cfirstfragstore = fragPtr.p->nextFragmentChunk;
8786 ndbrequire(cremainingfrags >= NO_OF_FRAGS_PER_CHUNK);
8787 cremainingfrags -= NO_OF_FRAGS_PER_CHUNK;
8789 ndbrequire(chunks < NDB_ARRAY_SIZE(tabPtr.p->startFid));
8790 tabPtr.p->startFid[chunks] = fragPtr.i;
8791 for (Uint32 i = 0; i<NO_OF_FRAGS_PER_CHUNK; i++)
8795 tmp.i = fragPtr.i +
i;
8796 ptrCheckGuard(tmp, cfragstoreFileSize, fragmentstore);
8800 tabPtr.p->totalfragments++;
8801 tabPtr.p->noOfFragChunks++;
8807 Dbdih::release_fragment_from_table(
Ptr<TabRecord> tabPtr, Uint32 fragId)
8809 FragmentstorePtr fragPtr;
8810 Uint32 fragments = tabPtr.p->totalfragments;
8811 Uint32 chunks = tabPtr.p->noOfFragChunks;
8813 if (fragId >= fragments)
8818 ndbrequire(fragId == fragments - 1);
8819 ndbrequire(fragments != 0);
8821 getFragstore(tabPtr.p, fragId, fragPtr);
8822 dec_ng_refcount(getNodeGroup(fragPtr.p->preferredPrimary));
8824 releaseReplicas(& fragPtr.p->storedReplicas);
8825 releaseReplicas(& fragPtr.p->oldStoredReplicas);
8827 if (fragId == ((chunks - 1) << LOG_NO_OF_FRAGS_PER_CHUNK))
8831 getFragstore(tabPtr.p, fragId, fragPtr);
8833 fragPtr.p->nextFragmentChunk = cfirstfragstore;
8834 cfirstfragstore = fragPtr.i;
8835 cremainingfrags += NO_OF_FRAGS_PER_CHUNK;
8836 tabPtr.p->noOfFragChunks = chunks - 1;
8839 tabPtr.p->totalfragments--;
8843 Dbdih::send_alter_tab_ref(
Signal* signal,
8849 ref->senderRef = reference();
8850 ref->senderData = connectPtr.p->userpointer;
8851 ref->errorCode = errCode;
8852 sendSignal(connectPtr.p->userblockref, GSN_ALTER_TAB_REF, signal,
8853 AlterTabRef::SignalLength, JBB);
8860 conf->senderRef = reference();
8861 conf->senderData = connectPtr.p->userpointer;
8862 conf->connectPtr = connectPtr.i;
8863 sendSignal(connectPtr.p->userblockref, GSN_ALTER_TAB_CONF, signal,
8864 AlterTabConf::SignalLength, JBB);
8868 Dbdih::saveTableFile(
Signal* signal,
8871 TabRecord::CopyStatus expectedStatus,
8874 ndbrequire(connectPtr.i == cb.m_callbackData);
8875 ndbrequire(tabPtr.p->tabCopyStatus == expectedStatus);
8876 memcpy(&connectPtr.p->m_callback, &cb,
sizeof(Callback));
8878 tabPtr.p->tabCopyStatus = TabRecord::CS_COPY_TO_SAVE;
8879 tabPtr.p->tabUpdateState = TabRecord::US_CALLBACK;
8880 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
8881 signal->theData[1] = tabPtr.i;
8882 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
8886 Dbdih::alter_table_writeTable_conf(
Signal* signal, Uint32 ptrI, Uint32 err)
8889 ndbrequire(err == 0);
8891 ConnectRecordPtr connectPtr;
8892 connectPtr.i = ptrI;
8893 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8895 switch(connectPtr.p->connectState){
8896 case ConnectRecord::ALTER_TABLE_REVERT:
8899 send_alter_tab_conf(signal, connectPtr);
8902 tabPtr.i = connectPtr.p->table;
8903 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8904 ndbrequire(tabPtr.p->connectrec == connectPtr.i);
8905 tabPtr.p->connectrec = RNIL;
8906 release_connect(connectPtr);
8909 case ConnectRecord::ALTER_TABLE:
8912 send_alter_tab_conf(signal, connectPtr);
8916 jamLine(connectPtr.p->connectState);
8925 ndbrequire(curr >= connectPtr.p->m_alter.m_org_totalfragments);
8926 if (curr == connectPtr.p->m_alter.m_org_totalfragments)
8933 tabPtr.i = connectPtr.p->table;
8934 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
8936 Uint32 new_frags = connectPtr.p->m_alter.m_totalfragments;
8937 Uint32 org_frags = connectPtr.p->m_alter.m_org_totalfragments;
8938 tabPtr.p->totalfragments = new_frags;
8939 for (Uint32 i = new_frags - 1; i >= org_frags; i--)
8942 release_fragment_from_table(tabPtr, i);
8944 connectPtr.p->m_alter.m_totalfragments = org_frags;
8946 switch(connectPtr.p->connectState){
8947 case ConnectRecord::ALTER_TABLE_ABORT:
8950 ndbrequire(tabPtr.p->tabCopyStatus == TabRecord::CS_ALTER_TABLE);
8951 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
8952 send_alter_tab_ref(signal, tabPtr, connectPtr, ~0);
8954 connectPtr.p->connectState = ConnectRecord::ALTER_TABLE;
8957 case ConnectRecord::ALTER_TABLE_REVERT:
8961 cb.m_callbackData = connectPtr.i;
8962 cb.m_callbackFunction = safe_cast(&Dbdih::alter_table_writeTable_conf);
8963 saveTableFile(signal, connectPtr, tabPtr, TabRecord::CS_ALTER_TABLE, cb);
8967 jamLine(connectPtr.p->connectState);
8973 ndbrequire(curr > 0);
8975 req->senderRef = reference();
8976 req->senderData = connectPtr.i;
8977 req->tableId = connectPtr.p->table;
8978 req->fragId = curr - 1;
8979 req->requestInfo = DropFragReq::AlterTableAbort;
8980 sendSignal(DBLQH_REF, GSN_DROP_FRAG_REQ, signal,
8981 DropFragReq::SignalLength, JBB);
8985 Dbdih::execDROP_FRAG_REF(
Signal* signal)
8991 Dbdih::execDROP_FRAG_CONF(
Signal* signal)
8995 ConnectRecordPtr connectPtr;
8996 connectPtr.i = conf->senderData;
8997 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
8999 drop_fragments(signal, connectPtr, conf->fragId);
9014 void Dbdih::execDIGETNODESREQ(
Signal* signal)
9017 FragmentstorePtr fragPtr;
9018 TabRecordPtr tabPtr;
9019 tabPtr.i = req->tableId;
9020 Uint32 hashValue = req->hashValue;
9021 Uint32 ttabFileSize = ctabFileSize;
9022 Uint32 fragId, newFragId = RNIL;
9024 TabRecord* regTabDesc = tabRecord;
9026 thrjamEntry(jambuf);
9027 ptrCheckGuard(tabPtr, ttabFileSize, regTabDesc);
9029 if (DictTabInfo::isOrderedIndex(tabPtr.p->tableType))
9032 tabPtr.i = tabPtr.p->primaryTableId;
9033 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
9037 Uint32 val = tabPtr.p->
m_lock.read_lock();
9038 Uint32 map_ptr_i = tabPtr.p->m_map_ptr_i;
9039 Uint32 new_map_ptr_i = tabPtr.p->m_new_map_ptr_i;
9045 if (req->distr_key_indicator)
9048 if (unlikely(fragId >= tabPtr.p->totalfragments))
9052 signal->theData[1]= ZUNDEFINED_FRAGMENT_ERROR;
9056 else if (tabPtr.p->method == TabRecord::HASH_MAP)
9060 g_hash_map.getPtr(ptr, map_ptr_i);
9061 fragId = ptr.p->m_map[hashValue % ptr.p->m_cnt];
9063 if (unlikely(new_map_ptr_i != RNIL))
9066 g_hash_map.getPtr(ptr, new_map_ptr_i);
9067 newFragId = ptr.p->m_map[hashValue % ptr.p->m_cnt];
9068 if (newFragId == fragId)
9075 else if (tabPtr.p->method == TabRecord::LINEAR_HASH)
9078 fragId = hashValue & tabPtr.p->mask;
9079 if (fragId < tabPtr.p->hashpointer) {
9081 fragId = hashValue & ((tabPtr.p->mask << 1) + 1);
9084 else if (tabPtr.p->method == TabRecord::NORMAL_HASH)
9087 fragId= hashValue % tabPtr.p->totalfragments;
9092 ndbassert(tabPtr.p->method == TabRecord::USER_DEFINED);
9096 signal->theData[1]= ZUNDEFINED_FRAGMENT_ERROR;
9099 getFragstore(tabPtr.p, fragId, fragPtr);
9100 Uint32 nodeCount = extractNodeInfo(fragPtr.p, conf->nodes);
9101 Uint32 sig2 = (nodeCount - 1) +
9102 (fragPtr.p->distributionKey << 16) +
9103 (dihGetInstanceKey(fragPtr) << 24);
9105 conf->reqinfo = sig2;
9106 conf->fragId = fragId;
9108 if (unlikely(newFragId != RNIL))
9111 conf->reqinfo |= DiGetNodesConf::REORG_MOVING;
9112 getFragstore(tabPtr.p, newFragId, fragPtr);
9113 nodeCount = extractNodeInfo(fragPtr.p, conf->nodes + 2 + MAX_REPLICAS);
9114 conf->nodes[MAX_REPLICAS] = newFragId;
9115 conf->nodes[MAX_REPLICAS + 1] = (nodeCount - 1) +
9116 (fragPtr.p->distributionKey << 16) +
9117 (dihGetInstanceKey(fragPtr) << 24);
9120 if (unlikely(!tabPtr.p->
m_lock.read_unlock(val)))
9124 Uint32 Dbdih::extractNodeInfo(
const Fragmentstore * fragPtr, Uint32 nodes[])
9126 Uint32 nodeCount = 0;
9127 nodes[0] = nodes[1] = nodes[2] = nodes[3] = 0;
9128 for (Uint32 i = 0; i < fragPtr->fragReplicas; i++) {
9130 NodeRecordPtr nodePtr;
9131 ndbrequire(i < MAX_REPLICAS);
9132 nodePtr.i = fragPtr->activeNodes[
i];
9133 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
9134 if (nodePtr.p->useInTransactions) {
9136 nodes[nodeCount] = nodePtr.i;
9140 ndbrequire(nodeCount > 0);
9145 Dbdih::getFragstore(TabRecord * tab,
9147 FragmentstorePtr & fragptr)
9149 FragmentstorePtr fragPtr;
9150 Uint32 TfragstoreFileSize = cfragstoreFileSize;
9151 Fragmentstore* TfragStore = fragmentstore;
9152 Uint32 chunkNo = fragNo >> LOG_NO_OF_FRAGS_PER_CHUNK;
9153 Uint32 chunkIndex = fragNo & (NO_OF_FRAGS_PER_CHUNK - 1);
9154 fragPtr.i = tab->startFid[chunkNo] + chunkIndex;
9155 if (likely(chunkNo < NDB_ARRAY_SIZE(tab->startFid))) {
9156 ptrCheckGuard(fragPtr, TfragstoreFileSize, TfragStore);
9163 void Dbdih::allocFragments(Uint32 noOfFragments, TabRecordPtr tabPtr)
9165 FragmentstorePtr fragPtr;
9166 Uint32 noOfChunks = (noOfFragments + (NO_OF_FRAGS_PER_CHUNK - 1)) >> LOG_NO_OF_FRAGS_PER_CHUNK;
9167 ndbrequire(cremainingfrags >= noOfFragments);
9168 for (Uint32 i = 0; i < noOfChunks; i++) {
9170 Uint32 baseFrag = cfirstfragstore;
9171 ndbrequire(i < NDB_ARRAY_SIZE(tabPtr.p->startFid));
9172 tabPtr.p->startFid[
i] = baseFrag;
9173 fragPtr.i = baseFrag;
9174 ptrCheckGuard(fragPtr, cfragstoreFileSize, fragmentstore);
9175 cfirstfragstore = fragPtr.p->nextFragmentChunk;
9176 cremainingfrags -= NO_OF_FRAGS_PER_CHUNK;
9177 for (Uint32 j = 0; j < NO_OF_FRAGS_PER_CHUNK; j++) {
9179 fragPtr.i = baseFrag + j;
9180 ptrCheckGuard(fragPtr, cfragstoreFileSize, fragmentstore);
9181 initFragstore(fragPtr);
9184 tabPtr.p->noOfFragChunks = noOfChunks;
9187 void Dbdih::releaseFragments(TabRecordPtr tabPtr)
9189 FragmentstorePtr fragPtr;
9190 for (Uint32 i = 0; i < tabPtr.p->noOfFragChunks; i++) {
9192 ndbrequire(i < NDB_ARRAY_SIZE(tabPtr.p->startFid));
9193 Uint32 baseFrag = tabPtr.p->startFid[
i];
9194 fragPtr.i = baseFrag;
9195 ptrCheckGuard(fragPtr, cfragstoreFileSize, fragmentstore);
9196 fragPtr.p->nextFragmentChunk = cfirstfragstore;
9197 cfirstfragstore = baseFrag;
9198 tabPtr.p->startFid[
i] = RNIL;
9199 cremainingfrags += NO_OF_FRAGS_PER_CHUNK;
9201 tabPtr.p->noOfFragChunks = 0;
9204 void Dbdih::initialiseFragstore()
9207 FragmentstorePtr fragPtr;
9208 for (i = 0; i < cfragstoreFileSize; i++) {
9210 ptrCheckGuard(fragPtr, cfragstoreFileSize, fragmentstore);
9211 initFragstore(fragPtr);
9213 Uint32 noOfChunks = cfragstoreFileSize >> LOG_NO_OF_FRAGS_PER_CHUNK;
9215 cfirstfragstore = RNIL;
9216 cremainingfrags = 0;
9217 for (i = 0; i < noOfChunks; i++) {
9219 ptrCheckGuard(fragPtr, cfragstoreFileSize, fragmentstore);
9220 fragPtr.p->nextFragmentChunk = cfirstfragstore;
9221 cfirstfragstore = fragPtr.i;
9222 fragPtr.i += NO_OF_FRAGS_PER_CHUNK;
9223 cremainingfrags += NO_OF_FRAGS_PER_CHUNK;
9227 #ifndef NDB_HAVE_RMB
9228 #define rmb() do { } while (0)
9231 #ifndef NDB_HAVE_WMB
9232 #define wmb() do { } while (0)
9237 Dbdih::isEmpty(
const DIVERIFY_queue & q)
9239 return q.cfirstVerifyQueue == q.clastVerifyQueue;
9244 Dbdih::enqueue(DIVERIFY_queue & q, Uint32 senderData, Uint64 gci)
9253 Uint32 first = q.cfirstVerifyQueue;
9256 Uint32 last = q.clastVerifyQueue;
9257 ApiConnectRecord * apiConnectRecord = q.apiConnectRecord;
9259 apiConnectRecord[last].senderData = senderData;
9260 apiConnectRecord[last].apiGci = gci;
9262 if (last + 1 == capiConnectFileSize)
9264 q.clastVerifyQueue = 0;
9268 q.clastVerifyQueue = last + 1;
9270 assert(q.clastVerifyQueue != first);
9275 Dbdih::dequeue(DIVERIFY_queue & q, ApiConnectRecord & conRecord)
9277 Uint32 first = q.cfirstVerifyQueue;
9278 ApiConnectRecord * apiConnectRecord = q.apiConnectRecord;
9281 conRecord.senderData = apiConnectRecord[first].senderData;
9282 conRecord.apiGci = apiConnectRecord[first].apiGci;
9284 if (first + 1 == capiConnectFileSize)
9286 q.cfirstVerifyQueue = 0;
9290 q.cfirstVerifyQueue = first + 1;
9305 void Dbdih::execDIVERIFYREQ(
Signal* signal)
9308 thrjamEntry(jambuf);
9309 Uint32 qno = signal->theData[1];
9310 ndbassert(qno < NDB_ARRAY_SIZE(c_diverify_queue));
9311 DIVERIFY_queue & q = c_diverify_queue[qno];
9313 Uint32 val = m_micro_gcp.m_lock.read_lock();
9314 Uint32 blocked = getBlockCommit() ==
true ? 1 : 0;
9315 if (blocked == 0 && isEmpty(q))
9325 signal->theData[1] = (Uint32)(m_micro_gcp.m_current_gci >> 32);
9326 signal->theData[2] = (Uint32)(m_micro_gcp.m_current_gci & 0xFFFFFFFF);
9327 signal->theData[3] = 0;
9328 if (unlikely(! m_micro_gcp.m_lock.read_unlock(val)))
9336 enqueue(q, signal->theData[0], m_micro_gcp.m_new_gci);
9337 if (blocked == 0 && jambuf == jamBuffer())
9339 emptyverificbuffer(signal, 0,
false);
9341 signal->theData[3] = blocked + 1;
9345 void Dbdih::execDIH_SCAN_TAB_REQ(
Signal* signal)
9348 TabRecordPtr tabPtr;
9349 const Uint32 senderData = req->senderData;
9350 const Uint32 senderRef = req->senderRef;
9351 const Uint32 schemaTransId = req->schemaTransId;
9355 tabPtr.i = req->tableId;
9356 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
9358 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
9360 if (! (tabPtr.p->tabStatus == TabRecord::TS_CREATING &&
9361 tabPtr.p->schemaTransId == schemaTransId))
9368 tabPtr.p->m_scan_count[0]++;
9372 conf->tableId = tabPtr.i;
9373 conf->senderData = senderData;
9374 conf->fragmentCount = tabPtr.p->totalfragments;
9375 conf->noOfBackups = tabPtr.p->noOfBackups;
9376 conf->scanCookie = tabPtr.p->m_map_ptr_i;
9377 conf->reorgFlag = tabPtr.p->m_scan_reorg_flag;
9378 sendSignal(senderRef, GSN_DIH_SCAN_TAB_CONF, signal,
9379 DihScanTabConf::SignalLength, JBB);
9385 ref->tableId = tabPtr.i;
9386 ref->senderData = senderData;
9387 ref->error = DihScanTabRef::ErroneousTableState;
9388 ref->tableStatus = tabPtr.p->tabStatus;
9389 ref->schemaTransId = schemaTransId;
9390 sendSignal(senderRef, GSN_DIH_SCAN_TAB_REF, signal,
9391 DihScanTabRef::SignalLength, JBB);
9396 void Dbdih::execDIH_SCAN_GET_NODES_REQ(
Signal* signal)
9398 FragmentstorePtr fragPtr;
9399 TabRecordPtr tabPtr;
9402 Uint32 senderRef = req->senderRef;
9403 Uint32 senderData = req->senderData;
9404 Uint32 fragId = req->fragId;
9406 tabPtr.i = req->tableId;
9407 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
9408 if (DictTabInfo::isOrderedIndex(tabPtr.p->tableType)) {
9410 tabPtr.i = tabPtr.p->primaryTableId;
9411 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
9414 Uint32 nodes[MAX_REPLICAS];
9415 getFragstore(tabPtr.p, fragId, fragPtr);
9416 Uint32 count = extractNodeInfo(fragPtr.p, nodes);
9419 conf->senderData = senderData;
9420 conf->nodes[0] = nodes[0];
9421 conf->nodes[1] = nodes[1];
9422 conf->nodes[2] = nodes[2];
9423 conf->nodes[3] = nodes[3];
9424 conf->count = count;
9425 conf->tableId = tabPtr.i;
9426 conf->fragId = fragId;
9427 conf->instanceKey = dihGetInstanceKey(fragPtr);
9428 sendSignal(senderRef, GSN_DIH_SCAN_GET_NODES_CONF, signal,
9429 DihScanGetNodesConf::SignalLength, JBB);
9433 Dbdih::execDIH_SCAN_TAB_COMPLETE_REP(
Signal* signal)
9437 TabRecordPtr tabPtr;
9438 tabPtr.i = rep->tableId;
9439 Uint32 map_ptr_i = rep->scanCookie;
9440 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
9442 if (map_ptr_i == tabPtr.p->m_map_ptr_i)
9445 ndbassert(tabPtr.p->m_scan_count[0]);
9446 tabPtr.p->m_scan_count[0]--;
9451 ndbassert(tabPtr.p->m_scan_count[1]);
9452 tabPtr.p->m_scan_count[1]--;
9466 Dbdih::check_enable_micro_gcp(
Signal* signal,
bool broadcast)
9468 ndbassert(m_micro_gcp.m_enabled ==
false);
9469 ndbassert(NodeVersionInfo::DataLength == 6);
9470 Uint32 min = ~(Uint32)0;
9472 for (Uint32 i = 0; i<3; i++)
9474 Uint32 tmp = info.m_type[
i].m_min_version;
9477 min = (min < tmp) ? min : tmp;
9481 if (ndb_check_micro_gcp(min))
9484 m_micro_gcp.m_enabled =
true;
9491 ord->type = UpgradeProtocolOrd::UPO_ENABLE_MICRO_GCP;
9496 NodeRecordPtr specNodePtr;
9497 specNodePtr.i = cfirstAliveNode;
9500 ptrCheckGuard(specNodePtr, MAX_NDB_NODES, nodeRecord);
9501 sendSignal(calcDihBlockRef(specNodePtr.i), GSN_UPGRADE_PROTOCOL_ORD,
9502 signal, UpgradeProtocolOrd::SignalLength, JBA);
9503 specNodePtr.i = specNodePtr.p->nextNode;
9504 }
while (specNodePtr.i != RNIL);
9505 EXECUTE_DIRECT(QMGR,GSN_UPGRADE_PROTOCOL_ORD,signal,signal->getLength());
9508 return m_micro_gcp.m_enabled;
9512 Dbdih::execUPGRADE_PROTOCOL_ORD(
Signal* signal)
9516 case UpgradeProtocolOrd::UPO_ENABLE_MICRO_GCP:
9518 m_micro_gcp.m_enabled =
true;
9519 EXECUTE_DIRECT(QMGR, GSN_UPGRADE_PROTOCOL_ORD,signal, signal->getLength());
9525 Dbdih::startGcpLab(
Signal* signal, Uint32 aWaitTime)
9527 for (Uint32 i = 0; i < c_diverify_queue_cnt; i++)
9529 if (c_diverify_queue[i].m_empty_done == 0)
9533 signal->theData[0] = DihContinueB::ZSTART_GCP;
9534 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 10, 1);
9539 emptyWaitGCPMasterQueue(signal,
9540 m_micro_gcp.m_current_gci,
9541 c_waitEpochMasterList);
9543 if (c_nodeStartMaster.blockGcp != 0 &&
9544 m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE)
9553 if (ERROR_INSERTED(7217))
9557 signal->theData[0] = 9999;
9558 sendSignal(numberToRef(CMVMI, refToNode(c_nodeStartMaster.startNode)),
9559 GSN_NDB_TAMPER, signal, 1, JBB);
9561 m_micro_gcp.m_master.m_start_time = 0;
9567 ndbrequire(c_nodeStartMaster.blockGcp == 1);
9568 c_nodeStartMaster.blockGcp = 2;
9569 gcpBlockedLab(signal);
9574 if (cgcpOrderBlocked)
9577 signal->theData[0] = DihContinueB::ZSTART_GCP;
9578 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 10, 1);
9582 Uint32 delayMicro = m_micro_gcp.m_enabled ?
9583 m_micro_gcp.m_master.m_time_between_gcp :
9584 m_gcp_save.m_master.m_time_between_gcp;
9586 Uint64 now = c_current_time = NdbTick_CurrentMillisecond();
9587 if (! (now >= m_micro_gcp.m_master.m_start_time + delayMicro))
9590 signal->theData[0] = DihContinueB::ZSTART_GCP;
9591 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 10, 1);
9595 m_micro_gcp.m_master.m_start_time = now;
9597 if (m_micro_gcp.m_enabled ==
false &&
9598 m_micro_gcp.m_master.m_time_between_gcp)
9604 check_enable_micro_gcp(signal,
true);
9610 Uint64 currGCI = m_micro_gcp.m_current_gci;
9611 ndbrequire(Uint32(currGCI) != ~(Uint32)0);
9612 m_micro_gcp.m_master.m_new_gci = currGCI + 1;
9614 Uint32 delaySave = m_gcp_save.m_master.m_time_between_gcp;
9615 if ((m_micro_gcp.m_enabled ==
false) ||
9616 (now >= m_gcp_save.m_master.m_start_time + delaySave &&
9617 m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE))
9623 m_gcp_save.m_master.m_start_time = now;
9624 m_micro_gcp.m_master.m_new_gci = Uint64((currGCI >> 32) + 1) << 32;
9627 signal->theData[1] = Uint32(currGCI >> 32);
9628 signal->theData[2] = Uint32(currGCI);
9629 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 3, JBB);
9632 ndbassert(m_micro_gcp.m_enabled || Uint32(m_micro_gcp.m_new_gci) == 0);
9639 CRASH_INSERTION(7000);
9640 m_micro_gcp.m_master.m_state = MicroGcp::M_GCP_PREPARE;
9641 signal->setTrace(TestOrd::TraceGlobalCheckpoint);
9644 if (ERROR_INSERTED(7186))
9646 sendToRandomNodes(
"GCP_PREPARE",
9647 signal, &c_GCP_PREPARE_Counter, &Dbdih::sendGCP_PREPARE);
9648 signal->theData[0] = 9999;
9649 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
9652 else if (ERROR_INSERTED(7200))
9654 c_GCP_PREPARE_Counter.clearWaitingFor();
9655 NodeRecordPtr nodePtr;
9656 nodePtr.i = cfirstAliveNode;
9659 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
9661 if (nodePtr.i != getOwnNodeId())
9663 SET_ERROR_INSERT_VALUE(7201);
9664 sendGCP_PREPARE(signal, nodePtr.i, RNIL);
9668 SET_ERROR_INSERT_VALUE(7202);
9669 sendGCP_PREPARE(signal, nodePtr.i, RNIL);
9671 nodePtr.i = nodePtr.p->nextNode;
9672 }
while (nodePtr.i != RNIL);
9675 rg.m_nodes.clear(getOwnNodeId());
9676 Uint32 victim = rg.m_nodes.find(0);
9678 signal->theData[0] = 9999;
9679 sendSignal(numberToRef(CMVMI, victim),
9680 GSN_NDB_TAMPER, signal, 1, JBA);
9682 CLEAR_ERROR_INSERT_VALUE;
9685 else if (ERROR_INSERTED(7227))
9687 ndbout_c(
"Not sending GCP_PREPARE to %u", c_error_insert_extra);
9688 c_GCP_PREPARE_Counter.clearWaitingFor();
9689 NodeRecordPtr nodePtr;
9690 nodePtr.i = cfirstAliveNode;
9693 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
9695 if (nodePtr.i != c_error_insert_extra)
9697 sendGCP_PREPARE(signal, nodePtr.i, RNIL);
9699 nodePtr.i = nodePtr.p->nextNode;
9700 }
while (nodePtr.i != RNIL);
9702 signal->theData[0] = 9999;
9703 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 200, 1);
9708 sendLoopMacro(GCP_PREPARE, sendGCP_PREPARE, RNIL);
9711 void Dbdih::execGCP_PREPARECONF(
Signal* signal)
9714 Uint32 senderNodeId = signal->theData[0];
9715 Uint32 gci_hi = signal->theData[1];
9716 Uint32 gci_lo = signal->theData[2];
9718 if (unlikely(signal->getLength() < GCPPrepareConf::SignalLength))
9721 ndbassert(!ndb_check_micro_gcp(
getNodeInfo(senderNodeId).m_version));
9724 Uint64 gci = gci_lo | (Uint64(gci_hi) << 32);
9725 ndbrequire(gci == m_micro_gcp.m_master.m_new_gci);
9726 receiveLoopMacro(GCP_PREPARE, senderNodeId);
9731 gcpcommitreqLab(signal);
9734 void Dbdih::gcpcommitreqLab(
Signal* signal)
9736 CRASH_INSERTION(7001);
9738 m_micro_gcp.m_master.m_state = MicroGcp::M_GCP_COMMIT;
9741 if (ERROR_INSERTED(7187))
9743 sendToRandomNodes(
"GCP_COMMIT",
9744 signal, &c_GCP_COMMIT_Counter, &Dbdih::sendGCP_COMMIT);
9745 signal->theData[0] = 9999;
9746 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
9751 sendLoopMacro(GCP_COMMIT, sendGCP_COMMIT, RNIL);
9755 void Dbdih::execGCP_NODEFINISH(
Signal* signal)
9758 const Uint32 senderNodeId = signal->theData[0];
9759 const Uint32 gci_hi = signal->theData[1];
9760 const Uint32 failureNr = signal->theData[2];
9761 const Uint32 gci_lo = signal->theData[3];
9762 const Uint64 gci = gci_lo | (Uint64(gci_hi) << 32);
9767 ndbrequire(m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_COMMIT);
9768 receiveLoopMacro(GCP_COMMIT, senderNodeId);
9772 if (m_micro_gcp.m_enabled)
9776 m_micro_gcp.m_master.m_state = MicroGcp::M_GCP_COMPLETE;
9779 rep->senderRef = reference();
9780 rep->gci_hi = (Uint32)(m_micro_gcp.m_old_gci >> 32);
9781 rep->gci_lo = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
9782 rep->flags = SubGcpCompleteRep::IN_MEMORY;
9785 if (ERROR_INSERTED(7190))
9787 sendToRandomNodes(
"GCP_COMPLETE_REP", signal,
9788 &c_SUB_GCP_COMPLETE_REP_Counter,
9789 &Dbdih::sendSUB_GCP_COMPLETE_REP);
9790 signal->theData[0] = 9999;
9791 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
9793 else if (ERROR_INSERTED(7226))
9795 ndbout_c(
"Not sending SUB_GCP_COMPLETE_REP to %u", c_error_insert_extra);
9796 c_SUB_GCP_COMPLETE_REP_Counter.clearWaitingFor();
9797 NodeRecordPtr nodePtr;
9798 nodePtr.i = cfirstAliveNode;
9801 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
9803 if (nodePtr.i != c_error_insert_extra)
9805 sendSignal(calcDihBlockRef(nodePtr.i), GSN_SUB_GCP_COMPLETE_REP,
9806 signal, SubGcpCompleteRep::SignalLength, JBA);
9808 nodePtr.i = nodePtr.p->nextNode;
9809 }
while (nodePtr.i != RNIL);
9810 SET_ERROR_INSERT_VALUE(7227);
9812 signal->theData[0] = 9999;
9813 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 200, 1);
9820 sendLoopMacro(SUB_GCP_COMPLETE_REP, sendSUB_GCP_COMPLETE_REP, RNIL);
9828 CRASH_INSERTION(7002);
9830 Uint32 curr_hi = (Uint32)(m_micro_gcp.m_current_gci >> 32);
9831 Uint32 old_hi = (Uint32)(m_micro_gcp.m_old_gci >> 32);
9833 if (m_micro_gcp.m_enabled)
9839 ndbrequire(curr_hi != old_hi);
9842 if (curr_hi == old_hi)
9851 Uint32 saveGCI = old_hi;
9852 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_REQ;
9853 m_gcp_save.m_master.m_new_gci = saveGCI;
9856 if (ERROR_INSERTED(7188))
9858 sendToRandomNodes(
"GCP_SAVE",
9859 signal, &c_GCP_SAVEREQ_Counter, &Dbdih::sendGCP_SAVEREQ);
9860 signal->theData[0] = 9999;
9861 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
9864 else if (ERROR_INSERTED(7216))
9866 infoEvent(
"GCP_SAVE all/%u", c_error_insert_extra);
9867 NodeRecordPtr nodePtr;
9868 nodePtr.i = c_error_insert_extra;
9869 ptrAss(nodePtr, nodeRecord);
9871 removeAlive(nodePtr);
9872 sendLoopMacro(GCP_SAVEREQ, sendGCP_SAVEREQ, RNIL);
9873 insertAlive(nodePtr);
9874 signal->theData[0] = 9999;
9875 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
9881 sendLoopMacro(GCP_SAVEREQ, sendGCP_SAVEREQ, RNIL);
9885 Dbdih::execSUB_GCP_COMPLETE_ACK(
Signal* signal)
9889 signal->getDataPtr());
9890 Uint32 senderNodeId = refToNode(ack.rep.senderRef);
9892 ndbrequire(m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_COMPLETE);
9893 receiveLoopMacro(SUB_GCP_COMPLETE_REP, senderNodeId);
9895 m_micro_gcp.m_master.m_state = MicroGcp::M_GCP_IDLE;
9897 if (!ERROR_INSERTED(7190))
9899 signal->theData[0] = DihContinueB::ZSTART_GCP;
9900 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 10, 1);
9905 Dbdih::execGCP_SAVEREQ(
Signal* signal)
9910 if (m_gcp_save.m_state == GcpSave::GCP_SAVE_REQ)
9917 ndbrequire(m_gcp_save.m_gci == req->gci);
9918 m_gcp_save.m_master_ref = req->dihBlockRef;
9922 if (m_gcp_save.m_gci == req->gci)
9929 m_gcp_save.m_master_ref = req->dihBlockRef;
9933 conf->dihPtr = save.dihPtr;
9934 conf->nodeId = getOwnNodeId();
9935 conf->gci = save.gci;
9936 sendSignal(m_gcp_save.m_master_ref, GSN_GCP_SAVECONF, signal,
9937 GCPSaveConf::SignalLength, JBA);
9941 ndbrequire(m_gcp_save.m_state == GcpSave::GCP_SAVE_IDLE);
9942 m_gcp_save.m_state = GcpSave::GCP_SAVE_REQ;
9943 m_gcp_save.m_master_ref = req->dihBlockRef;
9944 m_gcp_save.m_gci = req->gci;
9946 req->dihBlockRef = reference();
9947 sendSignal(DBLQH_REF, GSN_GCP_SAVEREQ, signal, signal->getLength(), JBA);
9950 void Dbdih::execGCP_SAVECONF(
Signal* signal)
9955 if (refToBlock(signal->getSendersBlockRef()) == DBLQH)
9959 ndbrequire(m_gcp_save.m_state == GcpSave::GCP_SAVE_REQ);
9960 m_gcp_save.m_state = GcpSave::GCP_SAVE_CONF;
9962 sendSignal(m_gcp_save.m_master_ref,
9963 GSN_GCP_SAVECONF, signal, signal->getLength(), JBA);
9967 ndbrequire(saveConf->gci == m_gcp_save.m_master.m_new_gci);
9968 ndbrequire(saveConf->nodeId == saveConf->dihPtr);
9969 SYSFILE->lastCompletedGCI[saveConf->nodeId] = saveConf->gci;
9970 GCP_SAVEhandling(signal, saveConf->nodeId);
9973 void Dbdih::execGCP_SAVEREF(
Signal* signal)
9978 if (refToBlock(signal->getSendersBlockRef()) == DBLQH)
9982 ndbrequire(m_gcp_save.m_state == GcpSave::GCP_SAVE_REQ);
9983 m_gcp_save.m_state = GcpSave::GCP_SAVE_CONF;
9985 sendSignal(m_gcp_save.m_master_ref,
9986 GSN_GCP_SAVEREF, signal, signal->getLength(), JBA);
9990 ndbrequire(saveRef->gci == m_gcp_save.m_master.m_new_gci);
9991 ndbrequire(saveRef->nodeId == saveRef->dihPtr);
9996 ndbrequire(saveRef->errorCode == GCPSaveRef::NodeShutdownInProgress ||
9997 saveRef->errorCode == GCPSaveRef::FakedSignalDueToNodeFailure ||
9998 saveRef->errorCode == GCPSaveRef::NodeRestartInProgress);
9999 GCP_SAVEhandling(signal, saveRef->nodeId);
10002 void Dbdih::GCP_SAVEhandling(
Signal* signal, Uint32 nodeId)
10004 ndbrequire(m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_REQ);
10005 receiveLoopMacro(GCP_SAVEREQ, nodeId);
10010 CRASH_INSERTION(7003);
10018 SYSFILE->newestRestorableGCI = m_gcp_save.m_gci;
10023 g_eventLogger->
info(
"Dbdih: Clearing initial start ongoing");
10025 Sysfile::clearInitialStartOngoing(SYSFILE->systemRestartBits);
10027 copyGciLab(signal, CopyGCIReq::GLOBAL_CHECKPOINT);
10029 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_COPY_GCI;
10037 void Dbdih::execGCP_PREPARE(
Signal* signal)
10040 CRASH_INSERTION(7005);
10042 if (ERROR_INSERTED(7030))
10045 g_eventLogger->
info(
"Delayed GCP_PREPARE 5s");
10046 sendSignalWithDelay(reference(), GSN_GCP_PREPARE, signal, 5000,
10047 signal->getLength());
10053 Uint32 masterNodeId = req->nodeId;
10054 Uint32 gci_hi = req->gci_hi;
10055 Uint32 gci_lo = req->gci_lo;
10056 if (unlikely(signal->getLength() < GCPPrepare::SignalLength))
10060 ndbassert(!ndb_check_micro_gcp(
getNodeInfo(masterNodeId).m_version));
10062 Uint64 gci = gci_lo | (Uint64(gci_hi) << 32);
10064 BlockReference retRef = calcDihBlockRef(masterNodeId);
10068 ndbrequire(m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_PREPARE);
10071 if (m_micro_gcp.m_state == MicroGcp::M_GCP_PREPARE)
10078 ndbrequire(m_micro_gcp.m_new_gci == gci);
10079 m_micro_gcp.m_master_ref = retRef;
10083 if (m_micro_gcp.m_new_gci == gci)
10090 m_micro_gcp.m_master_ref = retRef;
10094 ndbrequire(m_micro_gcp.m_state == MicroGcp::M_GCP_IDLE);
10096 m_micro_gcp.m_lock.write_lock();
10098 m_micro_gcp.m_state = MicroGcp::M_GCP_PREPARE;
10099 m_micro_gcp.m_new_gci = gci;
10100 m_micro_gcp.m_master_ref = retRef;
10101 m_micro_gcp.m_lock.write_unlock();
10103 if (ERROR_INSERTED(7031))
10105 g_eventLogger->
info(
"Crashing delayed in GCP_PREPARE 3s");
10106 signal->theData[0] = 9999;
10107 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 3000, 1);
10110 #ifdef GCP_TIMER_HACK
10111 NdbTick_getMicroTimer(&globalData.gcp_timer_commit[0]);
10122 sendSignal(SUMA_REF, GSN_GCP_PREPARE, signal, signal->
length(), JBB);
10125 conf->nodeId = cownNodeId;
10126 conf->gci_hi = gci_hi;
10127 conf->gci_lo = gci_lo;
10128 sendSignal(retRef, GSN_GCP_PREPARECONF, signal,
10129 GCPPrepareConf::SignalLength, JBA);
10133 void Dbdih::execGCP_COMMIT(
Signal* signal)
10136 CRASH_INSERTION(7006);
10139 Uint32 masterNodeId = req->nodeId;
10140 Uint32 gci_hi = req->gci_hi;
10141 Uint32 gci_lo = req->gci_lo;
10143 if (unlikely(signal->getLength() < GCPCommit::SignalLength))
10146 ndbassert(!ndb_check_micro_gcp(
getNodeInfo(masterNodeId).m_version));
10148 Uint64 gci = gci_lo | (Uint64(gci_hi) << 32);
10150 #ifdef ERROR_INSERT
10151 if (ERROR_INSERTED(7213))
10153 ndbout_c(
"err 7213 killing %d", c_error_insert_extra);
10154 Uint32 save = signal->theData[0];
10155 signal->theData[0] = 5048;
10156 sendSignal(numberToRef(DBLQH, c_error_insert_extra),
10157 GSN_NDB_TAMPER, signal, 1, JBB);
10158 signal->theData[0] = save;
10159 CLEAR_ERROR_INSERT_VALUE;
10161 signal->theData[0] = 9999;
10162 sendSignal(numberToRef(CMVMI, c_error_insert_extra),
10163 GSN_DUMP_STATE_ORD, signal, 1, JBB);
10165 signal->theData[0] = save;
10166 CLEAR_ERROR_INSERT_VALUE;
10172 Uint32 masterRef = calcDihBlockRef(masterNodeId);
10173 ndbrequire(masterNodeId == cmasterNodeId);
10176 ndbrequire(m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_COMMIT);
10179 if (m_micro_gcp.m_state == MicroGcp::M_GCP_COMMIT)
10186 ndbrequire(m_micro_gcp.m_current_gci == gci);
10187 m_micro_gcp.m_master_ref = masterRef;
10191 if (m_micro_gcp.m_current_gci == gci)
10198 m_micro_gcp.m_master_ref = masterRef;
10201 conf->nodeId = cownNodeId;
10202 conf->gci_hi = (Uint32)(m_micro_gcp.m_old_gci >> 32);
10203 conf->failno = cfailurenr;
10204 conf->gci_lo = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
10205 sendSignal(masterRef, GSN_GCP_NODEFINISH, signal,
10206 GCPNodeFinished::SignalLength, JBB);
10210 ndbrequire(m_micro_gcp.m_new_gci == gci);
10211 ndbrequire(m_micro_gcp.m_state == MicroGcp::M_GCP_PREPARE);
10212 m_micro_gcp.m_state = MicroGcp::M_GCP_COMMIT;
10213 m_micro_gcp.m_master_ref = calcDihBlockRef(masterNodeId);
10215 m_micro_gcp.m_lock.write_lock();
10216 m_micro_gcp.m_old_gci = m_micro_gcp.m_current_gci;
10217 m_micro_gcp.m_current_gci = gci;
10218 cgckptflag =
false;
10219 m_micro_gcp.m_lock.write_unlock();
10221 for (Uint32 i = 0; i < c_diverify_queue_cnt; i++)
10224 c_diverify_queue[
i].m_empty_done = 0;
10225 emptyverificbuffer(signal, i,
true);
10229 req2->senderRef = reference();
10230 req2->senderData = calcDihBlockRef(masterNodeId);
10231 req2->gci_hi = (Uint32)(m_micro_gcp.m_old_gci >> 32);
10232 req2->gci_lo = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
10233 sendSignal(clocaltcblockref, GSN_GCP_NOMORETRANS, signal,
10234 GCPNoMoreTrans::SignalLength, JBB);
10238 void Dbdih::execGCP_TCFINISHED(
Signal* signal)
10241 CRASH_INSERTION(7007);
10243 Uint32 retRef = conf->senderData;
10244 Uint32 gci_hi = conf->gci_hi;
10245 Uint32 gci_lo = conf->gci_lo;
10246 Uint64 gci = gci_lo | (Uint64(gci_hi) << 32);
10247 ndbrequire(gci == m_micro_gcp.m_old_gci);
10249 if (ERROR_INSERTED(7181) || ERROR_INSERTED(7182))
10251 c_error_7181_ref = retRef;
10252 ndbout_c(
"killing %d", refToNode(cmasterdihref));
10253 signal->theData[0] = 9999;
10254 sendSignal(numberToRef(CMVMI, refToNode(cmasterdihref)),
10255 GSN_NDB_TAMPER, signal, 1, JBB);
10259 #ifdef ERROR_INSERT
10260 if (ERROR_INSERTED(7214))
10262 ndbout_c(
"err 7214 killing %d", c_error_insert_extra);
10263 Uint32 save = signal->theData[0];
10264 signal->theData[0] = 9999;
10265 sendSignal(numberToRef(CMVMI, c_error_insert_extra),
10266 GSN_NDB_TAMPER, signal, 1, JBB);
10267 signal->theData[0] = save;
10268 CLEAR_ERROR_INSERT_VALUE;
10272 #ifdef GCP_TIMER_HACK
10273 NdbTick_getMicroTimer(&globalData.gcp_timer_commit[1]);
10276 ndbrequire(m_micro_gcp.m_state == MicroGcp::M_GCP_COMMIT);
10283 cb.m_callbackData = 10;
10284 cb.m_callbackFunction = safe_cast(&Dbdih::execGCP_TCFINISHED_sync_conf);
10285 Uint32 path[] = { DBLQH, SUMA, 0 };
10290 Dbdih::execGCP_TCFINISHED_sync_conf(
Signal* signal, Uint32 cb, Uint32 err)
10292 ndbrequire(m_micro_gcp.m_state == MicroGcp::M_GCP_COMMIT);
10294 m_micro_gcp.m_state = MicroGcp::M_GCP_COMMITTED;
10295 Uint32 retRef = m_micro_gcp.m_master_ref;
10298 conf2->nodeId = cownNodeId;
10299 conf2->gci_hi = (Uint32)(m_micro_gcp.m_old_gci >> 32);
10300 conf2->failno = cfailurenr;
10301 conf2->gci_lo = (Uint32)(m_micro_gcp.m_old_gci & 0xFFFFFFFF);
10302 sendSignal(retRef, GSN_GCP_NODEFINISH, signal,
10303 GCPNodeFinished::SignalLength, JBB);
10307 Dbdih::execSUB_GCP_COMPLETE_REP(
Signal* signal)
10311 CRASH_INSERTION(7228);
10315 ndbrequire(m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_COMPLETE);
10318 Uint32 masterRef = rep.senderRef;
10319 if (m_micro_gcp.m_state == MicroGcp::M_GCP_IDLE)
10326 m_micro_gcp.m_master_ref = masterRef;
10330 ndbrequire(m_micro_gcp.m_state == MicroGcp::M_GCP_COMMITTED);
10331 m_micro_gcp.m_state = MicroGcp::M_GCP_IDLE;
10337 sendSignal(DBLQH_REF, GSN_SUB_GCP_COMPLETE_REP, signal,
10340 Uint32 nodeId = refToNode(masterRef);
10341 if (!ndbd_dih_sub_gcp_complete_ack(
getNodeInfo(nodeId).m_version))
10348 signal->getDataPtrSend());
10350 ack->rep.senderRef = reference();
10351 sendSignal(masterRef, GSN_SUB_GCP_COMPLETE_ACK,
10352 signal, SubGcpCompleteAck::SignalLength, JBA);
10358 void Dbdih::execDIHNDBTAMPER(
Signal* signal)
10361 Uint32 tcgcpblocked = signal->theData[0];
10363 Uint32 tuserpointer = signal->theData[1];
10364 BlockReference tuserblockref = signal->theData[2];
10365 switch (tcgcpblocked) {
10370 cgcpOrderBlocked = 1;
10375 signal->theData[0] = tcgcpblocked;
10376 signal->theData[1] = tuserpointer;
10377 signal->theData[2] = tuserblockref;
10378 sendSignal(cmasterdihref, GSN_DIHNDBTAMPER, signal, 3, JBB);
10385 cgcpOrderBlocked = 0;
10390 signal->theData[0] = tcgcpblocked;
10391 signal->theData[1] = tuserpointer;
10392 signal->theData[2] = tuserblockref;
10393 sendSignal(cmasterdihref, GSN_DIHNDBTAMPER, signal, 3, JBB);
10402 signal->theData[0] = tuserpointer;
10403 signal->theData[1] = crestartGci;
10404 sendSignal(tuserblockref, GSN_DIHNDBTAMPER, signal, 2, JBB);
10406 #ifdef ERROR_INSERT
10409 if (tuserpointer >= 30000 && tuserpointer < 40000) {
10414 tuserblockref = cmasterdihref;
10415 tuserpointer -= 30000;
10416 signal->theData[0] = 5;
10417 signal->theData[1] = tuserpointer;
10418 signal->theData[2] = tuserblockref;
10419 sendSignal(tuserblockref, GSN_DIHNDBTAMPER, signal, 3, JBB);
10421 }
else if (tuserpointer >= 40000 && tuserpointer < 50000) {
10422 NodeRecordPtr localNodeptr;
10428 tuserpointer -= 40000;
10429 for (localNodeptr.i = 1;
10430 localNodeptr.i < MAX_NDB_NODES;
10431 localNodeptr.i++) {
10433 ptrAss(localNodeptr, nodeRecord);
10434 if ((localNodeptr.p->nodeStatus == NodeRecord::ALIVE) &&
10435 (localNodeptr.i != cmasterNodeId)) {
10437 tuserblockref = calcDihBlockRef(localNodeptr.i);
10449 signal->theData[0] = 5;
10450 signal->theData[1] = tuserpointer;
10451 signal->theData[2] = tuserblockref;
10452 sendSignal(tuserblockref, GSN_DIHNDBTAMPER, signal, 3, JBB);
10470 void Dbdih::copyGciLab(
Signal* signal, CopyGCIReq::CopyReason reason)
10472 if(c_copyGCIMaster.m_copyReason != CopyGCIReq::IDLE)
10478 for (Uint32 i = 0; i<CopyGCIMaster::WAIT_CNT; i++)
10481 if (c_copyGCIMaster.m_waiting[i] == CopyGCIReq::IDLE)
10484 c_copyGCIMaster.m_waiting[
i] = reason;
10496 c_copyGCIMaster.m_copyReason = reason;
10498 #ifdef ERROR_INSERT
10499 if (reason == CopyGCIReq::GLOBAL_CHECKPOINT && ERROR_INSERTED(7189))
10501 sendToRandomNodes(
"COPY_GCI",
10502 signal, &c_COPY_GCIREQ_Counter, &Dbdih::sendCOPY_GCIREQ);
10503 signal->theData[0] = 9999;
10504 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
10509 if (reason == CopyGCIReq::RESTART_NR)
10512 if (c_nodeStartMaster.startNode != RNIL)
10515 c_COPY_GCIREQ_Counter.clearWaitingFor();
10516 c_COPY_GCIREQ_Counter.
setWaitingFor(c_nodeStartMaster.startNode);
10517 sendCOPY_GCIREQ(signal, c_nodeStartMaster.startNode, RNIL);
10523 reason = c_copyGCIMaster.m_copyReason = c_copyGCIMaster.m_waiting[0];
10524 for (Uint32 i = 1; i<CopyGCIMaster::WAIT_CNT; i++)
10527 c_copyGCIMaster.m_waiting[i-1] = c_copyGCIMaster.m_waiting[
i];
10529 c_copyGCIMaster.m_waiting[CopyGCIMaster::WAIT_CNT-1] =
10532 if (reason == CopyGCIReq::IDLE)
10541 sendLoopMacro(COPY_GCIREQ, sendCOPY_GCIREQ, RNIL);
10548 void Dbdih::execCOPY_GCICONF(
Signal* signal)
10551 NodeRecordPtr senderNodePtr;
10552 senderNodePtr.i = signal->theData[0];
10553 receiveLoopMacro(COPY_GCIREQ, senderNodePtr.i);
10555 CopyGCIReq::CopyReason current = c_copyGCIMaster.m_copyReason;
10556 c_copyGCIMaster.m_copyReason = CopyGCIReq::IDLE;
10560 case CopyGCIReq::RESTART:{
10564 req->restartGci = SYSFILE->newestRestorableGCI;
10565 req->senderRef = reference();
10566 sendSignal(cdictblockref, GSN_DICTSTARTREQ,
10567 signal, DictStartReq::SignalLength, JBB);
10570 case CopyGCIReq::LOCAL_CHECKPOINT:{
10573 startLcpRoundLab(signal);
10576 case CopyGCIReq::GLOBAL_CHECKPOINT:
10584 signal->setTrace(0);
10586 signal->theData[1] = m_gcp_save.m_gci;
10587 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
10589 c_newest_restorable_gci = m_gcp_save.m_gci;
10590 #ifdef ERROR_INSERT
10591 if ((ERROR_INSERTED(7222) || ERROR_INSERTED(7223)) &&
10592 !Sysfile::getLCPOngoing(SYSFILE->systemRestartBits) &&
10593 c_newest_restorable_gci >= c_lcpState.lcpStopGcp)
10595 if (ERROR_INSERTED(7222))
10597 sendLoopMacro(COPY_TABREQ, nullRoutine, 0);
10600 rg.m_nodes.clear(getOwnNodeId());
10601 if (!rg.m_nodes.isclear())
10603 signal->theData[0] = 9999;
10604 sendSignal(rg, GSN_NDB_TAMPER, signal, 1, JBA);
10606 signal->theData[0] = 9999;
10607 sendSignalWithDelay(CMVMI_REF, GSN_NDB_TAMPER, signal, 1000, 1);
10609 signal->theData[0] = 932;
10614 if (ERROR_INSERTED(7223))
10616 CLEAR_ERROR_INSERT_VALUE;
10617 signal->theData[0] = 9999;
10618 sendSignal(numberToRef(CMVMI, c_error_insert_extra)
10619 , GSN_NDB_TAMPER, signal, 1, JBA);
10624 if (m_micro_gcp.m_enabled ==
false)
10630 signal->theData[0] = DihContinueB::ZSTART_GCP;
10631 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
10633 m_gcp_save.m_master.m_state = GcpSave::GCP_SAVE_IDLE;
10635 CRASH_INSERTION(7004);
10636 emptyWaitGCPMasterQueue(signal,
10637 Uint64(m_gcp_save.m_gci) << 32,
10638 c_waitGCPMasterList);
10641 case CopyGCIReq::INITIAL_START_COMPLETED:
10644 initialStartCompletedLab(signal);
10646 case CopyGCIReq::IDLE:
10650 case CopyGCIReq::RESTART_NR:
10653 startme_copygci_conf(signal);
10659 c_copyGCIMaster.m_copyReason = c_copyGCIMaster.m_waiting[0];
10660 for (Uint32 i = 1; i<CopyGCIMaster::WAIT_CNT; i++)
10663 c_copyGCIMaster.m_waiting[i-1] = c_copyGCIMaster.m_waiting[
i];
10665 c_copyGCIMaster.m_waiting[CopyGCIMaster::WAIT_CNT-1] = CopyGCIReq::IDLE;
10670 if(c_copyGCIMaster.m_copyReason != CopyGCIReq::IDLE)
10674 signal->theData[0] = DihContinueB::ZCOPY_GCI;
10675 signal->theData[1] = c_copyGCIMaster.m_copyReason;
10676 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
10680 void Dbdih::invalidateLcpInfoAfterSr(
Signal* signal)
10682 NodeRecordPtr nodePtr;
10683 SYSFILE->latestLCP_ID--;
10684 Sysfile::clearLCPOngoing(SYSFILE->systemRestartBits);
10685 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
10687 ptrAss(nodePtr, nodeRecord);
10695 switch (nodePtr.p->activeStatus) {
10696 case Sysfile::NS_Active:
10697 nodePtr.p->activeStatus = Sysfile::NS_Active;
10699 case Sysfile::NS_ActiveMissed_1:
10701 nodePtr.p->activeStatus = Sysfile::NS_Active;
10703 case Sysfile::NS_ActiveMissed_2:
10705 nodePtr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
10715 ndbassert(nodePtr.p->activeStatus == Sysfile::NS_Active);
10718 setNodeRestartInfoBits(signal);
10724 void Dbdih::openingCopyGciSkipInitLab(
Signal* signal, FileRecordPtr filePtr)
10726 writeRestorableGci(signal, filePtr);
10727 filePtr.p->reqStatus = FileRecord::WRITING_COPY_GCI;
10731 void Dbdih::writingCopyGciLab(
Signal* signal, FileRecordPtr filePtr)
10737 CRASH_INSERTION(7219);
10739 filePtr.p->reqStatus = FileRecord::IDLE;
10740 if (filePtr.i == crestartInfoFile[0]) {
10742 filePtr.i = crestartInfoFile[1];
10743 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
10744 if (filePtr.p->fileStatus == FileRecord::OPEN) {
10746 openingCopyGciSkipInitLab(signal, filePtr);
10749 openFileRw(signal, filePtr);
10750 filePtr.p->reqStatus = FileRecord::OPENING_COPY_GCI;
10759 CopyGCIReq::CopyReason reason = c_copyGCISlave.m_copyReason;
10761 if (reason == CopyGCIReq::GLOBAL_CHECKPOINT) {
10763 m_gcp_save.m_state = GcpSave::GCP_SAVE_IDLE;
10766 rep->gci_hi = SYSFILE->newestRestorableGCI;
10768 rep->flags = SubGcpCompleteRep::ON_DISK;
10770 sendSignal(LGMAN_REF, GSN_SUB_GCP_COMPLETE_REP, signal,
10771 SubGcpCompleteRep::SignalLength, JBB);
10775 if (m_micro_gcp.m_enabled ==
false)
10778 sendSignal(DBLQH_REF, GSN_SUB_GCP_COMPLETE_REP, signal,
10779 SubGcpCompleteRep::SignalLength, JBB);
10781 ndbrequire(m_micro_gcp.m_state == MicroGcp::M_GCP_COMMITTED);
10782 m_micro_gcp.m_state = MicroGcp::M_GCP_IDLE;
10784 CRASH_INSERTION(7190);
10787 #ifdef GCP_TIMER_HACK
10788 NdbTick_getMicroTimer(&globalData.gcp_timer_copygci[1]);
10793 Uint32 ms_commit = NdbTick_getMicrosPassed(
10794 g.gcp_timer_commit[0], g.gcp_timer_commit[1]) / 1000;
10795 Uint32 ms_save = NdbTick_getMicrosPassed(
10796 g.gcp_timer_save[0], g.gcp_timer_save[1]) / 1000;
10797 Uint32 ms_copygci = NdbTick_getMicrosPassed(
10798 g.gcp_timer_copygci[0], g.gcp_timer_copygci[1]) / 1000;
10800 Uint32 ms_total = ms_commit + ms_save + ms_copygci;
10804 g.gcp_timer_limit != 0 ?
10805 (ms_total > g.gcp_timer_limit) :
10806 (ms_total > 3000 * (1 + cgcpDelay / 1000));
10808 infoEvent(
"GCP %u ms: total:%u commit:%u save:%u copygci:%u",
10809 coldgcp, ms_total, ms_commit, ms_save, ms_copygci);
10815 c_copyGCISlave.m_copyReason = CopyGCIReq::IDLE;
10817 if (reason == CopyGCIReq::GLOBAL_CHECKPOINT)
10820 signal->theData[0] = c_copyGCISlave.m_senderData;
10821 sendSignal(m_gcp_save.m_master_ref, GSN_COPY_GCICONF, signal, 1, JBB);
10823 else if (c_copyGCISlave.m_senderRef == cmasterdihref)
10829 signal->theData[0] = c_copyGCISlave.m_senderData;
10830 sendSignal(c_copyGCISlave.m_senderRef, GSN_COPY_GCICONF, signal, 1, JBB);
10835 void Dbdih::execSTART_LCP_REQ(
Signal* signal)
10843 m_local_lcp_state.init(req);
10845 CRASH_INSERTION2(7021, isMaster());
10846 CRASH_INSERTION2(7022, !isMaster());
10848 ndbrequire(c_lcpState.m_masterLcpDihRef == req->senderRef);
10849 c_lcpState.m_participatingDIH = req->participatingDIH;
10850 c_lcpState.m_participatingLQH = req->participatingLQH;
10852 c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH = req->participatingLQH;
10856 c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH = req->participatingDIH;
10861 c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH.clearWaitingFor();
10864 c_lcpState.m_LCP_COMPLETE_REP_From_Master_Received =
false;
10866 c_lcpState.setLcpStatus(LCP_INIT_TABLES, __LINE__);
10868 signal->theData[0] = DihContinueB::ZINIT_LCP;
10869 signal->theData[1] = c_lcpState.m_masterLcpDihRef;
10870 signal->theData[2] = 0;
10871 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
10875 Dbdih::LocalLCPState::reset()
10877 m_state = LS_INITIAL;
10883 Dbdih::LocalLCPState::init(
const StartLcpReq * req)
10885 m_state = LS_RUNNING;
10886 m_start_lcp_req = *req;
10887 m_keep_gci = ~(Uint32)0;
10892 Dbdih::LocalLCPState::lcp_frag_rep(
const LcpFragRep * rep)
10894 assert(m_state == LS_RUNNING);
10895 if (rep->maxGciCompleted < m_keep_gci)
10897 m_keep_gci = rep->maxGciCompleted;
10900 if (rep->maxGciStarted > m_stop_gci)
10902 m_stop_gci = rep->maxGciStarted;
10907 Dbdih::LocalLCPState::lcp_complete_rep(Uint32 gci)
10909 assert(m_state == LS_RUNNING);
10910 m_state = LS_COMPLETE;
10911 if (gci > m_stop_gci)
10916 Dbdih::LocalLCPState::check_cut_log_tail(Uint32 gci)
const
10918 if (m_state == LS_COMPLETE)
10920 if (gci >= m_stop_gci)
10926 void Dbdih::initLcpLab(
Signal* signal, Uint32 senderRef, Uint32 tableId)
10928 TabRecordPtr tabPtr;
10929 tabPtr.i = tableId;
10931 if(c_lcpState.m_masterLcpDihRef != senderRef){
10937 g_eventLogger->
info(
"initLcpLab aborted due to LCP master takeover - 1");
10939 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
10940 sendMASTER_LCPCONF(signal);
10944 if(c_lcpState.m_masterLcpDihRef != cmasterdihref){
10950 g_eventLogger->
info(
"initLcpLab aborted due to LCP master takeover - 2");
10957 for(; tabPtr.i < ctabFileSize; tabPtr.i++){
10959 ptrAss(tabPtr, tabRecord);
10961 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
10964 tabPtr.p->tabLcpStatus = TabRecord::TLS_COMPLETED;
10968 if (tabPtr.p->tabStorage != TabRecord::ST_NORMAL) {
10973 tabPtr.p->tabLcpStatus = TabRecord::TLS_COMPLETED;
10977 if (tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE) {
10982 signal->theData[0] = DihContinueB::ZINIT_LCP;
10983 signal->theData[1] = senderRef;
10984 signal->theData[2] = tabPtr.i;
10985 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 20, 3);
10992 tabPtr.p->tabLcpStatus = TabRecord::TLS_ACTIVE;
10997 for (Uint32 fragId = 0; fragId < tabPtr.p->totalfragments; fragId++) {
10999 FragmentstorePtr fragPtr;
11000 getFragstore(tabPtr.p, fragId, fragPtr);
11005 Uint32 replicaCount = 0;
11006 ReplicaRecordPtr replicaPtr;
11007 for(replicaPtr.i = fragPtr.p->storedReplicas; replicaPtr.i != RNIL;
11008 replicaPtr.i = replicaPtr.p->nextReplica) {
11011 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
11012 Uint32 nodeId = replicaPtr.p->procNode;
11013 if(c_lcpState.m_participatingLQH.get(nodeId)){
11016 replicaPtr.p->lcpOngoingFlag =
true;
11020 fragPtr.p->noLcpReplicas = replicaCount;
11023 signal->theData[0] = DihContinueB::ZINIT_LCP;
11024 signal->theData[1] = senderRef;
11025 signal->theData[2] = tabPtr.i + 1;
11026 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
11035 if (c_lcpState.m_masterLcpDihRef != reference()){
11037 ndbrequire(!isMaster());
11038 c_lcpState.setLcpStatus(LCP_STATUS_ACTIVE, __LINE__);
11041 ndbrequire(isMaster());
11044 CRASH_INSERTION2(7023, isMaster());
11045 CRASH_INSERTION2(7024, !isMaster());
11049 conf->senderRef = reference();
11050 sendSignal(c_lcpState.m_masterLcpDihRef, GSN_START_LCP_CONF, signal,
11051 StartLcpConf::SignalLength, JBB);
11058 void Dbdih::openingCopyGciErrorLab(
Signal* signal, FileRecordPtr filePtr)
11060 createFileRw(signal, filePtr);
11064 filePtr.p->reqStatus = FileRecord::CREATING_COPY_GCI;
11072 void Dbdih::dictStartConfLab(
Signal* signal)
11077 signal->theData[0] = DihContinueB::ZSTART_FRAGMENT;
11078 signal->theData[1] = 0;
11079 signal->theData[2] = 0;
11080 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
11085 void Dbdih::openingTableLab(
Signal* signal, FileRecordPtr filePtr)
11090 TabRecordPtr tabPtr;
11091 PageRecordPtr pagePtr;
11093 tabPtr.i = filePtr.p->tabRef;
11094 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11095 tabPtr.p->noPages = 1;
11096 allocpage(pagePtr);
11097 tabPtr.p->pageRef[0] = pagePtr.i;
11098 readTabfile(signal, tabPtr.p, filePtr);
11099 filePtr.p->reqStatus = FileRecord::READING_TABLE;
11103 void Dbdih::openingTableErrorLab(
Signal* signal, FileRecordPtr filePtr)
11105 TabRecordPtr tabPtr;
11106 tabPtr.i = filePtr.p->tabRef;
11107 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11112 if (filePtr.i == tabPtr.p->tabFile[0])
11114 filePtr.i = tabPtr.p->tabFile[1];
11115 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
11116 openFileRw(signal, filePtr);
11117 filePtr.p->reqStatus = FileRecord::OPENING_TABLE;
11123 "Error opening DIH schema files for table: %d",
11125 progError(__LINE__, NDBD_EXIT_AFS_NO_SUCH_FILE, buf);
11129 void Dbdih::readingTableLab(
Signal* signal, FileRecordPtr filePtr)
11131 TabRecordPtr tabPtr;
11132 PageRecordPtr pagePtr;
11137 filePtr.p->reqStatus = FileRecord::IDLE;
11138 tabPtr.i = filePtr.p->tabRef;
11139 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11140 pagePtr.i = tabPtr.p->pageRef[0];
11141 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
11142 Uint32 noOfStoredPages = pagePtr.p->word[33];
11143 if (tabPtr.p->noPages < noOfStoredPages) {
11145 ndbrequire(noOfStoredPages <= NDB_ARRAY_SIZE(tabPtr.p->pageRef));
11146 for (Uint32 i = tabPtr.p->noPages; i < noOfStoredPages; i++) {
11148 allocpage(pagePtr);
11149 tabPtr.p->pageRef[
i] = pagePtr.i;
11151 tabPtr.p->noPages = noOfStoredPages;
11152 readTabfile(signal, tabPtr.p, filePtr);
11153 filePtr.p->reqStatus = FileRecord::READING_TABLE;
11155 ndbrequire(tabPtr.p->noPages == pagePtr.p->word[33]);
11156 ndbrequire(tabPtr.p->tabCopyStatus == TabRecord::CS_IDLE);
11162 tabPtr.p->tabCopyStatus = TabRecord::CS_SR_PHASE1_READ_PAGES;
11163 signal->theData[0] = DihContinueB::ZREAD_PAGES_INTO_TABLE;
11164 signal->theData[1] = tabPtr.i;
11165 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11171 void Dbdih::readTableFromPagesLab(
Signal* signal, TabRecordPtr tabPtr)
11173 FileRecordPtr filePtr;
11174 filePtr.i = tabPtr.p->tabFile[0];
11175 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
11181 if (filePtr.p->fileStatus != FileRecord::OPEN) {
11183 filePtr.i = tabPtr.p->tabFile[1];
11184 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
11186 closeFile(signal, filePtr);
11187 filePtr.p->reqStatus = FileRecord::CLOSING_TABLE_SR;
11191 void Dbdih::closingTableSrLab(
Signal* signal, FileRecordPtr filePtr)
11196 TabRecordPtr tabPtr;
11197 tabPtr.i = filePtr.p->tabRef;
11198 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11199 resetReplicaSr(tabPtr);
11201 signal->theData[0] = DihContinueB::ZCOPY_TABLE;
11202 signal->theData[1] = filePtr.p->tabRef;
11203 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11209 Dbdih::execDIH_GET_TABINFO_REQ(
Signal* signal)
11218 TabRecordPtr tabPtr;
11219 tabPtr.i = req.tableId;
11220 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11222 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
11225 err = DihGetTabInfoRef::TableNotDefined;
11229 if (cfirstconnect == RNIL)
11232 err = DihGetTabInfoRef::OutOfConnectionRecords;
11236 if (tabPtr.p->connectrec != RNIL)
11240 ConnectRecordPtr connectPtr;
11241 connectPtr.i = tabPtr.p->connectrec;
11242 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
11244 if (connectPtr.p->connectState != ConnectRecord::GET_TABINFO)
11247 err = DihGetTabInfoRef::TableBusy;
11252 ConnectRecordPtr connectPtr;
11253 connectPtr.i = cfirstconnect;
11254 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
11255 cfirstconnect = connectPtr.p->nextPool;
11257 connectPtr.p->nextPool = tabPtr.p->connectrec;
11258 tabPtr.p->connectrec = connectPtr.i;
11260 connectPtr.p->m_get_tabinfo.m_requestInfo = req.requestInfo;
11261 connectPtr.p->userpointer = req.senderData;
11262 connectPtr.p->userblockref = req.senderRef;
11263 connectPtr.p->connectState = ConnectRecord::GET_TABINFO;
11264 connectPtr.p->table = tabPtr.i;
11266 if (connectPtr.p->nextPool == RNIL)
11273 signal->theData[0] = DihContinueB::ZGET_TABINFO;
11274 signal->theData[1] = tabPtr.i;
11275 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11282 ref->senderData = req.senderData;
11283 ref->senderRef = reference();
11284 ref->errorCode = err;
11285 sendSignal(req.senderRef, GSN_DIH_GET_TABINFO_REF, signal,
11286 DihGetTabInfoRef::SignalLength, JBB);
11290 Dbdih::getTabInfo(
Signal* signal)
11292 TabRecordPtr tabPtr;
11293 tabPtr.i = signal->theData[1];
11294 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11296 if (tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE)
11299 signal->theData[0] = DihContinueB::ZGET_TABINFO;
11300 signal->theData[1] = tabPtr.i;
11301 sendSignalWithDelay(reference(), GSN_CONTINUEB,
11302 signal, 100, signal->
length());
11306 tabPtr.p->tabCopyStatus = TabRecord::CS_GET_TABINFO;
11308 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
11309 signal->theData[1] = tabPtr.i;
11310 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11317 PageRecordPtr pagePtr;
11318 pagePtr.i = ctn.ctnTabPtr.p->pageRef[0];
11319 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
11321 while (ctn.noOfWords > 2048)
11324 ndbrequire(
import(ptr, pagePtr.p->word, 2048));
11325 ctn.noOfWords -= 2048;
11328 pagePtr.i = ctn.ctnTabPtr.p->pageRef[ctn.pageIndex];
11329 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
11332 ndbrequire(
import(ptr, pagePtr.p->word, ctn.noOfWords));
11337 Dbdih::getTabInfo_copySectionToPages(TabRecordPtr tabPtr,
11341 Uint32 sz = ptr.sz;
11347 PageRecordPtr pagePtr;
11348 allocpage(pagePtr);
11349 tabPtr.p->pageRef[tabPtr.p->noPages] = pagePtr.i;
11350 tabPtr.p->noPages++;
11352 Uint32 len = sz > 2048 ? 2048 : sz;
11353 ndbrequire(reader.getWords(pagePtr.p->word, len));
11360 Dbdih::getTabInfo_send(
Signal* signal,
11361 TabRecordPtr tabPtr)
11363 ndbrequire(tabPtr.p->tabCopyStatus == TabRecord::CS_GET_TABINFO);
11365 ConnectRecordPtr connectPtr;
11366 connectPtr.i = tabPtr.p->connectrec;
11371 if (connectPtr.i == RNIL)
11374 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11378 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
11380 ndbrequire(connectPtr.p->connectState == ConnectRecord::GET_TABINFO);
11381 ndbrequire(connectPtr.p->table == tabPtr.i);
11388 PageRecordPtr pagePtr;
11389 pagePtr.i = tabPtr.p->pageRef[0];
11390 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
11391 Uint32 words = pagePtr.p->word[34];
11394 ctn.ctnTabPtr = tabPtr;
11397 ctn.noOfWords = words;
11400 ndbrequire(getTabInfo_copyTableToSection(ptr, ctn) == 0);
11402 Callback cb = { safe_cast(&Dbdih::getTabInfo_sendComplete), connectPtr.i };
11405 handle.m_ptr[0] = ptr;
11409 conf->senderData = connectPtr.p->userpointer;
11410 conf->senderRef = reference();
11411 sendFragmentedSignal(connectPtr.p->userblockref, GSN_DIH_GET_TABINFO_CONF, signal,
11412 DihGetTabInfoConf::SignalLength, JBB, &handle, cb);
11416 Dbdih::getTabInfo_sendComplete(
Signal * signal,
11420 ndbrequire(retVal == 0);
11422 ConnectRecordPtr connectPtr;
11423 connectPtr.i = senderData;
11424 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
11426 ndbrequire(connectPtr.p->connectState == ConnectRecord::GET_TABINFO);
11428 TabRecordPtr tabPtr;
11429 tabPtr.i = connectPtr.p->table;
11430 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11431 tabPtr.p->connectrec = connectPtr.p->nextPool;
11433 signal->theData[0] = DihContinueB::ZGET_TABINFO_SEND;
11434 signal->theData[1] = tabPtr.i;
11435 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11437 release_connect(connectPtr);
11441 Dbdih::resetReplicaSr(TabRecordPtr tabPtr){
11443 const Uint32 newestRestorableGCI = SYSFILE->newestRestorableGCI;
11445 for(Uint32 i = 0; i<tabPtr.p->totalfragments; i++)
11447 FragmentstorePtr fragPtr;
11448 getFragstore(tabPtr.p, i, fragPtr);
11453 fragPtr.p->distributionKey = 0;
11458 prepareReplicas(fragPtr);
11464 ReplicaRecordPtr replicaPtr;
11465 replicaPtr.i = fragPtr.p->oldStoredReplicas;
11466 while (replicaPtr.i != RNIL)
11469 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
11474 resetReplica(replicaPtr);
11476 const Uint32 nextReplicaPtrI = replicaPtr.p->nextReplica;
11478 NodeRecordPtr nodePtr;
11479 nodePtr.i = replicaPtr.p->procNode;
11480 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
11482 const Uint32 noCrashedReplicas = replicaPtr.p->noCrashedReplicas;
11484 if (nodePtr.p->nodeStatus == NodeRecord::ALIVE)
11487 switch (nodePtr.p->activeStatus) {
11488 case Sysfile::NS_Active:
11489 case Sysfile::NS_ActiveMissed_1:
11490 case Sysfile::NS_ActiveMissed_2:{
11495 arrGuardErr(noCrashedReplicas, MAX_CRASHED_REPLICAS, NDBD_EXIT_MAX_CRASHED_REPLICAS);
11498 newCrashedReplica(replicaPtr);
11501 Uint32 nextCrashed = replicaPtr.p->noCrashedReplicas;
11502 replicaPtr.p->createGci[nextCrashed] = newestRestorableGCI + 1;
11503 replicaPtr.p->replicaLastGci[nextCrashed] = ZINIT_REPLICA_LAST_GCI;
11506 mergeCrashedReplicas(replicaPtr);
11508 resetReplicaLcp(replicaPtr.p, newestRestorableGCI);
11514 CreateReplicaRecord createReplica;
11516 constReplicaPtr.i = replicaPtr.i;
11517 constReplicaPtr.p = replicaPtr.p;
11518 if (tabPtr.p->tabStorage != TabRecord::ST_NORMAL ||
11519 setup_create_replica(fragPtr,
11520 &createReplica, constReplicaPtr))
11523 removeOldStoredReplica(fragPtr, replicaPtr);
11524 linkStoredReplica(fragPtr, replicaPtr);
11529 infoEvent(
"Forcing take-over of node %d due to unsufficient REDO"
11530 " for table %d fragment: %d",
11531 nodePtr.i, tabPtr.i, i);
11533 m_sr_nodes.
clear(nodePtr.i);
11534 m_to_nodes.
set(nodePtr.i);
11535 setNodeActiveStatus(nodePtr.i,
11536 Sysfile::NS_NotActive_NotTakenOver);
11546 replicaPtr.i = nextReplicaPtrI;
11548 updateNodeInfo(fragPtr);
11553 Dbdih::resetReplica(ReplicaRecordPtr readReplicaPtr)
11561 for (i = 0; i < MAX_LCP_STORED; i++)
11564 if (readReplicaPtr.p->lcpStatus[i] == ZVALID &&
11565 readReplicaPtr.p->lcpId[i] > SYSFILE->latestLCP_ID)
11568 readReplicaPtr.p->lcpStatus[
i] = ZINVALID;
11576 Uint32 lastCompletedGCI = SYSFILE->newestRestorableGCI;
11577 for (i = 0; i < MAX_LCP_STORED; i++)
11580 if (readReplicaPtr.p->lcpStatus[i] == ZVALID &&
11581 readReplicaPtr.p->maxGciStarted[i] > lastCompletedGCI)
11584 readReplicaPtr.p->lcpStatus[
i] = ZINVALID;
11592 removeTooNewCrashedReplicas(readReplicaPtr, lastCompletedGCI);
11608 Dbdih::resetReplicaLcp(ReplicaRecord * replicaP, Uint32 stopGci){
11610 Uint32 lcpNo = replicaP->nextLcp;
11611 const Uint32 startLcpNo = lcpNo;
11613 lcpNo = prevLcpNo(lcpNo);
11614 ndbrequire(lcpNo < MAX_LCP_STORED);
11615 if (replicaP->lcpStatus[lcpNo] == ZVALID)
11617 if (replicaP->maxGciStarted[lcpNo] <= stopGci)
11634 replicaP->nextLcp = lcpNo;
11635 replicaP->lcpId[lcpNo] = 0;
11636 replicaP->lcpStatus[lcpNo] = ZINVALID;
11637 }
while (lcpNo != startLcpNo);
11639 replicaP->nextLcp = 0;
11642 void Dbdih::readingTableErrorLab(
Signal* signal, FileRecordPtr filePtr)
11644 TabRecordPtr tabPtr;
11645 tabPtr.i = filePtr.p->tabRef;
11646 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11650 ndbrequire(tabPtr.p->noPages <= NDB_ARRAY_SIZE(tabPtr.p->pageRef));
11651 for (Uint32 i = 0; i < tabPtr.p->noPages; i++) {
11653 releasePage(tabPtr.p->pageRef[i]);
11655 closeFile(signal, filePtr);
11656 filePtr.p->reqStatus = FileRecord::CLOSING_TABLE_CRASH;
11660 void Dbdih::closingTableCrashLab(
Signal* signal, FileRecordPtr filePtr)
11662 TabRecordPtr tabPtr;
11667 tabPtr.i = filePtr.p->tabRef;
11668 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11669 ndbrequire(filePtr.i == tabPtr.p->tabFile[0]);
11670 filePtr.i = tabPtr.p->tabFile[1];
11671 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
11672 openFileRw(signal, filePtr);
11673 filePtr.p->reqStatus = FileRecord::OPENING_TABLE;
11679 void Dbdih::execCOPY_TABREQ(
Signal* signal)
11681 CRASH_INSERTION(7172);
11683 TabRecordPtr tabPtr;
11684 PageRecordPtr pagePtr;
11686 BlockReference ref = signal->theData[0];
11687 Uint32 reqinfo = signal->theData[1];
11688 tabPtr.i = signal->theData[2];
11689 Uint32 schemaVersion = signal->theData[3];
11690 Uint32 noOfWords = signal->theData[4];
11691 ndbrequire(ref == cmasterdihref);
11692 ndbrequire(!isMaster());
11693 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11694 if (reqinfo == 1) {
11696 tabPtr.p->schemaVersion = schemaVersion;
11697 initTableFile(tabPtr);
11699 ndbrequire(tabPtr.p->noPages < NDB_ARRAY_SIZE(tabPtr.p->pageRef));
11700 if (tabPtr.p->noOfWords == 0) {
11702 allocpage(pagePtr);
11703 tabPtr.p->pageRef[tabPtr.p->noPages] = pagePtr.i;
11704 tabPtr.p->noPages++;
11707 pagePtr.i = tabPtr.p->pageRef[tabPtr.p->noPages - 1];
11708 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
11710 ndbrequire(tabPtr.p->noOfWords + 15 < 2048);
11711 ndbrequire(tabPtr.p->noOfWords < 2048);
11712 MEMCOPY_NO_WORDS(&pagePtr.p->word[tabPtr.p->noOfWords], &signal->theData[5], 16);
11713 tabPtr.p->noOfWords += 16;
11714 if (tabPtr.p->noOfWords == 2048) {
11716 tabPtr.p->noOfWords = 0;
11718 if (noOfWords > 16) {
11722 tabPtr.p->noOfWords = 0;
11723 ndbrequire(tabPtr.p->tabCopyStatus == TabRecord::CS_IDLE);
11724 tabPtr.p->tabCopyStatus = TabRecord::CS_COPY_TAB_REQ;
11725 signal->theData[0] = DihContinueB::ZREAD_PAGES_INTO_TABLE;
11726 signal->theData[1] = tabPtr.i;
11727 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11731 Dbdih::copyTabReq_complete(
Signal* signal, TabRecordPtr tabPtr){
11739 releaseTabPages(tabPtr.i);
11740 tabPtr.p->tabStatus = TabRecord::TS_ACTIVE;
11741 for (Uint32 fragId = 0; fragId < tabPtr.p->totalfragments; fragId++) {
11743 FragmentstorePtr fragPtr;
11744 getFragstore(tabPtr.p, fragId, fragPtr);
11745 updateNodeInfo(fragPtr);
11748 signal->theData[0] = cownNodeId;
11749 signal->theData[1] = tabPtr.i;
11750 sendSignal(cmasterdihref, GSN_COPY_TABCONF, signal, 2, JBB);
11756 void Dbdih::readPagesIntoTableLab(
Signal* signal, Uint32 tableId)
11761 rf.rwfTabPtr.i = tableId;
11762 ptrCheckGuard(rf.rwfTabPtr, ctabFileSize, tabRecord);
11763 rf.rwfPageptr.i = rf.rwfTabPtr.p->pageRef[0];
11764 ptrCheckGuard(rf.rwfPageptr, cpageFileSize, pageRecord);
11765 rf.rwfTabPtr.p->totalfragments = readPageWord(&rf);
11766 rf.rwfTabPtr.p->noOfBackups = readPageWord(&rf);
11767 rf.rwfTabPtr.p->hashpointer = readPageWord(&rf);
11768 rf.rwfTabPtr.p->kvalue = readPageWord(&rf);
11769 rf.rwfTabPtr.p->mask = readPageWord(&rf);
11770 rf.rwfTabPtr.p->method = (TabRecord::Method)readPageWord(&rf);
11774 rf.rwfTabPtr.p->tabStorage = (TabRecord::Storage)(readPageWord(&rf));
11776 Uint32 noOfFrags = rf.rwfTabPtr.p->totalfragments;
11777 ndbrequire(noOfFrags > 0);
11778 ndbrequire((noOfFrags * (rf.rwfTabPtr.p->noOfBackups + 1)) <= cnoFreeReplicaRec);
11779 allocFragments(noOfFrags, rf.rwfTabPtr);
11781 signal->theData[0] = DihContinueB::ZREAD_PAGES_INTO_FRAG;
11782 signal->theData[1] = rf.rwfTabPtr.i;
11783 signal->theData[2] = 0;
11784 signal->theData[3] = rf.pageIndex;
11785 signal->theData[4] = rf.wordIndex;
11786 sendSignal(reference(), GSN_CONTINUEB, signal, 5, JBB);
11790 void Dbdih::readPagesIntoFragLab(
Signal* signal, RWFragment* rf)
11792 ndbrequire(rf->pageIndex < NDB_ARRAY_SIZE(rf->rwfTabPtr.p->pageRef));
11793 rf->rwfPageptr.i = rf->rwfTabPtr.p->pageRef[rf->pageIndex];
11794 ptrCheckGuard(rf->rwfPageptr, cpageFileSize, pageRecord);
11795 FragmentstorePtr fragPtr;
11796 getFragstore(rf->rwfTabPtr.p, rf->fragId, fragPtr);
11797 readFragment(rf, fragPtr);
11798 readReplicas(rf, fragPtr);
11800 if (rf->fragId == rf->rwfTabPtr.p->totalfragments) {
11802 switch (rf->rwfTabPtr.p->tabCopyStatus) {
11803 case TabRecord::CS_SR_PHASE1_READ_PAGES:
11805 releaseTabPages(rf->rwfTabPtr.i);
11806 rf->rwfTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11807 signal->theData[0] = DihContinueB::ZREAD_TABLE_FROM_PAGES;
11808 signal->theData[1] = rf->rwfTabPtr.i;
11809 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11812 case TabRecord::CS_COPY_TAB_REQ:
11814 rf->rwfTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11816 rf->rwfTabPtr.p->tabStorage == TabRecord::ST_NORMAL)
11823 copyTabReq_complete(signal, rf->rwfTabPtr);
11826 rf->rwfTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11827 rf->rwfTabPtr.p->tabUpdateState = TabRecord::US_COPY_TAB_REQ;
11828 signal->theData[0] = DihContinueB::ZTABLE_UPDATE;
11829 signal->theData[1] = rf->rwfTabPtr.i;
11830 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11840 signal->theData[0] = DihContinueB::ZREAD_PAGES_INTO_FRAG;
11841 signal->theData[1] = rf->rwfTabPtr.i;
11842 signal->theData[2] = rf->fragId;
11843 signal->theData[3] = rf->pageIndex;
11844 signal->theData[4] = rf->wordIndex;
11845 sendSignal(reference(), GSN_CONTINUEB, signal, 5, JBB);
11854 void Dbdih::packTableIntoPagesLab(
Signal* signal, Uint32 tableId)
11857 TabRecordPtr tabPtr;
11858 allocpage(wf.rwfPageptr);
11859 tabPtr.i = tableId;
11860 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
11861 tabPtr.p->pageRef[0] = wf.rwfPageptr.i;
11862 tabPtr.p->noPages = 1;
11865 Uint32 totalfragments = tabPtr.p->totalfragments;
11866 if (tabPtr.p->connectrec != RNIL)
11870 connectPtr.i = tabPtr.p->connectrec;
11871 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
11872 ndbrequire(connectPtr.p->table == tabPtr.i);
11873 if (connectPtr.p->connectState == ConnectRecord::ALTER_TABLE)
11876 totalfragments = connectPtr.p->m_alter.m_totalfragments;
11880 writePageWord(&wf, totalfragments);
11881 writePageWord(&wf, tabPtr.p->noOfBackups);
11882 writePageWord(&wf, tabPtr.p->hashpointer);
11883 writePageWord(&wf, tabPtr.p->kvalue);
11884 writePageWord(&wf, tabPtr.p->mask);
11885 writePageWord(&wf, tabPtr.p->method);
11886 writePageWord(&wf, tabPtr.p->tabStorage);
11888 signal->theData[0] = DihContinueB::ZPACK_FRAG_INTO_PAGES;
11889 signal->theData[1] = tabPtr.i;
11890 signal->theData[2] = 0;
11891 signal->theData[3] = wf.pageIndex;
11892 signal->theData[4] = wf.wordIndex;
11893 signal->theData[5] = totalfragments;
11894 sendSignal(reference(), GSN_CONTINUEB, signal, 6, JBB);
11900 void Dbdih::packFragIntoPagesLab(
Signal* signal, RWFragment* wf)
11902 ndbrequire(wf->pageIndex < NDB_ARRAY_SIZE(wf->rwfTabPtr.p->pageRef));
11903 wf->rwfPageptr.i = wf->rwfTabPtr.p->pageRef[wf->pageIndex];
11904 ptrCheckGuard(wf->rwfPageptr, cpageFileSize, pageRecord);
11905 FragmentstorePtr fragPtr;
11906 getFragstore(wf->rwfTabPtr.p, wf->fragId, fragPtr);
11907 writeFragment(wf, fragPtr);
11908 writeReplicas(wf, fragPtr.p->storedReplicas);
11909 writeReplicas(wf, fragPtr.p->oldStoredReplicas);
11911 if (wf->fragId == wf->totalfragments) {
11913 PageRecordPtr pagePtr;
11914 pagePtr.i = wf->rwfTabPtr.p->pageRef[0];
11915 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
11916 pagePtr.p->word[33] = wf->rwfTabPtr.p->noPages;
11917 pagePtr.p->word[34] = ((wf->rwfTabPtr.p->noPages - 1) * 2048) + wf->wordIndex;
11918 switch (wf->rwfTabPtr.p->tabCopyStatus) {
11919 case TabRecord::CS_SR_PHASE2_READ_TABLE:
11925 wf->rwfTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11926 signal->theData[0] = DihContinueB::ZSR_PHASE2_READ_TABLE;
11927 signal->theData[1] = wf->rwfTabPtr.i;
11928 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11931 case TabRecord::CS_COPY_NODE_STATE:
11933 tableCopyNodeLab(signal, wf->rwfTabPtr);
11936 case TabRecord::CS_LCP_READ_TABLE:
11938 signal->theData[0] = DihContinueB::ZTABLE_UPDATE;
11939 signal->theData[1] = wf->rwfTabPtr.i;
11940 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11943 case TabRecord::CS_REMOVE_NODE:
11944 case TabRecord::CS_INVALIDATE_NODE_LCP:
11946 signal->theData[0] = DihContinueB::ZTABLE_UPDATE;
11947 signal->theData[1] = wf->rwfTabPtr.i;
11948 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11951 case TabRecord::CS_ADD_TABLE_MASTER:
11953 wf->rwfTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11954 signal->theData[0] = DihContinueB::ZADD_TABLE_MASTER_PAGES;
11955 signal->theData[1] = wf->rwfTabPtr.i;
11956 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11959 case TabRecord::CS_ADD_TABLE_SLAVE:
11961 wf->rwfTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
11962 signal->theData[0] = DihContinueB::ZADD_TABLE_SLAVE_PAGES;
11963 signal->theData[1] = wf->rwfTabPtr.i;
11964 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11966 case TabRecord::CS_COPY_TO_SAVE:
11967 signal->theData[0] = DihContinueB::ZTABLE_UPDATE;
11968 signal->theData[1] = wf->rwfTabPtr.i;
11969 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11971 case TabRecord::CS_GET_TABINFO:
11973 signal->theData[0] = DihContinueB::ZGET_TABINFO_SEND;
11974 signal->theData[1] = wf->rwfTabPtr.i;
11975 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
11984 signal->theData[0] = DihContinueB::ZPACK_FRAG_INTO_PAGES;
11985 signal->theData[1] = wf->rwfTabPtr.i;
11986 signal->theData[2] = wf->fragId;
11987 signal->theData[3] = wf->pageIndex;
11988 signal->theData[4] = wf->wordIndex;
11989 signal->theData[5] = wf->totalfragments;
11990 sendSignal(reference(), GSN_CONTINUEB, signal, 6, JBB);
11999 Dbdih::dump_replica_info()
12001 TabRecordPtr tabPtr;
12002 FragmentstorePtr fragPtr;
12004 for(tabPtr.i = 0; tabPtr.i < ctabFileSize; tabPtr.i++)
12006 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
12007 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
12010 for(Uint32 fid = 0; fid<tabPtr.p->totalfragments; fid++)
12012 getFragstore(tabPtr.p, fid, fragPtr);
12013 ndbout_c(
"tab: %d frag: %d gci: %d\n",
12014 tabPtr.i, fid, SYSFILE->newestRestorableGCI);
12016 dump_replica_info(fragPtr.p);
12022 Dbdih::dump_replica_info(
const Fragmentstore* fragPtrP)
12024 ndbout_c(
" -- storedReplicas: ");
12026 ReplicaRecordPtr replicaPtr;
12027 replicaPtr.i = fragPtrP->storedReplicas;
12028 for(; replicaPtr.i != RNIL; replicaPtr.i = replicaPtr.p->nextReplica)
12030 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
12031 ndbout_c(
" node: %d initialGci: %d nextLcp: %d noCrashedReplicas: %d",
12032 replicaPtr.p->procNode,
12033 replicaPtr.p->initialGci,
12034 replicaPtr.p->nextLcp,
12035 replicaPtr.p->noCrashedReplicas);
12036 for(i = 0; i<MAX_LCP_STORED; i++)
12038 ndbout_c(
" i: %d %s : lcpId: %d maxGci Completed: %d Started: %d",
12040 (replicaPtr.p->lcpStatus[i] == ZVALID ?
"VALID":
"INVALID"),
12041 replicaPtr.p->lcpId[i],
12042 replicaPtr.p->maxGciCompleted[i],
12043 replicaPtr.p->maxGciStarted[i]);
12046 for (i = 0; i < 8; i++)
12048 ndbout_c(
" crashed replica: %d replicaLastGci: %d createGci: %d",
12050 replicaPtr.p->replicaLastGci[i],
12051 replicaPtr.p->createGci[i]);
12054 ndbout_c(
" -- oldStoredReplicas");
12055 replicaPtr.i = fragPtrP->oldStoredReplicas;
12056 for(; replicaPtr.i != RNIL; replicaPtr.i = replicaPtr.p->nextReplica)
12058 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
12059 ndbout_c(
" node: %d initialGci: %d nextLcp: %d noCrashedReplicas: %d",
12060 replicaPtr.p->procNode,
12061 replicaPtr.p->initialGci,
12062 replicaPtr.p->nextLcp,
12063 replicaPtr.p->noCrashedReplicas);
12064 for(i = 0; i<MAX_LCP_STORED; i++)
12066 ndbout_c(
" i: %d %s : lcpId: %d maxGci Completed: %d Started: %d",
12068 (replicaPtr.p->lcpStatus[i] == ZVALID ?
"VALID":
"INVALID"),
12069 replicaPtr.p->lcpId[i],
12070 replicaPtr.p->maxGciCompleted[i],
12071 replicaPtr.p->maxGciStarted[i]);
12074 for (i = 0; i < 8; i++)
12076 ndbout_c(
" crashed replica: %d replicaLastGci: %d createGci: %d",
12078 replicaPtr.p->replicaLastGci[i],
12079 replicaPtr.p->createGci[i]);
12084 void Dbdih::startFragment(
Signal* signal, Uint32 tableId, Uint32 fragId)
12086 Uint32 TloopCount = 0;
12087 TabRecordPtr tabPtr;
12089 if (TloopCount > 100) {
12091 signal->theData[0] = DihContinueB::ZSTART_FRAGMENT;
12092 signal->theData[1] = tableId;
12093 signal->theData[2] = 0;
12094 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
12098 if (tableId >= ctabFileSize) {
12100 signal->theData[0] = DihContinueB::ZCOMPLETE_RESTART;
12101 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
12105 tabPtr.i = tableId;
12106 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
12107 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE){
12115 if(tabPtr.p->tabStorage != TabRecord::ST_NORMAL){
12127 FragmentstorePtr fragPtr;
12128 getFragstore(tabPtr.p, fragId, fragPtr);
12135 cnoOfCreateReplicas = 0;
12140 ndbrequire(tabPtr.p->noOfBackups < MAX_REPLICAS);
12144 searchStoredReplicas(fragPtr);
12146 if (cnoOfCreateReplicas == 0) {
12157 tableId, fragId, SYSFILE->newestRestorableGCI);
12159 ndbout_c(
"%s", buf);
12160 dump_replica_info();
12162 progError(__LINE__, NDBD_EXIT_NO_RESTORABLE_REPLICA, buf);
12172 updateNodeInfo(fragPtr);
12180 CreateReplicaRecordPtr createReplicaPtr;
12181 for (createReplicaPtr.i = 0;
12182 createReplicaPtr.i < cnoOfCreateReplicas;
12183 createReplicaPtr.i++) {
12185 ptrCheckGuard(createReplicaPtr, 4, createReplicaRecord);
12188 sendStartFragreq(signal, tabPtr, fragId);
12194 if (fragId >= tabPtr.p->totalfragments) {
12199 signal->theData[0] = DihContinueB::ZSTART_FRAGMENT;
12200 signal->theData[1] = tabPtr.i;
12201 signal->theData[2] = fragId;
12202 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
12211 void Dbdih::completeRestartLab(
Signal* signal)
12213 sendLoopMacro(START_RECREQ, sendSTART_RECREQ, RNIL);
12225 void Dbdih::execSTART_RECCONF(
Signal* signal)
12228 Uint32 senderNodeId = signal->theData[0];
12229 Uint32 senderData = signal->theData[1];
12231 if (senderData != RNIL)
12237 c_takeOverPool.
getPtr(takeOverPtr, senderData);
12238 sendStartTo(signal, takeOverPtr);
12246 receiveLoopMacro(START_RECREQ, senderNodeId);
12252 while ((i = m_to_nodes.
find(i + 1)) != NdbNodeBitmask::NotFound)
12255 NodeRecordPtr nodePtr;
12257 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
12258 nodePtr.p->copyCompleted = 0;
12261 if (m_to_nodes.
get(getOwnNodeId()))
12268 c_sr_wait_to =
true;
12271 if (!m_to_nodes.
isclear() && c_sr_wait_to)
12276 req->senderRef = reference();
12277 req->senderData = getOwnNodeId();
12281 while ((i = m_to_nodes.
find(i + 1)) != NdbNodeBitmask::NotFound)
12284 req->startingNodeId =
i;
12285 sendSignal(calcDihBlockRef(i), GSN_START_COPYREQ, signal,
12286 StartCopyReq::SignalLength, JBB);
12294 signal->theData[0] = reference();
12295 m_sr_nodes.
copyto(NdbNodeBitmask::Size, signal->theData+1);
12296 sendSignal(cntrlblockref, GSN_NDB_STARTCONF, signal,
12297 1 + NdbNodeBitmask::Size, JBB);
12300 void Dbdih::copyNodeLab(
Signal* signal, Uint32 tableId)
12306 Uint32 TloopCount = 0;
12308 if (!c_nodeStartMaster.activeState) {
12314 c_nodeStartMaster.wait = ZFALSE;
12317 TabRecordPtr tabPtr;
12318 tabPtr.i = tableId;
12319 while (tabPtr.i < ctabFileSize) {
12320 ptrAss(tabPtr, tabRecord);
12321 if (tabPtr.p->tabStatus == TabRecord::TS_ACTIVE)
12331 if (! (tabPtr.p->tabCopyStatus == TabRecord::CS_IDLE))
12334 signal->theData[0] = DihContinueB::ZCOPY_NODE;
12335 signal->theData[1] = tabPtr.i;
12336 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 100, 2);
12339 ndbrequire(tabPtr.p->tabCopyStatus == TabRecord::CS_IDLE);
12340 tabPtr.p->tabCopyStatus = TabRecord::CS_COPY_NODE_STATE;
12341 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
12342 signal->theData[1] = tabPtr.i;
12343 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
12347 if (TloopCount > 100) {
12352 signal->theData[0] = DihContinueB::ZCOPY_NODE;
12353 signal->theData[1] = tabPtr.i + 1;
12354 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
12363 dihCopyCompletedLab(signal);
12367 void Dbdih::tableCopyNodeLab(
Signal* signal, TabRecordPtr tabPtr)
12372 if (!c_nodeStartMaster.activeState) {
12374 releaseTabPages(tabPtr.i);
12375 c_nodeStartMaster.wait = ZFALSE;
12378 NodeRecordPtr copyNodePtr;
12379 PageRecordPtr pagePtr;
12380 copyNodePtr.i = c_nodeStartMaster.startNode;
12381 ptrCheckGuard(copyNodePtr, MAX_NDB_NODES, nodeRecord);
12383 copyNodePtr.p->activeTabptr = tabPtr.i;
12384 pagePtr.i = tabPtr.p->pageRef[0];
12385 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
12387 signal->theData[0] = DihContinueB::ZCOPY_TABLE_NODE;
12388 signal->theData[1] = tabPtr.i;
12389 signal->theData[2] = copyNodePtr.i;
12390 signal->theData[3] = 0;
12391 signal->theData[4] = 0;
12392 signal->theData[5] = pagePtr.p->word[34];
12393 sendSignal(reference(), GSN_CONTINUEB, signal, 6, JBB);
12402 void Dbdih::copyTableLab(
Signal* signal, Uint32 tableId)
12404 TabRecordPtr tabPtr;
12405 tabPtr.i = tableId;
12406 ptrAss(tabPtr, tabRecord);
12408 ndbrequire(tabPtr.p->tabCopyStatus == TabRecord::CS_IDLE);
12409 tabPtr.p->tabCopyStatus = TabRecord::CS_SR_PHASE2_READ_TABLE;
12410 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
12411 signal->theData[1] = tabPtr.i;
12412 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
12419 void Dbdih::srPhase2ReadTableLab(
Signal* signal, TabRecordPtr tabPtr)
12432 breakCopyTableLab(signal, tabPtr, cfirstAliveNode);
12439 void Dbdih::breakCopyTableLab(
Signal* signal, TabRecordPtr tabPtr, Uint32 nodeId)
12441 NodeRecordPtr nodePtr;
12442 nodePtr.i = nodeId;
12443 while (nodePtr.i != RNIL) {
12445 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
12446 if (nodePtr.i == getOwnNodeId()){
12458 tabPtr.p->tabUpdateState = TabRecord::US_COPY_TAB_REQ;
12459 signal->theData[0] = DihContinueB::ZTABLE_UPDATE;
12460 signal->theData[1] = tabPtr.i;
12461 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
12462 nodePtr.i = nodePtr.p->nextNode;
12464 PageRecordPtr pagePtr;
12471 tabPtr.p->tabCopyStatus = TabRecord::CS_SR_PHASE3_COPY_TABLE;
12472 pagePtr.i = tabPtr.p->pageRef[0];
12473 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
12474 signal->theData[0] = DihContinueB::ZCOPY_TABLE_NODE;
12475 signal->theData[1] = tabPtr.i;
12476 signal->theData[2] = nodePtr.i;
12477 signal->theData[3] = 0;
12478 signal->theData[4] = 0;
12479 signal->theData[5] = pagePtr.p->word[34];
12480 sendSignal(reference(), GSN_CONTINUEB, signal, 6, JBB);
12494 void Dbdih::copyTableNode(
Signal* signal,
12495 CopyTableNode* ctn, NodeRecordPtr nodePtr)
12503 if (!c_nodeStartMaster.activeState) {
12509 releaseTabPages(ctn->ctnTabPtr.i);
12510 c_nodeStartMaster.wait = ZFALSE;
12514 ndbrequire(ctn->pageIndex < NDB_ARRAY_SIZE(ctn->ctnTabPtr.p->pageRef));
12515 ctn->ctnPageptr.i = ctn->ctnTabPtr.p->pageRef[ctn->pageIndex];
12516 ptrCheckGuard(ctn->ctnPageptr, cpageFileSize, pageRecord);
12520 Uint32 reqinfo = (ctn->pageIndex == 0) && (ctn->wordIndex == 0);
12525 for (Uint32 i = 0; i < 16; i++) {
12527 sendCopyTable(signal, ctn, calcDihBlockRef(nodePtr.i), reqinfo);
12529 if (ctn->noOfWords <= 16) {
12531 switch (ctn->ctnTabPtr.p->tabCopyStatus) {
12532 case TabRecord::CS_SR_PHASE3_COPY_TABLE:
12539 ctn->ctnTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
12540 breakCopyTableLab(signal, ctn->ctnTabPtr, nodePtr.p->nextNode);
12543 case TabRecord::CS_COPY_NODE_STATE:
12545 ctn->ctnTabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
12554 ctn->wordIndex += 16;
12555 if (ctn->wordIndex == 2048) {
12557 ctn->wordIndex = 0;
12559 ndbrequire(ctn->pageIndex < NDB_ARRAY_SIZE(ctn->ctnTabPtr.p->pageRef));
12560 ctn->ctnPageptr.i = ctn->ctnTabPtr.p->pageRef[ctn->pageIndex];
12561 ptrCheckGuard(ctn->ctnPageptr, cpageFileSize, pageRecord);
12563 ctn->noOfWords -= 16;
12566 signal->theData[0] = DihContinueB::ZCOPY_TABLE_NODE;
12567 signal->theData[1] = ctn->ctnTabPtr.i;
12568 signal->theData[2] = nodePtr.i;
12569 signal->theData[3] = ctn->pageIndex;
12570 signal->theData[4] = ctn->wordIndex;
12571 signal->theData[5] = ctn->noOfWords;
12572 sendSignal(reference(), GSN_CONTINUEB, signal, 6, JBB);
12575 void Dbdih::sendCopyTable(
Signal* signal, CopyTableNode* ctn,
12576 BlockReference ref, Uint32 reqinfo)
12578 signal->theData[0] = reference();
12579 signal->theData[1] = reqinfo;
12580 signal->theData[2] = ctn->ctnTabPtr.i;
12581 signal->theData[3] = ctn->ctnTabPtr.p->schemaVersion;
12582 signal->theData[4] = ctn->noOfWords;
12583 ndbrequire(ctn->wordIndex + 15 < 2048);
12584 MEMCOPY_NO_WORDS(&signal->theData[5], &ctn->ctnPageptr.p->word[ctn->wordIndex], 16);
12585 sendSignal(ref, GSN_COPY_TABREQ, signal, 21, JBB);
12588 void Dbdih::execCOPY_TABCONF(
Signal* signal)
12590 NodeRecordPtr nodePtr;
12592 nodePtr.i = signal->theData[0];
12593 Uint32 tableId = signal->theData[1];
12600 NodeRecordPtr nodePtr;
12601 nodePtr.i = signal->theData[0];
12602 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
12603 c_COPY_TABREQ_Counter.clearWaitingFor(nodePtr.i);
12605 releaseTabPages(tableId);
12606 signal->theData[0] = DihContinueB::ZCOPY_NODE;
12607 signal->theData[1] = tableId + 1;
12608 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
12616 receiveLoopMacro(COPY_TABREQ, nodePtr.i);
12623 releaseTabPages(tableId);
12625 TabRecordPtr tabPtr;
12626 tabPtr.i = tableId;
12627 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
12629 ConnectRecordPtr connectPtr;
12630 connectPtr.i = tabPtr.p->connectrec;
12631 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
12633 connectPtr.p->m_alter.m_totalfragments = tabPtr.p->totalfragments;
12634 sendAddFragreq(signal, connectPtr, tabPtr, 0);
12651 void Dbdih::checkTcCounterLab(
Signal* signal)
12653 CRASH_INSERTION(7009);
12654 if (c_lcpState.lcpStatus != LCP_STATUS_IDLE) {
12655 g_eventLogger->
error(
"lcpStatus = %u"
12656 "lcpStatusUpdatedPlace = %d",
12657 (Uint32) c_lcpState.lcpStatus,
12658 c_lcpState.lcpStatusUpdatedPlace);
12662 add_lcp_counter(&c_lcpState.ctimer, 32);
12663 if ((c_nodeStartMaster.blockLcp ==
true) ||
12664 (c_lcpState.lcpStopGcp >= c_newest_restorable_gci)) {
12672 signal->theData[0] = DihContinueB::ZCHECK_TC_COUNTER;
12673 signal->theData[1] = __LINE__;
12674 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 1 * 100, 2);
12677 c_lcpState.setLcpStatus(LCP_TCGET, __LINE__);
12679 c_lcpState.ctcCounter = c_lcpState.ctimer;
12680 sendLoopMacro(TCGETOPSIZEREQ, sendTCGETOPSIZEREQ, RNIL);
12683 void Dbdih::checkLcpStart(
Signal* signal, Uint32 lineNo)
12689 ndbrequire(c_lcpState.lcpStart == ZIDLE);
12690 c_lcpState.lcpStart = ZACTIVE;
12691 signal->theData[0] = DihContinueB::ZCHECK_TC_COUNTER;
12692 signal->theData[1] = lineNo;
12693 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 1000, 2);
12699 void Dbdih::execTCGETOPSIZECONF(
Signal* signal)
12702 Uint32 senderNodeId = signal->theData[0];
12703 add_lcp_counter(&c_lcpState.ctcCounter, signal->theData[1]);
12705 receiveLoopMacro(TCGETOPSIZEREQ, senderNodeId);
12707 ndbrequire(c_lcpState.lcpStatus == LCP_TCGET);
12708 ndbrequire(c_lcpState.lcpStart == ZACTIVE);
12718 if (c_lcpState.immediateLcpStart ==
false)
12720 Uint64 cnt = Uint64(c_lcpState.ctcCounter);
12721 Uint64
limit = Uint64(1) << c_lcpState.clcpDelay;
12722 bool dostart = cnt >=
limit;
12723 if (dostart ==
false || c_nodeStartMaster.blockLcp ==
true)
12726 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
12728 signal->theData[0] = DihContinueB::ZCHECK_TC_COUNTER;
12729 signal->theData[1] = __LINE__;
12730 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 1 * 100, 2);
12734 c_lcpState.lcpStart = ZIDLE;
12735 c_lcpState.immediateLcpStart =
false;
12740 CRASH_INSERTION(7010);
12748 c_lcpState.ctimer = 0;
12749 c_lcpState.keepGci = (Uint32)(m_micro_gcp.m_old_gci >> 32);
12750 c_lcpState.oldestRestorableGci = SYSFILE->oldestRestorableGCI;
12752 CRASH_INSERTION(7014);
12753 c_lcpState.setLcpStatus(LCP_TC_CLOPSIZE, __LINE__);
12754 sendLoopMacro(TC_CLOPSIZEREQ, sendTC_CLOPSIZEREQ, RNIL);
12757 void Dbdih::execTC_CLOPSIZECONF(
Signal* signal)
12760 Uint32 senderNodeId = signal->theData[0];
12761 receiveLoopMacro(TC_CLOPSIZEREQ, senderNodeId);
12763 ndbrequire(c_lcpState.lcpStatus == LCP_TC_CLOPSIZE);
12768 cnoOfActiveTables = 0;
12769 c_lcpState.setLcpStatus(LCP_CALCULATE_KEEP_GCI, __LINE__);
12770 ndbrequire(((
int)c_lcpState.oldestRestorableGci) > 0);
12772 if (ERROR_INSERTED(7011)) {
12774 signal->theData[1] = 0;
12775 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
12779 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
12780 Callback c = { safe_cast(&Dbdih::lcpFragmentMutex_locked), 0 };
12781 ndbrequire(mutex.trylock(c,
false));
12785 Dbdih::lcpFragmentMutex_locked(
Signal* signal,
12791 if (retVal == UtilLockRef::LockAlreadyHeld)
12794 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
12797 if (senderData == 0)
12800 infoEvent(
"Local checkpoint blocked waiting for node-restart");
12804 if (senderData >= 2*c_lcpState.m_lcp_trylock_timeout)
12807 Callback c = { safe_cast(&Dbdih::lcpFragmentMutex_locked), 0 };
12808 ndbrequire(mutex.lock(c,
false));
12811 signal->theData[0] = DihContinueB::ZLCP_TRY_LOCK;
12812 signal->theData[1] = senderData + 1;
12813 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 500, 2);
12817 ndbrequire(retVal == 0);
12819 c_lcpState.m_start_time = c_current_time;
12821 setLcpActiveStatusStart(signal);
12823 c_lcpState.keepGci = m_micro_gcp.m_old_gci >> 32;
12824 c_lcpState.oldestRestorableGci = SYSFILE->oldestRestorableGCI;
12826 signal->theData[0] = DihContinueB::ZCALCULATE_KEEP_GCI;
12827 signal->theData[1] = 0;
12828 signal->theData[2] = 0;
12829 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
12837 void Dbdih::calculateKeepGciLab(
Signal* signal, Uint32 tableId, Uint32 fragId)
12839 TabRecordPtr tabPtr;
12840 Uint32 TloopCount = 1;
12841 tabPtr.i = tableId;
12843 if (tabPtr.i >= ctabFileSize) {
12844 if (cnoOfActiveTables > 0) {
12846 signal->theData[0] = DihContinueB::ZSTORE_NEW_LCP_ID;
12847 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
12855 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
12856 checkLcpStart(signal, __LINE__);
12860 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
12861 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE ||
12862 tabPtr.p->tabStorage != TabRecord::ST_NORMAL) {
12863 if (TloopCount > 100) {
12865 signal->theData[0] = DihContinueB::ZCALCULATE_KEEP_GCI;
12866 signal->theData[1] = tabPtr.i + 1;
12867 signal->theData[2] = 0;
12868 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
12879 }
while (TloopCount != 0);
12880 cnoOfActiveTables++;
12881 FragmentstorePtr fragPtr;
12882 getFragstore(tabPtr.p, fragId, fragPtr);
12883 checkKeepGci(tabPtr, fragId, fragPtr.p, fragPtr.p->storedReplicas);
12884 checkKeepGci(tabPtr, fragId, fragPtr.p, fragPtr.p->oldStoredReplicas);
12886 if (fragId >= tabPtr.p->totalfragments) {
12891 signal->theData[0] = DihContinueB::ZCALCULATE_KEEP_GCI;
12892 signal->theData[1] = tabPtr.i;
12893 signal->theData[2] = fragId;
12894 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
12903 void Dbdih::storeNewLcpIdLab(
Signal* signal)
12906 signal->theData[1] = SYSFILE->latestLCP_ID + 1;
12907 signal->theData[2] = c_lcpState.keepGci;
12908 signal->theData[3] = c_lcpState.oldestRestorableGci;
12909 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 4, JBB);
12915 signal->setTrace(TestOrd::TraceLocalCheckpoint);
12917 CRASH_INSERTION(7013);
12918 SYSFILE->keepGCI = c_lcpState.keepGci;
12920 SYSFILE->latestLCP_ID++;
12921 SYSFILE->oldestRestorableGCI = c_lcpState.oldestRestorableGci;
12923 const Uint32 oldestRestorableGCI = SYSFILE->oldestRestorableGCI;
12927 Int32 val = oldestRestorableGCI;
12928 ndbrequire(val > 0);
12934 SYSFILE->setLCPOngoing(SYSFILE->systemRestartBits);
12945 setNodeRestartInfoBits(signal);
12947 c_lcpState.setLcpStatus(LCP_COPY_GCI, __LINE__);
12954 copyGciLab(signal, CopyGCIReq::LOCAL_CHECKPOINT);
12957 void Dbdih::startLcpRoundLab(
Signal* signal) {
12960 CRASH_INSERTION(7218);
12962 Mutex mutex(signal, c_mutexMgr, c_startLcpMutexHandle);
12963 Callback c = { safe_cast(&Dbdih::startLcpMutex_locked), 0 };
12964 ndbrequire(mutex.lock(c));
12968 Dbdih::startLcpMutex_locked(
Signal* signal, Uint32 senderData, Uint32 retVal){
12970 ndbrequire(retVal == 0);
12973 req->senderRef = reference();
12974 req->lcpId = SYSFILE->latestLCP_ID;
12975 req->participatingLQH = c_lcpState.m_participatingLQH;
12976 req->participatingDIH = c_lcpState.m_participatingDIH;
12977 sendLoopMacro(START_LCP_REQ, sendSTART_LCP_REQ, RNIL);
12981 Dbdih::sendSTART_LCP_REQ(
Signal* signal, Uint32 nodeId, Uint32 extra){
12982 BlockReference ref = calcDihBlockRef(nodeId);
12983 if (ERROR_INSERTED(7021) && nodeId == getOwnNodeId())
12985 sendSignalWithDelay(ref, GSN_START_LCP_REQ, signal, 500,
12986 StartLcpReq::SignalLength);
12989 else if (ERROR_INSERTED(7021) && ((rand() % 10) > 4))
12991 infoEvent(
"Dont sent STARTLCPREQ to %u", nodeId);
12994 sendSignal(ref, GSN_START_LCP_REQ, signal, StartLcpReq::SignalLength, JBB);
12998 Dbdih::execSTART_LCP_CONF(
Signal* signal){
13001 Uint32 nodeId = refToNode(conf->senderRef);
13002 receiveLoopMacro(START_LCP_REQ, nodeId);
13004 Mutex mutex(signal, c_mutexMgr, c_startLcpMutexHandle);
13005 Callback c = { safe_cast(&Dbdih::startLcpMutex_unlocked), 0 };
13010 Dbdih::startLcpMutex_unlocked(
Signal* signal, Uint32 data, Uint32 retVal){
13012 ndbrequire(retVal == 0);
13014 Mutex mutex(signal, c_mutexMgr, c_startLcpMutexHandle);
13020 c_lcpState.m_LAST_LCP_FRAG_ORD = c_lcpState.m_participatingLQH;
13022 CRASH_INSERTION(7015);
13023 c_lcpState.setLcpStatus(LCP_START_LCP_ROUND, __LINE__);
13024 startLcpRoundLoopLab(signal, 0, 0);
13028 Dbdih::master_lcp_fragmentMutex_locked(
Signal* signal,
13029 Uint32 failedNodePtrI, Uint32 retVal)
13032 ndbrequire(retVal == 0);
13035 signal->theData[1] = c_lcpMasterTakeOverState.state;
13036 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
13038 signal->theData[0] = 7012;
13039 execDUMP_STATE_ORD(signal);
13041 c_lcpMasterTakeOverState.set(LMTOS_IDLE, __LINE__);
13043 checkLocalNodefailComplete(signal, failedNodePtrI, NF_LCP_TAKE_OVER);
13045 startLcpRoundLoopLab(signal, 0, 0);
13048 void Dbdih::startLcpRoundLoopLab(
Signal* signal,
13049 Uint32 startTableId, Uint32 startFragId)
13051 NodeRecordPtr nodePtr;
13052 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
13053 ptrAss(nodePtr, nodeRecord);
13054 if (nodePtr.p->nodeStatus == NodeRecord::ALIVE) {
13055 ndbrequire(nodePtr.p->noOfStartedChkpt == 0);
13056 ndbrequire(nodePtr.p->noOfQueuedChkpt == 0);
13059 c_lcpState.currentFragment.tableId = startTableId;
13060 c_lcpState.currentFragment.fragmentId = startFragId;
13061 startNextChkpt(signal);
13064 void Dbdih::startNextChkpt(
Signal* signal)
13066 Uint32 lcpId = SYSFILE->latestLCP_ID;
13070 const Uint32 lcpNodes = c_lcpState.m_participatingLQH.count();
13073 LcpState::CurrentFragment curr = c_lcpState.currentFragment;
13075 while (curr.tableId < ctabFileSize) {
13076 TabRecordPtr tabPtr;
13077 tabPtr.i = curr.tableId;
13078 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
13079 if ((tabPtr.p->tabStatus != TabRecord::TS_ACTIVE) ||
13080 (tabPtr.p->tabLcpStatus != TabRecord::TLS_ACTIVE)) {
13082 curr.fragmentId = 0;
13086 FragmentstorePtr fragPtr;
13087 getFragstore(tabPtr.p, curr.fragmentId, fragPtr);
13089 ReplicaRecordPtr replicaPtr;
13090 for(replicaPtr.i = fragPtr.p->storedReplicas;
13091 replicaPtr.i != RNIL ;
13092 replicaPtr.i = replicaPtr.p->nextReplica){
13095 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
13097 NodeRecordPtr nodePtr;
13098 nodePtr.i = replicaPtr.p->procNode;
13099 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
13101 if (c_lcpState.m_participatingLQH.get(nodePtr.i))
13103 if (replicaPtr.p->lcpOngoingFlag &&
13104 replicaPtr.p->lcpIdStarted < lcpId)
13112 if (nodePtr.p->noOfStartedChkpt < 2)
13122 replicaPtr.p->lcpIdStarted = lcpId;
13124 Uint32 i = nodePtr.p->noOfStartedChkpt;
13125 nodePtr.p->startedChkpt[
i].tableId = tabPtr.i;
13126 nodePtr.p->startedChkpt[
i].fragId = curr.fragmentId;
13127 nodePtr.p->startedChkpt[
i].replicaPtr = replicaPtr.i;
13128 nodePtr.p->noOfStartedChkpt = i + 1;
13130 sendLCP_FRAG_ORD(signal, nodePtr.p->startedChkpt[i]);
13132 else if (nodePtr.p->noOfQueuedChkpt < 2)
13142 replicaPtr.p->lcpIdStarted = lcpId;
13144 Uint32 i = nodePtr.p->noOfQueuedChkpt;
13145 nodePtr.p->queuedChkpt[
i].tableId = tabPtr.i;
13146 nodePtr.p->queuedChkpt[
i].fragId = curr.fragmentId;
13147 nodePtr.p->queuedChkpt[
i].replicaPtr = replicaPtr.i;
13148 nodePtr.p->noOfQueuedChkpt = i + 1;
13159 c_lcpState.currentFragment = curr;
13163 busyNodes.
set(nodePtr.i);
13164 if(busyNodes.
count() == lcpNodes)
13180 if (curr.fragmentId >= tabPtr.p->totalfragments) {
13182 curr.fragmentId = 0;
13187 sendLastLCP_FRAG_ORD(signal);
13190 void Dbdih::sendLastLCP_FRAG_ORD(
Signal* signal)
13193 lcpFragOrd->tableId = RNIL;
13194 lcpFragOrd->fragmentId = 0;
13195 lcpFragOrd->lcpId = SYSFILE->latestLCP_ID;
13196 lcpFragOrd->lcpNo = 0;
13197 lcpFragOrd->keepGci = c_lcpState.keepGci;
13198 lcpFragOrd->lastFragmentFlag =
true;
13200 NodeRecordPtr nodePtr;
13201 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
13203 ptrAss(nodePtr, nodeRecord);
13205 if(nodePtr.p->noOfQueuedChkpt == 0 &&
13206 nodePtr.p->noOfStartedChkpt == 0 &&
13207 c_lcpState.m_LAST_LCP_FRAG_ORD.isWaitingFor(nodePtr.i)){
13210 CRASH_INSERTION(7028);
13216 c_lcpState.m_LAST_LCP_FRAG_ORD.clearWaitingFor(nodePtr.i);
13217 if(ERROR_INSERTED(7075)){
13221 CRASH_INSERTION(7193);
13222 BlockReference ref = calcLqhBlockRef(nodePtr.i);
13223 sendSignal(ref, GSN_LCP_FRAG_ORD, signal,LcpFragOrd::SignalLength, JBB);
13226 if(ERROR_INSERTED(7075))
13228 if(c_lcpState.m_LAST_LCP_FRAG_ORD.done())
13230 CRASH_INSERTION(7075);
13241 void Dbdih::execLCP_FRAG_REP(
Signal* signal)
13250 const bool broadcast_req = lcpReport->nodeId == LcpFragRep::BROADCAST_REQ;
13254 ndbrequire(refToNode(signal->getSendersBlockRef()) == getOwnNodeId());
13259 lcpReport->nodeId = getOwnNodeId();
13262 rg.m_nodes.clear(getOwnNodeId());
13263 sendSignal(rg, GSN_LCP_FRAG_REP, signal, signal->getLength(), JBB);
13270 ndbrequire(c_lcpState.lcpStatus != LCP_STATUS_IDLE);
13273 printLCP_FRAG_REP(stdout,
13274 signal->getDataPtr(),
13275 signal->
length(), number());
13278 Uint32 nodeId = lcpReport->nodeId;
13279 Uint32 tableId = lcpReport->tableId;
13280 Uint32 fragId = lcpReport->fragId;
13284 if (ERROR_INSERTED(7178) && nodeId != getOwnNodeId())
13287 Uint32 owng =Sysfile::getNodeGroup(getOwnNodeId(), SYSFILE->nodeGroups);
13288 Uint32 nodeg = Sysfile::getNodeGroup(nodeId, SYSFILE->nodeGroups);
13292 ndbout_c(
"throwing away LCP_FRAG_REP from (and killing) %d", nodeId);
13293 SET_ERROR_INSERT_VALUE(7179);
13294 signal->theData[0] = 9999;
13295 sendSignal(numberToRef(CMVMI, nodeId),
13296 GSN_NDB_TAMPER, signal, 1, JBA);
13301 if (ERROR_INSERTED(7179) && nodeId != getOwnNodeId())
13304 Uint32 owng =Sysfile::getNodeGroup(getOwnNodeId(), SYSFILE->nodeGroups);
13305 Uint32 nodeg = Sysfile::getNodeGroup(nodeId, SYSFILE->nodeGroups);
13309 ndbout_c(
"throwing away LCP_FRAG_REP from %d", nodeId);
13314 CRASH_INSERTION2(7025, isMaster());
13315 CRASH_INSERTION2(7016, !isMaster());
13316 CRASH_INSERTION2(7191, (!isMaster() && tableId));
13318 bool fromTimeQueue = (signal->senderBlockRef()==reference()&&!broadcast_req);
13320 TabRecordPtr tabPtr;
13321 tabPtr.i = tableId;
13322 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
13323 if(tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE) {
13338 sendSignal(reference(), GSN_LCP_FRAG_REP, signal, signal->
length(), JBB);
13344 if(!fromTimeQueue){
13345 c_lcpState.noOfLcpFragRepOutstanding++;
13354 ndbrequire(c_lcpState.noOfLcpFragRepOutstanding > 0);
13355 c_lcpState.noOfLcpFragRepOutstanding--;
13358 bool tableDone = reportLcpCompletion(lcpReport);
13360 Uint32 started = lcpReport->maxGciStarted;
13361 Uint32 completed = lcpReport->maxGciCompleted;
13363 if (started > c_lcpState.lcpStopGcp)
13366 c_lcpState.lcpStopGcp = started;
13375 m_local_lcp_state.lcp_frag_rep(lcpReport);
13381 if (tabPtr.p->tabStatus == TabRecord::TS_IDLE ||
13382 tabPtr.p->tabStatus == TabRecord::TS_DROPPING)
13385 g_eventLogger->
info(
"TS_DROPPING - Neglecting to save Table: %d Frag: %d - ",
13394 tabPtr.p->tabLcpStatus = TabRecord::TLS_WRITING_TO_FILE;
13395 tabPtr.p->tabCopyStatus = TabRecord::CS_LCP_READ_TABLE;
13396 tabPtr.p->tabUpdateState = TabRecord::US_LOCAL_CHECKPOINT;
13397 signal->theData[0] = DihContinueB::ZPACK_TABLE_INTO_PAGES;
13398 signal->theData[1] = tabPtr.i;
13399 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
13401 bool ret = checkLcpAllTablesDoneInLqh(__LINE__);
13402 if (ret && ERROR_INSERTED(7209))
13406 signal->theData[0] = 9999;
13407 sendSignal(numberToRef(CMVMI, cmasterNodeId),
13408 GSN_NDB_TAMPER, signal, 1, JBB);
13418 signal->theData[1] = nodeId;
13419 signal->theData[2] = tableId;
13420 signal->theData[3] = fragId;
13421 signal->theData[4] = started;
13422 signal->theData[5] = completed;
13423 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 6, JBB);
13427 switch(c_lcpMasterTakeOverState.state){
13435 case LMTOS_WAIT_EMPTY_LCP:
13438 case LMTOS_WAIT_LCP_FRAG_REP:
13440 checkEmptyLcpComplete(signal);
13442 case LMTOS_INITIAL:
13443 case LMTOS_ALL_IDLE:
13444 case LMTOS_ALL_ACTIVE:
13445 case LMTOS_LCP_CONCLUDING:
13446 case LMTOS_COPY_ONGOING:
13461 NodeRecordPtr nodePtr;
13462 nodePtr.i = nodeId;
13463 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
13465 const Uint32 outstanding = nodePtr.p->noOfStartedChkpt;
13466 ndbrequire(outstanding > 0);
13467 if(nodePtr.p->startedChkpt[0].tableId != tableId ||
13468 nodePtr.p->startedChkpt[0].fragId != fragId){
13470 ndbrequire(outstanding > 1);
13471 ndbrequire(nodePtr.p->startedChkpt[1].tableId == tableId);
13472 ndbrequire(nodePtr.p->startedChkpt[1].fragId == fragId);
13475 nodePtr.p->startedChkpt[0] = nodePtr.p->startedChkpt[1];
13477 nodePtr.p->noOfStartedChkpt--;
13478 checkStartMoreLcp(signal, nodeId);
13483 Dbdih::checkLcpAllTablesDoneInLqh(Uint32 line){
13484 TabRecordPtr tabPtr;
13489 for (tabPtr.i = 0; tabPtr.i < ctabFileSize; tabPtr.i++) {
13491 ptrAss(tabPtr, tabRecord);
13492 if ((tabPtr.p->tabStatus == TabRecord::TS_ACTIVE) &&
13493 (tabPtr.p->tabLcpStatus == TabRecord::TLS_ACTIVE))
13503 CRASH_INSERTION2(7026, isMaster());
13504 CRASH_INSERTION2(7017, !isMaster());
13506 c_lcpState.setLcpStatus(LCP_TAB_COMPLETED, line);
13508 if (ERROR_INSERTED(7194))
13510 ndbout_c(
"CLEARING 7194");
13511 CLEAR_ERROR_INSERT_VALUE;
13517 void Dbdih::findReplica(ReplicaRecordPtr& replicaPtr,
13518 Fragmentstore* fragPtrP,
13522 replicaPtr.i = old ? fragPtrP->oldStoredReplicas : fragPtrP->storedReplicas;
13523 while(replicaPtr.i != RNIL){
13524 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
13525 if (replicaPtr.p->procNode == nodeId) {
13530 replicaPtr.i = replicaPtr.p->nextReplica;
13535 g_eventLogger->
info(
"Fragment Replica(node=%d) not found", nodeId);
13536 replicaPtr.i = fragPtrP->oldStoredReplicas;
13537 while(replicaPtr.i != RNIL){
13538 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
13539 if (replicaPtr.p->procNode == nodeId) {
13544 replicaPtr.i = replicaPtr.p->nextReplica;
13547 if(replicaPtr.i != RNIL){
13548 g_eventLogger->
info(
"...But was found in oldStoredReplicas");
13550 g_eventLogger->
info(
"...And wasn't found in oldStoredReplicas");
13558 Dbdih::handle_invalid_lcp_no(
const LcpFragRep* rep,
13559 ReplicaRecordPtr replicaPtr)
13561 ndbrequire(!isMaster());
13562 Uint32 lcpNo = rep->lcpNo;
13563 Uint32 lcpId = rep->lcpId;
13565 if (!ndb_pnr(
getNodeInfo(refToNode(cmasterdihref)).m_version))
13570 warningEvent(
"Detected previous node failure of %d during lcp",
13574 replicaPtr.p->nextLcp = lcpNo;
13575 replicaPtr.p->lcpId[lcpNo] = 0;
13576 replicaPtr.p->lcpStatus[lcpNo] = ZINVALID;
13578 for (Uint32 i = lcpNo; i != lcpNo; i = nextLcpNo(i))
13581 if (replicaPtr.p->lcpStatus[i] == ZVALID &&
13582 replicaPtr.p->lcpId[i] >= lcpId)
13584 ndbout_c(
"i: %d lcpId: %d", i, replicaPtr.p->lcpId[i]);
13598 Dbdih::reportLcpCompletion(
const LcpFragRep* lcpReport)
13600 Uint32 lcpNo = lcpReport->lcpNo;
13601 Uint32 lcpId = lcpReport->lcpId;
13602 Uint32 maxGciStarted = lcpReport->maxGciStarted;
13603 Uint32 maxGciCompleted = lcpReport->maxGciCompleted;
13604 Uint32 tableId = lcpReport->tableId;
13605 Uint32 fragId = lcpReport->fragId;
13606 Uint32 nodeId = lcpReport->nodeId;
13608 TabRecordPtr tabPtr;
13609 tabPtr.i = tableId;
13610 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
13612 if (tabPtr.p->tabStatus == TabRecord::TS_DROPPING ||
13613 tabPtr.p->tabStatus == TabRecord::TS_IDLE)
13619 FragmentstorePtr fragPtr;
13620 getFragstore(tabPtr.p, fragId, fragPtr);
13622 ReplicaRecordPtr replicaPtr;
13623 findReplica(replicaPtr, fragPtr.p, nodeId);
13625 ndbrequire(replicaPtr.p->lcpOngoingFlag ==
true);
13626 if(lcpNo != replicaPtr.p->nextLcp){
13627 if (handle_invalid_lcp_no(lcpReport, replicaPtr))
13629 g_eventLogger->
error(
"lcpNo = %d replicaPtr.p->nextLcp = %d",
13630 lcpNo, replicaPtr.p->nextLcp);
13634 ndbrequire(lcpNo == replicaPtr.p->nextLcp);
13635 ndbrequire(lcpNo < MAX_LCP_STORED);
13636 ndbrequire(replicaPtr.p->lcpId[lcpNo] != lcpId);
13638 replicaPtr.p->lcpIdStarted = lcpId;
13639 replicaPtr.p->lcpOngoingFlag =
false;
13641 removeOldCrashedReplicas(tableId, fragId, replicaPtr);
13642 replicaPtr.p->lcpId[lcpNo] = lcpId;
13643 replicaPtr.p->lcpStatus[lcpNo] = ZVALID;
13644 replicaPtr.p->maxGciStarted[lcpNo] = maxGciStarted;
13645 replicaPtr.p->maxGciCompleted[lcpNo] = maxGciCompleted;
13646 replicaPtr.p->nextLcp = nextLcpNo(replicaPtr.p->nextLcp);
13647 ndbrequire(fragPtr.p->noLcpReplicas > 0);
13648 fragPtr.p->noLcpReplicas --;
13650 if(fragPtr.p->noLcpReplicas > 0){
13655 for (Uint32 fid = 0; fid < tabPtr.p->totalfragments; fid++) {
13657 getFragstore(tabPtr.p, fid, fragPtr);
13658 if (fragPtr.p->noLcpReplicas > 0){
13664 g_eventLogger->
info(
"reportLcpCompletion: fragment %d not ready", fid);
13671 void Dbdih::checkStartMoreLcp(
Signal* signal, Uint32 nodeId)
13673 ndbrequire(isMaster());
13675 NodeRecordPtr nodePtr;
13676 nodePtr.i = nodeId;
13677 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
13679 ndbrequire(nodePtr.p->noOfStartedChkpt < 2);
13681 if (nodePtr.p->noOfQueuedChkpt > 0) {
13683 nodePtr.p->noOfQueuedChkpt--;
13684 Uint32 i = nodePtr.p->noOfStartedChkpt;
13685 nodePtr.p->startedChkpt[
i] = nodePtr.p->queuedChkpt[0];
13686 nodePtr.p->queuedChkpt[0] = nodePtr.p->queuedChkpt[1];
13691 nodePtr.p->noOfStartedChkpt = i + 1;
13693 sendLCP_FRAG_ORD(signal, nodePtr.p->startedChkpt[i]);
13702 startNextChkpt(signal);
13706 Dbdih::sendLCP_FRAG_ORD(
Signal* signal,
13707 NodeRecord::FragmentCheckpointInfo info){
13709 ReplicaRecordPtr replicaPtr;
13710 replicaPtr.i = info.replicaPtr;
13711 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
13714 BlockReference ref = calcLqhBlockRef(replicaPtr.p->procNode);
13716 if (ERROR_INSERTED(7193) && replicaPtr.p->procNode == getOwnNodeId())
13721 if (replicaPtr.p->nextLcp >= MAX_LCP_USED)
13724 infoEvent(
"Updating nextLcp from %u to %u tab: %u",
13725 replicaPtr.p->nextLcp, 0,
13727 replicaPtr.p->nextLcp = 0;
13730 Uint32 keepGci = c_lcpState.keepGci;
13731 if (keepGci > SYSFILE->lastCompletedGCI[replicaPtr.p->procNode])
13734 keepGci = SYSFILE->lastCompletedGCI[replicaPtr.p->procNode];
13738 lcpFragOrd->tableId = info.tableId;
13739 lcpFragOrd->fragmentId = info.fragId;
13740 lcpFragOrd->lcpId = SYSFILE->latestLCP_ID;
13741 lcpFragOrd->lcpNo = replicaPtr.p->nextLcp;
13742 lcpFragOrd->keepGci = keepGci;
13743 lcpFragOrd->lastFragmentFlag =
false;
13744 sendSignal(ref, GSN_LCP_FRAG_ORD, signal, LcpFragOrd::SignalLength, JBB);
13747 void Dbdih::checkLcpCompletedLab(
Signal* signal)
13749 if(c_lcpState.lcpStatus < LCP_TAB_COMPLETED)
13755 TabRecordPtr tabPtr;
13756 for (tabPtr.i = 0; tabPtr.i < ctabFileSize; tabPtr.i++) {
13758 ptrAss(tabPtr, tabRecord);
13759 if (tabPtr.p->tabLcpStatus != TabRecord::TLS_COMPLETED)
13766 CRASH_INSERTION2(7027, isMaster());
13767 CRASH_INSERTION2(7018, !isMaster());
13769 if(c_lcpState.lcpStatus == LCP_TAB_COMPLETED)
13775 if (ERROR_INSERTED(7209))
13777 signal->theData[0] = DihContinueB::ZCHECK_LCP_COMPLETED;
13778 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
13782 c_lcpState.setLcpStatus(LCP_TAB_SAVED, __LINE__);
13783 sendLCP_COMPLETE_REP(signal);
13785 if (ERROR_INSERTED(7210))
13787 CLEAR_ERROR_INSERT_VALUE;
13789 req->senderRef = reference();
13790 sendEMPTY_LCP_REQ(signal, getOwnNodeId(), 0);
13796 ndbrequire(c_lcpState.lcpStatus == LCP_TAB_SAVED);
13797 allNodesLcpCompletedLab(signal);
13802 Dbdih::sendLCP_COMPLETE_REP(
Signal* signal){
13810 c_lcpState.m_lastLCP_COMPLETE_REP_id == SYSFILE->latestLCP_ID &&
13811 c_lcpState.m_lastLCP_COMPLETE_REP_ref == c_lcpState.m_masterLcpDihRef;
13816 rep->nodeId = getOwnNodeId();
13817 rep->lcpId = SYSFILE->latestLCP_ID;
13818 rep->blockNo = DBDIH;
13820 sendSignal(c_lcpState.m_masterLcpDihRef, GSN_LCP_COMPLETE_REP, signal,
13821 LcpCompleteRep::SignalLength, JBB);
13823 c_lcpState.m_lastLCP_COMPLETE_REP_id = SYSFILE->latestLCP_ID;
13824 c_lcpState.m_lastLCP_COMPLETE_REP_ref = c_lcpState.m_masterLcpDihRef;
13831 if (c_set_initial_start_flag &&
13832 c_lcpState.m_participatingLQH.get(getOwnNodeId()))
13835 c_set_initial_start_flag = FALSE;
13842 void Dbdih::execLCP_COMPLETE_REP(
Signal* signal)
13846 CRASH_INSERTION(7191);
13849 g_eventLogger->
info(
"LCP_COMPLETE_REP");
13850 printLCP_COMPLETE_REP(stdout,
13851 signal->getDataPtr(),
13852 signal->
length(), number());
13857 if (rep->nodeId == LcpFragRep::BROADCAST_REQ)
13860 ndbrequire(refToNode(signal->getSendersBlockRef()) == getOwnNodeId());
13865 rep->nodeId = getOwnNodeId();
13868 rg.m_nodes.clear(getOwnNodeId());
13869 sendSignal(rg, GSN_LCP_COMPLETE_REP, signal, signal->getLength(), JBB);
13876 Uint32 lcpId = rep->lcpId;
13877 Uint32 nodeId = rep->nodeId;
13878 Uint32 blockNo = rep->blockNo;
13880 if(c_lcpMasterTakeOverState.state > LMTOS_WAIT_LCP_FRAG_REP){
13886 ndbrequire(isMaster());
13887 ndbrequire(blockNo == DBDIH);
13888 sendSignalWithDelay(reference(), GSN_LCP_COMPLETE_REP, signal, 100,
13893 ndbrequire(c_lcpState.lcpStatus != LCP_STATUS_IDLE);
13898 c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.clearWaitingFor(nodeId);
13899 ndbrequire(!c_lcpState.m_LAST_LCP_FRAG_ORD.isWaitingFor(nodeId));
13903 ndbrequire(isMaster());
13904 c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH.clearWaitingFor(nodeId);
13908 ndbrequire(!isMaster());
13909 ndbrequire(c_lcpState.m_LCP_COMPLETE_REP_From_Master_Received ==
false);
13910 c_lcpState.m_LCP_COMPLETE_REP_From_Master_Received =
true;
13915 ndbrequire(lcpId == SYSFILE->latestLCP_ID);
13917 allNodesLcpCompletedLab(signal);
13921 void Dbdih::allNodesLcpCompletedLab(
Signal* signal)
13925 if (c_lcpState.lcpStatus != LCP_TAB_SAVED) {
13933 if (!c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.done()){
13938 if (!c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH.done()){
13944 c_lcpState.m_LCP_COMPLETE_REP_From_Master_Received ==
false){
13952 if(c_lcpMasterTakeOverState.state != LMTOS_IDLE){
13955 g_eventLogger->
info(
"Exiting from allNodesLcpCompletedLab");
13971 CRASH_INSERTION(7019);
13972 signal->setTrace(0);
13974 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
13979 m_local_lcp_state.lcp_complete_rep(c_newest_restorable_gci);
13986 TakeOverRecordPtr takeOverPtr;
13987 for (c_activeTakeOverList.
first(takeOverPtr); !takeOverPtr.isNull();
13988 c_activeTakeOverList.
next(takeOverPtr))
13992 nodePtr.i = takeOverPtr.p->toStartingNode;
13993 if (takeOverPtr.p->toMasterStatus == TakeOverRecord::TO_WAIT_LCP)
13996 if (c_lcpState.m_participatingLQH.get(nodePtr.i))
13999 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
14000 ndbrequire(nodePtr.p->copyCompleted == 2);
14003 conf->senderData = takeOverPtr.p->m_senderData;
14004 conf->sendingNodeId = cownNodeId;
14005 conf->startingNodeId = nodePtr.i;
14006 sendSignal(takeOverPtr.p->m_senderRef, GSN_END_TOCONF, signal,
14007 EndToConf::SignalLength, JBB);
14009 releaseTakeOver(takeOverPtr);
14015 Sysfile::clearLCPOngoing(SYSFILE->systemRestartBits);
14016 setLcpActiveStatusEnd(signal);
14029 rep->nodeId = getOwnNodeId();
14030 rep->lcpId = SYSFILE->latestLCP_ID;
14033 NodeRecordPtr nodePtr;
14034 nodePtr.i = cfirstAliveNode;
14037 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
14038 if (nodePtr.i != cownNodeId){
14039 BlockReference ref = calcDihBlockRef(nodePtr.i);
14040 sendSignal(ref, GSN_LCP_COMPLETE_REP, signal,
14041 LcpCompleteRep::SignalLength, JBB);
14043 nodePtr.i = nodePtr.p->nextNode;
14044 }
while (nodePtr.i != RNIL);
14052 signal->theData[1] = SYSFILE->latestLCP_ID;
14053 sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, 2, JBB);
14055 if (c_newest_restorable_gci > c_lcpState.lcpStopGcp &&
14056 !(ERROR_INSERTED(7222) || ERROR_INSERTED(7223)))
14059 c_lcpState.lcpStopGcp = c_newest_restorable_gci;
14065 checkLcpStart(signal, __LINE__);
14067 Mutex mutex(signal, c_mutexMgr, c_fragmentInfoMutex_lcp);
14070 c_lcpState.m_lcp_time = c_current_time - c_lcpState.m_start_time;
14072 if (cwaitLcpSr ==
true) {
14074 cwaitLcpSr =
false;
14075 ndbsttorry10Lab(signal, __LINE__);
14080 if (c_nodeStartMaster.blockLcp ==
true) {
14082 lcpBlockedLab(signal,
false, c_nodeStartMaster.startNode);
14101 void Dbdih::tableUpdateLab(
Signal* signal, TabRecordPtr tabPtr) {
14102 FileRecordPtr filePtr;
14103 if(tabPtr.p->tabStorage == TabRecord::ST_TEMPORARY) {
14106 filePtr.i = tabPtr.p->tabFile[1];
14107 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
14108 tableCloseLab(signal, filePtr);
14111 filePtr.i = tabPtr.p->tabFile[0];
14112 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
14113 createFileRw(signal, filePtr);
14114 filePtr.p->reqStatus = FileRecord::TABLE_CREATE;
14118 void Dbdih::tableCreateLab(
Signal* signal, FileRecordPtr filePtr)
14120 TabRecordPtr tabPtr;
14121 tabPtr.i = filePtr.p->tabRef;
14122 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
14123 writeTabfile(signal, tabPtr.p, filePtr);
14124 filePtr.p->reqStatus = FileRecord::TABLE_WRITE;
14128 void Dbdih::tableWriteLab(
Signal* signal, FileRecordPtr filePtr)
14130 closeFile(signal, filePtr);
14131 filePtr.p->reqStatus = FileRecord::TABLE_CLOSE;
14135 void Dbdih::tableCloseLab(
Signal* signal, FileRecordPtr filePtr)
14137 TabRecordPtr tabPtr;
14138 tabPtr.i = filePtr.p->tabRef;
14139 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
14140 if (filePtr.i == tabPtr.p->tabFile[0]) {
14142 filePtr.i = tabPtr.p->tabFile[1];
14143 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
14144 createFileRw(signal, filePtr);
14145 filePtr.p->reqStatus = FileRecord::TABLE_CREATE;
14148 switch (tabPtr.p->tabUpdateState) {
14149 case TabRecord::US_LOCAL_CHECKPOINT:
14151 releaseTabPages(tabPtr.i);
14152 signal->theData[0] = DihContinueB::ZCHECK_LCP_COMPLETED;
14153 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
14155 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
14156 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14157 tabPtr.p->tabLcpStatus = TabRecord::TLS_COMPLETED;
14160 case TabRecord::US_REMOVE_NODE:
14162 releaseTabPages(tabPtr.i);
14163 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
14164 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14165 if (tabPtr.p->tabLcpStatus == TabRecord::TLS_WRITING_TO_FILE) {
14167 tabPtr.p->tabLcpStatus = TabRecord::TLS_COMPLETED;
14168 signal->theData[0] = DihContinueB::ZCHECK_LCP_COMPLETED;
14169 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
14171 signal->theData[0] = DihContinueB::ZREMOVE_NODE_FROM_TABLE;
14172 signal->theData[1] = tabPtr.p->tabRemoveNode;
14173 signal->theData[2] = tabPtr.i + 1;
14174 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
14177 case TabRecord::US_INVALIDATE_NODE_LCP:
14179 releaseTabPages(tabPtr.i);
14180 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
14181 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14183 signal->theData[0] = DihContinueB::ZINVALIDATE_NODE_LCP;
14184 signal->theData[1] = tabPtr.p->tabRemoveNode;
14185 signal->theData[2] = tabPtr.i + 1;
14186 if (ERROR_INSERTED(7204))
14188 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 2000, 3);
14192 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
14195 case TabRecord::US_COPY_TAB_REQ:
14197 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14198 copyTabReq_complete(signal, tabPtr);
14201 case TabRecord::US_ADD_TABLE_MASTER:
14203 releaseTabPages(tabPtr.i);
14204 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14205 signal->theData[0] = DihContinueB::ZDIH_ADD_TABLE_MASTER;
14206 signal->theData[1] = tabPtr.i;
14207 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
14210 case TabRecord::US_ADD_TABLE_SLAVE:
14212 releaseTabPages(tabPtr.i);
14213 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14214 signal->theData[0] = DihContinueB::ZDIH_ADD_TABLE_SLAVE;
14215 signal->theData[1] = tabPtr.i;
14216 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
14219 case TabRecord::US_CALLBACK:
14222 releaseTabPages(tabPtr.i);
14223 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
14224 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
14227 connectPtr.i = tabPtr.p->connectrec;
14228 ptrCheckGuard(connectPtr, cconnectFileSize, connectRecord);
14229 execute(signal, connectPtr.p->m_callback, 0);
14239 void Dbdih::checkGcpStopLab(
Signal* signal)
14241 Uint32 cnt0 = ++m_gcp_monitor.m_gcp_save.m_counter;
14242 Uint32 cnt1 = ++m_gcp_monitor.m_micro_gcp.m_counter;
14244 if (m_gcp_monitor.m_gcp_save.m_gci == m_gcp_save.m_gci)
14247 if (m_gcp_monitor.m_gcp_save.m_max_lag &&
14248 cnt0 == m_gcp_monitor.m_gcp_save.m_max_lag)
14250 crashSystemAtGcpStop(signal,
false);
14254 Uint32 threshold = 60;
14255 if (cnt0 && ((cnt0 % (threshold * 10)) == 0))
14257 if (m_gcp_monitor.m_gcp_save.m_max_lag)
14261 cnt0/10, m_gcp_monitor.m_gcp_save.m_max_lag/10);
14274 m_gcp_monitor.m_gcp_save.m_gci = m_gcp_save.m_gci;
14275 m_gcp_monitor.m_gcp_save.m_counter = 0;
14278 if (m_gcp_monitor.m_micro_gcp.m_gci == m_micro_gcp.m_current_gci)
14281 Uint32 cmp = m_micro_gcp.m_enabled ?
14282 m_gcp_monitor.m_micro_gcp.m_max_lag :
14283 m_gcp_monitor.m_gcp_save.m_max_lag;
14285 if (cmp && cnt1 == cmp)
14287 crashSystemAtGcpStop(signal,
false);
14291 Uint32 threshold = 10;
14292 if (cnt1 && ((cnt0 % (threshold * 10)) == 0))
14294 if (m_gcp_monitor.m_micro_gcp.m_max_lag)
14298 cnt1/10, m_gcp_monitor.m_micro_gcp.m_max_lag/10);
14311 m_gcp_monitor.m_micro_gcp.m_counter = 0;
14312 m_gcp_monitor.m_micro_gcp.m_gci = m_micro_gcp.m_current_gci;
14315 signal->theData[0] = DihContinueB::ZCHECK_GCP_STOP;
14316 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 100, 1);
14321 Dbdih::dumpGcpStop()
14323 ndbout_c(
"c_nodeStartMaster.blockGcp: %u %u",
14324 c_nodeStartMaster.blockGcp,
14325 c_nodeStartMaster.startNode);
14326 ndbout_c(
"m_gcp_save.m_counter: %u m_gcp_save.m_max_lag: %u",
14327 m_gcp_monitor.m_gcp_save.m_counter,
14328 m_gcp_monitor.m_gcp_save.m_max_lag);
14329 ndbout_c(
"m_micro_gcp.m_counter: %u m_micro_gcp.m_max_lag: %u",
14330 m_gcp_monitor.m_micro_gcp.m_counter,
14331 m_gcp_monitor.m_micro_gcp.m_max_lag);
14334 ndbout_c(
"m_gcp_save.m_state: %u", m_gcp_save.m_state);
14335 ndbout_c(
"m_gcp_save.m_master.m_state: %u", m_gcp_save.m_master.m_state);
14336 ndbout_c(
"m_micro_gcp.m_state: %u", m_micro_gcp.m_state);
14337 ndbout_c(
"m_micro_gcp.m_master.m_state: %u", m_micro_gcp.m_master.m_state);
14339 ndbout_c(
"c_COPY_GCIREQ_Counter = %s", c_COPY_GCIREQ_Counter.getText());
14340 ndbout_c(
"c_COPY_TABREQ_Counter = %s", c_COPY_TABREQ_Counter.getText());
14341 ndbout_c(
"c_CREATE_FRAGREQ_Counter = %s", c_CREATE_FRAGREQ_Counter.getText());
14342 ndbout_c(
"c_DIH_SWITCH_REPLICA_REQ_Counter = %s",
14343 c_DIH_SWITCH_REPLICA_REQ_Counter.getText());
14344 ndbout_c(
"c_EMPTY_LCP_REQ_Counter = %s",c_EMPTY_LCP_REQ_Counter.getText());
14345 ndbout_c(
"c_GCP_COMMIT_Counter = %s", c_GCP_COMMIT_Counter.getText());
14346 ndbout_c(
"c_GCP_PREPARE_Counter = %s", c_GCP_PREPARE_Counter.getText());
14347 ndbout_c(
"c_GCP_SAVEREQ_Counter = %s", c_GCP_SAVEREQ_Counter.getText());
14348 ndbout_c(
"c_SUB_GCP_COMPLETE_REP_Counter = %s",
14349 c_SUB_GCP_COMPLETE_REP_Counter.getText());
14350 ndbout_c(
"c_INCL_NODEREQ_Counter = %s", c_INCL_NODEREQ_Counter.getText());
14351 ndbout_c(
"c_MASTER_GCPREQ_Counter = %s", c_MASTER_GCPREQ_Counter.getText());
14352 ndbout_c(
"c_MASTER_LCPREQ_Counter = %s", c_MASTER_LCPREQ_Counter.getText());
14353 ndbout_c(
"c_START_INFOREQ_Counter = %s", c_START_INFOREQ_Counter.getText());
14354 ndbout_c(
"c_START_RECREQ_Counter = %s", c_START_RECREQ_Counter.getText());
14355 ndbout_c(
"c_STOP_ME_REQ_Counter = %s", c_STOP_ME_REQ_Counter.getText());
14356 ndbout_c(
"c_TC_CLOPSIZEREQ_Counter = %s", c_TC_CLOPSIZEREQ_Counter.getText());
14357 ndbout_c(
"c_TCGETOPSIZEREQ_Counter = %s", c_TCGETOPSIZEREQ_Counter.getText());
14359 ndbout_c(
"m_copyReason: %d m_waiting: %u %u",
14360 c_copyGCIMaster.m_copyReason,
14361 c_copyGCIMaster.m_waiting[0],
14362 c_copyGCIMaster.m_waiting[1]);
14364 ndbout_c(
"c_copyGCISlave: sender{Data, Ref} %d %x reason: %d nextWord: %d",
14365 c_copyGCISlave.m_senderData,
14366 c_copyGCISlave.m_senderRef,
14367 c_copyGCISlave.m_copyReason,
14368 c_copyGCISlave.m_expectedNextWord);
14375 void Dbdih::crashSystemAtGcpStop(
Signal* signal,
bool local)
14378 Uint32 save_counter = m_gcp_monitor.m_gcp_save.m_counter;
14379 Uint32 micro_counter = m_gcp_monitor.m_micro_gcp.m_counter;
14380 m_gcp_monitor.m_gcp_save.m_counter = 0;
14381 m_gcp_monitor.m_micro_gcp.m_counter = 0;
14386 if (c_nodeStartMaster.blockGcp == 2)
14394 sysErr->errorCode = SystemError::GCPStopDetected;
14395 sysErr->errorRef = reference();
14396 sysErr->data[0] = m_gcp_save.m_master.m_state;
14397 sysErr->data[1] = cgcpOrderBlocked;
14398 sysErr->data[2] = m_micro_gcp.m_master.m_state;
14399 sendSignal(calcNdbCntrBlockRef(c_nodeStartMaster.startNode),
14400 GSN_SYSTEM_ERROR, signal, SystemError::SignalLength, JBA);
14404 if (save_counter == m_gcp_monitor.m_gcp_save.m_max_lag)
14406 switch(m_gcp_save.m_master.m_state){
14407 case GcpSave::GCP_SAVE_IDLE:
14415 case GcpSave::GCP_SAVE_REQ:
14419 signal->theData[0] = 2305;
14420 sendSignal(rg, GSN_DUMP_STATE_ORD, signal, 1, JBB);
14422 warningEvent(
"Detected GCP stop(%d)...sending kill to %s",
14423 m_gcp_save.m_master.m_state, c_GCP_SAVEREQ_Counter.getText());
14424 ndbout_c(
"Detected GCP stop(%d)...sending kill to %s",
14425 m_gcp_save.m_master.m_state, c_GCP_SAVEREQ_Counter.getText());
14426 ndbrequire(!c_GCP_SAVEREQ_Counter.done());
14429 case GcpSave::GCP_SAVE_COPY_GCI:
14434 warningEvent(
"Detected GCP stop(%d)...sending kill to %s",
14435 m_gcp_save.m_master.m_state, c_COPY_GCIREQ_Counter.getText());
14436 ndbout_c(
"Detected GCP stop(%d)...sending kill to %s",
14437 m_gcp_save.m_master.m_state, c_COPY_GCIREQ_Counter.getText());
14441 signal->theData[0] = 7022;
14442 sendSignal(rg, GSN_DUMP_STATE_ORD, signal, 1, JBA);
14448 sysErr->errorCode = SystemError::GCPStopDetected;
14449 sysErr->errorRef = reference();
14450 sysErr->data[0] = m_gcp_save.m_master.m_state;
14451 sysErr->data[1] = cgcpOrderBlocked;
14452 sysErr->data[2] = m_micro_gcp.m_master.m_state;
14453 sendSignal(rg, GSN_SYSTEM_ERROR, signal,
14454 SystemError::SignalLength, JBA);
14456 ndbrequire(!c_COPY_GCIREQ_Counter.done());
14459 case GcpSave::GCP_SAVE_CONF:
14468 if (micro_counter == m_gcp_monitor.m_micro_gcp.m_max_lag)
14470 switch(m_micro_gcp.m_master.m_state){
14471 case MicroGcp::M_GCP_IDLE:
14479 case MicroGcp::M_GCP_PREPARE:
14484 warningEvent(
"Detected GCP stop(%d)...sending kill to %s",
14485 m_micro_gcp.m_state, c_GCP_PREPARE_Counter.getText());
14486 ndbout_c(
"Detected GCP stop(%d)...sending kill to %s",
14487 m_micro_gcp.m_state, c_GCP_PREPARE_Counter.getText());
14491 signal->theData[0] = 7022;
14492 sendSignal(rg, GSN_DUMP_STATE_ORD, signal, 1, JBA);
14498 sysErr->errorCode = SystemError::GCPStopDetected;
14499 sysErr->errorRef = reference();
14500 sysErr->data[0] = m_gcp_save.m_master.m_state;
14501 sysErr->data[1] = cgcpOrderBlocked;
14502 sysErr->data[2] = m_micro_gcp.m_master.m_state;
14503 sendSignal(rg, GSN_SYSTEM_ERROR, signal,
14504 SystemError::SignalLength, JBA);
14506 ndbrequire(!c_GCP_PREPARE_Counter.done());
14509 case MicroGcp::M_GCP_COMMIT:
14511 warningEvent(
"Detected GCP stop(%d)...sending kill to %s",
14512 m_micro_gcp.m_state, c_GCP_COMMIT_Counter.getText());
14513 ndbout_c(
"Detected GCP stop(%d)...sending kill to %s",
14514 m_micro_gcp.m_state, c_GCP_COMMIT_Counter.getText());
14518 signal->theData[0] = 7022;
14519 sendSignal(rg, GSN_DUMP_STATE_ORD, signal, 1, JBA);
14525 sysErr->errorCode = SystemError::GCPStopDetected;
14526 sysErr->errorRef = reference();
14527 sysErr->data[0] = m_gcp_save.m_master.m_state;
14528 sysErr->data[1] = cgcpOrderBlocked;
14529 sysErr->data[2] = m_micro_gcp.m_master.m_state;
14530 sendSignal(rg, GSN_SYSTEM_ERROR, signal,
14531 SystemError::SignalLength, JBA);
14533 ndbrequire(!c_GCP_COMMIT_Counter.done());
14536 case MicroGcp::M_GCP_COMMITTED:
14542 case MicroGcp::M_GCP_COMPLETE:
14543 infoEvent(
"Detected GCP stop(%d)...sending kill to %s",
14544 m_micro_gcp.m_state, c_SUB_GCP_COMPLETE_REP_Counter.getText());
14545 ndbout_c(
"Detected GCP stop(%d)...sending kill to %s",
14546 m_micro_gcp.m_state, c_SUB_GCP_COMPLETE_REP_Counter.getText());
14550 signal->theData[0] = 7022;
14551 sendSignal(rg, GSN_DUMP_STATE_ORD, signal, 1, JBA);
14557 sysErr->errorCode = SystemError::GCPStopDetected;
14558 sysErr->errorRef = reference();
14559 sysErr->data[0] = m_gcp_save.m_master.m_state;
14560 sysErr->data[1] = cgcpOrderBlocked;
14561 sysErr->data[2] = m_micro_gcp.m_master.m_state;
14562 sendSignal(rg, GSN_SYSTEM_ERROR, signal,
14563 SystemError::SignalLength, JBA);
14565 ndbrequire(!c_SUB_GCP_COMPLETE_REP_Counter.done());
14571 FileRecordPtr file0Ptr;
14572 file0Ptr.i = crestartInfoFile[0];
14573 ptrCheckGuard(file0Ptr, cfileFileSize, fileRecord);
14574 FileRecordPtr file1Ptr;
14575 file1Ptr.i = crestartInfoFile[1];
14576 ptrCheckGuard(file1Ptr, cfileFileSize, fileRecord);
14578 ndbout_c(
"file[0] status: %d type: %d reqStatus: %d file1: %d %d %d",
14579 file0Ptr.p->fileStatus, file0Ptr.p->fileType, file0Ptr.p->reqStatus,
14580 file1Ptr.p->fileStatus, file1Ptr.p->fileType, file1Ptr.p->reqStatus
14583 signal->theData[0] = 404;
14584 signal->theData[1] = file0Ptr.p->fileRef;
14587 signal->theData[0] = 404;
14588 signal->theData[1] = file1Ptr.p->fileRef;
14593 sysErr->errorCode = SystemError::GCPStopDetected;
14594 sysErr->errorRef = reference();
14595 sysErr->data[0] = m_gcp_save.m_master.m_state;
14596 sysErr->data[1] = cgcpOrderBlocked;
14597 sysErr->data[2] = m_micro_gcp.m_master.m_state;
14599 signal, SystemError::SignalLength);
14611 void Dbdih::allocpage(PageRecordPtr& pagePtr)
14613 ndbrequire(cfirstfreepage != RNIL);
14614 pagePtr.i = cfirstfreepage;
14615 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
14616 cfirstfreepage = pagePtr.p->nextfreepage;
14617 pagePtr.p->nextfreepage = RNIL;
14627 void Dbdih::allocStoredReplica(FragmentstorePtr fragPtr,
14628 ReplicaRecordPtr& newReplicaPtr,
14632 ReplicaRecordPtr arrReplicaPtr;
14633 ReplicaRecordPtr arrPrevReplicaPtr;
14635 seizeReplicaRec(newReplicaPtr);
14636 for (i = 0; i < MAX_LCP_STORED; i++) {
14637 newReplicaPtr.p->maxGciCompleted[
i] = 0;
14638 newReplicaPtr.p->maxGciStarted[
i] = 0;
14639 newReplicaPtr.p->lcpId[
i] = 0;
14640 newReplicaPtr.p->lcpStatus[
i] = ZINVALID;
14642 newReplicaPtr.p->noCrashedReplicas = 0;
14643 newReplicaPtr.p->initialGci = (Uint32)(m_micro_gcp.m_current_gci >> 32);
14644 for (i = 0; i < MAX_CRASHED_REPLICAS; i++) {
14645 newReplicaPtr.p->replicaLastGci[
i] = ZINIT_REPLICA_LAST_GCI;
14646 newReplicaPtr.p->createGci[
i] = ZINIT_CREATE_GCI;
14648 newReplicaPtr.p->createGci[0] = (Uint32)(m_micro_gcp.m_current_gci >> 32);
14649 newReplicaPtr.p->nextLcp = 0;
14650 newReplicaPtr.p->procNode = nodeId;
14651 newReplicaPtr.p->lcpOngoingFlag =
false;
14652 newReplicaPtr.p->lcpIdStarted = 0;
14654 arrPrevReplicaPtr.i = RNIL;
14655 arrReplicaPtr.i = fragPtr.p->storedReplicas;
14656 while (arrReplicaPtr.i != RNIL) {
14658 ptrCheckGuard(arrReplicaPtr, creplicaFileSize, replicaRecord);
14659 arrPrevReplicaPtr = arrReplicaPtr;
14660 arrReplicaPtr.i = arrReplicaPtr.p->nextReplica;
14662 if (arrPrevReplicaPtr.i == RNIL) {
14664 fragPtr.p->storedReplicas = newReplicaPtr.i;
14667 arrPrevReplicaPtr.p->nextReplica = newReplicaPtr.i;
14669 fragPtr.p->noStoredReplicas++;
14679 void Dbdih::checkEscalation()
14681 Uint32 TnodeGroup[MAX_NDB_NODES];
14682 NodeRecordPtr nodePtr;
14684 for (i = 0; i < cnoOfNodeGroups; i++) {
14685 TnodeGroup[
i] = ZFALSE;
14687 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
14689 ptrAss(nodePtr, nodeRecord);
14690 if (nodePtr.p->nodeStatus == NodeRecord::ALIVE &&
14691 nodePtr.p->activeStatus == Sysfile::NS_Active){
14692 ndbrequire(nodePtr.p->nodeGroup < MAX_NDB_NODES);
14693 TnodeGroup[nodePtr.p->nodeGroup] = ZTRUE;
14696 for (i = 0; i < cnoOfNodeGroups; i++) {
14698 if (TnodeGroup[c_node_groups[i]] == ZFALSE) {
14700 progError(__LINE__, NDBD_EXIT_LOST_NODE_GROUP,
"Lost node group");
14711 void Dbdih::checkKeepGci(TabRecordPtr tabPtr, Uint32 fragId, Fragmentstore*,
14712 Uint32 replicaStartIndex)
14714 ReplicaRecordPtr ckgReplicaPtr;
14715 ckgReplicaPtr.i = replicaStartIndex;
14716 while (ckgReplicaPtr.i != RNIL) {
14718 ptrCheckGuard(ckgReplicaPtr, creplicaFileSize, replicaRecord);
14719 if (c_lcpState.m_participatingLQH.get(ckgReplicaPtr.p->procNode))
14722 Uint32 oldestRestorableGci;
14723 findMinGci(ckgReplicaPtr, keepGci, oldestRestorableGci);
14724 if (keepGci < c_lcpState.keepGci) {
14731 c_lcpState.keepGci = keepGci;
14733 if (oldestRestorableGci > c_lcpState.oldestRestorableGci) {
14735 c_lcpState.oldestRestorableGci = oldestRestorableGci;
14738 ckgReplicaPtr.i = ckgReplicaPtr.p->nextReplica;
14742 void Dbdih::closeFile(
Signal* signal, FileRecordPtr filePtr)
14744 signal->theData[0] = filePtr.p->fileRef;
14745 signal->theData[1] = reference();
14746 signal->theData[2] = filePtr.i;
14747 signal->theData[3] = ZCLOSE_NO_DELETE;
14748 sendSignal(NDBFS_REF, GSN_FSCLOSEREQ, signal, 4, JBA);
14751 void Dbdih::closeFileDelete(
Signal* signal, FileRecordPtr filePtr)
14753 signal->theData[0] = filePtr.p->fileRef;
14754 signal->theData[1] = reference();
14755 signal->theData[2] = filePtr.i;
14756 signal->theData[3] = ZCLOSE_DELETE;
14757 sendSignal(NDBFS_REF, GSN_FSCLOSEREQ, signal, 4, JBA);
14760 void Dbdih::createFileRw(
Signal* signal, FileRecordPtr filePtr)
14762 signal->theData[0] = reference();
14763 signal->theData[1] = filePtr.i;
14764 signal->theData[2] = filePtr.p->fileName[0];
14765 signal->theData[3] = filePtr.p->fileName[1];
14766 signal->theData[4] = filePtr.p->fileName[2];
14767 signal->theData[5] = filePtr.p->fileName[3];
14768 signal->theData[6] = ZCREATE_READ_WRITE;
14769 sendSignal(NDBFS_REF, GSN_FSOPENREQ, signal, 7, JBA);
14773 Dbdih::emptyverificbuffer(
Signal* signal, Uint32 q,
bool aContinueB)
14775 if(unlikely(getBlockCommit() ==
true))
14781 if (!isEmpty(c_diverify_queue[q]))
14785 ApiConnectRecord localApiConnect;
14786 dequeue(c_diverify_queue[q], localApiConnect);
14787 ndbrequire(localApiConnect.apiGci <= m_micro_gcp.m_current_gci);
14788 signal->theData[0] = localApiConnect.senderData;
14789 signal->theData[1] = (Uint32)(m_micro_gcp.m_current_gci >> 32);
14790 signal->theData[2] = (Uint32)(m_micro_gcp.m_current_gci & 0xFFFFFFFF);
14791 signal->theData[3] = 0;
14792 sendSignal(c_diverify_queue[q].m_ref, GSN_DIVERIFYCONF, signal, 4, JBB);
14794 else if (aContinueB ==
true)
14802 Uint32 blocks[] = { DBTC, 0 };
14803 Callback c = { safe_cast(&Dbdih::emptyverificbuffer_check), q };
14808 if (aContinueB ==
true)
14817 signal->theData[0] = DihContinueB::ZEMPTY_VERIFY_QUEUE;
14818 signal->theData[1] = q;
14819 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
14826 Dbdih::emptyverificbuffer_check(
Signal* signal, Uint32 q, Uint32 retVal)
14828 ndbrequire(retVal == 0);
14829 if (!isEmpty(c_diverify_queue[q]))
14832 signal->theData[0] = DihContinueB::ZEMPTY_VERIFY_QUEUE;
14833 signal->theData[1] = q;
14834 sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
14841 c_diverify_queue[q].m_empty_done = 1;
14849 bool Dbdih::findLogNodes(CreateReplicaRecord* createReplica,
14850 FragmentstorePtr fragPtr,
14855 flnReplicaPtr.i = createReplica->replicaRec;
14856 ptrCheckGuard(flnReplicaPtr, creplicaFileSize, replicaRecord);
14873 arrGuard(flnReplicaPtr.p->noCrashedReplicas, MAX_CRASHED_REPLICAS);
14874 const Uint32 noCrashed = flnReplicaPtr.p->noCrashedReplicas;
14876 if (!(ERROR_INSERTED(7073) || ERROR_INSERTED(7074))&&
14877 (startGci >= flnReplicaPtr.p->createGci[noCrashed]) &&
14878 (stopGci <= flnReplicaPtr.p->replicaLastGci[noCrashed]) &&
14879 (stopGci <= SYSFILE->lastCompletedGCI[flnReplicaPtr.p->procNode])) {
14885 createReplica->noLogNodes = 1;
14886 createReplica->logStartGci[0] = startGci;
14887 createReplica->logStopGci[0] = stopGci;
14888 createReplica->logNodeId[0] = flnReplicaPtr.p->procNode;
14891 Uint32 logNode = 0;
14895 if(!findBestLogNode(createReplica,
14906 if (fblStopGci >= stopGci) {
14908 createReplica->noLogNodes = logNode;
14911 startGci = fblStopGci + 1;
14912 if (logNode >= MAX_LOG_EXEC)
14931 Dbdih::findBestLogNode(CreateReplicaRecord* createReplica,
14932 FragmentstorePtr fragPtr,
14936 Uint32& fblStopGci)
14940 LINT_INIT(fblFoundReplicaPtr.p);
14947 fblReplicaPtr.i = fragPtr.p->storedReplicas;
14948 while (fblReplicaPtr.i != RNIL) {
14950 ptrCheckGuard(fblReplicaPtr, creplicaFileSize, replicaRecord);
14951 if (m_sr_nodes.
get(fblReplicaPtr.p->procNode))
14954 Uint32 fliStopGci = findLogInterval(fblReplicaPtr, startGci);
14955 if (fliStopGci > fblStopGci)
14958 fblStopGci = fliStopGci;
14959 fblFoundReplicaPtr = fblReplicaPtr;
14962 fblReplicaPtr.i = fblReplicaPtr.p->nextReplica;
14964 fblReplicaPtr.i = fragPtr.p->oldStoredReplicas;
14965 while (fblReplicaPtr.i != RNIL) {
14967 ptrCheckGuard(fblReplicaPtr, creplicaFileSize, replicaRecord);
14968 if (m_sr_nodes.
get(fblReplicaPtr.p->procNode))
14971 Uint32 fliStopGci = findLogInterval(fblReplicaPtr, startGci);
14972 if (fliStopGci > fblStopGci)
14975 fblStopGci = fliStopGci;
14976 fblFoundReplicaPtr = fblReplicaPtr;
14979 fblReplicaPtr.i = fblReplicaPtr.p->nextReplica;
14981 if (fblStopGci != 0) {
14983 ndbrequire(logNode < MAX_LOG_EXEC);
14984 createReplica->logNodeId[logNode] = fblFoundReplicaPtr.p->procNode;
14985 createReplica->logStartGci[logNode] = startGci;
14986 if (fblStopGci >= stopGci) {
14988 createReplica->logStopGci[logNode] = stopGci;
14991 createReplica->logStopGci[logNode] = fblStopGci;
14995 return fblStopGci != 0;
15001 ndbrequire(replicaPtr.p->noCrashedReplicas <= MAX_CRASHED_REPLICAS);
15002 Uint32 loopLimit = replicaPtr.p->noCrashedReplicas + 1;
15003 for (Uint32 i = 0; i < loopLimit; i++) {
15005 if (replicaPtr.p->createGci[i] <= startGci) {
15006 if (replicaPtr.p->replicaLastGci[i] >= startGci) {
15008 return replicaPtr.p->replicaLastGci[
i];
15019 void Dbdih::findMinGci(ReplicaRecordPtr fmgReplicaPtr,
15021 Uint32& oldestRestorableGci)
15023 keepGci = (Uint32)-1;
15024 oldestRestorableGci = 0;
15026 Uint32 maxLcpId = 0;
15027 Uint32 maxLcpNo = MAX_LCP_STORED;
15028 for (Uint32 i = 0; i < MAX_LCP_STORED; i++)
15031 if (fmgReplicaPtr.p->lcpStatus[i] == ZVALID)
15033 if ((fmgReplicaPtr.p->lcpId[i] + MAX_LCP_STORED) <= (SYSFILE->latestLCP_ID + 1))
15041 fmgReplicaPtr.p->lcpStatus[
i] = ZINVALID;
15043 else if (fmgReplicaPtr.p->lcpId[i] > maxLcpId)
15046 maxLcpId = fmgReplicaPtr.p->lcpId[
i];
15052 if (maxLcpNo < MAX_LCP_STORED)
15058 keepGci = fmgReplicaPtr.p->maxGciCompleted[maxLcpNo];
15059 oldestRestorableGci = fmgReplicaPtr.p->maxGciStarted[maxLcpNo];
15062 if (oldestRestorableGci == 0 && keepGci == Uint32(-1))
15065 if (fmgReplicaPtr.p->createGci[0] == fmgReplicaPtr.p->initialGci)
15067 keepGci = fmgReplicaPtr.p->createGci[0];
15074 ndbassert(oldestRestorableGci <= c_newest_restorable_gci);
15085 Uint32 tmp[MAX_LCP_STORED];
15086 for (Uint32 i = 0; i<MAX_LCP_STORED; i++)
15089 if (replicaPtr.p->lcpStatus[i] == ZVALID &&
15090 replicaPtr.p->maxGciStarted[i] <= stopGci)
15110 Uint32 lcpId = replicaPtr.p->lcpId[lcpNo];
15111 for (Uint32 i = 1; i<cnt; i++)
15114 if (replicaPtr.p->lcpId[tmp[i]] > lcpId)
15118 lcpId = replicaPtr.p->lcpId[lcpNo];
15121 startGci = replicaPtr.p->maxGciCompleted[lcpNo] + 1;
15131 startGci = replicaPtr.p->initialGci;
15132 ndbrequire(replicaPtr.p->nextLcp == 0);
15141 for (ndb_mgm_first(iter); ndb_mgm_valid(iter); ndb_mgm_next(iter))
15144 Uint32 type = ~Uint32(0);
15145 if (ndb_mgm_get_int_parameter(iter, CFG_NODE_ID, &nodeId) == 0 &&
15146 ndb_mgm_get_int_parameter(iter,CFG_TYPE_OF_SECTION, &type) == 0 &&
15164 Uint32 dbnodes = count_db_nodes(cluster);
15166 Uint32 hbDBDB = 1500;
15167 Uint32 arbitTimeout = 1000;
15168 ndb_mgm_get_int_parameter(p, CFG_DB_HEARTBEAT_INTERVAL, &hbDBDB);
15169 ndb_mgm_get_int_parameter(p, CFG_DB_ARBIT_TIMEOUT, &arbitTimeout);
15174 Uint32 max_time_one_failure = arbitTimeout + 4 * hbDBDB;
15179 Uint32 max_time_total_failure = (dbnodes - 1) * max_time_one_failure;
15181 return max_time_total_failure;
15184 void Dbdih::initCommonData()
15186 c_blockCommit =
false;
15187 c_blockCommitNo = 0;
15189 cfirstAliveNode = RNIL;
15190 cfirstDeadNode = RNIL;
15191 cgckptflag =
false;
15192 cgcpOrderBlocked = 0;
15194 c_lcpMasterTakeOverState.set(LMTOS_IDLE, __LINE__);
15196 c_lcpState.clcpDelay = 0;
15197 c_lcpState.lcpStart = ZIDLE;
15198 c_lcpState.lcpStopGcp = 0;
15199 c_lcpState.setLcpStatus(LCP_STATUS_IDLE, __LINE__);
15200 c_lcpState.currentFragment.tableId = 0;
15201 c_lcpState.currentFragment.fragmentId = 0;
15202 c_lcpState.noOfLcpFragRepOutstanding = 0;
15203 c_lcpState.keepGci = 0;
15204 c_lcpState.oldestRestorableGci = 0;
15205 c_lcpState.ctcCounter = 0;
15206 c_lcpState.ctimer = 0;
15207 c_lcpState.immediateLcpStart =
false;
15208 c_lcpState.m_MASTER_LCPREQ_Received =
false;
15209 c_lcpState.m_lastLCP_COMPLETE_REP_ref = 0;
15212 cmasterState = MASTER_IDLE;
15213 cmasterTakeOverNode = 0;
15214 cnoOfActiveTables = 0;
15215 cnoOfNodeGroups = 0;
15216 c_nextNodeGroup = 0;
15221 crestartInfoFile[0] = RNIL;
15222 crestartInfoFile[1] = RNIL;
15224 cstarttype = (Uint32)-1;
15226 c_newest_restorable_gci = 0;
15227 cwaitLcpSr =
false;
15228 c_nodeStartMaster.blockGcp = 0;
15231 c_nodeStartMaster.wait = ZFALSE;
15233 memset(&sysfileData[0], 0,
sizeof(sysfileData));
15236 m_ctx.m_config.getOwnConfigIterator();
15237 ndbrequire(p != 0);
15239 c_lcpState.clcpDelay = 20;
15240 ndb_mgm_get_int_parameter(p, CFG_DB_LCP_INTERVAL, &c_lcpState.clcpDelay);
15241 c_lcpState.clcpDelay = c_lcpState.clcpDelay > 31 ? 31 : c_lcpState.clcpDelay;
15246 ndb_mgm_get_int_parameter(p, CFG_DB_NO_REPLICAS, &cnoReplicas);
15247 if (cnoReplicas > MAX_REPLICAS)
15249 progError(__LINE__, NDBD_EXIT_INVALID_CONFIG,
15250 "Only up to four replicas are supported. Check NoOfReplicas.");
15253 Uint32 max_failure_time = compute_max_failure_time
15254 (p, m_ctx.m_config.getClusterConfigIterator());
15256 bzero(&m_gcp_save,
sizeof(m_gcp_save));
15257 bzero(&m_micro_gcp,
sizeof(m_micro_gcp));
15261 ndb_mgm_get_int_parameter(p, CFG_DB_GCP_INTERVAL, &tmp);
15262 tmp = tmp > 60000 ? 60000 : (tmp < 10 ? 10 : tmp);
15263 m_gcp_save.m_master.m_time_between_gcp = tmp;
15267 if (ndb_mgm_get_int_parameter(p, CFG_DB_MICRO_GCP_INTERVAL, &tmp) == 0 &&
15273 if (tmp > m_gcp_save.m_master.m_time_between_gcp)
15274 tmp = m_gcp_save.m_master.m_time_between_gcp;
15277 m_micro_gcp.m_master.m_time_between_gcp = tmp;
15281 Uint32 tmp = 120000;
15282 tmp += max_failure_time;
15283 m_gcp_monitor.m_gcp_save.m_max_lag =
15284 (m_gcp_save.m_master.m_time_between_gcp + tmp) / 100;
15289 ndb_mgm_get_int_parameter(p, CFG_DB_MICRO_GCP_TIMEOUT, &tmp);
15293 tmp += max_failure_time;
15294 m_gcp_monitor.m_micro_gcp.m_max_lag =
15295 (m_micro_gcp.m_master.m_time_between_gcp + tmp) / 100;
15300 m_gcp_monitor.m_gcp_save.m_max_lag = 0;
15301 m_gcp_monitor.m_micro_gcp.m_max_lag = 0;
15307 void Dbdih::initFragstore(FragmentstorePtr fragPtr)
15309 fragPtr.p->storedReplicas = RNIL;
15310 fragPtr.p->oldStoredReplicas = RNIL;
15312 fragPtr.p->noStoredReplicas = 0;
15313 fragPtr.p->noOldStoredReplicas = 0;
15314 fragPtr.p->fragReplicas = 0;
15315 fragPtr.p->preferredPrimary = 0;
15317 for (Uint32 i = 0; i < MAX_REPLICAS; i++)
15318 fragPtr.p->activeNodes[i] = 0;
15320 fragPtr.p->noLcpReplicas = 0;
15321 fragPtr.p->distributionKey = 0;
15330 void Dbdih::initRestartInfo(
Signal* signal)
15333 for (i = 0; i < MAX_NDB_NODES; i++) {
15334 SYSFILE->lastCompletedGCI[
i] = 0;
15336 NodeRecordPtr nodePtr;
15337 nodePtr.i = cfirstAliveNode;
15340 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
15341 SYSFILE->lastCompletedGCI[nodePtr.i] = 1;
15343 nodePtr.i = nodePtr.p->nextNode;
15344 }
while (nodePtr.i != RNIL);
15346 Uint32 startGci = 1;
15350 const char* v = NdbEnv_GetEnv(
"NDB_START_GCI",
15355 startGci = strtoull(v, NULL, 0);
15357 ndbout_c(
"DbDih : Using value of %u from NDB_START_GCI",
15363 m_micro_gcp.m_old_gci = Uint64(startGci) << 32;
15364 m_micro_gcp.m_current_gci = Uint64(startGci + 1) << 32;
15365 crestartGci = startGci;
15366 c_newest_restorable_gci = startGci;
15368 SYSFILE->keepGCI = startGci;
15369 SYSFILE->oldestRestorableGCI = startGci;
15370 SYSFILE->newestRestorableGCI = startGci;
15371 SYSFILE->systemRestartBits = 0;
15372 for (i = 0; i < NdbNodeBitmask::Size; i++) {
15373 SYSFILE->lcpActive[0] = 0;
15375 for (i = 0; i < Sysfile::TAKE_OVER_SIZE; i++) {
15376 SYSFILE->takeOver[
i] = 0;
15378 Sysfile::setInitialStartOngoing(SYSFILE->systemRestartBits);
15379 srand((
unsigned int)time(0));
15380 globalData.m_restart_seq = SYSFILE->m_restart_seq = 0;
15382 if (m_micro_gcp.m_enabled ==
false &&
15383 m_micro_gcp.m_master.m_time_between_gcp)
15389 m_micro_gcp.m_enabled =
true;
15391 ord->type = UpgradeProtocolOrd::UPO_ENABLE_MICRO_GCP;
15392 EXECUTE_DIRECT(QMGR,GSN_UPGRADE_PROTOCOL_ORD,signal,signal->getLength());
15406 void Dbdih::initRestorableGciFiles()
15409 FileRecordPtr filePtr;
15410 seizeFile(filePtr);
15411 filePtr.p->tabRef = RNIL;
15412 filePtr.p->fileType = FileRecord::GCP_FILE;
15413 filePtr.p->reqStatus = FileRecord::IDLE;
15414 filePtr.p->fileStatus = FileRecord::CLOSED;
15415 crestartInfoFile[0] = filePtr.i;
15416 filePtr.p->fileName[0] = (Uint32)-1;
15417 filePtr.p->fileName[1] = (Uint32)-1;
15418 filePtr.p->fileName[2] = (Uint32)-1;
15420 tirgTmp = (tirgTmp << 8) + 6;
15421 tirgTmp = (tirgTmp << 8) + 1;
15422 tirgTmp = (tirgTmp << 8) + 0;
15423 filePtr.p->fileName[3] = tirgTmp;
15427 seizeFile(filePtr);
15428 filePtr.p->tabRef = RNIL;
15429 filePtr.p->fileType = FileRecord::GCP_FILE;
15430 filePtr.p->reqStatus = FileRecord::IDLE;
15431 filePtr.p->fileStatus = FileRecord::CLOSED;
15432 crestartInfoFile[1] = filePtr.i;
15433 filePtr.p->fileName[0] = (Uint32)-1;
15434 filePtr.p->fileName[1] = (Uint32)-1;
15435 filePtr.p->fileName[2] = (Uint32)-1;
15437 tirgTmp = (tirgTmp << 8) + 6;
15438 tirgTmp = (tirgTmp << 8) + 2;
15439 tirgTmp = (tirgTmp << 8) + 0;
15440 filePtr.p->fileName[3] = tirgTmp;
15446 void Dbdih::initTable(TabRecordPtr tabPtr)
15448 new (tabPtr.p) TabRecord();
15449 tabPtr.p->noOfFragChunks = 0;
15450 tabPtr.p->method = TabRecord::NOTDEFINED;
15451 tabPtr.p->tabStatus = TabRecord::TS_IDLE;
15452 tabPtr.p->noOfWords = 0;
15453 tabPtr.p->noPages = 0;
15454 tabPtr.p->tabLcpStatus = TabRecord::TLS_COMPLETED;
15455 tabPtr.p->tabCopyStatus = TabRecord::CS_IDLE;
15456 tabPtr.p->tabUpdateState = TabRecord::US_IDLE;
15457 tabPtr.p->noOfBackups = 0;
15458 tabPtr.p->kvalue = 0;
15459 tabPtr.p->hashpointer = (Uint32)-1;
15460 tabPtr.p->mask = 0;
15461 tabPtr.p->tabStorage = TabRecord::ST_NORMAL;
15462 tabPtr.p->tabErrorCode = 0;
15463 tabPtr.p->schemaVersion = (Uint32)-1;
15464 tabPtr.p->tabRemoveNode = RNIL;
15465 tabPtr.p->totalfragments = (Uint32)-1;
15466 tabPtr.p->connectrec = RNIL;
15467 tabPtr.p->tabFile[0] = RNIL;
15468 tabPtr.p->tabFile[1] = RNIL;
15469 tabPtr.p->m_dropTab.tabUserRef = 0;
15470 tabPtr.p->m_dropTab.tabUserPtr = RNIL;
15472 for (i = 0; i < NDB_ARRAY_SIZE(tabPtr.p->startFid); i++) {
15473 tabPtr.p->startFid[
i] = RNIL;
15475 for (i = 0; i < NDB_ARRAY_SIZE(tabPtr.p->pageRef); i++) {
15476 tabPtr.p->pageRef[
i] = RNIL;
15478 tabPtr.p->tableType = DictTabInfo::UndefTableType;
15479 tabPtr.p->schemaTransId = 0;
15488 void Dbdih::initTableFile(TabRecordPtr tabPtr)
15491 FileRecordPtr filePtr;
15492 seizeFile(filePtr);
15493 filePtr.p->tabRef = tabPtr.i;
15494 filePtr.p->fileType = FileRecord::TABLE_FILE;
15495 filePtr.p->reqStatus = FileRecord::IDLE;
15496 filePtr.p->fileStatus = FileRecord::CLOSED;
15497 tabPtr.p->tabFile[0] = filePtr.i;
15498 filePtr.p->fileName[0] = (Uint32)-1;
15499 filePtr.p->fileName[1] = (Uint32)-1;
15500 filePtr.p->fileName[2] = tabPtr.i;
15502 titfTmp = (titfTmp << 8) + 3;
15503 titfTmp = (titfTmp << 8) + 1;
15504 titfTmp = (titfTmp << 8) + 255;
15505 filePtr.p->fileName[3] = titfTmp;
15509 seizeFile(filePtr);
15510 filePtr.p->tabRef = tabPtr.i;
15511 filePtr.p->fileType = FileRecord::TABLE_FILE;
15512 filePtr.p->reqStatus = FileRecord::IDLE;
15513 filePtr.p->fileStatus = FileRecord::CLOSED;
15514 tabPtr.p->tabFile[1] = filePtr.i;
15515 filePtr.p->fileName[0] = (Uint32)-1;
15516 filePtr.p->fileName[1] = (Uint32)-1;
15517 filePtr.p->fileName[2] = tabPtr.i;
15519 titfTmp = (titfTmp << 8) + 3;
15520 titfTmp = (titfTmp << 8) + 2;
15521 titfTmp = (titfTmp << 8) + 255;
15522 filePtr.p->fileName[3] = titfTmp;
15528 void Dbdih::initialiseRecordsLab(
Signal* signal,
15529 Uint32 stepNo, Uint32 retRef, Uint32 retData)
15537 ApiConnectRecordPtr apiConnectptr;
15539 c_diverify_queue[0].m_ref = calcTcBlockRef(getOwnNodeId());
15540 for (Uint32 i = 0; i < c_diverify_queue_cnt; i++)
15542 if (c_diverify_queue_cnt > 1)
15544 c_diverify_queue[
i].m_ref = numberToRef(DBTC, i + 1, 0);
15547 for (apiConnectptr.i = 0;
15548 apiConnectptr.i < capiConnectFileSize; apiConnectptr.i++)
15551 ptrAss(apiConnectptr, c_diverify_queue[i].apiConnectRecord);
15552 apiConnectptr.p->senderData = RNIL;
15553 apiConnectptr.p->apiGci = ~(Uint64)0;
15560 ConnectRecordPtr connectPtr;
15563 for (connectPtr.i = 0; connectPtr.i < cconnectFileSize; connectPtr.i++) {
15565 ptrAss(connectPtr, connectRecord);
15566 connectPtr.p->userpointer = RNIL;
15567 connectPtr.p->userblockref = ZNIL;
15568 connectPtr.p->connectState = ConnectRecord::FREE;
15569 connectPtr.p->table = RNIL;
15570 connectPtr.p->nextPool = connectPtr.i + 1;
15571 bzero(connectPtr.p->nodes,
sizeof(connectPtr.p->nodes));
15573 connectPtr.i = cconnectFileSize - 1;
15574 ptrAss(connectPtr, connectRecord);
15575 connectPtr.p->nextPool = RNIL;
15581 FileRecordPtr filePtr;
15584 for (filePtr.i = 0; filePtr.i < cfileFileSize; filePtr.i++) {
15585 ptrAss(filePtr, fileRecord);
15586 filePtr.p->nextFile = filePtr.i + 1;
15587 filePtr.p->fileStatus = FileRecord::CLOSED;
15588 filePtr.p->reqStatus = FileRecord::IDLE;
15590 filePtr.i = cfileFileSize - 1;
15591 ptrAss(filePtr, fileRecord);
15592 filePtr.p->nextFile = RNIL;
15593 cfirstfreeFile = 0;
15594 initRestorableGciFiles();
15599 initialiseFragstore();
15606 NodeGroupRecordPtr loopNGPtr;
15607 for (loopNGPtr.i = 0; loopNGPtr.i < MAX_NDB_NODES; loopNGPtr.i++) {
15608 ptrAss(loopNGPtr, nodeGroupRecord);
15609 loopNGPtr.p->nodesInGroup[0] = RNIL;
15610 loopNGPtr.p->nodesInGroup[1] = RNIL;
15611 loopNGPtr.p->nodesInGroup[2] = RNIL;
15612 loopNGPtr.p->nodesInGroup[3] = RNIL;
15613 loopNGPtr.p->nextReplicaNode = 0;
15614 loopNGPtr.p->nodeCount = 0;
15615 loopNGPtr.p->activeTakeOver =
false;
15616 loopNGPtr.p->nodegroupIndex = RNIL;
15617 loopNGPtr.p->m_ref_count = 0;
15618 loopNGPtr.p->m_next_log_part = 0;
15624 PageRecordPtr pagePtr;
15627 for (pagePtr.i = 0; pagePtr.i < cpageFileSize; pagePtr.i++) {
15629 ptrAss(pagePtr, pageRecord);
15630 pagePtr.p->nextfreepage = pagePtr.i + 1;
15632 pagePtr.i = cpageFileSize - 1;
15633 ptrAss(pagePtr, pageRecord);
15634 pagePtr.p->nextfreepage = RNIL;
15635 cfirstfreepage = 0;
15640 ReplicaRecordPtr initReplicaPtr;
15643 for (initReplicaPtr.i = 0; initReplicaPtr.i < creplicaFileSize;
15644 initReplicaPtr.i++) {
15646 ptrAss(initReplicaPtr, replicaRecord);
15647 initReplicaPtr.p->lcpIdStarted = 0;
15648 initReplicaPtr.p->lcpOngoingFlag =
false;
15649 initReplicaPtr.p->nextReplica = initReplicaPtr.i + 1;
15651 initReplicaPtr.i = creplicaFileSize - 1;
15652 ptrAss(initReplicaPtr, replicaRecord);
15653 initReplicaPtr.p->nextReplica = RNIL;
15654 cnoFreeReplicaRec = creplicaFileSize;
15655 cfirstfreeReplica = 0;
15660 TabRecordPtr loopTabptr;
15663 for (loopTabptr.i = 0; loopTabptr.i < ctabFileSize; loopTabptr.i++) {
15664 ptrAss(loopTabptr, tabRecord);
15666 initTable(loopTabptr);
15674 conf->senderRef = reference();
15675 conf->senderData = retData;
15676 sendSignal(retRef, GSN_READ_CONFIG_CONF, signal,
15677 ReadConfigConf::SignalLength, JBB);
15689 signal->theData[0] = DihContinueB::ZINITIALISE_RECORDS;
15690 signal->theData[1] = stepNo + 1;
15691 signal->theData[2] = retRef;
15692 signal->theData[3] = retData;
15693 sendSignal(reference(), GSN_CONTINUEB, signal, 4, JBB);
15701 void Dbdih::insertAlive(NodeRecordPtr newNodePtr)
15703 NodeRecordPtr nodePtr;
15705 nodePtr.i = cfirstAliveNode;
15706 if (nodePtr.i == RNIL) {
15708 cfirstAliveNode = newNodePtr.i;
15711 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
15712 if (nodePtr.p->nextNode == RNIL) {
15714 nodePtr.p->nextNode = newNodePtr.i;
15718 nodePtr.i = nodePtr.p->nextNode;
15722 newNodePtr.p->nextNode = RNIL;
15725 void Dbdih::insertBackup(FragmentstorePtr fragPtr, Uint32 nodeId)
15727 for (Uint32 i = fragPtr.p->fragReplicas; i > 1; i--) {
15729 ndbrequire(i < MAX_REPLICAS && i > 0);
15730 fragPtr.p->activeNodes[
i] = fragPtr.p->activeNodes[i - 1];
15732 fragPtr.p->activeNodes[1] = nodeId;
15733 fragPtr.p->fragReplicas++;
15736 void Dbdih::insertDeadNode(NodeRecordPtr newNodePtr)
15738 NodeRecordPtr nodePtr;
15740 nodePtr.i = cfirstDeadNode;
15741 if (nodePtr.i == RNIL) {
15743 cfirstDeadNode = newNodePtr.i;
15747 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
15748 if (nodePtr.p->nextNode == RNIL) {
15750 nodePtr.p->nextNode = newNodePtr.i;
15754 nodePtr.i = nodePtr.p->nextNode;
15758 newNodePtr.p->nextNode = RNIL;
15761 void Dbdih::linkOldStoredReplica(FragmentstorePtr fragPtr,
15762 ReplicaRecordPtr replicatePtr)
15764 ReplicaRecordPtr losReplicaPtr;
15766 replicatePtr.p->nextReplica = RNIL;
15767 fragPtr.p->noOldStoredReplicas++;
15768 losReplicaPtr.i = fragPtr.p->oldStoredReplicas;
15769 if (losReplicaPtr.i == RNIL) {
15771 fragPtr.p->oldStoredReplicas = replicatePtr.i;
15774 ptrCheckGuard(losReplicaPtr, creplicaFileSize, replicaRecord);
15775 while (losReplicaPtr.p->nextReplica != RNIL) {
15777 losReplicaPtr.i = losReplicaPtr.p->nextReplica;
15778 ptrCheckGuard(losReplicaPtr, creplicaFileSize, replicaRecord);
15780 losReplicaPtr.p->nextReplica = replicatePtr.i;
15783 void Dbdih::linkStoredReplica(FragmentstorePtr fragPtr,
15784 ReplicaRecordPtr replicatePtr)
15786 ReplicaRecordPtr lsrReplicaPtr;
15788 fragPtr.p->noStoredReplicas++;
15789 replicatePtr.p->nextReplica = RNIL;
15790 lsrReplicaPtr.i = fragPtr.p->storedReplicas;
15791 if (fragPtr.p->storedReplicas == RNIL) {
15793 fragPtr.p->storedReplicas = replicatePtr.i;
15796 ptrCheckGuard(lsrReplicaPtr, creplicaFileSize, replicaRecord);
15797 while (lsrReplicaPtr.p->nextReplica != RNIL) {
15799 lsrReplicaPtr.i = lsrReplicaPtr.p->nextReplica;
15800 ptrCheckGuard(lsrReplicaPtr, creplicaFileSize, replicaRecord);
15802 lsrReplicaPtr.p->nextReplica = replicatePtr.i;
15809 Dbdih::add_nodegroup(NodeGroupRecordPtr NGPtr)
15811 if (NGPtr.p->nodegroupIndex == RNIL)
15814 NGPtr.p->nodegroupIndex = cnoOfNodeGroups;
15815 c_node_groups[cnoOfNodeGroups++] = NGPtr.i;
15820 Dbdih::inc_ng_refcount(Uint32 i)
15822 NodeGroupRecordPtr NGPtr;
15824 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15825 NGPtr.p->m_ref_count++;
15829 Dbdih::dec_ng_refcount(Uint32 i)
15831 NodeGroupRecordPtr NGPtr;
15833 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15834 ndbrequire(NGPtr.p->m_ref_count);
15835 NGPtr.p->m_ref_count--;
15838 void Dbdih::makeNodeGroups(Uint32 nodeArray[])
15840 NodeGroupRecordPtr NGPtr;
15841 NodeRecordPtr mngNodeptr;
15848 cnoOfNodeGroups = 0;
15849 for (Uint32 i = 0; nodeArray[
i] != RNIL; i++)
15852 mngNodeptr.i = nodeArray[
i];
15853 ptrCheckGuard(mngNodeptr, MAX_NDB_NODES, nodeRecord);
15857 mngNodeptr.p->nodeGroup = ZNIL;
15858 ndbout_c(
"setting nodeGroup = ZNIL for node %u",
15861 else if (mngNodeptr.p->nodeGroup != RNIL)
15864 NGPtr.i = mngNodeptr.p->nodeGroup;
15865 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15866 arrGuard(NGPtr.p->nodeCount, MAX_REPLICAS);
15867 NGPtr.p->nodesInGroup[NGPtr.p->nodeCount++] = mngNodeptr.i;
15869 add_nodegroup(NGPtr);
15873 for (; NGPtr.i < MAX_NDB_NODES; NGPtr.i++)
15876 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15877 if (NGPtr.p->nodeCount < cnoReplicas)
15881 for (Uint32 i = 0; nodeArray[
i] != RNIL; i++)
15884 mngNodeptr.i = nodeArray[
i];
15885 ptrCheckGuard(mngNodeptr, MAX_NDB_NODES, nodeRecord);
15886 if (mngNodeptr.p->nodeGroup == RNIL)
15888 mngNodeptr.p->nodeGroup = NGPtr.i;
15889 NGPtr.p->nodesInGroup[NGPtr.p->nodeCount++] = mngNodeptr.i;
15891 add_nodegroup(NGPtr);
15893 if (NGPtr.p->nodeCount == cnoReplicas)
15896 for (; NGPtr.i < MAX_NDB_NODES; NGPtr.i++)
15899 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15900 if (NGPtr.p->nodeCount < cnoReplicas)
15908 for (Uint32 i = 0; i<cnoOfNodeGroups; i++)
15911 NGPtr.i = c_node_groups[
i];
15912 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15913 if (NGPtr.p->nodeCount == 0)
15917 else if (NGPtr.p->nodeCount != cnoReplicas)
15923 if (NGPtr.i > maxNG)
15930 ndbrequire(csystemnodes < MAX_NDB_NODES);
15935 for(Uint32 i = 0; i < MAX_NDB_NODES; i++)
15938 Sysfile::setNodeGroup(i, SYSFILE->nodeGroups, NO_NODE_GROUP_ID);
15939 Sysfile::setNodeStatus(i, SYSFILE->nodeStatus,Sysfile::NS_NotDefined);
15942 for (Uint32 i = 0; nodeArray[
i] != RNIL; i++)
15945 Uint32 nodeId = mngNodeptr.i = nodeArray[
i];
15946 ptrCheckGuard(mngNodeptr, MAX_NDB_NODES, nodeRecord);
15948 if (mngNodeptr.p->nodeGroup != ZNIL)
15951 Sysfile::setNodeGroup(nodeId, SYSFILE->nodeGroups,
15952 mngNodeptr.p->nodeGroup);
15954 if (mngNodeptr.p->nodeStatus == NodeRecord::ALIVE)
15957 mngNodeptr.p->activeStatus = Sysfile::NS_Active;
15962 mngNodeptr.p->activeStatus = Sysfile::NS_NotActive_NotTakenOver;
15968 Sysfile::setNodeGroup(mngNodeptr.i, SYSFILE->nodeGroups,
15970 mngNodeptr.p->activeStatus = Sysfile::NS_Configured;
15972 Sysfile::setNodeStatus(nodeId, SYSFILE->nodeStatus,
15973 mngNodeptr.p->activeStatus);
15976 for (Uint32 i = 0; i<cnoOfNodeGroups; i++)
15979 bool alive =
false;
15980 NodeGroupRecordPtr NGPtr;
15981 NGPtr.i = c_node_groups[
i];
15982 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
15983 for (j = 0; j<NGPtr.p->nodeCount; j++)
15986 mngNodeptr.i = NGPtr.p->nodesInGroup[j];
15987 ptrCheckGuard(mngNodeptr, MAX_NDB_NODES, nodeRecord);
15988 if (checkNodeAlive(NGPtr.p->nodesInGroup[j]))
16000 "Illegal initial start, no alive node in nodegroup %u", i);
16002 NDBD_EXIT_INSUFFICENT_NODES,
16017 void Dbdih::execCHECKNODEGROUPSREQ(
Signal* signal)
16022 bool direct = (sd->requestType & CheckNodeGroups::Direct);
16024 switch(sd->requestType & ~CheckNodeGroups::Direct){
16025 case CheckNodeGroups::ArbitCheck:{
16028 unsigned missall = 0;
16029 unsigned haveall = 0;
16030 for (Uint32 i = 0; i < cnoOfNodeGroups; i++) {
16032 NodeGroupRecordPtr ngPtr;
16033 ngPtr.i = c_node_groups[
i];
16034 ptrAss(ngPtr, nodeGroupRecord);
16036 for (Uint32 j = 0; j < ngPtr.p->nodeCount; j++) {
16038 Uint32 nodeId = ngPtr.p->nodesInGroup[j];
16039 if (sd->mask.
get(nodeId)) {
16048 if (count == ngPtr.p->nodeCount) {
16055 sd->output = CheckNodeGroups::Lose;
16056 }
else if (haveall) {
16058 sd->output = CheckNodeGroups::Win;
16061 sd->output = CheckNodeGroups::Partitioning;
16065 case CheckNodeGroups::GetNodeGroup:{
16067 Uint32 ng = Sysfile::getNodeGroup(getOwnNodeId(), SYSFILE->nodeGroups);
16068 if (ng == NO_NODE_GROUP_ID)
16073 case CheckNodeGroups::GetNodeGroupMembers: {
16075 Uint32 ng = Sysfile::getNodeGroup(sd->nodeId, SYSFILE->nodeGroups);
16076 if (ng == NO_NODE_GROUP_ID)
16082 NodeGroupRecordPtr ngPtr;
16084 if (ngPtr.i != RNIL)
16087 ptrAss(ngPtr, nodeGroupRecord);
16088 for (Uint32 j = 0; j < ngPtr.p->nodeCount; j++) {
16090 sd->mask.
set(ngPtr.p->nodesInGroup[j]);
16095 case CheckNodeGroups::GetDefaultFragments:
16098 sd->output = (cnoOfNodeGroups + sd->extraNodeGroups)
16099 * c_fragments_per_node * cnoReplicas;
16105 sendSignal(sd->blockRef, GSN_CHECKNODEGROUPSCONF, signal,
16106 CheckNodeGroups::SignalLength, JBB);
16110 Dbdih::makePrnList(
ReadNodesConf * readNodes, Uint32 nodeArray[])
16112 cfirstAliveNode = RNIL;
16113 ndbrequire(con_lineNodes > 0);
16114 ndbrequire(csystemnodes < MAX_NDB_NODES);
16115 for (Uint32 i = 0; i < csystemnodes; i++) {
16116 NodeRecordPtr nodePtr;
16118 nodePtr.i = nodeArray[
i];
16119 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
16120 new (nodePtr.p) NodeRecord();
16123 nodePtr.p->nodeStatus = NodeRecord::ALIVE;
16124 nodePtr.p->useInTransactions =
true;
16125 nodePtr.p->copyCompleted =
true;
16126 nodePtr.p->m_inclDihLcp =
true;
16127 insertAlive(nodePtr);
16130 nodePtr.p->nodeStatus = NodeRecord::DEAD;
16131 insertDeadNode(nodePtr);
16139 void Dbdih::newCrashedReplica(ReplicaRecordPtr ncrReplicaPtr)
16149 Uint32 nodeId = ncrReplicaPtr.p->procNode;
16150 Uint32 lastGCI = SYSFILE->lastCompletedGCI[nodeId];
16151 if (ncrReplicaPtr.p->noCrashedReplicas + 1 == MAX_CRASHED_REPLICAS)
16154 packCrashedReplicas(ncrReplicaPtr);
16157 Uint32 noCrashedReplicas = ncrReplicaPtr.p->noCrashedReplicas;
16158 arrGuardErr(ncrReplicaPtr.p->noCrashedReplicas + 1, MAX_CRASHED_REPLICAS,
16159 NDBD_EXIT_MAX_CRASHED_REPLICAS);
16161 if (noCrashedReplicas > 0 &&
16162 ncrReplicaPtr.p->replicaLastGci[noCrashedReplicas - 1] == lastGCI)
16169 ncrReplicaPtr.p->createGci[ncrReplicaPtr.p->noCrashedReplicas] =
16171 ncrReplicaPtr.p->replicaLastGci[ncrReplicaPtr.p->noCrashedReplicas] =
16172 ZINIT_REPLICA_LAST_GCI;
16174 else if (ncrReplicaPtr.p->createGci[noCrashedReplicas] <= lastGCI)
16177 ncrReplicaPtr.p->replicaLastGci[ncrReplicaPtr.p->noCrashedReplicas] =
16179 ncrReplicaPtr.p->noCrashedReplicas = ncrReplicaPtr.p->noCrashedReplicas + 1;
16180 ncrReplicaPtr.p->createGci[ncrReplicaPtr.p->noCrashedReplicas] =
16182 ncrReplicaPtr.p->replicaLastGci[ncrReplicaPtr.p->noCrashedReplicas] =
16183 ZINIT_REPLICA_LAST_GCI;
16197 ncrReplicaPtr.p->createGci[noCrashedReplicas] = ZINIT_CREATE_GCI;
16207 void Dbdih::nodeResetStart(
Signal *signal)
16210 Uint32 startGCP = c_nodeStartMaster.blockGcp;
16212 c_nodeStartSlave.nodeId = 0;
16213 c_nodeStartMaster.startNode = RNIL;
16214 c_nodeStartMaster.failNr = cfailurenr;
16215 c_nodeStartMaster.activeState =
false;
16216 c_nodeStartMaster.blockGcp = 0;
16217 c_nodeStartMaster.blockLcp =
false;
16218 c_nodeStartMaster.m_outstandingGsn = 0;
16223 ndbrequire(isMaster());
16224 ndbrequire(m_micro_gcp.m_master.m_state == MicroGcp::M_GCP_IDLE);
16225 signal->theData[0] = DihContinueB::ZSTART_GCP;
16226 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
16230 void Dbdih::openFileRw(
Signal* signal, FileRecordPtr filePtr)
16232 signal->theData[0] = reference();
16233 signal->theData[1] = filePtr.i;
16234 signal->theData[2] = filePtr.p->fileName[0];
16235 signal->theData[3] = filePtr.p->fileName[1];
16236 signal->theData[4] = filePtr.p->fileName[2];
16237 signal->theData[5] = filePtr.p->fileName[3];
16238 signal->theData[6] = FsOpenReq::OM_READWRITE;
16239 sendSignal(NDBFS_REF, GSN_FSOPENREQ, signal, 7, JBA);
16242 void Dbdih::openFileRo(
Signal* signal, FileRecordPtr filePtr)
16244 signal->theData[0] = reference();
16245 signal->theData[1] = filePtr.i;
16246 signal->theData[2] = filePtr.p->fileName[0];
16247 signal->theData[3] = filePtr.p->fileName[1];
16248 signal->theData[4] = filePtr.p->fileName[2];
16249 signal->theData[5] = filePtr.p->fileName[3];
16250 signal->theData[6] = FsOpenReq::OM_READONLY;
16251 sendSignal(NDBFS_REF, GSN_FSOPENREQ, signal, 7, JBA);
16258 void Dbdih::packCrashedReplicas(ReplicaRecordPtr replicaPtr)
16260 ndbrequire(replicaPtr.p->noCrashedReplicas > 0);
16261 ndbrequire(replicaPtr.p->noCrashedReplicas <= MAX_CRASHED_REPLICAS);
16262 for (Uint32 i = 0; i < replicaPtr.p->noCrashedReplicas; i++) {
16264 replicaPtr.p->createGci[
i] = replicaPtr.p->createGci[i + 1];
16265 replicaPtr.p->replicaLastGci[
i] = replicaPtr.p->replicaLastGci[i + 1];
16267 replicaPtr.p->noCrashedReplicas--;
16268 replicaPtr.p->createGci[replicaPtr.p->noCrashedReplicas + 1] =
16270 replicaPtr.p->replicaLastGci[replicaPtr.p->noCrashedReplicas + 1] =
16271 ZINIT_REPLICA_LAST_GCI;
16275 Dbdih::mergeCrashedReplicas(ReplicaRecordPtr replicaPtr)
16280 for (Uint32 i = replicaPtr.p->noCrashedReplicas; i > 0; i--)
16283 if (replicaPtr.p->createGci[i] == 1 + replicaPtr.p->replicaLastGci[i-1])
16286 replicaPtr.p->replicaLastGci[i-1] = replicaPtr.p->replicaLastGci[
i];
16287 replicaPtr.p->createGci[
i] = ZINIT_CREATE_GCI;
16288 replicaPtr.p->replicaLastGci[
i] = ZINIT_REPLICA_LAST_GCI;
16289 replicaPtr.p->noCrashedReplicas--;
16299 void Dbdih::prepareReplicas(FragmentstorePtr fragPtr)
16301 ReplicaRecordPtr prReplicaPtr;
16302 Uint32 prevReplica = RNIL;
16309 prReplicaPtr.i = fragPtr.p->storedReplicas;
16310 while (prReplicaPtr.i != RNIL) {
16312 prevReplica = prReplicaPtr.i;
16313 ptrCheckGuard(prReplicaPtr, creplicaFileSize, replicaRecord);
16314 prReplicaPtr.i = prReplicaPtr.p->nextReplica;
16319 if (prevReplica != RNIL) {
16320 prReplicaPtr.i = prevReplica;
16321 ptrCheckGuard(prReplicaPtr, creplicaFileSize, replicaRecord);
16322 prReplicaPtr.p->nextReplica = fragPtr.p->oldStoredReplicas;
16323 fragPtr.p->oldStoredReplicas = fragPtr.p->storedReplicas;
16324 fragPtr.p->storedReplicas = RNIL;
16325 fragPtr.p->noOldStoredReplicas += fragPtr.p->noStoredReplicas;
16326 fragPtr.p->noStoredReplicas = 0;
16330 void Dbdih::readFragment(RWFragment* rf, FragmentstorePtr fragPtr)
16332 Uint32 TreadFid = readPageWord(rf);
16333 fragPtr.p->preferredPrimary = readPageWord(rf);
16334 fragPtr.p->noStoredReplicas = readPageWord(rf);
16335 fragPtr.p->noOldStoredReplicas = readPageWord(rf);
16336 Uint32 TdistKey = readPageWord(rf);
16338 ndbrequire(fragPtr.p->noStoredReplicas > 0);
16339 ndbrequire(TreadFid == rf->fragId);
16340 ndbrequire(TdistKey < 256);
16341 fragPtr.p->distributionKey = TdistKey;
16343 fragPtr.p->m_log_part_id = readPageWord(rf);
16344 inc_ng_refcount(getNodeGroup(fragPtr.p->preferredPrimary));
16347 Uint32 Dbdih::readPageWord(RWFragment* rf)
16349 if (rf->wordIndex >= 2048) {
16351 ndbrequire(rf->wordIndex == 2048);
16353 ndbrequire(rf->pageIndex < NDB_ARRAY_SIZE(rf->rwfTabPtr.p->pageRef));
16354 rf->rwfPageptr.i = rf->rwfTabPtr.p->pageRef[rf->pageIndex];
16355 ptrCheckGuard(rf->rwfPageptr, cpageFileSize, pageRecord);
16356 rf->wordIndex = 32;
16358 Uint32 dataWord = rf->rwfPageptr.p->word[rf->wordIndex];
16363 void Dbdih::readReplica(RWFragment* rf, ReplicaRecordPtr readReplicaPtr)
16366 readReplicaPtr.p->procNode = readPageWord(rf);
16367 readReplicaPtr.p->initialGci = readPageWord(rf);
16368 readReplicaPtr.p->noCrashedReplicas = readPageWord(rf);
16369 readReplicaPtr.p->nextLcp = readPageWord(rf);
16371 for (i = 0; i < MAX_LCP_STORED; i++) {
16372 readReplicaPtr.p->maxGciCompleted[
i] = readPageWord(rf);
16373 readReplicaPtr.p->maxGciStarted[
i] = readPageWord(rf);
16374 readReplicaPtr.p->lcpId[
i] = readPageWord(rf);
16375 readReplicaPtr.p->lcpStatus[
i] = readPageWord(rf);
16377 const Uint32 noCrashedReplicas = readReplicaPtr.p->noCrashedReplicas;
16378 ndbrequire(noCrashedReplicas < MAX_CRASHED_REPLICAS);
16379 for (i = 0; i < noCrashedReplicas; i++) {
16380 readReplicaPtr.p->createGci[
i] = readPageWord(rf);
16381 readReplicaPtr.p->replicaLastGci[
i] = readPageWord(rf);
16383 for(i = noCrashedReplicas; i<MAX_CRASHED_REPLICAS; i++){
16384 readReplicaPtr.p->createGci[
i] = readPageWord(rf);
16385 readReplicaPtr.p->replicaLastGci[
i] = readPageWord(rf);
16389 void Dbdih::readReplicas(RWFragment* rf, FragmentstorePtr fragPtr)
16392 ReplicaRecordPtr newReplicaPtr;
16393 Uint32 noStoredReplicas = fragPtr.p->noStoredReplicas;
16394 Uint32 noOldStoredReplicas = fragPtr.p->noOldStoredReplicas;
16399 fragPtr.p->noStoredReplicas = 0;
16400 fragPtr.p->noOldStoredReplicas = 0;
16401 Uint32 replicaIndex = 0;
16402 ndbrequire(noStoredReplicas + noOldStoredReplicas <= MAX_REPLICAS);
16403 for (i = 0; i < noStoredReplicas; i++)
16405 seizeReplicaRec(newReplicaPtr);
16406 readReplica(rf, newReplicaPtr);
16407 ndbrequire(replicaIndex < MAX_REPLICAS);
16408 fragPtr.p->activeNodes[replicaIndex] = newReplicaPtr.p->procNode;
16410 linkStoredReplica(fragPtr, newReplicaPtr);
16412 fragPtr.p->fragReplicas = noStoredReplicas;
16413 for (i = 0; i < noOldStoredReplicas; i++) {
16415 seizeReplicaRec(newReplicaPtr);
16416 readReplica(rf, newReplicaPtr);
16417 linkOldStoredReplica(fragPtr, newReplicaPtr);
16421 void Dbdih::readRestorableGci(
Signal* signal, FileRecordPtr filePtr)
16423 signal->theData[0] = filePtr.p->fileRef;
16424 signal->theData[1] = reference();
16425 signal->theData[2] = filePtr.i;
16426 signal->theData[3] = ZLIST_OF_PAIRS;
16427 signal->theData[4] = ZVAR_NO_CRESTART_INFO;
16428 signal->theData[5] = 1;
16429 signal->theData[6] = 0;
16430 signal->theData[7] = 0;
16431 sendSignal(NDBFS_REF, GSN_FSREADREQ, signal, 8, JBA);
16434 void Dbdih::readTabfile(
Signal* signal, TabRecord* tab, FileRecordPtr filePtr)
16436 signal->theData[0] = filePtr.p->fileRef;
16437 signal->theData[1] = reference();
16438 signal->theData[2] = filePtr.i;
16439 signal->theData[3] = ZLIST_OF_PAIRS;
16440 signal->theData[4] = ZVAR_NO_WORD;
16441 signal->theData[5] = tab->noPages;
16442 Uint32 section[2 * NDB_ARRAY_SIZE(tab->pageRef)];
16443 for (Uint32 i = 0; i < tab->noPages; i++)
16445 section[(2 *
i) + 0] = tab->pageRef[i];
16446 section[(2 * i) + 1] =
i;
16449 ptr[0].p = section;
16450 ptr[0].sz = 2 * tab->noPages;
16451 sendSignal(NDBFS_REF, GSN_FSREADREQ, signal, 6, JBA, ptr, 1);
16454 void Dbdih::releasePage(Uint32 pageIndex)
16456 PageRecordPtr pagePtr;
16457 pagePtr.i = pageIndex;
16458 ptrCheckGuard(pagePtr, cpageFileSize, pageRecord);
16459 pagePtr.p->nextfreepage = cfirstfreepage;
16460 cfirstfreepage = pagePtr.i;
16463 void Dbdih::releaseTabPages(Uint32 tableId)
16465 TabRecordPtr tabPtr;
16466 tabPtr.i = tableId;
16467 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
16468 ndbrequire(tabPtr.p->noPages <= NDB_ARRAY_SIZE(tabPtr.p->pageRef));
16469 for (Uint32 i = 0; i < tabPtr.p->noPages; i++) {
16471 releasePage(tabPtr.p->pageRef[i]);
16473 tabPtr.p->noPages = 0;
16479 void Dbdih::removeAlive(NodeRecordPtr removeNodePtr)
16481 NodeRecordPtr nodePtr;
16483 nodePtr.i = cfirstAliveNode;
16484 if (nodePtr.i == removeNodePtr.i) {
16486 cfirstAliveNode = removeNodePtr.p->nextNode;
16491 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
16492 if (nodePtr.p->nextNode == removeNodePtr.i) {
16494 nodePtr.p->nextNode = removeNodePtr.p->nextNode;
16498 nodePtr.i = nodePtr.p->nextNode;
16506 void Dbdih::removeDeadNode(NodeRecordPtr removeNodePtr)
16508 NodeRecordPtr nodePtr;
16510 nodePtr.i = cfirstDeadNode;
16511 if (nodePtr.i == removeNodePtr.i) {
16513 cfirstDeadNode = removeNodePtr.p->nextNode;
16518 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
16519 if (nodePtr.p->nextNode == removeNodePtr.i) {
16521 nodePtr.p->nextNode = removeNodePtr.p->nextNode;
16525 nodePtr.i = nodePtr.p->nextNode;
16535 void Dbdih::removeNodeFromStored(Uint32 nodeId,
16536 FragmentstorePtr fragPtr,
16537 ReplicaRecordPtr replicatePtr,
16543 newCrashedReplica(replicatePtr);
16549 removeStoredReplica(fragPtr, replicatePtr);
16550 linkOldStoredReplica(fragPtr, replicatePtr);
16551 ndbrequire(fragPtr.p->storedReplicas != RNIL);
16557 void Dbdih::removeOldCrashedReplicas(Uint32 tab, Uint32 frag,
16558 ReplicaRecordPtr rocReplicaPtr)
16560 mergeCrashedReplicas(rocReplicaPtr);
16561 while (rocReplicaPtr.p->noCrashedReplicas > 0) {
16566 if (rocReplicaPtr.p->replicaLastGci[0] < SYSFILE->oldestRestorableGCI){
16572 packCrashedReplicas(rocReplicaPtr);
16578 while (rocReplicaPtr.p->createGci[0] < SYSFILE->keepGCI)
16585 rocReplicaPtr.p->createGci[0] = SYSFILE->keepGCI;
16587 if (rocReplicaPtr.p->noCrashedReplicas)
16593 if (rocReplicaPtr.p->createGci[0] > rocReplicaPtr.p->replicaLastGci[0])
16596 packCrashedReplicas(rocReplicaPtr);
16602 void Dbdih::removeOldStoredReplica(FragmentstorePtr fragPtr,
16603 ReplicaRecordPtr replicatePtr)
16605 ReplicaRecordPtr rosTmpReplicaPtr;
16606 ReplicaRecordPtr rosPrevReplicaPtr;
16608 fragPtr.p->noOldStoredReplicas--;
16609 if (fragPtr.p->oldStoredReplicas == replicatePtr.i) {
16611 fragPtr.p->oldStoredReplicas = replicatePtr.p->nextReplica;
16613 rosPrevReplicaPtr.i = fragPtr.p->oldStoredReplicas;
16614 ptrCheckGuard(rosPrevReplicaPtr, creplicaFileSize, replicaRecord);
16615 rosTmpReplicaPtr.i = rosPrevReplicaPtr.p->nextReplica;
16616 while (rosTmpReplicaPtr.i != replicatePtr.i) {
16618 rosPrevReplicaPtr.i = rosTmpReplicaPtr.i;
16619 ptrCheckGuard(rosPrevReplicaPtr, creplicaFileSize, replicaRecord);
16620 ptrCheckGuard(rosTmpReplicaPtr, creplicaFileSize, replicaRecord);
16621 rosTmpReplicaPtr.i = rosTmpReplicaPtr.p->nextReplica;
16623 rosPrevReplicaPtr.p->nextReplica = replicatePtr.p->nextReplica;
16627 void Dbdih::removeStoredReplica(FragmentstorePtr fragPtr,
16628 ReplicaRecordPtr replicatePtr)
16630 ReplicaRecordPtr rsrTmpReplicaPtr;
16631 ReplicaRecordPtr rsrPrevReplicaPtr;
16633 fragPtr.p->noStoredReplicas--;
16634 if (fragPtr.p->storedReplicas == replicatePtr.i) {
16636 fragPtr.p->storedReplicas = replicatePtr.p->nextReplica;
16639 rsrPrevReplicaPtr.i = fragPtr.p->storedReplicas;
16640 rsrTmpReplicaPtr.i = fragPtr.p->storedReplicas;
16641 ptrCheckGuard(rsrTmpReplicaPtr, creplicaFileSize, replicaRecord);
16642 rsrTmpReplicaPtr.i = rsrTmpReplicaPtr.p->nextReplica;
16643 while (rsrTmpReplicaPtr.i != replicatePtr.i) {
16645 rsrPrevReplicaPtr.i = rsrTmpReplicaPtr.i;
16646 ptrCheckGuard(rsrTmpReplicaPtr, creplicaFileSize, replicaRecord);
16647 rsrTmpReplicaPtr.i = rsrTmpReplicaPtr.p->nextReplica;
16649 ptrCheckGuard(rsrPrevReplicaPtr, creplicaFileSize, replicaRecord);
16650 rsrPrevReplicaPtr.p->nextReplica = replicatePtr.p->nextReplica;
16657 void Dbdih::removeTooNewCrashedReplicas(ReplicaRecordPtr rtnReplicaPtr, Uint32 lastCompletedGCI)
16659 while (rtnReplicaPtr.p->noCrashedReplicas > 0) {
16666 arrGuard(rtnReplicaPtr.p->noCrashedReplicas - 1, MAX_CRASHED_REPLICAS);
16667 if (rtnReplicaPtr.p->createGci[rtnReplicaPtr.p->noCrashedReplicas - 1] > lastCompletedGCI)
16670 rtnReplicaPtr.p->createGci[rtnReplicaPtr.p->noCrashedReplicas - 1] =
16672 rtnReplicaPtr.p->replicaLastGci[rtnReplicaPtr.p->noCrashedReplicas - 1] =
16673 ZINIT_REPLICA_LAST_GCI;
16674 rtnReplicaPtr.p->noCrashedReplicas--;
16688 Dbdih::setup_create_replica(FragmentstorePtr fragPtr,
16689 CreateReplicaRecord* createReplicaPtrP,
16692 createReplicaPtrP->dataNodeId = replicaPtr.p->procNode;
16693 createReplicaPtrP->replicaRec = replicaPtr.i;
16701 Uint32 stopGci = SYSFILE->newestRestorableGCI;
16702 bool result = findStartGci(replicaPtr,
16719 createReplicaPtrP->lcpNo = ZNIL;
16728 createReplicaPtrP->lcpNo = startLcpNo;
16729 arrGuard(startLcpNo, MAX_LCP_STORED);
16730 createReplicaPtrP->createLcpId = replicaPtr.p->lcpId[startLcpNo];
16740 return findLogNodes(createReplicaPtrP, fragPtr, startGci, stopGci);
16743 void Dbdih::searchStoredReplicas(FragmentstorePtr fragPtr)
16745 Uint32 nextReplicaPtrI;
16748 replicaPtr.i = fragPtr.p->storedReplicas;
16749 while (replicaPtr.i != RNIL) {
16751 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
16752 nextReplicaPtrI = replicaPtr.p->nextReplica;
16754 constReplicaPtr.i = replicaPtr.i;
16755 constReplicaPtr.p = replicaPtr.p;
16756 NodeRecordPtr nodePtr;
16757 nodePtr.i = replicaPtr.p->procNode;
16758 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
16759 if (nodePtr.p->nodeStatus == NodeRecord::ALIVE) {
16761 switch (nodePtr.p->activeStatus) {
16762 case Sysfile::NS_Active:
16763 case Sysfile::NS_ActiveMissed_1:
16764 case Sysfile::NS_ActiveMissed_2:{
16771 CreateReplicaRecordPtr createReplicaPtr;
16772 createReplicaPtr.i = cnoOfCreateReplicas;
16773 ptrCheckGuard(createReplicaPtr, 4, createReplicaRecord);
16774 cnoOfCreateReplicas++;
16779 ndbrequire(setup_create_replica(fragPtr,
16780 createReplicaPtr.p,
16790 replicaPtr.i = nextReplicaPtrI;
16800 void Dbdih::seizeFile(FileRecordPtr& filePtr)
16802 filePtr.i = cfirstfreeFile;
16803 ptrCheckGuard(filePtr, cfileFileSize, fileRecord);
16804 cfirstfreeFile = filePtr.p->nextFile;
16805 filePtr.p->nextFile = RNIL;
16815 void Dbdih::sendStartFragreq(
Signal* signal,
16816 TabRecordPtr tabPtr, Uint32 fragId)
16818 CreateReplicaRecordPtr replicaPtr;
16819 for (replicaPtr.i = 0; replicaPtr.i < cnoOfCreateReplicas; replicaPtr.i++) {
16821 ptrAss(replicaPtr, createReplicaRecord);
16823 BlockReference ref = numberToRef(DBLQH, replicaPtr.p->dataNodeId);
16826 startFragReq->userPtr = replicaPtr.p->replicaRec;
16827 startFragReq->userRef = reference();
16828 startFragReq->lcpNo = replicaPtr.p->lcpNo;
16829 startFragReq->lcpId = replicaPtr.p->createLcpId;
16830 startFragReq->tableId = tabPtr.i;
16831 startFragReq->fragId = fragId;
16832 startFragReq->requestInfo = StartFragReq::SFR_RESTORE_LCP;
16834 if(ERROR_INSERTED(7072) || ERROR_INSERTED(7074)){
16836 const Uint32 noNodes = replicaPtr.p->noLogNodes;
16837 Uint32 start = replicaPtr.p->logStartGci[noNodes - 1];
16838 const Uint32 stop = replicaPtr.p->logStopGci[noNodes - 1];
16840 for(Uint32 i = noNodes; i < MAX_LOG_EXEC && (stop - start) > 0; i++){
16841 replicaPtr.p->noLogNodes++;
16842 replicaPtr.p->logStopGci[i - 1] = start;
16844 replicaPtr.p->logNodeId[
i] = replicaPtr.p->logNodeId[i-1];
16845 replicaPtr.p->logStartGci[
i] = start + 1;
16846 replicaPtr.p->logStopGci[
i] = stop;
16851 startFragReq->noOfLogNodes = replicaPtr.p->noLogNodes;
16853 for (Uint32 i = 0; i < MAX_LOG_EXEC ; i++) {
16854 startFragReq->lqhLogNode[
i] = replicaPtr.p->logNodeId[
i];
16855 startFragReq->startGci[
i] = replicaPtr.p->logStartGci[
i];
16856 startFragReq->lastGci[
i] = replicaPtr.p->logStopGci[
i];
16859 sendSignal(ref, GSN_START_FRAGREQ, signal,
16860 StartFragReq::SignalLength, JBB);
16867 void Dbdih::setLcpActiveStatusStart(
Signal* signal)
16869 NodeRecordPtr nodePtr;
16871 c_lcpState.m_participatingLQH.clear();
16872 c_lcpState.m_participatingDIH.clear();
16874 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
16875 ptrAss(nodePtr, nodeRecord);
16877 if(nodePtr.p->nodeStatus != NodeRecord::NOT_IN_CLUSTER){
16878 infoEvent(
"Node %d nodeStatus=%d activeStatus=%d copyCompleted=%d lcp=%d",
16880 nodePtr.p->nodeStatus,
16881 nodePtr.p->activeStatus,
16882 nodePtr.p->copyCompleted,
16883 nodePtr.p->m_inclDihLcp);
16886 if(nodePtr.p->nodeStatus == NodeRecord::ALIVE)
16889 if (nodePtr.p->m_inclDihLcp)
16892 c_lcpState.m_participatingDIH.set(nodePtr.i);
16895 if (nodePtr.p->copyCompleted)
16898 c_lcpState.m_participatingLQH.set(nodePtr.i);
16900 else if (nodePtr.p->activeStatus == Sysfile::NS_Configured)
16908 nodePtr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
16911 else if (nodePtr.p->activeStatus == Sysfile::NS_Configured)
16916 else if (nodePtr.p->activeStatus != Sysfile::NS_NotDefined)
16919 nodePtr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
16927 void Dbdih::setLcpActiveStatusEnd(
Signal* signal)
16929 NodeRecordPtr nodePtr;
16931 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
16933 ptrAss(nodePtr, nodeRecord);
16934 if (c_lcpState.m_participatingLQH.get(nodePtr.i))
16937 nodePtr.p->copyCompleted = 1;
16938 if (! (nodePtr.p->activeStatus == Sysfile::NS_Configured))
16941 nodePtr.p->activeStatus = Sysfile::NS_Active;
16949 else if (nodePtr.p->activeStatus == Sysfile::NS_Configured)
16954 else if (nodePtr.p->activeStatus != Sysfile::NS_NotDefined)
16957 nodePtr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
16961 c_lcpState.m_participatingDIH.clear();
16962 c_lcpState.m_participatingLQH.clear();
16965 setNodeRestartInfoBits(signal);
16972 void Dbdih::setNodeActiveStatus()
16974 NodeRecordPtr snaNodeptr;
16976 for (snaNodeptr.i = 1; snaNodeptr.i < MAX_NDB_NODES; snaNodeptr.i++)
16978 ptrAss(snaNodeptr, nodeRecord);
16979 const Uint32 tsnaNodeBits = Sysfile::getNodeStatus(snaNodeptr.i,
16980 SYSFILE->nodeStatus);
16981 switch (tsnaNodeBits) {
16982 case Sysfile::NS_Active:
16984 snaNodeptr.p->activeStatus = Sysfile::NS_Active;
16986 case Sysfile::NS_ActiveMissed_1:
16988 snaNodeptr.p->activeStatus = Sysfile::NS_ActiveMissed_1;
16990 case Sysfile::NS_ActiveMissed_2:
16992 snaNodeptr.p->activeStatus = Sysfile::NS_ActiveMissed_2;
16994 case Sysfile::NS_TakeOver:
16996 snaNodeptr.p->activeStatus = Sysfile::NS_TakeOver;
16998 case Sysfile::NS_NotActive_NotTakenOver:
17000 snaNodeptr.p->activeStatus = Sysfile::NS_NotActive_NotTakenOver;
17002 case Sysfile::NS_NotDefined:
17004 snaNodeptr.p->activeStatus = Sysfile::NS_NotDefined;
17006 case Sysfile::NS_Configured:
17008 snaNodeptr.p->activeStatus = Sysfile::NS_Configured;
17020 void Dbdih::setNodeGroups()
17022 NodeGroupRecordPtr NGPtr;
17023 NodeRecordPtr sngNodeptr;
17026 for (Ti = 0; Ti < cnoOfNodeGroups; Ti++) {
17027 NGPtr.i = c_node_groups[Ti];
17028 ptrAss(NGPtr, nodeGroupRecord);
17029 NGPtr.p->nodeCount = 0;
17030 NGPtr.p->nodegroupIndex = RNIL;
17032 cnoOfNodeGroups = 0;
17033 for (sngNodeptr.i = 1; sngNodeptr.i < MAX_NDB_NODES; sngNodeptr.i++) {
17034 ptrAss(sngNodeptr, nodeRecord);
17037 SYSFILE->nodeStatus);
17039 case Sysfile::NS_Active:
17040 case Sysfile::NS_ActiveMissed_1:
17041 case Sysfile::NS_ActiveMissed_2:
17042 case Sysfile::NS_NotActive_NotTakenOver:
17043 case Sysfile::NS_TakeOver:
17045 sngNodeptr.p->nodeGroup = Sysfile::getNodeGroup(sngNodeptr.i,
17046 SYSFILE->nodeGroups);
17047 NGPtr.i = sngNodeptr.p->nodeGroup;
17048 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
17049 NGPtr.p->nodesInGroup[NGPtr.p->nodeCount] = sngNodeptr.i;
17050 NGPtr.p->nodeCount++;
17051 add_nodegroup(NGPtr);
17053 case Sysfile::NS_NotDefined:
17054 case Sysfile::NS_Configured:
17056 sngNodeptr.p->nodeGroup = ZNIL;
17069 void Dbdih::setNodeRestartInfoBits(
Signal * signal)
17071 NodeRecordPtr nodePtr;
17072 Uint32 tsnrNodeGroup;
17073 Uint32 tsnrNodeActiveStatus;
17075 for(i = 1; i < MAX_NDB_NODES; i++){
17076 Sysfile::setNodeStatus(i, SYSFILE->nodeStatus, Sysfile::NS_Active);
17078 for(i = 1; i < Sysfile::NODE_GROUPS_SIZE; i++){
17079 SYSFILE->nodeGroups[
i] = 0;
17081 NdbNodeBitmask::clear(SYSFILE->lcpActive);
17083 #ifdef ERROR_INSERT
17087 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
17088 ptrAss(nodePtr, nodeRecord);
17089 switch (nodePtr.p->activeStatus) {
17090 case Sysfile::NS_Active:
17092 tsnrNodeActiveStatus = Sysfile::NS_Active;
17094 case Sysfile::NS_ActiveMissed_1:
17096 tsnrNodeActiveStatus = Sysfile::NS_ActiveMissed_1;
17098 case Sysfile::NS_ActiveMissed_2:
17100 tsnrNodeActiveStatus = Sysfile::NS_ActiveMissed_2;
17102 case Sysfile::NS_TakeOver:
17104 tsnrNodeActiveStatus = Sysfile::NS_TakeOver;
17106 case Sysfile::NS_NotActive_NotTakenOver:
17108 tsnrNodeActiveStatus = Sysfile::NS_NotActive_NotTakenOver;
17110 case Sysfile::NS_NotDefined:
17112 tsnrNodeActiveStatus = Sysfile::NS_NotDefined;
17114 case Sysfile::NS_Configured:
17116 tsnrNodeActiveStatus = Sysfile::NS_Configured;
17120 tsnrNodeActiveStatus = Sysfile::NS_NotDefined;
17123 Sysfile::setNodeStatus(nodePtr.i, SYSFILE->nodeStatus,
17124 tsnrNodeActiveStatus);
17125 if (nodePtr.p->nodeGroup == ZNIL) {
17127 tsnrNodeGroup = NO_NODE_GROUP_ID;
17130 tsnrNodeGroup = nodePtr.p->nodeGroup;
17132 Sysfile::setNodeGroup(nodePtr.i, SYSFILE->nodeGroups, tsnrNodeGroup);
17133 if (c_lcpState.m_participatingLQH.get(nodePtr.i))
17136 NdbNodeBitmask::set(SYSFILE->lcpActive, nodePtr.i);
17138 #ifdef ERROR_INSERT
17139 else if (Sysfile::getLCPOngoing(SYSFILE->systemRestartBits))
17142 if (nodePtr.p->activeStatus == Sysfile::NS_Active)
17143 tmp.
set(nodePtr.i);
17148 #ifdef ERROR_INSERT
17149 if (ERROR_INSERTED(7220) && !tmp.
isclear())
17154 nodePtr.i = cfirstAliveNode;
17157 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
17158 all.
set(nodePtr.i);
17159 nodePtr.i = nodePtr.p->nextNode;
17160 }
while (nodePtr.i != RNIL);
17164 signal->theData[0] = 7219;
17165 sendSignal(rg, GSN_NDB_TAMPER, signal, 1, JBA);
17173 void Dbdih::startGcp(
Signal* signal)
17175 signal->theData[0] = DihContinueB::ZSTART_GCP;
17176 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
17178 startGcpMonitor(signal);
17182 Dbdih::startGcpMonitor(
Signal* signal)
17185 m_gcp_monitor.m_gcp_save.m_gci = m_gcp_save.m_gci;
17186 m_gcp_monitor.m_gcp_save.m_counter = 0;
17187 m_gcp_monitor.m_micro_gcp.m_gci = m_micro_gcp.m_current_gci;
17188 m_gcp_monitor.m_micro_gcp.m_counter = 0;
17190 signal->theData[0] = DihContinueB::ZCHECK_GCP_STOP;
17191 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 100, 1);
17194 void Dbdih::updateNodeInfo(FragmentstorePtr fragPtr)
17196 ReplicaRecordPtr replicatePtr;
17198 replicatePtr.i = fragPtr.p->storedReplicas;
17201 ptrCheckGuard(replicatePtr, creplicaFileSize, replicaRecord);
17202 ndbrequire(index < MAX_REPLICAS);
17203 fragPtr.p->activeNodes[
index] = replicatePtr.p->procNode;
17205 replicatePtr.i = replicatePtr.p->nextReplica;
17206 }
while (replicatePtr.i != RNIL);
17207 fragPtr.p->fragReplicas =
index;
17213 const Uint32 prefPrim = fragPtr.p->preferredPrimary;
17214 for (Uint32 i = 1; i <
index; i++) {
17216 ndbrequire(i < MAX_REPLICAS);
17217 if (fragPtr.p->activeNodes[i] == prefPrim){
17219 Uint32 switchNode = fragPtr.p->activeNodes[0];
17220 fragPtr.p->activeNodes[0] = prefPrim;
17221 fragPtr.p->activeNodes[
i] = switchNode;
17227 void Dbdih::writeFragment(RWFragment* wf, FragmentstorePtr fragPtr)
17229 writePageWord(wf, wf->fragId);
17230 writePageWord(wf, fragPtr.p->preferredPrimary);
17231 writePageWord(wf, fragPtr.p->noStoredReplicas);
17232 writePageWord(wf, fragPtr.p->noOldStoredReplicas);
17233 writePageWord(wf, fragPtr.p->distributionKey);
17234 writePageWord(wf, fragPtr.p->m_log_part_id);
17237 void Dbdih::writePageWord(RWFragment* wf, Uint32 dataWord)
17239 if (wf->wordIndex >= 2048) {
17241 ndbrequire(wf->wordIndex == 2048);
17242 allocpage(wf->rwfPageptr);
17243 wf->wordIndex = 32;
17245 ndbrequire(wf->pageIndex < NDB_ARRAY_SIZE(wf->rwfTabPtr.p->pageRef));
17246 wf->rwfTabPtr.p->pageRef[wf->pageIndex] = wf->rwfPageptr.i;
17247 wf->rwfTabPtr.p->noPages++;
17249 wf->rwfPageptr.p->word[wf->wordIndex] = dataWord;
17253 void Dbdih::writeReplicas(RWFragment* wf, Uint32 replicaStartIndex)
17255 ReplicaRecordPtr wfReplicaPtr;
17256 wfReplicaPtr.i = replicaStartIndex;
17257 while (wfReplicaPtr.i != RNIL) {
17259 ptrCheckGuard(wfReplicaPtr, creplicaFileSize, replicaRecord);
17260 writePageWord(wf, wfReplicaPtr.p->procNode);
17261 writePageWord(wf, wfReplicaPtr.p->initialGci);
17262 writePageWord(wf, wfReplicaPtr.p->noCrashedReplicas);
17263 writePageWord(wf, wfReplicaPtr.p->nextLcp);
17265 for (i = 0; i < MAX_LCP_STORED; i++) {
17266 writePageWord(wf, wfReplicaPtr.p->maxGciCompleted[i]);
17267 writePageWord(wf, wfReplicaPtr.p->maxGciStarted[i]);
17268 writePageWord(wf, wfReplicaPtr.p->lcpId[i]);
17269 writePageWord(wf, wfReplicaPtr.p->lcpStatus[i]);
17271 for (i = 0; i < MAX_CRASHED_REPLICAS; i++) {
17272 writePageWord(wf, wfReplicaPtr.p->createGci[i]);
17273 writePageWord(wf, wfReplicaPtr.p->replicaLastGci[i]);
17276 wfReplicaPtr.i = wfReplicaPtr.p->nextReplica;
17280 void Dbdih::writeRestorableGci(
Signal* signal, FileRecordPtr filePtr)
17282 for (Uint32 i = 0; i < Sysfile::SYSFILE_SIZE32; i++) {
17283 sysfileDataToFile[
i] = sysfileData[
i];
17285 signal->theData[0] = filePtr.p->fileRef;
17286 signal->theData[1] = reference();
17287 signal->theData[2] = filePtr.i;
17288 signal->theData[3] = ZLIST_OF_PAIRS_SYNCH;
17289 signal->theData[4] = ZVAR_NO_CRESTART_INFO_TO_FILE;
17290 signal->theData[5] = 1;
17291 signal->theData[6] = 0;
17292 signal->theData[7] = 0;
17294 if (ERROR_INSERTED(7224) && filePtr.i == crestartInfoFile[1])
17297 SET_ERROR_INSERT_VALUE(7225);
17298 sendSignalWithDelay(NDBFS_REF, GSN_FSWRITEREQ, signal, 500, 8);
17300 signal->theData[0] = 9999;
17301 sendSignal(numberToRef(CMVMI, refToNode(cmasterdihref)),
17302 GSN_NDB_TAMPER, signal, 1, JBB);
17305 sendSignal(NDBFS_REF, GSN_FSWRITEREQ, signal, 8, JBA);
17308 void Dbdih::writeTabfile(
Signal* signal, TabRecord* tab, FileRecordPtr filePtr)
17310 signal->theData[0] = filePtr.p->fileRef;
17311 signal->theData[1] = reference();
17312 signal->theData[2] = filePtr.i;
17313 signal->theData[3] = ZLIST_OF_PAIRS_SYNCH;
17314 signal->theData[4] = ZVAR_NO_WORD;
17315 signal->theData[5] = tab->noPages;
17317 Uint32 section[2 * NDB_ARRAY_SIZE(tab->pageRef)];
17318 for (Uint32 i = 0; i < tab->noPages; i++)
17320 section[(2 *
i) + 0] = tab->pageRef[i];
17321 section[(2 * i) + 1] =
i;
17324 ptr[0].p = section;
17325 ptr[0].sz = 2 * tab->noPages;
17326 sendSignal(NDBFS_REF, GSN_FSWRITEREQ, signal, 6, JBA, ptr, 1);
17329 void Dbdih::execDEBUG_SIG(
Signal* signal)
17335 Dbdih::execDUMP_STATE_ORD(
Signal* signal)
17338 Uint32 arg = dumpState->args[0];
17339 if (arg == DumpStateOrd::DihDumpNodeRestartInfo) {
17340 infoEvent(
"c_nodeStartMaster.blockLcp = %d, c_nodeStartMaster.blockGcp = %d, c_nodeStartMaster.wait = %d",
17341 c_nodeStartMaster.blockLcp, c_nodeStartMaster.blockGcp, c_nodeStartMaster.wait);
17342 for (Uint32 i = 0; i < c_diverify_queue_cnt; i++)
17344 infoEvent(
"[ %u : cfirstVerifyQueue = %u clastVerifyQueue = %u sz: %u]",
17346 c_diverify_queue[i].cfirstVerifyQueue,
17347 c_diverify_queue[i].clastVerifyQueue,
17348 capiConnectFileSize);
17353 if (arg == DumpStateOrd::DihDumpNodeStatusInfo) {
17354 NodeRecordPtr localNodePtr;
17355 infoEvent(
"Printing nodeStatus of all nodes");
17356 for (localNodePtr.i = 1; localNodePtr.i < MAX_NDB_NODES; localNodePtr.i++) {
17357 ptrAss(localNodePtr, nodeRecord);
17358 if (localNodePtr.p->nodeStatus != NodeRecord::NOT_IN_CLUSTER) {
17360 localNodePtr.i, localNodePtr.p->nodeStatus);
17365 if (arg == DumpStateOrd::DihPrintFragmentation)
17368 for (Uint32 i = 0; i<cnoOfNodeGroups; i++)
17370 NodeGroupRecordPtr NGPtr;
17371 NGPtr.i = c_node_groups[
i];
17372 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
17374 infoEvent(
"NG %u(%u) ref: %u [ cnt: %u : %u %u %u %u ]",
17375 NGPtr.i, NGPtr.p->nodegroupIndex, NGPtr.p->m_ref_count,
17376 NGPtr.p->nodeCount,
17377 NGPtr.p->nodesInGroup[0], NGPtr.p->nodesInGroup[1], NGPtr.p->nodesInGroup[2], NGPtr.p->nodesInGroup[3]);
17380 infoEvent(
"Printing fragmentation of all tables --");
17381 for(Uint32 i = 0; i<ctabFileSize; i++){
17382 TabRecordPtr tabPtr;
17384 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
17386 if(tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
17389 for(Uint32 j = 0; j < tabPtr.p->totalfragments; j++){
17390 FragmentstorePtr fragPtr;
17391 getFragstore(tabPtr.p, j, fragPtr);
17393 Uint32 nodeOrder[MAX_REPLICAS];
17394 const Uint32 noOfReplicas = extractNodeInfo(fragPtr.p, nodeOrder);
17396 BaseString::snprintf(buf,
sizeof(buf),
" Table %d Fragment %d(%u) LP: %u - ", tabPtr.i, j, dihGetInstanceKey(fragPtr), fragPtr.p->m_log_part_id);
17397 for(Uint32 k = 0; k < noOfReplicas; k++){
17407 if (signal->theData[0] == 7000) {
17409 c_lcpState.ctimer);
17410 infoEvent(
"cmasterState = %d", cmasterState);
17411 infoEvent(
"cmasterTakeOverNode = %d, ctcCounter = %d",
17412 cmasterTakeOverNode, c_lcpState.ctcCounter);
17414 if (signal->theData[0] == 7001) {
17416 c_lcpState.keepGci);
17417 infoEvent(
"c_lcpState.lcpStatus = %d, clcpStopGcp = %d",
17418 c_lcpState.lcpStatus,
17419 c_lcpState.lcpStopGcp);
17421 c_lcpState.immediateLcpStart);
17423 if (signal->theData[0] == 7002) {
17425 cnoOfActiveTables);
17426 infoEvent(
"cdictblockref = %d, cfailurenr = %d",
17427 cdictblockref, cfailurenr);
17428 infoEvent(
"con_lineNodes = %d, reference() = %d, creceivedfrag = %d",
17429 con_lineNodes, reference(), creceivedfrag);
17431 if (signal->theData[0] == 7003) {
17432 infoEvent(
"cfirstAliveNode = %d, cgckptflag = %d",
17433 cfirstAliveNode, cgckptflag);
17434 infoEvent(
"clocallqhblockref = %d, clocaltcblockref = %d, cgcpOrderBlocked = %d",
17435 clocallqhblockref, clocaltcblockref, cgcpOrderBlocked);
17436 infoEvent(
"cstarttype = %d, csystemnodes = %d",
17437 cstarttype, csystemnodes);
17439 if (signal->theData[0] == 7004) {
17440 infoEvent(
"cmasterdihref = %d, cownNodeId = %d",
17441 cmasterdihref, cownNodeId);
17442 infoEvent(
"cndbStartReqBlockref = %d, cremainingfrags = %d",
17443 cndbStartReqBlockref, cremainingfrags);
17445 if (signal->theData[0] == 7005) {
17449 if (signal->theData[0] == 7006) {
17451 c_lcpState.clcpDelay);
17452 infoEvent(
"cmasterNodeId = %d", cmasterNodeId);
17453 infoEvent(
"c_nodeStartMaster.startNode = %d, c_nodeStartMaster.wait = %d",
17454 c_nodeStartMaster.startNode, c_nodeStartMaster.wait);
17456 if (signal->theData[0] == 7007) {
17457 infoEvent(
"c_nodeStartMaster.failNr = %d", c_nodeStartMaster.failNr);
17458 infoEvent(
"c_nodeStartMaster.startInfoErrorCode = %d",
17459 c_nodeStartMaster.startInfoErrorCode);
17460 infoEvent(
"c_nodeStartMaster.blockLcp = %d, c_nodeStartMaster.blockGcp = %d",
17461 c_nodeStartMaster.blockLcp, c_nodeStartMaster.blockGcp);
17463 if (signal->theData[0] == 7008) {
17464 infoEvent(
"cfirstDeadNode = %d, cstartPhase = %d, cnoReplicas = %d",
17465 cfirstDeadNode, cstartPhase, cnoReplicas);
17466 infoEvent(
"cwaitLcpSr = %d",cwaitLcpSr);
17468 if (signal->theData[0] == 7009) {
17469 infoEvent(
"ccalcOldestRestorableGci = %d, cnoOfNodeGroups = %d",
17470 c_lcpState.oldestRestorableGci, cnoOfNodeGroups);
17474 if (signal->theData[0] == 7010) {
17475 infoEvent(
"c_lcpState.lcpStatusUpdatedPlace = %d, cLcpStart = %d",
17476 c_lcpState.lcpStatusUpdatedPlace, c_lcpState.lcpStart);
17477 infoEvent(
"c_blockCommit = %d, c_blockCommitNo = %d",
17478 c_blockCommit, c_blockCommitNo);
17480 if (signal->theData[0] == 7011){
17481 infoEvent(
"c_COPY_GCIREQ_Counter = %s",
17482 c_COPY_GCIREQ_Counter.getText());
17483 infoEvent(
"c_COPY_TABREQ_Counter = %s",
17484 c_COPY_TABREQ_Counter.getText());
17485 infoEvent(
"c_CREATE_FRAGREQ_Counter = %s",
17486 c_CREATE_FRAGREQ_Counter.getText());
17487 infoEvent(
"c_DIH_SWITCH_REPLICA_REQ_Counter = %s",
17488 c_DIH_SWITCH_REPLICA_REQ_Counter.getText());
17489 infoEvent(
"c_EMPTY_LCP_REQ_Counter = %s",c_EMPTY_LCP_REQ_Counter.getText());
17490 infoEvent(
"c_GCP_COMMIT_Counter = %s", c_GCP_COMMIT_Counter.getText());
17491 infoEvent(
"c_GCP_PREPARE_Counter = %s", c_GCP_PREPARE_Counter.getText());
17492 infoEvent(
"c_GCP_SAVEREQ_Counter = %s", c_GCP_SAVEREQ_Counter.getText());
17493 infoEvent(
"c_SUB_GCP_COMPLETE_REP_Counter = %s",
17494 c_SUB_GCP_COMPLETE_REP_Counter.getText());
17495 infoEvent(
"c_INCL_NODEREQ_Counter = %s", c_INCL_NODEREQ_Counter.getText());
17496 infoEvent(
"c_MASTER_GCPREQ_Counter = %s",
17497 c_MASTER_GCPREQ_Counter.getText());
17498 infoEvent(
"c_MASTER_LCPREQ_Counter = %s",
17499 c_MASTER_LCPREQ_Counter.getText());
17500 infoEvent(
"c_START_INFOREQ_Counter = %s",
17501 c_START_INFOREQ_Counter.getText());
17502 infoEvent(
"c_START_RECREQ_Counter = %s", c_START_RECREQ_Counter.getText());
17503 infoEvent(
"c_STOP_ME_REQ_Counter = %s", c_STOP_ME_REQ_Counter.getText());
17504 infoEvent(
"c_TC_CLOPSIZEREQ_Counter = %s",
17505 c_TC_CLOPSIZEREQ_Counter.getText());
17506 infoEvent(
"c_TCGETOPSIZEREQ_Counter = %s",
17507 c_TCGETOPSIZEREQ_Counter.getText());
17510 if(signal->theData[0] == 7012){
17511 char buf[8*_NDB_NODE_BITMASK_SIZE+1];
17512 infoEvent(
"ParticipatingDIH = %s", c_lcpState.m_participatingDIH.getText(buf));
17513 infoEvent(
"ParticipatingLQH = %s", c_lcpState.m_participatingLQH.getText(buf));
17514 infoEvent(
"m_LCP_COMPLETE_REP_Counter_DIH = %s",
17515 c_lcpState.m_LCP_COMPLETE_REP_Counter_DIH.getText());
17516 infoEvent(
"m_LCP_COMPLETE_REP_Counter_LQH = %s",
17517 c_lcpState.m_LCP_COMPLETE_REP_Counter_LQH.getText());
17519 c_lcpState.m_LAST_LCP_FRAG_ORD.getText());
17520 infoEvent(
"m_LCP_COMPLETE_REP_From_Master_Received = %d",
17521 c_lcpState.m_LCP_COMPLETE_REP_From_Master_Received);
17523 NodeRecordPtr nodePtr;
17524 for (nodePtr.i = 1; nodePtr.i < MAX_NDB_NODES; nodePtr.i++) {
17526 ptrAss(nodePtr, nodeRecord);
17527 if(nodePtr.p->nodeStatus == NodeRecord::ALIVE){
17529 for(i = 0; i<nodePtr.p->noOfStartedChkpt; i++){
17530 infoEvent(
"Node %d: started: table=%d fragment=%d replica=%d",
17532 nodePtr.p->startedChkpt[i].tableId,
17533 nodePtr.p->startedChkpt[i].fragId,
17534 nodePtr.p->startedChkpt[i].replicaPtr);
17537 for(i = 0; i<nodePtr.p->noOfQueuedChkpt; i++){
17538 infoEvent(
"Node %d: queued: table=%d fragment=%d replica=%d",
17540 nodePtr.p->queuedChkpt[i].tableId,
17541 nodePtr.p->queuedChkpt[i].fragId,
17542 nodePtr.p->queuedChkpt[i].replicaPtr);
17548 if(arg == 7019 && signal->getLength() == 2 &&
17549 signal->theData[1] < MAX_NDB_NODES)
17552 NodeRecordPtr nodePtr;
17553 nodePtr.i = signal->theData[1];
17554 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
17555 infoEvent(
"NF Node %d tc: %d lqh: %d dih: %d dict: %d recNODE_FAILREP: %d",
17557 nodePtr.p->dbtcFailCompleted,
17558 nodePtr.p->dblqhFailCompleted,
17559 nodePtr.p->dbdihFailCompleted,
17560 nodePtr.p->dbdictFailCompleted,
17561 nodePtr.p->recNODE_FAILREP);
17562 infoEvent(
" m_NF_COMPLETE_REP: %s m_nodefailSteps: %s",
17563 nodePtr.p->m_NF_COMPLETE_REP.getText(),
17564 nodePtr.p->m_nodefailSteps.getText(buf2));
17567 if(arg == 7020 && signal->getLength() > 3)
17569 Uint32 gsn= signal->theData[1];
17570 Uint32
block= signal->theData[2];
17571 Uint32 length= signal->
length() - 3;
17572 memmove(signal->theData, signal->theData+3, 4*length);
17573 sendSignal(numberToRef(block, getOwnNodeId()), gsn, signal, length, JBB);
17576 char buf[100], buf2[100];
17578 for(Uint32 i = 0; i<length; i++)
17583 warningEvent(
"gsn: %d block: %s, length: %d theData: %s",
17584 gsn, getBlockName(block,
"UNKNOWN"), length, buf);
17586 g_eventLogger->
warning(
"-- SENDING CUSTOM SIGNAL --");
17587 g_eventLogger->
warning(
"gsn: %d block: %s, length: %d theData: %s",
17588 gsn, getBlockName(block,
"UNKNOWN"), length, buf);
17591 if(arg == DumpStateOrd::DihDumpLCPState){
17592 infoEvent(
"-- Node %d LCP STATE --", getOwnNodeId());
17593 infoEvent(
"lcpStatus = %d (update place = %d) ",
17594 c_lcpState.lcpStatus, c_lcpState.lcpStatusUpdatedPlace);
17596 (
"lcpStart = %d lcpStopGcp = %d keepGci = %d oldestRestorable = %d",
17597 c_lcpState.lcpStart, c_lcpState.lcpStopGcp,
17598 c_lcpState.keepGci, c_lcpState.oldestRestorableGci);
17601 (
"immediateLcpStart = %d masterLcpNodeId = %d",
17602 c_lcpState.immediateLcpStart,
17603 refToNode(c_lcpState.m_masterLcpDihRef));
17605 for (Uint32 i = 0; i<10; i++)
17607 infoEvent(
"%u : status: %u place: %u", i,
17608 c_lcpState.m_saveState[i].m_status,
17609 c_lcpState.m_saveState[i].m_place);
17612 infoEvent(
"-- Node %d LCP STATE --", getOwnNodeId());
17615 if(arg == DumpStateOrd::DihDumpLCPMasterTakeOver){
17616 infoEvent(
"-- Node %d LCP MASTER TAKE OVER STATE --", getOwnNodeId());
17618 (
"c_lcpMasterTakeOverState.state = %d updatePlace = %d failedNodeId = %d",
17619 c_lcpMasterTakeOverState.state,
17620 c_lcpMasterTakeOverState.updatePlace,
17621 c_lcpMasterTakeOverState.failedNodeId);
17623 infoEvent(
"c_lcpMasterTakeOverState.minTableId = %u minFragId = %u",
17624 c_lcpMasterTakeOverState.minTableId,
17625 c_lcpMasterTakeOverState.minFragId);
17627 infoEvent(
"-- Node %d LCP MASTER TAKE OVER STATE --", getOwnNodeId());
17630 if (signal->theData[0] == 7015)
17632 if (signal->getLength() == 1)
17634 signal->theData[1] = 0;
17637 Uint32 tableId = signal->theData[1];
17638 if (tableId < ctabFileSize)
17640 signal->theData[0] = 7021;
17641 execDUMP_STATE_ORD(signal);
17642 signal->theData[0] = 7015;
17643 signal->theData[1] = tableId + 1;
17644 sendSignal(reference(), GSN_DUMP_STATE_ORD, signal, 2, JBB);
17648 if(arg == DumpStateOrd::EnableUndoDelayDataWrite){
17649 g_eventLogger->
info(
"Dbdih:: delay write of datapages for table = %d",
17650 dumpState->args[1]);
17652 sendSignal(DBACC_REF, GSN_DUMP_STATE_ORD, signal, 2, JBB);
17653 sendSignal(DBTUP_REF, GSN_DUMP_STATE_ORD, signal, 2, JBB);
17656 add_lcp_counter(&c_lcpState.ctimer, (1 << 31));
17660 if (signal->theData[0] == DumpStateOrd::DihAllAllowNodeStart) {
17661 for (Uint32 i = 1; i < MAX_NDB_NODES; i++)
17662 setAllowNodeStart(i,
true);
17665 if (signal->theData[0] == DumpStateOrd::DihMinTimeBetweenLCP) {
17667 if (signal->getLength() == 2)
17671 m_ctx.m_config.getOwnConfigIterator();
17672 ndbrequire(p != 0);
17673 ndb_mgm_get_int_parameter(p, CFG_DB_LCP_INTERVAL, &tmp);
17674 g_eventLogger->
info(
"Reset time between LCP to %u", tmp);
17675 c_lcpState.clcpDelay = tmp;
17679 g_eventLogger->
info(
"Set time between LCP to min value");
17680 c_lcpState.clcpDelay = 0;
17684 if (signal->theData[0] == DumpStateOrd::DihMaxTimeBetweenLCP) {
17686 g_eventLogger->
info(
"Set time between LCP to max value");
17687 c_lcpState.clcpDelay = 31;
17692 if(signal->
length() == 3){
17694 infoEvent(
"startLcpRoundLoopLab(tabel=%d, fragment=%d)",
17695 signal->theData[1], signal->theData[2]);
17696 startLcpRoundLoopLab(signal, signal->theData[1], signal->theData[2]);
17699 infoEvent(
"Invalid no of arguments to 7098 - startLcpRoundLoopLab -"
17700 " expected 2 (tableId, fragmentId)");
17704 if (arg == DumpStateOrd::DihStartLcpImmediately)
17707 add_lcp_counter(&c_lcpState.ctimer, (1 << 31));
17712 if (cmasterNodeId != getOwnNodeId() &&
17713 refToMain(signal->getSendersBlockRef()) == DBLQH)
17716 sendSignal(cmasterdihref, GSN_DUMP_STATE_ORD, signal, 1, JBB);
17721 if (arg == DumpStateOrd::DihSetTimeBetweenGcp)
17724 if (signal->getLength() == 1)
17727 m_ctx.m_config.getOwnConfigIterator();
17728 ndbrequire(p != 0);
17729 ndb_mgm_get_int_parameter(p, CFG_DB_GCP_INTERVAL, &tmp);
17733 tmp = signal->theData[1];
17735 m_gcp_save.m_master.m_time_between_gcp = tmp;
17736 g_eventLogger->
info(
"Setting time between gcp : %d", tmp);
17739 if (arg == 7021 && signal->getLength() == 2)
17741 TabRecordPtr tabPtr;
17742 tabPtr.i = signal->theData[1];
17743 if (tabPtr.i >= ctabFileSize)
17746 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
17748 if(tabPtr.p->tabStatus != TabRecord::TS_ACTIVE)
17752 (
"Table %d: TabCopyStatus: %d TabUpdateStatus: %d TabLcpStatus: %d",
17754 tabPtr.p->tabCopyStatus,
17755 tabPtr.p->tabUpdateState,
17756 tabPtr.p->tabLcpStatus);
17758 FragmentstorePtr fragPtr;
17759 for (Uint32 fid = 0; fid < tabPtr.p->totalfragments; fid++) {
17761 getFragstore(tabPtr.p, fid, fragPtr);
17763 char buf[100], buf2[100];
17765 fid, fragPtr.p->noLcpReplicas);
17768 ReplicaRecordPtr replicaPtr;
17769 replicaPtr.i = fragPtr.p->storedReplicas;
17771 ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord);
17774 replicaPtr.p->procNode,
17775 replicaPtr.p->lcpIdStarted,
17776 replicaPtr.p->lcpOngoingFlag ?
"Ongoing" :
"Idle");
17780 replicaPtr.i = replicaPtr.p->nextReplica;
17781 }
while (replicaPtr.i != RNIL);
17789 crashSystemAtGcpStop(signal,
true);
17799 #ifdef GCP_TIMER_HACK
17800 if (signal->theData[0] == 7901)
17801 globalData.gcp_timer_limit = signal->theData[1];
17809 ptr.i = signal->theData[1];
17810 if (signal->getLength() == 1)
17812 infoEvent(
"Starting dump all active take-over");
17813 c_activeTakeOverList.
first(ptr);
17818 infoEvent(
"Dump all active take-over done");
17822 c_activeTakeOverList.
getPtr(ptr);
17823 infoEvent(
"TakeOverPtr(%u) starting: %u flags: 0x%x ref: 0x%x, data: %u",
17825 ptr.p->toStartingNode,
17827 ptr.p->m_senderRef,
17828 ptr.p->m_senderData);
17829 infoEvent(
"slaveState: %u masterState: %u",
17830 ptr.p->toSlaveStatus, ptr.p->toMasterStatus);
17831 infoEvent(
"restorableGci: %u startGci: %u tab: %u frag: %u src: %u max: %u",
17832 ptr.p->restorableGci, ptr.p->startGci,
17833 ptr.p->toCurrentTabref, ptr.p->toCurrentFragid,
17834 ptr.p->toCopyNode, ptr.p->maxPage);
17836 c_activeTakeOverList.
next(ptr);
17837 signal->theData[0] = arg;
17838 signal->theData[1] = ptr.i;
17841 if (arg == DumpStateOrd::SchemaResourceSnapshot)
17843 RSS_OP_SNAPSHOT_SAVE(cremainingfrags);
17844 RSS_OP_SNAPSHOT_SAVE(cnoFreeReplicaRec);
17847 Uint32 cnghash = 0;
17848 NodeGroupRecordPtr NGPtr;
17849 for (Uint32 i = 0; i<cnoOfNodeGroups; i++)
17851 NGPtr.i = c_node_groups[
i];
17852 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
17853 cnghash = (cnghash * 33) + NGPtr.p->m_ref_count;
17855 RSS_OP_SNAPSHOT_SAVE(cnghash);
17860 if (arg == DumpStateOrd::SchemaResourceCheckLeak)
17862 RSS_OP_SNAPSHOT_CHECK(cremainingfrags);
17863 RSS_OP_SNAPSHOT_SAVE(cnoFreeReplicaRec);
17866 Uint32 cnghash = 0;
17867 NodeGroupRecordPtr NGPtr;
17868 for (Uint32 i = 0; i<cnoOfNodeGroups; i++)
17870 NGPtr.i = c_node_groups[
i];
17871 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
17872 cnghash = (cnghash * 33) + NGPtr.p->m_ref_count;
17874 RSS_OP_SNAPSHOT_CHECK(cnghash);
17878 DECLARE_DUMP0(DBDIH, 7213,
"Set error 7213 with extra arg")
17880 SET_ERROR_INSERT_VALUE2(7213, signal->theData[1]);
17883 DECLARE_DUMP0(DBDIH, 7214,
"Set error 7214 with extra arg")
17885 SET_ERROR_INSERT_VALUE2(7214, signal->theData[1]);
17889 DECLARE_DUMP0(DBDIH, 7216,
"Set error 7216 with extra arg")
17891 SET_ERROR_INSERT_VALUE2(7216, signal->theData[1]);
17894 DECLARE_DUMP0(DBDIH, 6099,
"Start microgcp")
17899 m_micro_gcp.m_master.m_start_time = 0;
17904 sendSignal(cmasterdihref, GSN_DUMP_STATE_ORD, signal, 1, JBB);
17908 DECLARE_DUMP0(DBDIH, 7999,
"Set error code with extra arg")
17910 SET_ERROR_INSERT_VALUE2(signal->theData[1],
17911 signal->theData[2]);
17916 Dbdih::execPREP_DROP_TAB_REQ(
Signal* signal){
17921 TabRecordPtr tabPtr;
17922 tabPtr.i = req->tableId;
17923 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
17925 Uint32 senderRef = req->senderRef;
17926 Uint32 senderData = req->senderData;
17928 PrepDropTabRef::ErrorCode err = PrepDropTabRef::OK;
17933 switch(tabPtr.p->tabStatus){
17934 case TabRecord::TS_IDLE:
17937 err = PrepDropTabRef::NoSuchTable;
17939 case TabRecord::TS_DROPPING:
17942 err = PrepDropTabRef::PrepDropInProgress;
17944 case TabRecord::TS_CREATING:
17948 case TabRecord::TS_ACTIVE:
17956 if(err != PrepDropTabRef::OK)
17960 ref->senderRef = reference();
17961 ref->senderData = senderData;
17962 ref->tableId = tabPtr.i;
17963 ref->errorCode = err;
17964 sendSignal(senderRef, GSN_PREP_DROP_TAB_REF, signal,
17965 PrepDropTabRef::SignalLength, JBB);
17969 tabPtr.p->tabStatus = TabRecord::TS_DROPPING;
17971 conf->tableId = tabPtr.i;
17972 conf->senderRef = reference();
17973 conf->senderData = senderData;
17974 sendSignal(senderRef, GSN_PREP_DROP_TAB_CONF,
17975 signal, PrepDropTabConf::SignalLength, JBB);
17979 Dbdih::waitDropTabWritingToFile(
Signal* signal, TabRecordPtr tabPtr){
17981 if (tabPtr.p->tabLcpStatus == TabRecord::TLS_WRITING_TO_FILE)
17984 signal->theData[0] = DihContinueB::WAIT_DROP_TAB_WRITING_TO_FILE;
17985 signal->theData[1] = tabPtr.i;
17986 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 100, 2);
17990 ndbrequire(tabPtr.p->tabLcpStatus == TabRecord::TLS_COMPLETED);
17991 checkDropTabComplete(signal, tabPtr);
17995 Dbdih::checkDropTabComplete(
Signal* signal, TabRecordPtr tabPtr)
17997 startDeleteFile(signal, tabPtr);
18001 Dbdih::execNDB_TAMPER(
Signal* signal)
18003 if ((ERROR_INSERTED(7011)) &&
18004 (signal->theData[0] == 7012)) {
18005 CLEAR_ERROR_INSERT_VALUE;
18006 calculateKeepGciLab(signal, 0, 0);
18009 SET_ERROR_INSERT_VALUE(signal->theData[0]);
18013 void Dbdih::execBLOCK_COMMIT_ORD(
Signal* signal){
18018 c_blockCommit =
true;
18019 c_blockCommitNo = block->failNo;
18022 void Dbdih::execUNBLOCK_COMMIT_ORD(
Signal* signal){
18028 if(c_blockCommit ==
true)
18032 c_blockCommit =
false;
18033 for (Uint32 i = 0; i<c_diverify_queue_cnt; i++)
18035 c_diverify_queue[
i].m_empty_done = 0;
18036 emptyverificbuffer(signal, i,
true);
18041 void Dbdih::execSTOP_PERM_REQ(
Signal* signal){
18048 const Uint32 senderData = req->senderData;
18049 const BlockReference senderRef = req->senderRef;
18050 const NodeId nodeId = refToNode(senderRef);
18057 CRASH_INSERTION(7065);
18058 if (c_stopPermMaster.clientRef != 0) {
18061 ref->senderData = senderData;
18062 ref->errorCode = StopPermRef::NodeShutdownInProgress;
18063 sendSignal(senderRef, GSN_STOP_PERM_REF, signal,
18064 StopPermRef::SignalLength, JBB);
18068 if (c_nodeStartMaster.activeState) {
18070 ref->senderData = senderData;
18071 ref->errorCode = StopPermRef::NodeStartInProgress;
18072 sendSignal(senderRef, GSN_STOP_PERM_REF, signal,
18073 StopPermRef::SignalLength, JBB);
18080 c_nodeStartMaster.activeState =
true;
18081 c_stopPermMaster.clientRef = senderRef;
18083 c_stopPermMaster.clientData = senderData;
18084 c_stopPermMaster.returnValue = 0;
18085 c_switchReplicas.clear();
18087 Mutex mutex(signal, c_mutexMgr, c_switchPrimaryMutexHandle);
18088 Callback c = { safe_cast(&Dbdih::switch_primary_stop_node), nodeId };
18089 ndbrequire(mutex.lock(c));
18095 CRASH_INSERTION(7066);
18096 if(c_stopPermProxy.clientRef != 0){
18098 ref->senderData = senderData;
18099 ref->errorCode = StopPermRef::NodeShutdownInProgress;
18100 sendSignal(senderRef, GSN_STOP_PERM_REF, signal, 2, JBB);
18104 c_stopPermProxy.clientRef = senderRef;
18105 c_stopPermProxy.masterRef = cmasterdihref;
18106 c_stopPermProxy.clientData = senderData;
18108 req->senderRef = reference();
18109 req->senderData = senderData;
18110 sendSignal(cmasterdihref, GSN_STOP_PERM_REQ, signal,
18111 StopPermReq::SignalLength, JBB);
18116 Dbdih::switch_primary_stop_node(
Signal* signal, Uint32 node_id, Uint32 ret_val)
18118 ndbrequire(ret_val == 0);
18119 signal->theData[0] = DihContinueB::SwitchReplica;
18120 signal->theData[1] = node_id;
18121 signal->theData[2] = 0;
18122 signal->theData[3] = 0;
18123 sendSignal(reference(), GSN_CONTINUEB, signal, 4, JBB);
18126 void Dbdih::execSTOP_PERM_REF(
Signal* signal)
18129 ndbrequire(c_stopPermProxy.clientRef != 0);
18130 ndbrequire(c_stopPermProxy.masterRef == signal->senderBlockRef());
18131 sendSignal(c_stopPermProxy.clientRef, GSN_STOP_PERM_REF, signal, 2, JBB);
18132 c_stopPermProxy.clientRef = 0;
18135 void Dbdih::execSTOP_PERM_CONF(
Signal* signal)
18138 ndbrequire(c_stopPermProxy.clientRef != 0);
18139 ndbrequire(c_stopPermProxy.masterRef == signal->senderBlockRef());
18140 sendSignal(c_stopPermProxy.clientRef, GSN_STOP_PERM_CONF, signal, 1, JBB);
18141 c_stopPermProxy.clientRef = 0;
18144 void Dbdih::execDIH_SWITCH_REPLICA_REQ(
Signal* signal)
18148 const Uint32 tableId = req->tableId;
18149 const Uint32 fragNo = req->fragNo;
18150 const BlockReference senderRef = req->senderRef;
18152 CRASH_INSERTION(7067);
18153 TabRecordPtr tabPtr;
18154 tabPtr.i = tableId;
18155 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
18157 ndbrequire(tabPtr.p->tabStatus == TabRecord::TS_ACTIVE);
18158 if (tabPtr.p->tabCopyStatus != TabRecord::CS_IDLE) {
18160 sendSignal(reference(), GSN_DIH_SWITCH_REPLICA_REQ, signal,
18161 DihSwitchReplicaReq::SignalLength, JBB);
18164 FragmentstorePtr fragPtr;
18165 getFragstore(tabPtr.p, fragNo, fragPtr);
18170 Uint32 oldOrder[MAX_REPLICAS];
18171 const Uint32 noOfReplicas = extractNodeInfo(fragPtr.p, oldOrder);
18173 if (noOfReplicas < req->noOfReplicas) {
18179 ref->senderNode = cownNodeId;
18180 ref->errorCode = StopPermRef::NF_CausedAbortOfStopProcedure;
18181 sendSignal(senderRef, GSN_DIH_SWITCH_REPLICA_REF, signal,
18182 DihSwitchReplicaRef::SignalLength, JBB);
18185 DIH_TAB_WRITE_LOCK(tabPtr.p);
18186 for (Uint32 i = 0; i < noOfReplicas; i++) {
18188 ndbrequire(i < MAX_REPLICAS);
18189 fragPtr.p->activeNodes[
i] = req->newNodeOrder[
i];
18191 DIH_TAB_WRITE_UNLOCK(tabPtr.p);
18197 conf->senderNode = cownNodeId;
18198 sendSignal(senderRef, GSN_DIH_SWITCH_REPLICA_CONF, signal,
18199 DihSwitchReplicaConf::SignalLength, JBB);
18202 void Dbdih::execDIH_SWITCH_REPLICA_CONF(
Signal* signal)
18208 CRASH_INSERTION(7068);
18210 switchReplicaReply(signal, conf->senderNode);
18213 void Dbdih::execDIH_SWITCH_REPLICA_REF(
Signal* signal)
18217 if(c_stopPermMaster.returnValue == 0){
18219 c_stopPermMaster.returnValue = ref->errorCode;
18221 switchReplicaReply(signal, ref->senderNode);
18224 void Dbdih::switchReplicaReply(
Signal* signal,
18227 receiveLoopMacro(DIH_SWITCH_REPLICA_REQ, nodeId);
18233 if(c_stopPermMaster.returnValue != 0){
18235 c_switchReplicas.tableId = ctabFileSize + 1;
18237 c_switchReplicas.fragNo++;
18239 signal->theData[0] = DihContinueB::SwitchReplica;
18240 signal->theData[1] = c_switchReplicas.nodeId;
18241 signal->theData[2] = c_switchReplicas.tableId;
18242 signal->theData[3] = c_switchReplicas.fragNo;
18243 sendSignal(reference(), GSN_CONTINUEB, signal, 4, JBB);
18247 Dbdih::switchReplica(
Signal* signal,
18254 const Uint32 RT_BREAK = 64;
18256 for (Uint32 i = 0; i < RT_BREAK; i++) {
18258 if (tableId >= ctabFileSize) {
18265 if(c_stopPermMaster.returnValue == 0) {
18267 conf->senderData = c_stopPermMaster.clientData;
18268 sendSignal(c_stopPermMaster.clientRef, GSN_STOP_PERM_CONF,
18272 ref->senderData = c_stopPermMaster.clientData;
18273 ref->errorCode = c_stopPermMaster.returnValue;
18274 sendSignal(c_stopPermMaster.clientRef, GSN_STOP_PERM_REF, signal, 2,JBB);
18280 c_nodeStartMaster.activeState =
false;
18281 c_stopPermMaster.clientRef = 0;
18282 c_stopPermMaster.clientData = 0;
18283 c_stopPermMaster.returnValue = 0;
18284 Mutex mutex(signal, c_mutexMgr, c_switchPrimaryMutexHandle);
18289 TabRecordPtr tabPtr;
18290 tabPtr.i = tableId;
18291 ptrCheckGuard(tabPtr, ctabFileSize, tabRecord);
18293 if (tabPtr.p->tabStatus != TabRecord::TS_ACTIVE) {
18299 if (fragNo >= tabPtr.p->totalfragments) {
18305 FragmentstorePtr fragPtr;
18306 getFragstore(tabPtr.p, fragNo, fragPtr);
18308 Uint32 oldOrder[MAX_REPLICAS];
18309 const Uint32 noOfReplicas = extractNodeInfo(fragPtr.p, oldOrder);
18311 if(oldOrder[0] != nodeId) {
18316 req->tableId = tableId;
18317 req->fragNo = fragNo;
18318 req->noOfReplicas = noOfReplicas;
18319 for (Uint32 i = 0; i < (noOfReplicas - 1); i++) {
18320 req->newNodeOrder[
i] = oldOrder[i+1];
18322 req->newNodeOrder[noOfReplicas-1] = nodeId;
18323 req->senderRef = reference();
18328 c_switchReplicas.tableId = tableId;
18329 c_switchReplicas.fragNo = fragNo;
18330 c_switchReplicas.nodeId = nodeId;
18332 sendLoopMacro(DIH_SWITCH_REPLICA_REQ, sendDIH_SWITCH_REPLICA_REQ, RNIL);
18336 signal->theData[0] = DihContinueB::SwitchReplica;
18337 signal->theData[1] = nodeId;
18338 signal->theData[2] = tableId;
18339 signal->theData[3] = fragNo;
18340 sendSignal(reference(), GSN_CONTINUEB, signal, 4, JBB);
18343 void Dbdih::execSTOP_ME_REQ(
Signal* signal)
18347 const BlockReference senderRef = req->senderRef;
18348 const Uint32 senderData = req->senderData;
18349 const Uint32 nodeId = refToNode(senderRef);
18354 NodeRecordPtr nodePtr;
18355 nodePtr.i = nodeId;
18356 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18357 nodePtr.p->useInTransactions =
false;
18359 if (nodeId != getOwnNodeId()) {
18362 stopMeConf->senderData = senderData;
18363 stopMeConf->senderRef = reference();
18364 sendSignal(senderRef, GSN_STOP_ME_CONF, signal,
18365 StopMeConf::SignalLength, JBB);
18373 ndbrequire(c_stopMe.clientRef == 0);
18375 c_stopMe.clientData = senderData;
18376 c_stopMe.clientRef = senderRef;
18378 req->senderData = senderData;
18379 req->senderRef = reference();
18381 sendLoopMacro(STOP_ME_REQ, sendSTOP_ME_REQ, RNIL);
18387 stopMeConf->senderData = senderData;
18388 stopMeConf->senderRef = reference();
18389 sendSignal(reference(), GSN_STOP_ME_CONF, signal,
18390 StopMeConf::SignalLength, JBB);
18393 void Dbdih::execSTOP_ME_REF(
Signal* signal)
18398 void Dbdih::execSTOP_ME_CONF(
Signal* signal)
18403 const Uint32 senderRef = stopMeConf->senderRef;
18404 const Uint32 senderData = stopMeConf->senderData;
18405 const Uint32 nodeId = refToNode(senderRef);
18407 ndbrequire(c_stopMe.clientRef != 0);
18408 ndbrequire(c_stopMe.clientData == senderData);
18410 receiveLoopMacro(STOP_ME_REQ, nodeId);
18416 stopMeConf->senderRef = reference();
18417 stopMeConf->senderData = c_stopMe.clientData;
18418 sendSignal(c_stopMe.clientRef, GSN_STOP_ME_CONF, signal,
18419 StopMeConf::SignalLength, JBB);
18420 c_stopMe.clientRef = 0;
18423 void Dbdih::execWAIT_GCP_REQ(
Signal* signal)
18429 const Uint32 senderData = req->senderData;
18430 const BlockReference senderRef = req->senderRef;
18431 const Uint32 requestType = req->requestType;
18432 Uint32 errorCode = 0;
18437 conf->senderData = senderData;
18438 conf->gci_hi = Uint32(m_micro_gcp.m_current_gci >> 32);
18439 conf->gci_lo = Uint32(m_micro_gcp.m_current_gci);
18440 conf->blockStatus = cgcpOrderBlocked;
18441 sendSignal(senderRef, GSN_WAIT_GCP_CONF, signal,
18442 WaitGCPConf::SignalLength, JBB);
18446 if(requestType == WaitGCPReq::RestartGCI)
18449 conf->senderData = senderData;
18450 conf->gci_hi = Uint32(crestartGci);
18452 conf->blockStatus = cgcpOrderBlocked;
18453 sendSignal(senderRef, GSN_WAIT_GCP_CONF, signal,
18454 WaitGCPConf::SignalLength, JBB);
18458 if (requestType == WaitGCPReq::BlockStartGcp)
18461 conf->senderData = senderData;
18462 conf->gci_hi = Uint32(m_micro_gcp.m_current_gci >> 32);
18463 conf->gci_lo = Uint32(m_micro_gcp.m_current_gci);
18464 conf->blockStatus = cgcpOrderBlocked;
18465 sendSignal(senderRef, GSN_WAIT_GCP_CONF, signal,
18466 WaitGCPConf::SignalLength, JBB);
18467 cgcpOrderBlocked = 1;
18471 if (requestType == WaitGCPReq::UnblockStartGcp)
18474 conf->senderData = senderData;
18475 conf->gci_hi = Uint32(m_micro_gcp.m_current_gci >> 32);
18476 conf->gci_lo = Uint32(m_micro_gcp.m_current_gci);
18477 conf->blockStatus = cgcpOrderBlocked;
18478 sendSignal(senderRef, GSN_WAIT_GCP_CONF, signal,
18479 WaitGCPConf::SignalLength, JBB);
18480 cgcpOrderBlocked = 0;
18490 if (!isActiveMaster())
18492 ndbassert(cmasterState == MASTER_TAKE_OVER_GCP);
18493 errorCode = WaitGCPRef::NF_MasterTakeOverInProgress;
18498 (m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE))
18501 conf->senderData = senderData;
18502 conf->gci_hi = Uint32(m_micro_gcp.m_old_gci >> 32);
18503 conf->gci_lo = Uint32(m_micro_gcp.m_old_gci);
18504 conf->blockStatus = cgcpOrderBlocked;
18505 sendSignal(senderRef, GSN_WAIT_GCP_CONF, signal,
18506 WaitGCPConf::SignalLength, JBB);
18510 WaitGCPMasterPtr ptr;
18511 WaitGCPList * list = &c_waitGCPMasterList;
18512 if (requestType == WaitGCPReq::WaitEpoch)
18515 list = &c_waitEpochMasterList;
18518 if(list->seize(ptr) ==
false)
18521 errorCode = WaitGCPRef::NoWaitGCPRecords;
18526 ptr.p->clientRef = senderRef;
18527 ptr.p->clientData = senderData;
18530 (m_gcp_save.m_master.m_state == GcpSave::GCP_SAVE_IDLE))
18533 m_micro_gcp.m_master.m_start_time = m_gcp_save.m_master.m_start_time = 0;
18543 WaitGCPProxyPtr ptr;
18544 if (c_waitGCPProxyList.
seize(ptr) ==
false)
18547 errorCode = WaitGCPRef::NoWaitGCPRecords;
18550 ptr.p->clientRef = senderRef;
18551 ptr.p->clientData = senderData;
18552 ptr.p->masterRef = cmasterdihref;
18554 req->senderData = ptr.i;
18555 req->senderRef = reference();
18556 req->requestType = requestType;
18558 sendSignal(cmasterdihref, GSN_WAIT_GCP_REQ, signal,
18559 WaitGCPReq::SignalLength, JBB);
18564 ref->senderData = senderData;
18565 ref->errorCode = errorCode;
18566 sendSignal(senderRef, GSN_WAIT_GCP_REF, signal,
18567 WaitGCPRef::SignalLength, JBB);
18570 void Dbdih::execWAIT_GCP_REF(
Signal* signal)
18573 ndbrequire(!isMaster());
18576 const Uint32 proxyPtr = ref->senderData;
18577 const Uint32 errorCode = ref->errorCode;
18579 WaitGCPProxyPtr ptr;
18581 c_waitGCPProxyList.
getPtr(ptr);
18583 ref->senderData = ptr.p->clientData;
18584 ref->errorCode = errorCode;
18585 sendSignal(ptr.p->clientRef, GSN_WAIT_GCP_REF, signal,
18586 WaitGCPRef::SignalLength, JBB);
18588 c_waitGCPProxyList.
release(ptr);
18591 void Dbdih::execWAIT_GCP_CONF(
Signal* signal)
18594 ndbrequire(!isMaster());
18596 const Uint32 proxyPtr = conf->senderData;
18597 const Uint32 gci_hi = conf->gci_hi;
18598 const Uint32 gci_lo = conf->gci_lo;
18599 WaitGCPProxyPtr ptr;
18602 c_waitGCPProxyList.
getPtr(ptr);
18604 conf->senderData = ptr.p->clientData;
18605 conf->gci_hi = gci_hi;
18606 conf->gci_lo = gci_lo;
18607 conf->blockStatus = cgcpOrderBlocked;
18608 sendSignal(ptr.p->clientRef, GSN_WAIT_GCP_CONF, signal,
18609 WaitGCPConf::SignalLength, JBB);
18611 c_waitGCPProxyList.
release(ptr);
18614 void Dbdih::checkWaitGCPProxy(
Signal* signal, NodeId failedNodeId)
18618 ref->errorCode = WaitGCPRef::NF_CausedAbortOfProcedure;
18620 WaitGCPProxyPtr ptr;
18621 c_waitGCPProxyList.
first(ptr);
18622 while(ptr.i != RNIL) {
18624 const Uint32 i = ptr.i;
18625 const Uint32 clientData = ptr.p->clientData;
18626 const BlockReference clientRef = ptr.p->clientRef;
18627 const BlockReference masterRef = ptr.p->masterRef;
18629 c_waitGCPProxyList.
next(ptr);
18630 if(refToNode(masterRef) == failedNodeId) {
18632 c_waitGCPProxyList.
release(i);
18633 ref->senderData = clientData;
18634 sendSignal(clientRef, GSN_WAIT_GCP_REF, signal,
18635 WaitGCPRef::SignalLength, JBB);
18640 void Dbdih::checkWaitGCPMaster(
Signal* signal, NodeId failedNodeId)
18643 WaitGCPMasterPtr ptr;
18644 c_waitGCPMasterList.
first(ptr);
18646 while (ptr.i != RNIL) {
18648 const Uint32 i = ptr.i;
18649 const NodeId nodeId = refToNode(ptr.p->clientRef);
18651 c_waitGCPMasterList.
next(ptr);
18652 if (nodeId == failedNodeId) {
18654 c_waitGCPMasterList.
release(i);
18659 void Dbdih::emptyWaitGCPMasterQueue(
Signal* signal,
18661 WaitGCPList & list)
18665 conf->gci_hi = Uint32(gci >> 32);
18666 conf->gci_lo = Uint32(gci);
18668 WaitGCPMasterPtr ptr;
18670 while(ptr.i != RNIL) {
18672 const Uint32 i = ptr.i;
18673 const Uint32 clientData = ptr.p->clientData;
18674 const BlockReference clientRef = ptr.p->clientRef;
18676 c_waitGCPMasterList.
next(ptr);
18677 conf->senderData = clientData;
18678 conf->blockStatus = cgcpOrderBlocked;
18679 sendSignal(clientRef, GSN_WAIT_GCP_CONF, signal,
18680 WaitGCPConf::SignalLength, JBB);
18686 void Dbdih::setNodeStatus(Uint32 nodeId, NodeRecord::NodeStatus newStatus)
18688 NodeRecordPtr nodePtr;
18689 nodePtr.i = nodeId;
18690 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18691 nodePtr.p->nodeStatus = newStatus;
18694 Dbdih::NodeRecord::NodeStatus Dbdih::getNodeStatus(Uint32 nodeId)
18696 NodeRecordPtr nodePtr;
18697 nodePtr.i = nodeId;
18698 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18699 return nodePtr.p->nodeStatus;
18703 Dbdih::getNodeActiveStatus(Uint32 nodeId)
18705 NodeRecordPtr nodePtr;
18706 nodePtr.i = nodeId;
18707 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18708 return nodePtr.p->activeStatus;
18715 NodeRecordPtr nodePtr;
18716 nodePtr.i = nodeId;
18717 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18718 nodePtr.p->activeStatus = newStatus;
18721 void Dbdih::setAllowNodeStart(Uint32 nodeId,
bool newState)
18723 NodeRecordPtr nodePtr;
18724 nodePtr.i = nodeId;
18725 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18726 nodePtr.p->allowNodeStart = newState;
18729 bool Dbdih::getAllowNodeStart(Uint32 nodeId)
18731 NodeRecordPtr nodePtr;
18732 nodePtr.i = nodeId;
18733 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18734 return nodePtr.p->allowNodeStart;
18738 Dbdih::getNodeGroup(Uint32 nodeId)
const
18740 NodeRecordPtr nodePtr;
18741 nodePtr.i = nodeId;
18742 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18743 return nodePtr.p->nodeGroup;
18746 bool Dbdih::checkNodeAlive(Uint32 nodeId)
18748 NodeRecordPtr nodePtr;
18749 nodePtr.i = nodeId;
18750 ndbrequire(nodeId > 0);
18751 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18752 if (nodePtr.p->nodeStatus != NodeRecord::ALIVE) {
18759 bool Dbdih::isMaster()
18761 return (reference() == cmasterdihref);
18764 bool Dbdih::isActiveMaster()
18766 return ((reference() == cmasterdihref) && (cmasterState == MASTER_ACTIVE));
18769 Dbdih::NodeRecord::NodeRecord(){
18770 m_nodefailSteps.
clear();
18772 activeStatus = Sysfile::NS_NotDefined;
18773 recNODE_FAILREP = ZFALSE;
18774 dbtcFailCompleted = ZTRUE;
18775 dbdictFailCompleted = ZTRUE;
18776 dbdihFailCompleted = ZTRUE;
18777 dblqhFailCompleted = ZTRUE;
18778 noOfStartedChkpt = 0;
18779 noOfQueuedChkpt = 0;
18780 lcpStateAtTakeOver = (MasterLCPConf::State)255;
18782 activeTabptr = RNIL;
18783 nodeStatus = NodeRecord::NOT_IN_CLUSTER;
18784 useInTransactions =
false;
18785 copyCompleted =
false;
18786 allowNodeStart =
true;
18792 Dbdih::sendDictLockReq(
Signal* signal, Uint32 lockType, Callback c)
18795 DictLockSlavePtr lockPtr;
18797 c_dictLockSlavePool.
seize(lockPtr);
18798 ndbrequire(lockPtr.i != RNIL);
18800 req->userPtr = lockPtr.i;
18801 req->lockType = lockType;
18802 req->userRef = reference();
18804 lockPtr.p->lockPtr = RNIL;
18805 lockPtr.p->lockType = lockType;
18806 lockPtr.p->locked =
false;
18807 lockPtr.p->callback = c;
18813 const unsigned int get_major = getMajor(masterVersion);
18814 const unsigned int get_minor = getMinor(masterVersion);
18815 const unsigned int get_build = getBuild(masterVersion);
18816 ndbrequire(get_major >= 4);
18818 if (masterVersion < NDBD_DICT_LOCK_VERSION_5 ||
18819 (masterVersion < NDBD_DICT_LOCK_VERSION_5_1 &&
18820 get_major == 5 && get_minor == 1) ||
18821 ERROR_INSERTED(7176)) {
18824 infoEvent(
"DIH: detect upgrade: master node %u old version %u.%u.%u",
18825 (
unsigned int)cmasterNodeId, get_major, get_minor, get_build);
18828 conf->userPtr = lockPtr.i;
18829 conf->lockType = lockType;
18830 conf->lockPtr = ZNIL;
18832 sendSignal(reference(), GSN_DICT_LOCK_CONF, signal,
18833 DictLockConf::SignalLength, JBB);
18838 BlockReference dictMasterRef = calcDictBlockRef(cmasterNodeId);
18839 sendSignal(dictMasterRef, GSN_DICT_LOCK_REQ, signal,
18840 DictLockReq::SignalLength, JBB);
18844 Dbdih::execDICT_LOCK_CONF(
Signal* signal)
18847 recvDictLockConf(signal);
18851 Dbdih::execDICT_LOCK_REF(
Signal* signal)
18858 Dbdih::recvDictLockConf(
Signal* signal)
18862 DictLockSlavePtr lockPtr;
18863 c_dictLockSlavePool.
getPtr(lockPtr, conf->userPtr);
18865 lockPtr.p->lockPtr = conf->lockPtr;
18866 ndbrequire(lockPtr.p->lockType == conf->lockType);
18867 ndbrequire(lockPtr.p->locked ==
false);
18868 lockPtr.p->locked =
true;
18870 lockPtr.p->callback.m_callbackData = lockPtr.i;
18871 execute(signal, lockPtr.p->callback, 0);
18875 Dbdih::sendDictUnlockOrd(
Signal* signal, Uint32 lockSlavePtrI)
18879 DictLockSlavePtr lockPtr;
18880 c_dictLockSlavePool.
getPtr(lockPtr, lockSlavePtrI);
18882 ord->lockPtr = lockPtr.p->lockPtr;
18883 ord->lockType = lockPtr.p->lockType;
18884 ord->senderData = lockPtr.i;
18885 ord->senderRef = reference();
18887 c_dictLockSlavePool.
release(lockPtr);
18893 const unsigned int get_major = getMajor(masterVersion);
18894 const unsigned int get_minor = getMinor(masterVersion);
18895 ndbrequire(get_major >= 4);
18897 if (masterVersion < NDBD_DICT_LOCK_VERSION_5 ||
18898 (masterVersion < NDBD_DICT_LOCK_VERSION_5_1 &&
18899 get_major == 5 && get_minor == 1) ||
18900 ERROR_INSERTED(7176)) {
18905 Uint32 len = DictUnlockOrd::SignalLength;
18906 if (unlikely(
getNodeInfo(cmasterNodeId).m_version < NDB_MAKE_VERSION(6,3,0)))
18912 BlockReference dictMasterRef = calcDictBlockRef(cmasterNodeId);
18913 sendSignal(dictMasterRef, GSN_DICT_UNLOCK_ORD, signal, len, JBB);
18916 #ifdef ERROR_INSERT
18918 Dbdih::sendToRandomNodes(
const char *
msg,
18926 JobBufferLevel
level)
18930 counter->clearWaitingFor();
18933 NodeRecordPtr nodePtr;
18934 nodePtr.i = cfirstAliveNode;
18937 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18938 if (nodePtr.i != getOwnNodeId())
18940 nodes.push_back(nodePtr.i);
18942 nodePtr.i = nodePtr.p->nextNode;
18943 }
while (nodePtr.i != RNIL);
18947 Uint32 cnt = nodes.size();
18954 Uint32
remove = (rand() % cnt);
18958 for (Uint32 i = 0; i<
remove; i++)
18960 Uint32 rand_node = rand() % nodes.size();
18961 masked.
set(nodes[rand_node]);
18962 nodes.erase(rand_node);
18970 nodePtr.i = cfirstAliveNode;
18973 ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord);
18976 if (!masked.
get(nodePtr.i))
18980 (this->*fun)(signal, nodePtr.i, extra);
18984 Uint32 ref = numberToRef(block, nodePtr.i);
18985 sendSignal(ref, gsn, signal, len, level);
18993 bufpos = strlen(buf);
18994 nodePtr.i = nodePtr.p->nextNode;
18995 }
while (nodePtr.i != RNIL);
19004 Dbdih::dihGetInstanceKey(Uint32 tabId, Uint32 fragId)
19006 TabRecordPtr tTabPtr;
19008 ptrCheckGuard(tTabPtr, ctabFileSize, tabRecord);
19009 FragmentstorePtr tFragPtr;
19010 getFragstore(tTabPtr.p, fragId, tFragPtr);
19011 Uint32 instanceKey = dihGetInstanceKey(tFragPtr);
19012 return instanceKey;
19019 Dbdih::execCREATE_NODEGROUP_IMPL_REQ(
Signal* signal)
19026 Uint32 rt = req->requestType;
19029 case CreateNodegroupImplReq::RT_ABORT:
19032 case CreateNodegroupImplReq::RT_PARSE:
19033 case CreateNodegroupImplReq::RT_PREPARE:
19034 case CreateNodegroupImplReq::RT_COMMIT:
19037 for (Uint32 i = 0; i<NDB_ARRAY_SIZE(req->nodes) && req->nodes[
i] ; i++)
19040 if (getNodeActiveStatus(req->nodes[i]) != Sysfile::NS_Configured)
19043 err = CreateNodegroupRef::NodeAlreadyInNodegroup;
19048 if (cnt != cnoReplicas)
19051 err = CreateNodegroupRef::InvalidNoOfNodesInNodegroup;
19055 Uint32 ng = req->nodegroupId;
19058 for (Uint32 i = 0; i<cnoOfNodeGroups; i++)
19060 tmp.
clear(c_node_groups[i]);
19063 if (ng == RNIL && rt == CreateNodegroupImplReq::RT_PARSE)
19069 if (ng > MAX_NDB_NODES)
19072 err = CreateNodegroupRef::InvalidNodegroupId;
19076 if (tmp.
get(ng) ==
false)
19079 err = CreateNodegroupRef::NodegroupInUse;
19083 if (rt == CreateNodegroupImplReq::RT_PARSE || rt == CreateNodegroupImplReq::RT_PREPARE)
19088 bool alive =
false;
19089 for (Uint32 i = 0; i<cnoReplicas; i++)
19092 Uint32 nodeId = req->nodes[
i];
19093 if (getNodeStatus(nodeId) == NodeRecord::ALIVE)
19102 if (alive ==
false)
19105 err = CreateNodegroupRef::NoNodeAlive;
19110 if (rt == CreateNodegroupImplReq::RT_PARSE)
19113 signal->theData[0] = 0;
19114 signal->theData[1] = ng;
19118 if (rt == CreateNodegroupImplReq::RT_PREPARE)
19124 ndbrequire(rt == CreateNodegroupImplReq::RT_COMMIT);
19125 for (Uint32 i = 0; i<cnoReplicas; i++)
19127 Uint32 nodeId = req->nodes[
i];
19128 Sysfile::setNodeGroup(nodeId, SYSFILE->nodeGroups, req->nodegroupId);
19129 if (getNodeStatus(nodeId) == NodeRecord::ALIVE)
19132 Sysfile::setNodeStatus(nodeId, SYSFILE->nodeStatus, Sysfile::NS_Active);
19137 Sysfile::setNodeStatus(nodeId, SYSFILE->nodeStatus, Sysfile::NS_ActiveMissed_1);
19139 setNodeActiveStatus();
19144 case CreateNodegroupImplReq::RT_COMPLETE:
19146 gci = m_micro_gcp.m_current_gci;
19152 conf->senderRef = reference();
19153 conf->senderData = req->senderData;
19154 conf->gci_hi = Uint32(gci >> 32);
19155 conf->gci_lo = Uint32(gci);
19156 sendSignal(req->senderRef, GSN_CREATE_NODEGROUP_IMPL_CONF, signal,
19157 CreateNodegroupImplConf::SignalLength, JBB);
19162 if (rt == CreateNodegroupImplReq::RT_PARSE)
19165 signal->theData[0] = err;
19169 if (rt == CreateNodegroupImplReq::RT_PREPARE)
19173 ref->senderRef = reference();
19174 ref->senderData = req->senderData;
19175 ref->errorCode = err;
19176 sendSignal(req->senderRef, GSN_CREATE_NODEGROUP_IMPL_REF, signal,
19177 CreateNodegroupImplRef::SignalLength, JBB);
19189 Dbdih::execDROP_NODEGROUP_IMPL_REQ(
Signal* signal)
19195 NodeGroupRecordPtr NGPtr;
19198 Uint32 rt = req->requestType;
19201 case DropNodegroupImplReq::RT_ABORT:
19204 case DropNodegroupImplReq::RT_PARSE:
19205 case DropNodegroupImplReq::RT_PREPARE:
19207 NGPtr.i = req->nodegroupId;
19208 if (NGPtr.i >= MAX_NDB_NODES)
19211 err = DropNodegroupRef::NoSuchNodegroup;
19214 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
19216 if (NGPtr.p->nodegroupIndex == RNIL)
19219 err = DropNodegroupRef::NoSuchNodegroup;
19223 if (NGPtr.p->m_ref_count)
19226 err = DropNodegroupRef::NodegroupInUse;
19230 case DropNodegroupImplReq::RT_COMMIT:
19233 gci = m_micro_gcp.m_current_gci;
19236 case DropNodegroupImplReq::RT_COMPLETE:
19238 NGPtr.i = req->nodegroupId;
19239 ptrCheckGuard(NGPtr, MAX_NDB_NODES, nodeGroupRecord);
19240 for (Uint32 i = 0; i<NGPtr.p->nodeCount; i++)
19243 Uint32 nodeId = NGPtr.p->nodesInGroup[
i];
19244 Sysfile::setNodeGroup(nodeId, SYSFILE->nodeGroups, NO_NODE_GROUP_ID);
19245 Sysfile::setNodeStatus(nodeId, SYSFILE->nodeStatus, Sysfile::NS_Configured);
19247 setNodeActiveStatus();
19255 conf->senderRef = reference();
19256 conf->senderData = req->senderData;
19257 conf->gci_hi = Uint32(gci >> 32);
19258 conf->gci_lo = Uint32(gci);
19259 sendSignal(req->senderRef, GSN_DROP_NODEGROUP_IMPL_CONF, signal,
19260 DropNodegroupImplConf::SignalLength, JBB);
19266 ref->senderRef = reference();
19267 ref->senderData = req->senderData;
19268 ref->errorCode = err;
19269 sendSignal(req->senderRef, GSN_DROP_NODEGROUP_IMPL_REF, signal,
19270 DropNodegroupImplRef::SignalLength, JBB);