📄 testdict.cpp
字号:
} // Verify that table is not in db const NdbDictionary::Table* pTab4 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab4 != NULL){ ndbout << pTab4->getName() << " was found in DB"<< endl; return NDBT_FAILED; }#endif return result;}struct ErrorCodes { int error_id; bool crash;};ErrorCodesNF_codes[] = { {6003, true} ,{6004, true} //,6005, true, //{7173, false}};intrunNF1(NDBT_Context* ctx, NDBT_Step* step){ NdbRestarter restarter; if(restarter.getNumDbNodes() < 2) return NDBT_OK; myRandom48Init(NdbTick_CurrentMillisecond()); Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); NdbDictionary::Dictionary* dict = pNdb->getDictionary(); dict->dropTable(pTab->getName()); int result = NDBT_OK; const int loops = ctx->getNumLoops(); for (int l = 0; l < loops && result == NDBT_OK ; l++){ const int sz = sizeof(NF_codes)/sizeof(NF_codes[0]); for(int i = 0; i<sz; i++){ int rand = myRandom48(restarter.getNumDbNodes()); int nodeId = restarter.getRandomNotMasterNodeId(rand); struct ErrorCodes err_struct = NF_codes[i]; int error = err_struct.error_id; bool crash = err_struct.crash; g_info << "NF1: node = " << nodeId << " error code = " << error << endl; int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 3}; CHECK2(restarter.dumpStateOneNode(nodeId, val2, 2) == 0, "failed to set RestartOnErrorInsert"); CHECK2(restarter.insertErrorInNode(nodeId, error) == 0, "failed to set error insert"); CHECK2(dict->createTable(* pTab) == 0, "failed to create table"); if (crash) { CHECK2(restarter.waitNodesNoStart(&nodeId, 1) == 0, "waitNodesNoStart failed"); if(myRandom48(100) > 50){ CHECK2(restarter.startNodes(&nodeId, 1) == 0, "failed to start node"); CHECK2(restarter.waitClusterStarted() == 0, "waitClusterStarted failed"); CHECK2(dict->dropTable(pTab->getName()) == 0, "drop table failed"); } else { CHECK2(dict->dropTable(pTab->getName()) == 0, "drop table failed"); CHECK2(restarter.startNodes(&nodeId, 1) == 0, "failed to start node"); CHECK2(restarter.waitClusterStarted() == 0, "waitClusterStarted failed"); } } } } end: dict->dropTable(pTab->getName()); return result;} #define APIERROR(error) \ { g_err << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \ << error.code << ", msg: " << error.message << "." << endl; \ }intrunCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){ Uint32 startvalues[5] = {256-2, 0, 256*256-2, ~0, 256*256*256-2}; int ret = NDBT_OK; for (int jj = 0; jj < 5 && ret == NDBT_OK; jj++) { char tabname[] = "AUTOINCTAB"; Uint32 startvalue = startvalues[jj]; NdbDictionary::Table myTable; NdbDictionary::Column myColumn; Ndb* myNdb = GETNDB(step); NdbDictionary::Dictionary* myDict = myNdb->getDictionary(); if (myDict->getTable(tabname) != NULL) { g_err << "NDB already has example table: " << tabname << endl; APIERROR(myNdb->getNdbError()); return NDBT_FAILED; } myTable.setName(tabname); myColumn.setName("ATTR1"); myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setLength(1); myColumn.setPrimaryKey(true); myColumn.setNullable(false); myColumn.setAutoIncrement(true); if (startvalue != ~0) // check that default value starts with 1 myColumn.setAutoIncrementInitialValue(startvalue); myTable.addColumn(myColumn); if (myDict->createTable(myTable) == -1) { g_err << "Failed to create table " << tabname << endl; APIERROR(myNdb->getNdbError()); return NDBT_FAILED; } if (startvalue == ~0) // check that default value starts with 1 startvalue = 1; for (int i = 0; i < 16; i++) { Uint64 value; if (myNdb->getAutoIncrementValue(tabname, value, 1) == -1) { g_err << "getAutoIncrementValue failed on " << tabname << endl; APIERROR(myNdb->getNdbError()); return NDBT_FAILED; } else if (value != (startvalue+i)) { g_err << "value = " << value << " expected " << startvalue+i << endl;; APIERROR(myNdb->getNdbError()); // ret = NDBT_FAILED; // break; } } if (myDict->dropTable(tabname) == -1) { g_err << "Failed to drop table " << tabname << endl; APIERROR(myNdb->getNdbError()); ret = NDBT_FAILED; } } return ret;}intrunTableRename(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* dict = pNdb->getDictionary(); int records = ctx->getNumRecords(); const int loops = ctx->getNumLoops(); ndbout << "|- " << ctx->getTab()->getName() << endl; for (int l = 0; l < loops && result == NDBT_OK ; l++){ const NdbDictionary::Table* pTab = ctx->getTab(); // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } ctx->setTab(pTab2); // Load table HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } // Rename table BaseString pTabName(pTab->getName()); BaseString pTabNewName(pTabName); pTabNewName.append("xx"); const NdbDictionary::Table * oldTable = dict->getTable(pTabName.c_str()); if (oldTable) { NdbDictionary::Table newTable = *oldTable; newTable.setName(pTabNewName.c_str()); CHECK2(dict->alterTable(newTable) == 0, "TableRename failed"); } else { result = NDBT_FAILED; } // Verify table contents NdbDictionary::Table pNewTab(pTabNewName.c_str()); UtilTransactions utilTrans(pNewTab); if (utilTrans.clearTable(pNdb, records) != 0){ continue; } // Drop table dict->dropTable(pNewTab.getName()); } end: return result;}intrunTableRenameNF(NDBT_Context* ctx, NDBT_Step* step){ NdbRestarter restarter; if(restarter.getNumDbNodes() < 2) return NDBT_OK; int result = NDBT_OK; Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* dict = pNdb->getDictionary(); int records = ctx->getNumRecords(); const int loops = ctx->getNumLoops(); ndbout << "|- " << ctx->getTab()->getName() << endl; for (int l = 0; l < loops && result == NDBT_OK ; l++){ const NdbDictionary::Table* pTab = ctx->getTab(); // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } ctx->setTab(pTab2); // Load table HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } BaseString pTabName(pTab->getName()); BaseString pTabNewName(pTabName); pTabNewName.append("xx"); const NdbDictionary::Table * oldTable = dict->getTable(pTabName.c_str()); if (oldTable) { NdbDictionary::Table newTable = *oldTable; newTable.setName(pTabNewName.c_str()); CHECK2(dict->alterTable(newTable) == 0, "TableRename failed"); } else { result = NDBT_FAILED; } // Restart one node at a time /** * Need to run LCP at high rate otherwise * packed replicas become "to many" */ int val = DumpStateOrd::DihMinTimeBetweenLCP; if(restarter.dumpStateAllNodes(&val, 1) != 0){ do { CHECK(0); } while(0); g_err << "Failed to set LCP to min value" << endl; return NDBT_FAILED; } const int numNodes = restarter.getNumDbNodes(); for(int i = 0; i<numNodes; i++){ int nodeId = restarter.getDbNodeId(i); int error = NF_codes[i].error_id; g_info << "NF1: node = " << nodeId << " error code = " << error << endl; CHECK2(restarter.restartOneDbNode(nodeId) == 0, "failed to set restartOneDbNode"); CHECK2(restarter.waitClusterStarted() == 0, "waitClusterStarted failed"); } // Verify table contents NdbDictionary::Table pNewTab(pTabNewName.c_str()); UtilTransactions utilTrans(pNewTab); if (utilTrans.clearTable(pNdb, records) != 0){ continue; } // Drop table dict->dropTable(pTabNewName.c_str()); } end: return result;}intrunTableRenameSR(NDBT_Context* ctx, NDBT_Step* step){ NdbRestarter restarter; if(restarter.getNumDbNodes() < 2) return NDBT_OK; int result = NDBT_OK; Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* dict = pNdb->getDictionary(); int records = ctx->getNumRecords(); const int loops = ctx->getNumLoops(); ndbout << "|- " << ctx->getTab()->getName() << endl; for (int l = 0; l < loops && result == NDBT_OK ; l++){ // Rename table const NdbDictionary::Table* pTab = ctx->getTab(); // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } ctx->setTab(pTab2); // Load table HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } BaseString pTabName(pTab->getName()); BaseString pTabNewName(pTabName); pTabNewName.append("xx"); const NdbDictionary::Table * oldTable = dict->getTable(pTabName.c_str()); if (oldTable) { NdbDictionary::Table newTable = *oldTable; newTable.setName(pTabNewName.c_str()); CHECK2(dict->alterTable(newTable) == 0, "TableRename failed"); } else { result = NDBT_FAILED; } // Restart cluster /** * Need to run LCP at high rate otherwise * packed replicas become "to many" */ int val = DumpStateOrd::DihMinTimeBetweenLCP; if(restarter.dumpStateAllNodes(&val, 1) != 0){ do { CHECK(0); } while(0); g_err << "Failed to set LCP to min value" << endl; return NDBT_FAILED; } CHECK2(restarter.restartAll() == 0, "failed to set restartOneDbNode"); CHECK2(restarter.waitClusterStarted() == 0, "waitClusterStarted failed"); // Verify table contents NdbDictionary::Table pNewTab(pTabNewName.c_str()); UtilTransactions utilTrans(pNewTab); if (utilTrans.clearTable(pNdb, records) != 0){ continue; } // Drop table dict->dropTable(pTabNewName.c_str()); } end: return result;}static voidf(const NdbDictionary::Column * col){ if(col == 0){ abort(); }}intrunTestDictionaryPerf(NDBT_Context* ctx, NDBT_Step* step){ Vector<char*> cols; Vector<const NdbDictionary::Table*> tabs; int i; Ndb* pNdb = GETNDB(step); const Uint32 count = NDBT_Tables::getNumTables(); for (i=0; i < count; i++){ const NdbDictionary::Table * tab = NDBT_Tables::getTable(i); pNdb->getDictionary()->createTable(* tab); const NdbDictionary::Table * tab2 = pNdb->getDictionary()->getTable(tab->getName()); for(size_t j = 0; j<tab->getNoOfColumns(); j++){ cols.push_back((char*)tab2); cols.push_back(strdup(tab->getColumn(j)->getName())); } } const Uint32 times = 10000000; ndbout_c("%d tables and %d columns", NDBT_Tables::getNumTables(), cols.size()/2); char ** tcols = cols.getBase(); srand(time(0)); Uint32 size = cols.size() / 2; char ** columns = &cols[0]; Uint64 start = NdbTick_CurrentMillisecond(); for(i = 0; i<times; i++){ int j = 2 * (rand() % size); const NdbDictionary::Table* tab = (const NdbDictionary::Table*)tcols[j]; const char * col = tcols[j+1]; const NdbDictionary::Column* column = tab->getColumn(col); f(column); } Uint64 stop = NdbTick_CurrentMillisecond(); stop -= start; Uint64 per = stop; per *= 1000; per /= times; ndbout_c("%d random getColumn(name) in %Ld ms -> %d us/get", times, stop, per); return NDBT_OK;}int runFailAddFragment(NDBT_Context* ctx, NDBT_Step* step){ static int acclst[] = { 3001 }; static int tuplst[] = { 4007, 4008, 4009, 4010, 4011, 4012 }; static int tuxlst[] = { 12001, 12002, 12003, 12004, 12005, 12006 }; static unsigned acccnt = sizeof(acclst)/sizeof(acclst[0]); static unsigned tupcnt = sizeof(tuplst)/sizeof(tuplst[0]); static unsigned tuxcnt = sizeof(tuxlst)/sizeof(tuxlst[0]); NdbRestarter restarter; int nodeId = restarter.getMasterNodeId(); Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* pDic = pNdb->getDictionary(); NdbDictionary::Table tab(*ctx->getTab()); tab.setFragmentType(NdbDictionary::Object::FragAllLarge); // ordered index on first few columns
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -