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

📄 testsystemrestart.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 <signaldata/DumpStateOrd.hpp>int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){  int records = ctx->getNumRecords();  HugoTransactions hugoTrans(*ctx->getTab());  if (hugoTrans.loadTable(GETNDB(step), records) != 0){    return NDBT_FAILED;  }  return NDBT_OK;}#define CHECK(b) if (!(b)) { \  g_err << "ERR: "<< step->getName() \         << " failed on line " << __LINE__ << endl; \  result = NDBT_FAILED; \  continue; } int runSystemRestart1(NDBT_Context* ctx, NDBT_Step* step){  Ndb* pNdb = GETNDB(step);  int result = NDBT_OK;  int timeout = 300;  Uint32 loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int count;  NdbRestarter restarter;  Uint32 i = 1;  UtilTransactions utilTrans(*ctx->getTab());  HugoTransactions hugoTrans(*ctx->getTab());  while(i<=loops && result != NDBT_FAILED){    ndbout << "Loop " << i << "/"<< loops <<" started" << endl;    /*      1. Load data      2. Restart cluster and verify records      3. Update records      4. Restart cluster and verify records      5. Delete half of the records      6. Restart cluster and verify records      7. Delete all records      8. Restart cluster and verify records      9. Insert, update, delete records      10. Restart cluster and verify records      11. Insert, update, delete records      12. Restart cluster with error insert 5020 and verify records    */    ndbout << "Loading records..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    ndbout << "Restarting cluster" << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == records);    ndbout << "Updating records..." << endl;    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == records);        ndbout << "Deleting 50% of records..." << endl;    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == (records/2));    ndbout << "Deleting all records..." << endl;    CHECK(utilTrans.clearTable(pNdb, records/2) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == 0);    ndbout << "Doing it all..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == 0);    ndbout << "Doing it all..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    ndbout << "Restarting cluster with error insert 5020..." << endl;    CHECK(restarter.restartAll(false, true) == 0);    CHECK(restarter.waitClusterNoStart(timeout) == 0);    CHECK(restarter.insertErrorInAllNodes(5020) == 0);    CHECK(restarter.startAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);        i++;  }  ndbout << "runSystemRestart1 finished" << endl;    return result;}int runSystemRestart2(NDBT_Context* ctx, NDBT_Step* step){  Ndb* pNdb = GETNDB(step);  int result = NDBT_OK;///  int timeout = 300;  int timeout = 120;  Uint32 loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int count;  NdbRestarter restarter;  Uint32 i = 1;  UtilTransactions utilTrans(*ctx->getTab());  HugoTransactions hugoTrans(*ctx->getTab());  while(i<=loops && result != NDBT_FAILED && !ctx->isTestStopped()){    ndbout << "Loop " << i << "/"<< loops <<" started" << endl;    /* Use error 7070 to set time between LCP to it's min value      1. Load data      2. Restart cluster and verify records      3. Update records      4. Restart cluster and verify records      5. Delete half of the records      6. Restart cluster and verify records      7. Delete all records      8. Restart cluster and verify records      9. Insert, update, delete records      10. Restart cluster and verify records    */    int val = DumpStateOrd::DihMinTimeBetweenLCP;    CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);    ndbout << "Loading records..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    ndbout << "Restarting cluster" << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    {      int val = DumpStateOrd::DihMinTimeBetweenLCP;      CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);    }    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == records);    ndbout << "Updating records..." << endl;    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    {      int val = DumpStateOrd::DihMinTimeBetweenLCP;      CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);    }    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == records);        ndbout << "Deleting 50% of records..." << endl;    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    {      int val = DumpStateOrd::DihMinTimeBetweenLCP;      CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);    }    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == (records/2));    ndbout << "Deleting all records..." << endl;    CHECK(utilTrans.clearTable(pNdb, records/2) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    {      int val = DumpStateOrd::DihMinTimeBetweenLCP;      CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);    }    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == 0);    ndbout << "Doing it all..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    {      int val = DumpStateOrd::DihMinTimeBetweenLCP;      CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);    }    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == 0);    i++;  }  ndbout << "runSystemRestart2 finished" << endl;    return result;}int runSystemRestartTestUndoLog(NDBT_Context* ctx, NDBT_Step* step){  Ndb* pNdb = GETNDB(step);  int result = NDBT_OK;  int timeout = 300;  Uint32 loops = ctx->getNumLoops();  int records = ctx->getNumRecords();  int count;  NdbRestarter restarter;  Uint32 i = 1;  int dump7080[2];  dump7080[0] = 7080;  dump7080[1] = ctx->getTab()->getTableId();  UtilTransactions utilTrans(*ctx->getTab());  HugoTransactions hugoTrans(*ctx->getTab());  while(i<=loops && result != NDBT_FAILED){    ndbout << "Loop " << i << "/"<< loops <<" started" << endl;    /*      1. Start LCP, turn on undologging but delay write of datapages.      2. Insert, update, delete records      3. Complete writing of data pages and finish LCP.      4. Restart cluster and verify records    */    // Use dump state 7080 to delay writing of datapages    // for the current table    ndbout << "Dump state: "<<dump7080[0]<<", "<<dump7080[1]<<endl;    CHECK(restarter.dumpStateAllNodes(dump7080, 2) == 0);        NdbSleep_SecSleep(10);    ndbout << "Doing it all..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    CHECK(hugoTrans.scanUpdateRecords(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(utilTrans.clearTable(pNdb, records) == 0);    // Reset error and let LCP continue    CHECK(restarter.insertErrorInAllNodes(0) == 0);    NdbSleep_SecSleep(60);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == 0);    // Use dump state 7080 to delay writing of datapages    // for the current table    ndbout << "Dump state: "<<dump7080[0]<<", "<<dump7080[1]<<endl;    CHECK(restarter.dumpStateAllNodes(dump7080, 2) == 0);    NdbSleep_SecSleep(10);    ndbout << "Doing it all, delete 50%..." << endl;    CHECK(hugoTrans.loadTable(pNdb, records) == 0);    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);    // Reset error and let LCP continue    CHECK(restarter.insertErrorInAllNodes(0) == 0);    NdbSleep_SecSleep(20);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);    CHECK(count == (records/2));    CHECK(utilTrans.clearTable(pNdb, records) == 0);    i++;  }  ndbout << "runSystemRestartTestUndoLog finished" << endl;    return result;}int runSystemRestartTestFullDb(NDBT_Context* ctx, NDBT_Step* step){  Ndb* pNdb = GETNDB(step);  int result = NDBT_OK;  int timeout = 300;  Uint32 loops = ctx->getNumLoops();  int count1, count2;  NdbRestarter restarter;  Uint32 i = 1;  UtilTransactions utilTrans(*ctx->getTab());  HugoTransactions hugoTrans(*ctx->getTab());  while(i<=loops && result != NDBT_FAILED){    ndbout << "Loop " << i << "/"<< loops <<" started" << endl;    /*      1. Load data until db reports it's full      2. Restart cluster and verify records    */    ndbout << "Filling up table..." << endl;    CHECK(hugoTrans.fillTable(pNdb) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count1) == 0);    ndbout << "Db is full. Table has "<<count1 <<" records."<< endl;        ndbout << "Restarting cluster" << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(hugoTrans.scanReadRecords(pNdb, count1) == 0);    CHECK(utilTrans.selectCount(pNdb, 64, &count2) == 0);    CHECK(count1 == count2);    ndbout << "Deleting all records..." << endl;    CHECK(utilTrans.clearTable2(pNdb, count1) == 0);    ndbout << "Restarting cluster..." << endl;    CHECK(restarter.restartAll() == 0);    CHECK(restarter.waitClusterStarted(timeout) == 0);    CHECK(pNdb->waitUntilReady(timeout) == 0);    ndbout << "Verifying records..." << endl;    CHECK(utilTrans.selectCount(pNdb, 64, &count1) == 0);    CHECK(count1 == 0);    i++;  }  ndbout << "runSystemRestartTestFullDb finished" << endl;  

⌨️ 快捷键说明

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