1
/* Copyright (C) 2003 MySQL AB
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.
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.
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 */
16
#include <signaldata/DumpStateOrd.hpp>
17
#include <NdbGrep.hpp>
19
#include <NDBT_Output.hpp>
20
#include <NdbConfig.h>
21
#include <ConfigRetriever.hpp>
22
#include <ndb_version.h>
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; } }
56
NdbGrep::verify(NDBT_Context * ctx){
61
char cheat_table[255];
62
BaseString::snprintf(cheat_table, 255, "TEST_DB/def/%s",ctx->getTab()->getName());
65
BaseString::snprintf(buf, 255, "testGrepVerify -c \"nodeid=%d;host=%s\" -t %s -r %d",
66
4, //cheat. Hardcoded nodeid....
69
ctx->getNumRecords());
72
ndbout << "buf: "<< buf <<endl;
73
int res = system(buf);
75
ndbout << "res: " << res << endl;
87
NFDuringGrepM_codes[] = {
101
NFDuringGrepS_codes[] = {
110
// Master takeover etc...
112
NFDuringGrepSL_codes[] = {
119
NdbGrep::NFMaster(NdbRestarter& _restarter){
120
const int sz = sizeof(NFDuringGrepM_codes)/sizeof(NFDuringGrepM_codes[0]);
121
return NF(_restarter, NFDuringGrepM_codes, sz, true);
125
NdbGrep::NFMasterAsSlave(NdbRestarter& _restarter){
126
const int sz = sizeof(NFDuringGrepS_codes)/sizeof(NFDuringGrepS_codes[0]);
127
return NF(_restarter, NFDuringGrepS_codes, sz, true);
131
NdbGrep::NFSlave(NdbRestarter& _restarter){
132
const int sz = sizeof(NFDuringGrepS_codes)/sizeof(NFDuringGrepS_codes[0]);
133
return NF(_restarter, NFDuringGrepS_codes, sz, false);
137
NdbGrep::NF(NdbRestarter& _restarter, int *NFDuringGrep_codes, const int sz, bool onMaster){
139
int nodeId = _restarter.getMasterNodeId();
141
CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
142
"Could not restart node "<< nodeId);
144
CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
145
"waitNodesNoStart failed");
147
CHECK(_restarter.startNodes(&nodeId, 1) == 0,
148
"failed to start node");
150
NdbSleep_SecSleep(10);
153
CHECK(_restarter.waitClusterStarted() == 0,
154
"waitClusterStarted failed");
156
int nNodes = _restarter.getNumDbNodes();
158
myRandom48Init(NdbTick_CurrentMillisecond());
160
for(int i = 0; i<sz; i++){
162
int error = NFDuringGrep_codes[i];
163
unsigned int backupId;
165
const int masterNodeId = _restarter.getMasterNodeId();
166
CHECK(masterNodeId > 0, "getMasterNodeId failed");
169
nodeId = masterNodeId;
172
while (nodeId == masterNodeId) {
173
randomId = myRandom48(nNodes);
174
nodeId = _restarter.getDbNodeId(randomId);
178
g_err << "NdbGrep::NF node = " << nodeId
179
<< " error code = " << error << " masterNodeId = "
180
<< masterNodeId << endl;
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");
189
g_info << "error inserted" << endl;
191
g_info << "starting backup" << endl;
193
g_info << "r = " << r
194
<< " (which should fail) started with id = " << backupId << endl;
196
g_err << "Grep should have failed on error_insertion " << error << endl
197
<< "Master = " << masterNodeId << "Node = " << nodeId << endl;
200
CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
201
"waitNodesNoStart failed");
203
g_info << "number of nodes running " << _restarter.getNumDbNodes() << endl;
205
if (_restarter.getNumDbNodes() != nNodes) {
206
g_err << "Failure: cluster not up" << endl;
210
NdbSleep_SecSleep(1);
212
g_info << "starting new backup" << endl;
214
"failed to start backup");
215
g_info << "(which should succeed) started with id = " << backupId << endl;
217
g_info << "starting node" << endl;
218
CHECK(_restarter.startNodes(&nodeId, 1) == 0,
219
"failed to start node");
221
CHECK(_restarter.waitClusterStarted() == 0,
222
"waitClusterStarted failed");
223
g_info << "node started" << endl;
225
CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
226
"failed to set error insert");
259
NdbGrep::FailMaster(NdbRestarter& _restarter){
260
const int sz = sizeof(FailM_codes)/sizeof(FailM_codes[0]);
261
return Fail(_restarter, FailM_codes, sz, true);
265
NdbGrep::FailMasterAsSlave(NdbRestarter& _restarter){
266
const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
267
return Fail(_restarter, FailS_codes, sz, true);
271
NdbGrep::FailSlave(NdbRestarter& _restarter){
272
const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
273
return Fail(_restarter, FailS_codes, sz, false);
277
NdbGrep::Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster){
279
CHECK(_restarter.waitClusterStarted() == 0,
280
"waitClusterStarted failed");
282
int nNodes = _restarter.getNumDbNodes();
284
myRandom48Init(NdbTick_CurrentMillisecond());
286
for(int i = 0; i<sz; i++){
287
int error = Fail_codes[i];
288
unsigned int backupId;
290
const int masterNodeId = _restarter.getMasterNodeId();
291
CHECK(masterNodeId > 0, "getMasterNodeId failed");
294
nodeId = masterNodeId;
297
while (nodeId == masterNodeId) {
298
randomId = myRandom48(nNodes);
299
nodeId = _restarter.getDbNodeId(randomId);
303
g_err << "NdbGrep::Fail node = " << nodeId
304
<< " error code = " << error << " masterNodeId = "
305
<< masterNodeId << endl;
307
CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
308
"failed to set error insert");
310
g_info << "error inserted" << endl;
311
g_info << "waiting some before starting backup" << endl;
313
g_info << "starting backup" << endl;
315
g_info << "r = " << r
316
<< " (which should fail) started with id = " << backupId << endl;
318
g_err << "Grep should have failed on error_insertion " << error << endl
319
<< "Master = " << masterNodeId << "Node = " << nodeId << endl;
322
CHECK(_restarter.waitClusterStarted() == 0,
323
"waitClusterStarted failed");
325
CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
326
"failed to set error insert");