summaryrefslogtreecommitdiff
path: root/storage/ndb/test/ndbnet/testError.run
blob: 3cce489a3da84e6fc2f7ff4ef3ccfef3cd89d66f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#
# file : test/ndbnet/testError.run
# usage: perl testError.run
#
# you need to have $NDB_TOP/lib/perl5 on search path $PERL5LIB
# or else write perl -I$NDB_TOP/lib/perl5 test1.run
#
# The database is specified by the $NDB_DATABASE environment variable
#
# method names and argument style will change slightly.
#
#

use strict;
use NDB::Run;

my $env = NDB::Run->getenv;
my $log = $env->getlog;
$log->setpart(time => 1, line => 0);
$log->setprio("info");

my $database = $ENV{NDB_DATABASE};
my $api_cmd = $ENV{API_CMD};
$log->put("start test database=$database");
$env->init or $log->push("init failed")->fatal;

my $db = $env->getdb($database) or $log->push->fatal;
my $mgm = $db->getnode(1) or $log->push->fatal;
my $api = $db->getnode(4) or $log->push->fatal;

my @dbnode = ();	# array of db nodes indexed 2..3
for my $i (2..3) {
    $dbnode[$i] = $db->getnode($i) or $log->push->fatal;
}

# list of db nodes and errors to insert
my @errors = (		# array of array refs
    [ 2, 9998 ],
    [ 2, 37017 ],
    [ 2, 37018 ],
    [ 2, 37017 ],
    [ 2, 37018 ],
    [ 2, 37017 ],
    [ 2, 37018 ],
    [ 2, 37017 ],
    [ 2, 37018 ],
    [ 2, 37017 ],
    [ 2, 37018 ],
    [ 2, 37017 ],
    [ 2, 9998 ],
    [ 3, 9998 ],
    [ 3, 9998 ],
    [ 2, 9998 ],
    [ 3, 9998 ],
    [ 3, 9998 ],
    [ 2, 38002 ],
    [ 2, 38002 ],
    [ 2, 8002 ],
    [ 3, 8029 ],
    [ 2, 8030 ],
    [ 2, 8031 ],
    [ 3, 8020 ],
    [ 2, 8021 ],
    [ 3, 8022 ],
    [ 2, 8023 ],
    [ 3, 8025 ],
    [ 2, 8027 ],
    [ 2, 38002 ],
    [ 3, 38029 ],
    [ 2, 38030 ],
    [ 2, 38031 ],
    [ 3, 38020 ],
    [ 2, 38021 ],
    [ 3, 38022 ],
    [ 2, 38023 ],
    [ 3, 38025 ],
    [ 2, 38027 ],
    [ 2, 48002 ],
    [ 3, 48029 ],
    [ 2, 48030 ],
    [ 2, 48031 ],
    [ 3, 48020 ],
    [ 2, 48021 ],
    [ 3, 48022 ],
    [ 2, 48023 ],
    [ 3, 48025 ],
    [ 2, 48027 ],
    [ 2, 9999 ],
    [ 3, 9999 ],
    [ 3, 9999 ],
    [ 2, 9998 ],
    [ 3, 9998 ],
    [ 3, 9998 ],
    [ 2, 9998 ],
    [ 3, 9998 ],
    [ 3, 9998 ],
    [ 3, 37000 ],
    [ 2, 37001 ],
    [ 2, 37002 ],
    [ 2, 37003 ],
    [ 2, 47005 ],
    [ 2, 47006 ],
    [ 2, 47007 ],
    [ 2, 47008 ],
    [ 2, 45000 ],
    [ 2, 37005 ],
    [ 2, 37006 ],
    [ 2, 37007 ],
    [ 2, 37008 ],
    [ 2, 35000 ],
    [ 2, 37009 ],
    [ 2, 37010 ],
    [ 2, 37013 ],
    [ 2, 37014 ],
    [ 2, 37015 ],
    [ 2, 37016 ],
    [ 2, 37017 ],
    [ 2, 37018 ],
    [ 2, 37019 ],
    [ 2, 47020 ],
    [ 2, 37020 ],
    [ 2, 48000 ],
    [ 2, 38000 ],
    [ 2, 48001 ],
    [ 2, 38001 ],
    [ 2, 45001 ],
    [ 2, 35001 ],
);

$db->kill;
$db->start({init_rm=>1}) or $log->push->fatal;
sleep 10;

# should be option (or default) in $db->start
sub wait_until_started {
    my $local_cnt = 60;
    while (--$local_cnt > 0) {
	sleep 2;
	my $ret = $mgm->write("all status", { wait => 3 });
	$ret or $log->fatal;
	my $output = $ret->{output};
	if ($output =~ /\bstarted\b(.|\n)*started\b/i) {
	    $log->put("*** db is started ***")->info;
	    return;
	}
	if ($output =~ /\bno.contact\b(.|\n)*no.contact\b/i) {
	    print "NDBT_ProgramExit: 1 - test error\n";
	    $log->put("*** db is dead ***")->fatal;
	}
    }
    print "NDBT_ProgramExit: 1 - test error\n";
    $log->put("*** node recovery failed ***")->fatal;
}

sub getdbstatus {
    my $ret = $mgm->write("all status", { wait => 3 });
    $ret or return undef;
    my $output = $ret->{output};
    my @status = ();	# indexed 2..3
    for my $i (2..3) {
	my $s = "Unknown";
	if ($output =~ /Node\s*$i\s*:\s*(\w+)/i) {
	    $s = $1;
	}#if
	$status[$i] = lc $s;
    }#for
    return \@status;
}

# count elapsed time
my $lasttime;
sub settime { $lasttime = time };
sub gettime { return time - $lasttime };

wait_until_started();
$api->start({run=>$api_cmd});
sleep 10;

# loop over error inserts
for my $e (@errors) {
for my $loop (1..7) {
  my $i = $e->[0];                      # db node number 2..3
  my $c = $e->[1];                      # error code
  my $dead_node_id = $i;
  my $dbnode = $dbnode[$i];
  my $two = 2;
  my $three = 3;
  my $kill_no = 9998;

  $log->put("insert error $c")->push($dbnode)->notice;

  # insert error
  if ($c eq $kill_no) {
    $dbnode->kill
       or $log->put("Kill 1 failed")->fatal;
  } else {
    $mgm->write("$i error $c")
       or $log->put("insert error fault")->fatal;
  }#if

  # after a few seconds check that node is dead
  settime();
  loop: {
    gettime() <= 300
      or $log->put("db node $i refuses to die")->fatal;
    my $status = getdbstatus()
       or $log->put("getdbstatus error")->fatal;

    if (($status->[$two] eq 'no') && ($status->[$three] eq 'no')) {
      print "NDBT_ProgramExit: 1 - test error\n";
      $log->put("*** db is dead ***")->fatal;
    }#if
    if ($c < 10000) {
      if ($status->[$i] ne 'no') {         # ...contact
        sleep 2;
        redo loop;
      }#if
      $dead_node_id = $i;
    } else {
      if (($status->[$two] eq 'no') &&
          ($status->[$three] eq 'started')) {
        $dead_node_id = 2;
      } else {
        if (($status->[$three] eq 'no') &&
            ($status->[$two] eq 'started')) {
          $dead_node_id = 3;
        } else {
          sleep 2;
          redo loop;
        }#if
      }#if
    }#if
  }#loop

  my $dead_node = $dbnode[$dead_node_id];
  # have to even check the process is gone
  sleep 5;
  if ($dead_node->stat ne "down") {
    $log->put("ndb did not die, kill it")->push($dead_node)->warn;
    $dead_node->kill
       or $log->put("Kill 2 failed")->fatal;
  }#if

  $log->put("node $dead_node_id is dead")->notice;

  # start the failed node
  $dead_node->start
     or $log->put("Start ndb node failed")->fatal;

  wait_until_started();
  $log->put("node $dead_node_id is up again")->notice;

  # check test pgm is running
  my $stat = $api->stat
    or $log->put("api->stat failed")->fatal;
  if ($stat ne "up") {
    print "NDBT_ProgramExit: 1 - test error\n";
    $db->kill;
    $log->put("flexBench has crashed")->fatal;
  }#if
}#for
}#for
print "NDBT_ProgramExit: 0 - test ready\n";
$db->kill;

# vim: set sw=4: