~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/src/NdbRestarts.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <NdbRestarts.hpp>
 
17
#include <NDBT.hpp>
 
18
#include <string.h>
 
19
#include <NdbSleep.h>
 
20
#include <kernel/ndb_limits.h>
 
21
#include <signaldata/DumpStateOrd.hpp>
 
22
#include <NdbEnv.h>
 
23
 
 
24
 
 
25
int restartRandomNodeGraceful(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
26
int restartRandomNodeAbort(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
27
int restartRandomNodeError(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
28
int restartRandomNodeInitial(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
29
int restartNFDuringNR(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
30
int restartMasterNodeError(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
31
int twoNodeFailure(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
32
int fiftyPercentFail(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
33
int twoMasterNodeFailure(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
34
int restartAllNodesGracfeul(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
35
int restartAllNodesAbort(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
36
int restartAllNodesError9999(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
37
int fiftyPercentStopAndWait(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
38
int restartNodeDuringLCP(NdbRestarter& _restarter,
 
39
                         const NdbRestarts::NdbRestart* _restart);
 
40
int stopOnError(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
41
int getRandomNodeId(NdbRestarter& _restarter);
 
42
 
 
43
/**
 
44
 * Define list of restarts
 
45
 *  - name of restart
 
46
 *  - function perfoming the restart
 
47
 *  - required number of nodes
 
48
 *  - ...
 
49
 *  - arg1, used depending of restart
 
50
 *  - arg2, used depending of restart
 
51
 */
 
52
 
 
53
const NdbRestarts::NdbRestart NdbRestarts::m_restarts[] = {
 
54
  /*********************************************************
 
55
   *
 
56
   *  NODE RESTARTS with 1 node restarted
 
57
   *
 
58
   *********************************************************/
 
59
  /** 
 
60
   * Restart a randomly selected node
 
61
   * with graceful shutdown
 
62
   */ 
 
63
  NdbRestart("RestartRandomNode", 
 
64
             NODE_RESTART,
 
65
             restartRandomNodeGraceful,
 
66
             2),
 
67
  /** 
 
68
   * Restart a randomly selected node
 
69
   * with immediate(abort) shutdown
 
70
   */ 
 
71
  NdbRestart("RestartRandomNodeAbort", 
 
72
             NODE_RESTART,
 
73
             restartRandomNodeAbort,
 
74
             2),
 
75
  /** 
 
76
   * Restart a randomly selected node
 
77
   * with  error insert
 
78
   *
 
79
   */ 
 
80
  NdbRestart("RestartRandomNodeError",
 
81
             NODE_RESTART,
 
82
             restartRandomNodeError,
 
83
             2),
 
84
  /**
 
85
   * Restart the master node
 
86
   * with  error insert
 
87
   */ 
 
88
  NdbRestart("RestartMasterNodeError",
 
89
             NODE_RESTART,
 
90
             restartMasterNodeError,
 
91
             2),
 
92
  /**
 
93
   * Restart a randomly selected node without fileystem
 
94
   *
 
95
   */ 
 
96
  NdbRestart("RestartRandomNodeInitial",
 
97
             NODE_RESTART,
 
98
             restartRandomNodeInitial,
 
99
             2),
 
100
  /**
 
101
   * Restart a randomly selected node and then 
 
102
   * crash it while restarting
 
103
   *
 
104
   */    
 
105
  NdbRestart("RestartNFDuringNR",
 
106
             NODE_RESTART,
 
107
             restartNFDuringNR,
 
108
             2),   
 
109
 
 
110
  /**
 
111
   * Set StopOnError and crash the node by sending
 
112
   * SYSTEM_ERROR to it
 
113
   *
 
114
   */    
 
115
  NdbRestart("StopOnError",
 
116
             NODE_RESTART,
 
117
             stopOnError,
 
118
             1),  
 
119
 
 
120
  /*********************************************************
 
121
   *
 
122
   *  MULTIPLE NODE RESTARTS with more than 1 node
 
123
   *
 
124
   *********************************************************/
 
125
  /**
 
126
   * 2 nodes restart, select nodes to restart randomly and restart 
 
127
   * with a small random delay between restarts
 
128
   */ 
 
129
  NdbRestart("TwoNodeFailure",
 
130
             MULTIPLE_NODE_RESTART,
 
131
             twoNodeFailure,
 
132
             4),
 
133
  /**
 
134
   * 2 nodes restart, select master nodes and restart with 
 
135
   * a small random delay between restarts 
 
136
   */ 
 
137
  
 
138
  NdbRestart("TwoMasterNodeFailure",
 
139
             MULTIPLE_NODE_RESTART,
 
140
             twoMasterNodeFailure,
 
141
             4),
 
142
 
 
143
  NdbRestart("FiftyPercentFail",
 
144
             MULTIPLE_NODE_RESTART,
 
145
             fiftyPercentFail,
 
146
             2),
 
147
 
 
148
  /*********************************************************
 
149
   *
 
150
   *  SYSTEM RESTARTS
 
151
   *
 
152
   *********************************************************/
 
153
  /**
 
154
   * Restart all nodes with graceful shutdown
 
155
   *
 
156
   */ 
 
157
  
 
158
  NdbRestart("RestartAllNodes",
 
159
             SYSTEM_RESTART,
 
160
             restartAllNodesGracfeul,
 
161
             1),
 
162
  /**
 
163
   * Restart all nodes immediately without
 
164
   * graful shutdown
 
165
   */ 
 
166
  NdbRestart("RestartAllNodesAbort",
 
167
             SYSTEM_RESTART,
 
168
             restartAllNodesAbort,
 
169
             1),
 
170
  /**
 
171
   * Restart all nodes with error insert 9999
 
172
   * TODO! We can later add more errors like 9998, 9997 etc.
 
173
   */ 
 
174
  NdbRestart("RestartAllNodesError9999",
 
175
             SYSTEM_RESTART,
 
176
             restartAllNodesError9999,
 
177
             1),
 
178
  /**
 
179
   * Stop 50% of all nodes with error insert 9999
 
180
   * Wait for a random number of minutes
 
181
   * Stop the rest of the nodes and then start all again
 
182
   */ 
 
183
  NdbRestart("FiftyPercentStopAndWait",
 
184
             SYSTEM_RESTART,
 
185
             fiftyPercentStopAndWait,
 
186
             2),
 
187
  /** 
 
188
   * Restart a master node during LCP with error inserts.
 
189
   */ 
 
190
  NdbRestart("RestartNodeDuringLCP", 
 
191
             NODE_RESTART,
 
192
             restartNodeDuringLCP,
 
193
             2),
 
194
};
 
195
 
 
196
const int NdbRestarts::m_NoOfRestarts = sizeof(m_restarts) / sizeof(NdbRestart);
 
197
 
 
198
 
 
199
const NdbRestarts::NdbErrorInsert NdbRestarts::m_errors[] = {
 
200
  NdbErrorInsert("Error9999", 9999)
 
201
};
 
202
 
 
203
const int NdbRestarts::m_NoOfErrors = sizeof(m_errors) / sizeof(NdbErrorInsert);
 
204
 
 
205
NdbRestarts::NdbRestart::NdbRestart(const char* _name,
 
206
                                    NdbRestartType _type,
 
207
                                    restartFunc* _func,
 
208
                                    int _requiredNodes,
 
209
                                    int _arg1){
 
210
  m_name = _name;
 
211
  m_type = _type;
 
212
  m_restartFunc = _func;
 
213
  m_numRequiredNodes = _requiredNodes;
 
214
  //  m_arg1 = arg1;
 
215
}
 
216
 
 
217
 
 
218
int NdbRestarts::getNumRestarts(){
 
219
  return m_NoOfRestarts;
 
220
}
 
221
 
 
222
const NdbRestarts::NdbRestart* NdbRestarts::getRestart(int _num){
 
223
  if (_num >= m_NoOfRestarts)
 
224
    return NULL;
 
225
 
 
226
  return &m_restarts[_num];
 
227
}
 
228
 
 
229
const NdbRestarts::NdbRestart* NdbRestarts::getRestart(const char* _name){
 
230
  for(int i = 0; i < m_NoOfRestarts; i++){
 
231
    if (strcmp(m_restarts[i].m_name, _name) == 0){
 
232
      return &m_restarts[i];
 
233
    }
 
234
  }
 
235
  g_err << "The restart \""<< _name << "\" not found in NdbRestarts" << endl;
 
236
  return NULL;
 
237
}
 
238
 
 
239
 
 
240
int NdbRestarts::executeRestart(const NdbRestarts::NdbRestart* _restart, 
 
241
                                unsigned int _timeout){
 
242
  // Check that there are enough nodes in the cluster
 
243
  // for this test
 
244
  NdbRestarter restarter;
 
245
  if (_restart->m_numRequiredNodes > restarter.getNumDbNodes()){
 
246
    g_err << "This test requires " << _restart->m_numRequiredNodes << " nodes "
 
247
          << "there are only "<< restarter.getNumDbNodes() <<" nodes in cluster" 
 
248
          << endl;
 
249
    return NDBT_OK;
 
250
  }
 
251
  if (restarter.waitClusterStarted(120) != 0){
 
252
    // If cluster is not started when we shall peform restart
 
253
    // the restart can not be executed and the test fails
 
254
    return NDBT_FAILED;
 
255
  }
 
256
  
 
257
  int res = _restart->m_restartFunc(restarter, _restart);
 
258
 
 
259
  // Sleep a little waiting for nodes to react to command
 
260
  NdbSleep_SecSleep(2);
 
261
 
 
262
  if  (_timeout == 0){
 
263
    // If timeout == 0 wait for ever
 
264
    while(restarter.waitClusterStarted(60) != 0)
 
265
      g_err << "Cluster is not started after restart. Waiting 60s more..." 
 
266
            << endl;
 
267
  } else {
 
268
    if (restarter.waitClusterStarted(_timeout) != 0){
 
269
      g_err<<"Cluster failed to start" << endl;
 
270
      res = NDBT_FAILED; 
 
271
    }
 
272
  }
 
273
 
 
274
  return res;
 
275
 
276
 
 
277
int NdbRestarts::executeRestart(int _num,
 
278
                                unsigned int _timeout){
 
279
  const NdbRestarts::NdbRestart* r = getRestart(_num);
 
280
  if (r == NULL)
 
281
    return NDBT_FAILED;
 
282
 
 
283
  int res = executeRestart(r, _timeout);
 
284
  return res;
 
285
}
 
286
 
 
287
int NdbRestarts::executeRestart(const char* _name,
 
288
                                unsigned int _timeout){
 
289
  const NdbRestarts::NdbRestart* r = getRestart(_name);
 
290
  if (r == NULL)
 
291
    return NDBT_FAILED;
 
292
 
 
293
  int res = executeRestart(r, _timeout);
 
294
  return res;
 
295
}
 
296
 
 
297
void NdbRestarts::listRestarts(NdbRestartType _type){
 
298
  for(int i = 0; i < m_NoOfRestarts; i++){
 
299
    if (m_restarts[i].m_type == _type)
 
300
      ndbout << " " << m_restarts[i].m_name << ", min " 
 
301
             << m_restarts[i].m_numRequiredNodes 
 
302
             << " nodes"<< endl;
 
303
  }  
 
304
}
 
305
 
 
306
void NdbRestarts::listRestarts(){
 
307
  ndbout << "NODE RESTARTS" << endl;
 
308
  listRestarts(NODE_RESTART);
 
309
  ndbout << "MULTIPLE NODE RESTARTS" << endl;
 
310
  listRestarts(MULTIPLE_NODE_RESTART);
 
311
  ndbout << "SYSTEM RESTARTS" << endl;
 
312
  listRestarts(SYSTEM_RESTART);  
 
313
}
 
314
 
 
315
NdbRestarts::NdbErrorInsert::NdbErrorInsert(const char* _name,
 
316
                                            int _errorNo){
 
317
  
 
318
  m_name = _name;
 
319
  m_errorNo = _errorNo;
 
320
}
 
321
 
 
322
int NdbRestarts::getNumErrorInserts(){
 
323
  return m_NoOfErrors;
 
324
}
 
325
 
 
326
const NdbRestarts::NdbErrorInsert* NdbRestarts::getError(int _num){
 
327
  if (_num >= m_NoOfErrors)
 
328
    return NULL;
 
329
  return &m_errors[_num];
 
330
}
 
331
 
 
332
const NdbRestarts::NdbErrorInsert* NdbRestarts::getRandomError(){
 
333
  int randomId = myRandom48(m_NoOfErrors);
 
334
  return &m_errors[randomId];
 
335
}
 
336
 
 
337
 
 
338
 
 
339
/**
 
340
 *
 
341
 * IMPLEMENTATION OF THE DIFFERENT RESTARTS
 
342
 * Each function should perform it's action
 
343
 * and the returned NDBT_OK or NDBT_FAILED
 
344
 *
 
345
 */
 
346
 
 
347
 
 
348
#define CHECK(b, m) { int _xx = b; if (!(_xx)) { \
 
349
  ndbout << "ERR: "<< m \
 
350
           << "   " << "File: " << __FILE__ \
 
351
           << " (Line: " << __LINE__ << ")" << "- " << _xx << endl; \
 
352
  return NDBT_FAILED; } }
 
353
 
 
354
 
 
355
 
 
356
int restartRandomNodeGraceful(NdbRestarter& _restarter, 
 
357
                              const NdbRestarts::NdbRestart* _restart){
 
358
 
 
359
  myRandom48Init(NdbTick_CurrentMillisecond());
 
360
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
361
  int nodeId = _restarter.getDbNodeId(randomId);
 
362
  
 
363
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
364
 
 
365
  CHECK(_restarter.restartOneDbNode(nodeId) == 0, 
 
366
        "Could not restart node "<<nodeId);
 
367
 
 
368
  return NDBT_OK;
 
369
}
 
370
 
 
371
int restartRandomNodeAbort(NdbRestarter& _restarter, 
 
372
                              const NdbRestarts::NdbRestart* _restart){
 
373
 
 
374
  myRandom48Init(NdbTick_CurrentMillisecond());
 
375
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
376
  int nodeId = _restarter.getDbNodeId(randomId);
 
377
  
 
378
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
379
 
 
380
  CHECK(_restarter.restartOneDbNode(nodeId, false, false, true) == 0, 
 
381
        "Could not restart node "<<nodeId);
 
382
 
 
383
  return NDBT_OK;
 
384
}
 
385
 
 
386
int restartRandomNodeError(NdbRestarter& _restarter, 
 
387
                           const NdbRestarts::NdbRestart* _restart){
 
388
 
 
389
  myRandom48Init(NdbTick_CurrentMillisecond());
 
390
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
391
  int nodeId = _restarter.getDbNodeId(randomId);
 
392
  
 
393
  ndbout << _restart->m_name << ": node = "<<nodeId << endl;
 
394
 
 
395
  CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0, 
 
396
        "Could not restart node "<<nodeId);
 
397
 
 
398
  return NDBT_OK;
 
399
}
 
400
 
 
401
int restartMasterNodeError(NdbRestarter& _restarter, 
 
402
                           const NdbRestarts::NdbRestart* _restart){
 
403
 
 
404
  int nodeId = _restarter.getDbNodeId(0);
 
405
  
 
406
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
407
 
 
408
  CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0, 
 
409
        "Could not restart node "<<nodeId);
 
410
 
 
411
  return NDBT_OK;
 
412
}
 
413
 
 
414
int restartRandomNodeInitial(NdbRestarter& _restarter, 
 
415
                             const NdbRestarts::NdbRestart* _restart){
 
416
 
 
417
  myRandom48Init(NdbTick_CurrentMillisecond());
 
418
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
419
  int nodeId = _restarter.getDbNodeId(randomId);
 
420
  
 
421
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
422
 
 
423
  CHECK(_restarter.restartOneDbNode(nodeId, true) == 0,
 
424
        "Could not restart node "<<nodeId);
 
425
 
 
426
  return NDBT_OK;
 
427
}
 
428
 
 
429
int twoNodeFailure(NdbRestarter& _restarter, 
 
430
                   const NdbRestarts::NdbRestart* _restart){
 
431
 
 
432
  myRandom48Init(NdbTick_CurrentMillisecond());
 
433
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
434
  int nodeId = _restarter.getDbNodeId(randomId);  
 
435
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
436
 
 
437
  CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
 
438
        "Could not restart node "<< nodeId);
 
439
 
 
440
    // Create random value, max 10 secs
 
441
  int max = 10;
 
442
  int seconds = (myRandom48(max)) + 1;   
 
443
  g_info << "Waiting for " << seconds << "(" << max 
 
444
         << ") secs " << endl;
 
445
  NdbSleep_SecSleep(seconds);
 
446
 
 
447
  nodeId = _restarter.getRandomNodeOtherNodeGroup(nodeId, rand());
 
448
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
449
 
 
450
  CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
 
451
        "Could not restart node "<< nodeId);
 
452
 
 
453
  return NDBT_OK;
 
454
}
 
455
 
 
456
int twoMasterNodeFailure(NdbRestarter& _restarter, 
 
457
                         const NdbRestarts::NdbRestart* _restart){
 
458
 
 
459
  int nodeId = _restarter.getDbNodeId(0);  
 
460
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
461
 
 
462
  CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
 
463
        "Could not restart node "<< nodeId);
 
464
 
 
465
  // Create random value, max 10 secs
 
466
  int max = 10;
 
467
  int seconds = (myRandom48(max)) + 1;   
 
468
  g_info << "Waiting for " << seconds << "(" << max 
 
469
         << ") secs " << endl;
 
470
  NdbSleep_SecSleep(seconds);
 
471
 
 
472
  nodeId = _restarter.getDbNodeId(0);  
 
473
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
474
 
 
475
  CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
 
476
        "Could not restart node "<< nodeId);
 
477
 
 
478
  return NDBT_OK;
 
479
}
 
480
 
 
481
int get50PercentOfNodes(NdbRestarter& restarter, 
 
482
                        int * _nodes){
 
483
  // For now simply return all nodes with even node id
 
484
  // TODO Check nodegroup and return one node from each 
 
485
 
 
486
  int num50Percent = restarter.getNumDbNodes() / 2;
 
487
  assert(num50Percent <= MAX_NDB_NODES);
 
488
 
 
489
  // Calculate which nodes to stop, select all even nodes
 
490
  for (int i = 0; i < num50Percent; i++){
 
491
    _nodes[i] = restarter.getDbNodeId(i*2);
 
492
  }
 
493
  return num50Percent;
 
494
}
 
495
 
 
496
int fiftyPercentFail(NdbRestarter& _restarter, 
 
497
                            const NdbRestarts::NdbRestart* _restart){
 
498
 
 
499
 
 
500
  int nodes[MAX_NDB_NODES];
 
501
 
 
502
  int numNodes = get50PercentOfNodes(_restarter, nodes);
 
503
  
 
504
  // Stop the nodes, with nostart and abort
 
505
  for (int i = 0; i < numNodes; i++){
 
506
    g_info << "Stopping node "<< nodes[i] << endl;
 
507
    int res = _restarter.restartOneDbNode(nodes[i], false, true, true);
 
508
    CHECK(res == 0, "Could not stop node: "<< nodes[i]);
 
509
  }
 
510
 
 
511
  CHECK(_restarter.waitNodesNoStart(nodes, numNodes) == 0, 
 
512
        "waitNodesNoStart");
 
513
 
 
514
  // Order all nodes to start 
 
515
  ndbout << "Starting all nodes" << endl;
 
516
  CHECK(_restarter.startAll() == 0,
 
517
        "Could not start all nodes");
 
518
 
 
519
  return NDBT_OK;
 
520
}
 
521
 
 
522
 
 
523
int restartAllNodesGracfeul(NdbRestarter& _restarter, 
 
524
                            const NdbRestarts::NdbRestart* _restart){
 
525
 
 
526
  g_info << _restart->m_name  << endl;
 
527
 
 
528
  // Restart graceful
 
529
  CHECK(_restarter.restartAll() == 0,
 
530
        "Could not restart all nodes");
 
531
 
 
532
  return NDBT_OK;
 
533
 
 
534
}
 
535
 
 
536
int restartAllNodesAbort(NdbRestarter& _restarter, 
 
537
                         const NdbRestarts::NdbRestart* _restart){
 
538
  
 
539
  g_info << _restart->m_name  << endl;
 
540
 
 
541
  // Restart abort
 
542
  CHECK(_restarter.restartAll(false, false, true) == 0,
 
543
        "Could not restart all nodes");
 
544
 
 
545
  return NDBT_OK;
 
546
}
 
547
 
 
548
int restartAllNodesError9999(NdbRestarter& _restarter, 
 
549
                             const NdbRestarts::NdbRestart* _restart){
 
550
  
 
551
  g_info << _restart->m_name <<  endl;
 
552
 
 
553
  // Restart with error insert
 
554
  CHECK(_restarter.insertErrorInAllNodes(9999) == 0,
 
555
        "Could not restart all nodes ");
 
556
 
 
557
  return NDBT_OK;
 
558
}
 
559
 
 
560
int fiftyPercentStopAndWait(NdbRestarter& _restarter, 
 
561
                            const NdbRestarts::NdbRestart* _restart){
 
562
 
 
563
  int nodes[MAX_NDB_NODES];
 
564
  int numNodes = get50PercentOfNodes(_restarter, nodes);
 
565
 
 
566
  // Stop the nodes, with nostart and abort
 
567
  for (int i = 0; i < numNodes; i++){
 
568
    g_info << "Stopping node "<<nodes[i] << endl;
 
569
    int res = _restarter.restartOneDbNode(nodes[i], false, true, true);
 
570
    CHECK(res == 0, "Could not stop node: "<< nodes[i]);
 
571
  }
 
572
 
 
573
  CHECK(_restarter.waitNodesNoStart(nodes, numNodes) == 0, 
 
574
        "waitNodesNoStart");
 
575
 
 
576
  // Create random value, max 120 secs
 
577
  int max = 120;
 
578
  int seconds = (myRandom48(max)) + 1;   
 
579
  g_info << "Waiting for " << seconds << "(" << max 
 
580
         << ") secs " << endl;
 
581
  NdbSleep_SecSleep(seconds);  
 
582
 
 
583
 
 
584
  // Restart graceful
 
585
  CHECK(_restarter.restartAll() == 0,
 
586
        "Could not restart all nodes");
 
587
 
 
588
  g_info << _restart->m_name <<  endl;
 
589
 
 
590
  return NDBT_OK;
 
591
}
 
592
 
 
593
int
 
594
NFDuringNR_codes[] = {
 
595
  7121,
 
596
  5027,
 
597
  7172,
 
598
  6000,
 
599
  6001,
 
600
  6002,
 
601
  7171,
 
602
  7130,
 
603
  7133,
 
604
  7138,
 
605
  7154,
 
606
  7144,
 
607
  5026,
 
608
  7139,
 
609
  7132,
 
610
  5045,
 
611
 
 
612
  //LCP
 
613
  8000,
 
614
  8001,
 
615
  5010,
 
616
  7022,
 
617
  7024,
 
618
  7016,
 
619
  7017,
 
620
  5002
 
621
};
 
622
 
 
623
int restartNFDuringNR(NdbRestarter& _restarter, 
 
624
                           const NdbRestarts::NdbRestart* _restart){
 
625
 
 
626
  myRandom48Init(NdbTick_CurrentMillisecond());
 
627
  int i;
 
628
  const int sz = sizeof(NFDuringNR_codes)/sizeof(NFDuringNR_codes[0]);
 
629
  for(i = 0; i<sz; i++){
 
630
    int randomId = myRandom48(_restarter.getNumDbNodes());
 
631
    int nodeId = _restarter.getDbNodeId(randomId);
 
632
    int error = NFDuringNR_codes[i];
 
633
    
 
634
    g_err << _restart->m_name << ": node = " << nodeId 
 
635
          << " error code = " << error << endl;
 
636
    
 
637
    CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
 
638
          "Could not restart node "<< nodeId);
 
639
    
 
640
    CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
 
641
          "waitNodesNoStart failed");
 
642
    
 
643
    int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 } ;
 
644
    CHECK(_restarter.dumpStateOneNode(nodeId, val, 2) == 0,
 
645
          "failed to set RestartOnErrorInsert");
 
646
    
 
647
    CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
 
648
          "failed to set error insert");
 
649
   
 
650
    CHECK(_restarter.startNodes(&nodeId, 1) == 0,
 
651
          "failed to start node");
 
652
 
 
653
    NdbSleep_SecSleep(3);
 
654
 
 
655
    //CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
 
656
    //  "waitNodesNoStart failed");
 
657
    _restarter.waitNodesNoStart(&nodeId, 1);
 
658
 
 
659
    CHECK(_restarter.startNodes(&nodeId, 1) == 0,
 
660
          "failed to start node");
 
661
    
 
662
    CHECK(_restarter.waitNodesStarted(&nodeId, 1) == 0,
 
663
          "waitNodesStarted failed");
 
664
  }
 
665
 
 
666
  return NDBT_OK;
 
667
  
 
668
  if(_restarter.getNumDbNodes() < 4)
 
669
    return NDBT_OK;
 
670
 
 
671
  char buf[256];
 
672
  if(NdbEnv_GetEnv("USER", buf, 256) == 0 || strcmp(buf, "ejonore") != 0)
 
673
    return NDBT_OK;
 
674
  
 
675
  for(i = 0; i<sz; i++){
 
676
    const int randomId = myRandom48(_restarter.getNumDbNodes());
 
677
    int nodeId = _restarter.getDbNodeId(randomId);
 
678
    const int error = NFDuringNR_codes[i];
 
679
    
 
680
    const int masterNodeId = _restarter.getMasterNodeId();
 
681
    CHECK(masterNodeId > 0, "getMasterNodeId failed");
 
682
    int crashNodeId = 0;
 
683
    do {
 
684
      int rand = myRandom48(1000);
 
685
      crashNodeId = _restarter.getRandomNodeOtherNodeGroup(nodeId, rand);
 
686
    } while(crashNodeId == masterNodeId);
 
687
 
 
688
    CHECK(crashNodeId > 0, "getMasterNodeId failed");
 
689
 
 
690
    g_info << _restart->m_name << " restarting node = " << nodeId 
 
691
           << " error code = " << error 
 
692
           << " crash node = " << crashNodeId << endl;
 
693
    
 
694
    CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
 
695
          "Could not restart node "<< nodeId);
 
696
    
 
697
    CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
 
698
          "waitNodesNoStart failed");
 
699
        
 
700
    int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
 
701
    CHECK(_restarter.dumpStateOneNode(crashNodeId, val, 2) == 0,
 
702
          "failed to set RestartOnErrorInsert");
 
703
    
 
704
    CHECK(_restarter.insertErrorInNode(crashNodeId, error) == 0,
 
705
          "failed to set error insert");
 
706
   
 
707
    CHECK(_restarter.startNodes(&nodeId, 1) == 0,
 
708
          "failed to start node");
 
709
 
 
710
    CHECK(_restarter.waitClusterStarted() == 0,
 
711
          "waitClusterStarted failed");
 
712
  }
 
713
 
 
714
  return NDBT_OK;
 
715
}
 
716
 
 
717
int
 
718
NRDuringLCP_Master_codes[] = {
 
719
  7009, // Insert system error in master when local checkpoint is idle.
 
720
  7010, // Insert system error in master when local checkpoint is in the
 
721
        // state clcpStatus = CALCULATE_KEEP_GCI.
 
722
  7013, // Insert system error in master when local checkpoint is in the
 
723
        // state clcpStatus = COPY_GCI before sending COPY_GCIREQ.
 
724
  7014, // Insert system error in master when local checkpoint is in the
 
725
        // state clcpStatus = TC_CLOPSIZE before sending TC_CLOPSIZEREQ.
 
726
  7015, // Insert system error in master when local checkpoint is in the
 
727
        // state clcpStatus = START_LCP_ROUND before sending START_LCP_ROUND.
 
728
  7019, // Insert system error in master when local checkpoint is in the
 
729
        // state clcpStatus = IDLE before sending CONTINUEB(ZCHECK_TC_COUNTER).
 
730
  7075, // Master. Don't send any LCP_FRAG_ORD(last=true)
 
731
        // And crash when all have "not" been sent
 
732
  7021, // Crash in  master when receiving START_LCP_REQ
 
733
  7023, // Crash in  master when sending START_LCP_CONF
 
734
  7025, // Crash in  master when receiving LCP_FRAG_REP
 
735
  7026, // Crash in  master when changing state to LCP_TAB_COMPLETED 
 
736
  7027  // Crash in  master when changing state to LCP_TAB_SAVED
 
737
};
 
738
 
 
739
int
 
740
NRDuringLCP_NonMaster_codes[] = {
 
741
  7020, // Insert system error in local checkpoint participant at reception 
 
742
        // of COPY_GCIREQ.
 
743
  8000, // Crash particpant when receiving TCGETOPSIZEREQ
 
744
  8001, // Crash particpant when receiving TC_CLOPSIZEREQ
 
745
  5010, // Crash any when receiving LCP_FRAGORD
 
746
  7022, // Crash in !master when receiving START_LCP_REQ
 
747
  7024, // Crash in !master when sending START_LCP_CONF
 
748
  7016, // Crash in !master when receiving LCP_FRAG_REP
 
749
  7017, // Crash in !master when changing state to LCP_TAB_COMPLETED 
 
750
  7018  // Crash in !master when changing state to LCP_TAB_SAVED
 
751
};
 
752
 
 
753
int restartNodeDuringLCP(NdbRestarter& _restarter, 
 
754
                         const NdbRestarts::NdbRestart* _restart) {
 
755
  int i;
 
756
  // Master
 
757
  int val = DumpStateOrd::DihMinTimeBetweenLCP;
 
758
  CHECK(_restarter.dumpStateAllNodes(&val, 1) == 0,
 
759
        "Failed to set LCP to min value"); // Set LCP to min val
 
760
  int sz = sizeof(NRDuringLCP_Master_codes)/
 
761
           sizeof(NRDuringLCP_Master_codes[0]);
 
762
  for(i = 0; i<sz; i++) {
 
763
 
 
764
    int error = NRDuringLCP_Master_codes[i];
 
765
    int masterNodeId = _restarter.getMasterNodeId();
 
766
 
 
767
    CHECK(masterNodeId > 0, "getMasterNodeId failed");
 
768
 
 
769
    ndbout << _restart->m_name << " restarting master node = " << masterNodeId 
 
770
           << " error code = " << error << endl;
 
771
 
 
772
    {
 
773
      int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
 
774
      CHECK(_restarter.dumpStateAllNodes(val, 2) == 0,
 
775
            "failed to set RestartOnErrorInsert");
 
776
    }
 
777
 
 
778
    CHECK(_restarter.insertErrorInNode(masterNodeId, error) == 0,
 
779
          "failed to set error insert");
 
780
 
 
781
    CHECK(_restarter.waitNodesNoStart(&masterNodeId, 1, 300) == 0,
 
782
                                      "failed to wait no start");
 
783
 
 
784
    CHECK(_restarter.startNodes(&masterNodeId, 1) == 0,
 
785
          "failed to start node");
 
786
 
 
787
    CHECK(_restarter.waitClusterStarted(300) == 0,
 
788
          "waitClusterStarted failed");
 
789
 
 
790
    {
 
791
      int val = DumpStateOrd::DihMinTimeBetweenLCP;
 
792
      CHECK(_restarter.dumpStateOneNode(masterNodeId, &val, 1) == 0,
 
793
            "failed to set error insert");
 
794
    }
 
795
  }
 
796
 
 
797
  // NON-Master
 
798
  sz = sizeof(NRDuringLCP_NonMaster_codes)/
 
799
       sizeof(NRDuringLCP_NonMaster_codes[0]);
 
800
  for(i = 0; i<sz; i++) {
 
801
 
 
802
    int error = NRDuringLCP_NonMaster_codes[i];
 
803
    int nodeId = getRandomNodeId(_restarter);
 
804
    int masterNodeId = _restarter.getMasterNodeId();
 
805
    CHECK(masterNodeId > 0, "getMasterNodeId failed");
 
806
 
 
807
    while (nodeId == masterNodeId) {
 
808
      nodeId = getRandomNodeId(_restarter);
 
809
    }
 
810
 
 
811
    ndbout << _restart->m_name << " restarting non-master node = " << nodeId
 
812
           << " error code = " << error << endl;
 
813
 
 
814
    int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
 
815
    CHECK(_restarter.dumpStateAllNodes(val, 2) == 0,
 
816
          "failed to set RestartOnErrorInsert");
 
817
    
 
818
    CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
 
819
          "failed to set error insert");
 
820
 
 
821
    CHECK(_restarter.waitNodesNoStart(&nodeId, 1, 300) == 0,
 
822
                                      "failed to wait no start");
 
823
 
 
824
    CHECK(_restarter.startNodes(&nodeId, 1) == 0,
 
825
          "failed to start node");
 
826
 
 
827
    CHECK(_restarter.waitClusterStarted(300) == 0,
 
828
          "waitClusterStarted failed");
 
829
 
 
830
    {
 
831
      int val = DumpStateOrd::DihMinTimeBetweenLCP;
 
832
      CHECK(_restarter.dumpStateOneNode(nodeId, &val, 1) == 0,
 
833
            "failed to set error insert");
 
834
    }
 
835
  }
 
836
 
 
837
  return NDBT_OK;
 
838
}
 
839
 
 
840
int stopOnError(NdbRestarter& _restarter, 
 
841
                const NdbRestarts::NdbRestart* _restart){
 
842
 
 
843
  myRandom48Init(NdbTick_CurrentMillisecond());
 
844
 
 
845
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
846
  int nodeId = _restarter.getDbNodeId(randomId);
 
847
  
 
848
  do {
 
849
    g_info << _restart->m_name << ": node = " << nodeId 
 
850
           << endl;
 
851
    
 
852
    CHECK(_restarter.waitClusterStarted(300) == 0,
 
853
          "waitClusterStarted failed");
 
854
    
 
855
    int val = DumpStateOrd::NdbcntrTestStopOnError;
 
856
    CHECK(_restarter.dumpStateOneNode(nodeId, &val, 1) == 0,
 
857
          "failed to set NdbcntrTestStopOnError");
 
858
    
 
859
    NdbSleep_SecSleep(3);
 
860
    
 
861
    CHECK(_restarter.waitClusterStarted(300) == 0,
 
862
          "waitClusterStarted failed");
 
863
  } while (false);
 
864
  
 
865
  return NDBT_OK;
 
866
}
 
867
 
 
868
int getRandomNodeId(NdbRestarter& _restarter) {
 
869
  myRandom48Init(NdbTick_CurrentMillisecond());
 
870
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
871
  int nodeId = _restarter.getDbNodeId(randomId);
 
872
 
 
873
  return nodeId;
 
874
}