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

📄 testscan.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* 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 "ScanFunctions.hpp"#include <random.h>const NdbDictionary::Table *getTable(Ndb* pNdb, int i){  const NdbDictionary::Table* t = NDBT_Tables::getTable(i);  if (t == NULL){    return 0;  }  return pNdb->getDictionary()->getTable(t->getName());}int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){    int records = ctx->getProperty("Rows", ctx->getNumRecords());  HugoTransactions hugoTrans(*ctx->getTab());  if (hugoTrans.loadTable(GETNDB(step), records) != 0){    return NDBT_FAILED;  }  return NDBT_OK;}int runCreateAllTables(NDBT_Context* ctx, NDBT_Step* step){  int a = NDBT_Tables::createAllTables(GETNDB(step), false, true);   return a;}int runDropAllTablesExceptTestTable(NDBT_Context* ctx, NDBT_Step* step){  for (int i=0; i < NDBT_Tables::getNumTables(); i++){    const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);    if (tab == NULL){      return NDBT_ProgramExit(NDBT_FAILED);    }    // Don't drop test table    if (strcmp(tab->getName(), ctx->getTab()->getName()) == 0){      continue;    }	        int res = GETNDB(step)->getDictionary()->dropTable(tab->getName());    if(res == -1){      return NDBT_FAILED;    }  }  return NDBT_OK;}int runLoadAllTables(NDBT_Context* ctx, NDBT_Step* step){    int records = ctx->getNumRecords();  for (int i=0; i < NDBT_Tables::getNumTables(); i++){    const NdbDictionary::Table* tab = getTable(GETNDB(step), i);    if (tab == NULL){       return NDBT_FAILED;    }    HugoTransactions hugoTrans(*tab);    if (hugoTrans.loadTable(GETNDB(step), records) != 0){      return NDBT_FAILED;    }      }  return NDBT_OK;}char orderedPkIdxName[255];int createOrderedPkIndex(NDBT_Context* ctx, NDBT_Step* step){  const NdbDictionary::Table* pTab = ctx->getTab();  Ndb* pNdb = GETNDB(step);    // Create index      BaseString::snprintf(orderedPkIdxName, sizeof(orderedPkIdxName), 		       "IDC_O_PK_%s", pTab->getName());  NdbDictionary::Index pIdx(orderedPkIdxName);  pIdx.setTable(pTab->getName());  pIdx.setType(NdbDictionary::Index::OrderedIndex);  pIdx.setLogging(false);  for (int c = 0; c< pTab->getNoOfColumns(); c++){    const NdbDictionary::Column * col = pTab->getColumn(c);    if(col->getPrimaryKey()){      pIdx.addIndexColumn(col->getName());    }  }    if (pNdb->getDictionary()->createIndex(pIdx) != 0){    ndbout << "FAILED! to create index" << endl;    const NdbError err = pNdb->getDictionary()->getNdbError();    ERR(err);    return NDBT_FAILED;  }    return NDBT_OK;}int createOrderedPkIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){  const NdbDictionary::Table* pTab = ctx->getTab();  Ndb* pNdb = GETNDB(step);    // Drop index  if (pNdb->getDictionary()->dropIndex(orderedPkIdxName, 				       pTab->getName()) != 0){    ndbout << "FAILED! to drop index" << endl;    ERR(pNdb->getDictionary()->getNdbError());    return NDBT_FAILED;  }    return NDBT_OK;}int runScanReadRandomTable(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int parallelism = ctx->getProperty("Parallelism", 240);  int abort = ctx->getProperty("AbortProb", 5);    int i = 0;  while (i<loops) {        int tabNum = myRandom48(NDBT_Tables::getNumTables());    const NdbDictionary::Table* tab = getTable(GETNDB(step), tabNum);    if (tab == NULL){      g_info << "tab == NULL" << endl;      return NDBT_FAILED;    }        g_info << "Scan reading from table " << tab->getName() << endl;    HugoTransactions hugoTrans(*tab);        g_info << i << ": ";    if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){  int records = ctx->getNumRecords();  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (ctx->isTestStopped() == false) {    g_info << i << ": ";        if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runInsertDelete(NDBT_Context* ctx, NDBT_Step* step){  int result = NDBT_OK;  int records = ctx->getNumRecords();  int loops = ctx->getNumLoops();  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  UtilTransactions utilTrans(*ctx->getTab());  while (i<loops) {    g_info << i << ": ";        if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){      result = NDBT_FAILED;      break;    }    if (utilTrans.clearTable(GETNDB(step),  records) != 0){      result = NDBT_FAILED;      break;    }    i++;  }  ctx->stopTest();  return result;}int runClearTable(NDBT_Context* ctx, NDBT_Step* step){  int records = ctx->getNumRecords();    UtilTransactions utilTrans(*ctx->getTab());  if (utilTrans.clearTable2(GETNDB(step),  records) != 0){    return NDBT_FAILED;  }  return NDBT_OK;}int runScanDelete(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int i = 0;  UtilTransactions utilTrans(*ctx->getTab());  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops) {    g_info << i << ": ";    if (utilTrans.clearTable(GETNDB(step), records) != 0){      return NDBT_FAILED;    }    // Load table, don't allow any primary key violations    if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){      return NDBT_FAILED;    }    i++;  }    return NDBT_OK;}int runScanDelete2(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();    int i = 0;  UtilTransactions utilTrans(*ctx->getTab());  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops) {    g_info << i << ": ";    if (utilTrans.clearTable2(GETNDB(step),  records) != 0){      return NDBT_FAILED;    }    // Load table, don't allow any primary key violations    if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runVerifyTable(NDBT_Context* ctx, NDBT_Step* step){  return NDBT_OK;}int runScanRead(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getProperty("Rows", ctx->getNumRecords());  int parallelism = ctx->getProperty("Parallelism", 240);  int abort = ctx->getProperty("AbortProb", 5);  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops && !ctx->isTestStopped()) {    g_info << i << ": ";    if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runRandScanRead(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int parallelism = ctx->getProperty("Parallelism", 240);  int abort = ctx->getProperty("AbortProb", 5);  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops && !ctx->isTestStopped()) {    g_info << i << ": ";    NdbOperation::LockMode lm = (NdbOperation::LockMode)(rand() % 3);    if (hugoTrans.scanReadRecords(GETNDB(step),				  records, abort, parallelism,				  lm) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runScanReadIndex(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int parallelism = ctx->getProperty("Parallelism", 240);  int abort = ctx->getProperty("AbortProb", 5);  const NdbDictionary::Index * pIdx =     GETNDB(step)->getDictionary()->getIndex(orderedPkIdxName, 					    ctx->getTab()->getName());  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (pIdx && i<loops && !ctx->isTestStopped()) {    g_info << i << ": ";    bool sort = (rand() % 100) > 50 ? true : false;    bool desc = (rand() % 100) > 50 ? true : false;    desc = false;       // random causes too many deadlocks    int scan_flags =      (NdbScanOperation::SF_OrderBy & -(int)sort) |      (NdbScanOperation::SF_Descending & -(int)desc);    NdbOperation::LockMode lm = (NdbOperation::LockMode)(rand() % 3);    if (hugoTrans.scanReadRecords(GETNDB(step), pIdx,				  records, abort, parallelism,				  lm,				  scan_flags) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runScanReadCommitted(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int parallelism = ctx->getProperty("Parallelism", 240);  int abort = ctx->getProperty("AbortProb", 5);  bool tupScan = ctx->getProperty("TupScan");  int scan_flags = (NdbScanOperation::SF_TupScan & -(int)tupScan);  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops && !ctx->isTestStopped()) {    g_info << i << ": ";    if (hugoTrans.scanReadRecords(GETNDB(step), records, 				  abort, parallelism, 				  NdbOperation::LM_CommittedRead,                                  scan_flags) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runScanReadError(NDBT_Context* ctx, NDBT_Step* step){  int result = NDBT_OK;  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int parallelism = 240; // Max parallelism  int error = ctx->getProperty("ErrorCode");  NdbRestarter restarter;    int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops && !ctx->isTestStopped()) {    g_info << i << ": ";        ndbout << "insertErrorInAllNodes("<<error<<")"<<endl;    if (restarter.insertErrorInAllNodes(error) != 0){      ndbout << "Could not insert error in all nodes "<<endl;      return NDBT_FAILED;    }        if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){      result = NDBT_FAILED;    }    i++;  }    restarter.insertErrorInAllNodes(0);  return result;}intrunInsertError(NDBT_Context* ctx, NDBT_Step* step){  int error = ctx->getProperty("ErrorCode");  NdbRestarter restarter;  ctx->setProperty("ErrorCode", (Uint32)0);  if (restarter.insertErrorInAllNodes(error) != 0){    ndbout << "Could not insert error in all nodes "<<endl;    return NDBT_FAILED;  }  return NDBT_OK;}     int runScanReadErrorOneNode(NDBT_Context* ctx, NDBT_Step* step){  int result = NDBT_OK;  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int parallelism = 240; // Max parallelism  int error = ctx->getProperty("ErrorCode");  NdbRestarter restarter;  int lastId = 0;  if (restarter.getNumDbNodes() < 2){      ctx->stopTest();      return NDBT_OK;  }  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops && result == NDBT_OK) {    g_info << i << ": ";            int nodeId = restarter.getDbNodeId(lastId);    lastId = (lastId + 1) % restarter.getNumDbNodes();    ndbout << "insertErrorInNode("<<nodeId<<", "<<error<<")"<<endl;    if (restarter.insertErrorInNode(nodeId, error) != 0){      ndbout << "Could not insert error in node="<<nodeId<<endl;      return NDBT_FAILED;    }        for (int j=0; j<10; j++){      if (hugoTrans.scanReadRecords(GETNDB(step), 				    records, 0, parallelism) != 0)	result = NDBT_FAILED;    }	    if(restarter.waitClusterStarted(120) != 0){      g_err << "Cluster failed to restart" << endl;      result = NDBT_FAILED;    }    restarter.insertErrorInAllNodes(0);        i++;  }  restarter.insertErrorInAllNodes(0);  return result;}int runRestartAll(NDBT_Context* ctx, NDBT_Step* step){  NdbRestarter restarter;  if (restarter.restartAll() != 0){    ndbout << "Could not restart all nodes"<<endl;    return NDBT_FAILED;  }  if (restarter.waitClusterStarted(120) != 0){    ndbout << "Could not restarted" << endl;    return NDBT_FAILED;  }        return NDBT_OK;}static int RANDOM_PARALLELISM = 9999;int runScanReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){  int records = ctx->getNumRecords();  int i = 0;  int parallelism = ctx->getProperty("Parallelism", 240);  int para = parallelism;  HugoTransactions hugoTrans(*ctx->getTab());  while (ctx->isTestStopped() == false) {    if (parallelism == RANDOM_PARALLELISM)      para = myRandom48(239)+1;    g_info << i << ": ";    if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, para) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runScanReadUntilStoppedNoCount(NDBT_Context* ctx, NDBT_Step* step){  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (ctx->isTestStopped() == false) {    g_info << i << ": ";    if (hugoTrans.scanReadRecords(GETNDB(step), 0) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}int runScanReadUntilStoppedPrintTime(NDBT_Context* ctx, NDBT_Step* step){  int records = ctx->getNumRecords();  int i = 0;  int parallelism = ctx->getProperty("Parallelism", 240);  NdbTimer timer;  Ndb* ndb = GETNDB(step);  HugoTransactions hugoTrans(*ctx->getTab());  while (ctx->isTestStopped() == false) {    timer.doReset();    timer.doStart();    g_info << i << ": ";    if (ndb->waitUntilReady() != 0)      return NDBT_FAILED;          if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0)      return NDBT_FAILED;    timer.doStop();    if ((timer.elapsedTime()/1000) > 1)      timer.printTotalTime();    i++;  }  return NDBT_OK;}int runPkRead(NDBT_Context* ctx, NDBT_Step* step){  int loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int i = 0;  HugoTransactions hugoTrans(*ctx->getTab());  while (i<loops) {    g_info << i << ": ";    if (hugoTrans.pkReadRecords(GETNDB(step), records) != 0){      return NDBT_FAILED;    }    i++;  }  return NDBT_OK;}

⌨️ 快捷键说明

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