flexscan.cpp
来自「MySQL数据库开发源码 值得一看哦」· C++ 代码 · 共 1,668 行 · 第 1/4 页
CPP
1,668 行
resetThreads(pThreads); // Update START_TIMER; tellThreads(pThreads, stUpdate); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "update") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("update", tNoOfOperations*tNoOfThreads, tNoOfTables); resetThreads(pThreads); // Scan read START_TIMER; tellThreads(pThreads, stScanRead); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "scanread") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("scanread", tNoOfTables*tNoOfThreads, 1); resetThreads(pThreads); // Update START_TIMER; tellThreads(pThreads, stUpdate); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "update") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("update", tNoOfOperations*tNoOfThreads, tNoOfTables); resetThreads(pThreads); // Read START_TIMER; tellThreads(pThreads, stRead); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "read") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables); resetThreads(pThreads); // Only do scan update if told to do so if (theNoScanUpdateFlag == 0) { // Scan update START_TIMER; tellThreads(pThreads, stScanUpdate); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "scanupdate") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("scanupdate", tNoOfTables*tNoOfThreads, 1); resetThreads(pThreads); // Read START_TIMER; tellThreads(pThreads, stRead); // tellThreads(pThreads, stScanRead); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "read") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables); resetThreads(pThreads); } // if theNoScanUpdateFlag // Shift between delete and scan delete if ((every2ndScanDelete % 2 == 0) || (theNoScanDeleteFlag == 1)){ // Delete START_TIMER; tellThreads(pThreads, stDelete); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "delete") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("delete", tNoOfOperations*tNoOfThreads, tNoOfTables); resetThreads(pThreads); } // if else { resetThreads(pThreads); // Scan delete START_TIMER; tellThreads(pThreads, stScanDelete); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "scandelete") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("scandelete", tNoOfTables*tNoOfThreads, 1); resetThreads(pThreads); } // else every2ndScanDelete++; resetThreads(pThreads); // Verify delete START_TIMER; tellThreads(pThreads, stVerifyDelete); waitForThreads(pThreads); STOP_TIMER; if (checkThreadResults(pThreads, "verifydelete") != 0) { returnValue = NDBT_FAILED; break; } // if PRINT_TIMER("verifydelete", tNoOfOperations*tNoOfThreads*tNoOfTables, 1); resetThreads(pThreads); ndbout << "--------------------------------------------------" << endl; tLoops++; } // while } // if } // else } // else // Stop threads in a nice way tellThreads(pThreads, stStop); waitForThreads(pThreads); // Clean up delete [] pThreads; delete pMyNdb; flexScanErrorData->printErrorCounters(ndbout); if (returnValue == NDBT_OK) { ndbout << endl << "Benchmark completed successfully" << endl; } // if else { ndbout << endl << "Benchmark failed" << endl; } // else // Exit via NDBT return NDBT_ProgramExit(returnValue);;} // mainvoid*flexScanThread(void* ThreadData){ ThreadNdb* pThreadData = (ThreadNdb*)ThreadData; unsigned int thread_no = pThreadData->ThreadNo; unsigned int thread_base = (thread_no * 2000000) + (tNodeId * 26000); int tThreadResult = 0; Ndb* MyNdb = NULL; int check = 0; StartType tType = stLast; int* pkValue = NULL; int* attrValue = NULL; int* readValue = NULL; int AllocSize = 0; AllocSize = tNoOfTables * (tNoOfAttributes-1) * tNoOfOperations * tAttributeSize * sizeof(int); attrValue = (int*)malloc(AllocSize); readValue = (int*)malloc(AllocSize); pkValue = (int*)malloc(tNoOfOperations * sizeof(int)); if ((attrValue == NULL) || (readValue == NULL) || (pkValue == NULL)) { tThreadResult = 98; pThreadData->threadStart = stIdle; } // if setAttrValues(attrValue, readValue, thread_base); MyNdb = new Ndb( "TEST_DB" ); MyNdb->init(); if (MyNdb->waitUntilReady(10000) != 0) { tThreadResult = 99; pThreadData->threadStart = stIdle; } // if // Set primary key value, same for all tables for (int c = 0; c < tNoOfOperations; c++) { pkValue[c] = (int)(c + thread_base); } // for while (FOREVER) { pThreadData->threadResult = tThreadResult; pThreadData->threadReady = 1; while (pThreadData->threadStart == stIdle) { NdbSleep_MilliSleep(10); } // while // Check if signal to exit is received if (pThreadData->threadStart >= stStop){ pThreadData->threadReady = 1; break; } // if tType = pThreadData->threadStart; pThreadData->threadStart = stIdle; switch (tType) { case stInsert: check = insertRows(MyNdb, pkValue, attrValue, tType); break; case stRead: check = readRows(MyNdb, pkValue, readValue); Compare(attrValue, readValue); break; case stUpdate: UpdateArray(attrValue); check = insertRows(MyNdb, pkValue, attrValue, tType); break; case stScanRead: //check = readRows(MyNdb, pkValue, readValue); check = scanReadRows(MyNdb, readValue); Compare(attrValue, readValue); break; case stScanUpdate: UpdateArray(attrValue); //tType = stUpdate; //check = insertRows(MyNdb, pkValue, attrValue, tType); check = scanUpdateRows(MyNdb, readValue, attrValue); break; case stDelete: check = deleteRows(MyNdb, pkValue); break; case stScanDelete: check = scanDeleteRows(MyNdb, readValue); break; case stVerifyDelete: check = verifyDeleteRows(MyNdb, pkValue, readValue); break; default: ndbout << "tType is " << tType << endl; assert(false); break; } // switch tThreadResult = check; if (tThreadResult != 0) { // Check if error is fatak or not } // if else { continue; } // else } // while // Clean up delete MyNdb; if (attrValue != NULL) { free(attrValue); } //if if (readValue != NULL) { free(readValue); } // if if (pkValue != NULL) { free(pkValue); } // if return NULL; // thread exits} // flexScanThreadstatic int setAttrNames(){ int i = 0; int retVal = 0; for (i = 0; i < MAXATTR ; i++) { retVal = BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i); if (retVal < 0) { return(-1); } // if } // for return(0);} // setAttrNamesstatic int setTableNames(){ // Note! Uses only uppercase letters in table name's // so that we can look at the tables with SQL int i = 0; int retVal = 0; for (i = 0; i < MAXTABLES ; i++) { if (theStdTableNameFlag == 0) { retVal = BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i, (int)(NdbTick_CurrentMillisecond() / 1000)); } // if else { retVal = BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i); } // if else if (retVal < 0) { return(-1); } // if } // for return(0);} // setTableNames// Create Table and Attributes. static int createTables(Ndb* pMyNdb){ NdbSchemaCon *MySchemaTransaction = NULL; NdbSchemaOp *MySchemaOp = NULL; int i = 0; int j = 0; int check = 0; if (theTableCreateFlag == 0) { i = 0; do { i++; ndbout << endl << "Creating " << tableName[i - 1] << "..." << endl; MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pMyNdb); if( MySchemaTransaction == NULL ) { return (-1); } // if MySchemaOp = MySchemaTransaction->getNdbSchemaOp(); if( MySchemaOp == NULL ) { NdbSchemaCon::closeSchemaTrans(MySchemaTransaction); return (-1); } // if#if defined NDB_OSE || defined NDB_SOFTOSE check = MySchemaOp->createTable(tableName[i - 1], 8, // Table Size TupleKey, // Key Type 40, // Nr of Pages All, 6, 78, 80, 1, false);#else check = MySchemaOp->createTable(tableName[i - 1] ,8 // Table Size ,TupleKey // Key Type ,40); // Nr of Pages#endif if (check == -1) { NdbSchemaCon::closeSchemaTrans(MySchemaTransaction); return -1; } // if check = MySchemaOp->createAttribute( (char*)attrName[0], TupleKey, 32, PKSIZE, UnSigned, MMBased, NotNullAttribute ); if (check == -1) { NdbSchemaCon::closeSchemaTrans(MySchemaTransaction); return -1; } // if for (j = 1; j < tNoOfAttributes ; j++) { check = MySchemaOp->createAttribute( (char*)attrName[j], NoKey, 32, tAttributeSize, UnSigned, MMBased, NotNullAttribute ); if (check == -1) { NdbSchemaCon::closeSchemaTrans(MySchemaTransaction); return -1; } // if } // for if (MySchemaTransaction->execute() == -1) { ndbout << MySchemaTransaction->getNdbError().message << endl; ndbout << "Probably, " << tableName[i - 1] << " already exist" << endl; } // if NdbSchemaCon::closeSchemaTrans(MySchemaTransaction); } while (tNoOfTables > i); } return 0;} // createTablesstatic void printUsage(){ ndbout << "Usage of flexScan:" << endl; ndbout << "-f <path> Location of Ndb.cfg file, default: Ndb.cfg" << endl; ndbout << "-t <int> Number of threads to start, default 1" << endl; ndbout << "-o <int> Number of operations per loop, default 500" << endl;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?