22 #include <OutputStream.hpp>
27 #include <NdbRestarter.hpp>
30 int main(
int argc,
const char** argv){
33 const char* _hostName = NULL;
43 {
"seconds",
's', arg_integer, &_wait,
"Seconds to wait between each restart(0=random)",
"secs" },
44 {
"loops",
'l', arg_integer, &_loops,
"Number of loops",
"loops 0=forever"},
47 {
"abort",
'a', arg_flag, &_abort,
"Restart abort"},
48 {
"crash",
'c', arg_flag, &_crash,
"Crash instead of restart"},
50 {
"usage",
'?', arg_flag, &_help,
"Print help",
"" }
53 int num_args =
sizeof(args) /
sizeof(args[0]);
57 "This program will connect to the mgmsrv of a NDB cluster.\n"\
58 "It will wait for all nodes to be started, then restart all nodes\n"\
59 "into nostart state. Then after a random delay it will tell all nodes\n"\
60 "to start. It will do this loop number of times\n";
62 if(getarg(args, num_args, argc, argv, &optind) || _help) {
63 arg_printusage(args, num_args, argv[0], desc);
64 return NDBT_ProgramExit(NDBT_WRONGARGS);
66 _hostName = argv[optind];
71 g_err <<
"You can't specify both abort and crash" << endl;
72 arg_printusage(args, num_args, argv[0], desc);
73 return NDBT_ProgramExit(NDBT_WRONGARGS);
76 restarter.setRestartType(NdbRestarter::AbortRestart);
79 restarter.setRestartType(NdbRestarter::Crash);
84 while (_loops == 0 || l<_loops){
85 g_info <<
"Waiting for cluster to start" << endl;
86 while(restarter.waitClusterStarted(120) != 0){
87 g_warning <<
"Ndb failed to start in 2 minutes" << endl;
92 seconds = (rand() % 120) + 1;
93 g_info <<
"Waiting for "<<seconds<<
" secs" << endl;
94 NdbSleep_SecSleep(seconds);
96 g_info << l <<
": restarting all nodes with nostart" << endl;
97 const bool b = (restarter.restartAll(
false,
true,
false) == 0);
100 g_info <<
"Waiting for cluster to enter nostart" << endl;
101 while(restarter.waitClusterNoStart(120) != 0){
102 g_warning <<
"Ndb failed to enter no start in 2 minutes" << endl;
107 seconds = (rand() % 120) + 1;
108 g_info <<
"Waiting for " <<seconds<<
" secs" << endl;
109 NdbSleep_SecSleep(seconds);
111 g_info << l <<
": Telling all nodes to start" << endl;
112 const bool b2 = (restarter.startAll() == 0);
118 return NDBT_ProgramExit(NDBT_OK);