~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

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 <signaldata/DumpStateOrd.hpp>
 
17
#include <NdbGrep.hpp>
 
18
#include <NdbOut.hpp>
 
19
#include <NDBT_Output.hpp>
 
20
#include <NdbConfig.h>
 
21
#include <ConfigRetriever.hpp>
 
22
#include <ndb_version.h>
 
23
#include <NDBT.hpp>
 
24
#include <NdbSleep.h>
 
25
#include <random.h>
 
26
#include <NdbTick.h>
 
27
 
 
28
#define CHECK(b, m) { int _xx = b; if (!(_xx)) { \
 
29
  ndbout << "ERR: "<< m \
 
30
           << "   " << "File: " << __FILE__ \
 
31
           << " (Line: " << __LINE__ << ")" << "- " << _xx << endl; \
 
32
  return NDBT_FAILED; } }
 
33
 
 
34
 
 
35
int 
 
36
NdbGrep::start(){
 
37
 
 
38
  return 1;
 
39
}
 
40
 
 
41
int 
 
42
NdbGrep::stop(){
 
43
 
 
44
  return 1;
 
45
}
 
46
 
 
47
 
 
48
int 
 
49
NdbGrep::query(){
 
50
 
 
51
  return 1;
 
52
}
 
53
 
 
54
 
 
55
int 
 
56
NdbGrep::verify(NDBT_Context * ctx){
 
57
  
 
58
  if (!isConnected())
 
59
    return -1;
 
60
 
 
61
  char cheat_table[255];
 
62
  BaseString::snprintf(cheat_table, 255, "TEST_DB/def/%s",ctx->getTab()->getName());
 
63
 
 
64
  char buf[255];
 
65
  BaseString::snprintf(buf, 255, "testGrepVerify -c \"nodeid=%d;host=%s\" -t %s -r %d", 
 
66
           4,  //cheat. Hardcoded nodeid....
 
67
           ctx->getRemoteMgm(),
 
68
           cheat_table,
 
69
           ctx->getNumRecords());
 
70
  
 
71
 
 
72
  ndbout << "buf: "<< buf <<endl;
 
73
  int res = system(buf);  
 
74
 
 
75
  ndbout << "res: " << res << endl;
 
76
 
 
77
  return res;
 
78
  
 
79
 
 
80
  
 
81
 
 
82
}
 
83
 
 
84
 
 
85
// Master failure
 
86
int
 
87
NFDuringGrepM_codes[] = {
 
88
  10003,
 
89
  10004,
 
90
  10005,
 
91
  10007,
 
92
  10008,
 
93
  10009,
 
94
  10010,
 
95
  10012,
 
96
  10013
 
97
};
 
98
 
 
99
// Slave failure
 
100
int
 
101
NFDuringGrepS_codes[] = {
 
102
  10014,
 
103
  10015,
 
104
  10016,
 
105
  10017,
 
106
  10018,
 
107
  10020
 
108
};
 
109
 
 
110
// Master takeover etc...
 
111
int
 
112
NFDuringGrepSL_codes[] = {
 
113
  10001,
 
114
  10002,
 
115
  10021
 
116
};
 
117
 
 
118
int 
 
119
NdbGrep::NFMaster(NdbRestarter& _restarter){
 
120
  const int sz = sizeof(NFDuringGrepM_codes)/sizeof(NFDuringGrepM_codes[0]);
 
121
  return NF(_restarter, NFDuringGrepM_codes, sz, true);
 
122
}
 
123
 
 
124
int 
 
125
NdbGrep::NFMasterAsSlave(NdbRestarter& _restarter){
 
126
  const int sz = sizeof(NFDuringGrepS_codes)/sizeof(NFDuringGrepS_codes[0]);
 
127
  return NF(_restarter, NFDuringGrepS_codes, sz, true);
 
128
}
 
129
 
 
130
int 
 
131
NdbGrep::NFSlave(NdbRestarter& _restarter){
 
132
  const int sz = sizeof(NFDuringGrepS_codes)/sizeof(NFDuringGrepS_codes[0]);
 
133
  return NF(_restarter, NFDuringGrepS_codes, sz, false);
 
134
}
 
135
 
 
136
int 
 
137
NdbGrep::NF(NdbRestarter& _restarter, int *NFDuringGrep_codes, const int sz, bool onMaster){
 
138
  {
 
139
    int nodeId = _restarter.getMasterNodeId();
 
140
 
 
141
    CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
 
142
          "Could not restart node "<< nodeId);
 
143
    
 
144
    CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
 
145
          "waitNodesNoStart failed");
 
146
    
 
147
    CHECK(_restarter.startNodes(&nodeId, 1) == 0,
 
148
          "failed to start node");
 
149
 
 
150
    NdbSleep_SecSleep(10);
 
151
  }
 
152
 
 
153
  CHECK(_restarter.waitClusterStarted() == 0,
 
154
        "waitClusterStarted failed");
 
155
 
 
156
  int nNodes = _restarter.getNumDbNodes();
 
157
 
 
158
  myRandom48Init(NdbTick_CurrentMillisecond());
 
159
 
 
160
  for(int i = 0; i<sz; i++){
 
161
 
 
162
    int error = NFDuringGrep_codes[i];
 
163
    unsigned int backupId;
 
164
 
 
165
    const int masterNodeId = _restarter.getMasterNodeId();
 
166
    CHECK(masterNodeId > 0, "getMasterNodeId failed");
 
167
    int nodeId;
 
168
 
 
169
    nodeId = masterNodeId;
 
170
    if (!onMaster) {
 
171
      int randomId;
 
172
      while (nodeId == masterNodeId) {
 
173
        randomId = myRandom48(nNodes);
 
174
        nodeId = _restarter.getDbNodeId(randomId);
 
175
      }
 
176
    }
 
177
 
 
178
    g_err << "NdbGrep::NF node = " << nodeId 
 
179
           << " error code = " << error << " masterNodeId = "
 
180
           << masterNodeId << endl;
 
181
 
 
182
 
 
183
    int val = DumpStateOrd::CmvmiSetRestartOnErrorInsert;
 
184
    CHECK(_restarter.dumpStateOneNode(nodeId, &val, 1) == 0,
 
185
          "failed to set RestartOnErrorInsert");
 
186
    CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
 
187
          "failed to set error insert");
 
188
   
 
189
    g_info << "error inserted"  << endl;
 
190
 
 
191
    g_info << "starting backup"  << endl;
 
192
    int r = start();
 
193
    g_info << "r = " << r
 
194
           << " (which should fail) started with id = "  << backupId << endl;
 
195
    if (r == 0) {
 
196
      g_err << "Grep should have failed on error_insertion " << error << endl
 
197
            << "Master = " << masterNodeId << "Node = " << nodeId << endl;
 
198
    }
 
199
 
 
200
    CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
 
201
          "waitNodesNoStart failed");
 
202
 
 
203
    g_info << "number of nodes running " << _restarter.getNumDbNodes() << endl;
 
204
 
 
205
    if (_restarter.getNumDbNodes() != nNodes) {
 
206
      g_err << "Failure: cluster not up" << endl;
 
207
      return NDBT_FAILED;
 
208
    }
 
209
 
 
210
    NdbSleep_SecSleep(1);
 
211
 
 
212
    g_info << "starting new backup"  << endl;
 
213
    CHECK(start() == 0,
 
214
          "failed to start backup");
 
215
    g_info << "(which should succeed) started with id = "  << backupId << endl;
 
216
 
 
217
    g_info << "starting node"  << endl;
 
218
    CHECK(_restarter.startNodes(&nodeId, 1) == 0,
 
219
          "failed to start node");
 
220
 
 
221
    CHECK(_restarter.waitClusterStarted() == 0,
 
222
          "waitClusterStarted failed");
 
223
    g_info << "node started"  << endl;
 
224
 
 
225
    CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
 
226
          "failed to set error insert");
 
227
  }
 
228
 
 
229
  return NDBT_OK;
 
230
}
 
231
 
 
232
int
 
233
FailS_codes[] = {
 
234
  10023,
 
235
  10024,
 
236
  10025,
 
237
  10026,
 
238
  10027,
 
239
  10028,
 
240
 10029,
 
241
  10030,
 
242
  10031
 
243
};
 
244
 
 
245
int
 
246
FailM_codes[] = {
 
247
  10023,
 
248
  10024,
 
249
  10025,
 
250
  10026,
 
251
  10027,
 
252
  10028,
 
253
  10029,
 
254
  10030,
 
255
  10031
 
256
};
 
257
 
 
258
int 
 
259
NdbGrep::FailMaster(NdbRestarter& _restarter){
 
260
  const int sz = sizeof(FailM_codes)/sizeof(FailM_codes[0]);
 
261
  return Fail(_restarter, FailM_codes, sz, true);
 
262
}
 
263
 
 
264
int 
 
265
NdbGrep::FailMasterAsSlave(NdbRestarter& _restarter){
 
266
  const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
 
267
  return Fail(_restarter, FailS_codes, sz, true);
 
268
}
 
269
 
 
270
int 
 
271
NdbGrep::FailSlave(NdbRestarter& _restarter){
 
272
  const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
 
273
  return Fail(_restarter, FailS_codes, sz, false);
 
274
}
 
275
 
 
276
int 
 
277
NdbGrep::Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster){
 
278
 
 
279
  CHECK(_restarter.waitClusterStarted() == 0,
 
280
        "waitClusterStarted failed");
 
281
 
 
282
  int nNodes = _restarter.getNumDbNodes();
 
283
 
 
284
  myRandom48Init(NdbTick_CurrentMillisecond());
 
285
 
 
286
  for(int i = 0; i<sz; i++){
 
287
    int error = Fail_codes[i];
 
288
    unsigned int backupId;
 
289
 
 
290
    const int masterNodeId = _restarter.getMasterNodeId();
 
291
    CHECK(masterNodeId > 0, "getMasterNodeId failed");
 
292
    int nodeId;
 
293
 
 
294
    nodeId = masterNodeId;
 
295
    if (!onMaster) {
 
296
      int randomId;
 
297
      while (nodeId == masterNodeId) {
 
298
        randomId = myRandom48(nNodes);
 
299
        nodeId = _restarter.getDbNodeId(randomId);
 
300
      }
 
301
    }
 
302
 
 
303
    g_err << "NdbGrep::Fail node = " << nodeId 
 
304
           << " error code = " << error << " masterNodeId = "
 
305
           << masterNodeId << endl;
 
306
 
 
307
    CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
 
308
          "failed to set error insert");
 
309
   
 
310
    g_info << "error inserted"  << endl;
 
311
    g_info << "waiting some before starting backup"  << endl;
 
312
 
 
313
    g_info << "starting backup"  << endl;
 
314
    int r = start();
 
315
    g_info << "r = " << r
 
316
           << " (which should fail) started with id = "  << backupId << endl;
 
317
    if (r == 0) {
 
318
      g_err << "Grep should have failed on error_insertion " << error << endl
 
319
            << "Master = " << masterNodeId << "Node = " << nodeId << endl;
 
320
    }
 
321
 
 
322
    CHECK(_restarter.waitClusterStarted() == 0,
 
323
          "waitClusterStarted failed");
 
324
 
 
325
    CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
 
326
          "failed to set error insert");
 
327
  }
 
328
 
 
329
  return NDBT_OK;
 
330
}
 
331
 
 
332