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

📄 testdict.cpp

📁 mysql-5.0.24源码包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  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;}// NFNR// Restarter controls dict ops : 1-run 2-pause 3-stop// synced by polling...static boolsend_dict_ops_cmd(NDBT_Context* ctx, Uint32 cmd){  ctx->setProperty("DictOps_CMD", cmd);  while (1) {    if (ctx->isTestStopped())      return false;    if (ctx->getProperty("DictOps_ACK") == cmd)      break;    NdbSleep_MilliSleep(100);  }  return true;}static boolrecv_dict_ops_run(NDBT_Context* ctx){  while (1) {    if (ctx->isTestStopped())      return false;    Uint32 cmd = ctx->getProperty("DictOps_CMD");    ctx->setProperty("DictOps_ACK", cmd);    if (cmd == 1)      break;    if (cmd == 3)      return false;    NdbSleep_MilliSleep(100);  }  return true;}intrunRestarts(NDBT_Context* ctx, NDBT_Step* step){  static int errlst_master[] = {   // non-crashing    7175,       // send one fake START_PERMREF    0   };  static int errlst_node[] = {    7174,       // crash before sending DICT_LOCK_REQ    7176,       // pretend master does not support DICT lock    7121,       // crash at receive START_PERMCONF    0  };  const uint errcnt_master = sizeof(errlst_master)/sizeof(errlst_master[0]);  const uint errcnt_node = sizeof(errlst_node)/sizeof(errlst_node[0]);  myRandom48Init(NdbTick_CurrentMillisecond());  NdbRestarter restarter;  int result = NDBT_OK;  const int loops = ctx->getNumLoops();  for (int l = 0; l < loops && result == NDBT_OK; l++) {    g_info << "1: === loop " << l << " ===" << endl;    // assuming 2-way replicated    int numnodes = restarter.getNumDbNodes();    CHECK(numnodes >= 1);    if (numnodes == 1)      break;    int masterNodeId = restarter.getMasterNodeId();    CHECK(masterNodeId != -1);    // for more complex cases need more restarter support methods    int nodeIdList[2] = { 0, 0 };    int nodeIdCnt = 0;    if (numnodes >= 2) {      int rand = myRandom48(numnodes);      int nodeId = restarter.getRandomNotMasterNodeId(rand);      CHECK(nodeId != -1);      nodeIdList[nodeIdCnt++] = nodeId;    }    if (numnodes >= 4 && myRandom48(2) == 0) {      int rand = myRandom48(numnodes);      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;    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));    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("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 + -