18 #include "NdbMixRestarter.hpp"
20 NdbMixRestarter::NdbMixRestarter(
unsigned * _seed,
const char* _addr) :
26 ownseed = (unsigned)NdbTick_CurrentMillisecond();
35 NdbMixRestarter::~NdbMixRestarter()
40 #define CHECK(b) if (!(b)) { \
41 ndbout << "ERR: "<< step->getName() \
42 << " failed on line " << __LINE__ << endl; \
43 result = NDBT_FAILED; \
56 ctx->setProperty(NMR_SR_THREADS_STOPPED, (Uint32)0);
57 ctx->setProperty(NMR_SR_VALIDATE_THREADS_DONE, (Uint32)0);
59 ndbout <<
" -- Shutting down " << endl;
60 ctx->setProperty(NMR_SR, NdbMixRestarter::SR_STOPPING);
61 CHECK(restartAll(
false,
true, stopabort) == 0);
62 ctx->setProperty(NMR_SR, NdbMixRestarter::SR_STOPPED);
63 CHECK(waitClusterNoStart(timeout) == 0);
65 Uint32 cnt = ctx->getProperty(NMR_SR_THREADS);
66 Uint32 curr= ctx->getProperty(NMR_SR_THREADS_STOPPED);
67 while(curr != cnt && !ctx->isTestStopped())
71 ndbout_c(
"stopping: curr: %d cnt: %d", curr, cnt);
75 NdbSleep_MilliSleep(100);
76 curr= ctx->getProperty(NMR_SR_THREADS_STOPPED);
79 CHECK(ctx->isTestStopped() ==
false);
80 CHECK(startAll() == 0);
81 CHECK(waitClusterStarted(timeout) == 0);
83 cnt = ctx->getProperty(NMR_SR_VALIDATE_THREADS);
86 ndbout <<
" -- Validating starts " << endl;
87 ctx->setProperty(NMR_SR_VALIDATE_THREADS_DONE, (Uint32)0);
88 ctx->setProperty(NMR_SR, NdbMixRestarter::SR_VALIDATING);
89 curr = ctx->getProperty(NMR_SR_VALIDATE_THREADS_DONE);
90 while (curr != cnt && !ctx->isTestStopped())
94 ndbout_c(
"validating: curr: %d cnt: %d", curr, cnt);
98 NdbSleep_MilliSleep(100);
99 curr = ctx->getProperty(NMR_SR_VALIDATE_THREADS_DONE);
101 ndbout <<
" -- Validating complete " << endl;
103 CHECK(ctx->isTestStopped() ==
false);
104 ctx->setProperty(NMR_SR, NdbMixRestarter::SR_RUNNING);
118 for(i = 0; i<nodes.size(); i++)
122 alive_nodes.push_back(node);
126 for(i = 0; i<alive_nodes.size(); i++)
128 int group = alive_nodes[
i]->node_group;
129 for(j = 0; j<alive_nodes.size(); j++)
131 if (i != j && alive_nodes[j]->node_group == group)
133 victims.push_back(alive_nodes[i]);
145 select_nodes_to_stop(victims, nodes);
149 int victim = ndb_rand_r(seed) % victims.size();
150 return victims[victim];
164 for(i = 0; i<nodes.size(); i++)
168 victims.push_back(node);
174 select_node_to_start(
unsigned * seed,
178 select_nodes_to_start(victims, nodes);
182 int victim = ndb_rand_r(seed) % victims.size();
183 return victims[victim];
192 NdbMixRestarter::setRestartTypeMask(Uint32 mask)
205 while (!ctx->isTestStopped())
207 if (dostep(ctx, step))
209 NdbSleep_SecSleep(freq);
212 if (!finish(ctx, step))
221 Uint32 period, Uint32 freq)
226 Uint32 stop = (Uint32)
time(0) + period;
227 while (!ctx->isTestStopped() && (
time(0) < stop))
229 if (dostep(ctx, step))
233 NdbSleep_SecSleep(freq);
236 if (finish(ctx, step))
248 waitClusterStarted();
259 while(((action = (1 << (ndb_rand_r(seed) % RTM_COUNT))) & m_mask) == 0);
261 case RTM_RestartCluster:
262 if (restart_cluster(ctx, step))
264 for (Uint32 i = 0; i<m_nodes.size(); i++)
267 case RTM_RestartNode:
268 case RTM_RestartNodeInitial:
270 case RTM_StopNodeInitial:
272 if ((node = select_node_to_stop(seed, m_nodes)) == 0)
275 if (action == RTM_RestartNode || action == RTM_RestartNodeInitial)
276 ndbout <<
"Restarting " << node->
node_id;
278 ndbout <<
"Stopping " << node->
node_id;
281 action == RTM_RestartNodeInitial || action == RTM_StopNodeInitial;
287 if (restartOneDbNode(node->
node_id, initial,
true,
true))
290 if (waitNodesNoStart(&node->
node_id, 1))
295 if (action == RTM_StopNode || action == RTM_StopNodeInitial)
301 if ((node = select_node_to_start(seed, m_nodes)) == 0)
304 ndbout <<
"Starting " << node->
node_id << endl;
305 if (startNodes(&node->
node_id, 1))
307 if (waitNodesStarted(&node->
node_id, 1))
322 while((node = select_node_to_start(seed, m_nodes)))
324 not_started.push_back(node->
node_id);
329 if (not_started.size())
331 ndbout <<
"Starting stopped nodes " << endl;
332 if (startNodes(not_started.getBase(), not_started.size()))
334 if (waitClusterStarted())