DbtcMain.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:428k
-
- if(4 + 3 * op_count > 25){
- jam();
- LinearSectionPtr ptr[3];
- ptr[0].p = signal->getDataPtrSend()+25;
- ptr[0].sz = 3 * op_count;
- sendSignal(apiConnectptr.p->ndbapiBlockref, GSN_SCAN_TABCONF, signal,
- ScanTabConf::SignalLength, JBB, ptr, 1);
- } else {
- jam();
- sendSignal(apiConnectptr.p->ndbapiBlockref, GSN_SCAN_TABCONF, signal,
- ScanTabConf::SignalLength + 3 * op_count, JBB);
- }
- scanPtr.p->m_queued_count = 0;
- }//Dbtc::sendScanTabConf()
- void Dbtc::gcpTcfinished(Signal* signal)
- {
- signal->theData[1] = tcheckGcpId;
- sendSignal(cdihblockref, GSN_GCP_TCFINISHED, signal, 2, JBB);
- }//Dbtc::gcpTcfinished()
- void Dbtc::initApiConnect(Signal* signal)
- {
- Uint32 tiacTmp;
- Uint32 guard4;
- tiacTmp = capiConnectFilesize / 3;
- ndbrequire(tiacTmp > 0);
- guard4 = tiacTmp + 1;
- for (cachePtr.i = 0; cachePtr.i < guard4; cachePtr.i++) {
- refresh_watch_dog();
- ptrAss(cachePtr, cacheRecord);
- cachePtr.p->firstAttrbuf = RNIL;
- cachePtr.p->lastAttrbuf = RNIL;
- cachePtr.p->firstKeybuf = RNIL;
- cachePtr.p->lastKeybuf = RNIL;
- cachePtr.p->nextCacheRec = cachePtr.i + 1;
- }//for
- cachePtr.i = tiacTmp;
- ptrCheckGuard(cachePtr, ccacheFilesize, cacheRecord);
- cachePtr.p->nextCacheRec = RNIL;
- cfirstfreeCacheRec = 0;
- guard4 = tiacTmp - 1;
- for (apiConnectptr.i = 0; apiConnectptr.i <= guard4; apiConnectptr.i++) {
- refresh_watch_dog();
- jam();
- ptrAss(apiConnectptr, apiConnectRecord);
- apiConnectptr.p->apiConnectstate = CS_DISCONNECTED;
- apiConnectptr.p->apiFailState = ZFALSE;
- setApiConTimer(apiConnectptr.i, 0, __LINE__);
- apiConnectptr.p->takeOverRec = (Uint8)Z8NIL;
- apiConnectptr.p->cachePtr = RNIL;
- apiConnectptr.p->nextApiConnect = apiConnectptr.i + 1;
- apiConnectptr.p->ndbapiBlockref = 0xFFFFFFFF; // Invalid ref
- apiConnectptr.p->commitAckMarker = RNIL;
- apiConnectptr.p->firstTcConnect = RNIL;
- apiConnectptr.p->lastTcConnect = RNIL;
- apiConnectptr.p->triggerPending = false;
- apiConnectptr.p->isIndexOp = false;
- apiConnectptr.p->accumulatingIndexOp = RNIL;
- apiConnectptr.p->executingIndexOp = RNIL;
- apiConnectptr.p->buddyPtr = RNIL;
- apiConnectptr.p->currSavePointId = 0;
- }//for
- apiConnectptr.i = tiacTmp - 1;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- apiConnectptr.p->nextApiConnect = RNIL;
- cfirstfreeApiConnect = 0;
- guard4 = (2 * tiacTmp) - 1;
- for (apiConnectptr.i = tiacTmp; apiConnectptr.i <= guard4; apiConnectptr.i++)
- {
- refresh_watch_dog();
- jam();
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- apiConnectptr.p->apiConnectstate = CS_RESTART;
- apiConnectptr.p->apiFailState = ZFALSE;
- setApiConTimer(apiConnectptr.i, 0, __LINE__);
- apiConnectptr.p->takeOverRec = (Uint8)Z8NIL;
- apiConnectptr.p->cachePtr = RNIL;
- apiConnectptr.p->nextApiConnect = apiConnectptr.i + 1;
- apiConnectptr.p->ndbapiBlockref = 0xFFFFFFFF; // Invalid ref
- apiConnectptr.p->commitAckMarker = RNIL;
- apiConnectptr.p->firstTcConnect = RNIL;
- apiConnectptr.p->lastTcConnect = RNIL;
- apiConnectptr.p->triggerPending = false;
- apiConnectptr.p->isIndexOp = false;
- apiConnectptr.p->accumulatingIndexOp = RNIL;
- apiConnectptr.p->executingIndexOp = RNIL;
- apiConnectptr.p->buddyPtr = RNIL;
- apiConnectptr.p->currSavePointId = 0;
- }//for
- apiConnectptr.i = (2 * tiacTmp) - 1;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- apiConnectptr.p->nextApiConnect = RNIL;
- cfirstfreeApiConnectCopy = tiacTmp;
- guard4 = (3 * tiacTmp) - 1;
- for (apiConnectptr.i = 2 * tiacTmp; apiConnectptr.i <= guard4;
- apiConnectptr.i++) {
- refresh_watch_dog();
- jam();
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- setApiConTimer(apiConnectptr.i, 0, __LINE__);
- apiConnectptr.p->apiFailState = ZFALSE;
- apiConnectptr.p->apiConnectstate = CS_RESTART;
- apiConnectptr.p->takeOverRec = (Uint8)Z8NIL;
- apiConnectptr.p->cachePtr = RNIL;
- apiConnectptr.p->nextApiConnect = apiConnectptr.i + 1;
- apiConnectptr.p->ndbapiBlockref = 0xFFFFFFFF; // Invalid ref
- apiConnectptr.p->commitAckMarker = RNIL;
- apiConnectptr.p->firstTcConnect = RNIL;
- apiConnectptr.p->lastTcConnect = RNIL;
- apiConnectptr.p->triggerPending = false;
- apiConnectptr.p->isIndexOp = false;
- apiConnectptr.p->accumulatingIndexOp = RNIL;
- apiConnectptr.p->executingIndexOp = RNIL;
- apiConnectptr.p->buddyPtr = RNIL;
- apiConnectptr.p->currSavePointId = 0;
- }//for
- apiConnectptr.i = (3 * tiacTmp) - 1;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- apiConnectptr.p->nextApiConnect = RNIL;
- cfirstfreeApiConnectFail = 2 * tiacTmp;
- }//Dbtc::initApiConnect()
- void Dbtc::initattrbuf(Signal* signal)
- {
- ndbrequire(cattrbufFilesize > 0);
- for (attrbufptr.i = 0; attrbufptr.i < cattrbufFilesize; attrbufptr.i++) {
- refresh_watch_dog();
- jam();
- ptrAss(attrbufptr, attrbufRecord);
- attrbufptr.p->attrbuf[ZINBUF_NEXT] = attrbufptr.i + 1; /* NEXT ATTRBUF */
- }//for
- attrbufptr.i = cattrbufFilesize - 1;
- ptrAss(attrbufptr, attrbufRecord);
- attrbufptr.p->attrbuf[ZINBUF_NEXT] = RNIL; /* NEXT ATTRBUF */
- cfirstfreeAttrbuf = 0;
- }//Dbtc::initattrbuf()
- void Dbtc::initdatabuf(Signal* signal)
- {
- ndbrequire(cdatabufFilesize > 0);
- for (databufptr.i = 0; databufptr.i < cdatabufFilesize; databufptr.i++) {
- refresh_watch_dog();
- ptrAss(databufptr, databufRecord);
- databufptr.p->nextDatabuf = databufptr.i + 1;
- }//for
- databufptr.i = cdatabufFilesize - 1;
- ptrCheckGuard(databufptr, cdatabufFilesize, databufRecord);
- databufptr.p->nextDatabuf = RNIL;
- cfirstfreeDatabuf = 0;
- }//Dbtc::initdatabuf()
- void Dbtc::initgcp(Signal* signal)
- {
- ndbrequire(cgcpFilesize > 0);
- for (gcpPtr.i = 0; gcpPtr.i < cgcpFilesize; gcpPtr.i++) {
- ptrAss(gcpPtr, gcpRecord);
- gcpPtr.p->nextGcp = gcpPtr.i + 1;
- }//for
- gcpPtr.i = cgcpFilesize - 1;
- ptrCheckGuard(gcpPtr, cgcpFilesize, gcpRecord);
- gcpPtr.p->nextGcp = RNIL;
- cfirstfreeGcp = 0;
- cfirstgcp = RNIL;
- clastgcp = RNIL;
- }//Dbtc::initgcp()
- void Dbtc::inithost(Signal* signal)
- {
- cpackedListIndex = 0;
- ndbrequire(chostFilesize > 0);
- for (hostptr.i = 0; hostptr.i < chostFilesize; hostptr.i++) {
- jam();
- ptrAss(hostptr, hostRecord);
- hostptr.p->hostStatus = HS_DEAD;
- hostptr.p->inPackedList = false;
- hostptr.p->takeOverStatus = TOS_NOT_DEFINED;
- hostptr.p->lqhTransStatus = LTS_IDLE;
- hostptr.p->noOfWordsTCKEYCONF = 0;
- hostptr.p->noOfWordsTCINDXCONF = 0;
- hostptr.p->noOfPackedWordsLqh = 0;
- hostptr.p->hostLqhBlockRef = calcLqhBlockRef(hostptr.i);
- }//for
- }//Dbtc::inithost()
- void Dbtc::initialiseRecordsLab(Signal* signal, UintR Tdata0,
- Uint32 retRef, Uint32 retData)
- {
- switch (Tdata0) {
- case 0:
- jam();
- initApiConnect(signal);
- break;
- case 1:
- jam();
- initattrbuf(signal);
- break;
- case 2:
- jam();
- initdatabuf(signal);
- break;
- case 3:
- jam();
- initgcp(signal);
- break;
- case 4:
- jam();
- inithost(signal);
- break;
- case 5:
- jam();
- // UNUSED Free to initialise something
- break;
- case 6:
- jam();
- initTable(signal);
- break;
- case 7:
- jam();
- initialiseScanrec(signal);
- break;
- case 8:
- jam();
- initialiseScanOprec(signal);
- break;
- case 9:
- jam();
- initialiseScanFragrec(signal);
- break;
- case 10:
- jam();
- initialiseTcConnect(signal);
- break;
- case 11:
- jam();
- initTcFail(signal);
- {
- ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend();
- conf->senderRef = reference();
- conf->senderData = retData;
- sendSignal(retRef, GSN_READ_CONFIG_CONF, signal,
- ReadConfigConf::SignalLength, JBB);
- }
- return;
- break;
- default:
- jam();
- systemErrorLab(signal);
- return;
- break;
- }//switch
- signal->theData[0] = TcContinueB::ZINITIALISE_RECORDS;
- signal->theData[1] = Tdata0 + 1;
- signal->theData[2] = 0;
- signal->theData[3] = retRef;
- signal->theData[4] = retData;
- sendSignal(DBTC_REF, GSN_CONTINUEB, signal, 5, JBB);
- }
- /* ========================================================================= */
- /* ======= INITIALISE_SCANREC ======= */
- /* */
- /* ========================================================================= */
- void Dbtc::initialiseScanrec(Signal* signal)
- {
- ScanRecordPtr scanptr;
- ndbrequire(cscanrecFileSize > 0);
- for (scanptr.i = 0; scanptr.i < cscanrecFileSize; scanptr.i++) {
- refresh_watch_dog();
- jam();
- ptrAss(scanptr, scanRecord);
- new (scanptr.p) ScanRecord();
- scanptr.p->scanState = ScanRecord::IDLE;
- scanptr.p->scanApiRec = RNIL;
- scanptr.p->nextScan = scanptr.i + 1;
- }//for
- scanptr.i = cscanrecFileSize - 1;
- ptrAss(scanptr, scanRecord);
- scanptr.p->nextScan = RNIL;
- cfirstfreeScanrec = 0;
- }//Dbtc::initialiseScanrec()
- void Dbtc::initialiseScanFragrec(Signal* signal)
- {
- }//Dbtc::initialiseScanFragrec()
- void Dbtc::initialiseScanOprec(Signal* signal)
- {
- }//Dbtc::initialiseScanOprec()
- void Dbtc::initTable(Signal* signal)
- {
- ndbrequire(ctabrecFilesize > 0);
- for (tabptr.i = 0; tabptr.i < ctabrecFilesize; tabptr.i++) {
- refresh_watch_dog();
- ptrAss(tabptr, tableRecord);
- tabptr.p->currentSchemaVersion = 0;
- tabptr.p->storedTable = true;
- tabptr.p->tableType = 0;
- tabptr.p->enabled = false;
- tabptr.p->dropping = false;
- }//for
- }//Dbtc::initTable()
- void Dbtc::initialiseTcConnect(Signal* signal)
- {
- ndbrequire(ctcConnectFilesize >= 2);
- // Place half of tcConnectptr's in cfirstfreeTcConnectFail list
- Uint32 titcTmp = ctcConnectFilesize / 2;
- for (tcConnectptr.i = 0; tcConnectptr.i < titcTmp; tcConnectptr.i++) {
- refresh_watch_dog();
- jam();
- ptrAss(tcConnectptr, tcConnectRecord);
- tcConnectptr.p->tcConnectstate = OS_RESTART;
- tcConnectptr.p->apiConnect = RNIL;
- tcConnectptr.p->noOfNodes = 0;
- tcConnectptr.p->nextTcConnect = tcConnectptr.i + 1;
- }//for
- tcConnectptr.i = titcTmp - 1;
- ptrAss(tcConnectptr, tcConnectRecord);
- tcConnectptr.p->nextTcConnect = RNIL;
- cfirstfreeTcConnectFail = 0;
- // Place other half in cfirstfreeTcConnect list
- for (tcConnectptr.i = titcTmp; tcConnectptr.i < ctcConnectFilesize;
- tcConnectptr.i++) {
- refresh_watch_dog();
- jam();
- ptrAss(tcConnectptr, tcConnectRecord);
- tcConnectptr.p->tcConnectstate = OS_RESTART;
- tcConnectptr.p->apiConnect = RNIL;
- tcConnectptr.p->noOfNodes = 0;
- tcConnectptr.p->nextTcConnect = tcConnectptr.i + 1;
- }//for
- tcConnectptr.i = ctcConnectFilesize - 1;
- ptrAss(tcConnectptr, tcConnectRecord);
- tcConnectptr.p->nextTcConnect = RNIL;
- cfirstfreeTcConnect = titcTmp;
- c_counters.cconcurrentOp = 0;
- }//Dbtc::initialiseTcConnect()
- /* ------------------------------------------------------------------------- */
- /* ---- LINK A GLOBAL CHECKPOINT RECORD INTO THE LIST WITH TRANSACTIONS */
- /* WAITING FOR COMPLETION. */
- /* ------------------------------------------------------------------------- */
- void Dbtc::linkGciInGcilist(Signal* signal)
- {
- GcpRecordPtr tmpGcpPointer;
- if (cfirstgcp == RNIL) {
- jam();
- cfirstgcp = gcpPtr.i;
- } else {
- jam();
- tmpGcpPointer.i = clastgcp;
- ptrCheckGuard(tmpGcpPointer, cgcpFilesize, gcpRecord);
- tmpGcpPointer.p->nextGcp = gcpPtr.i;
- }//if
- clastgcp = gcpPtr.i;
- }//Dbtc::linkGciInGcilist()
- /* ------------------------------------------------------------------------- */
- /* ------- LINK SECONDARY KEY BUFFER IN OPERATION RECORD ------- */
- /* ------------------------------------------------------------------------- */
- void Dbtc::linkKeybuf(Signal* signal)
- {
- seizeDatabuf(signal);
- tmpDatabufptr.i = cachePtr.p->lastKeybuf;
- cachePtr.p->lastKeybuf = databufptr.i;
- if (tmpDatabufptr.i == RNIL) {
- jam();
- cachePtr.p->firstKeybuf = databufptr.i;
- } else {
- jam();
- ptrCheckGuard(tmpDatabufptr, cdatabufFilesize, databufRecord);
- tmpDatabufptr.p->nextDatabuf = databufptr.i;
- }//if
- }//Dbtc::linkKeybuf()
- /* ------------------------------------------------------------------------- */
- /* ------- LINK A TC CONNECT RECORD INTO THE API LIST OF TC CONNECTIONS --- */
- /* ------------------------------------------------------------------------- */
- void Dbtc::linkTcInConnectionlist(Signal* signal)
- {
- /* POINTER FOR THE CONNECT_RECORD */
- TcConnectRecordPtr ltcTcConnectptr;
- tcConnectptr.p->nextTcConnect = RNIL;
- ltcTcConnectptr.i = apiConnectptr.p->lastTcConnect;
- ptrCheck(ltcTcConnectptr, ctcConnectFilesize, tcConnectRecord);
- apiConnectptr.p->lastTcConnect = tcConnectptr.i;
- if (ltcTcConnectptr.i == RNIL) {
- jam();
- apiConnectptr.p->firstTcConnect = tcConnectptr.i;
- } else {
- jam();
- ptrGuard(ltcTcConnectptr);
- ltcTcConnectptr.p->nextTcConnect = tcConnectptr.i;
- }//if
- }//Dbtc::linkTcInConnectionlist()
- /*---------------------------------------------------------------------------*/
- /* RELEASE_ABORT_RESOURCES */
- /* THIS CODE RELEASES ALL RESOURCES AFTER AN ABORT OF A TRANSACTION AND ALSO */
- /* SENDS THE ABORT DECISION TO THE APPLICATION. */
- /*---------------------------------------------------------------------------*/
- void Dbtc::releaseAbortResources(Signal* signal)
- {
- TcConnectRecordPtr rarTcConnectptr;
- c_counters.cabortCount++;
- if (apiConnectptr.p->cachePtr != RNIL) {
- cachePtr.i = apiConnectptr.p->cachePtr;
- ptrCheckGuard(cachePtr, ccacheFilesize, cacheRecord);
- releaseAttrinfo();
- releaseKeys();
- }//if
- tcConnectptr.i = apiConnectptr.p->firstTcConnect;
- while (tcConnectptr.i != RNIL) {
- jam();
- ptrCheckGuard(tcConnectptr, ctcConnectFilesize, tcConnectRecord);
- // Clear any markers that were set in CS_RECEIVING state
- clearCommitAckMarker(apiConnectptr.p, tcConnectptr.p);
- rarTcConnectptr.i = tcConnectptr.p->nextTcConnect;
- releaseTcCon();
- tcConnectptr.i = rarTcConnectptr.i;
- }//while
- apiConnectptr.p->firstTcConnect = RNIL;
- apiConnectptr.p->lastTcConnect = RNIL;
- // MASV let state be CS_ABORTING until all
- // signals in the "air" have been received. Reset to CS_CONNECTED
- // will be done when a TCKEYREQ with start flag is recieved
- // or releaseApiCon is called
- // apiConnectptr.p->apiConnectstate = CS_CONNECTED;
- apiConnectptr.p->apiConnectstate = CS_ABORTING;
- apiConnectptr.p->abortState = AS_IDLE;
- releaseAllSeizedIndexOperations(apiConnectptr.p);
- if(apiConnectptr.p->m_exec_flag || apiConnectptr.p->apiFailState == ZTRUE){
- jam();
- bool ok = false;
- Uint32 blockRef = apiConnectptr.p->ndbapiBlockref;
- ReturnSignal ret = apiConnectptr.p->returnsignal;
- apiConnectptr.p->returnsignal = RS_NO_RETURN;
- apiConnectptr.p->m_exec_flag = 0;
- switch(ret){
- case RS_TCROLLBACKCONF:
- jam();
- ok = true;
- signal->theData[0] = apiConnectptr.p->ndbapiConnect;
- signal->theData[1] = apiConnectptr.p->transid[0];
- signal->theData[2] = apiConnectptr.p->transid[1];
- sendSignal(blockRef, GSN_TCROLLBACKCONF, signal, 3, JBB);
- break;
- case RS_TCROLLBACKREP:{
- jam();
- ok = true;
- TcRollbackRep * const tcRollbackRep =
- (TcRollbackRep *) signal->getDataPtr();
-
- tcRollbackRep->connectPtr = apiConnectptr.p->ndbapiConnect;
- tcRollbackRep->transId[0] = apiConnectptr.p->transid[0];
- tcRollbackRep->transId[1] = apiConnectptr.p->transid[1];
- tcRollbackRep->returnCode = apiConnectptr.p->returncode;
- sendSignal(blockRef, GSN_TCROLLBACKREP, signal,
- TcRollbackRep::SignalLength, JBB);
- }
- break;
- case RS_NO_RETURN:
- jam();
- ok = true;
- break;
- case RS_TCKEYCONF:
- case RS_TC_COMMITCONF:
- break;
- }
- if(!ok){
- jam();
- ndbout_c("returnsignal = %d", apiConnectptr.p->returnsignal);
- sendSystemError(signal);
- }//if
- }
- setApiConTimer(apiConnectptr.i, 0,
- 100000+c_apiConTimer_line[apiConnectptr.i]);
- if (apiConnectptr.p->apiFailState == ZTRUE) {
- jam();
- handleApiFailState(signal, apiConnectptr.i);
- return;
- }//if
- }//Dbtc::releaseAbortResources()
- void Dbtc::releaseApiCon(Signal* signal, UintR TapiConnectPtr)
- {
- ApiConnectRecordPtr TlocalApiConnectptr;
- TlocalApiConnectptr.i = TapiConnectPtr;
- ptrCheckGuard(TlocalApiConnectptr, capiConnectFilesize, apiConnectRecord);
- TlocalApiConnectptr.p->nextApiConnect = cfirstfreeApiConnect;
- cfirstfreeApiConnect = TlocalApiConnectptr.i;
- setApiConTimer(TlocalApiConnectptr.i, 0, __LINE__);
- TlocalApiConnectptr.p->apiConnectstate = CS_DISCONNECTED;
- ndbassert(TlocalApiConnectptr.p->apiScanRec == RNIL);
- TlocalApiConnectptr.p->ndbapiBlockref = 0;
- }//Dbtc::releaseApiCon()
- void Dbtc::releaseApiConnectFail(Signal* signal)
- {
- apiConnectptr.p->apiConnectstate = CS_RESTART;
- apiConnectptr.p->takeOverRec = (Uint8)Z8NIL;
- setApiConTimer(apiConnectptr.i, 0, __LINE__);
- apiConnectptr.p->nextApiConnect = cfirstfreeApiConnectFail;
- cfirstfreeApiConnectFail = apiConnectptr.i;
- }//Dbtc::releaseApiConnectFail()
- void Dbtc::releaseGcp(Signal* signal)
- {
- ptrGuard(gcpPtr);
- gcpPtr.p->nextGcp = cfirstfreeGcp;
- cfirstfreeGcp = gcpPtr.i;
- }//Dbtc::releaseGcp()
- void Dbtc::releaseKeys()
- {
- UintR Tmp;
- databufptr.i = cachePtr.p->firstKeybuf;
- while (databufptr.i != RNIL) {
- jam();
- ptrCheckGuard(databufptr, cdatabufFilesize, databufRecord);
- Tmp = databufptr.p->nextDatabuf;
- databufptr.p->nextDatabuf = cfirstfreeDatabuf;
- cfirstfreeDatabuf = databufptr.i;
- databufptr.i = Tmp;
- }//while
- cachePtr.p->firstKeybuf = RNIL;
- cachePtr.p->lastKeybuf = RNIL;
- }//Dbtc::releaseKeys()
- void Dbtc::releaseTcConnectFail(Signal* signal)
- {
- ptrGuard(tcConnectptr);
- tcConnectptr.p->nextTcConnect = cfirstfreeTcConnectFail;
- cfirstfreeTcConnectFail = tcConnectptr.i;
- }//Dbtc::releaseTcConnectFail()
- void Dbtc::seizeApiConnect(Signal* signal)
- {
- if (cfirstfreeApiConnect != RNIL) {
- jam();
- terrorCode = ZOK;
- apiConnectptr.i = cfirstfreeApiConnect; /* ASSIGN A FREE RECORD FROM */
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- cfirstfreeApiConnect = apiConnectptr.p->nextApiConnect;
- apiConnectptr.p->nextApiConnect = RNIL;
- setApiConTimer(apiConnectptr.i, 0, __LINE__);
- apiConnectptr.p->apiConnectstate = CS_CONNECTED; /* STATE OF CONNECTION */
- apiConnectptr.p->triggerPending = false;
- apiConnectptr.p->isIndexOp = false;
- } else {
- jam();
- terrorCode = ZNO_FREE_API_CONNECTION;
- }//if
- }//Dbtc::seizeApiConnect()
- void Dbtc::seizeApiConnectFail(Signal* signal)
- {
- apiConnectptr.i = cfirstfreeApiConnectFail;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- cfirstfreeApiConnectFail = apiConnectptr.p->nextApiConnect;
- }//Dbtc::seizeApiConnectFail()
- void Dbtc::seizeDatabuf(Signal* signal)
- {
- databufptr.i = cfirstfreeDatabuf;
- ptrCheckGuard(databufptr, cdatabufFilesize, databufRecord);
- cfirstfreeDatabuf = databufptr.p->nextDatabuf;
- databufptr.p->nextDatabuf = RNIL;
- }//Dbtc::seizeDatabuf()
- void Dbtc::seizeTcConnect(Signal* signal)
- {
- tcConnectptr.i = cfirstfreeTcConnect;
- ptrCheckGuard(tcConnectptr, ctcConnectFilesize, tcConnectRecord);
- cfirstfreeTcConnect = tcConnectptr.p->nextTcConnect;
- c_counters.cconcurrentOp++;
- tcConnectptr.p->isIndexOp = false;
- }//Dbtc::seizeTcConnect()
- void Dbtc::seizeTcConnectFail(Signal* signal)
- {
- tcConnectptr.i = cfirstfreeTcConnectFail;
- ptrCheckGuard(tcConnectptr, ctcConnectFilesize, tcConnectRecord);
- cfirstfreeTcConnectFail = tcConnectptr.p->nextTcConnect;
- }//Dbtc::seizeTcConnectFail()
- void Dbtc::sendAttrinfo(Signal* signal,
- UintR TattrinfoPtr,
- AttrbufRecord * const regAttrPtr,
- UintR TBref)
- {
- UintR TdataPos;
- UintR sig0, sig1, sig2, sig3, sig4, sig5, sig6, sig7;
- ApiConnectRecord * const regApiPtr = apiConnectptr.p;
- TdataPos = regAttrPtr->attrbuf[ZINBUF_DATA_LEN];
- sig0 = TattrinfoPtr;
- sig1 = regApiPtr->transid[0];
- sig2 = regApiPtr->transid[1];
- signal->theData[0] = sig0;
- signal->theData[1] = sig1;
- signal->theData[2] = sig2;
- sig0 = regAttrPtr->attrbuf[0];
- sig1 = regAttrPtr->attrbuf[1];
- sig2 = regAttrPtr->attrbuf[2];
- sig3 = regAttrPtr->attrbuf[3];
- sig4 = regAttrPtr->attrbuf[4];
- sig5 = regAttrPtr->attrbuf[5];
- sig6 = regAttrPtr->attrbuf[6];
- sig7 = regAttrPtr->attrbuf[7];
- signal->theData[3] = sig0;
- signal->theData[4] = sig1;
- signal->theData[5] = sig2;
- signal->theData[6] = sig3;
- signal->theData[7] = sig4;
- signal->theData[8] = sig5;
- signal->theData[9] = sig6;
- signal->theData[10] = sig7;
- if (TdataPos > 8) {
- sig0 = regAttrPtr->attrbuf[8];
- sig1 = regAttrPtr->attrbuf[9];
- sig2 = regAttrPtr->attrbuf[10];
- sig3 = regAttrPtr->attrbuf[11];
- sig4 = regAttrPtr->attrbuf[12];
- sig5 = regAttrPtr->attrbuf[13];
- sig6 = regAttrPtr->attrbuf[14];
- jam();
- signal->theData[11] = sig0;
- signal->theData[12] = sig1;
- signal->theData[13] = sig2;
- signal->theData[14] = sig3;
- signal->theData[15] = sig4;
- signal->theData[16] = sig5;
- signal->theData[17] = sig6;
- if (TdataPos > 15) {
- sig0 = regAttrPtr->attrbuf[15];
- sig1 = regAttrPtr->attrbuf[16];
- sig2 = regAttrPtr->attrbuf[17];
- sig3 = regAttrPtr->attrbuf[18];
- sig4 = regAttrPtr->attrbuf[19];
- sig5 = regAttrPtr->attrbuf[20];
- sig6 = regAttrPtr->attrbuf[21];
- jam();
- signal->theData[18] = sig0;
- signal->theData[19] = sig1;
- signal->theData[20] = sig2;
- signal->theData[21] = sig3;
- signal->theData[22] = sig4;
- signal->theData[23] = sig5;
- signal->theData[24] = sig6;
- }//if
- }//if
- sendSignal(TBref, GSN_ATTRINFO, signal, TdataPos + 3, JBB);
- }//Dbtc::sendAttrinfo()
- void Dbtc::sendContinueTimeOutControl(Signal* signal, Uint32 TapiConPtr)
- {
- signal->theData[0] = TcContinueB::ZCONTINUE_TIME_OUT_CONTROL;
- signal->theData[1] = TapiConPtr;
- sendSignal(cownref, GSN_CONTINUEB, signal, 2, JBB);
- }//Dbtc::sendContinueTimeOutControl()
- void Dbtc::sendKeyinfo(Signal* signal, BlockReference TBRef, Uint32 len)
- {
- signal->theData[0] = tcConnectptr.i;
- signal->theData[1] = apiConnectptr.p->transid[0];
- signal->theData[2] = apiConnectptr.p->transid[1];
- signal->theData[3] = cdata[0];
- signal->theData[4] = cdata[1];
- signal->theData[5] = cdata[2];
- signal->theData[6] = cdata[3];
- signal->theData[7] = cdata[4];
- signal->theData[8] = cdata[5];
- signal->theData[9] = cdata[6];
- signal->theData[10] = cdata[7];
- signal->theData[11] = cdata[8];
- signal->theData[12] = cdata[9];
- signal->theData[13] = cdata[10];
- signal->theData[14] = cdata[11];
- signal->theData[15] = cdata[12];
- signal->theData[16] = cdata[13];
- signal->theData[17] = cdata[14];
- signal->theData[18] = cdata[15];
- signal->theData[19] = cdata[16];
- signal->theData[20] = cdata[17];
- signal->theData[21] = cdata[18];
- signal->theData[22] = cdata[19];
- sendSignal(TBRef, GSN_KEYINFO, signal, 3 + len, JBB);
- }//Dbtc::sendKeyinfo()
- void Dbtc::sendSystemError(Signal* signal)
- {
- progError(0, 0);
- }//Dbtc::sendSystemError()
- /* ========================================================================= */
- /* ------- LINK ACTUAL GCP OUT OF LIST ------- */
- /* ------------------------------------------------------------------------- */
- void Dbtc::unlinkGcp(Signal* signal)
- {
- if (cfirstgcp == gcpPtr.i) {
- jam();
- cfirstgcp = gcpPtr.p->nextGcp;
- if (gcpPtr.i == clastgcp) {
- jam();
- clastgcp = RNIL;
- }//if
- } else {
- jam();
- /* --------------------------------------------------------------------
- * WE ARE TRYING TO REMOVE A GLOBAL CHECKPOINT WHICH WAS NOT THE OLDEST.
- * THIS IS A SYSTEM ERROR.
- * ------------------------------------------------------------------- */
- sendSystemError(signal);
- }//if
- gcpPtr.p->nextGcp = cfirstfreeGcp;
- cfirstfreeGcp = gcpPtr.i;
- }//Dbtc::unlinkGcp()
- void
- Dbtc::execDUMP_STATE_ORD(Signal* signal)
- {
- DumpStateOrd * const dumpState = (DumpStateOrd *)&signal->theData[0];
- if(signal->theData[0] == DumpStateOrd::CommitAckMarkersSize){
- infoEvent("TC: m_commitAckMarkerPool: %d free size: %d",
- m_commitAckMarkerPool.getNoOfFree(),
- m_commitAckMarkerPool.getSize());
- }
- if(signal->theData[0] == DumpStateOrd::CommitAckMarkersDump){
- infoEvent("TC: m_commitAckMarkerPool: %d free size: %d",
- m_commitAckMarkerPool.getNoOfFree(),
- m_commitAckMarkerPool.getSize());
-
- CommitAckMarkerIterator iter;
- for(m_commitAckMarkerHash.first(iter); iter.curr.i != RNIL;
- m_commitAckMarkerHash.next(iter)){
- infoEvent("CommitAckMarker: i = %d (0x%x, 0x%x)"
- " Api: %d Lghs(%d): %d %d %d %d bucket = %d",
- iter.curr.i,
- iter.curr.p->transid1,
- iter.curr.p->transid2,
- iter.curr.p->apiNodeId,
- iter.curr.p->noOfLqhs,
- iter.curr.p->lqhNodeId[0],
- iter.curr.p->lqhNodeId[1],
- iter.curr.p->lqhNodeId[2],
- iter.curr.p->lqhNodeId[3],
- iter.bucket);
- }
- }
- // Dump all ScanFragRecs
- if (dumpState->args[0] == DumpStateOrd::TcDumpAllScanFragRec){
- Uint32 recordNo = 0;
- if (signal->getLength() == 1)
- infoEvent("TC: Dump all ScanFragRec - size: %d",
- cscanFragrecFileSize);
- else if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
-
- dumpState->args[0] = DumpStateOrd::TcDumpOneScanFragRec;
- dumpState->args[1] = recordNo;
- execDUMP_STATE_ORD(signal);
- if (recordNo < cscanFragrecFileSize-1){
- dumpState->args[0] = DumpStateOrd::TcDumpAllScanFragRec;
- dumpState->args[1] = recordNo+1;
- sendSignal(reference(), GSN_DUMP_STATE_ORD, signal, 2, JBB);
- }
- }
- // Dump one ScanFragRec
- if (dumpState->args[0] == DumpStateOrd::TcDumpOneScanFragRec){
- Uint32 recordNo = RNIL;
- if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
- if (recordNo >= cscanFragrecFileSize)
- return;
- ScanFragRecPtr sfp;
- sfp.i = recordNo;
- c_scan_frag_pool.getPtr(sfp);
- infoEvent("Dbtc::ScanFragRec[%d]: state=%d fragid=%d",
- sfp.i,
- sfp.p->scanFragState,
- sfp.p->scanFragId);
- infoEvent(" nodeid=%d, timer=%d",
- refToNode(sfp.p->lqhBlockref),
- sfp.p->scanFragTimer);
- }
- // Dump all ScanRecords
- if (dumpState->args[0] == DumpStateOrd::TcDumpAllScanRec){
- Uint32 recordNo = 0;
- if (signal->getLength() == 1)
- infoEvent("TC: Dump all ScanRecord - size: %d",
- cscanrecFileSize);
- else if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
- dumpState->args[0] = DumpStateOrd::TcDumpOneScanRec;
- dumpState->args[1] = recordNo;
- execDUMP_STATE_ORD(signal);
-
- if (recordNo < cscanrecFileSize-1){
- dumpState->args[0] = DumpStateOrd::TcDumpAllScanRec;
- dumpState->args[1] = recordNo+1;
- sendSignal(reference(), GSN_DUMP_STATE_ORD, signal, 2, JBB);
- }
- }
- // Dump all active ScanRecords
- if (dumpState->args[0] == DumpStateOrd::TcDumpAllActiveScanRec){
- Uint32 recordNo = 0;
- if (signal->getLength() == 1)
- infoEvent("TC: Dump active ScanRecord - size: %d",
- cscanrecFileSize);
- else if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
- ScanRecordPtr sp;
- sp.i = recordNo;
- ptrAss(sp, scanRecord);
- if (sp.p->scanState != ScanRecord::IDLE){
- dumpState->args[0] = DumpStateOrd::TcDumpOneScanRec;
- dumpState->args[1] = recordNo;
- execDUMP_STATE_ORD(signal);
- }
- if (recordNo < cscanrecFileSize-1){
- dumpState->args[0] = DumpStateOrd::TcDumpAllActiveScanRec;
- dumpState->args[1] = recordNo+1;
- sendSignal(reference(), GSN_DUMP_STATE_ORD, signal, 2, JBB);
- }
- }
- // Dump one ScanRecord
- // and associated ScanFragRec and ApiConnectRecord
- if (dumpState->args[0] == DumpStateOrd::TcDumpOneScanRec){
- Uint32 recordNo = RNIL;
- if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
- if (recordNo >= cscanrecFileSize)
- return;
- ScanRecordPtr sp;
- sp.i = recordNo;
- ptrAss(sp, scanRecord);
- infoEvent("Dbtc::ScanRecord[%d]: state=%d"
- "nextfrag=%d, nofrag=%d",
- sp.i,
- sp.p->scanState,
- sp.p->scanNextFragId,
- sp.p->scanNoFrag);
- infoEvent(" ailen=%d, para=%d, receivedop=%d, noOprePperFrag=%d",
- sp.p->scanAiLength,
- sp.p->scanParallel,
- sp.p->scanReceivedOperations,
- sp.p->batch_size_rows);
- infoEvent(" schv=%d, tab=%d, sproc=%d",
- sp.p->scanSchemaVersion,
- sp.p->scanTableref,
- sp.p->scanStoredProcId);
- infoEvent(" apiRec=%d, next=%d",
- sp.p->scanApiRec, sp.p->nextScan);
- if (sp.p->scanState != ScanRecord::IDLE){
- // Request dump of ScanFragRec
- ScanFragRecPtr sfptr;
- #define DUMP_SFR(x){
- ScanFragList list(c_scan_frag_pool, x);
- for(list.first(sfptr); !sfptr.isNull(); list.next(sfptr)){
- dumpState->args[0] = DumpStateOrd::TcDumpOneScanFragRec;
- dumpState->args[1] = sfptr.i;
- execDUMP_STATE_ORD(signal);
- }}
- DUMP_SFR(sp.p->m_running_scan_frags);
- DUMP_SFR(sp.p->m_queued_scan_frags);
- DUMP_SFR(sp.p->m_delivered_scan_frags);
- // Request dump of ApiConnectRecord
- dumpState->args[0] = DumpStateOrd::TcDumpOneApiConnectRec;
- dumpState->args[1] = sp.p->scanApiRec;
- execDUMP_STATE_ORD(signal);
- }
- }
- // Dump all ApiConnectRecord(s)
- if (dumpState->args[0] == DumpStateOrd::TcDumpAllApiConnectRec){
- Uint32 recordNo = 0;
- if (signal->getLength() == 1)
- infoEvent("TC: Dump all ApiConnectRecord - size: %d",
- capiConnectFilesize);
- else if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
- dumpState->args[0] = DumpStateOrd::TcDumpOneApiConnectRec;
- dumpState->args[1] = recordNo;
- execDUMP_STATE_ORD(signal);
-
- if (recordNo < capiConnectFilesize-1){
- dumpState->args[0] = DumpStateOrd::TcDumpAllApiConnectRec;
- dumpState->args[1] = recordNo+1;
- sendSignal(reference(), GSN_DUMP_STATE_ORD, signal, 2, JBB);
- }
- }
- // Dump one ApiConnectRecord
- if (dumpState->args[0] == DumpStateOrd::TcDumpOneApiConnectRec){
- Uint32 recordNo = RNIL;
- if (signal->getLength() == 2)
- recordNo = dumpState->args[1];
- else
- return;
- if (recordNo >= capiConnectFilesize)
- return;
- ApiConnectRecordPtr ap;
- ap.i = recordNo;
- ptrAss(ap, apiConnectRecord);
- infoEvent("Dbtc::ApiConnectRecord[%d]: state=%d, abortState=%d, "
- "apiFailState=%d",
- ap.i,
- ap.p->apiConnectstate,
- ap.p->abortState,
- ap.p->apiFailState);
- infoEvent(" transid(0x%x, 0x%x), apiBref=0x%x, scanRec=%d",
- ap.p->transid[0],
- ap.p->transid[1],
- ap.p->ndbapiBlockref,
- ap.p->apiScanRec);
- infoEvent(" ctcTimer=%d, apiTimer=%d, counter=%d, retcode=%d, "
- "retsig=%d",
- ctcTimer, getApiConTimer(ap.i),
- ap.p->counter,
- ap.p->returncode,
- ap.p->returnsignal);
- infoEvent(" lqhkeyconfrec=%d, lqhkeyreqrec=%d, "
- "tckeyrec=%d",
- ap.p->lqhkeyconfrec,
- ap.p->lqhkeyreqrec,
- ap.p->tckeyrec);
- infoEvent(" next=%d ",
- ap.p->nextApiConnect);
- }
- if (dumpState->args[0] == DumpStateOrd::TcSetTransactionTimeout){
- jam();
- if(signal->getLength() > 1){
- set_timeout_value(signal->theData[1]);
- }
- }
- if (dumpState->args[0] == DumpStateOrd::TcSetApplTransactionTimeout){
- jam();
- if(signal->getLength() > 1){
- set_appl_timeout_value(signal->theData[1]);
- }
- }
- if (dumpState->args[0] == DumpStateOrd::StartTcTimer){
- c_counters.c_trans_status = TransCounters::Started;
- c_counters.reset();
- }
- if (dumpState->args[0] == DumpStateOrd::StopTcTimer){
- c_counters.c_trans_status = TransCounters::Off;
- Uint32 len = c_counters.report(signal);
- sendSignal(CMVMI_REF, GSN_EVENT_REP, signal, len, JBB);
- c_counters.reset();
- }
-
- if (dumpState->args[0] == DumpStateOrd::StartPeriodicTcTimer){
- c_counters.c_trans_status = TransCounters::Timer;
- c_counters.reset();
- signal->theData[0] = TcContinueB::ZTRANS_EVENT_REP;
- sendSignalWithDelay(cownref, GSN_CONTINUEB, signal, 5000, 1);
- }
- if (dumpState->args[0] == DumpStateOrd::TcStartDumpIndexOpCount)
- {
- static int frequency = 1;
- if (signal->getLength() > 1)
- frequency = signal->theData[1];
- else
- if (refToBlock(signal->getSendersBlockRef()) != DBTC)
- frequency = 1;
-
- if (frequency)
- {
- dumpState->args[0] = DumpStateOrd::TcDumpIndexOpCount;
- execDUMP_STATE_ORD(signal);
- dumpState->args[0] = DumpStateOrd::TcStartDumpIndexOpCount;
-
- Uint32 delay = 1000 * (frequency > 25 ? 25 : frequency);
- sendSignalWithDelay(cownref, GSN_DUMP_STATE_ORD, signal, delay, 1);
- }
- }
-
- if (dumpState->args[0] == DumpStateOrd::TcDumpIndexOpCount)
- {
- infoEvent("IndexOpCount: pool: %d free: %d",
- c_theIndexOperationPool.getSize(),
- c_theIndexOperationPool.getNoOfFree());
- }
- }//Dbtc::execDUMP_STATE_ORD()
- void Dbtc::execSET_VAR_REQ(Signal* signal)
- {
- #if 0
- SetVarReq* const setVarReq = (SetVarReq*)&signal->theData[0];
- ConfigParamId var = setVarReq->variable();
- int val = setVarReq->value();
- switch (var) {
- case TransactionInactiveTime:
- jam();
- set_appl_timeout_value(val);
- break;
- case TransactionDeadlockDetectionTimeout:
- set_timeout_value(val);
- sendSignal(CMVMI_REF, GSN_SET_VAR_CONF, signal, 1, JBB);
- break;
- case NoOfConcurrentProcessesHandleTakeover:
- set_no_parallel_takeover(val);
- sendSignal(CMVMI_REF, GSN_SET_VAR_CONF, signal, 1, JBB);
- break;
- default:
- sendSignal(CMVMI_REF, GSN_SET_VAR_REF, signal, 1, JBB);
- } // switch
- #endif
- }
- void Dbtc::execABORT_ALL_REQ(Signal* signal)
- {
- jamEntry();
- AbortAllReq * req = (AbortAllReq*)&signal->theData[0];
- AbortAllRef * ref = (AbortAllRef*)&signal->theData[0];
-
- const Uint32 senderData = req->senderData;
- const BlockReference senderRef = req->senderRef;
-
- if(getAllowStartTransaction() == true && !getNodeState().getSingleUserMode()){
- jam();
- ref->senderData = senderData;
- ref->errorCode = AbortAllRef::InvalidState;
- sendSignal(senderRef, GSN_ABORT_ALL_REF, signal,
- AbortAllRef::SignalLength, JBB);
- return;
- }
-
- if(c_abortRec.clientRef != 0){
- jam();
-
- ref->senderData = senderData;
- ref->errorCode = AbortAllRef::AbortAlreadyInProgress;
- sendSignal(senderRef, GSN_ABORT_ALL_REF, signal,
- AbortAllRef::SignalLength, JBB);
- return;
- }
- if(refToNode(senderRef) != getOwnNodeId()){
- jam();
-
- ref->senderData = senderData;
- ref->errorCode = AbortAllRef::FunctionNotImplemented;
- sendSignal(senderRef, GSN_ABORT_ALL_REF, signal,
- AbortAllRef::SignalLength, JBB);
- return;
- }
- c_abortRec.clientRef = senderRef;
- c_abortRec.clientData = senderData;
- c_abortRec.oldTimeOutValue = ctimeOutValue;
-
- ctimeOutValue = 0;
- const Uint32 sleepTime = (2 * 10 * ctimeOutCheckDelay + 199) / 200;
-
- checkAbortAllTimeout(signal, (sleepTime == 0 ? 1 : sleepTime));
- }
- void Dbtc::checkAbortAllTimeout(Signal* signal, Uint32 sleepTime)
- {
-
- ndbrequire(c_abortRec.clientRef != 0);
-
- if(sleepTime > 0){
- jam();
-
- sleepTime -= 1;
- signal->theData[0] = TcContinueB::ZWAIT_ABORT_ALL;
- signal->theData[1] = sleepTime;
- sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 200, 2);
- return;
- }
- AbortAllConf * conf = (AbortAllConf*)&signal->theData[0];
- conf->senderData = c_abortRec.clientData;
- sendSignal(c_abortRec.clientRef, GSN_ABORT_ALL_CONF, signal,
- AbortAllConf::SignalLength, JBB);
-
- ctimeOutValue = c_abortRec.oldTimeOutValue;
- c_abortRec.clientRef = 0;
- }
- /* **************************************************************** */
- /* ---------------------------------------------------------------- */
- /* ------------------ TRIGGER AND INDEX HANDLING ------------------ */
- /* ---------------------------------------------------------------- */
- /* **************************************************************** */
- void Dbtc::execCREATE_TRIG_REQ(Signal* signal)
- {
- jamEntry();
- CreateTrigReq * const createTrigReq =
- (CreateTrigReq *)&signal->theData[0];
- TcDefinedTriggerData* triggerData;
- DefinedTriggerPtr triggerPtr;
- BlockReference sender = signal->senderBlockRef();
- releaseSections(signal);
-
- triggerPtr.i = createTrigReq->getTriggerId();
- if (ERROR_INSERTED(8033) ||
- !c_theDefinedTriggers.seizeId(triggerPtr,
- createTrigReq->getTriggerId())) {
- jam();
- CLEAR_ERROR_INSERT_VALUE;
- // Failed to allocate trigger record
- CreateTrigRef * const createTrigRef =
- (CreateTrigRef *)&signal->theData[0];
-
- createTrigRef->setConnectionPtr(createTrigReq->getConnectionPtr());
- createTrigRef->setErrorCode(CreateTrigRef::TooManyTriggers);
- sendSignal(sender, GSN_CREATE_TRIG_REF,
- signal, CreateTrigRef::SignalLength, JBB);
- return;
- }
- triggerData = triggerPtr.p;
- triggerData->triggerId = createTrigReq->getTriggerId();
- triggerData->triggerType = createTrigReq->getTriggerType();
- triggerData->triggerEvent = createTrigReq->getTriggerEvent();
- triggerData->attributeMask = createTrigReq->getAttributeMask();
- if (triggerData->triggerType == TriggerType::SECONDARY_INDEX)
- triggerData->indexId = createTrigReq->getIndexId();
- CreateTrigConf * const createTrigConf =
- (CreateTrigConf *)&signal->theData[0];
-
- createTrigConf->setConnectionPtr(createTrigReq->getConnectionPtr());
- sendSignal(sender, GSN_CREATE_TRIG_CONF,
- signal, CreateTrigConf::SignalLength, JBB);
- }
- void Dbtc::execDROP_TRIG_REQ(Signal* signal)
- {
- jamEntry();
- DropTrigReq * const dropTrigReq = (DropTrigReq *)&signal->theData[0];
- BlockReference sender = signal->senderBlockRef();
- if (ERROR_INSERTED(8035) ||
- (c_theDefinedTriggers.getPtr(dropTrigReq->getTriggerId())) == NULL) {
- jam();
- CLEAR_ERROR_INSERT_VALUE;
- // Failed to find find trigger record
- DropTrigRef * const dropTrigRef = (DropTrigRef *)&signal->theData[0];
- dropTrigRef->setConnectionPtr(dropTrigReq->getConnectionPtr());
- dropTrigRef->setErrorCode(DropTrigRef::TriggerNotFound);
- sendSignal(sender, GSN_DROP_TRIG_REF,
- signal, DropTrigRef::SignalLength, JBB);
- return;
- }
- // Release trigger record
- c_theDefinedTriggers.release(dropTrigReq->getTriggerId());
- DropTrigConf * const dropTrigConf = (DropTrigConf *)&signal->theData[0];
-
- dropTrigConf->setConnectionPtr(dropTrigReq->getConnectionPtr());
- sendSignal(sender, GSN_DROP_TRIG_CONF,
- signal, DropTrigConf::SignalLength, JBB);
- }
- void Dbtc::execCREATE_INDX_REQ(Signal* signal)
- {
- jamEntry();
- CreateIndxReq * const createIndxReq =
- (CreateIndxReq *)signal->getDataPtr();
- TcIndexData* indexData;
- TcIndexDataPtr indexPtr;
- BlockReference sender = signal->senderBlockRef();
-
- if (ERROR_INSERTED(8034) ||
- !c_theIndexes.seizeId(indexPtr, createIndxReq->getIndexId())) {
- jam();
- CLEAR_ERROR_INSERT_VALUE;
- // Failed to allocate index record
- CreateIndxRef * const createIndxRef =
- (CreateIndxRef *)&signal->theData[0];
- createIndxRef->setConnectionPtr(createIndxReq->getConnectionPtr());
- createIndxRef->setErrorCode(CreateIndxRef::TooManyIndexes);
- releaseSections(signal);
- sendSignal(sender, GSN_CREATE_INDX_REF,
- signal, CreateIndxRef::SignalLength, JBB);
- return;
- }
- indexData = indexPtr.p;
- // Indexes always start in state IS_BUILDING
- // Will become IS_ONLINE in execALTER_INDX_REQ
- indexData->indexState = IS_BUILDING;
- indexData->indexId = indexPtr.i;
- indexData->primaryTableId = createIndxReq->getTableId();
- // So far need only attribute count
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr, CreateIndxReq::ATTRIBUTE_LIST_SECTION);
- SimplePropertiesSectionReader r0(ssPtr, getSectionSegmentPool());
- r0.reset(); // undo implicit first()
- if (!r0.getWord(&indexData->attributeList.sz) ||
- !r0.getWords(indexData->attributeList.id, indexData->attributeList.sz)) {
- ndbrequire(false);
- }
- indexData->primaryKeyPos = indexData->attributeList.sz;
- releaseSections(signal);
-
- CreateIndxConf * const createIndxConf =
- (CreateIndxConf *)&signal->theData[0];
- createIndxConf->setConnectionPtr(createIndxReq->getConnectionPtr());
- createIndxConf->setTableId(createIndxReq->getTableId());
- createIndxConf->setIndexId(createIndxReq->getIndexId());
- sendSignal(sender, GSN_CREATE_INDX_CONF,
- signal, CreateIndxConf::SignalLength, JBB);
- }
- void Dbtc::execALTER_INDX_REQ(Signal* signal)
- {
- jamEntry();
- AlterIndxReq * const alterIndxReq = (AlterIndxReq *)signal->getDataPtr();
- TcIndexData* indexData;
- //BlockReference sender = signal->senderBlockRef();
- BlockReference sender = (BlockReference) alterIndxReq->getUserRef();
- Uint32 connectionPtr = alterIndxReq->getConnectionPtr();
- AlterIndxReq::RequestType requestType = alterIndxReq->getRequestType();
- Uint32 tableId = alterIndxReq->getTableId();
- Uint32 indexId = alterIndxReq->getIndexId();
- bool online = (alterIndxReq->getOnline() == 1) ? true : false;
- if ((indexData = c_theIndexes.getPtr(indexId)) == NULL) {
- jam();
- // Failed to find index record
- AlterIndxRef * const alterIndxRef =
- (AlterIndxRef *)signal->getDataPtrSend();
-
- alterIndxRef->setUserRef(reference());
- alterIndxRef->setConnectionPtr(connectionPtr);
- alterIndxRef->setRequestType(requestType);
- alterIndxRef->setTableId(tableId);
- alterIndxRef->setIndexId(indexId);
- alterIndxRef->setErrorCode(AlterIndxRef::IndexNotFound);
- alterIndxRef->setErrorLine(__LINE__);
- alterIndxRef->setErrorNode(getOwnNodeId());
- sendSignal(sender, GSN_ALTER_INDX_REF,
- signal, AlterIndxRef::SignalLength, JBB);
- return;
- }
- // Found index record, alter it's state
- if (online) {
- jam();
- indexData->indexState = IS_ONLINE;
- } else {
- jam();
- indexData->indexState = IS_BUILDING;
- }//if
- AlterIndxConf * const alterIndxConf =
- (AlterIndxConf *)signal->getDataPtrSend();
-
- alterIndxConf->setUserRef(reference());
- alterIndxConf->setConnectionPtr(connectionPtr);
- alterIndxConf->setRequestType(requestType);
- alterIndxConf->setTableId(tableId);
- alterIndxConf->setIndexId(indexId);
- sendSignal(sender, GSN_ALTER_INDX_CONF,
- signal, AlterIndxConf::SignalLength, JBB);
- }
- void Dbtc::execFIRE_TRIG_ORD(Signal* signal)
- {
- jamEntry();
- FireTrigOrd * const fireOrd = (FireTrigOrd *)signal->getDataPtr();
- ApiConnectRecord *localApiConnectRecord = apiConnectRecord;
- ApiConnectRecordPtr transPtr;
- TcConnectRecord *localTcConnectRecord = tcConnectRecord;
- TcConnectRecordPtr opPtr;
- /**
- * TODO
- * Check transid,
- * Fix overload i.e invalid word count
- */
- TcFiredTriggerData key;
- key.fireingOperation = fireOrd->getConnectionPtr();
- key.nodeId = refToNode(signal->getSendersBlockRef());
- FiredTriggerPtr trigPtr;
- if(c_firedTriggerHash.find(trigPtr, key)){
-
- c_firedTriggerHash.remove(trigPtr);
- bool ok = trigPtr.p->keyValues.getSize() == fireOrd->m_noPrimKeyWords;
- ok &= trigPtr.p->afterValues.getSize() == fireOrd->m_noAfterValueWords;
- ok &= trigPtr.p->beforeValues.getSize() == fireOrd->m_noBeforeValueWords;
- if(ok){
- opPtr.i = key.fireingOperation;
- ptrCheckGuard(opPtr, ctcConnectFilesize, localTcConnectRecord);
- transPtr.i = opPtr.p->apiConnect;
- transPtr.p = &localApiConnectRecord[transPtr.i];
-
- opPtr.p->noReceivedTriggers++;
- opPtr.p->triggerExecutionCount++;
-
- // Insert fired trigger in execution queue
- transPtr.p->theFiredTriggers.add(trigPtr);
- if (opPtr.p->noReceivedTriggers == opPtr.p->noFiredTriggers) {
- executeTriggers(signal, &transPtr);
- }
- return;
- }
- jam();
- c_theFiredTriggerPool.release(trigPtr);
- }
- jam();
- /**
- * Failed to find record or invalid word counts
- */
- ndbrequire(false);
- }
- void Dbtc::execTRIG_ATTRINFO(Signal* signal)
- {
- jamEntry();
- TrigAttrInfo * const trigAttrInfo = (TrigAttrInfo *)signal->getDataPtr();
- Uint32 attrInfoLength = signal->getLength() - TrigAttrInfo::StaticLength;
- const Uint32 *src = trigAttrInfo->getData();
- FiredTriggerPtr firedTrigPtr;
-
- TcFiredTriggerData key;
- key.fireingOperation = trigAttrInfo->getConnectionPtr();
- key.nodeId = refToNode(signal->getSendersBlockRef());
- if(!c_firedTriggerHash.find(firedTrigPtr, key)){
- jam();
- if(!c_firedTriggerHash.seize(firedTrigPtr)){
- jam();
- /**
- * Will be handled when FIRE_TRIG_ORD arrives
- */
- ndbout_c("op: %d node: %d failed to seize",
- key.fireingOperation, key.nodeId);
- return;
- }
- ndbrequire(firedTrigPtr.p->keyValues.getSize() == 0 &&
- firedTrigPtr.p->beforeValues.getSize() == 0 &&
- firedTrigPtr.p->afterValues.getSize() == 0);
-
- firedTrigPtr.p->nodeId = refToNode(signal->getSendersBlockRef());
- firedTrigPtr.p->fireingOperation = key.fireingOperation;
- firedTrigPtr.p->triggerId = trigAttrInfo->getTriggerId();
- c_firedTriggerHash.add(firedTrigPtr);
- }
-
- AttributeBuffer::DataBufferPool & pool = c_theAttributeBufferPool;
- switch (trigAttrInfo->getAttrInfoType()) {
- case(TrigAttrInfo::PRIMARY_KEY):
- jam();
- {
- LocalDataBuffer<11> buf(pool, firedTrigPtr.p->keyValues);
- buf.append(src, attrInfoLength);
- }
- break;
- case(TrigAttrInfo::BEFORE_VALUES):
- jam();
- {
- LocalDataBuffer<11> buf(pool, firedTrigPtr.p->beforeValues);
- buf.append(src, attrInfoLength);
- }
- break;
- case(TrigAttrInfo::AFTER_VALUES):
- jam();
- {
- LocalDataBuffer<11> buf(pool, firedTrigPtr.p->afterValues);
- buf.append(src, attrInfoLength);
- }
- break;
- default:
- ndbrequire(false);
- }
- }
- void Dbtc::execDROP_INDX_REQ(Signal* signal)
- {
- jamEntry();
- DropIndxReq * const dropIndxReq = (DropIndxReq *)signal->getDataPtr();
- TcIndexData* indexData;
- BlockReference sender = signal->senderBlockRef();
-
- if (ERROR_INSERTED(8036) ||
- (indexData = c_theIndexes.getPtr(dropIndxReq->getIndexId())) == NULL) {
- jam();
- CLEAR_ERROR_INSERT_VALUE;
- // Failed to find index record
- DropIndxRef * const dropIndxRef =
- (DropIndxRef *)signal->getDataPtrSend();
- dropIndxRef->setConnectionPtr(dropIndxReq->getConnectionPtr());
- dropIndxRef->setErrorCode(DropIndxRef::IndexNotFound);
- sendSignal(sender, GSN_DROP_INDX_REF,
- signal, DropIndxRef::SignalLength, JBB);
- return;
- }
- // Release index record
- c_theIndexes.release(dropIndxReq->getIndexId());
- DropIndxConf * const dropIndxConf =
- (DropIndxConf *)signal->getDataPtrSend();
- dropIndxConf->setConnectionPtr(dropIndxReq->getConnectionPtr());
- sendSignal(sender, GSN_DROP_INDX_CONF,
- signal, DropIndxConf::SignalLength, JBB);
- }
- void Dbtc::execTCINDXREQ(Signal* signal)
- {
- jamEntry();
- TcIndxReq * const tcIndxReq = (TcIndxReq *)signal->getDataPtr();
- const UintR TapiIndex = tcIndxReq->apiConnectPtr;
- Uint32 tcIndxRequestInfo = tcIndxReq->requestInfo;
- Uint32 startFlag = tcIndxReq->getStartFlag(tcIndxRequestInfo);
- Uint32 * dataPtr = &tcIndxReq->scanInfo;
- Uint32 indexBufSize = 8; // Maximum for index in TCINDXREQ
- Uint32 attrBufSize = 5; // Maximum for attrInfo in TCINDXREQ
- ApiConnectRecordPtr transPtr;
- transPtr.i = TapiIndex;
- if (transPtr.i >= capiConnectFilesize) {
- jam();
- warningHandlerLab(signal);
- return;
- }//if
- ptrAss(transPtr, apiConnectRecord);
- ApiConnectRecord * const regApiPtr = transPtr.p;
- // Seize index operation
- TcIndexOperationPtr indexOpPtr;
- if ((startFlag == 1) &&
- (regApiPtr->apiConnectstate == CS_CONNECTED ||
- (regApiPtr->apiConnectstate == CS_STARTED &&
- regApiPtr->firstTcConnect == RNIL)) ||
- (regApiPtr->apiConnectstate == CS_ABORTING &&
- regApiPtr->abortState == AS_IDLE)) {
- jam();
- // This is a newly started transaction, clean-up
- releaseAllSeizedIndexOperations(regApiPtr);
- regApiPtr->transid[0] = tcIndxReq->transId1;
- regApiPtr->transid[1] = tcIndxReq->transId2;
- }//if
- if (ERROR_INSERTED(8036) || !seizeIndexOperation(regApiPtr, indexOpPtr)) {
- jam();
- // Failed to allocate index operation
- terrorCode = 288;
- regApiPtr->m_exec_flag |= TcKeyReq::getExecuteFlag(tcIndxRequestInfo);
- apiConnectptr = transPtr;
- abortErrorLab(signal);
- return;
- }
- TcIndexOperation* indexOp = indexOpPtr.p;
- indexOp->indexOpId = indexOpPtr.i;
- // Save original signal
- indexOp->tcIndxReq = *tcIndxReq;
- indexOp->connectionIndex = TapiIndex;
- regApiPtr->accumulatingIndexOp = indexOp->indexOpId;
- // If operation is readTupleExclusive or updateTuple then read index
- // table with exclusive lock
- Uint32 indexLength = TcIndxReq::getIndexLength(tcIndxRequestInfo);
- Uint32 attrLength = tcIndxReq->attrLen;
- indexOp->expectedKeyInfo = indexLength;
- Uint32 includedIndexLength = MIN(indexLength, indexBufSize);
- indexOp->expectedAttrInfo = attrLength;
- Uint32 includedAttrLength = MIN(attrLength, attrBufSize);
- if (saveINDXKEYINFO(signal,
- indexOp,
- dataPtr,
- includedIndexLength)) {
- jam();
- // We have received all we need
- readIndexTable(signal, regApiPtr, indexOp);
- return;
- }
- dataPtr += includedIndexLength;
- if (saveINDXATTRINFO(signal,
- indexOp,
- dataPtr,
- includedAttrLength)) {
- jam();
- // We have received all we need
- readIndexTable(signal, regApiPtr, indexOp);
- return;
- }
- }
- void Dbtc::sendTcIndxConf(Signal* signal, UintR TcommitFlag)
- {
- HostRecordPtr localHostptr;
- ApiConnectRecord * const regApiPtr = apiConnectptr.p;
- const UintR TopWords = (UintR)regApiPtr->tcindxrec;
- localHostptr.i = refToNode(regApiPtr->ndbapiBlockref);
- const Uint32 type = getNodeInfo(localHostptr.i).m_type;
- const bool is_api = (type >= NodeInfo::API && type <= NodeInfo::REP);
- const BlockNumber TblockNum = refToBlock(regApiPtr->ndbapiBlockref);
- const Uint32 Tmarker = (regApiPtr->commitAckMarker == RNIL ? 0 : 1);
- ptrAss(localHostptr, hostRecord);
- UintR TcurrLen = localHostptr.p->noOfWordsTCINDXCONF;
- UintR confInfo = 0;
- TcIndxConf::setNoOfOperations(confInfo, (TopWords >> 1));
- TcIndxConf::setCommitFlag(confInfo, TcommitFlag == 1);
- TcIndxConf::setMarkerFlag(confInfo, Tmarker);
- const UintR TpacketLen = 6 + TopWords;
- regApiPtr->tcindxrec = 0;
- if(TcommitFlag || (regApiPtr->lqhkeyreqrec == regApiPtr->lqhkeyconfrec)){
- jam();
- regApiPtr->m_exec_flag = 0;
- }
- if ((TpacketLen > 25) || !is_api){
- TcIndxConf * const tcIndxConf = (TcIndxConf *)signal->getDataPtrSend();
-
- jam();
- tcIndxConf->apiConnectPtr = regApiPtr->ndbapiConnect;
- tcIndxConf->gci = regApiPtr->globalcheckpointid;;
- tcIndxConf->confInfo = confInfo;
- tcIndxConf->transId1 = regApiPtr->transid[0];
- tcIndxConf->transId2 = regApiPtr->transid[1];
- copyFromToLen(®ApiPtr->tcIndxSendArray[0],
- (UintR*)&tcIndxConf->operations,
- (UintR)ZTCOPCONF_SIZE);
- sendSignal(regApiPtr->ndbapiBlockref,
- GSN_TCINDXCONF, signal, (TpacketLen - 1), JBB);
- return;
- } else if (((TcurrLen + TpacketLen) > 25) && (TcurrLen > 0)) {
- jam();
- sendPackedTCINDXCONF(signal, localHostptr.p, localHostptr.i);
- TcurrLen = 0;
- } else {
- jam();
- updatePackedList(signal, localHostptr.p, localHostptr.i);
- }//if
- // -------------------------------------------------------------------------
- // The header contains the block reference of receiver plus the real signal
- // length - 3, since we have the real signal length plus one additional word
- // for the header we have to do - 4.
- // -------------------------------------------------------------------------
- UintR Tpack0 = (TblockNum << 16) + (TpacketLen - 4);
- UintR Tpack1 = regApiPtr->ndbapiConnect;
- UintR Tpack2 = regApiPtr->globalcheckpointid;
- UintR Tpack3 = confInfo;
- UintR Tpack4 = regApiPtr->transid[0];
- UintR Tpack5 = regApiPtr->transid[1];
- localHostptr.p->noOfWordsTCINDXCONF = TcurrLen + TpacketLen;
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 0] = Tpack0;
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 1] = Tpack1;
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 2] = Tpack2;
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 3] = Tpack3;
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 4] = Tpack4;
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 5] = Tpack5;
- UintR Ti;
- for (Ti = 6; Ti < TpacketLen; Ti++) {
- localHostptr.p->packedWordsTCINDXCONF[TcurrLen + Ti] =
- regApiPtr->tcIndxSendArray[Ti - 6];
- }//for
- }//Dbtc::sendTcIndxConf()
- void Dbtc::execINDXKEYINFO(Signal* signal)
- {
- jamEntry();
- Uint32 keyInfoLength = signal->getLength() - IndxKeyInfo::HeaderLength;
- IndxKeyInfo * const indxKeyInfo = (IndxKeyInfo *)signal->getDataPtr();
- const Uint32 *src = indxKeyInfo->getData();
- const UintR TconnectIndex = indxKeyInfo->connectPtr;
- ApiConnectRecordPtr transPtr;
- transPtr.i = TconnectIndex;
- if (transPtr.i >= capiConnectFilesize) {
- jam();
- warningHandlerLab(signal);
- return;
- }//if
- ptrAss(transPtr, apiConnectRecord);
- ApiConnectRecord * const regApiPtr = transPtr.p;
- TcIndexOperationPtr indexOpPtr;
- TcIndexOperation* indexOp;
- if((indexOpPtr.i = regApiPtr->accumulatingIndexOp) != RNIL)
- {
- indexOp = c_theIndexOperationPool.getPtr(indexOpPtr.i);
- if (saveINDXKEYINFO(signal,
- indexOp,
- src,
- keyInfoLength)) {
- jam();
- // We have received all we need
- readIndexTable(signal, regApiPtr, indexOp);
- }
- }
- }
- void Dbtc::execINDXATTRINFO(Signal* signal)
- {
- jamEntry();
- Uint32 attrInfoLength = signal->getLength() - IndxAttrInfo::HeaderLength;
- IndxAttrInfo * const indxAttrInfo = (IndxAttrInfo *)signal->getDataPtr();
- const Uint32 *src = indxAttrInfo->getData();
- const UintR TconnectIndex = indxAttrInfo->connectPtr;
- ApiConnectRecordPtr transPtr;
- transPtr.i = TconnectIndex;
- if (transPtr.i >= capiConnectFilesize) {
- jam();
- warningHandlerLab(signal);
- return;
- }//if
- ptrAss(transPtr, apiConnectRecord);
- ApiConnectRecord * const regApiPtr = transPtr.p;
- TcIndexOperationPtr indexOpPtr;
- TcIndexOperation* indexOp;
- if((indexOpPtr.i = regApiPtr->accumulatingIndexOp) != RNIL)
- {
- indexOp = c_theIndexOperationPool.getPtr(indexOpPtr.i);
- if (saveINDXATTRINFO(signal,
- indexOp,
- src,
- attrInfoLength)) {
- jam();
- // We have received all we need
- readIndexTable(signal, regApiPtr, indexOp);
- }
- }
- }
- /**
- * Save signal INDXKEYINFO
- * Return true if we have received all needed data
- */
- bool Dbtc::saveINDXKEYINFO(Signal* signal,
- TcIndexOperation* indexOp,
- const Uint32 *src,
- Uint32 len)
- {
- if (!indexOp->keyInfo.append(src, len)) {
- jam();
- // Failed to seize keyInfo, abort transaction
- #ifdef VM_TRACE
- ndbout_c("Dbtc::saveINDXKEYINFO: Failed to seize keyinfon");
- #endif
- // Abort transaction
- apiConnectptr.i = indexOp->connectionIndex;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- releaseIndexOperation(apiConnectptr.p, indexOp);
- terrorCode = 4000;
- abortErrorLab(signal);
- return false;
- }
- if (receivedAllINDXKEYINFO(indexOp) && receivedAllINDXATTRINFO(indexOp)) {
- jam();
- return true;
- }
- return false;
- }
- bool Dbtc::receivedAllINDXKEYINFO(TcIndexOperation* indexOp)
- {
- return (indexOp->keyInfo.getSize() == indexOp->expectedKeyInfo);
- }
- /**
- * Save signal INDXATTRINFO
- * Return true if we have received all needed data
- */
- bool Dbtc::saveINDXATTRINFO(Signal* signal,
- TcIndexOperation* indexOp,
- const Uint32 *src,
- Uint32 len)
- {
- if (!indexOp->attrInfo.append(src, len)) {
- jam();
- #ifdef VM_TRACE
- ndbout_c("Dbtc::saveINDXATTRINFO: Failed to seize attrInfon");
- #endif
- apiConnectptr.i = indexOp->connectionIndex;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- releaseIndexOperation(apiConnectptr.p, indexOp);
- terrorCode = 4000;
- abortErrorLab(signal);
- return false;
- }
- if (receivedAllINDXKEYINFO(indexOp) && receivedAllINDXATTRINFO(indexOp)) {
- jam();
- return true;
- }
- return false;
- }
- bool Dbtc::receivedAllINDXATTRINFO(TcIndexOperation* indexOp)
- {
- return (indexOp->attrInfo.getSize() == indexOp->expectedAttrInfo);
- }
- bool Dbtc::saveTRANSID_AI(Signal* signal,
- TcIndexOperation* indexOp,
- const Uint32 *src,
- Uint32 len)
- {
- Uint32 currentTransIdAILength = indexOp->transIdAI.getSize();
-
- if (currentTransIdAILength == 0) {
- jam();
- // Read first AttributeHeader to get expected size
- // of the single key attribute expected
- AttributeHeader* head = (AttributeHeader *) src;
- indexOp->expectedTransIdAI = head->getHeaderSize() + head->getDataSize();
- }
- if (!indexOp->transIdAI.append(src, len)) {
- jam();
- #ifdef VM_TRACE
- ndbout_c("Dbtc::saveTRANSID_AI: Failed to seize transIdAIn");
- #endif
- apiConnectptr.i = indexOp->connectionIndex;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- releaseIndexOperation(apiConnectptr.p, indexOp);
- terrorCode = 4000;
- abortErrorLab(signal);
- return false;
- }
- return true;
- }
- bool Dbtc::receivedAllTRANSID_AI(TcIndexOperation* indexOp)
- {
- return (indexOp->transIdAI.getSize() == indexOp->expectedTransIdAI);
- }
- /**
- * Receive signal TCINDXCONF
- * This can be either the return of reading an index table
- * or performing an index operation
- */
- void Dbtc::execTCKEYCONF(Signal* signal)
- {
- TcKeyConf * const tcKeyConf = (TcKeyConf *)signal->getDataPtr();
- TcIndexOperationPtr indexOpPtr;
- jamEntry();
- indexOpPtr.i = tcKeyConf->apiConnectPtr;
- TcIndexOperation* indexOp = c_theIndexOperationPool.getPtr(indexOpPtr.i);
- Uint32 confInfo = tcKeyConf->confInfo;
- /**
- * Check on TCKEYCONF wheater the the transaction was committed
- */
- Uint32 Tcommit = TcKeyConf::getCommitFlag(confInfo);
- indexOpPtr.p = indexOp;
- if (!indexOp) {
- jam();
- // Missing index operation
- return;
- }
- const UintR TconnectIndex = indexOp->connectionIndex;
- ApiConnectRecord * const regApiPtr = &apiConnectRecord[TconnectIndex];
- apiConnectptr.p = regApiPtr;
- apiConnectptr.i = TconnectIndex;
- switch(indexOp->indexOpState) {
- case(IOS_NOOP): {
- jam();
- // Should never happen, abort
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4349;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- }
- case(IOS_INDEX_ACCESS): {
- jam();
- // Wait for TRANSID_AI
- indexOp->indexOpState = IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI;
- break;
- }
- case(IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI): {
- jam();
- // Double TCKEYCONF, should never happen, abort
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4349;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- }
- case(IOS_INDEX_ACCESS_WAIT_FOR_TCKEYCONF): {
- jam();
- // Continue with index operation
- executeIndexOperation(signal, regApiPtr, indexOp);
- break;
- }
- case(IOS_INDEX_OPERATION): {
- // We are done, send TCINDXCONF
- jam();
- Uint32 Ttcindxrec = regApiPtr->tcindxrec;
- // Copy reply from TcKeyConf
- ndbassert(regApiPtr->noIndexOp);
- regApiPtr->noIndexOp--; // Decrease count
- regApiPtr->tcIndxSendArray[Ttcindxrec] = indexOp->tcIndxReq.senderData;
- regApiPtr->tcIndxSendArray[Ttcindxrec + 1] =
- tcKeyConf->operations[0].attrInfoLen;
- regApiPtr->tcindxrec = Ttcindxrec + 2;
- if (regApiPtr->noIndexOp == 0) {
- jam();
- sendTcIndxConf(signal, Tcommit);
- } else if (regApiPtr->tcindxrec == ZTCOPCONF_SIZE) {
- jam();
- sendTcIndxConf(signal, 0);
- }
- releaseIndexOperation(regApiPtr, indexOp);
- break;
- }
- }
- }
- void Dbtc::execTCKEYREF(Signal* signal)
- {
- TcKeyRef * const tcKeyRef = (TcKeyRef *)signal->getDataPtr();
- TcIndexOperationPtr indexOpPtr;
- jamEntry();
- indexOpPtr.i = tcKeyRef->connectPtr;
- TcIndexOperation* indexOp = c_theIndexOperationPool.getPtr(indexOpPtr.i);
- indexOpPtr.p = indexOp;
- if (!indexOp) {
- jam();
- // Missing index operation
- return;
- }
- const UintR TconnectIndex = indexOp->connectionIndex;
- ApiConnectRecord * const regApiPtr = &apiConnectRecord[TconnectIndex];
- Uint32 tcKeyRequestInfo = indexOp->tcIndxReq.requestInfo;
- Uint32 commitFlg = TcKeyReq::getCommitFlag(tcKeyRequestInfo);
- switch(indexOp->indexOpState) {
- case(IOS_NOOP): {
- jam();
- // Should never happen, abort
- break;
- }
- case(IOS_INDEX_ACCESS):
- case(IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI):
- case(IOS_INDEX_ACCESS_WAIT_FOR_TCKEYCONF): {
- jam();
- // If we fail index access for a non-read operation during commit
- // we abort transaction
- if (commitFlg == 1) {
- jam();
- releaseIndexOperation(regApiPtr, indexOp);
- apiConnectptr.i = indexOp->connectionIndex;
- ptrCheckGuard(apiConnectptr, capiConnectFilesize, apiConnectRecord);
- terrorCode = tcKeyRef->errorCode;
- abortErrorLab(signal);
- break;
- }
- /**
- * Increase count as it will be decreased below...
- * (and the code is written to handle failing lookup on "real" table
- * not lookup on index table)
- */
- regApiPtr->noIndexOp++;
- // else continue
- }
- case(IOS_INDEX_OPERATION): {
- // Send TCINDXREF
-
- jam();
- TcIndxReq * const tcIndxReq = &indexOp->tcIndxReq;
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
-
- ndbassert(regApiPtr->noIndexOp);
- regApiPtr->noIndexOp--; // Decrease count
- tcIndxRef->connectPtr = tcIndxReq->senderData;
- tcIndxRef->transId[0] = tcKeyRef->transId[0];
- tcIndxRef->transId[1] = tcKeyRef->transId[1];
- tcIndxRef->errorCode = tcKeyRef->errorCode;
- sendSignal(regApiPtr->ndbapiBlockref,
- GSN_TCINDXREF, signal, TcIndxRef::SignalLength, JBB);
- return;
- }
- }
- }
- void Dbtc::execTRANSID_AI_R(Signal* signal){
- TransIdAI * const transIdAI = (TransIdAI *)signal->getDataPtr();
- Uint32 sigLen = signal->length();
- Uint32 dataLen = sigLen - TransIdAI::HeaderLength - 1;
- Uint32 recBlockref = transIdAI->attrData[dataLen];
- jamEntry();
- /**
- * Forward signal to final destination
- * Truncate last word since that was used to hold the final dest.
- */
- sendSignal(recBlockref, GSN_TRANSID_AI,
- signal, sigLen - 1, JBB);
- }
- void Dbtc::execKEYINFO20_R(Signal* signal){
- KeyInfo20 * const keyInfo = (KeyInfo20 *)signal->getDataPtr();
- Uint32 sigLen = signal->length();
- Uint32 dataLen = sigLen - KeyInfo20::HeaderLength - 1;
- Uint32 recBlockref = keyInfo->keyData[dataLen];
- jamEntry();
-
- /**
- * Forward signal to final destination
- * Truncate last word since that was used to hold the final dest.
- */
- sendSignal(recBlockref, GSN_KEYINFO20,
- signal, sigLen - 1, JBB);
- }
- void Dbtc::execTRANSID_AI(Signal* signal)
- {
- TransIdAI * const transIdAI = (TransIdAI *)signal->getDataPtr();
- jamEntry();
- TcIndexOperationPtr indexOpPtr;
- indexOpPtr.i = transIdAI->connectPtr;
- TcIndexOperation* indexOp = c_theIndexOperationPool.getPtr(indexOpPtr.i);
- indexOpPtr.p = indexOp;
- if (!indexOp) {
- jam();
- // Missing index operation
- }
- const UintR TconnectIndex = indexOp->connectionIndex;
- // ApiConnectRecord * const regApiPtr = &apiConnectRecord[TconnectIndex];
- ApiConnectRecordPtr transPtr;
-
- transPtr.i = TconnectIndex;
- ptrCheckGuard(transPtr, capiConnectFilesize, apiConnectRecord);
- ApiConnectRecord * const regApiPtr = transPtr.p;
- // Acccumulate attribute data
- if (!saveTRANSID_AI(signal,
- indexOp,
- transIdAI->getData(),
- signal->getLength() - TransIdAI::HeaderLength)) {
- jam();
- // Failed to allocate space for TransIdAI
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
-
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4000;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- }
- switch(indexOp->indexOpState) {
- case(IOS_NOOP): {
- jam();
- // Should never happen, abort
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
-
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4349;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- break;
- }
- case(IOS_INDEX_ACCESS): {
- jam();
- // Check if all TRANSID_AI have been received
- if (receivedAllTRANSID_AI(indexOp)) {
- jam();
- // Wait for TRANSID_AI
- indexOp->indexOpState = IOS_INDEX_ACCESS_WAIT_FOR_TCKEYCONF;
- }
- break;
- }
- case(IOS_INDEX_ACCESS_WAIT_FOR_TCKEYCONF): {
- jam();
- #ifdef VM_TRACE
- ndbout_c("Dbtc::execTRANSID_AI: Too many TRANSID_AI, ignore for nown");
- #endif
- /*
- // Too many TRANSID_AI
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
-
- tcIndexRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4349;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- */
- break;
- }
- case(IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI): {
- jam();
- // Check if all TRANSID_AI have been received
- if (receivedAllTRANSID_AI(indexOp)) {
- jam();
- // Continue with index operation
- executeIndexOperation(signal, regApiPtr, indexOp);
- }
- // else continue waiting for more TRANSID_AI
- break;
- }
- case(IOS_INDEX_OPERATION): {
- // Should never receive TRANSID_AI in this state!!
- jam();
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4349;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- }
- }
- }
- void Dbtc::execTCROLLBACKREP(Signal* signal)
- {
- TcRollbackRep* tcRollbackRep = (TcRollbackRep *)signal->getDataPtr();
- jamEntry();
- TcIndexOperationPtr indexOpPtr;
- indexOpPtr.i = tcRollbackRep->connectPtr;
- TcIndexOperation* indexOp = c_theIndexOperationPool.getPtr(indexOpPtr.i);
- indexOpPtr.p = indexOp;
- tcRollbackRep = (TcRollbackRep *)signal->getDataPtrSend();
- tcRollbackRep->connectPtr = indexOp->tcIndxReq.senderData;
- sendSignal(apiConnectptr.p->ndbapiBlockref,
- GSN_TCROLLBACKREP, signal, TcRollbackRep::SignalLength, JBB);
- }
- /**
- * Read index table with the index attributes as PK
- */
- void Dbtc::readIndexTable(Signal* signal,
- ApiConnectRecord* regApiPtr,
- TcIndexOperation* indexOp)
- {
- Uint32 keyBufSize = 8; // Maximum for key in TCKEYREQ
- Uint32 dataPos = 0;
- TcKeyReq * const tcKeyReq = (TcKeyReq *)signal->getDataPtrSend();
- Uint32 * dataPtr = &tcKeyReq->scanInfo;
- Uint32 tcKeyLength = TcKeyReq::StaticLength;
- Uint32 tcKeyRequestInfo = indexOp->tcIndxReq.requestInfo;
- AttributeBuffer::DataBufferIterator keyIter;
- Uint32 keyLength = TcKeyReq::getKeyLength(tcKeyRequestInfo);
- TcIndexData* indexData;
- Uint32 transId1 = indexOp->tcIndxReq.transId1;
- Uint32 transId2 = indexOp->tcIndxReq.transId2;
- const Operation_t opType =
- (Operation_t)TcKeyReq::getOperationType(tcKeyRequestInfo);
- // Find index table
- if ((indexData = c_theIndexes.getPtr(indexOp->tcIndxReq.indexId)) == NULL) {
- jam();
- // Failed to find index record
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4000;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- }
- tcKeyReq->transId1 = transId1;
- tcKeyReq->transId2 = transId2;
- tcKeyReq->tableId = indexData->indexId;
- tcKeyLength += MIN(keyLength, keyBufSize);
- tcKeyReq->tableSchemaVersion = indexOp->tcIndxReq.indexSchemaVersion;
- TcKeyReq::setOperationType(tcKeyRequestInfo,
- opType == ZREAD ? ZREAD : ZREAD_EX);
- TcKeyReq::setAIInTcKeyReq(tcKeyRequestInfo, 1); // Allways send one AttrInfo
- TcKeyReq::setExecutingTrigger(tcKeyRequestInfo, 0);
- BlockReference originalReceiver = regApiPtr->ndbapiBlockref;
- regApiPtr->ndbapiBlockref = reference(); // Send result to me
- tcKeyReq->senderData = indexOp->indexOpId;
- indexOp->indexOpState = IOS_INDEX_ACCESS;
- regApiPtr->executingIndexOp = regApiPtr->accumulatingIndexOp;
- regApiPtr->accumulatingIndexOp = RNIL;
- regApiPtr->isIndexOp = true;
- Uint32 remainingKey = indexOp->keyInfo.getSize();
- bool moreKeyData = indexOp->keyInfo.first(keyIter);
- // *********** KEYINFO in TCKEYREQ ***********
- while((dataPos < keyBufSize) &&
- (remainingKey-- != 0)) {
- *dataPtr++ = *keyIter.data;
- dataPos++;
- moreKeyData = indexOp->keyInfo.next(keyIter);
- }
- // *********** ATTRINFO in TCKEYREQ ***********
- tcKeyReq->attrLen = 1; // Primary key is stored as one attribute
- AttributeHeader::init(dataPtr, indexData->primaryKeyPos, 0);
- tcKeyLength++;
- tcKeyReq->requestInfo = tcKeyRequestInfo;
- ndbassert(TcKeyReq::getDirtyFlag(tcKeyRequestInfo) == 0);
- ndbassert(TcKeyReq::getSimpleFlag(tcKeyRequestInfo) == 0);
- EXECUTE_DIRECT(DBTC, GSN_TCKEYREQ, signal, tcKeyLength);
-
- /**
- * "Fool" TC not to start commiting transaction since it always will
- * have one outstanding lqhkeyreq
- * This is later decreased when the index read is complete
- */
- regApiPtr->lqhkeyreqrec++;
- /**
- * Remember ptr to index read operation
- * (used to set correct save point id on index operation later)
- */
- indexOp->indexReadTcConnect = regApiPtr->lastTcConnect;
- jamEntry();
- // *********** KEYINFO ***********
- if (moreKeyData) {
- jam();
- // Send KEYINFO sequence
- KeyInfo * const keyInfo = (KeyInfo *)signal->getDataPtrSend();
-
- keyInfo->connectPtr = indexOp->tcIndxReq.apiConnectPtr;
- keyInfo->transId[0] = transId1;
- keyInfo->transId[1] = transId2;
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- while(remainingKey-- != 0) {// If we have not read complete key
- *dataPtr++ = *keyIter.data;
- dataPos++;
- if (dataPos == KeyInfo::DataLength) {
- // Flush KEYINFO
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength);
- jamEntry();
- dataPos = 0;
- dataPtr = (Uint32 *) &keyInfo->keyData;
- }
- moreKeyData = indexOp->keyInfo.next(keyIter);
- }
- if (dataPos != 0) {
- // Flush last KEYINFO
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + dataPos);
- jamEntry();
- }
- }
-
- regApiPtr->ndbapiBlockref = originalReceiver; // reset original receiver
- }
- /**
- * Execute the index operation with the result from
- * the index table read as PK
- */
- void Dbtc::executeIndexOperation(Signal* signal,
- ApiConnectRecord* regApiPtr,
- TcIndexOperation* indexOp) {
-
- Uint32 keyBufSize = 8; // Maximum for key in TCKEYREQ
- Uint32 attrBufSize = 5;
- Uint32 dataPos = 0;
- TcIndxReq * const tcIndxReq = &indexOp->tcIndxReq;
- TcKeyReq * const tcKeyReq = (TcKeyReq *)signal->getDataPtrSend();
- Uint32 * dataPtr = &tcKeyReq->scanInfo;
- Uint32 tcKeyLength = TcKeyReq::StaticLength;
- Uint32 tcKeyRequestInfo = tcIndxReq->requestInfo;
- TcIndexData* indexData;
- AttributeBuffer::DataBufferIterator attrIter;
- AttributeBuffer::DataBufferIterator aiIter;
- bool moreKeyData = indexOp->transIdAI.first(aiIter);
-
- // Find index table
- if ((indexData = c_theIndexes.getPtr(tcIndxReq->indexId)) == NULL) {
- jam();
- // Failed to find index record
- TcIndxRef * const tcIndxRef = (TcIndxRef *)signal->getDataPtrSend();
- tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
- tcIndxRef->transId[0] = regApiPtr->transid[0];
- tcIndxRef->transId[1] = regApiPtr->transid[1];
- tcIndxRef->errorCode = 4349;
- sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal,
- TcIndxRef::SignalLength, JBB);
- return;
- }
- // Find schema version of primary table
- TableRecordPtr tabPtr;
- tabPtr.i = indexData->primaryTableId;
- ptrCheckGuard(tabPtr, ctabrecFilesize, tableRecord);
- tcKeyReq->apiConnectPtr = tcIndxReq->apiConnectPtr;
- tcKeyReq->attrLen = tcIndxReq->attrLen;
- tcKeyReq->tableId = indexData->primaryTableId;
- tcKeyReq->tableSchemaVersion = tabPtr.p->currentSchemaVersion;
- tcKeyReq->transId1 = regApiPtr->transid[0];
- tcKeyReq->transId2 = regApiPtr->transid[1];
- tcKeyReq->senderData = tcIndxReq->senderData; // Needed for TRANSID_AI to API
- indexOp->indexOpState = IOS_INDEX_OPERATION;
- regApiPtr->isIndexOp = true;
- regApiPtr->executingIndexOp = indexOp->indexOpId;;
- regApiPtr->noIndexOp++; // Increase count
- // Filter out AttributeHeader:s since this should not be in key
- AttributeHeader* attrHeader = (AttributeHeader *) aiIter.data;
-
- Uint32 headerSize = attrHeader->getHeaderSize();
- Uint32 keySize = attrHeader->getDataSize();
- TcKeyReq::setKeyLength(tcKeyRequestInfo, keySize);
- // Skip header
- if (headerSize == 1) {
- jam();
- moreKeyData = indexOp->transIdAI.next(aiIter);
- } else {
- jam();
- moreKeyData = indexOp->transIdAI.next(aiIter, headerSize - 1);
- }//if
- while(// If we have not read complete key
- (keySize != 0) &&
- (dataPos < keyBufSize)) {
- *dataPtr++ = *aiIter.data;
- dataPos++;
- keySize--;
- moreKeyData = indexOp->transIdAI.next(aiIter);
- }
- tcKeyLength += dataPos;
- Uint32 attributesLength = indexOp->attrInfo.getSize();
- if (attributesLength <= attrBufSize) {
- jam();
- // ATTRINFO fits in TCKEYREQ
- // Pack ATTRINFO IN TCKEYREQ
- TcKeyReq::setAIInTcKeyReq(tcKeyRequestInfo, indexOp->attrInfo.getSize());
- // Insert IndxAttrInfo
- for(bool moreAttrData = indexOp->attrInfo.first(attrIter);
- moreAttrData;
- moreAttrData = indexOp->attrInfo.next(attrIter)) {
- *dataPtr++ = *attrIter.data;
- }
- tcKeyLength += attributesLength;
- } else {
- jam();
- // No ATTRINFO in TCKEYREQ
- TcKeyReq::setAIInTcKeyReq(tcKeyRequestInfo, 0);
- }
- TcKeyReq::setCommitFlag(tcKeyRequestInfo, 0);
- TcKeyReq::setExecuteFlag(tcKeyRequestInfo, 0);
- TcKeyReq::setExecutingTrigger(tcKeyRequestInfo, 0);
- tcKeyReq->requestInfo = tcKeyRequestInfo;
- ndbassert(TcKeyReq::getDirtyFlag(tcKeyRequestInfo) == 0);
- ndbassert(TcKeyReq::getSimpleFlag(tcKeyRequestInfo) == 0);
- /**
- * Decrease lqhkeyreqrec to compensate for addition
- * during read of index table
- * I.e. let TC start committing when other operations has completed
- */
- regApiPtr->lqhkeyreqrec--;
- /**
- * Fix savepoint id -
- * fix so that index operation has the same savepoint id
- * as the read of the index table (TCINDXREQ)
- */
- TcConnectRecordPtr tmp;
- tmp.i = indexOp->indexReadTcConnect;
- ptrCheckGuard(tmp, ctcConnectFilesize, tcConnectRecord);
- const Uint32 currSavePointId = regApiPtr->currSavePointId;
- regApiPtr->currSavePointId = tmp.p->savePointId;
- EXECUTE_DIRECT(DBTC, GSN_TCKEYREQ, signal, tcKeyLength);
- regApiPtr->currSavePointId = currSavePointId;
-
- jamEntry();
- // *********** KEYINFO ***********
- if (moreKeyData) {
- jam();
- // Send KEYINFO sequence
- KeyInfo * const keyInfo = (KeyInfo *)signal->getDataPtrSend();
-
- keyInfo->connectPtr = indexOp->tcIndxReq.apiConnectPtr;
- keyInfo->transId[0] = regApiPtr->transid[0];
- keyInfo->transId[1] = regApiPtr->transid[1];
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- // Pack any part of a key attribute that did no fit TCKEYREQ
- while(keySize-- != 0) {// If we have not read complete key
- *dataPtr++ = *aiIter.data;
- dataPos++;
- if (dataPos == KeyInfo::DataLength) {
- // Flush KEYINFO
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength);
- jamEntry();
- dataPos = 0;
- dataPtr = (Uint32 *) &keyInfo->keyData;
- }
- moreKeyData = indexOp->transIdAI.next(aiIter);
- }
- if (dataPos != 0) {
- // Flush last KEYINFO
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + dataPos);
- jamEntry();
- }
- }
-
- // *********** ATTRINFO ***********
- if (attributesLength > attrBufSize) {
- jam();
- // No ATTRINFO in TcKeyReq
- TcKeyReq::setAIInTcKeyReq(tcKeyReq->requestInfo, 0);
- // Send ATTRINFO sequence
- AttrInfo * const attrInfo = (AttrInfo *)signal->getDataPtrSend();
- Uint32 attrInfoPos = 0;
-
- attrInfo->connectPtr = indexOp->tcIndxReq.apiConnectPtr;
- attrInfo->transId[0] = regApiPtr->transid[0];
- attrInfo->transId[1] = regApiPtr->transid[1];
- dataPtr = (Uint32 *) &attrInfo->attrData;
-
- // Insert attribute values (insert key values of primary table)
- for(bool moreAttrData = indexOp->attrInfo.first(attrIter);
- moreAttrData;
- moreAttrData = indexOp->attrInfo.next(attrIter)) {
- *dataPtr++ = *attrIter.data;
- attrInfoPos++;
- if (attrInfoPos == AttrInfo::DataLength) {
- // Flush ATTRINFO
- EXECUTE_DIRECT(DBTC, GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + AttrInfo::DataLength);
- jamEntry();
- attrInfoPos = 0;
- dataPtr = (Uint32 *) &attrInfo->attrData;
- }
- }
- if (attrInfoPos != 0) {
- // Send last ATTRINFO
- EXECUTE_DIRECT(DBTC, GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + attrInfoPos);
- jamEntry();
- }
- }
- }
- bool Dbtc::seizeIndexOperation(ApiConnectRecord* regApiPtr,
- TcIndexOperationPtr& indexOpPtr)
- {
- return regApiPtr->theSeizedIndexOperations.seize(indexOpPtr);
- }
- void Dbtc::releaseIndexOperation(ApiConnectRecord* regApiPtr,
- TcIndexOperation* indexOp)
- {
- indexOp->indexOpState = IOS_NOOP;
- indexOp->expectedKeyInfo = 0;
- indexOp->keyInfo.release();
- indexOp->expectedAttrInfo = 0;
- indexOp->attrInfo.release();
- indexOp->expectedTransIdAI = 0;
- indexOp->transIdAI.release();
- regApiPtr->theSeizedIndexOperations.release(indexOp->indexOpId);
- }
- void Dbtc::releaseAllSeizedIndexOperations(ApiConnectRecord* regApiPtr)
- {
- TcIndexOperationPtr seizedIndexOpPtr;
- regApiPtr->theSeizedIndexOperations.first(seizedIndexOpPtr);
- while(seizedIndexOpPtr.i != RNIL) {
- jam();
- TcIndexOperation* indexOp = seizedIndexOpPtr.p;
- indexOp->indexOpState = IOS_NOOP;
- indexOp->expectedKeyInfo = 0;
- indexOp->keyInfo.release();
- indexOp->expectedAttrInfo = 0;
- indexOp->attrInfo.release();
- indexOp->expectedTransIdAI = 0;
- indexOp->transIdAI.release();
- regApiPtr->theSeizedIndexOperations.next(seizedIndexOpPtr);
- }
- regApiPtr->theSeizedIndexOperations.release();
- }
- void Dbtc::saveTriggeringOpState(Signal* signal, TcConnectRecord* trigOp)
- {
- LqhKeyConf * lqhKeyConf = (LqhKeyConf *)signal->getDataPtr();
- copyFromToLen((UintR*)lqhKeyConf,
- &trigOp->savedState[0],
- LqhKeyConf::SignalLength);
- }
- void Dbtc::continueTriggeringOp(Signal* signal, TcConnectRecord* trigOp)
- {
- LqhKeyConf * lqhKeyConf = (LqhKeyConf *)signal->getDataPtr();
- copyFromToLen(&trigOp->savedState[0],
- (UintR*)lqhKeyConf,
- LqhKeyConf::SignalLength);
- lqhKeyConf->noFiredTriggers = 0;
- trigOp->noReceivedTriggers = 0;
- // All triggers executed successfully, continue operation
- execLQHKEYCONF(signal);
- }
- void Dbtc::scheduleFiredTrigger(ApiConnectRecordPtr* transPtr,
- TcConnectRecordPtr* opPtr)
- {
- // Set initial values for trigger fireing operation
- opPtr->p->triggerExecutionCount++;
- // Insert fired trigger in execution queue
- transPtr->p->theFiredTriggers.add(opPtr->p->accumulatingTriggerData);
- opPtr->p->accumulatingTriggerData.i = RNIL;
- opPtr->p->accumulatingTriggerData.p = NULL;
- }
- void Dbtc::executeTriggers(Signal* signal, ApiConnectRecordPtr* transPtr)
- {
- ApiConnectRecord* regApiPtr = transPtr->p;
- TcConnectRecord *localTcConnectRecord = tcConnectRecord;
- TcConnectRecordPtr opPtr;
- FiredTriggerPtr trigPtr;
- if (!regApiPtr->theFiredTriggers.isEmpty()) {
- jam();
- if ((regApiPtr->apiConnectstate == CS_STARTED) ||
- (regApiPtr->apiConnectstate == CS_START_COMMITTING)) {
- jam();
- regApiPtr->theFiredTriggers.first(trigPtr);
- while (trigPtr.i != RNIL) {
- jam();
- // Execute all ready triggers in parallel
- opPtr.i = trigPtr.p->fireingOperation;
- ptrCheckGuard(opPtr, ctcConnectFilesize, localTcConnectRecord);
- FiredTriggerPtr nextTrigPtr = trigPtr;
- regApiPtr->theFiredTriggers.next(nextTrigPtr);
- if (opPtr.p->noReceivedTriggers == opPtr.p->noFiredTriggers) {
- jam();
- // Fireing operation is ready to have a trigger executing
- executeTrigger(signal, trigPtr.p, transPtr, &opPtr);
- // Should allow for interleaving here by sending a CONTINUEB and
- // return
- // Release trigger records
- AttributeBuffer::DataBufferPool & pool = c_theAttributeBufferPool;
- LocalDataBuffer<11> tmp1(pool, trigPtr.p->keyValues);
- tmp1.release();
- LocalDataBuffer<11> tmp2(pool, trigPtr.p->beforeValues);
- tmp2.release();
- LocalDataBuffer<11> tmp3(pool, trigPtr.p->afterValues);
- tmp3.release();
- regApiPtr->theFiredTriggers.release(trigPtr.i);
- }
- trigPtr = nextTrigPtr;
- }
- return;
- // No more triggers, continue transaction after last executed trigger has
- // reurned (in execLQHKEYCONF or execLQHKEYREF)
- } else {
- // Wait until transaction is ready to execute a trigger
- jam();
- if (!regApiPtr->triggerPending) {
- jam();
- regApiPtr->triggerPending = true;
- signal->theData[0] = TcContinueB::TRIGGER_PENDING;
- signal->theData[1] = transPtr->i;
- sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
- }
- // else
- // We are already waiting for a pending trigger (CONTINUEB)
- }
- }
- }
- void Dbtc::executeTrigger(Signal* signal,
- TcFiredTriggerData* firedTriggerData,
- ApiConnectRecordPtr* transPtr,
- TcConnectRecordPtr* opPtr)
- {
- TcDefinedTriggerData* definedTriggerData;
- if ((definedTriggerData =
- c_theDefinedTriggers.getPtr(firedTriggerData->triggerId))
- != NULL) {
- switch(definedTriggerData->triggerType) {
- case(TriggerType::SECONDARY_INDEX):
- jam();
- executeIndexTrigger(signal, definedTriggerData, firedTriggerData,
- transPtr, opPtr);
- break;
- default:
- ndbrequire(false);
- }
- }
- }
- void Dbtc::executeIndexTrigger(Signal* signal,
- TcDefinedTriggerData* definedTriggerData,
- TcFiredTriggerData* firedTriggerData,
- ApiConnectRecordPtr* transPtr,
- TcConnectRecordPtr* opPtr)
- {
- TcIndexData* indexData;
- indexData = c_theIndexes.getPtr(definedTriggerData->indexId);
- ndbassert(indexData != NULL);
- switch (definedTriggerData->triggerEvent) {
- case(TriggerEvent::TE_INSERT): {
- jam();
- insertIntoIndexTable(signal, firedTriggerData, transPtr, opPtr, indexData);
- break;
- }
- case(TriggerEvent::TE_DELETE): {
- jam();
- deleteFromIndexTable(signal, firedTriggerData, transPtr, opPtr, indexData);
- break;
- }
- case(TriggerEvent::TE_UPDATE): {
- jam();
- deleteFromIndexTable(signal, firedTriggerData, transPtr, opPtr,
- indexData, true); // Hold the triggering operation
- insertIntoIndexTable(signal, firedTriggerData, transPtr, opPtr, indexData);
- break;
- }
- default:
- ndbrequire(false);
- }
- }
- void Dbtc::releaseFiredTriggerData(DLFifoList<TcFiredTriggerData>* triggers)
- {
- FiredTriggerPtr trigPtr;
- triggers->first(trigPtr);
- while (trigPtr.i != RNIL) {
- jam();
- // Release trigger records
- AttributeBuffer::DataBufferPool & pool = c_theAttributeBufferPool;
- LocalDataBuffer<11> tmp1(pool, trigPtr.p->keyValues);
- tmp1.release();
- LocalDataBuffer<11> tmp2(pool, trigPtr.p->beforeValues);
- tmp2.release();
- LocalDataBuffer<11> tmp3(pool, trigPtr.p->afterValues);
- tmp3.release();
-
- triggers->next(trigPtr);
- }
- triggers->release();
- }
- void Dbtc::insertIntoIndexTable(Signal* signal,
- TcFiredTriggerData* firedTriggerData,
- ApiConnectRecordPtr* transPtr,
- TcConnectRecordPtr* opPtr,
- TcIndexData* indexData,
- bool holdOperation)
- {
- ApiConnectRecord* regApiPtr = transPtr->p;
- TcConnectRecord* opRecord = opPtr->p;
- TcKeyReq * const tcKeyReq = (TcKeyReq *)signal->getDataPtrSend();
- Uint32 tcKeyRequestInfo = 0;
- Uint32 tcKeyLength = TcKeyReq::StaticLength;
- TableRecordPtr indexTabPtr;
- AttributeBuffer::DataBufferIterator iter;
- Uint32 attrId = 0;
- Uint32 keyLength = 0;
- Uint32 totalPrimaryKeyLength = 0;
- Uint32 hops;
- indexTabPtr.i = indexData->indexId;
- ptrCheckGuard(indexTabPtr, ctabrecFilesize, tableRecord);
- tcKeyReq->apiConnectPtr = transPtr->i;
- tcKeyReq->senderData = opPtr->i;
- if (holdOperation) {
- jam();
- opRecord->triggerExecutionCount++;
- }//if
- // Calculate key length and renumber attribute id:s
- AttributeBuffer::DataBufferPool & pool = c_theAttributeBufferPool;
- LocalDataBuffer<11> afterValues(pool, firedTriggerData->afterValues);
- bool skipNull = false;
- for(bool moreKeyAttrs = afterValues.first(iter); moreKeyAttrs; attrId++) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
- // Filter out NULL valued attributes
- if (attrHeader->isNULL()) {
- skipNull = true;
- break;
- }
- attrHeader->setAttributeId(attrId);
- keyLength += attrHeader->getDataSize();
- hops = attrHeader->getHeaderSize() + attrHeader->getDataSize();
- moreKeyAttrs = afterValues.next(iter, hops);
- }
- if (skipNull) {
- jam();
- opRecord->triggerExecutionCount--;
- if (opRecord->triggerExecutionCount == 0) {
- /*
- We have completed current trigger execution
- Continue triggering operation
- */
- jam();
- continueTriggeringOp(signal, opRecord);
- }//if
- return;
- }//if
- // Calculate total length of primary key to be stored in index table
- LocalDataBuffer<11> keyValues(pool, firedTriggerData->keyValues);
- for(bool moreAttrData = keyValues.first(iter); moreAttrData; ) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- totalPrimaryKeyLength += attrHeader->getDataSize();
- hops = attrHeader->getHeaderSize() + attrHeader->getDataSize();
- moreAttrData = keyValues.next(iter, hops);
- }
- AttributeHeader pkAttrHeader(attrId, totalPrimaryKeyLength);
-
- TcKeyReq::setKeyLength(tcKeyRequestInfo, keyLength);
- tcKeyReq->attrLen = afterValues.getSize() +
- pkAttrHeader.getHeaderSize() + pkAttrHeader.getDataSize();
- tcKeyReq->tableId = indexData->indexId;
- TcKeyReq::setOperationType(tcKeyRequestInfo, ZINSERT);
- TcKeyReq::setExecutingTrigger(tcKeyRequestInfo, true);
- tcKeyReq->tableSchemaVersion = indexTabPtr.p->currentSchemaVersion;
- tcKeyReq->transId1 = regApiPtr->transid[0];
- tcKeyReq->transId2 = regApiPtr->transid[1];
- Uint32 * dataPtr = &tcKeyReq->scanInfo;
- // Write first part of key in TCKEYREQ
- Uint32 keyBufSize = 8; // Maximum for key in TCKEYREQ
- Uint32 attrBufSize = 5; // Maximum for key in TCKEYREQ
- Uint32 dataPos = 0;
- // Filter out AttributeHeader:s since this should no be in key
- bool moreKeyData = afterValues.first(iter);
- Uint32 headerSize = 0, keyAttrSize = 0, dataSize = 0, headAndData = 0;
- while (moreKeyData && (dataPos < keyBufSize)) {
- /*
- * If we have not read complete key
- * and it fits in the signal
- */
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- headerSize = attrHeader->getHeaderSize();
- keyAttrSize = attrHeader->getDataSize();
- headAndData = headerSize + attrHeader->getDataSize();
- // Skip header
- if (headerSize == 1) {
- jam();
- moreKeyData = afterValues.next(iter);
- } else {
- jam();
- moreKeyData = afterValues.next(iter, headerSize - 1);
- }//if
- while((keyAttrSize != 0) && (dataPos < keyBufSize)) {
- // If we have not read complete key
- jam();
- *dataPtr++ = *iter.data;
- dataPos++;
- keyAttrSize--;
- moreKeyData = afterValues.next(iter);
- }
- if (keyAttrSize != 0) {
- jam();
- break;
- }//if
- }
- tcKeyLength += dataPos;
- Uint32 attributesLength = afterValues.getSize() +
- pkAttrHeader.getHeaderSize() + pkAttrHeader.getDataSize();
- if (attributesLength <= attrBufSize) {
- jam();
- // ATTRINFO fits in TCKEYREQ
- // Pack ATTRINFO IN TCKEYREQ as one attribute
- TcKeyReq::setAIInTcKeyReq(tcKeyRequestInfo, attributesLength);
- bool moreAttrData;
- // Insert primary key attributes (insert after values of primary table)
- for(moreAttrData = afterValues.first(iter);
- moreAttrData;
- moreAttrData = afterValues.next(iter)) {
- *dataPtr++ = *iter.data;
- }
- // Insert attribute values (insert key values of primary table)
- // as one attribute
- pkAttrHeader.insertHeader(dataPtr);
- dataPtr += pkAttrHeader.getHeaderSize();
- moreAttrData = keyValues.first(iter);
- while(moreAttrData) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- headerSize = attrHeader->getHeaderSize();
- dataSize = attrHeader->getDataSize();
- // Skip header
- if (headerSize == 1) {
- jam();
- moreAttrData = keyValues.next(iter);
- } else {
- jam();
- moreAttrData = keyValues.next(iter, headerSize - 1);
- }//if
- // Copy attribute data
- while(dataSize-- != 0) {
- *dataPtr++ = *iter.data;
- moreAttrData = keyValues.next(iter);
- }
- }
- tcKeyLength += attributesLength;
- } else {
- jam();
- // No ATTRINFO in TCKEYREQ
- TcKeyReq::setAIInTcKeyReq(tcKeyRequestInfo, 0);
- }
- tcKeyReq->requestInfo = tcKeyRequestInfo;
- /**
- * Fix savepoint id -
- * fix so that insert has same savepoint id as triggering operation
- */
- const Uint32 currSavePointId = regApiPtr->currSavePointId;
- regApiPtr->currSavePointId = opRecord->savePointId;
- EXECUTE_DIRECT(DBTC, GSN_TCKEYREQ, signal, tcKeyLength);
- regApiPtr->currSavePointId = currSavePointId;
- tcConnectptr.p->currentIndexId = indexData->indexId;
- jamEntry();
- // *********** KEYINFO ***********
- if (moreKeyData) {
- jam();
- // Send KEYINFO sequence
- KeyInfo * const keyInfo = (KeyInfo *)signal->getDataPtrSend();
-
- keyInfo->connectPtr = transPtr->i;
- keyInfo->transId[0] = regApiPtr->transid[0];
- keyInfo->transId[1] = regApiPtr->transid[1];
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- // Pack any part of a key attribute that did no fit TCKEYREQ
- while((keyAttrSize != 0) && (dataPos < KeyInfo::DataLength)) {
- // If we have not read complete key
- *dataPtr++ = *iter.data;
- dataPos++;
- keyAttrSize--;
- if (dataPos == KeyInfo::DataLength) {
- jam();
- // Flush KEYINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength);
- jamEntry();
- #endif
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- }
- moreKeyData = afterValues.next(iter);
- }
-
- while(moreKeyData) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- headerSize = attrHeader->getHeaderSize();
- keyAttrSize = attrHeader->getDataSize();
- headAndData = headerSize + attrHeader->getDataSize();
- // Skip header
- if (headerSize == 1) {
- jam();
- moreKeyData = afterValues.next(iter);
- } else {
- jam();
- moreKeyData = afterValues.next(iter, headerSize - 1);
- }//if
- while (keyAttrSize-- != 0) {
- *dataPtr++ = *iter.data;
- dataPos++;
- if (dataPos == KeyInfo::DataLength) {
- jam();
- // Flush KEYINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength);
- jamEntry();
- #endif
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- }
- moreKeyData = afterValues.next(iter);
- }
- }
- if (dataPos != 0) {
- jam();
- // Flush last KEYINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + dataPos, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + dataPos);
- jamEntry();
- #endif
- }
- }
-
- // *********** ATTRINFO ***********
- if (attributesLength > attrBufSize) {
- jam();
- // No ATTRINFO in TcKeyReq
- TcKeyReq::setAIInTcKeyReq(tcKeyReq->requestInfo, 0);
- // Send ATTRINFO sequence
- AttrInfo * const attrInfo = (AttrInfo *)signal->getDataPtrSend();
- Uint32 attrInfoPos = 0;
-
- attrInfo->connectPtr = transPtr->i;
- attrInfo->transId[0] = regApiPtr->transid[0];
- attrInfo->transId[1] = regApiPtr->transid[1];
- dataPtr = (Uint32 *) &attrInfo->attrData;
-
- bool moreAttrData;
- // Insert primary key attributes (insert after values of primary table)
- for(moreAttrData = afterValues.first(iter);
- moreAttrData;
- moreAttrData = afterValues.next(iter)) {
- *dataPtr++ = *iter.data;
- attrInfoPos++;
- if (attrInfoPos == AttrInfo::DataLength) {
- jam();
- // Flush ATTRINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + AttrInfo::DataLength, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + AttrInfo::DataLength);
- jamEntry();
- #endif
- dataPtr = (Uint32 *) &attrInfo->attrData;
- attrInfoPos = 0;
- }
- }
- // Insert attribute values (insert key values of primary table)
- // as one attribute
- pkAttrHeader.insertHeader(dataPtr);
- dataPtr += pkAttrHeader.getHeaderSize();
- attrInfoPos += pkAttrHeader.getHeaderSize();
- moreAttrData = keyValues.first(iter);
- while(moreAttrData) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- headerSize = attrHeader->getHeaderSize();
- dataSize = attrHeader->getDataSize();
- // Skip header
- if (headerSize == 1) {
- jam();
- moreAttrData = keyValues.next(iter);
- } else {
- jam();
- moreAttrData = keyValues.next(iter, headerSize - 1);
- }//if
- while(dataSize-- != 0) { // If we have not read complete key
- if (attrInfoPos == AttrInfo::DataLength) {
- jam();
- // Flush ATTRINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + AttrInfo::DataLength, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + AttrInfo::DataLength);
- jamEntry();
- #endif
- dataPtr = (Uint32 *) &attrInfo->attrData;
- attrInfoPos = 0;
- }
- *dataPtr++ = *iter.data;
- attrInfoPos++;
- moreAttrData = keyValues.next(iter);
- }
- }
- if (attrInfoPos != 0) {
- jam();
- // Flush last ATTRINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + attrInfoPos, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_ATTRINFO, signal,
- AttrInfo::HeaderLength + attrInfoPos);
- jamEntry();
- #endif
- }
- }
- }
- void Dbtc::deleteFromIndexTable(Signal* signal,
- TcFiredTriggerData* firedTriggerData,
- ApiConnectRecordPtr* transPtr,
- TcConnectRecordPtr* opPtr,
- TcIndexData* indexData,
- bool holdOperation)
- {
- ApiConnectRecord* regApiPtr = transPtr->p;
- TcConnectRecord* opRecord = opPtr->p;
- TcKeyReq * const tcKeyReq = (TcKeyReq *)signal->getDataPtrSend();
- Uint32 tcKeyRequestInfo = 0;
- Uint32 tcKeyLength = 12; // Static length
- TableRecordPtr indexTabPtr;
- AttributeBuffer::DataBufferIterator iter;
- Uint32 attrId = 0;
- Uint32 keyLength = 0;
- Uint32 hops;
- indexTabPtr.i = indexData->indexId;
- ptrCheckGuard(indexTabPtr, ctabrecFilesize, tableRecord);
- tcKeyReq->apiConnectPtr = transPtr->i;
- tcKeyReq->senderData = opPtr->i;
- if (holdOperation) {
- jam();
- opRecord->triggerExecutionCount++;
- }//if
- // Calculate key length and renumber attribute id:s
- AttributeBuffer::DataBufferPool & pool = c_theAttributeBufferPool;
- LocalDataBuffer<11> beforeValues(pool, firedTriggerData->beforeValues);
- bool skipNull = false;
- for(bool moreKeyAttrs = beforeValues.first(iter);
- (moreKeyAttrs);
- attrId++) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- // Filter out NULL valued attributes
- if (attrHeader->isNULL()) {
- skipNull = true;
- break;
- }
- attrHeader->setAttributeId(attrId);
- keyLength += attrHeader->getDataSize();
- hops = attrHeader->getHeaderSize() + attrHeader->getDataSize();
- moreKeyAttrs = beforeValues.next(iter, hops);
- }
- if (skipNull) {
- jam();
- opRecord->triggerExecutionCount--;
- if (opRecord->triggerExecutionCount == 0) {
- /*
- We have completed current trigger execution
- Continue triggering operation
- */
- jam();
- continueTriggeringOp(signal, opRecord);
- }//if
- return;
- }//if
- TcKeyReq::setKeyLength(tcKeyRequestInfo, keyLength);
- tcKeyReq->attrLen = 0;
- tcKeyReq->tableId = indexData->indexId;
- TcKeyReq::setOperationType(tcKeyRequestInfo, ZDELETE);
- TcKeyReq::setExecutingTrigger(tcKeyRequestInfo, true);
- tcKeyReq->tableSchemaVersion = indexTabPtr.p->currentSchemaVersion;
- tcKeyReq->transId1 = regApiPtr->transid[0];
- tcKeyReq->transId2 = regApiPtr->transid[1];
- Uint32 * dataPtr = &tcKeyReq->scanInfo;
- // Write first part of key in TCKEYREQ
- Uint32 keyBufSize = 8; // Maximum for key in TCKEYREQ
- Uint32 dataPos = 0;
- // Filter out AttributeHeader:s since this should no be in key
- bool moreKeyData = beforeValues.first(iter);
- Uint32 headerSize = 0, keyAttrSize = 0, headAndData = 0;
- while (moreKeyData &&
- (dataPos < keyBufSize)) {
- /*
- If we have not read complete key
- and it fits in the signal
- */
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- headerSize = attrHeader->getHeaderSize();
- keyAttrSize = attrHeader->getDataSize();
- headAndData = headerSize + attrHeader->getDataSize();
- // Skip header
- if (headerSize == 1) {
- jam();
- moreKeyData = beforeValues.next(iter);
- } else {
- jam();
- moreKeyData = beforeValues.next(iter, headerSize - 1);
- }//if
- while((keyAttrSize != 0) &&
- (dataPos < keyBufSize)) {
- // If we have not read complete key
- jam();
- *dataPtr++ = *iter.data;
- dataPos++;
- keyAttrSize--;
- moreKeyData = beforeValues.next(iter);
- }
- if (keyAttrSize != 0) {
- jam();
- break;
- }//if
- }
- tcKeyLength += dataPos;
- tcKeyReq->requestInfo = tcKeyRequestInfo;
- /**
- * Fix savepoint id -
- * fix so that delete has same savepoint id as triggering operation
- */
- const Uint32 currSavePointId = regApiPtr->currSavePointId;
- regApiPtr->currSavePointId = opRecord->savePointId;
- EXECUTE_DIRECT(DBTC, GSN_TCKEYREQ, signal, tcKeyLength);
- regApiPtr->currSavePointId = currSavePointId;
- tcConnectptr.p->currentIndexId = indexData->indexId;
- jamEntry();
- // *********** KEYINFO ***********
- if (moreKeyData) {
- jam();
- // Send KEYINFO sequence
- KeyInfo * const keyInfo = (KeyInfo *)signal->getDataPtrSend();
-
- keyInfo->connectPtr = transPtr->i;
- keyInfo->transId[0] = regApiPtr->transid[0];
- keyInfo->transId[1] = regApiPtr->transid[1];
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- // Pack any part of a key attribute that did no fit TCKEYREQ
- while((keyAttrSize != 0) &&
- (dataPos < KeyInfo::DataLength)) {
- // If we have not read complete key
- *dataPtr++ = *iter.data;
- dataPos++;
- keyAttrSize--;
- if (dataPos == KeyInfo::DataLength) {
- jam();
- // Flush KEYINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength);
- jamEntry();
- #endif
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- }
- moreKeyData = beforeValues.next(iter);
- }
-
- while(moreKeyData) {
- jam();
- AttributeHeader* attrHeader = (AttributeHeader *) iter.data;
-
- headerSize = attrHeader->getHeaderSize();
- keyAttrSize = attrHeader->getDataSize();
- headAndData = headerSize + attrHeader->getDataSize();
- // Skip header
- if (headerSize == 1) {
- jam();
- moreKeyData = beforeValues.next(iter);
- } else {
- jam();
- moreKeyData = beforeValues.next(iter,
- headerSize - 1);
- }//if
- while (keyAttrSize-- != 0) {
- *dataPtr++ = *iter.data;
- dataPos++;
- if (dataPos == KeyInfo::DataLength) {
- jam();
- // Flush KEYINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + KeyInfo::DataLength);
- jamEntry();
- #endif
- dataPtr = (Uint32 *) &keyInfo->keyData;
- dataPos = 0;
- }
- moreKeyData = beforeValues.next(iter);
- }
- }
- if (dataPos != 0) {
- jam();
- // Flush last KEYINFO
- #if INTERNAL_TRIGGER_TCKEYREQ_JBA
- sendSignal(reference(), GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + dataPos, JBA);
- #else
- EXECUTE_DIRECT(DBTC, GSN_KEYINFO, signal,
- KeyInfo::HeaderLength + dataPos);
- jamEntry();
- #endif
- }
- }
- }
- Uint32
- Dbtc::TableRecord::getErrorCode(Uint32 schemaVersion) const {
- if(!enabled)
- return ZNO_SUCH_TABLE;
- if(dropping)
- return ZDROP_TABLE_IN_PROGRESS;
- if(table_version_major(schemaVersion) != table_version_major(currentSchemaVersion))
- return ZWRONG_SCHEMA_VERSION_ERROR;
- ErrorReporter::handleAssert("Dbtc::TableRecord::getErrorCode",
- __FILE__, __LINE__);
- return 0;
- }