flexscan.cpp
来自「MySQL数据库开发源码 值得一看哦」· C++ 代码 · 共 1,668 行 · 第 1/4 页
CPP
1,668 行
tResult = 1; break; } // if MyOperation = MyTransaction->getNdbOperation(tableName[tableCount]); if (MyOperation == NULL) { tResult = 2; break; } // if check = MyOperation->openScanRead(tParallellism); if (check == -1) { tResult = 10; break; } // if for (int attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) { // Get all attributes tmp = MyOperation-> getValue((char*)attrName[attrCount+1], (char*)&(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize + attrCount*tNoOfOperations*tAttributeSize])); if (tmp == NULL) { tResult = 9; break; } // if } // for attrCount check = MyTransaction->executeScan(); if (check == -1) { tResult = 12; break; } // if check = MyTransaction->nextScanResult(); while (check == 0) { // Check if scan abort is requested if (theScanAbortTestFlag == 1) { if (countAbort == tAbortAfter) { MyTransaction->stopScan(); ndbout << "scanread aborted on request after " << countAbort*tParallellism << " tuples" << endl; break; // break while loop } // if countAbort++; } // if check = MyTransaction->nextScanResult(); } // while pNdb->closeTransaction(MyTransaction); } // for tableCount return(tResult);} // scanReadRowsstatic int scanUpdateRows(Ndb* pNdb, int* readValue, int* attrValue){ int tResult = 0; int tableCount = 0; int attrCount = 0; int check = 0; int opCount = 0; NdbConnection* MyTransaction = NULL; NdbOperation* MyOperation = NULL; NdbConnection* MyTakeOverTrans = NULL; NdbOperation* MyTakeOverOp = NULL; NdbRecAttr* tTmp = NULL; for (tableCount = 0; tableCount < tNoOfTables; tableCount++) { MyTransaction = pNdb->startTransaction(); if (MyTransaction == NULL) { tResult = 1; break; // break tableCount for loop } // if MyOperation = MyTransaction->getNdbOperation(tableName[tableCount]); if (MyOperation == NULL) { tResult = 2; break; } // if check = MyOperation->openScanExclusive(tParallellism); if (check == -1) { tResult = 11; break; } // if MyOperation->interpret_exit_ok(); // Fetch all attributes for (int attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) { tTmp = MyOperation-> getValue((char*)attrName[attrCount+1], (char*)&(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize + attrCount*tNoOfOperations*tAttributeSize])); if (tTmp == NULL) { tResult = 9; break; // break for loop } // if } // for if (tResult != 0) { break; // break while loop also } // if check = MyTransaction->executeScan(); if (check == -1) { tResult = 12; break; } // if check = MyTransaction->nextScanResult(); opCount = 0; while (check == 0) { MyTakeOverTrans = pNdb->startTransaction(); MyTakeOverOp = MyOperation->takeOverForUpdate(MyTakeOverTrans); for (attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) { check = MyTakeOverOp->setValue((char*)attrName[attrCount+1], (char*)&(attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize + attrCount*tNoOfOperations*tAttributeSize + opCount*tAttributeSize])); } // for check = MyTakeOverTrans->execute(Commit); if (check == 0) { check = MyTransaction->nextScanResult(); opCount++; } // if else { tResult = 95; /* MyTransaction, MyTakeOverTrans, Which one? */ // Any further error handling? int retCode = flexScanErrorData->handleErrorCommon(MyTakeOverTrans->getNdbError()); if (retCode == 1) { if (MyTakeOverTrans->getNdbError().code != 626 && MyTakeOverTrans->getNdbError().code != 630){ ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message); ndbout_c("Error code = %d", MyTakeOverTrans->getNdbError().code);} tResult = 20; } else if (retCode == 2) { ndbout << "4115 should not happen in flexBench" << endl; tResult = 20; } else if (retCode == 3) { // -------------------------------------------------------------------- // We are not certain if the transaction was successful or not. // We must reexecute but might very well find that the transaction // actually was updated. Updates and Reads are no problem here. Inserts // will not cause a problem if error code 630 arrives. Deletes will // not cause a problem if 626 arrives. // -------------------------------------------------------------------- /* What can we do here? */ ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message); }//if(retCode == 3) } // else pNdb->closeTransaction(MyTakeOverTrans); } // while pNdb->closeTransaction(MyTransaction); } // for return(tResult);} // scanUpdateRowsstatic int scanDeleteRows(Ndb* pNdb, int* readValue){ int tResult = 0; int tableCount = 0; int attrCount = 0; int check = 0; NdbRecAttr* tTmp = NULL; NdbConnection* MyTransaction = NULL; NdbOperation* MyOperation = NULL; NdbConnection* MyTakeOverTrans = NULL; NdbOperation* MyTakeOverOp = NULL; for (tableCount = 0; tableCount < tNoOfTables; tableCount++) { MyTransaction = pNdb->startTransaction(); if (MyTransaction == NULL) { tResult = 1; break; // break tableCount for loop } // if MyOperation = MyTransaction->getNdbOperation(tableName[tableCount]); if (MyOperation == NULL) { tResult = 2; break; } // if check = MyOperation->openScanExclusive(tParallellism); if (check == -1) { tResult = 11; break; } // if MyOperation->interpret_exit_ok(); for (int attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) { tTmp = MyOperation-> getValue((char*)attrName[attrCount+1], (char*)&(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations + attrCount*tNoOfOperations])); if (tTmp == NULL) { tResult = 9; break; } // if } // for check = MyTransaction->executeScan(); if (check == -1) { tResult = 12; break; } // if check = MyTransaction->nextScanResult(); while (check == 0) { MyTakeOverTrans = pNdb->startTransaction(); MyTakeOverOp = MyOperation->takeOverForDelete(MyTakeOverTrans); check = MyTakeOverOp->deleteTuple(); check = MyTakeOverTrans->execute(Commit); //Error handling here int retCode =flexScanErrorData->handleErrorCommon(MyTakeOverTrans->getNdbError()); if (retCode == 1) { if (MyTakeOverTrans->getNdbError().code != 626 && MyTakeOverTrans->getNdbError().code != 630){ ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message ); ndbout_c("Error code = %d", MyTakeOverTrans->getNdbError().code );} tResult = 20; } else if (retCode == 2) { ndbout << "4115 should not happen in flexBench" << endl; tResult = 20; } else if (retCode == 3) {// --------------------------------------------------------------------// We are not certain if the transaction was successful or not.// We must reexecute but might very well find that the transaction// actually was updated. Updates and Reads are no problem here. Inserts// will not cause a problem if error code 630 arrives. Deletes will// not cause a problem if 626 arrives.// -------------------------------------------------------------------- /* What can we do here? */ ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message ); }//if(retCode == 3) End of error handling pNdb->closeTransaction(MyTakeOverTrans); check = MyTransaction->nextScanResult(); } // while pNdb->closeTransaction(MyTransaction); } // for tableCount return(tResult);} // scanDeleteRowsstatic int deleteRows(Ndb* pNdb, int* pkValue){ int tResult = 0; NdbConnection* MyTransaction = NULL; int tableCount = 0; int opCount = 0; int check = 0; NdbOperation* MyOperations[MAXTABLES] = {NULL}; for (opCount = 0; opCount < tNoOfOperations; opCount++) { MyTransaction = pNdb->startTransaction(); if (MyTransaction == NULL) { tResult = 1; } // if else { for (tableCount = 0; tableCount < tNoOfTables; tableCount++) { MyOperations[tableCount] = MyTransaction->getNdbOperation(tableName[tableCount]); if (MyOperations[tableCount] == NULL) { tResult = 2; // Break for tableCount loop break; } // if check = MyOperations[tableCount]->deleteTuple(); if (check == -1) { tResult = 3; break; } // if check = MyOperations[tableCount]-> equal((char*)attrName[0], (char*)&(pkValue[opCount])); if (check == -1) { tResult = 7; break; } // if } // for tableCount // Execute transaction deleting one tuple in every table check = MyTransaction->execute(Commit); if (check == -1) { ndbout << MyTransaction->getNdbError().message << endl; // Add complete error handling here int retCode = flexScanErrorData->handleErrorCommon(MyTransaction->getNdbError()); if (retCode == 1) { if (MyTransaction->getNdbError().code != 626 && MyTransaction->getNdbError().code != 630){ ndbout_c("execute: %d, %s", opCount, MyTransaction->getNdbError().message ); ndbout_c("Error code = %d", MyTransaction->getNdbError().code );} tResult = 20; } else if (retCode == 2) { ndbout << "4115 should not happen in flexBench" << endl; tResult = 20; } else if (retCode == 3) {// --------------------------------------------------------------------// We are not certain if the transaction was successful or not.// We must reexecute but might very well find that the transaction// actually was updated. Updates and Reads are no problem here. Inserts// will not cause a problem if error code 630 arrives. Deletes will// not cause a problem if 626 arrives.// -------------------------------------------------------------------- /* What can we do here? */ ndbout_c("execute: %s", MyTransaction->getNdbError().message ); }//if(retCode == 3) } // if pNdb->closeTransaction(MyTransaction); } // else } // for opCount return(tResult);} // deleteRows//////////////////////////////////////////// Name: verifyDeleteRows//// Purpose: Verifies that all tables are empty by reading every tuple// No deletions made here//// Returns: 'Standard' error codes///////////////////////////////////////static int verifyDeleteRows(Ndb* pNdb, int* pkValue, int* readValue){ int tResult = 0; int tableCount = 0; int attrCount = 0; int check = 0; NdbConnection* MyTransaction = NULL; NdbOperation* MyOperations = NULL; NdbRecAttr* tmp = NULL; int Value = 0; int Index = 0; int opCount = 0; for (opCount = 0; opCount < tNoOfOperations; opCount++) { for (tableCount = 0; tableCount < tNoOfTables; tableCount++) { MyTransaction = pNdb->startTransaction(); if (MyTransaction == NULL) { tResult = 1; } // if else { MyOperations = MyTransaction->getNdbOperation(tableName[tableCount]); if (MyOperations == NULL) { tResult = 2; // Break for tableCount loop break; } // if check = MyOperations->readTuple(); if (check == -1) { tResult = 3; break; } // if check = MyOperations-> equal((char*)attrName[0], (char*)&(pkValue[opCount])); if (check == -1) { tResult = 7; break; } // if for (int attrCount = 0; attrCount < tNoOfAttributes - 1; attrCount++) { Index = tableCount * (tNoOfAttributes - 1) * tNoOfOperations * tAttributeSize + attrCount * tNoOfOperations * tAttributeSize + opCount * tAttributeSize; tmp = MyOperations-> getValue((char*)attrName[attrCount + 1], (char*)&(readValue[Index])); if (tmp == NULL) { tResult = 9; break; } // if } // for attrCount // Execute transaction reading one tuple in every table check = MyTransaction->execute(Commit); if ((check == -1) && (MyTransaction->getNdbError().code == 626)){ // This is expected because everything should be deleted } // if else if (check == 0) { // We have found a tuple that should have been deleted ndbout << "tuple " << tableName[tableCount] << ":" << opCount << " was never deleted" << endl; tResult = 97; } // else if else { // Unexpected error ndbout << "Unexpected error during delete" << endl; assert(false); } // else pNdb->closeTransaction(MyTransaction); } // else } // for tableCount } // for opCount return(tResult);} // verifyDeleteRows
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?