📄 testdict.cpp
字号:
int nodeId = restarter.getRandomNodeOtherNodeGroup(nodeIdList[0], rand); CHECK(nodeId != -1); if (nodeId != masterNodeId) nodeIdList[nodeIdCnt++] = nodeId; } g_info << "1: master=" << masterNodeId << " nodes=" << nodeIdList[0] << "," << nodeIdList[1] << endl; const uint timeout = 60; //secs for node wait const unsigned maxsleep = 2000; //ms bool NF_ops = ctx->getProperty("Restart_NF_ops"); uint NF_type = ctx->getProperty("Restart_NF_type"); bool NR_ops = ctx->getProperty("Restart_NR_ops"); bool NR_error = ctx->getProperty("Restart_NR_error"); g_info << "1: " << (NF_ops ? "run" : "pause") << " dict ops" << endl; if (! send_dict_ops_cmd(ctx, NF_ops ? 1 : 2)) break; NdbSleep_MilliSleep(myRandom48(maxsleep)); { for (int i = 0; i < nodeIdCnt; i++) { int nodeId = nodeIdList[i]; bool nostart = true; bool abort = NF_type == 0 ? myRandom48(2) : (NF_type == 2); bool initial = myRandom48(2); char flags[40]; strcpy(flags, "flags: nostart"); if (abort) strcat(flags, ",abort"); if (initial) strcat(flags, ",initial"); g_info << "1: restart " << nodeId << " " << flags << endl; CHECK(restarter.restartOneDbNode(nodeId, initial, nostart, abort) == 0); } } g_info << "1: wait for nostart" << endl; CHECK(restarter.waitNodesNoStart(nodeIdList, nodeIdCnt, timeout) == 0); NdbSleep_MilliSleep(myRandom48(maxsleep)); int err_master = 0; int err_node[2] = { 0, 0 }; if (NR_error) { err_master = errlst_master[l % errcnt_master]; // limitation: cannot have 2 node restarts and crash_insert // one node may die for real (NF during startup) for (int i = 0; i < nodeIdCnt && nodeIdCnt == 1; i++) { err_node[i] = errlst_node[l % errcnt_node]; // 7176 - no DICT lock protection if (err_node[i] == 7176) { g_info << "1: no dict ops due to error insert " << err_node[i] << endl; NR_ops = false; } } } g_info << "1: " << (NR_ops ? "run" : "pause") << " dict ops" << endl; if (! send_dict_ops_cmd(ctx, NR_ops ? 1 : 2)) break; NdbSleep_MilliSleep(myRandom48(maxsleep)); g_info << "1: start nodes" << endl; CHECK(restarter.startNodes(nodeIdList, nodeIdCnt) == 0); if (NR_error) { { int err = err_master; if (err != 0) { g_info << "1: insert master error " << err << endl; CHECK(restarter.insertErrorInNode(masterNodeId, err) == 0); } } for (int i = 0; i < nodeIdCnt; i++) { int nodeId = nodeIdList[i]; int err = err_node[i]; if (err != 0) { g_info << "1: insert node " << nodeId << " error " << err << endl; CHECK(restarter.insertErrorInNode(nodeId, err) == 0); } } } NdbSleep_MilliSleep(myRandom48(maxsleep)); g_info << "1: wait cluster started" << endl; CHECK(restarter.waitClusterStarted(timeout) == 0); NdbSleep_MilliSleep(myRandom48(maxsleep)); g_info << "1: restart done" << endl; } g_info << "1: stop dict ops" << endl; send_dict_ops_cmd(ctx, 3); return result;}intrunDictOps(NDBT_Context* ctx, NDBT_Step* step){ myRandom48Init(NdbTick_CurrentMillisecond()); int result = NDBT_OK; for (int l = 0; result == NDBT_OK; l++) { if (! recv_dict_ops_run(ctx)) break; g_info << "2: === loop " << l << " ===" << endl; Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* pDic = pNdb->getDictionary(); const NdbDictionary::Table* pTab = ctx->getTab(); const char* tabName = pTab->getName(); const unsigned long maxsleep = 100; //ms g_info << "2: create table" << endl; { uint count = 0; try_create: count++; if (pDic->createTable(*pTab) != 0) { const NdbError err = pDic->getNdbError(); if (count == 1) g_err << "2: " << tabName << ": create failed: " << err << endl; if (err.code != 711) { result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); goto try_create; } } NdbSleep_MilliSleep(myRandom48(maxsleep)); g_info << "2: verify create" << endl; const NdbDictionary::Table* pTab2 = pDic->getTable(tabName); if (pTab2 == NULL) { const NdbError err = pDic->getNdbError(); g_err << "2: " << tabName << ": verify create: " << err << endl; result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); // replace by the Retrieved table pTab = pTab2; // create indexes const char** indlist = NDBT_Tables::getIndexes(tabName); uint indnum = 0; while (*indlist != 0) { uint count = 0; try_create_index: count++; if (count == 1) g_info << "2: create index " << indnum << " " << *indlist << endl; NdbDictionary::Index ind; char indName[200]; sprintf(indName, "%s_X%u", tabName, indnum); ind.setName(indName); ind.setTable(tabName); if (strcmp(*indlist, "UNIQUE") == 0) { ind.setType(NdbDictionary::Index::UniqueHashIndex); ind.setLogging(pTab->getLogging()); } else if (strcmp(*indlist, "ORDERED") == 0) { ind.setType(NdbDictionary::Index::OrderedIndex); ind.setLogging(false); } else { assert(false); } const char** indtemp = indlist; while (*++indtemp != 0) { ind.addColumn(*indtemp); } if (pDic->createIndex(ind) != 0) { const NdbError err = pDic->getNdbError(); if (count == 1) g_err << "2: " << indName << ": create failed: " << err << endl; if (err.code != 711) { result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); goto try_create_index; } indlist = ++indtemp; indnum++; } if (result == NDBT_FAILED) break; uint indcount = indnum; int records = myRandom48(ctx->getNumRecords()); g_info << "2: load " << records << " records" << endl; HugoTransactions hugoTrans(*pTab); if (hugoTrans.loadTable(pNdb, records) != 0) { // XXX get error code from hugo g_err << "2: " << tabName << ": load failed" << endl; result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); // drop indexes indnum = 0; while (indnum < indcount) { uint count = 0; try_drop_index: count++; if (count == 1) g_info << "2: drop index " << indnum << endl; char indName[200]; sprintf(indName, "%s_X%u", tabName, indnum); if (pDic->dropIndex(indName, tabName) != 0) { const NdbError err = pDic->getNdbError(); if (count == 1) g_err << "2: " << indName << ": drop failed: " << err << endl; if (err.code != 711) { result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); goto try_drop_index; } indnum++; } if (result == NDBT_FAILED) break; g_info << "2: drop" << endl; { uint count = 0; try_drop: count++; if (pDic->dropTable(tabName) != 0) { const NdbError err = pDic->getNdbError(); if (count == 1) g_err << "2: " << tabName << ": drop failed: " << err << endl; if (err.code != 711) { result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); goto try_drop; } } NdbSleep_MilliSleep(myRandom48(maxsleep)); g_info << "2: verify drop" << endl; const NdbDictionary::Table* pTab3 = pDic->getTable(tabName); if (pTab3 != NULL) { g_err << "2: " << tabName << ": verify drop: table exists" << endl; result = NDBT_FAILED; break; } if (pDic->getNdbError().code != 709) { const NdbError err = pDic->getNdbError(); g_err << "2: " << tabName << ": verify drop: " << err << endl; result = NDBT_FAILED; break; } NdbSleep_MilliSleep(myRandom48(maxsleep)); } return result;}NDBT_TESTSUITE(testDict);TESTCASE("CreateAndDrop", "Try to create and drop the table loop number of times\n"){ INITIALIZER(runCreateAndDrop);}TESTCASE("CreateAndDropAtRandom", "Try to create and drop table at random loop number of times\n" "Uses all available tables\n" "Uses error insert 4013 to make TUP verify table descriptor"){ INITIALIZER(runCreateAndDropAtRandom);}TESTCASE("CreateAndDropWithData", "Try to create and drop the table when it's filled with data\n" "do this loop number of times\n"){ INITIALIZER(runCreateAndDropWithData);}TESTCASE("CreateAndDropDuring", "Try to create and drop the table when other thread is using it\n" "do this loop number of times\n"){ STEP(runCreateAndDropDuring); STEP(runUseTableUntilStopped);}TESTCASE("CreateInvalidTables", "Try to create the invalid tables we have defined\n"){ INITIALIZER(runCreateInvalidTables);}TESTCASE("CreateTableWhenDbIsFull", "Try to create a new table when db already is full\n"){ INITIALIZER(runCreateTheTable); INITIALIZER(runFillTable); INITIALIZER(runCreateTableWhenDbIsFull); INITIALIZER(runDropTableWhenDbIsFull); FINALIZER(runDropTheTable);}TESTCASE("FragmentTypeSingle", "Create the table with fragment type Single\n"){ TC_PROPERTY("FragmentType", NdbDictionary::Table::FragSingle); INITIALIZER(runTestFragmentTypes);}TESTCASE("FragmentTypeAllSmall", "Create the table with fragment type AllSmall\n"){ TC_PROPERTY("FragmentType", NdbDictionary::Table::FragAllSmall); INITIALIZER(runTestFragmentTypes);}TESTCASE("FragmentTypeAllMedium", "Create the table with fragment type AllMedium\n"){ TC_PROPERTY("FragmentType", NdbDictionary::Table::FragAllMedium); INITIALIZER(runTestFragmentTypes);}TESTCASE("FragmentTypeAllLarge", "Create the table with fragment type AllLarge\n"){ TC_PROPERTY("FragmentType", NdbDictionary::Table::FragAllLarge); INITIALIZER(runTestFragmentTypes);}TESTCASE("TemporaryTables", "Create the table as temporary and make sure it doesn't\n" "contain any data when system is restarted\n"){ INITIALIZER(runTestTemporaryTables);}TESTCASE("CreateMaxTables", "Create tables until db says that it can't create any more\n"){ TC_PROPERTY("tables", 1000); INITIALIZER(runCreateMaxTables); INITIALIZER(runDropMaxTables);}TESTCASE("PkSizes", "Create tables with all different primary key sizes.\n"\ "Test all data operations insert, update, delete etc.\n"\ "Drop table."){ INITIALIZER(runPkSizes);}TESTCASE("StoreFrm", "Test that a frm file can be properly stored as part of the\n" "data in Dict."){ INITIALIZER(runStoreFrm);}TESTCASE("GetPrimaryKey", "Test the function NdbDictionary::Column::getPrimaryKey\n" "It should return true only if the column is part of \n" "the primary key in the table"){ INITIALIZER(runGetPrimaryKey);}TESTCASE("StoreFrmError", "Test that a frm file with too long length can't be stored."){ INITIALIZER(runStoreFrmError);}TESTCASE("NF1", "Test that create table can handle NF (not master)"){ INITIALIZER(runNF1);}TESTCASE("TableRename", "Test basic table rename"){ INITIALIZER(runTableRename);}TESTCASE("TableRenameNF", "Test that table rename can handle node failure"){ INITIALIZER(runTableRenameNF);}TESTCASE("TableRenameSR", "Test that table rename can handle system restart"){ INITIALIZER(runTableRenameSR);}TESTCASE("DictionaryPerf", ""){ INITIALIZER(runTestDictionaryPerf);}TESTCASE("FailAddFragment", "Fail add fragment or attribute in ACC or TUP or TUX\n"){ INITIALIZER(runFailAddFragment);}TESTCASE("Restart_NF1", "DICT ops during node graceful shutdown (not master)"){ TC_PROPERTY("Restart_NF_ops", 1); TC_PROPERTY("Restart_NF_type", 1); STEP(runRestarts); STEP(runDictOps);}TESTCASE("Restart_NF2", "DICT ops during node shutdown abort (not master)"){ TC_PROPERTY("Restart_NF_ops", 1); TC_PROPERTY("Restart_NF_type", 2); STEP(runRestarts); STEP(runDictOps);}TESTCASE("Restart_NR1", "DICT ops during node startup (not master)"){ TC_PROPERTY("Restart_NR_ops", 1); STEP(runRestarts); STEP(runDictOps);}TESTCASE("Restart_NR2", "DICT ops during node startup with crash inserts (not master)"){ TC_PROPERTY("Restart_NR_ops", 1); TC_PROPERTY("Restart_NR_error", 1); STEP(runRestarts); STEP(runDictOps);}NDBT_TESTSUITE_END(testDict);int main(int argc, const char** argv){ ndb_init(); // Tables should not be auto created testDict.setCreateTable(false); myRandom48Init(NdbTick_CurrentMillisecond()); return testDict.execute(argc, argv);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -