📄 testdict.cpp
字号:
/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <NDBT.hpp>#include <NDBT_Test.hpp>#include <HugoTransactions.hpp>#include <UtilTransactions.hpp>#include <NdbRestarter.hpp>#include <Vector.hpp>#include <signaldata/DumpStateOrd.hpp>#include <../../include/kernel/ndb_limits.h>#include <random.h>#include <NdbAutoPtr.hpp> #define CHECK(b) if (!(b)) { \ g_err << "ERR: "<< step->getName() \ << " failed on line " << __LINE__ << endl; \ result = NDBT_FAILED; \ break; } #define CHECK2(b, c) if (!(b)) { \ g_err << "ERR: "<< step->getName() \ << " failed on line " << __LINE__ << ": " << c << endl; \ result = NDBT_FAILED; \ goto end; }int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int records = ctx->getNumRecords(); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runCreateInvalidTables(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int result = NDBT_OK; char failTabName[256]; for (int i = 0; i < 10; i++){ BaseString::snprintf(failTabName, 256, "F%d", i); const NdbDictionary::Table* pFailTab = NDBT_Tables::getTable(failTabName); if (pFailTab != NULL){ ndbout << "|- " << failTabName << endl; // Try to create table in db if (pFailTab->createTableInDb(pNdb) == 0){ ndbout << failTabName << " created, this was not expected"<< endl; result = NDBT_FAILED; } // Verify that table is not in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, failTabName) ; if (pTab2 != NULL){ ndbout << failTabName << " was found in DB, this was not expected"<< endl; result = NDBT_FAILED; if (pFailTab->equal(*pTab2) == true){ ndbout << "It was equal" << endl; } else { ndbout << "It was not equal" << endl; } int records = 1000; HugoTransactions hugoTrans(*pTab2); if (hugoTrans.loadTable(pNdb, records) != 0){ ndbout << "It can NOT be loaded" << endl; } else{ ndbout << "It can be loaded" << endl; UtilTransactions utilTrans(*pTab2); if (utilTrans.clearTable(pNdb, records, 64) != 0){ ndbout << "It can NOT be cleared" << endl; } else{ ndbout << "It can be cleared" << endl; } } if (pNdb->getDictionary()->dropTable(pTab2->getName()) == -1){ ndbout << "It can NOT be dropped" << endl; } else { ndbout << "It can be dropped" << endl; } } } } return result;}int runCreateTheTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); 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); return NDBT_OK;}int runDropTheTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); // Try to create table in db pNdb->getDictionary()->dropTable(pTab->getName()); return NDBT_OK;}int runCreateTableWhenDbIsFull(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int result = NDBT_OK; const char* tabName = "TRANSACTION"; //Use a util table const NdbDictionary::Table* pTab = NDBT_Tables::getTable(tabName); if (pTab != NULL){ ndbout << "|- " << tabName << endl; // Verify that table is not in db if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){ ndbout << tabName << " was found in DB"<< endl; return NDBT_FAILED; } // Try to create table in db if (pTab->createTableInDb(pNdb) == 0){ result = NDBT_FAILED; } // Verify that table is in db if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){ ndbout << tabName << " was found in DB"<< endl; result = NDBT_FAILED; } } return result;}int runDropTableWhenDbIsFull(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int result = NDBT_OK; const char* tabName = "TRANSACTION"; //Use a util table const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(pNdb, tabName); if (pTab != NULL){ ndbout << "|- TRANSACTION" << endl; // Try to drop table in db if (pNdb->getDictionary()->dropTable(pTab->getName()) == -1){ result = NDBT_FAILED; } // Verify that table is not in db if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){ ndbout << tabName << " was found in DB"<< endl; result = NDBT_FAILED; } } return result;}int runCreateAndDrop(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int loops = ctx->getNumLoops(); int i = 0; const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; while (i < loops){ ndbout << i << ": "; // 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; } if (pNdb->getDictionary()->dropTable(pTab2->getName())){ ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl; return 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; return NDBT_FAILED; } i++; } return NDBT_OK;}int runCreateAndDropAtRandom(NDBT_Context* ctx, NDBT_Step* step){ myRandom48Init(NdbTick_CurrentMillisecond()); Ndb* pNdb = GETNDB(step); NdbDictionary::Dictionary* pDic = pNdb->getDictionary(); int loops = ctx->getNumLoops(); int numTables = NDBT_Tables::getNumTables(); bool* tabList = new bool [ numTables ]; int tabCount; { for (int num = 0; num < numTables; num++) { (void)pDic->dropTable(NDBT_Tables::getTable(num)->getName()); tabList[num] = false; } tabCount = 0; } NdbRestarter restarter; int result = NDBT_OK; int bias = 1; // 0-less 1-more int i = 0; while (i < loops) { g_info << "loop " << i << " tabs " << tabCount << "/" << numTables << endl; int num = myRandom48(numTables); const NdbDictionary::Table* pTab = NDBT_Tables::getTable(num); char tabName[200]; strcpy(tabName, pTab->getName()); if (tabList[num] == false) { if (bias == 0 && myRandom48(100) < 80) continue; g_info << tabName << ": create" << endl; if (pDic->createTable(*pTab) != 0) { const NdbError err = pDic->getNdbError(); g_err << tabName << ": create failed: " << err << endl; result = NDBT_FAILED; break; } const NdbDictionary::Table* pTab2 = pDic->getTable(tabName); if (pTab2 == NULL) { const NdbError err = pDic->getNdbError(); g_err << tabName << ": verify create: " << err << endl; result = NDBT_FAILED; break; } tabList[num] = true; assert(tabCount < numTables); tabCount++; if (tabCount == numTables) bias = 0; } else { if (bias == 1 && myRandom48(100) < 80) continue; g_info << tabName << ": drop" << endl; if (restarter.insertErrorInAllNodes(4013) != 0) { g_err << "error insert failed" << endl; result = NDBT_FAILED; break; } if (pDic->dropTable(tabName) != 0) { const NdbError err = pDic->getNdbError(); g_err << tabName << ": drop failed: " << err << endl; result = NDBT_FAILED; break; } const NdbDictionary::Table* pTab2 = pDic->getTable(tabName); if (pTab2 != NULL) { g_err << tabName << ": verify drop: table exists" << endl; result = NDBT_FAILED; break; } if (pDic->getNdbError().code != 709 && pDic->getNdbError().code != 723) { const NdbError err = pDic->getNdbError(); g_err << tabName << ": verify drop: " << err << endl; result = NDBT_FAILED; break; } tabList[num] = false; assert(tabCount > 0); tabCount--; if (tabCount == 0) bias = 1; } i++; } delete [] tabList; return result;}int runCreateAndDropWithData(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); int i = 0; NdbRestarter restarter; int val = DumpStateOrd::DihMinTimeBetweenLCP; if(restarter.dumpStateAllNodes(&val, 1) != 0){ int result; do { CHECK(0); } while (0); g_err << "Unable to change timebetween LCP" << endl; return NDBT_FAILED; } const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; while (i < loops){ ndbout << i << ": "; // 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; } HugoTransactions hugoTrans(*pTab2); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } int count = 0; UtilTransactions utilTrans(*pTab2); if (utilTrans.selectCount(pNdb, 64, &count) != 0){ return NDBT_FAILED; } if (count != records){ ndbout << count <<" != "<<records << endl; return NDBT_FAILED; } if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){ ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl; return 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; return NDBT_FAILED; } i++; } return NDBT_OK;}int runFillTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.fillTable(pNdb) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runClearTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int records = ctx->getNumRecords(); UtilTransactions utilTrans(*ctx->getTab()); if (utilTrans.clearTable(pNdb, records) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runCreateAndDropDuring(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int i = 0; const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; while (i < loops && result == NDBT_OK){ ndbout << i << ": " << endl; // Try to create table in db Ndb* pNdb = GETNDB(step); g_debug << "Creating table" << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -