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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <NDBT_Test.hpp>
#include <NDBT_ReturnCodes.h>
#include <HugoTransactions.hpp>
#include <UtilTransactions.hpp>
#include <NdbRestarter.hpp>
#include <signaldata/DumpStateOrd.hpp>
struct OperationTestCase {
const char * name;
bool preCond; // start transaction | insert | commit
// start transaction 1
const char * op1;
const int val1;
// no commit
// start transaction 2
const char * op2;
const int res2;
const int val2;
// no commit
// commit transaction 1
// commit transaction 2
// start transaction
// op3 = READ
const int res3;
const int val3;
// commit transaction
};
#define X -1
OperationTestCase matrix[] = {
{ "ReadRead", true, "READ", 1, "READ", 0, 1, 0, 1 },
{ "ReadReadEx", true, "READ", 1, "READ-EX", 266, X, 0, 1 },
{ "ReadSimpleRead", true, "READ", 1, "S-READ", 0, 1, 0, 1 },
{ "ReadDirtyRead", true, "READ", 1, "D-READ", 0, 1, 0, 1 },
{ "ReadInsert", true, "READ", 1, "INSERT", 266, X, 0, 1 },
{ "ReadUpdate", true, "READ", 1, "UPDATE", 266, X, 0, 1 },
{ "ReadDelete", true, "READ", 1, "DELETE", 266, X, 0, 1 },
{ "ReadScan", true, "READ", 1, "SCAN", 0, 1, 0, 1 },
{ "ReadScanHl", true, "READ", 1, "SCAN-HL", 0, 1, 0, 1 },
{ "ReadScanEx", true, "READ", 1, "SCAN-EX", 274, X, 0, 1 },
#if 0
{ "ReadScanUp", true, "READ", 1, "SCAN-UP", 266, X, 0, 1 },
{ "ReadScanDe", true, "READ", 1, "SCAN-DE", 266, X, 0, 1 },
#endif
{ "ScanRead", true, "SCAN", 1, "READ", 0, 1, 0, 1 },
{ "ScanReadEx", true, "SCAN", 1, "READ-EX", 0, 1, 0, 1 },
{ "ScanSimpleRead", true, "SCAN", 1, "S-READ", 0, 1, 0, 1 },
{ "ScanDirtyRead", true, "SCAN", 1, "D-READ", 0, 1, 0, 1 },
{ "ScanInsert", true, "SCAN", 1, "INSERT", 630, X, 0, 1 },
{ "ScanUpdate", true, "SCAN", 1, "UPDATE", 0, 2, 0, 2 },
{ "ScanDelete", true, "SCAN", 1, "DELETE", 0, X, 626, X },
{ "ScanScan", true, "SCAN", 1, "SCAN", 0, 1, 0, 1 },
{ "ScanScanHl", true, "SCAN", 1, "SCAN-HL", 0, 1, 0, 1 },
{ "ScanScanEx", true, "SCAN", 1, "SCAN-EX", 0, 1, 0, 1 },
#if 0
{ "ScanScanUp", true, "SCAN", 1, "SCAN-UP", 266, X, 0, 1 },
{ "ScanScanDe", true, "SCAN", 1, "SCAN-DE", 266, X, 0, 1 },
#endif
{ "ScanHlRead", true, "SCAN-HL",1, "READ", 0, 1, 0, 1 },
{ "ScanHlReadEx", true, "SCAN-HL",1, "READ-EX", 266, 1, 0, 1 },
{ "ScanHlSimpleRead", true, "SCAN-HL",1, "S-READ", 0, 1, 0, 1 },
{ "ScanHlDirtyRead", true, "SCAN-HL",1, "D-READ", 0, 1, 0, 1 },
{ "ScanHlInsert", true, "SCAN-HL",1, "INSERT", 266, X, 0, 1 },
{ "ScanHlUpdate", true, "SCAN-HL",1, "UPDATE", 266, 2, 0, 1 },
{ "ScanHlDelete", true, "SCAN-HL",1, "DELETE", 266, X, 0, 1 },
{ "ScanHlScan", true, "SCAN-HL",1, "SCAN", 0, 1, 0, 1 },
{ "ScanHlScanHl", true, "SCAN-HL",1, "SCAN-HL", 0, 1, 0, 1 },
{ "ScanHlScanEx", true, "SCAN-HL",1, "SCAN-EX", 274, X, 0, 1 },
#if 0
{ "ScanHlScanUp", true, "SCAN-HL",1, "SCAN-UP", 266, X, 0, 1 },
{ "ScanHlScanDe", true, "SCAN-HL",1, "SCAN-DE", 266, X, 0, 1 },
#endif
{ "ScanExRead", true, "SCAN-EX",1, "READ", 266, 1, 0, 1 },
{ "ScanExReadEx", true, "SCAN-EX",1, "READ-EX", 266, 1, 0, 1 },
{ "ScanExSimpleRead", true, "SCAN-EX",1, "S-READ", 266, 1, 0, 1 },
{ "ScanExDirtyRead", true, "SCAN-EX",1, "D-READ", 0, 1, 0, 1 },
{ "ScanExInsert", true, "SCAN-EX",1, "INSERT", 266, X, 0, 1 },
{ "ScanExUpdate", true, "SCAN-EX",1, "UPDATE", 266, 2, 0, 1 },
{ "ScanExDelete", true, "SCAN-EX",1, "DELETE", 266, X, 0, 1 },
{ "ScanExScan", true, "SCAN-EX",1, "SCAN", 0, 1, 0, 1 },
{ "ScanExScanHl", true, "SCAN-EX",1, "SCAN-HL", 274, X, 0, 1 },
{ "ScanExScanEx", true, "SCAN-EX",1, "SCAN-EX", 274, X, 0, 1 },
#if 0
{ "ScanExScanUp", true, "SCAN-EX",1, "SCAN-UP", 266, X, 0, 1 },
{ "ScanExScanDe", true, "SCAN-EX",1, "SCAN-DE", 266, X, 0, 1 },
#endif
{ "ReadExRead", true, "READ-EX",1, "READ", 266, X, 0, 1 },
{ "ReadExReadEx", true, "READ-EX",1, "READ-EX", 266, X, 0, 1 },
{ "ReadExSimpleRead", true, "READ-EX",1, "S-READ", 266, X, 0, 1 },
{ "ReadExDirtyRead", true, "READ-EX",1, "D-READ", 0, 1, 0, 1 },
{ "ReadExInsert", true, "READ-EX",1, "INSERT", 266, X, 0, 1 },
{ "ReadExUpdate", true, "READ-EX",1, "UPDATE", 266, X, 0, 1 },
{ "ReadExDelete", true, "READ-EX",1, "DELETE", 266, X, 0, 1 },
{ "ReadExScan", true, "READ-EX",1, "SCAN", 0, 1, 0, 1 },
{ "ReadExScanHl", true, "READ-EX",1, "SCAN-HL", 274, X, 0, 1 },
{ "ReadExScanEx", true, "READ-EX",1, "SCAN-EX", 274, X, 0, 1 },
#if 0
{ "ReadExScanUp", true, "READ-EX",1, "SCAN-UP", 266, X, 0, 1 },
{ "ReadExScanDe", true, "READ-EX",1, "SCAN-DE", 266, X, 0, 1 },
#endif
{ "InsertRead", false, "INSERT", 1, "READ", 266, X, 0, 1 },
{ "InsertReadEx", false, "INSERT", 1, "READ-EX", 266, X, 0, 1 },
{ "InsertSimpleRead",false, "INSERT", 1, "S-READ", 266, X, 0, 1 },
{ "InsertDirtyRead", false, "INSERT", 1, "D-READ", 626, X, 0, 1 },
{ "InsertInsert", false, "INSERT", 1, "INSERT", 266, X, 0, 1 },
{ "InsertUpdate", false, "INSERT", 1, "UPDATE", 266, X, 0, 1 },
{ "InsertDelete", false, "INSERT", 1, "DELETE", 266, X, 0, 1 },
{ "InsertScan", false, "INSERT", 1, "SCAN", 626, X, 0, 1 },
{ "InsertScanHl", false, "INSERT", 1, "SCAN-HL", 274, X, 0, 1 },
{ "InsertScanEx", false, "INSERT", 1, "SCAN-EX", 274, X, 0, 1 },
#if 0
{ "InsertScanUp", false, "INSERT", 1, "SCAN-UP", 266, X, 0, 1 },
{ "InsertScanDe", false, "INSERT", 1, "SCAN-DE", 266, X, 0, 1 },
#endif
{ "UpdateRead", true, "UPDATE", 2, "READ", 266, X, 0, 2 },
{ "UpdateReadEx", true, "UPDATE", 2, "READ-EX", 266, X, 0, 2 },
{ "UpdateSimpleRead", true, "UPDATE", 2, "S-READ", 266, X, 0, 2 },
{ "UpdateDirtyRead", true, "UPDATE", 2, "D-READ", 0, 1, 0, 2 },
{ "UpdateInsert", true, "UPDATE", 2, "INSERT", 266, X, 0, 2 },
{ "UpdateUpdate", true, "UPDATE", 2, "UPDATE", 266, X, 0, 2 },
{ "UpdateDelete", true, "UPDATE", 2, "DELETE", 266, X, 0, 2 },
{ "UpdateScan", true, "UPDATE", 2, "SCAN", 0, 1, 0, 2 },
{ "UpdateScanHl", true, "UPDATE", 2, "SCAN-HL", 274, X, 0, 2 },
{ "UpdateScanEx", true, "UPDATE", 2, "SCAN-EX", 274, X, 0, 2 },
#if 0
{ "UpdateScanUp", true, "UPDATE", 2, "SCAN-UP", 266, X, 0, 2 },
{ "UpdateScanDe", true, "UPDATE", 2, "SCAN-DE", 266, X, 0, 2 },
#endif
{ "DeleteRead", true, "DELETE", X, "READ", 266, X, 626, X },
{ "DeleteReadEx", true, "DELETE", X, "READ-EX", 266, X, 626, X },
{ "DeleteSimpleRead", true, "DELETE", X, "S-READ", 266, X, 626, X },
{ "DeleteDirtyRead", true, "DELETE", X, "D-READ", 0, 1, 626, X },
{ "DeleteInsert", true, "DELETE", X, "INSERT", 266, X, 626, X },
{ "DeleteUpdate", true, "DELETE", X, "UPDATE", 266, X, 626, X },
{ "DeleteDelete", true, "DELETE", X, "DELETE", 266, X, 626, X },
{ "DeleteScan", true, "DELETE", X, "SCAN", 0, 1, 626, X },
{ "DeleteScanHl", true, "DELETE", X, "SCAN-HL", 274, X, 626, X },
{ "DeleteScanEx", true, "DELETE", X, "SCAN-EX", 274, X, 626, X },
#if 0
{ "DeleteScanUp", true, "DELETE", X, "SCAN-UP", 266, X, 626, X },
{ "DeleteScanDe", true, "DELETE", X, "SCAN-DE", 266, X, 626, X }
#endif
};
#define CHECK(a, b) { int x = a; int y = b; if (x != y) { \
g_err << "ERR: "<< step->getName() \
<< " failed on line " << __LINE__ << endl << " " \
<< x << " != " << y << endl;\
result = NDBT_FAILED; \
break; } }
int
runOp(HugoOperations & hugoOps,
Ndb * pNdb,
const char * op,
int value){
#define C2(x) if(!(x)) {\
g_err << "ERR: failed on line " << __LINE__ << endl; \
return NDBT_FAILED; }
if(strcmp(op, "READ") == 0){
C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
} else if(strcmp(op, "READ-EX") == 0){
C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
} else if(strcmp(op, "S-READ") == 0){
C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
} else if(strcmp(op, "D-READ") == 0){
C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_CommittedRead) == 0);
} else if(strcmp(op, "INSERT") == 0){
C2(hugoOps.pkInsertRecord(pNdb, 1, 1, value) == 0);
} else if(strcmp(op, "UPDATE") == 0){
C2(hugoOps.pkUpdateRecord(pNdb, 1, 1, value) == 0);
} else if(strcmp(op, "DELETE") == 0){
C2(hugoOps.pkDeleteRecord(pNdb, 1, 1) == 0);
} else if(strcmp(op, "SCAN") == 0){
C2(hugoOps.scanReadRecords(pNdb) == 0);
} else if(strcmp(op, "SCAN-HL") == 0){
C2(hugoOps.scanReadRecords(pNdb, NdbScanOperation::LM_Read)== 0);
} else if(strcmp(op, "SCAN-EX") == 0){
C2(hugoOps.scanReadRecords(pNdb, NdbScanOperation::LM_Exclusive)== 0);
} else {
g_err << __FILE__ << " - " << __LINE__
<< ": Unknown operation" << op << endl;
return NDBT_FAILED;
}
return NDBT_OK;
}
int
checkVal(HugoOperations & hugoOps,
const char * op,
int value,
int result){
if(result != 0)
return NDBT_OK;
if(strcmp(op, "READ") == 0){
} else if(strcmp(op, "READ-EX") == 0){
} else if(strcmp(op, "S-READ") == 0){
} else if(strcmp(op, "D-READ") == 0){
} else if(strcmp(op, "SCAN") == 0){
} else if(strcmp(op, "SCAN-HL") == 0){
} else if(strcmp(op, "SCAN-EX") == 0){
} else {
return NDBT_OK;
}
return hugoOps.verifyUpdatesValue(value);
}
#define TIMEOUT 100
int
setTransactionTimeout(NDBT_Context* ctx, NDBT_Step* step){
NdbRestarter restarter;
int val[] =
{ DumpStateOrd::TcSetTransactionTimeout, TIMEOUT };
if(restarter.dumpStateAllNodes(val, 2) != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
int
runTwoTrans1(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
HugoOperations T1(*ctx->getTab());
Ndb* pNdb = GETNDB(step);
const char * op1 = ctx->getProperty("op1", "NONE");
int val1 = ctx->getProperty("val1", ~0);
do {
// Insert, read
CHECK(T1.startTransaction(pNdb), 0);
CHECK(runOp(T1, pNdb, op1, val1), 0);
CHECK(T1.execute_NoCommit(pNdb), 0);
CHECK(checkVal(T1, op1, val1, 0), 0);
ctx->setProperty("T1-1-Complete", 1);
while(ctx->getProperty("T2-Complete", (Uint32)0) == 0){
T1.refresh();
NdbSleep_MilliSleep(10);
}
CHECK(T1.execute_Commit(pNdb), 0);
} while(false);
T1.closeTransaction(pNdb);
if(result != NDBT_OK)
return result;
const int res3 = ctx->getProperty("res3", ~0);
const int val3 = ctx->getProperty("val3", ~0);
do {
CHECK(T1.startTransaction(pNdb), 0);
CHECK(runOp(T1, pNdb, "READ", 0), 0);
CHECK(T1.execute_Commit(pNdb), res3);
CHECK(checkVal(T1, "READ", val3, res3), 0);
} while(false);
T1.closeTransaction(pNdb);
return result;
}
int
runTwoTrans2(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
HugoOperations T2(*ctx->getTab());
Ndb* pNdb = GETNDB(step);
const char * op2 = ctx->getProperty("op2", "NONE");
const int res2 = ctx->getProperty("res2", ~0);
const int val2 = ctx->getProperty("val2", ~0);
while(ctx->getProperty("T1-1-Complete", (Uint32)0) == 0 &&
!ctx->isTestStopped()){
NdbSleep_MilliSleep(100);
}
if(!ctx->isTestStopped()){
do {
CHECK(T2.startTransaction(pNdb), 0);
CHECK(runOp(T2, pNdb, op2, val2), 0);
CHECK(T2.execute_NoCommit(pNdb), res2);
CHECK(checkVal(T2, op2, val2, res2), 0);
if(res2 == 0){
CHECK(T2.execute_Commit(pNdb), res2);
}
} while(false);
T2.closeTransaction(pNdb);
}
ctx->setProperty("T2-Complete", 1);
return result;
}
int
runInsertRecord(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
HugoOperations hugoOps(*ctx->getTab());
Ndb* pNdb = GETNDB(step);
do{
// Insert, insert
CHECK(hugoOps.startTransaction(pNdb), 0);
CHECK(hugoOps.pkInsertRecord(pNdb, 1, 1, 1), 0);
CHECK(hugoOps.execute_Commit(pNdb), 0);
} while(false);
hugoOps.closeTransaction(pNdb);
return result;
}
int
runClearTable(NDBT_Context* ctx, NDBT_Step* step){
int records = ctx->getNumRecords();
UtilTransactions utilTrans(*ctx->getTab());
if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
int
main(int argc, const char** argv){
ndb_init();
NDBT_TestSuite ts("testOperations");
for(Uint32 i = 0; i<sizeof(matrix)/sizeof(matrix[0]); i++){
NDBT_TestCaseImpl1 *pt = new NDBT_TestCaseImpl1(&ts, matrix[i].name, "");
pt->addInitializer(new NDBT_Initializer(pt,
"runClearTable",
runClearTable));
if(matrix[i].preCond){
pt->addInitializer(new NDBT_Initializer(pt,
"runInsertRecord",
runInsertRecord));
}
pt->addInitializer(new NDBT_Initializer(pt,
"setTransactionTimeout",
setTransactionTimeout));
pt->setProperty("op1", matrix[i].op1);
pt->setProperty("val1", matrix[i].val1);
pt->setProperty("op2", matrix[i].op2);
pt->setProperty("res2", matrix[i].res2);
pt->setProperty("val2", matrix[i].val2);
pt->setProperty("res3", matrix[i].res3);
pt->setProperty("val3", matrix[i].val3);
pt->addStep(new NDBT_ParallelStep(pt,
matrix[i].name,
runTwoTrans1));
pt->addStep(new NDBT_ParallelStep(pt,
matrix[i].name,
runTwoTrans2));
pt->addFinalizer(new NDBT_Finalizer(pt,
"runClearTable",
runClearTable));
ts.addTest(pt);
}
return ts.execute(argc, argv);
}
|