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

📄 testdict.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        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;  }    // 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 = myNdb->getAutoIncrementValue(tabname, 1);      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){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -