~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

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

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

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; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
 
 
17
#include <NdbRestarts.hpp>
 
18
#include <NDBT.hpp>
 
19
#include <string.h>
 
20
#include <NdbSleep.h>
 
21
#include <kernel/ndb_limits.h>
 
22
#include <signaldata/DumpStateOrd.hpp>
 
23
#include <NdbEnv.h>
 
24
 
 
25
 
 
26
int restartRandomNodeGraceful(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
27
int restartRandomNodeAbort(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
28
int restartRandomNodeError(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
29
int restartRandomNodeInitial(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
30
int restartNFDuringNR(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
31
int restartMasterNodeError(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
32
int twoNodeFailure(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
33
int fiftyPercentFail(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
34
int twoMasterNodeFailure(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
35
int restartAllNodesGracfeul(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
36
int restartAllNodesAbort(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
37
int restartAllNodesError9999(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
38
int fiftyPercentStopAndWait(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
39
int restartNodeDuringLCP(NdbRestarter& _restarter,
 
40
                         const NdbRestarts::NdbRestart* _restart);
 
41
int stopOnError(NdbRestarter&, const NdbRestarts::NdbRestart*);
 
42
int getRandomNodeId(NdbRestarter& _restarter);
 
43
 
 
44
/**
 
45
 * Define list of restarts
 
46
 *  - name of restart
 
47
 *  - function perfoming the restart
 
48
 *  - required number of nodes
 
49
 *  - ...
 
50
 *  - arg1, used depending of restart
 
51
 *  - arg2, used depending of restart
 
52
 */
 
53
 
 
54
const NdbRestarts::NdbRestart NdbRestarts::m_restarts[] = {
 
55
  /*********************************************************
 
56
   *
 
57
   *  NODE RESTARTS with 1 node restarted
 
58
   *
 
59
   *********************************************************/
 
60
  /** 
 
61
   * Restart a randomly selected node
 
62
   * with graceful shutdown
 
63
   */ 
 
64
  NdbRestart("RestartRandomNode", 
 
65
             NODE_RESTART,
 
66
             restartRandomNodeGraceful,
 
67
             2),
 
68
  /** 
 
69
   * Restart a randomly selected node
 
70
   * with immediate(abort) shutdown
 
71
   */ 
 
72
  NdbRestart("RestartRandomNodeAbort", 
 
73
             NODE_RESTART,
 
74
             restartRandomNodeAbort,
 
75
             2),
 
76
  /** 
 
77
   * Restart a randomly selected node
 
78
   * with  error insert
 
79
   *
 
80
   */ 
 
81
  NdbRestart("RestartRandomNodeError",
 
82
             NODE_RESTART,
 
83
             restartRandomNodeError,
 
84
             2),
 
85
  /**
 
86
   * Restart the master node
 
87
   * with  error insert
 
88
   */ 
 
89
  NdbRestart("RestartMasterNodeError",
 
90
             NODE_RESTART,
 
91
             restartMasterNodeError,
 
92
             2),
 
93
  /**
 
94
   * Restart a randomly selected node without fileystem
 
95
   *
 
96
   */ 
 
97
  NdbRestart("RestartRandomNodeInitial",
 
98
             NODE_RESTART,
 
99
             restartRandomNodeInitial,
 
100
             2),
 
101
  /**
 
102
   * Restart a randomly selected node and then 
 
103
   * crash it while restarting
 
104
   *
 
105
   */    
 
106
  NdbRestart("RestartNFDuringNR",
 
107
             NODE_RESTART,
 
108
             restartNFDuringNR,
 
109
             2),   
 
110
 
 
111
  /**
 
112
   * Set StopOnError and crash the node by sending
 
113
   * SYSTEM_ERROR to it
 
114
   *
 
115
   */    
 
116
  NdbRestart("StopOnError",
 
117
             NODE_RESTART,
 
118
             stopOnError,
 
119
             1),  
 
120
 
 
121
  /*********************************************************
 
122
   *
 
123
   *  MULTIPLE NODE RESTARTS with more than 1 node
 
124
   *
 
125
   *********************************************************/
 
126
  /**
 
127
   * 2 nodes restart, select nodes to restart randomly and restart 
 
128
   * with a small random delay between restarts
 
129
   */ 
 
130
  NdbRestart("TwoNodeFailure",
 
131
             MULTIPLE_NODE_RESTART,
 
132
             twoNodeFailure,
 
133
             4),
 
134
  /**
 
135
   * 2 nodes restart, select master nodes and restart with 
 
136
   * a small random delay between restarts 
 
137
   */ 
 
138
  
 
139
  NdbRestart("TwoMasterNodeFailure",
 
140
             MULTIPLE_NODE_RESTART,
 
141
             twoMasterNodeFailure,
 
142
             4),
 
143
 
 
144
  NdbRestart("FiftyPercentFail",
 
145
             MULTIPLE_NODE_RESTART,
 
146
             fiftyPercentFail,
 
147
             2),
 
148
 
 
149
  /*********************************************************
 
150
   *
 
151
   *  SYSTEM RESTARTS
 
152
   *
 
153
   *********************************************************/
 
154
  /**
 
155
   * Restart all nodes with graceful shutdown
 
156
   *
 
157
   */ 
 
158
  
 
159
  NdbRestart("RestartAllNodes",
 
160
             SYSTEM_RESTART,
 
161
             restartAllNodesGracfeul,
 
162
             1),
 
163
  /**
 
164
   * Restart all nodes immediately without
 
165
   * graful shutdown
 
166
   */ 
 
167
  NdbRestart("RestartAllNodesAbort",
 
168
             SYSTEM_RESTART,
 
169
             restartAllNodesAbort,
 
170
             1),
 
171
  /**
 
172
   * Restart all nodes with error insert 9999
 
173
   * TODO! We can later add more errors like 9998, 9997 etc.
 
174
   */ 
 
175
  NdbRestart("RestartAllNodesError9999",
 
176
             SYSTEM_RESTART,
 
177
             restartAllNodesError9999,
 
178
             1),
 
179
  /**
 
180
   * Stop 50% of all nodes with error insert 9999
 
181
   * Wait for a random number of minutes
 
182
   * Stop the rest of the nodes and then start all again
 
183
   */ 
 
184
  NdbRestart("FiftyPercentStopAndWait",
 
185
             SYSTEM_RESTART,
 
186
             fiftyPercentStopAndWait,
 
187
             2),
 
188
  /** 
 
189
   * Restart a master node during LCP with error inserts.
 
190
   */ 
 
191
  NdbRestart("RestartNodeDuringLCP", 
 
192
             NODE_RESTART,
 
193
             restartNodeDuringLCP,
 
194
             2),
 
195
};
 
196
 
 
197
const int NdbRestarts::m_NoOfRestarts = sizeof(m_restarts) / sizeof(NdbRestart);
 
198
 
 
199
 
 
200
const NdbRestarts::NdbErrorInsert NdbRestarts::m_errors[] = {
 
201
  NdbErrorInsert("Error9999", 9999)
 
202
};
 
203
 
 
204
const int NdbRestarts::m_NoOfErrors = sizeof(m_errors) / sizeof(NdbErrorInsert);
 
205
 
 
206
NdbRestarts::NdbRestart::NdbRestart(const char* _name,
 
207
                                    NdbRestartType _type,
 
208
                                    restartFunc* _func,
 
209
                                    int _requiredNodes,
 
210
                                    int _arg1){
 
211
  m_name = _name;
 
212
  m_type = _type;
 
213
  m_restartFunc = _func;
 
214
  m_numRequiredNodes = _requiredNodes;
 
215
  //  m_arg1 = arg1;
 
216
}
 
217
 
 
218
 
 
219
int NdbRestarts::getNumRestarts(){
 
220
  return m_NoOfRestarts;
 
221
}
 
222
 
 
223
const NdbRestarts::NdbRestart* NdbRestarts::getRestart(int _num){
 
224
  if (_num >= m_NoOfRestarts)
 
225
    return NULL;
 
226
 
 
227
  return &m_restarts[_num];
 
228
}
 
229
 
 
230
const NdbRestarts::NdbRestart* NdbRestarts::getRestart(const char* _name){
 
231
  for(int i = 0; i < m_NoOfRestarts; i++){
 
232
    if (strcmp(m_restarts[i].m_name, _name) == 0){
 
233
      return &m_restarts[i];
 
234
    }
 
235
  }
 
236
  g_err << "The restart \""<< _name << "\" not found in NdbRestarts" << endl;
 
237
  return NULL;
 
238
}
 
239
 
 
240
 
 
241
int NdbRestarts::executeRestart(const NdbRestarts::NdbRestart* _restart, 
 
242
                                unsigned int _timeout){
 
243
  // Check that there are enough nodes in the cluster
 
244
  // for this test
 
245
  NdbRestarter restarter;
 
246
  if (_restart->m_numRequiredNodes > restarter.getNumDbNodes()){
 
247
    g_err << "This test requires " << _restart->m_numRequiredNodes << " nodes "
 
248
          << "there are only "<< restarter.getNumDbNodes() <<" nodes in cluster" 
 
249
          << endl;
 
250
    return NDBT_OK;
 
251
  }
 
252
  if (restarter.waitClusterStarted(120) != 0){
 
253
    // If cluster is not started when we shall peform restart
 
254
    // the restart can not be executed and the test fails
 
255
    return NDBT_FAILED;
 
256
  }
 
257
  
 
258
  int res = _restart->m_restartFunc(restarter, _restart);
 
259
 
 
260
  // Sleep a little waiting for nodes to react to command
 
261
  NdbSleep_SecSleep(2);
 
262
 
 
263
  if  (_timeout == 0){
 
264
    // If timeout == 0 wait for ever
 
265
    while(restarter.waitClusterStarted(60) != 0)
 
266
      g_err << "Cluster is not started after restart. Waiting 60s more..." 
 
267
            << endl;
 
268
  } else {
 
269
    if (restarter.waitClusterStarted(_timeout) != 0){
 
270
      g_err<<"Cluster failed to start" << endl;
 
271
      res = NDBT_FAILED; 
 
272
    }
 
273
  }
 
274
 
 
275
  return res;
 
276
 
277
 
 
278
int NdbRestarts::executeRestart(int _num,
 
279
                                unsigned int _timeout){
 
280
  const NdbRestarts::NdbRestart* r = getRestart(_num);
 
281
  if (r == NULL)
 
282
    return NDBT_FAILED;
 
283
 
 
284
  int res = executeRestart(r, _timeout);
 
285
  return res;
 
286
}
 
287
 
 
288
int NdbRestarts::executeRestart(const char* _name,
 
289
                                unsigned int _timeout){
 
290
  const NdbRestarts::NdbRestart* r = getRestart(_name);
 
291
  if (r == NULL)
 
292
    return NDBT_FAILED;
 
293
 
 
294
  int res = executeRestart(r, _timeout);
 
295
  return res;
 
296
}
 
297
 
 
298
void NdbRestarts::listRestarts(NdbRestartType _type){
 
299
  for(int i = 0; i < m_NoOfRestarts; i++){
 
300
    if (m_restarts[i].m_type == _type)
 
301
      ndbout << " " << m_restarts[i].m_name << ", min " 
 
302
             << m_restarts[i].m_numRequiredNodes 
 
303
             << " nodes"<< endl;
 
304
  }  
 
305
}
 
306
 
 
307
void NdbRestarts::listRestarts(){
 
308
  ndbout << "NODE RESTARTS" << endl;
 
309
  listRestarts(NODE_RESTART);
 
310
  ndbout << "MULTIPLE NODE RESTARTS" << endl;
 
311
  listRestarts(MULTIPLE_NODE_RESTART);
 
312
  ndbout << "SYSTEM RESTARTS" << endl;
 
313
  listRestarts(SYSTEM_RESTART);  
 
314
}
 
315
 
 
316
NdbRestarts::NdbErrorInsert::NdbErrorInsert(const char* _name,
 
317
                                            int _errorNo){
 
318
  
 
319
  m_name = _name;
 
320
  m_errorNo = _errorNo;
 
321
}
 
322
 
 
323
int NdbRestarts::getNumErrorInserts(){
 
324
  return m_NoOfErrors;
 
325
}
 
326
 
 
327
const NdbRestarts::NdbErrorInsert* NdbRestarts::getError(int _num){
 
328
  if (_num >= m_NoOfErrors)
 
329
    return NULL;
 
330
  return &m_errors[_num];
 
331
}
 
332
 
 
333
const NdbRestarts::NdbErrorInsert* NdbRestarts::getRandomError(){
 
334
  int randomId = myRandom48(m_NoOfErrors);
 
335
  return &m_errors[randomId];
 
336
}
 
337
 
 
338
 
 
339
 
 
340
/**
 
341
 *
 
342
 * IMPLEMENTATION OF THE DIFFERENT RESTARTS
 
343
 * Each function should perform it's action
 
344
 * and the returned NDBT_OK or NDBT_FAILED
 
345
 *
 
346
 */
 
347
 
 
348
 
 
349
#define CHECK(b, m) { int _xx = b; if (!(_xx)) { \
 
350
  ndbout << "ERR: "<< m \
 
351
           << "   " << "File: " << __FILE__ \
 
352
           << " (Line: " << __LINE__ << ")" << "- " << _xx << endl; \
 
353
  return NDBT_FAILED; } }
 
354
 
 
355
 
 
356
 
 
357
int restartRandomNodeGraceful(NdbRestarter& _restarter, 
 
358
                              const NdbRestarts::NdbRestart* _restart){
 
359
 
 
360
  myRandom48Init(NdbTick_CurrentMillisecond());
 
361
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
362
  int nodeId = _restarter.getDbNodeId(randomId);
 
363
  
 
364
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
365
 
 
366
  CHECK(_restarter.restartOneDbNode(nodeId) == 0, 
 
367
        "Could not restart node "<<nodeId);
 
368
 
 
369
  return NDBT_OK;
 
370
}
 
371
 
 
372
int restartRandomNodeAbort(NdbRestarter& _restarter, 
 
373
                              const NdbRestarts::NdbRestart* _restart){
 
374
 
 
375
  myRandom48Init(NdbTick_CurrentMillisecond());
 
376
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
377
  int nodeId = _restarter.getDbNodeId(randomId);
 
378
  
 
379
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
380
 
 
381
  CHECK(_restarter.restartOneDbNode(nodeId, false, false, true) == 0, 
 
382
        "Could not restart node "<<nodeId);
 
383
 
 
384
  return NDBT_OK;
 
385
}
 
386
 
 
387
int restartRandomNodeError(NdbRestarter& _restarter, 
 
388
                           const NdbRestarts::NdbRestart* _restart){
 
389
 
 
390
  myRandom48Init(NdbTick_CurrentMillisecond());
 
391
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
392
  int nodeId = _restarter.getDbNodeId(randomId);
 
393
  
 
394
  ndbout << _restart->m_name << ": node = "<<nodeId << endl;
 
395
 
 
396
  CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0, 
 
397
        "Could not restart node "<<nodeId);
 
398
 
 
399
  return NDBT_OK;
 
400
}
 
401
 
 
402
int restartMasterNodeError(NdbRestarter& _restarter, 
 
403
                           const NdbRestarts::NdbRestart* _restart){
 
404
 
 
405
  int nodeId = _restarter.getDbNodeId(0);
 
406
  
 
407
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
408
 
 
409
  CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0, 
 
410
        "Could not restart node "<<nodeId);
 
411
 
 
412
  return NDBT_OK;
 
413
}
 
414
 
 
415
int restartRandomNodeInitial(NdbRestarter& _restarter, 
 
416
                             const NdbRestarts::NdbRestart* _restart){
 
417
 
 
418
  myRandom48Init(NdbTick_CurrentMillisecond());
 
419
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
420
  int nodeId = _restarter.getDbNodeId(randomId);
 
421
  
 
422
  g_info << _restart->m_name << ": node = "<<nodeId << endl;
 
423
 
 
424
  CHECK(_restarter.restartOneDbNode(nodeId, true) == 0,
 
425
        "Could not restart node "<<nodeId);
 
426
 
 
427
  return NDBT_OK;
 
428
}
 
429
 
 
430
int twoNodeFailure(NdbRestarter& _restarter, 
 
431
                   const NdbRestarts::NdbRestart* _restart){
 
432
 
 
433
  myRandom48Init(NdbTick_CurrentMillisecond());
 
434
  int randomId = myRandom48(_restarter.getNumDbNodes());
 
435
  int nodeId = _restarter.getDbNodeId(randomId);  
 
436
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
437
 
 
438
  CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
 
439
        "Could not restart node "<< nodeId);
 
440
 
 
441
    // Create random value, max 10 secs
 
442
  int max = 10;
 
443
  int seconds = (myRandom48(max)) + 1;   
 
444
  g_info << "Waiting for " << seconds << "(" << max 
 
445
         << ") secs " << endl;
 
446
  NdbSleep_SecSleep(seconds);
 
447
 
 
448
  nodeId = _restarter.getRandomNodeOtherNodeGroup(nodeId, rand());
 
449
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
450
 
 
451
  CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
 
452
        "Could not restart node "<< nodeId);
 
453
 
 
454
  return NDBT_OK;
 
455
}
 
456
 
 
457
int twoMasterNodeFailure(NdbRestarter& _restarter, 
 
458
                         const NdbRestarts::NdbRestart* _restart){
 
459
 
 
460
  int nodeId = _restarter.getDbNodeId(0);  
 
461
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
462
 
 
463
  CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
 
464
        "Could not restart node "<< nodeId);
 
465
 
 
466
  // Create random value, max 10 secs
 
467
  int max = 10;
 
468
  int seconds = (myRandom48(max)) + 1;   
 
469
  g_info << "Waiting for " << seconds << "(" << max 
 
470
         << ") secs " << endl;
 
471
  NdbSleep_SecSleep(seconds);
 
472
 
 
473
  nodeId = _restarter.getDbNodeId(0);  
 
474
  g_info << _restart->m_name << ": node = "<< nodeId << endl;
 
475
 
 
476
  CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
 
477
        "Could not restart node "<< nodeId);
 
478
 
 
479
  return NDBT_OK;
 
480
}
 
481
 
 
482
int get50PercentOfNodes(NdbRestarter& restarter, 
 
483
                        int * _nodes){
 
484
  // For now simply return all nodes with even node id
 
485
  // TODO Check nodegroup and return one node from each 
 
486
 
 
487
  int num50Percent = restarter.getNumDbNodes() / 2;
 
488
  assert(num50Percent <= MAX_NDB_NODES);
 
489
 
 
490
  // Calculate which nodes to stop, select all even nodes
 
491
  for (int i = 0; i < num50Percent; i++){
 
492
    _nodes[i] = restarter.getDbNodeId(i*2);
 
493
  }
 
494
  return num50Percent;
 
495
}
 
496
 
 
497
int fiftyPercentFail(NdbRestarter& _restarter, 
 
498
                            const NdbRestarts::NdbRestart* _restart){
 
499
 
 
500
 
 
501
  int nodes[MAX_NDB_NODES];
 
502
 
 
503
  int numNodes = get50PercentOfNodes(_restarter, nodes);
 
504
  
 
505
  // Stop the nodes, with nostart and abort
 
506
  for (int i = 0; i < numNodes; i++){
 
507
    g_info << "Stopping node "<< nodes[i] << endl;
 
508
    int res = _restarter.restartOneDbNode(nodes[i], false, true, true);
 
509
    CHECK(res == 0, "Could not stop node: "<< nodes[i]);
 
510
  }
 
511
 
 
512
  CHECK(_restarter.waitNodesNoStart(nodes, numNodes) == 0, 
 
513
        "waitNodesNoStart");
 
514
 
 
515
  // Order all nodes to start 
 
516
  ndbout << "Starting all nodes" << endl;
 
517
  CHECK(_restarter.startAll() == 0,
 
518
        "Could not start all nodes");
 
519
 
 
520
  return NDBT_OK;
 
521
}
 
522
 
 
523
 
 
524
int restartAllNodesGracfeul(NdbRestarter& _restarter, 
 
525
                            const NdbRestarts::NdbRestart* _restart){
 
526
 
 
527
  g_info << _restart->m_name  << endl;
 
528
 
 
529
  // Restart graceful
 
530
  CHECK(_restarter.restartAll() == 0,
 
531
        "Could not restart all nodes");
 
532
 
 
533
  return NDBT_OK;
 
534
 
 
535
}
 
536
 
 
537
int restartAllNodesAbort(NdbRestarter& _restarter, 
 
538
                         const NdbRestarts::NdbRestart* _restart){
 
539
  
 
540
  g_info << _restart->m_name  << endl;
 
541
 
 
542
  // Restart abort
 
543
  CHECK(_restarter.restartAll(false, false, true) == 0,
 
544
        "Could not restart all nodes");
 
545
 
 
546
  return NDBT_OK;
 
547
}
 
548
 
 
549
int restartAllNodesError9999(NdbRestarter& _restarter, 
 
550
                             const NdbRestarts::NdbRestart* _restart){
 
551
  
 
552
  g_info << _restart->m_name <<  endl;
 
553
 
 
554
  // Restart with error insert
 
555
  CHECK(_restarter.insertErrorInAllNodes(9999) == 0,
 
556
        "Could not restart all nodes ");
 
557
 
 
558
  return NDBT_OK;
 
559
}
 
560
 
 
561
int fiftyPercentStopAndWait(NdbRestarter& _restarter, 
 
562
                            const NdbRestarts::NdbRestart* _restart){
 
563
 
 
564
  int nodes[MAX_NDB_NODES];
 
565
  int numNodes = get50PercentOfNodes(_restarter, nodes);
 
566
 
 
567
  // Stop the nodes, with nostart and abort
 
568
  for (int i = 0; i < numNodes; i++){
 
569
    g_info << "Stopping node "<<nodes[i] << endl;
 
570
    int res = _restarter.restartOneDbNode(nodes[i], false, true, true);
 
571
    CHECK(res == 0, "Could not stop node: "<< nodes[i]);
 
572
  }
 
573
 
 
574
  CHECK(_restarter.waitNodesNoStart(nodes, numNodes) == 0, 
 
575
        "waitNodesNoStart");
 
576
 
 
577
  // Create random value, max 120 secs
 
578
  int max = 120;
 
579
  int seconds = (myRandom48(max)) + 1;   
 
580
  g_info << "Waiting for " << seconds << "(" << max 
 
581
         << ") secs " << endl;
 
582
  NdbSleep_SecSleep(seconds);  
 
583
 
 
584
 
 
585
  // Restart graceful
 
586
  CHECK(_restarter.restartAll() == 0,
 
587
        "Could not restart all nodes");
 
588
 
 
589
  g_info << _restart->m_name <<  endl;
 
590
 
 
591
  return NDBT_OK;
 
592
}
 
593
 
 
594
int
 
595
NFDuringNR_codes[] = {
 
596
  7121,
 
597
  5027,
 
598
  7172,
 
599
  6000,
 
600
  6001,
 
601
  6002,
 
602
  7171,
 
603
  7130,
 
604
  7133,
 
605
  7138,
 
606
  7154,
 
607
  7144,
 
608
  5026,
 
609
  7139,
 
610
  7132,
 
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_info << _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
}