📄 testdict.cpp
字号:
char tabName[256]; int numTables = ctx->getProperty("maxtables", (Uint32)0); Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* pDic = pNdb->getDictionary(); for (int i = 0; i < numTables; i++) { BaseString::snprintf(tabName, 256, "MAXTAB%d", i); if (pNdb->waitUntilReady(30) != 0) { // Db is not ready, return with failure return NDBT_FAILED; } // Verify that table exists in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, tabName) ; if (pTab3 == NULL) { ndbout << tabName << " was not found in DB: " << pDic->getNdbError() << endl; return NDBT_FAILED; } // Try to drop table in db if (pDic->dropTable(pTab3->getName()) != 0) { ndbout << tabName << " could not be dropped: " << pDic->getNdbError() << endl; return NDBT_FAILED; } } return NDBT_OK;}int runTestFragmentTypes(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); int fragTtype = ctx->getProperty("FragmentType"); Ndb* pNdb = GETNDB(step); int result = NDBT_OK; NdbRestarter restarter; if (pNdb->waitUntilReady(30) != 0){ // Db is not ready, return with failure return NDBT_FAILED; } const NdbDictionary::Table* pTab = ctx->getTab(); pNdb->getDictionary()->dropTable(pTab->getName()); NdbDictionary::Table newTab(* pTab); // Set fragment type for table newTab.setFragmentType((NdbDictionary::Object::FragmentType)fragTtype); // Try to create table in db if (newTab.createTableInDb(pNdb) != 0){ ndbout << newTab.getName() << " could not be created" << ", fragmentType = "<<fragTtype <<endl; ndbout << pNdb->getDictionary()->getNdbError() << endl; return NDBT_FAILED; } // Verify that table exists in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()) ; if (pTab3 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } if (pTab3->getFragmentType() != fragTtype){ ndbout << pTab->getName() << " fragmentType error "<< endl; result = NDBT_FAILED; goto drop_the_tab; }/** This test does not work since fragmentation is decided by the kernel, hence the fragementation attribute on the column will differ if (newTab.equal(*pTab3) == false){ ndbout << "It was not equal" << endl; result = NDBT_FAILED; goto drop_the_tab; } */ do { HugoTransactions hugoTrans(*pTab3); UtilTransactions utilTrans(*pTab3); int count; CHECK(hugoTrans.loadTable(pNdb, records) == 0); CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == records); CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0); CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == (records/2)); // restart all ndbout << "Restarting cluster" << endl; CHECK(restarter.restartAll() == 0); int timeout = 120; CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); // Verify content CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == (records/2)); CHECK(utilTrans.clearTable(pNdb, records) == 0); CHECK(hugoTrans.loadTable(pNdb, records) == 0); CHECK(utilTrans.clearTable(pNdb, records) == 0); CHECK(hugoTrans.loadTable(pNdb, records) == 0); CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.clearTable(pNdb, records, 64) == 0); } while(false); drop_the_tab: // Try to drop table in db if (pNdb->getDictionary()->dropTable(pTab3->getName()) != 0){ ndbout << pTab3->getName() << " could not be dropped"<< endl; result = NDBT_FAILED; } return result;}int runTestTemporaryTables(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); Ndb* pNdb = GETNDB(step); int i = 0; NdbRestarter restarter; const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; NdbDictionary::Table newTab(* pTab); // Set table as temporary newTab.setStoredTable(false); // Try to create table in db if (newTab.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; } if (pTab2->getStoredTable() != false){ ndbout << pTab->getName() << " was not temporary in DB"<< endl; result = NDBT_FAILED; goto drop_the_tab; } while (i < loops && result == NDBT_OK){ ndbout << i << ": "; HugoTransactions hugoTrans(*pTab2); CHECK(hugoTrans.loadTable(pNdb, records) == 0); int count = 0; UtilTransactions utilTrans(*pTab2); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == records); // restart all ndbout << "Restarting cluster" << endl; CHECK(restarter.restartAll() == 0); int timeout = 120; CHECK(restarter.waitClusterStarted(timeout) == 0); CHECK(pNdb->waitUntilReady(timeout) == 0); ndbout << "Verifying records..." << endl; CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == 0); i++; } drop_the_tab: if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){ ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl; result = NDBT_FAILED; } // Verify that table is not in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab3 != NULL){ ndbout << pTab3->getName() << " was found in DB"<< endl; result = NDBT_FAILED; } return result;}int runPkSizes(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; char tabName[256]; int minPkSize = 1; ndbout << "minPkSize=" <<minPkSize<<endl; int maxPkSize = MAX_KEY_SIZE_IN_WORDS * 4; ndbout << "maxPkSize=" <<maxPkSize<<endl; Ndb* pNdb = GETNDB(step); int numRecords = ctx->getNumRecords(); for (int i = minPkSize; i < maxPkSize; i++){ BaseString::snprintf(tabName, 256, "TPK_%d", i); int records = numRecords; int max = ~0; // Limit num records for small PKs if (i == 1) max = 99; if (i == 2) max = 999; if (i == 3) max = 9999; if (records > max) records = max; ndbout << "records =" << records << endl; if (pNdb->waitUntilReady(30) != 0){ // Db is not ready, return with failure return NDBT_FAILED; } ndbout << "|- " << tabName << endl; if (NDBT_Tables::createTable(pNdb, tabName) != 0){ ndbout << tabName << " could not be created"<< endl; return NDBT_FAILED; } // Verify that table exists in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, tabName) ; if (pTab3 == NULL){ g_err << tabName << " was not found in DB"<< endl; return NDBT_FAILED; } // ndbout << *pTab3 << endl; if (pTab3->equal(*NDBT_Tables::getTable(tabName)) == false){ g_err << "It was not equal" << endl; return NDBT_FAILED; } do { // Do it all HugoTransactions hugoTrans(*pTab3); UtilTransactions utilTrans(*pTab3); int count; CHECK(hugoTrans.loadTable(pNdb, records) == 0); CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == records); CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0); CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == (records/2)); CHECK(utilTrans.clearTable(pNdb, records) == 0); #if 0 // Fill table CHECK(hugoTrans.fillTable(pNdb) == 0); CHECK(utilTrans.clearTable2(pNdb, records) == 0); CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0); CHECK(count == 0);#endif } while(false); // Drop table if (pNdb->getDictionary()->dropTable(pTab3->getName()) != 0){ ndbout << "Failed to drop "<<pTab3->getName()<<" in db" << endl; return NDBT_FAILED; } } return result;}int runStoreFrm(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); int result = NDBT_OK; int loops = ctx->getNumLoops(); for (int l = 0; l < loops && result == NDBT_OK ; l++){ Uint32 dataLen = (Uint32)myRandom48(MAX_FRM_DATA_SIZE); // size_t dataLen = 10; unsigned char data[MAX_FRM_DATA_SIZE]; char start = l + 248; for(Uint32 i = 0; i < dataLen; i++){ data[i] = start; start++; }#if 0 ndbout << "dataLen="<<dataLen<<endl; for (Uint32 i = 0; i < dataLen; i++){ unsigned char c = data[i]; ndbout << hex << c << ", "; } ndbout << endl;#endif NdbDictionary::Table newTab(* pTab); void* pData = &data; newTab.setFrm(pData, dataLen); // Try to create table in db if (newTab.createTableInDb(pNdb) != 0){ result = NDBT_FAILED; continue; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ g_err << pTab->getName() << " was not found in DB"<< endl; result = NDBT_FAILED; continue; } const void* pData2 = pTab2->getFrmData(); Uint32 resultLen = pTab2->getFrmLength(); if (dataLen != resultLen){ g_err << "Length of data failure" << endl << " expected = " << dataLen << endl << " got = " << resultLen << endl; result = NDBT_FAILED; } // Verfiy the frm data if (memcmp(pData, pData2, resultLen) != 0){ g_err << "Wrong data recieved" << endl; for (size_t i = 0; i < dataLen; i++){ unsigned char c = ((unsigned char*)pData2)[i]; g_err << hex << c << ", "; } g_err << endl; result = NDBT_FAILED; } if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){ g_err << "It can NOT be dropped" << endl; result = NDBT_FAILED; } } return result;}int runStoreFrmError(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); int result = NDBT_OK; int loops = ctx->getNumLoops(); for (int l = 0; l < loops && result == NDBT_OK ; l++){ const Uint32 dataLen = MAX_FRM_DATA_SIZE + 10; unsigned char data[dataLen]; char start = l + 248; for(Uint32 i = 0; i < dataLen; i++){ data[i] = start; start++; }#if 0 ndbout << "dataLen="<<dataLen<<endl; for (Uint32 i = 0; i < dataLen; i++){ unsigned char c = data[i]; ndbout << hex << c << ", "; } ndbout << endl;#endif NdbDictionary::Table newTab(* pTab); void* pData = &data; newTab.setFrm(pData, dataLen); // Try to create table in db if (newTab.createTableInDb(pNdb) == 0){ result = NDBT_FAILED; continue; } const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 != NULL){ g_err << pTab->getName() << " was found in DB"<< endl; result = NDBT_FAILED; if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){ g_err << "It can NOT be dropped" << endl; result = NDBT_FAILED; } continue; } } return result;}int verifyTablesAreEqual(const NdbDictionary::Table* pTab, const NdbDictionary::Table* pTab2){ // Verify that getPrimaryKey only returned true for primary keys for (int i = 0; i < pTab2->getNoOfColumns(); i++){ const NdbDictionary::Column* col = pTab->getColumn(i); const NdbDictionary::Column* col2 = pTab2->getColumn(i); if (col->getPrimaryKey() != col2->getPrimaryKey()){ g_err << "col->getPrimaryKey() != col2->getPrimaryKey()" << endl; return NDBT_FAILED; } } if (!pTab->equal(*pTab2)){ g_err << "equal failed" << endl; g_info << *pTab; g_info << *pTab2; return NDBT_FAILED; } return NDBT_OK;}int runGetPrimaryKey(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; g_info << *pTab; // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } 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; } int result = NDBT_OK; if (verifyTablesAreEqual(pTab, pTab2) != NDBT_OK) result = NDBT_FAILED; #if 0 // Create an index on the table and see what // the function returns now char name[200]; sprintf(name, "%s_X007", pTab->getName()); NDBT_Index* pInd = new NDBT_Index(name); pInd->setTable(pTab->getName()); pInd->setType(NdbDictionary::Index::UniqueHashIndex); // pInd->setLogging(false); for (int i = 0; i < 2; i++){ const NDBT_Attribute* pAttr = pTab->getAttribute(i); pInd->addAttribute(*pAttr); } g_info << "Create index:" << endl << *pInd; if (pInd->createIndexInDb(pNdb, false) != 0){ result = NDBT_FAILED; } delete pInd; const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab3 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } if (verifyTablesAreEqual(pTab, pTab3) != NDBT_OK) result = NDBT_FAILED; if (verifyTablesAreEqual(pTab2, pTab3) != NDBT_OK) result = NDBT_FAILED;#endif#if 0 if (pTab2->getDictionary()->dropTable(pNdb) != 0){ ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl; return NDBT_FAILED;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -