flexscan.cpp
来自「MySQL数据库开发源码 值得一看哦」· C++ 代码 · 共 1,668 行 · 第 1/4 页
CPP
1,668 行
ndbout << "-l <int> Number of loops to run, default 1, 0=infinite" << endl; ndbout << "-a <int> Number of attributes, default 25" << endl; ndbout << "-c <int> Number of tables, default 1" << endl; ndbout << "-s <int> Size of each attribute, default 1" << endl; ndbout << "-stdtables Use standard table names" << endl; ndbout << "-no_table_create Don't create tables in db" << endl; ndbout << "-sleep <int> Sleep a number of seconds before running the test" << endl; ndbout << "-p <int> Parallellism to use 1-32, default:1" << endl; ndbout << "-abort <int> Test scan abort after a number of tuples" << endl; ndbout << "-no_scan_update Don't do scan updates" << endl; ndbout << "-no_scan_delete Don't do scan deletes" << endl; ndbout << "-h Print this text" << endl; // inputErrorArg(); flexScanErrorData->printCmdLineArgs(ndbout);}static int readArguments(int argc, const char** argv){ int i = 1; int retValue = 0; int printFlag = 0; tNoOfThreads = 1; // Set default Value tNoOfTables = 1; // Default Value while (argc > 1) { if (strcmp(argv[i], "-t") == 0) { if (argv[i + 1] != NULL) { tNoOfThreads = atoi(argv[i + 1]); if ((tNoOfThreads < 1) || (tNoOfThreads > MAXTHREADS)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // if else if (strcmp(argv[i], "-o") == 0) { if (argv[i + 1] != NULL) { tNoOfOperations = atoi(argv[i + 1]); if (tNoOfOperations < 1) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-a") == 0) { if (argv[i + 1] != NULL) { tNoOfAttributes = atoi(argv[i + 1]); if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-c") == 0) { if (argv[i + 1] != NULL) { tNoOfTables = atoi(argv[i+1]); if ((tNoOfTables < 1) || (tNoOfTables > MAXTABLES)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-l") == 0) { if (argv[i + 1] != NULL) { tNoOfLoops = atoi(argv[i+1]); if ((tNoOfLoops < 0) || (tNoOfLoops > 100000)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-s") == 0) { if (argv[i + 1] != NULL) { tAttributeSize = atoi(argv[i+1]); if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-no_table_create") == 0) { theTableCreateFlag = 1; argc++; i--; } // else if else if (strcmp(argv[i], "-stdtables") == 0) { theStdTableNameFlag = 1; argc++; i--; } // else if else if (strcmp(argv[i], "-sleep") == 0) { if (argv[i + 1] != NULL) { tSleepTime = atoi(argv[i+1]); if ((tSleepTime < 1) || (tSleepTime > 3600)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-abort") == 0) { // Test scan abort after a number of tuples theScanAbortTestFlag = 1; if (argv[i + 1] != NULL) { tAbortAfter = atoi(argv[i + 1]); } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-p") == 0) { if (argv[i + 1] != NULL) { tParallellism = atoi(argv[i + 1]); if ((tParallellism < 1) || (tParallellism > 32)) { retValue = -1; } // if } // if else { retValue = -1; } // else } // else if else if (strcmp(argv[i], "-h") == 0) { printFlag = 1; argc++; i--; } // else if else if (strcmp(argv[i], "-no_scan_update") == 0) { theNoScanUpdateFlag = 1; argc++; i--; } // else if else if (strcmp(argv[i], "-no_scan_delete") == 0) { theNoScanDeleteFlag = 1; argc++; i--; } // else if else { retValue = -1; } // else argc -= 2; i = i + 2; } if ((retValue != 0) || (printFlag == 1)) { printUsage(); } // if return(retValue); } // readArgumentsstatic void sleepBeforeStartingTest(int seconds){ if (seconds > 0) { ndbout << "Sleeping(" <<seconds << ")..."; NdbSleep_SecSleep(seconds); ndbout << " done!" << endl; } // if} // sleepBeforeStartingTeststatic void setAttrValues(int* attrValue, int* readValue, int Offset){ int tableCount = 0; int attrCount = 0; int OpCount = 0; int attrSize = 0; int* pAttr = NULL; int* pRead = NULL; // Set attribute values in memory array for (tableCount = 0; tableCount < tNoOfTables; tableCount++) { for (attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) { for (OpCount = 0; OpCount < tNoOfOperations; OpCount++) { pAttr = &(attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations + attrCount*tNoOfOperations + OpCount]); pRead = &(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations + attrCount*tNoOfOperations + OpCount]); for (attrSize = 0; attrSize < tAttributeSize; attrSize++){ *pAttr = (int)(Offset + tableCount + attrCount + OpCount + attrSize); //ndbout << "attrValue[" << tableCount*(tNoOfAttributes-1)*tNoOfOperations + //attrCount*tNoOfOperations + OpCount + attrSize << "] = " << //attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations + //attrCount*tNoOfOperations + OpCount + attrSize] << endl; *pRead = 0; pAttr++; pRead++; } // for attrSize } // for OpCount } // for attrCount } // for tableCount } // setAttrValuesstatic int insertRows(Ndb* pNdb, // NDB object int* pkValue, // Primary key values int* attrValue, // Attribute values StartType tType){ int tResult = 0; int check = 0; int tableCount = 0; int attrCount = 0; NdbConnection* MyTransaction = NULL; NdbOperation* MyOperations[MAXTABLES] = {NULL}; int opCount = 0; 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 if (tType == stUpdate) { check = MyOperations[tableCount]->updateTuple(); } // if else if (tType == stInsert) { check = MyOperations[tableCount]->insertTuple(); } // else if else { assert(false); } // else 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 (attrCount = 0; attrCount < tNoOfAttributes - 1; attrCount++) { int Index = tableCount * (tNoOfAttributes - 1) * tNoOfOperations * tAttributeSize + attrCount * tNoOfOperations * tAttributeSize + opCount * tAttributeSize; check = MyOperations[tableCount]-> setValue((char*)attrName[attrCount + 1], (char*)&(attrValue[Index])); if (check == -1) { tResult = 8; break; // break attrCount loop } // if } // for } // for tableCount // Execute transaction with insert 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, %d, %s", opCount, tType, 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(check == -1) pNdb->closeTransaction(MyTransaction); } // else } // for opCount return(tResult);} // insertRowsstatic int readRows(Ndb* pNdb, int* pkValue, int* readValue){ int tResult = 0; int tableCount = 0; int attrCount = 0; int check = 0; NdbConnection* MyTransaction = NULL; NdbOperation* MyOperations[MAXTABLES] = {NULL}; NdbRecAttr* tmp = NULL; int Value = 0; int Index = 0; int opCount = 0; 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]->readTuple(); 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 (int attrCount = 0; attrCount < tNoOfAttributes - 1; attrCount++) { Index = tableCount * (tNoOfAttributes - 1) * tNoOfOperations * tAttributeSize + attrCount * tNoOfOperations * tAttributeSize + opCount * tAttributeSize; tmp = MyOperations[tableCount]-> getValue((char*)attrName[attrCount + 1], (char*)&(readValue[Index])); if (tmp == NULL) { tResult = 9; break; } // if } // for attrCount } // for tableCount // Execute transaction reading 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);} // readRowsstatic int scanReadRows(Ndb* pNdb, int* readValue){ int tResult = 0; int tableCount = 0; int attrCount = 0; int check = 0; int countAbort = 0; // Counts loops until scan abort if requested NdbConnection* MyTransaction = NULL; NdbOperation* MyOperation = NULL; NdbRecAttr* tmp = NULL; for (tableCount = 0; tableCount < tNoOfTables; tableCount++) { MyTransaction = pNdb->startTransaction(); if (MyTransaction == NULL) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?