📄 ndbtransaction.cpp
字号:
DBUG_RETURN(0); default: ndbout << "Inconsistent theSendStatus = " << (Uint32) theSendStatus << endl; abort(); break; }//switch setOperationErrorCodeAbort(4002); theReleaseOnClose = true; theTransactionIsStarted = false; theCommitStatus = Aborted; DBUG_RETURN(-1);}//NdbTransaction::doSend()/**************************************************************************int sendROLLBACK();Return Value: Return -1 if send unsuccessful. Parameters : None.Remark: Order NDB to rollback the transaction. **************************************************************************/int NdbTransaction::sendROLLBACK() // Send a TCROLLBACKREQ signal;{ Ndb* tNdb = theNdb; if ((theTransactionIsStarted == true) && (theCommitStatus != Committed) && (theCommitStatus != Aborted)) {/************************************************************************** * The user did not perform any rollback but simply closed the * transaction. We must rollback Ndb since Ndb have been contacted. *************************************************************************/ NdbApiSignal tSignal(tNdb->theMyRef); Uint32 tTransId1, tTransId2; TransporterFacade *tp = TransporterFacade::instance(); int tReturnCode; tTransId1 = (Uint32) theTransactionId; tTransId2 = (Uint32) (theTransactionId >> 32); tSignal.setSignal(GSN_TCROLLBACKREQ); tSignal.setData(theTCConPtr, 1); tSignal.setData(tTransId1, 2); tSignal.setData(tTransId2, 3); tReturnCode = tp->sendSignal(&tSignal,theDBnode); if (tReturnCode != -1) { theSendStatus = sendTC_ROLLBACK; tNdb->insert_sent_list(this); return 0; }//if /********************************************************************* * It was not possible to abort the transaction towards the NDB kernel * and thus we put it into the array of completed transactions that * are ready for reporting to the application. *********************************************************************/ return -1; } else { /* It is not necessary to abort the transaction towards the NDB kernel and thus we put it into the array of completed transactions that are ready for reporting to the application. */ theSendStatus = sendCompleted; tNdb->insert_completed_list(this); return 0; ; }//if}//NdbTransaction::sendROLLBACK()/***************************************************************************int sendCOMMIT();Return Value: Return 0 : send was successful. Return -1: In all other case. Parameters : None.Remark: Order NDB to commit the transaction. ***************************************************************************/int NdbTransaction::sendCOMMIT() // Send a TC_COMMITREQ signal;{ NdbApiSignal tSignal(theNdb->theMyRef); Uint32 tTransId1, tTransId2; TransporterFacade *tp = TransporterFacade::instance(); int tReturnCode; tTransId1 = (Uint32) theTransactionId; tTransId2 = (Uint32) (theTransactionId >> 32); tSignal.setSignal(GSN_TC_COMMITREQ); tSignal.setData(theTCConPtr, 1); tSignal.setData(tTransId1, 2); tSignal.setData(tTransId2, 3); tReturnCode = tp->sendSignal(&tSignal,theDBnode); if (tReturnCode != -1) { theSendStatus = sendTC_COMMIT; theNdb->insert_sent_list(this); return 0; } else { return -1; }//if}//NdbTransaction::sendCOMMIT()/******************************************************************************void release();Remark: Release all operations.******************************************************************************/void NdbTransaction::release(){ releaseOperations(); if ( (theTransactionIsStarted == true) && ((theCommitStatus != Committed) && (theCommitStatus != Aborted))) { /************************************************************************ * The user did not perform any rollback but simply closed the * transaction. We must rollback Ndb since Ndb have been contacted. ************************************************************************/ execute(Rollback); }//if theMagicNumber = 0xFE11DC; theInUseState = false;#ifdef VM_TRACE if (theListState != NotInList) { theNdb->printState("release %x", this); abort(); }#endif}//NdbTransaction::release()voidNdbTransaction::releaseOps(NdbOperation* tOp){ while (tOp != NULL) { NdbOperation* tmp = tOp; tOp->release(); tOp = tOp->next(); theNdb->releaseOperation(tmp); }//while}/******************************************************************************void releaseOperations();Remark: Release all operations.******************************************************************************/void NdbTransaction::releaseOperations(){ // Release any open scans releaseScanOperations(m_theFirstScanOperation); releaseScanOperations(m_firstExecutedScanOp); releaseOps(theCompletedFirstOp); releaseOps(theFirstOpInList); releaseOps(theFirstExecOpInList); theCompletedFirstOp = NULL; theCompletedLastOp = NULL; theFirstOpInList = NULL; theFirstExecOpInList = NULL; theLastOpInList = NULL; theLastExecOpInList = NULL; theScanningOp = NULL; m_theFirstScanOperation = NULL; m_theLastScanOperation = NULL; m_firstExecutedScanOp = NULL;}//NdbTransaction::releaseOperations()void NdbTransaction::releaseCompletedOperations(){ releaseOps(theCompletedFirstOp); theCompletedFirstOp = NULL; theCompletedLastOp = NULL;}//NdbTransaction::releaseOperations()/******************************************************************************void releaseScanOperations();Remark: Release all cursor operations. (NdbScanOperation and NdbIndexOperation)******************************************************************************/void NdbTransaction::releaseScanOperations(NdbIndexScanOperation* cursorOp){ while(cursorOp != 0){ NdbIndexScanOperation* next = (NdbIndexScanOperation*)cursorOp->next(); cursorOp->release(); theNdb->releaseScanOperation(cursorOp); cursorOp = next; }}//NdbTransaction::releaseScanOperations()/*****************************************************************************void releaseExecutedScanOperation();Remark: Release scan op when hupp'ed trans closed (save memory)******************************************************************************/void NdbTransaction::releaseExecutedScanOperation(NdbIndexScanOperation* cursorOp){ DBUG_ENTER("NdbTransaction::releaseExecutedScanOperation"); DBUG_PRINT("enter", ("this=0x%x op=0x%x", (UintPtr)this, (UintPtr)cursorOp)) // here is one reason to make op lists doubly linked if (m_firstExecutedScanOp == cursorOp) { m_firstExecutedScanOp = (NdbIndexScanOperation*)cursorOp->theNext; cursorOp->release(); theNdb->releaseScanOperation(cursorOp); } else if (m_firstExecutedScanOp != NULL) { NdbIndexScanOperation* tOp = m_firstExecutedScanOp; while (tOp->theNext != NULL) { if (tOp->theNext == cursorOp) { tOp->theNext = cursorOp->theNext; cursorOp->release(); theNdb->releaseScanOperation(cursorOp); break; } tOp = (NdbIndexScanOperation*)tOp->theNext; } } DBUG_VOID_RETURN;}//NdbTransaction::releaseExecutedScanOperation()/*****************************************************************************NdbOperation* getNdbOperation(const char* aTableName);Return Value Return a pointer to a NdbOperation object if getNdbOperation was succesful. Return NULL : In all other case. Parameters: aTableName : Name of the database table. Remark: Get an operation from NdbOperation idlelist and get the NdbTransaction object who was fetch by startTransaction pointing to this operation getOperation will set the theTableId in the NdbOperation object. synchronous******************************************************************************/NdbOperation*NdbTransaction::getNdbOperation(const char* aTableName){ if (theCommitStatus == Started){ NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName); if (table != 0){ return getNdbOperation(table); } else { setErrorCode(theNdb->theDictionary->getNdbError().code); return NULL; }//if } setOperationErrorCodeAbort(4114); return NULL;}//NdbTransaction::getNdbOperation()/*****************************************************************************NdbOperation* getNdbOperation(int aTableId);Return Value Return a pointer to a NdbOperation object if getNdbOperation was succesful. Return NULL: In all other case. Parameters: tableId : Id of the database table beeing deleted.Remark: Get an operation from NdbOperation object idlelist and get the NdbTransaction object who was fetch by startTransaction pointing to this operation getOperation will set the theTableId in the NdbOperation object, synchronous.*****************************************************************************/NdbOperation*NdbTransaction::getNdbOperation(const NdbTableImpl * tab, NdbOperation* aNextOp){ NdbOperation* tOp; if (theScanningOp != NULL){ setErrorCode(4607); return NULL; } tOp = theNdb->getOperation(); if (tOp == NULL) goto getNdbOp_error1; if (aNextOp == NULL) { if (theLastOpInList != NULL) { theLastOpInList->next(tOp); theLastOpInList = tOp; } else { theLastOpInList = tOp; theFirstOpInList = tOp; }//if tOp->next(NULL); } else { // add before the given op if (theFirstOpInList == aNextOp) { theFirstOpInList = tOp; } else { NdbOperation* aLoopOp = theFirstOpInList; while (aLoopOp != NULL && aLoopOp->next() != aNextOp) aLoopOp = aLoopOp->next(); assert(aLoopOp != NULL); aLoopOp->next(tOp); } tOp->next(aNextOp); } if (tOp->init(tab, this) != -1) { return tOp; } else { theNdb->releaseOperation(tOp); }//if return NULL; getNdbOp_error1: setOperationErrorCodeAbort(4000); return NULL;}//NdbTransaction::getNdbOperation()NdbOperation* NdbTransaction::getNdbOperation(const NdbDictionary::Table * table){ if (table) return getNdbOperation(& NdbTableImpl::getImpl(*table)); else return NULL;}//NdbTransaction::getNdbOperation()// NdbScanOperation/*****************************************************************************NdbScanOperation* getNdbScanOperation(const char* aTableName);Return Value Return a pointer to a NdbScanOperation object if getNdbScanOperation was succesful. Return NULL : In all other case. Parameters: aTableName : Name of the database table. Remark: Get an operation from NdbScanOperation idlelist and get the NdbTransaction object who was fetch by startTransaction pointing to this operation getOperation will set the theTableId in the NdbOperation object.synchronous******************************************************************************/NdbScanOperation*NdbTransaction::getNdbScanOperation(const char* aTableName){ if (theCommitStatus == Started){ NdbTableImpl* tab = theNdb->theDictionary->getTable(aTableName); if (tab != 0){ return getNdbScanOperation(tab); } else { setOperationErrorCodeAbort(theNdb->theDictionary->m_error.code); return NULL; }//if } setOperationErrorCodeAbort(4114); return NULL;}//NdbTransaction::getNdbScanOperation()/*****************************************************************************NdbScanOperation* getNdbIndexScanOperation(const char* anIndexName, const char* aTableName);Return Value Return a pointer to a NdbIndexScanOperation object if getNdbIndexScanOperation was succesful. Return NULL : In all other case. Parameters: anIndexName : Name of the index to use. aTableName : Name of the database table. Remark: Get an operation from NdbIndexScanOperation idlelist and get the NdbTransaction object who was fetch by startTransaction pointing to this operation getOperation will set the theTableId in the NdbIndexScanOperation object.synchronous******************************************************************************/NdbIndexScanOperation*NdbTransaction::getNdbIndexScanOperation(const char* anIndexName, const char* aTableName){ NdbIndexImpl* index = theNdb->theDictionary->getIndex(anIndexName, aTableName); if (index == 0) { setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code); return 0; } NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName); if (table == 0) { setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code); return 0; } return getNdbIndexScanOperation(index, table);}NdbIndexScanOperation*NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index, const NdbTableImpl* table){ if (theCommitStatus == Started){ const NdbTableImpl * indexTable = index->getIndexTable(); if (indexTable != 0){ NdbIndexScanOperation* tOp = getNdbScanOperation(indexTable); if(tOp)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -