⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdict.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
      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  NdbDictionary::Index idx("X");  idx.setTable(tab.getName());  idx.setType(NdbDictionary::Index::OrderedIndex);  idx.setLogging(false);  for (int i_hate_broken_compilers = 0;       i_hate_broken_compilers < 3 &&       i_hate_broken_compilers < tab.getNoOfColumns();       i_hate_broken_compilers++) {    idx.addColumn(*tab.getColumn(i_hate_broken_compilers));  }  const int loops = ctx->getNumLoops();  int result = NDBT_OK;  (void)pDic->dropTable(tab.getName());  for (int l = 0; l < loops; l++) {    for (unsigned i0 = 0; i0 < acccnt; i0++) {      unsigned j = (l == 0 ? i0 : myRandom48(acccnt));      int errval = acclst[j];      g_info << "insert error node=" << nodeId << " value=" << errval << endl;      CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0,             "failed to set error insert");      CHECK2(pDic->createTable(tab) != 0,             "failed to fail after error insert " << errval);      CHECK2(pDic->createTable(tab) == 0,             pDic->getNdbError());      CHECK2(pDic->dropTable(tab.getName()) == 0,             pDic->getNdbError());    }    for (unsigned i1 = 0; i1 < tupcnt; i1++) {      unsigned j = (l == 0 ? i1 : myRandom48(tupcnt));      int errval = tuplst[j];      g_info << "insert error node=" << nodeId << " value=" << errval << endl;      CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0,             "failed to set error insert");      CHECK2(pDic->createTable(tab) != 0,             "failed to fail after error insert " << errval);      CHECK2(pDic->createTable(tab) == 0,             pDic->getNdbError());      CHECK2(pDic->dropTable(tab.getName()) == 0,             pDic->getNdbError());    }    for (unsigned i2 = 0; i2 < tuxcnt; i2++) {      unsigned j = (l == 0 ? i2 : myRandom48(tuxcnt));      int errval = tuxlst[j];      g_info << "insert error node=" << nodeId << " value=" << errval << endl;      CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0,             "failed to set error insert");      CHECK2(pDic->createTable(tab) == 0,             pDic->getNdbError());      CHECK2(pDic->createIndex(idx) != 0,             "failed to fail after error insert " << errval);      CHECK2(pDic->createIndex(idx) == 0,             pDic->getNdbError());      CHECK2(pDic->dropTable(tab.getName()) == 0,             pDic->getNdbError());    }  }end:  return result;}NDBT_TESTSUITE(testDict);TESTCASE("CreateAndDrop", 	 "Try to create and drop the table loop number of times\n"){  INITIALIZER(runCreateAndDrop);}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);}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 + -