summaryrefslogtreecommitdiff
path: root/ndb/test/ndbapi/testNodeRestart.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ndb/test/ndbapi/testNodeRestart.cpp')
-rw-r--r--ndb/test/ndbapi/testNodeRestart.cpp449
1 files changed, 449 insertions, 0 deletions
diff --git a/ndb/test/ndbapi/testNodeRestart.cpp b/ndb/test/ndbapi/testNodeRestart.cpp
new file mode 100644
index 00000000000..fd591f04c69
--- /dev/null
+++ b/ndb/test/ndbapi/testNodeRestart.cpp
@@ -0,0 +1,449 @@
+/* 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 <NdbRestarts.hpp>
+#include <Vector.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;
+}
+
+int runFillTable(NDBT_Context* ctx, NDBT_Step* step){
+
+ HugoTransactions hugoTrans(*ctx->getTab());
+ if (hugoTrans.fillTable(GETNDB(step)) != 0){
+ return NDBT_FAILED;
+ }
+ return NDBT_OK;
+}
+
+int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int records = ctx->getNumRecords();
+ int i = 0;
+ HugoTransactions hugoTrans(*ctx->getTab());
+ while (ctx->isTestStopped() == false) {
+ g_info << i << ": ";
+ if (hugoTrans.loadTable(GETNDB(step), records) != 0){
+ return NDBT_FAILED;
+ }
+ i++;
+ }
+ return result;
+}
+
+int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
+ int records = ctx->getNumRecords();
+
+ UtilTransactions utilTrans(*ctx->getTab());
+ if (utilTrans.clearTable(GETNDB(step), records) != 0){
+ return NDBT_FAILED;
+ }
+ return NDBT_OK;
+}
+
+int runClearTableUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
+ int records = ctx->getNumRecords();
+ int i = 0;
+
+ UtilTransactions utilTrans(*ctx->getTab());
+ while (ctx->isTestStopped() == false) {
+ g_info << i << ": ";
+ if (utilTrans.clearTable(GETNDB(step), records) != 0){
+ return NDBT_FAILED;
+ }
+ i++;
+ }
+ return NDBT_OK;
+}
+
+int runScanReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int records = ctx->getNumRecords();
+ int i = 0;
+ HugoTransactions hugoTrans(*ctx->getTab());
+ while (ctx->isTestStopped() == false) {
+ g_info << i << ": ";
+ if (hugoTrans.scanReadRecords(GETNDB(step), records) != 0){
+ return NDBT_FAILED;
+ }
+ i++;
+ }
+ return result;
+}
+
+int runPkReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int records = ctx->getNumRecords();
+ int i = 0;
+ HugoTransactions hugoTrans(*ctx->getTab());
+ while (ctx->isTestStopped() == false) {
+ g_info << i << ": ";
+ if (hugoTrans.pkReadRecords(GETNDB(step), records, 128) != 0){
+ return NDBT_FAILED;
+ }
+ i++;
+ }
+ return result;
+}
+
+int runPkUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int records = ctx->getNumRecords();
+ int i = 0;
+ HugoTransactions hugoTrans(*ctx->getTab());
+ while (ctx->isTestStopped() == false) {
+ g_info << i << ": ";
+ if (hugoTrans.pkUpdateRecords(GETNDB(step), records) != 0){
+ return NDBT_FAILED;
+ }
+ i++;
+ }
+ return result;
+}
+
+int runScanUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int records = ctx->getNumRecords();
+ int parallelism = ctx->getProperty("Parallelism", 1);
+ int abort = ctx->getProperty("AbortProb", (Uint32)0);
+ int i = 0;
+ HugoTransactions hugoTrans(*ctx->getTab());
+ while (ctx->isTestStopped() == false) {
+ g_info << i << ": ";
+ if (hugoTrans.scanUpdateRecords(GETNDB(step), records, abort,
+ parallelism) == NDBT_FAILED){
+ return NDBT_FAILED;
+ }
+ i++;
+ }
+ return result;
+}
+
+int runScanReadVerify(NDBT_Context* ctx, NDBT_Step* step){
+ int records = ctx->getNumRecords();
+ HugoTransactions hugoTrans(*ctx->getTab());
+
+ if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, 64) != 0){
+ return NDBT_FAILED;
+ }
+ return NDBT_OK;
+}
+
+int runRestarter(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int loops = ctx->getNumLoops();
+ NdbRestarter restarter;
+ int i = 0;
+ int lastId = 0;
+
+ if (restarter.getNumDbNodes() < 2){
+ ctx->stopTest();
+ return NDBT_OK;
+ }
+
+ if(restarter.waitClusterStarted(60) != 0){
+ g_err << "Cluster failed to start" << endl;
+ return NDBT_FAILED;
+ }
+
+ loops *= restarter.getNumDbNodes();
+ while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
+
+ int id = lastId % restarter.getNumDbNodes();
+ int nodeId = restarter.getDbNodeId(id);
+ ndbout << "Restart node " << nodeId << endl;
+ if(restarter.restartOneDbNode(nodeId) != 0){
+ g_err << "Failed to restartNextDbNode" << endl;
+ result = NDBT_FAILED;
+ break;
+ }
+
+ if(restarter.waitClusterStarted(60) != 0){
+ g_err << "Cluster failed to start" << endl;
+ result = NDBT_FAILED;
+ break;
+ }
+
+ NdbSleep_SecSleep(1);
+
+ lastId++;
+ i++;
+ }
+
+ ctx->stopTest();
+
+ return result;
+}
+
+int runCheckAllNodesStarted(NDBT_Context* ctx, NDBT_Step* step){
+ NdbRestarter restarter;
+
+ if(restarter.waitClusterStarted(1) != 0){
+ g_err << "All nodes was not started " << endl;
+ return NDBT_FAILED;
+ }
+
+ return NDBT_OK;
+}
+
+
+
+int runRestarts(NDBT_Context* ctx, NDBT_Step* step){
+ int result = NDBT_OK;
+ int loops = ctx->getNumLoops();
+ NDBT_TestCase* pCase = ctx->getCase();
+ NdbRestarts restarts;
+ int i = 0;
+ int timeout = 240;
+
+ while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
+
+ if(restarts.executeRestart(pCase->getName(), timeout) != 0){
+ g_err << "Failed to executeRestart(" <<pCase->getName() <<")" << endl;
+ result = NDBT_FAILED;
+ break;
+ }
+ i++;
+ }
+ return result;
+}
+
+NDBT_TESTSUITE(testNodeRestart);
+TESTCASE("NoLoad",
+ "Test that one node at a time can be stopped and then restarted "\
+ "when there are no load on the system. Do this loop number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarter);
+ FINALIZER(runClearTable);
+}
+TESTCASE("PkRead",
+ "Test that one node at a time can be stopped and then restarted "\
+ "perform pk read while restarting. Do this loop number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarter);
+ STEP(runPkReadUntilStopped);
+ FINALIZER(runClearTable);
+}
+TESTCASE("PkReadPkUpdate",
+ "Test that one node at a time can be stopped and then restarted "\
+ "perform pk read and pk update while restarting. Do this loop number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarter);
+ STEP(runPkReadUntilStopped);
+ STEP(runPkReadUntilStopped);
+ STEP(runPkReadUntilStopped);
+ STEP(runPkReadUntilStopped);
+ STEP(runPkUpdateUntilStopped);
+ FINALIZER(runClearTable);
+}
+TESTCASE("ReadUpdateScan",
+ "Test that one node at a time can be stopped and then restarted "\
+ "perform pk read, pk update and scan reads while restarting. Do this loop number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarter);
+ STEP(runPkReadUntilStopped);
+ STEP(runPkUpdateUntilStopped);
+ STEP(runScanReadUntilStopped);
+ STEP(runScanUpdateUntilStopped);
+ FINALIZER(runClearTable);
+}
+TESTCASE("Terror",
+ "Test that one node at a time can be stopped and then restarted "\
+ "perform all kind of transactions while restarting. Do this loop number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarter);
+ STEP(runPkReadUntilStopped);
+ STEP(runPkUpdateUntilStopped);
+ STEP(runScanReadUntilStopped);
+ STEP(runScanUpdateUntilStopped);
+ STEP(runInsertUntilStopped);
+ STEP(runClearTableUntilStopped);
+ FINALIZER(runClearTable);
+}
+TESTCASE("FullDb",
+ "Test that one node at a time can be stopped and then restarted "\
+ "when db is full. Do this loop number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runFillTable);
+ STEP(runRestarter);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartRandomNode",
+ "Test that we can execute the restart RestartRandomNode loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartRandomNodeError",
+ "Test that we can execute the restart RestartRandomNodeError loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartRandomNodeInitial",
+ "Test that we can execute the restart RestartRandomNodeInitial loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartNFDuringNR",
+ "Test that we can execute the restart RestartNFDuringNR loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartMasterNodeError",
+ "Test that we can execute the restart RestartMasterNodeError loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+
+TESTCASE("TwoNodeFailure",
+ "Test that we can execute the restart TwoNodeFailure\n"\
+ "(which is a multiple node failure restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("TwoMasterNodeFailure",
+ "Test that we can execute the restart TwoMasterNodeFailure\n"\
+ "(which is a multiple node failure restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("FiftyPercentFail",
+ "Test that we can execute the restart FiftyPercentFail\n"\
+ "(which is a multiple node failure restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartAllNodes",
+ "Test that we can execute the restart RestartAllNodes\n"\
+ "(which is a system restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartAllNodesAbort",
+ "Test that we can execute the restart RestartAllNodesAbort\n"\
+ "(which is a system restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartAllNodesError9999",
+ "Test that we can execute the restart RestartAllNodesError9999\n"\
+ "(which is a system restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("FiftyPercentStopAndWait",
+ "Test that we can execute the restart FiftyPercentStopAndWait\n"\
+ "(which is a system restart) loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("RestartNodeDuringLCP",
+ "Test that we can execute the restart RestartRandomNode loop\n"\
+ "number of times"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+TESTCASE("StopOnError",
+ "Test StopOnError. A node that has StopOnError set to false "\
+ "should restart automatically when an error occurs"){
+ INITIALIZER(runCheckAllNodesStarted);
+ INITIALIZER(runLoadTable);
+ STEP(runRestarts);
+ FINALIZER(runScanReadVerify);
+ FINALIZER(runClearTable);
+}
+NDBT_TESTSUITE_END(testNodeRestart);
+
+int main(int argc, const char** argv){
+#if 0
+ // It might be interesting to have longer defaults for num
+ // loops in this test
+ // Just performing 100 node restarts would not be enough?
+ // We can have initialisers in the NDBT_Testcase class like
+ // this...
+ testNodeRestart.setDefaultLoops(1000);
+#endif
+ return testNodeRestart.execute(argc, argv);
+}
+