📄 testindex.cpp
字号:
ndbout << "Updating records..." << endl; CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); ndbout << "Restarting cluster..." << endl; CHECK(restarter.restartAll() == 0); CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); ndbout << "Verifying records..." << endl; CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == records); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); ndbout << "Deleting 50% of records..." << endl; CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); ndbout << "Restarting cluster..." << endl; CHECK(restarter.restartAll() == 0); CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); ndbout << "Verifying records..." << endl; CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == (records/2)); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); ndbout << "Deleting all records..." << endl; CHECK(utilTrans.clearTable(pNdb, records/2) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); ndbout << "Restarting cluster..." << endl; CHECK(restarter.restartAll() == 0); CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); ndbout << "Verifying records..." << endl; CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); ndbout << "Doing it all..." << endl; CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0); CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(utilTrans.clearTable(pNdb, records) == 0); CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0); CHECK(utilTrans.clearTable(pNdb, records) == 0); CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0); CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.clearTable(pNdb, records) == 0); ndbout << "Restarting cluster..." << endl; CHECK(restarter.restartAll() == 0); CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); ndbout << "Verifying records..." << endl; CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == 0); ndbout << "Doing it all..." << endl; CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0); CHECK(utilTrans.clearTable(pNdb, records) == 0); CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0); CHECK(utilTrans.clearTable(pNdb, records) == 0); ndbout << "Restarting cluster with error insert 5020..." << endl; CHECK(restarter.restartAll(false, true) == 0); CHECK(restarter.waitClusterNoStart(timeout) == 0); CHECK(restarter.insertErrorInAllNodes(5020) == 0); CHECK(restarter.startAll() == 0); CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); i++; } ctx->stopTest(); ndbout << "runSystemRestart1 finished" << endl; return result;}#define CHECK2(b, t) if(!b){ g_err << __LINE__ << ": " << t << endl; break;}intrunMixed1(NDBT_Context* ctx, NDBT_Step* step){ // Verify that data in index match // table data Ndb* pNdb = GETNDB(step); HugoOperations hugoOps(*ctx->getTab()); do { // TC1 g_err << "pkRead, indexRead, Commit" << endl; CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction"); CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords"); CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord"); CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit"); CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction"); // TC1 g_err << "pkRead, indexRead, Commit" << endl; CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction"); CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord"); CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords"); CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit"); CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction"); // TC2 g_err << "pkRead, indexRead, NoCommit, Commit" << endl; CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction"); CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord"); CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords"); CHECK2(hugoOps.execute_NoCommit(pNdb) == 0, "executeNoCommit"); CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit"); CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction"); // TC3 g_err << "pkRead, pkRead, Commit" << endl; CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction "); CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecords "); CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecords "); CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit"); CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction "); // TC4 g_err << "indexRead, indexRead, Commit" << endl; CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction "); CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords"); CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords"); CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit"); CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction "); return NDBT_OK; } while(false); hugoOps.closeTransaction(pNdb); return NDBT_FAILED;}intrunBuildDuring(NDBT_Context* ctx, NDBT_Step* step){ // Verify that data in index match // table data const int Threads = ctx->getProperty("Threads", (Uint32)0); const int loops = ctx->getNumLoops(); for(int i = 0; i<loops; i++){#if 1 if(createPkIndex(ctx, step) != NDBT_OK){ g_err << "Failed to create index" << endl; return NDBT_FAILED; }#endif if(ctx->isTestStopped()) break;#if 1 if(createRandomIndex(ctx, step) != NDBT_OK){ g_err << "Failed to create index" << endl; return NDBT_FAILED; }#endif if(ctx->isTestStopped()) break; ctx->setProperty("pause", 1); int count = 0; for(int j = 0; count < Threads && !ctx->isTestStopped(); j = (j+1) % Threads){ char buf[255]; sprintf(buf, "Thread%d_paused", j); int tmp = ctx->getProperty(buf, (Uint32)0); count += tmp; } if(ctx->isTestStopped()) break;#if 1 if(createPkIndex_Drop(ctx, step) != NDBT_OK){ g_err << "Failed to drop index" << endl; return NDBT_FAILED; }#endif if(ctx->isTestStopped()) break; #if 1 if(createRandomIndex_Drop(ctx, step) != NDBT_OK){ g_err << "Failed to drop index" << endl; return NDBT_FAILED; }#endif ctx->setProperty("pause", (Uint32)0); NdbSleep_SecSleep(2); } ctx->stopTest(); return NDBT_OK;}static NdbLockable g_lock;static int threadCounter = 0;voidwait_paused(NDBT_Context* ctx, int id){ if(ctx->getProperty("pause", (Uint32)0) == 1){ char buf[255]; sprintf(buf, "Thread%d_paused", id); ctx->setProperty(buf, 1); while(!ctx->isTestStopped() && ctx->getProperty("pause", (Uint32)0) == 1){ NdbSleep_MilliSleep(250); } ctx->setProperty(buf, (Uint32)0); }}intrunTransactions4(NDBT_Context* ctx, NDBT_Step* step){ g_lock.lock(); const int ThreadId = threadCounter++; g_lock.unlock(); // Verify that data in index match // table data Ndb* pNdb = GETNDB(step); HugoTransactions hugoTrans(*ctx->getTab()); UtilTransactions utilTrans(*ctx->getTab()); const int batchSize = ctx->getProperty("BatchSize", 32); const int parallel = batchSize > 240 ? 240 : batchSize; int rows = ctx->getNumRecords(); while (ctx->isTestStopped() == false) { if(hugoTrans.loadTable(pNdb, rows, batchSize, false) != 0){ g_err << "Load table failed" << endl; return NDBT_FAILED; } wait_paused(ctx, ThreadId); if(ctx->isTestStopped()) break; if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){ g_err << "Updated table failed" << endl; return NDBT_FAILED; } wait_paused(ctx, ThreadId); if(ctx->isTestStopped()) break; if (hugoTrans.scanUpdateRecords(pNdb, rows, 5, parallel) != 0){ g_err << "Scan updated table failed" << endl; return NDBT_FAILED; } wait_paused(ctx, ThreadId); if(ctx->isTestStopped()) break; if(utilTrans.clearTable(pNdb, rows, parallel) != 0){ g_err << "Clear table failed" << endl; return NDBT_FAILED; } } return NDBT_OK;}intrunUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); bool logged = ctx->getProperty("LoggedIndexes", 1); bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0); NdbConnection * pTrans = 0; const NdbDictionary::Table* pTab = ctx->getTab(); // Create index char nullIndex[255]; BaseString::snprintf(nullIndex, 255, "IDC_PK_%s_NULL", pTab->getName()); if (orderedIndex) ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index " << pkIdxName << " ("; else ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index " << pkIdxName << " ("; NdbDictionary::Index pIdx(pkIdxName); pIdx.setTable(pTab->getName()); if (orderedIndex) pIdx.setType(NdbDictionary::Index::OrderedIndex); else pIdx.setType(NdbDictionary::Index::UniqueHashIndex); pIdx.setStoredIndex(logged); int c; for (c = 0; c< pTab->getNoOfColumns(); c++){ const NdbDictionary::Column * col = pTab->getColumn(c); if(col->getPrimaryKey()){ pIdx.addIndexColumn(col->getName()); ndbout << col->getName() <<" "; } } int colId = -1; for (c = 0; c< pTab->getNoOfColumns(); c++){ const NdbDictionary::Column * col = pTab->getColumn(c); if(col->getNullable()){ pIdx.addIndexColumn(col->getName()); ndbout << col->getName() <<" "; colId = c; break; } } ndbout << ") "; if(colId == -1){ ndbout << endl << "No nullable column found -> NDBT_FAILED" << endl; return NDBT_FAILED; } if (pNdb->getDictionary()->createIndex(pIdx) != 0){ ndbout << "FAILED!" << endl; const NdbError err = pNdb->getDictionary()->getNdbError(); ERR(err); return NDBT_FAILED; } int result = NDBT_OK; HugoTransactions hugoTrans(*ctx->getTab()); const int batchSize = ctx->getProperty("BatchSize", 50); int loops = ctx->getNumLoops(); int rows = ctx->getNumRecords(); while (loops-- > 0 && ctx->isTestStopped() == false) { if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){ g_err << "Updated table failed" << endl; result = NDBT_FAILED; goto done; } } if(ctx->isTestStopped()){ goto done; } ctx->stopTest(); while(ctx->getNoOfRunningSteps() > 1){ NdbSleep_MilliSleep(100); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -