19 #include <NDBT_Test.hpp>
20 #include <HugoTransactions.hpp>
21 #include <UtilTransactions.hpp>
22 #include <NdbRestarter.hpp>
23 #include <AtrtClient.hpp>
24 #include <Bitmask.hpp>
25 #include <NdbBackup.hpp>
26 #include <ndb_version.h>
39 createEvent(
Ndb *pNdb,
41 bool merge_events =
true,
45 sprintf(eventName,
"%s_EVENT",tab.
getName());
50 g_err <<
"Dictionary not found "
56 myDict->dropEvent(eventName);
59 myEvent.setTable(tab.
getName());
62 myEvent.addEventColumn(a);
64 myEvent.mergeEvents(merge_events);
67 myEvent.setReport(NdbDictionary::Event::ER_SUBSCRIBE);
69 int res = myDict->createEvent(myEvent);
73 else if (myDict->getNdbError().classification ==
76 g_info <<
"Event creation failed event exists\n";
77 res = myDict->dropEvent(eventName);
79 g_err <<
"Failed to drop event: "
80 << myDict->getNdbError().code <<
" : "
81 << myDict->getNdbError().message << endl;
85 res = myDict->createEvent(myEvent);
87 g_err <<
"Failed to create event (1): "
88 << myDict->getNdbError().code <<
" : "
89 << myDict->getNdbError().message << endl;
95 g_err <<
"Failed to create event (2): "
96 << myDict->getNdbError().code <<
" : "
97 << myDict->getNdbError().message << endl;
108 char eventName[1024];
109 sprintf(eventName,
"%s_EVENT",tab.
getName());
112 g_err <<
"Dictionary not found "
117 if (myDict->dropEvent(eventName)) {
118 g_err <<
"Failed to drop event: "
119 << myDict->getNdbError().code <<
" : "
120 << myDict->getNdbError().message << endl;
131 Ndb* pNdb = GETNDB(step);
134 if (ctx->getProperty(
"NoDDL", Uint32(0)) == 0)
136 for (
unsigned i = 0;
i<table_list.size();
i++)
144 if ((res = createEvent(pNdb, *tab) != NDBT_OK))
151 if ((res = dropEvent(pNdb, *tab)) != NDBT_OK)
171 uint getNodeCount(NodeSet
set, uint numNodes)
185 uint range = numNodes - 2;
188 return (1 + (rand() % (range + 1)));
195 g_err <<
"Unknown set type : " <<
set << endl;
209 NodeSet mgmdNodeSet = (NodeSet) ctx->getProperty(
"MgmdNodeSet", Uint32(0));
210 NodeSet ndbdNodeSet = (NodeSet) ctx->getProperty(
"NdbdNodeSet", Uint32(0));
213 if (!atrt.getClusters(clusters))
216 while (clusters.next())
218 uint clusterId= clusters.columnAsInt(
"id");
220 if (!atrt.getConnectString(clusterId, tmp_result))
223 NdbRestarter restarter(tmp_result.column(
"connectstring"));
224 restarter.setReconnect(
true);
225 g_err <<
"Cluster '" << clusters.column(
"name")
226 <<
"@" << tmp_result.column(
"connectstring") <<
"'" << endl;
228 if (restarter.waitClusterStarted())
233 if (!atrt.getMgmds(clusterId, mgmds))
236 uint mgmdCount = mgmds.numRows();
237 uint restartCount = getNodeCount(mgmdNodeSet, mgmdCount);
239 ndbout <<
"Restarting "
240 << restartCount <<
" of " << mgmdCount
243 while (mgmds.next() && restartCount --)
245 ndbout <<
"Restart mgmd " << mgmds.columnAsInt(
"node_id") << endl;
246 if (!atrt.changeVersion(mgmds.columnAsInt(
"id"),
""))
249 if (restarter.waitConnected())
251 ndbout <<
"Connected to mgmd"<< endl;
254 ndbout <<
"Waiting for started"<< endl;
255 if (restarter.waitClusterStarted())
257 ndbout <<
"Started"<< endl;
261 if (!atrt.getNdbds(clusterId, ndbds))
264 uint ndbdCount = ndbds.numRows();
265 restartCount = getNodeCount(ndbdNodeSet, ndbdCount);
267 ndbout <<
"Restarting "
268 << restartCount <<
" of " << ndbdCount
271 while(ndbds.next() && restartCount --)
273 int nodeId = ndbds.columnAsInt(
"node_id");
274 int processId = ndbds.columnAsInt(
"id");
275 ndbout <<
"Restart node " << nodeId << endl;
277 if (!atrt.changeVersion(processId,
""))
280 if (restarter.waitNodesNoStart(&nodeId, 1))
283 if (restarter.startNodes(&nodeId, 1))
286 if (restarter.waitNodesStarted(&nodeId, 1))
289 if (createDropEvent(ctx, step))
302 Ndb* pNdb = GETNDB(step);
304 return NDBT_Tables::createTable(pNdb,
"I1");
315 const bool waitNode = ctx->getProperty(
"WaitNode", Uint32(0)) != 0;
316 const bool event = ctx->getProperty(
"CreateDropEvent", Uint32(0)) != 0;
317 const char * args =
"";
318 if (ctx->getProperty(
"KeepFS", Uint32(0)) != 0)
320 args =
"--initial=0";
323 NodeSet mgmdNodeSet = (NodeSet) ctx->getProperty(
"MgmdNodeSet", Uint32(0));
324 NodeSet ndbdNodeSet = (NodeSet) ctx->getProperty(
"NdbdNodeSet", Uint32(0));
327 if (!atrt.getClusters(clusters))
330 while (clusters.next())
332 uint clusterId= clusters.columnAsInt(
"id");
334 if (!atrt.getConnectString(clusterId, tmp_result))
337 NdbRestarter restarter(tmp_result.column(
"connectstring"));
338 restarter.setReconnect(
true);
339 g_err <<
"Cluster '" << clusters.column(
"name")
340 <<
"@" << tmp_result.column(
"connectstring") <<
"'" << endl;
342 if(restarter.waitClusterStarted())
347 if (!atrt.getMgmds(clusterId, mgmds))
350 uint mgmdCount = mgmds.numRows();
351 uint restartCount = getNodeCount(mgmdNodeSet, mgmdCount);
353 ndbout <<
"Restarting "
354 << restartCount <<
" of " << mgmdCount
357 while (mgmds.next() && restartCount --)
359 ndbout <<
"Restart mgmd" << mgmds.columnAsInt(
"node_id") << endl;
360 if (!atrt.changeVersion(mgmds.columnAsInt(
"id"),
""))
363 if(restarter.waitConnected())
367 NdbSleep_SecSleep(5);
371 if (!atrt.getNdbds(clusterId, ndbds))
378 n.nodeId = ndbds.columnAsInt(
"node_id");
379 n.processId = ndbds.columnAsInt(
"id");
380 n.nodeGroup = restarter.getNodeGroup(
n.nodeId);
384 uint ndbdCount = ndbds.numRows();
385 restartCount = getNodeCount(ndbdNodeSet, ndbdCount);
387 ndbout <<
"Restarting "
388 << restartCount <<
" of " << ndbdCount
396 for (Uint32
i = 0; (
i<nodes.size() && restartCount);
i++)
398 int nodeId = nodes[
i].nodeId;
399 int processId = nodes[
i].processId;
400 int nodeGroup= nodes[
i].nodeGroup;
402 if (seen_groups.
get(nodeGroup))
407 seen_groups.
set(nodeGroup);
408 restarted_nodes.
set(nodeId);
410 ndbout <<
"Restart node " << nodeId << endl;
412 if (!atrt.changeVersion(processId, args))
417 restarter.waitNodesNoStart(&nodeId, 1);
420 nodesarray[cnt++]= nodeId;
426 if (restarter.waitNodesNoStart(nodesarray, cnt))
430 ndbout <<
"Starting and wait for started..." << endl;
431 if (restarter.startAll())
434 if (restarter.waitClusterStarted())
437 if (
event && createDropEvent(ctx, step))
444 for (Uint32
i = 0; (
i<nodes.size() && restartCount);
i++)
446 int nodeId = nodes[
i].nodeId;
447 int processId = nodes[
i].processId;
449 if (restarted_nodes.
get(nodeId))
452 ndbout <<
"Restart node " << nodeId << endl;
453 if (!atrt.changeVersion(processId, args))
458 restarter.waitNodesNoStart(&nodeId, 1);
461 nodesarray[cnt++]= nodeId;
468 if (restarter.waitNodesNoStart(nodesarray, cnt))
472 ndbout <<
"Starting and wait for started..." << endl;
473 if (restarter.startAll())
476 if (restarter.waitClusterStarted())
479 if (
event && createDropEvent(ctx, step))
499 ctx->setProperty(
"WaitNode", 1);
500 ctx->setProperty(
"CreateDropEvent", 1);
501 int res = runUpgrade_Half(ctx, step);
515 ctx->setProperty(
"CreateDropEvent", 1);
516 int res = runUpgrade_Half(ctx, step);
526 ctx->setProperty(
"MgmdNodeSet", (Uint32) NodeSet(None));
527 int res = runUpgrade_Half(ctx, step);
538 ctx->setProperty(
"MgmdNodeSet", (Uint32) NodeSet(None));
539 int res = runUpgrade_Half(ctx, step);
542 ctx->setProperty(
"MgmdNodeSet", (Uint32) NodeSet(All));
543 ctx->setProperty(
"NdbdNodeSet", (Uint32) NodeSet(None));
544 res = runUpgrade_Half(ctx, step);
555 ctx->setProperty(
"MgmdNodeSet", (Uint32) NodeSet(NotAll));
556 ctx->setProperty(
"NdbdNodeSet", (Uint32) NodeSet(None));
557 int res = runUpgrade_Half(ctx, step);
566 if(restarter.waitClusterStarted() != 0){
567 g_err <<
"All nodes was not started " << endl;
573 if(!atrt.waitConnected()){
574 g_err <<
"atrt server was not started " << endl;
580 if (!atrt.doQuery(
"SELECT * FROM process where type <> \'mysql\'", procs))
585 if (procs.columnAsInt(
"node_id") == (unsigned)-1){
586 ndbout <<
"Found one process with node_id -1, "
587 <<
"use --fix-nodeid=1 to atrt to fix this" << endl;
598 ndbout_c(
"createAllTables");
599 if (NDBT_Tables::createAllTables(GETNDB(step),
false,
true))
602 for (
int i = 0;
i<NDBT_Tables::getNumTables();
i++)
603 table_list.push_back(
BaseString(NDBT_Tables::getTable(
i)->getName()));
621 ndbout <<
"Looking for tables ... ";
622 for (
int i = 0;
i<NDBT_Tables::getNumTables();
i++)
625 GETNDB(step)->getDictionary()
626 ->getTable(NDBT_Tables::getTable(
i)
630 ndbout << tab->
getName() <<
" ";
642 Ndb* pNdb = GETNDB(step);
644 int records = ctx->getNumRecords();
645 int result = NDBT_OK;
647 for (
unsigned i = 0;
i<table_list.size();
i++)
651 trans.loadTable(pNdb, records);
652 trans.scanUpdateRecords(pNdb, records);
661 Ndb* pNdb = GETNDB(step);
663 int records = ctx->getNumRecords();
664 int result = NDBT_OK;
666 for (
unsigned i = 0;
i<table_list.size();
i++)
672 trans.clearTable(pNdb, records);
683 Ndb* pNdb = GETNDB(step);
685 int records = ctx->getNumRecords();
686 int result = NDBT_OK;
689 while (!ctx->isTestStopped())
691 for (
unsigned i = 0;
i<table_list.size();
i++)
697 trans.loadTable(pNdb, records);
698 trans.scanUpdateRecords(pNdb, records);
699 trans.pkUpdateRecords(pNdb, records);
700 trans.pkReadUnlockRecords(pNdb, records);
703 trans.scanUpdateRecords(pNdb, records);
706 if (strcmp(tab->
getName(),
"T1") == 0)
707 trans.pkInterpretedUpdateRecords(pNdb, records);
708 trans.clearTable(pNdb, records/2);
709 trans.loadTable(pNdb, records/2);
712 trans.clearTable(pNdb, records/2);
713 trans.loadTable(pNdb, records/2);
714 trans.clearTable(pNdb, records/2);
717 if (createDropEvent(ctx, step))
738 if (!atrt.getClusters(clusters))
741 while (clusters.next())
743 uint clusterId= clusters.columnAsInt(
"id");
745 if (!atrt.getConnectString(clusterId, tmp_result))
748 NdbRestarter restarter(tmp_result.column(
"connectstring"));
749 if (restarter.rollingRestart())
760 ndbout_c(
"upgrading");
761 int res = runUpgrade_Half(ctx, step);
764 ndbout_c(
"rolling restarting");
765 res = rollingRestart(ctx, step);
779 if (ctx->getProperty(
"RestartNoDDL", Uint32(0)))
784 extraArgs.
append(
" --noddl ");
796 tc.
assfmt(
"-n %s--post-upgrade %s",
797 ctx->getCase()->getName(),
800 ndbout <<
"About to restart self with extra arg: " << tc.
c_str() << endl;
804 if (process_id == -1)
806 g_err <<
"Failed to find own process id" << endl;
810 if (!atrt.changeVersion(process_id, tc.
c_str()))
826 ctx->setProperty(
"RestartNoDDL", 1);
827 return startPostUpgradeChecks(ctx, step);
838 NdbBackup backup(GETNDB(step)->getNodeId()+1);
840 ndbout <<
"Starting backup..." << flush;
841 if (backup.start() != 0)
843 ndbout <<
"Failed" << endl;
846 ndbout <<
"done" << endl;
849 if ((ctx->getProperty(
"NoDDL", Uint32(0)) == 0) &&
850 (ctx->getProperty(
"KeepFS", Uint32(0)) != 0))
858 Ndb* pNdb = GETNDB(step);
868 if (NDBT_Tables::createTable(pNdb,
"I3"))
870 ndbout_c(
"Failed to create table!");
883 if (res.restartAll() != 0)
885 ndbout_c(
"restartAll() failed");
889 if (res.waitClusterStarted() != 0)
891 ndbout_c(
"waitClusterStarted() failed");
897 ndbout_c(
"Table disappered");
909 Uint32 waitSeconds = ctx->getProperty(
"WaitSeconds", Uint32(30));
910 while (waitSeconds &&
911 !ctx->isTestStopped())
913 NdbSleep_MilliSleep(1000);
920 bool versionsSpanBoundary(
int verA,
int verB,
int incBoundaryVer)
922 int minPeerVer = MIN(verA, verB);
923 int maxPeerVer = MAX(verA, verB);
925 return ( (minPeerVer < incBoundaryVer) &&
926 (maxPeerVer >= incBoundaryVer) );
929 #define SchemaTransVersion NDB_MAKE_VERSION(6,4,0)
943 Ndb* pNdb = GETNDB(step);
947 int myVer = NDB_VERSION;
953 g_err <<
"getNodeTypeVersionRange call failed" << endl;
957 if (minNdbVer != maxNdbVer)
960 ndbout <<
"Ndbd nodes have mixed versions, DDL not supported" << endl;
962 if (versionsSpanBoundary(myVer, minNdbVer, SchemaTransVersion))
965 ndbout <<
"Api and Ndbd versions span schema-trans boundary, DDL not supported" << endl;
968 ctx->setProperty(
"NoDDL", useDDL?0:1);
972 ndbout <<
"Dropping and recreating tables..." << endl;
974 for (
int i=0;
i < NDBT_Tables::getNumTables();
i++)
978 int ret= NDBT_Tables::createTable(pNdb,
979 NDBT_Tables::getTable(
i)->getName(),
986 g_err <<
"Failed to create table "
987 << NDBT_Tables::getTable(
i)->
getName()
996 if (minNdbVer >= myVer)
998 g_err <<
"Error 794 received, but data nodes are upgraded" << endl;
1002 g_err <<
"Create table failure due to old version NDBDs, continuing" << endl;
1006 ndbout <<
"Done" << endl;
1013 NDBT_TESTSUITE(testUpgrade);
1014 TESTCASE(
"Upgrade_NR1",
1015 "Test that one node at a time can be upgraded"){
1016 INITIALIZER(runCheckStarted);
1017 INITIALIZER(runBug48416);
1018 STEP(runUpgrade_NR1);
1019 VERIFIER(startPostUpgradeChecks);
1021 POSTUPGRADE(
"Upgrade_NR1")
1023 INITIALIZER(runCheckStarted);
1024 INITIALIZER(runPostUpgradeChecks);
1026 TESTCASE(
"Upgrade_NR2",
1027 "Test that one node in each nodegroup can be upgradde simultaneously"){
1028 INITIALIZER(runCheckStarted);
1029 STEP(runUpgrade_NR2);
1030 VERIFIER(startPostUpgradeChecks);
1032 POSTUPGRADE(
"Upgrade_NR2")
1034 INITIALIZER(runCheckStarted);
1035 INITIALIZER(runPostUpgradeChecks);
1037 TESTCASE(
"Upgrade_NR3",
1038 "Test that one node in each nodegroup can be upgradde simultaneously"){
1039 INITIALIZER(runCheckStarted);
1040 STEP(runUpgrade_NR3);
1041 VERIFIER(startPostUpgradeChecks);
1043 POSTUPGRADE(
"Upgrade_NR3")
1045 INITIALIZER(runCheckStarted);
1046 INITIALIZER(runPostUpgradeChecks);
1048 TESTCASE(
"Upgrade_FS",
1049 "Test that one node in each nodegroup can be upgrade simultaneously")
1051 TC_PROPERTY(
"KeepFS", 1);
1052 INITIALIZER(runCheckStarted);
1053 INITIALIZER(runCreateAllTables);
1054 INITIALIZER(runLoadAll);
1055 STEP(runUpgrade_Traffic);
1056 VERIFIER(startPostUpgradeChecks);
1058 POSTUPGRADE(
"Upgrade_FS")
1060 INITIALIZER(runCheckStarted);
1061 INITIALIZER(runPostUpgradeChecks);
1063 TESTCASE(
"Upgrade_Traffic",
1064 "Test upgrade with traffic, all tables and restart --initial")
1066 INITIALIZER(runCheckStarted);
1067 INITIALIZER(runCreateAllTables);
1068 STEP(runUpgrade_Traffic);
1070 VERIFIER(startPostUpgradeChecks);
1072 POSTUPGRADE(
"Upgrade_Traffic")
1074 INITIALIZER(runCheckStarted);
1075 INITIALIZER(runPostUpgradeChecks);
1077 TESTCASE(
"Upgrade_Traffic_FS",
1078 "Test upgrade with traffic, all tables and restart using FS")
1080 TC_PROPERTY(
"KeepFS", 1);
1081 INITIALIZER(runCheckStarted);
1082 INITIALIZER(runCreateAllTables);
1083 STEP(runUpgrade_Traffic);
1085 VERIFIER(startPostUpgradeChecks);
1087 POSTUPGRADE(
"Upgrade_Traffic_FS")
1089 INITIALIZER(runCheckStarted);
1090 INITIALIZER(runPostUpgradeChecks);
1092 TESTCASE(
"Upgrade_Traffic_one",
1093 "Test upgrade with traffic, *one* table and restart --initial")
1095 INITIALIZER(runCheckStarted);
1096 INITIALIZER(runCreateOneTable);
1097 STEP(runUpgrade_Traffic);
1099 VERIFIER(startPostUpgradeChecks);
1101 POSTUPGRADE(
"Upgrade_Traffic_one")
1103 INITIALIZER(runCheckStarted);
1104 INITIALIZER(runPostUpgradeChecks);
1106 TESTCASE(
"Upgrade_Traffic_FS_one",
1107 "Test upgrade with traffic, all tables and restart using FS")
1109 TC_PROPERTY(
"KeepFS", 1);
1110 INITIALIZER(runCheckStarted);
1111 INITIALIZER(runCreateOneTable);
1112 STEP(runUpgrade_Traffic);
1114 VERIFIER(startPostUpgradeChecks);
1116 POSTUPGRADE(
"Upgrade_Traffic_FS_one")
1118 INITIALIZER(runCheckStarted);
1119 INITIALIZER(runPostUpgradeChecks);
1121 TESTCASE(
"Upgrade_Api_Only",
1122 "Test that upgrading the Api node only works")
1124 INITIALIZER(runCheckStarted);
1125 INITIALIZER(runCreateAllTables);
1126 VERIFIER(startPostUpgradeChecksApiFirst);
1128 POSTUPGRADE(
"Upgrade_Api_Only")
1130 INITIALIZER(runCheckStarted);
1131 INITIALIZER(runPostUpgradeDecideDDL);
1132 INITIALIZER(runGetTableList);
1133 TC_PROPERTY(
"WaitSeconds", 30);
1135 STEP(runPostUpgradeChecks);
1137 FINALIZER(runClearAll);
1139 TESTCASE(
"Upgrade_Api_Before_NR1",
1140 "Test that upgrading the Api node before the kernel works")
1143 INITIALIZER(runCheckStarted);
1144 INITIALIZER(runCreateAllTables);
1145 VERIFIER(startPostUpgradeChecksApiFirst);
1147 POSTUPGRADE(
"Upgrade_Api_Before_NR1")
1149 INITIALIZER(runCheckStarted);
1150 INITIALIZER(runPostUpgradeDecideDDL);
1151 INITIALIZER(runGetTableList);
1153 STEP(runUpgrade_NR1);
1154 FINALIZER(runPostUpgradeChecks);
1155 FINALIZER(runClearAll);
1157 TESTCASE(
"Upgrade_Api_NDBD_MGMD",
1158 "Test that updating in reverse order works")
1160 INITIALIZER(runCheckStarted);
1161 INITIALIZER(runCreateAllTables);
1162 VERIFIER(startPostUpgradeChecksApiFirst);
1164 POSTUPGRADE(
"Upgrade_Api_NDBD_MGMD")
1166 INITIALIZER(runCheckStarted);
1167 INITIALIZER(runPostUpgradeDecideDDL);
1168 INITIALIZER(runGetTableList);
1170 STEP(runUpgrade_NdbdFirst);
1171 FINALIZER(runPostUpgradeChecks);
1172 FINALIZER(runClearAll);
1174 TESTCASE(
"Upgrade_Mixed_MGMD_API_NDBD",
1175 "Test that upgrading MGMD/API partially before data nodes works")
1177 INITIALIZER(runCheckStarted);
1178 INITIALIZER(runCreateAllTables);
1179 STEP(runUpgrade_NotAllMGMD);
1181 VERIFIER(startPostUpgradeChecksApiFirst);
1183 POSTUPGRADE(
"Upgrade_Mixed_MGMD_API_NDBD")
1185 INITIALIZER(runCheckStarted);
1186 INITIALIZER(runPostUpgradeDecideDDL);
1187 INITIALIZER(runGetTableList);
1188 INITIALIZER(runClearAll);
1190 STEP(runUpgrade_NdbdFirst);
1191 FINALIZER(runPostUpgradeChecks);
1192 FINALIZER(runClearAll);
1195 NDBT_TESTSUITE_END(testUpgrade);
1197 int main(
int argc,
const char** argv){
1199 NDBT_TESTSUITE_INSTANCE(testUpgrade);
1200 testUpgrade.setCreateAllTables(
true);
1201 return testUpgrade.execute(argc, argv);