int runVerifyOne(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); Ndb* pNdb = GETNDB(step); int result = NDBT_OK; int count = 0; const NdbDictionary::Table* tab = GETNDB(step)->getDictionary()->getTable(ctx->getTab()->getName()); if(tab == 0) return NDBT_FAILED; UtilTransactions utilTrans(* tab); HugoTransactions hugoTrans(* tab); do{ // Check that there are as many records as we expected CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); g_err << "count = " << count; g_err << " records = " << records; g_err << endl; CHECK(count == records); // Read and verify every record CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0); } while (false); return result; }
int runScanJoin(NDBT_Context* ctx, NDBT_Step* step){ int loops = ctx->getNumLoops(); int joinlevel = ctx->getProperty("JoinLevel", 3); int until_stopped = ctx->getProperty("UntilStopped", (Uint32)0); Uint32 stepNo = step->getStepNo(); int i = 0; HugoQueryBuilder qb(GETNDB(step), ctx->getTab(), HugoQueryBuilder::O_SCAN); qb.setJoinLevel(joinlevel); const NdbQueryDef * query = qb.createQuery(GETNDB(step)); HugoQueries hugoTrans(* query); while ((i<loops || until_stopped) && !ctx->isTestStopped()) { g_info << i << ": "; if (hugoTrans.runScanQuery(GETNDB(step))) { g_info << endl; return NDBT_FAILED; } addMask(ctx, (1 << stepNo), "Running"); i++; } g_info << endl; return NDBT_OK; }
int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){ int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); int batchSize = ctx->getProperty("BatchSize", 1); int transactions = (records / 100) + 1; int operations = (records / transactions) + 1; int i = 0; HugoAsynchTransactions hugoTrans(*ctx->getTab()); while (i<loops) { ndbout << i << ": "; if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize, transactions, operations) != 0){ return NDBT_FAILED; } // Load table, don't allow any primary key violations if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize, transactions, operations) != 0){ return NDBT_FAILED; } i++; } return NDBT_OK; }
int runVerifyUndoData(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); Ndb* pNdb = GETNDB(step); int count = 0; int num = 5; if (records - 5 < 0) num = 1; const NdbDictionary::Table* tab = GETNDB(step)->getDictionary()->getTable(ctx->getTab()->getName()); if(tab == 0) { g_err << " Can't find table" << endl; return NDBT_FAILED; } UtilTransactions utilTrans(* tab); HugoTransactions hugoTrans(* tab); // Check that there are as many records as we expected if(utilTrans.selectCount(pNdb, 64, &count) != 0) { g_err << "Can't get records count" << endl; return NDBT_FAILED; } g_err << "count = " << count; g_err << " records = " << records; g_err << endl; if (count != records) { g_err << "The records count is not correct" << endl; return NDBT_FAILED; } // make sure all the update data is there NdbTransaction *pTransaction= pNdb->startTransaction(); if (pTransaction == NULL) { g_err << "Can't get transaction pointer" << endl; return NDBT_FAILED; } if(hugoTrans.setTransaction(pTransaction) != 0) { g_err << "Set transaction error" << endl; pNdb->closeTransaction(pTransaction); return NDBT_FAILED; } if(hugoTrans.pkReadRecord(pNdb, 0, records, NdbOperation::LM_Read) != 0) { g_err << "Can't read record" << endl; return NDBT_FAILED; } if(hugoTrans.verifyUpdatesValue(0, records) != 0) { g_err << "The records restored with undo log is not correct" << endl; return NDBT_FAILED; } hugoTrans.closeTransaction(pNdb); return NDBT_OK; }
int runBackupBank(NDBT_Context* ctx, NDBT_Step* step){ int loops = ctx->getNumLoops(); int l = 0; int maxSleep = 30; // Max seconds between each backup Ndb* pNdb = GETNDB(step); NdbBackup backup(GETNDB(step)->getNodeId()+1); unsigned minBackupId = ~0; unsigned maxBackupId = 0; unsigned backupId = 0; int result = NDBT_OK; while (l < loops && result != NDBT_FAILED){ if (pNdb->waitUntilReady() != 0){ result = NDBT_FAILED; continue; } // Sleep for a while NdbSleep_SecSleep(maxSleep); // Perform backup if (backup.start(backupId) != 0){ ndbout << "backup.start failed" << endl; result = NDBT_FAILED; continue; } ndbout << "Started backup " << backupId << endl; // Remember min and max backupid if (backupId < minBackupId) minBackupId = backupId; if (backupId > maxBackupId) maxBackupId = backupId; ndbout << " maxBackupId = " << maxBackupId << ", minBackupId = " << minBackupId << endl; ctx->setProperty("MinBackupId", minBackupId); ctx->setProperty("MaxBackupId", maxBackupId); l++; } ctx->stopTest(); return result; }
int runRestartGciControl(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); Ndb* pNdb = GETNDB(step); UtilTransactions utilTrans(*ctx->getTab()); NdbRestarter restarter; // Wait until we have enough records in db int count = 0; while (count < records){ if (utilTrans.selectCount(pNdb, 64, &count) != 0){ ctx->stopTest(); return NDBT_FAILED; } } // Restart cluster with abort if (restarter.restartAll(false, false, true) != 0){ ctx->stopTest(); return NDBT_FAILED; } // Stop the other thread ctx->stopTest(); if (restarter.waitClusterStarted(300) != 0){ return NDBT_FAILED; } if (pNdb->waitUntilReady() != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runInsertRememberGci(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int records = ctx->getNumRecords(); HugoOperations hugoOps(*ctx->getTab()); Ndb* pNdb = GETNDB(step); int i = 0; while(ctx->isTestStopped() == false && i < records){ // Insert record and read it in same transaction CHECK(hugoOps.startTransaction(pNdb) == 0); CHECK(hugoOps.pkInsertRecord(pNdb, i) == 0); if (hugoOps.execute_NoCommit(pNdb) != 0){ ndbout << "Could not insert record " << i << endl; result = NDBT_FAILED; break; } CHECK(hugoOps.pkReadRecord(pNdb, i) == 0); if (hugoOps.execute_Commit(pNdb) != 0){ ndbout << "Did not find record in DB " << i << endl; result = NDBT_FAILED; break; } savedRecords.push_back(SavedRecord(hugoOps.getRecordGci(0), hugoOps.getRecordStr(0))); CHECK(hugoOps.closeTransaction(pNdb) == 0); i++; }; return result; }
int runSetup(NDBT_Context* ctx, NDBT_Step* step, int waitGroupSize){ int records = ctx->getNumRecords(); int batchSize = ctx->getProperty("BatchSize", 1); int transactions = (records / 100) + 1; int operations = (records / transactions) + 1; Ndb* pNdb = GETNDB(step); HugoAsynchTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTableAsynch(pNdb, records, batchSize, transactions, operations) != 0){ return NDBT_FAILED; } Ndb_cluster_connection* conn = &pNdb->get_ndb_cluster_connection(); /* The first call to create_multi_ndb_wait_group() should succeed ... */ global_poll_group = conn->create_ndb_wait_group(waitGroupSize); if(global_poll_group == 0) { return NDBT_FAILED; } /* and subsequent calls should fail */ if(conn->create_ndb_wait_group(waitGroupSize) != 0) { return NDBT_FAILED; } return NDBT_OK; }
int runMiscUntilStopped(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); int i = 0; Ndb * ndb = GETNDB(step); HugoTransactions hugoTrans(*ctx->getTab()); while (ctx->isTestStopped() == false) { int r = 0; switch(i % 5) { case 0: // batch size = 2, random = 1 r = hugoTrans.pkReadRecords(ndb, records / 20, 2, NdbOperation::LM_Read, 1); break; case 1: r = hugoTrans.pkUpdateRecords(ndb, records / 20); break; case 2: r = hugoTrans.scanReadRecords(ndb, records); break; case 3: r = hugoTrans.scanUpdateRecords(ndb, records / 10); break; case 4: NdbSleep_MilliSleep(records); break; } if(r != 0) return NDBT_FAILED; i++; } ndbout << "V2 Test misc thread: " << i << " transactions" << endl; return NDBT_OK; }
int runCreateIndexT1(NDBT_Context* ctx, NDBT_Step* step) { Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* pDict = pNdb->getDictionary(); const NdbDictionary::Table* pTab = pDict->getTable("T1"); if (pTab == 0) { g_err << "getTable(T1) error: " << pDict->getNdbError() << endl; return NDBT_FAILED; } NdbDictionary::Index ind; ind.setName("T1X1"); ind.setTable("T1"); ind.setType(NdbDictionary::Index::OrderedIndex); ind.setLogging(false); ind.addColumn("KOL2"); ind.addColumn("KOL3"); ind.addColumn("KOL4"); if (pDict->createIndex(ind, *pTab) != 0) { g_err << "createIndex(T1X1) error: " << pDict->getNdbError() << endl; return NDBT_FAILED; } return NDBT_OK; }
int dropTable(NDBT_Context* ctx, NDBT_Step* step, Uint32 num) { Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab= ctx->getTab(); /* Run as a 'T1' testcase - do nothing for other tables */ if (strcmp(pTab->getName(), "T1") != 0) return NDBT_OK; char tabnameBuff[10]; snprintf(tabnameBuff, sizeof(tabnameBuff), "TAB%u", num); if (pNdb->getDictionary()->dropTable(tabnameBuff) != 0) { ndbout << "Drop table failed with error : " << pNdb->getDictionary()->getNdbError().code << " " << pNdb->getDictionary()->getNdbError().message << endl; } else { ndbout << "Dropped table " << tabnameBuff << endl; } return NDBT_OK; }
int runBug24717(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); NdbRestarter restarter; Ndb* pNdb = GETNDB(step); HugoTransactions hugoTrans(*ctx->getTab()); int dump[] = { 9002, 0 } ; Uint32 ownNode = refToNode(pNdb->getReference()); dump[1] = ownNode; for (; loops; loops --) { int nodeId = restarter.getRandomNotMasterNodeId(rand()); restarter.restartOneDbNode(nodeId, false, true, true); restarter.waitNodesNoStart(&nodeId, 1); if (restarter.dumpStateOneNode(nodeId, dump, 2)) return NDBT_FAILED; restarter.startNodes(&nodeId, 1); do { for (Uint32 i = 0; i < 100; i++) { hugoTrans.pkReadRecords(pNdb, 100, 1, NdbOperation::LM_CommittedRead); } } while (restarter.waitClusterStarted(5) != 0); } return NDBT_OK; }
int runError4012(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int stepNo = step->getStepNo(); int timeout = ctx->getProperty("TransactionDeadlockTimeout", TIMEOUT); HugoOperations hugoOps(*ctx->getTab()); Ndb* pNdb = GETNDB(step); do{ // Commit transaction CHECK(hugoOps.startTransaction(pNdb) == 0); CHECK(hugoOps.pkUpdateRecord(pNdb, 0) == 0); int ret = hugoOps.execute_NoCommit(pNdb); if (ret == 0) { int sleep = timeout; ndbout << "Sleeping for " << sleep << " milliseconds" << endl; NdbSleep_MilliSleep(sleep); // Expect that transaction has NOT timed-out CHECK(hugoOps.execute_Commit(pNdb) == 0); } else { CHECK(ret == 4012); } } while(false); hugoOps.closeTransaction(pNdb); return result; }
int runDDL(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb= GETNDB(step); NdbDictionary::Dictionary* pDict = pNdb->getDictionary(); const int tables = NDBT_Tables::getNumTables(); while(!ctx->isTestStopped()) { const int tab_no = rand() % (tables); NdbDictionary::Table tab = *NDBT_Tables::getTable(tab_no); BaseString name= tab.getName(); name.appfmt("-%d", step->getStepNo()); tab.setName(name.c_str()); if(pDict->createTable(tab) == 0) { HugoTransactions hugoTrans(* pDict->getTable(name.c_str())); if (hugoTrans.loadTable(pNdb, 10000) != 0){ return NDBT_FAILED; } while(pDict->dropTable(tab.getName()) != 0 && pDict->getNdbError().code != 4009) g_err << pDict->getNdbError() << endl; sleep(1); } } return NDBT_OK; }
static int createDropEvent(NDBT_Context* ctx, NDBT_Step* step) { Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary *myDict = pNdb->getDictionary(); if (ctx->getProperty("NoDDL", Uint32(0)) == 0) { for (unsigned i = 0; i<table_list.size(); i++) { int res = NDBT_OK; const NdbDictionary::Table* tab = myDict->getTable(table_list[i].c_str()); if (tab == 0) { continue; } if ((res = createEvent(pNdb, *tab) != NDBT_OK)) { return res; } if ((res = dropEvent(pNdb, *tab)) != NDBT_OK) { return res; } } } return NDBT_OK; }
int runFail(NDBT_Context* ctx, NDBT_Step* step){ NdbBackup backup(GETNDB(step)->getNodeId()+1); NdbRestarter restarter; if (restarter.getNumDbNodes() < 2){ ctx->stopTest(); return NDBT_OK; } if(restarter.waitClusterStarted(60) != 0){ g_err << "Cluster failed to start" << endl; return NDBT_FAILED; } if (testMaster) { if (testSlave) { if (backup.FailMasterAsSlave(restarter) != NDBT_OK){ return NDBT_FAILED; } } else { if (backup.FailMaster(restarter) != NDBT_OK){ return NDBT_FAILED; } } } else { if (backup.FailSlave(restarter) != NDBT_OK){ return NDBT_FAILED; } } return NDBT_OK; }
int runScanRefreshNoTimeout(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); int stepNo = step->getStepNo(); int maxSleep = (int)(TIMEOUT * 0.3); ndbout << "TransactionInactiveTimeout="<< TIMEOUT << ", maxSleep="<<maxSleep<<endl; HugoOperations hugoOps(*ctx->getTab()); Ndb* pNdb = GETNDB(step); for (int l = 1; l < loops && result == NDBT_OK; l++){ do{ // Start an insert trans CHECK(hugoOps.startTransaction(pNdb) == 0); int recordNo = records + (stepNo*loops) + l; CHECK(hugoOps.pkInsertRecord(pNdb, recordNo) == 0); CHECK(hugoOps.execute_NoCommit(pNdb) == 0); for (int i = 0; i < 3; i++) { NdbTransaction* pTrans = hugoOps.getTransaction(); Vector<NdbScanOperation*> ops; for (int j = 0; j <= i; j++) { // Perform buddy scan reads NdbScanOperation* pOp = pTrans->getNdbScanOperation(ctx->getTab()); CHECK(pOp != 0); CHECK(pOp->readTuples(NdbOperation::LM_Read, 0, 0, 1) == 0); ops.push_back(pOp); } CHECK(pTrans->execute(NoCommit) == 0); for (unsigned i = 0; i<TIMEOUT; i += 1000) { pTrans->refresh(); NdbSleep_MilliSleep(1000); } int res; for (unsigned j = 0; j < ops.size(); j++) { while((res = ops[j]->nextResult()) == 0); CHECK(res != -1); } } // Expect that transaction has NOT timed-out CHECK(hugoOps.execute_Commit(pNdb) == 0); } while(false); hugoOps.closeTransaction(pNdb); } return result; }
int clearOldBackups(NDBT_Context* ctx, NDBT_Step* step) { strcpy(tabname, ctx->getTab()->getName()); NdbBackup backup(GETNDB(step)->getNodeId()); backup.clearOldBackups(); return NDBT_OK; }
int runFillTable(NDBT_Context* ctx, NDBT_Step* step){ HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.fillTable(GETNDB(step)) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runDropTable(NDBT_Context* ctx, NDBT_Step* step) { const NdbDictionary::Table *tab = ctx->getTab(); GETNDB(step)->getDictionary()->dropTable(tab->getName()); return NDBT_OK; }
static int runBug48416(NDBT_Context* ctx, NDBT_Step* step) { Ndb* pNdb = GETNDB(step); return NDBT_Tables::createTable(pNdb, "I1"); }
int runScanReadVerify(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, 64) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); UtilTransactions utilTrans(*ctx->getTab()); if (utilTrans.clearTable2(GETNDB(step), records) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(GETNDB(step), records) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runClearTable(NDBT_Context* ctx, NDBT_Step* step) { UtilTransactions utilTrans(*ctx->getTab()); if (utilTrans.clearTable(GETNDB(step)) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runCreateEvent(NDBT_Context* ctx, NDBT_Step* step) { HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.createEvent(GETNDB(step)) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runDeadlockTimeoutTrans(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int stepNo = step->getStepNo(); Uint32 deadlock_timeout; NdbConfig conf(GETNDB(step)->getNodeId()+1); unsigned int nodeId = conf.getMasterNodeId(); if (!conf.getProperty(nodeId, NODE_TYPE_DB, CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT, &deadlock_timeout)){ return NDBT_FAILED; } int do_sleep = (int)(deadlock_timeout * 0.5); HugoOperations hugoOps(*ctx->getTab()); Ndb* pNdb = GETNDB(step); for (int l = 0; l < loops && result == NDBT_OK; l++){ do{ // Commit transaction CHECK(hugoOps.startTransaction(pNdb) == 0); CHECK(hugoOps.pkReadRecord(pNdb, stepNo) == 0); CHECK(hugoOps.execute_NoCommit(pNdb) == 0); int sleep = deadlock_timeout * 1.5 + myRandom48(do_sleep); ndbout << "Sleeping for " << sleep << " milliseconds" << endl; NdbSleep_MilliSleep(sleep); // Expect that transaction has NOT timed-out CHECK(hugoOps.execute_Commit(pNdb) == 0); } while(false); hugoOps.closeTransaction(pNdb); } return result; }
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); int batchSize = ctx->getProperty("BatchSize", 1); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.pkDelRecords(GETNDB(step), records, batchSize) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runTestIncValue64(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); // NDBT_Table* pTab = ctx->getTab(); //Ndb* pNdb = GETNDB(step); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.pkInterpretedUpdateRecords(GETNDB(step), records) != 0){ return NDBT_FAILED; } // Verify the update if (hugoTrans.pkReadRecords(GETNDB(step), records) != 0){ return NDBT_FAILED; } return NDBT_OK; }
int runEventLoad(NDBT_Context* ctx, NDBT_Step* step) { int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); HugoTransactions hugoTrans(*ctx->getTab()); sleep(5); sleep(theThreadIdCounter); if (hugoTrans.loadTable(GETNDB(step), records, 1, true, loops) != 0){ return NDBT_FAILED; } if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, loops) != 0){ return NDBT_FAILED; } if (hugoTrans.pkDelRecords(GETNDB(step), records, 1, true, loops) != 0){ return NDBT_FAILED; } return NDBT_OK; }