1 /* Copyright (c) 2003-2007 MySQL AB
2 Use is subject to license terms
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16
17 #include <NDBT.hpp>
18 #include <NDBT_Test.hpp>
19 #include <HugoTransactions.hpp>
20 #include <UtilTransactions.hpp>
21 #include <NdbRestarter.hpp>
22 #include <Vector.hpp>
23 #include "ScanFunctions.hpp"
24 #include <random.h>
25
26 const NdbDictionary::Table *
getTable(Ndb * pNdb,int i)27 getTable(Ndb* pNdb, int i){
28 const NdbDictionary::Table* t = NDBT_Tables::getTable(i);
29 if (t == NULL){
30 return 0;
31 }
32 return pNdb->getDictionary()->getTable(t->getName());
33 }
34
35
runLoadTable(NDBT_Context * ctx,NDBT_Step * step)36 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
37
38 int records = ctx->getProperty("Rows", ctx->getNumRecords());
39
40 HugoTransactions hugoTrans(*ctx->getTab());
41 if (hugoTrans.loadTable(GETNDB(step), records) != 0){
42 return NDBT_FAILED;
43 }
44 return NDBT_OK;
45 }
46
47
runCreateAllTables(NDBT_Context * ctx,NDBT_Step * step)48 int runCreateAllTables(NDBT_Context* ctx, NDBT_Step* step){
49
50 int a = NDBT_Tables::createAllTables(GETNDB(step), false, true);
51 return a;
52 }
53
runDropAllTablesExceptTestTable(NDBT_Context * ctx,NDBT_Step * step)54 int runDropAllTablesExceptTestTable(NDBT_Context* ctx, NDBT_Step* step){
55
56 for (int i=0; i < NDBT_Tables::getNumTables(); i++){
57
58 const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);
59 if (tab == NULL){
60 return NDBT_ProgramExit(NDBT_FAILED);
61 }
62
63 // Don't drop test table
64 if (strcmp(tab->getName(), ctx->getTab()->getName()) == 0){
65 continue;
66 }
67
68 int res = GETNDB(step)->getDictionary()->dropTable(tab->getName());
69 if(res == -1){
70 return NDBT_FAILED;
71 }
72 }
73 return NDBT_OK;
74 }
75
76
runLoadAllTables(NDBT_Context * ctx,NDBT_Step * step)77 int runLoadAllTables(NDBT_Context* ctx, NDBT_Step* step){
78
79 int records = ctx->getNumRecords();
80 for (int i=0; i < NDBT_Tables::getNumTables(); i++){
81
82 const NdbDictionary::Table* tab = getTable(GETNDB(step), i);
83 if (tab == NULL){
84 return NDBT_FAILED;
85 }
86 HugoTransactions hugoTrans(*tab);
87 if (hugoTrans.loadTable(GETNDB(step), records) != 0){
88 return NDBT_FAILED;
89 }
90 }
91 return NDBT_OK;
92 }
93
94 char orderedPkIdxName[255];
95
createOrderedPkIndex(NDBT_Context * ctx,NDBT_Step * step)96 int createOrderedPkIndex(NDBT_Context* ctx, NDBT_Step* step){
97
98 const NdbDictionary::Table* pTab = ctx->getTab();
99 Ndb* pNdb = GETNDB(step);
100
101 // Create index
102 BaseString::snprintf(orderedPkIdxName, sizeof(orderedPkIdxName),
103 "IDC_O_PK_%s", pTab->getName());
104 NdbDictionary::Index pIdx(orderedPkIdxName);
105 pIdx.setTable(pTab->getName());
106 pIdx.setType(NdbDictionary::Index::OrderedIndex);
107 pIdx.setLogging(false);
108
109 for (int c = 0; c< pTab->getNoOfColumns(); c++){
110 const NdbDictionary::Column * col = pTab->getColumn(c);
111 if(col->getPrimaryKey()){
112 pIdx.addIndexColumn(col->getName());
113 }
114 }
115
116 if (pNdb->getDictionary()->createIndex(pIdx) != 0){
117 ndbout << "FAILED! to create index" << endl;
118 const NdbError err = pNdb->getDictionary()->getNdbError();
119 ERR(err);
120 return NDBT_FAILED;
121 }
122
123 return NDBT_OK;
124 }
125
createOrderedPkIndex_Drop(NDBT_Context * ctx,NDBT_Step * step)126 int createOrderedPkIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
127 const NdbDictionary::Table* pTab = ctx->getTab();
128 Ndb* pNdb = GETNDB(step);
129
130 // Drop index
131 if (pNdb->getDictionary()->dropIndex(orderedPkIdxName,
132 pTab->getName()) != 0){
133 ndbout << "FAILED! to drop index" << endl;
134 ERR(pNdb->getDictionary()->getNdbError());
135 return NDBT_FAILED;
136 }
137
138 return NDBT_OK;
139 }
140
141
runScanReadRandomTable(NDBT_Context * ctx,NDBT_Step * step)142 int runScanReadRandomTable(NDBT_Context* ctx, NDBT_Step* step){
143 int loops = ctx->getNumLoops();
144 int records = ctx->getNumRecords();
145 int parallelism = ctx->getProperty("Parallelism", 240);
146 int abort = ctx->getProperty("AbortProb", 5);
147
148 int i = 0;
149 while (i<loops) {
150
151 int tabNum = myRandom48(NDBT_Tables::getNumTables());
152 const NdbDictionary::Table* tab = getTable(GETNDB(step), tabNum);
153 if (tab == NULL){
154 g_info << "tab == NULL" << endl;
155 return NDBT_FAILED;
156 }
157
158 g_info << "Scan reading from table " << tab->getName() << endl;
159 HugoTransactions hugoTrans(*tab);
160
161 g_info << i << ": ";
162 if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism) != 0){
163 return NDBT_FAILED;
164 }
165 i++;
166 }
167 return NDBT_OK;
168 }
169
runInsertUntilStopped(NDBT_Context * ctx,NDBT_Step * step)170 int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
171 int records = ctx->getNumRecords();
172 int i = 0;
173 HugoTransactions hugoTrans(*ctx->getTab());
174 while (ctx->isTestStopped() == false) {
175 g_info << i << ": ";
176 if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){
177 return NDBT_FAILED;
178 }
179 i++;
180 }
181 return NDBT_OK;
182 }
183
runInsertDelete(NDBT_Context * ctx,NDBT_Step * step)184 int runInsertDelete(NDBT_Context* ctx, NDBT_Step* step){
185 int result = NDBT_OK;
186 int records = ctx->getNumRecords();
187 int loops = ctx->getNumLoops();
188 int i = 0;
189 HugoTransactions hugoTrans(*ctx->getTab());
190 UtilTransactions utilTrans(*ctx->getTab());
191 while (i<loops) {
192 g_info << i << ": ";
193 if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){
194 result = NDBT_FAILED;
195 break;
196 }
197 if (utilTrans.clearTable(GETNDB(step), records) != 0){
198 result = NDBT_FAILED;
199 break;
200 }
201 i++;
202 }
203
204 ctx->stopTest();
205
206 return result;
207 }
208
runClearTable(NDBT_Context * ctx,NDBT_Step * step)209 int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
210 int records = ctx->getNumRecords();
211
212 UtilTransactions utilTrans(*ctx->getTab());
213 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
214 return NDBT_FAILED;
215 }
216 return NDBT_OK;
217 }
218
runScanDelete(NDBT_Context * ctx,NDBT_Step * step)219 int runScanDelete(NDBT_Context* ctx, NDBT_Step* step){
220 int loops = ctx->getNumLoops();
221 int records = ctx->getNumRecords();
222
223 int i = 0;
224 UtilTransactions utilTrans(*ctx->getTab());
225 HugoTransactions hugoTrans(*ctx->getTab());
226 while (i<loops) {
227 g_info << i << ": ";
228 if (utilTrans.clearTable(GETNDB(step), records) != 0){
229 return NDBT_FAILED;
230 }
231 // Load table, don't allow any primary key violations
232 if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
233 return NDBT_FAILED;
234 }
235 i++;
236 }
237 return NDBT_OK;
238 }
239
runScanDelete2(NDBT_Context * ctx,NDBT_Step * step)240 int runScanDelete2(NDBT_Context* ctx, NDBT_Step* step){
241 int loops = ctx->getNumLoops();
242 int records = ctx->getNumRecords();
243
244 int i = 0;
245 UtilTransactions utilTrans(*ctx->getTab());
246 HugoTransactions hugoTrans(*ctx->getTab());
247
248 while (i<loops) {
249 g_info << i << ": ";
250 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
251 return NDBT_FAILED;
252 }
253 // Load table, don't allow any primary key violations
254 if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
255 return NDBT_FAILED;
256 }
257 i++;
258 }
259 return NDBT_OK;
260 }
261
runVerifyTable(NDBT_Context * ctx,NDBT_Step * step)262 int runVerifyTable(NDBT_Context* ctx, NDBT_Step* step){
263 return NDBT_OK;
264 }
265
runScanRead(NDBT_Context * ctx,NDBT_Step * step)266 int runScanRead(NDBT_Context* ctx, NDBT_Step* step){
267 int loops = ctx->getNumLoops();
268 int records = ctx->getProperty("Rows", ctx->getNumRecords());
269 int parallelism = ctx->getProperty("Parallelism", 240);
270 int abort = ctx->getProperty("AbortProb", 5);
271
272 int i = 0;
273 HugoTransactions hugoTrans(*ctx->getTab());
274 while (i<loops && !ctx->isTestStopped()) {
275 g_info << i << ": ";
276 if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism) != 0){
277 return NDBT_FAILED;
278 }
279 i++;
280 }
281 return NDBT_OK;
282 }
283
runRandScanRead(NDBT_Context * ctx,NDBT_Step * step)284 int runRandScanRead(NDBT_Context* ctx, NDBT_Step* step){
285 int loops = ctx->getNumLoops();
286 int records = ctx->getNumRecords();
287 int parallelism = ctx->getProperty("Parallelism", 240);
288 int abort = ctx->getProperty("AbortProb", 5);
289 int tupscan = ctx->getProperty("TupScan", (Uint32)0);
290
291 int i = 0;
292 HugoTransactions hugoTrans(*ctx->getTab());
293 while (i<loops && !ctx->isTestStopped()) {
294 g_info << i << ": ";
295 NdbOperation::LockMode lm = (NdbOperation::LockMode)(rand() % 3);
296 int scan_flags = 0;
297
298 if (tupscan == 1)
299 scan_flags |= NdbScanOperation::SF_TupScan;
300 else if (tupscan == 2 && ((rand() & 0x800)))
301 {
302 scan_flags |= NdbScanOperation::SF_TupScan;
303 }
304
305 if (hugoTrans.scanReadRecords(GETNDB(step),
306 records, abort, parallelism,
307 lm,
308 scan_flags) != 0){
309 return NDBT_FAILED;
310 }
311 i++;
312 }
313 return NDBT_OK;
314 }
315
runScanReadIndex(NDBT_Context * ctx,NDBT_Step * step)316 int runScanReadIndex(NDBT_Context* ctx, NDBT_Step* step){
317 int loops = ctx->getNumLoops();
318 int records = ctx->getNumRecords();
319 int parallelism = ctx->getProperty("Parallelism", 240);
320 int abort = ctx->getProperty("AbortProb", 5);
321 const NdbDictionary::Index * pIdx =
322 GETNDB(step)->getDictionary()->getIndex(orderedPkIdxName,
323 ctx->getTab()->getName());
324
325 int i = 0;
326 HugoTransactions hugoTrans(*ctx->getTab());
327 while (pIdx && i<loops && !ctx->isTestStopped()) {
328 g_info << i << ": ";
329 bool sort = (rand() % 100) > 50 ? true : false;
330 bool desc = (rand() % 100) > 50 ? true : false;
331 desc = false; // random causes too many deadlocks
332 int scan_flags =
333 (NdbScanOperation::SF_OrderBy & -(int)sort) |
334 (NdbScanOperation::SF_Descending & -(int)desc);
335 NdbOperation::LockMode lm = (NdbOperation::LockMode)(rand() % 3);
336 if (hugoTrans.scanReadRecords(GETNDB(step), pIdx,
337 records, abort, parallelism,
338 lm,
339 scan_flags) != 0){
340 return NDBT_FAILED;
341 }
342 i++;
343 }
344 return NDBT_OK;
345 }
346
runScanReadCommitted(NDBT_Context * ctx,NDBT_Step * step)347 int runScanReadCommitted(NDBT_Context* ctx, NDBT_Step* step){
348 int loops = ctx->getNumLoops();
349 int records = ctx->getNumRecords();
350 int parallelism = ctx->getProperty("Parallelism", 240);
351 int abort = ctx->getProperty("AbortProb", 5);
352 bool tupScan = ctx->getProperty("TupScan");
353 int scan_flags = (NdbScanOperation::SF_TupScan & -(int)tupScan);
354
355 int i = 0;
356 HugoTransactions hugoTrans(*ctx->getTab());
357 while (i<loops && !ctx->isTestStopped()) {
358 g_info << i << ": ";
359 if (hugoTrans.scanReadRecords(GETNDB(step), records,
360 abort, parallelism,
361 NdbOperation::LM_CommittedRead,
362 scan_flags) != 0){
363 return NDBT_FAILED;
364 }
365 i++;
366 }
367 return NDBT_OK;
368 }
369
runScanReadError(NDBT_Context * ctx,NDBT_Step * step)370 int runScanReadError(NDBT_Context* ctx, NDBT_Step* step){
371 int result = NDBT_OK;
372 int loops = ctx->getNumLoops();
373 int records = ctx->getNumRecords();
374 int parallelism = 240; // Max parallelism
375 int error = ctx->getProperty("ErrorCode");
376 NdbRestarter restarter;
377
378 int i = 0;
379 HugoTransactions hugoTrans(*ctx->getTab());
380 while (i<loops && !ctx->isTestStopped()) {
381 g_info << i << ": ";
382
383 ndbout << "insertErrorInAllNodes("<<error<<")"<<endl;
384 if (restarter.insertErrorInAllNodes(error) != 0){
385 ndbout << "Could not insert error in all nodes "<<endl;
386 return NDBT_FAILED;
387 }
388
389 if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
390 result = NDBT_FAILED;
391 }
392 i++;
393 }
394
395 restarter.insertErrorInAllNodes(0);
396 return result;
397 }
398
399 int
runInsertError(NDBT_Context * ctx,NDBT_Step * step)400 runInsertError(NDBT_Context* ctx, NDBT_Step* step){
401 int error = ctx->getProperty("ErrorCode");
402 NdbRestarter restarter;
403
404 ctx->setProperty("ErrorCode", (Uint32)0);
405 if (restarter.insertErrorInAllNodes(error) != 0){
406 ndbout << "Could not insert error in all nodes "<<endl;
407 return NDBT_FAILED;
408 }
409 return NDBT_OK;
410 }
411
runScanReadErrorOneNode(NDBT_Context * ctx,NDBT_Step * step)412 int runScanReadErrorOneNode(NDBT_Context* ctx, NDBT_Step* step){
413 int result = NDBT_OK;
414 int loops = ctx->getNumLoops();
415 int records = ctx->getNumRecords();
416 int parallelism = 240; // Max parallelism
417 int error = ctx->getProperty("ErrorCode");
418 NdbRestarter restarter;
419 int lastId = 0;
420
421 if (restarter.getNumDbNodes() < 2){
422 ctx->stopTest();
423 return NDBT_OK;
424 }
425
426 int i = 0;
427 HugoTransactions hugoTrans(*ctx->getTab());
428 while (i<loops && result == NDBT_OK) {
429 g_info << i << ": ";
430
431 int nodeId = restarter.getDbNodeId(lastId);
432 lastId = (lastId + 1) % restarter.getNumDbNodes();
433 ndbout << "insertErrorInNode("<<nodeId<<", "<<error<<")"<<endl;
434 if (restarter.insertErrorInNode(nodeId, error) != 0){
435 ndbout << "Could not insert error in node="<<nodeId<<endl;
436 return NDBT_FAILED;
437 }
438
439 for (int j=0; j<10; j++){
440 if (hugoTrans.scanReadRecords(GETNDB(step),
441 records, 0, parallelism) != 0)
442 result = NDBT_FAILED;
443 }
444
445
446 if(restarter.waitClusterStarted(120) != 0){
447 g_err << "Cluster failed to restart" << endl;
448 result = NDBT_FAILED;
449 }
450 restarter.insertErrorInAllNodes(0);
451
452 i++;
453 }
454 restarter.insertErrorInAllNodes(0);
455 return result;
456 }
457
runRestartAll(NDBT_Context * ctx,NDBT_Step * step)458 int runRestartAll(NDBT_Context* ctx, NDBT_Step* step){
459
460 NdbRestarter restarter;
461
462 if (restarter.restartAll() != 0){
463 ndbout << "Could not restart all nodes"<<endl;
464 return NDBT_FAILED;
465 }
466
467 if (restarter.waitClusterStarted(120) != 0){
468 ndbout << "Could not restarted" << endl;
469 return NDBT_FAILED;
470 }
471
472 return NDBT_OK;
473 }
474
475 static int RANDOM_PARALLELISM = 9999;
476
runScanReadUntilStopped(NDBT_Context * ctx,NDBT_Step * step)477 int runScanReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
478 int records = ctx->getNumRecords();
479 int i = 0;
480
481 int parallelism = ctx->getProperty("Parallelism", 240);
482 int para = parallelism;
483
484 HugoTransactions hugoTrans(*ctx->getTab());
485 while (ctx->isTestStopped() == false) {
486 if (parallelism == RANDOM_PARALLELISM)
487 para = myRandom48(239)+1;
488
489 g_info << i << ": ";
490 if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, para) != 0){
491 return NDBT_FAILED;
492 }
493 i++;
494 }
495 return NDBT_OK;
496 }
497
runScanReadUntilStoppedNoCount(NDBT_Context * ctx,NDBT_Step * step)498 int runScanReadUntilStoppedNoCount(NDBT_Context* ctx, NDBT_Step* step){
499 int i = 0;
500 HugoTransactions hugoTrans(*ctx->getTab());
501 while (ctx->isTestStopped() == false) {
502 g_info << i << ": ";
503 if (hugoTrans.scanReadRecords(GETNDB(step), 0) != 0){
504 return NDBT_FAILED;
505 }
506 i++;
507 }
508 return NDBT_OK;
509 }
510
runScanReadUntilStoppedPrintTime(NDBT_Context * ctx,NDBT_Step * step)511 int runScanReadUntilStoppedPrintTime(NDBT_Context* ctx, NDBT_Step* step){
512 int records = ctx->getNumRecords();
513 int i = 0;
514 int parallelism = ctx->getProperty("Parallelism", 240);
515 NdbTimer timer;
516 Ndb* ndb = GETNDB(step);
517
518
519 HugoTransactions hugoTrans(*ctx->getTab());
520 while (ctx->isTestStopped() == false) {
521 timer.doReset();
522 timer.doStart();
523 g_info << i << ": ";
524 if (ndb->waitUntilReady() != 0)
525 return NDBT_FAILED;
526 if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0)
527 return NDBT_FAILED;
528 timer.doStop();
529 if ((timer.elapsedTime()/1000) > 1)
530 timer.printTotalTime();
531 i++;
532 }
533 return NDBT_OK;
534 }
535
536
runPkRead(NDBT_Context * ctx,NDBT_Step * step)537 int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
538 int loops = ctx->getNumLoops();
539 int records = ctx->getNumRecords();
540 int i = 0;
541 HugoTransactions hugoTrans(*ctx->getTab());
542 while (i<loops) {
543 g_info << i << ": ";
544 if (hugoTrans.pkReadRecords(GETNDB(step), records) != 0){
545 return NDBT_FAILED;
546 }
547 i++;
548 }
549 return NDBT_OK;
550 }
551
runScanUpdate(NDBT_Context * ctx,NDBT_Step * step)552 int runScanUpdate(NDBT_Context* ctx, NDBT_Step* step){
553 int loops = ctx->getNumLoops();
554 int records = ctx->getNumRecords();
555 int parallelism = ctx->getProperty("Parallelism", 1);
556 int abort = ctx->getProperty("AbortProb", 5);
557 int i = 0;
558 HugoTransactions hugoTrans(*ctx->getTab());
559 while (i<loops) {
560 g_info << i << ": ";
561
562 if (hugoTrans.scanUpdateRecords(GETNDB(step), records, abort, parallelism) != 0){
563 return NDBT_FAILED;
564 }
565 i++;
566 }
567 return NDBT_OK;
568 }
569
runScanUpdateUntilStopped(NDBT_Context * ctx,NDBT_Step * step)570 int runScanUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
571 int records = ctx->getNumRecords();
572 int i = 0;
573
574 int parallelism = ctx->getProperty("Parallelism", 240);
575 int para = parallelism;
576
577 HugoTransactions hugoTrans(*ctx->getTab());
578 while (ctx->isTestStopped() == false) {
579 if (parallelism == RANDOM_PARALLELISM)
580 para = myRandom48(239)+1;
581
582 g_info << i << ": ";
583 if (hugoTrans.scanUpdateRecords(GETNDB(step), 0, 0, para) == NDBT_FAILED){
584 return NDBT_FAILED;
585 }
586 i++;
587 }
588 return NDBT_OK;
589 }
590
591
runScanUpdate2(NDBT_Context * ctx,NDBT_Step * step)592 int runScanUpdate2(NDBT_Context* ctx, NDBT_Step* step){
593 int loops = ctx->getNumLoops();
594 int records = ctx->getNumRecords();
595 int parallelism = ctx->getProperty("Parallelism", 240);
596 int abort = ctx->getProperty("AbortProb", 5);
597 int i = 0;
598 HugoTransactions hugoTrans(*ctx->getTab());
599 while (i<loops) {
600 g_info << i << ": ";
601 if (hugoTrans.scanUpdateRecords2(GETNDB(step), records, abort, parallelism) != 0){
602 return NDBT_FAILED;
603 }
604 i++;
605 }
606 return NDBT_OK;
607 }
608
runLocker(NDBT_Context * ctx,NDBT_Step * step)609 int runLocker(NDBT_Context* ctx, NDBT_Step* step){
610 int result = NDBT_OK;
611 int records = ctx->getNumRecords();
612 HugoTransactions hugoTrans(*ctx->getTab());
613
614 if (hugoTrans.lockRecords(GETNDB(step), records, 5, 500) != 0){
615 result = NDBT_FAILED;
616 }
617 ctx->stopTest();
618
619 return result;
620 }
621
runRestarter(NDBT_Context * ctx,NDBT_Step * step)622 int runRestarter(NDBT_Context* ctx, NDBT_Step* step){
623 int result = NDBT_OK;
624 int loops = ctx->getNumLoops();
625 NdbRestarter restarter;
626 int i = 0;
627 int lastId = 0;
628 int timeout = 240;
629
630 if (restarter.getNumDbNodes() < 2){
631 ctx->stopTest();
632 return NDBT_OK;
633 }
634 while(i<loops && result != NDBT_FAILED){
635 if(restarter.waitClusterStarted(timeout) != 0){
636 g_err << "Cluster failed to start 1" << endl;
637 result = NDBT_FAILED;
638 break;
639 }
640 NdbSleep_SecSleep(10);
641
642 int nodeId = restarter.getDbNodeId(lastId);
643 lastId = (lastId + 1) % restarter.getNumDbNodes();
644 if(restarter.restartOneDbNode(nodeId, false, false, true) != 0){
645 g_err << "Failed to restartNextDbNode" << endl;
646 result = NDBT_FAILED;
647 break;
648 }
649 i++;
650 }
651 if(restarter.waitClusterStarted(timeout) != 0){
652 g_err << "Cluster failed to start 2" << endl;
653 result = NDBT_FAILED;
654 }
655
656 ctx->stopTest();
657
658 return result;
659 }
660
661
runStopAndStartNode(NDBT_Context * ctx,NDBT_Step * step)662 int runStopAndStartNode(NDBT_Context* ctx, NDBT_Step* step){
663 int result = NDBT_OK;
664 int loops = ctx->getNumLoops();
665 NdbRestarter restarter;
666 int i = 0;
667 int lastId = 0;
668 int timeout = 240;
669
670 if (restarter.getNumDbNodes() < 2){
671 ctx->stopTest();
672 return NDBT_OK;
673 }
674 while(i<loops && result != NDBT_FAILED){
675 if(restarter.waitClusterStarted(timeout) != 0){
676 g_err << "Cluster failed to start 1" << endl;
677 result = NDBT_FAILED;
678 break;
679 }
680 NdbSleep_SecSleep(1);
681 int nodeId = restarter.getDbNodeId(lastId);
682 lastId = (lastId + 1) % restarter.getNumDbNodes();
683 g_err << "Stopping node " << nodeId << endl;
684
685 if(restarter.restartOneDbNode(nodeId, false, true) != 0){
686 g_err << "Failed to restartOneDbNode" << endl;
687 result = NDBT_FAILED;
688 break;
689 }
690
691 if(restarter.waitNodesNoStart(&nodeId, 1, timeout) != 0){
692 g_err << "Node failed to reach NoStart" << endl;
693 result = NDBT_FAILED;
694 break;
695 }
696
697 g_info << "Sleeping for 10 secs" << endl;
698 NdbSleep_SecSleep(10);
699
700 g_err << "Starting node " << nodeId << endl;
701 if(restarter.startNodes(&nodeId, 1) != 0){
702 g_err << "Failed to start the node" << endl;
703 result = NDBT_FAILED;
704 break;
705 }
706
707 i++;
708 }
709 if(restarter.waitClusterStarted(timeout) != 0){
710 g_err << "Cluster failed to start 2" << endl;
711 result = NDBT_FAILED;
712 }
713
714 ctx->stopTest();
715
716 return result;
717 }
718
runRestarter9999(NDBT_Context * ctx,NDBT_Step * step)719 int runRestarter9999(NDBT_Context* ctx, NDBT_Step* step){
720 int result = NDBT_OK;
721 int loops = ctx->getNumLoops();
722 NdbRestarter restarter;
723 int i = 0;
724 int lastId = 0;
725
726 if (restarter.getNumDbNodes() < 2){
727 ctx->stopTest();
728 return NDBT_OK;
729 }
730 while(i<loops && result != NDBT_FAILED){
731 if(restarter.waitClusterStarted(120) != 0){
732 g_err << "Cluster failed to start" << endl;
733 result = NDBT_FAILED;
734 break;
735 }
736 NdbSleep_SecSleep(10);
737
738 int nodeId = restarter.getDbNodeId(lastId);
739 lastId = (lastId + 1) % restarter.getNumDbNodes();
740 if(restarter.insertErrorInNode(nodeId, 9999) != 0){
741 g_err << "Failed to insertErrorInNode="<<nodeId << endl;
742 result = NDBT_FAILED;
743 break;
744 }
745 NdbSleep_SecSleep(10);
746 i++;
747 }
748 if(restarter.waitClusterStarted(120) != 0){
749 g_err << "Cluster failed to start" << endl;
750 result = NDBT_FAILED;
751 }
752
753 ctx->stopTest();
754
755 return result;
756 }
757
758
runCheckGetValue(NDBT_Context * ctx,NDBT_Step * step)759 int runCheckGetValue(NDBT_Context* ctx, NDBT_Step* step){
760 const NdbDictionary::Table* pTab = ctx->getTab();
761 int parallelism = ctx->getProperty("Parallelism", 1);
762 int records = ctx->getNumRecords();
763 int numFailed = 0;
764 AttribList alist;
765 alist.buildAttribList(pTab);
766 UtilTransactions utilTrans(*pTab);
767 for(size_t i = 0; i < alist.attriblist.size(); i++){
768 g_info << (unsigned)i << endl;
769 if(utilTrans.scanReadRecords(GETNDB(step),
770 parallelism,
771 NdbOperation::LM_Read,
772 records,
773 alist.attriblist[i]->numAttribs,
774 alist.attriblist[i]->attribs) != 0){
775 numFailed++;
776 }
777 if(utilTrans.scanReadRecords(GETNDB(step),
778 parallelism,
779 NdbOperation::LM_Read,
780 records,
781 alist.attriblist[i]->numAttribs,
782 alist.attriblist[i]->attribs) != 0){
783 numFailed++;
784 }
785 }
786
787 if(numFailed > 0)
788 return NDBT_FAILED;
789 else
790 return NDBT_OK;
791 }
792
runCloseWithoutStop(NDBT_Context * ctx,NDBT_Step * step)793 int runCloseWithoutStop(NDBT_Context* ctx, NDBT_Step* step){
794 const NdbDictionary::Table* pTab = ctx->getTab();
795 int records = ctx->getNumRecords();
796 int numFailed = 0;
797 ScanFunctions scanF(*pTab);
798 // Iterate over all possible parallelism valuse
799 for (int p = 1; p<240; p++){
800 g_info << p << " CloseWithoutStop openScan" << endl;
801 if (scanF.scanReadFunctions(GETNDB(step),
802 records,
803 p,
804 ScanFunctions::CloseWithoutStop,
805 false) != 0){
806 numFailed++;
807 }
808 g_info << p << " CloseWithoutStop openScanExclusive" << endl;
809 if (scanF.scanReadFunctions(GETNDB(step),
810 records,
811 p,
812 ScanFunctions::CloseWithoutStop,
813 true) != 0){
814 numFailed++;
815 }
816 }
817
818 if(numFailed > 0)
819 return NDBT_FAILED;
820 else
821 return NDBT_OK;
822 }
823
runNextScanWhenNoMore(NDBT_Context * ctx,NDBT_Step * step)824 int runNextScanWhenNoMore(NDBT_Context* ctx, NDBT_Step* step){
825 const NdbDictionary::Table* pTab = ctx->getTab();
826 int records = ctx->getNumRecords();
827 int numFailed = 0;
828 ScanFunctions scanF(*pTab);
829 if (scanF.scanReadFunctions(GETNDB(step),
830 records,
831 6,
832 ScanFunctions::NextScanWhenNoMore,
833 false) != 0){
834 numFailed++;
835 }
836 if (scanF.scanReadFunctions(GETNDB(step),
837 records,
838 6,
839 ScanFunctions::NextScanWhenNoMore,
840 true) != 0){
841 numFailed++;
842 }
843
844
845 if(numFailed > 0)
846 return NDBT_FAILED;
847 else
848 return NDBT_OK;
849 }
850
runEqualAfterOpenScan(NDBT_Context * ctx,NDBT_Step * step)851 int runEqualAfterOpenScan(NDBT_Context* ctx, NDBT_Step* step){
852 const NdbDictionary::Table* pTab = ctx->getTab();
853 int records = ctx->getNumRecords();
854 int numFailed = 0;
855 ScanFunctions scanF(*pTab);
856 if (scanF.scanReadFunctions(GETNDB(step),
857 records,
858 6,
859 ScanFunctions::EqualAfterOpenScan,
860 false) == NDBT_OK){
861 numFailed++;
862 }
863 if (scanF.scanReadFunctions(GETNDB(step),
864 records,
865 6,
866 ScanFunctions::EqualAfterOpenScan,
867 true) == NDBT_OK){
868 numFailed++;
869 }
870
871
872 if(numFailed > 0)
873 return NDBT_FAILED;
874 else
875 return NDBT_OK;
876 }
877
runOnlyOpenScanOnce(NDBT_Context * ctx,NDBT_Step * step)878 int runOnlyOpenScanOnce(NDBT_Context* ctx, NDBT_Step* step){
879 const NdbDictionary::Table* pTab = ctx->getTab();
880 int records = ctx->getNumRecords();
881 int numFailed = 0;
882 ScanFunctions scanF(*pTab);
883 g_info << "OnlyOpenScanOnce openScanRead" << endl;
884 if (scanF.scanReadFunctions(GETNDB(step),
885 records,
886 6,
887 ScanFunctions::OnlyOpenScanOnce,
888 false) == 0){
889 numFailed++;
890 }
891 g_info << "OnlyOpenScanOnce openScanExclusive" << endl;
892 if (scanF.scanReadFunctions(GETNDB(step),
893 records,
894 6,
895 ScanFunctions::OnlyOpenScanOnce,
896 true) == 0){
897 numFailed++;
898 }
899
900
901 if(numFailed > 0)
902 return NDBT_FAILED;
903 else
904 return NDBT_OK;
905 }
906
runOnlyOneOpInScanTrans(NDBT_Context * ctx,NDBT_Step * step)907 int runOnlyOneOpInScanTrans(NDBT_Context* ctx, NDBT_Step* step){
908 return NDBT_OK;
909 }
910
runExecuteScanWithoutOpenScan(NDBT_Context * ctx,NDBT_Step * step)911 int runExecuteScanWithoutOpenScan(NDBT_Context* ctx, NDBT_Step* step){
912 return NDBT_OK;
913 }
914
runOnlyOneOpBeforeOpenScan(NDBT_Context * ctx,NDBT_Step * step)915 int runOnlyOneOpBeforeOpenScan(NDBT_Context* ctx, NDBT_Step* step){
916 return NDBT_OK;
917 }
918
runOnlyOneScanPerTrans(NDBT_Context * ctx,NDBT_Step * step)919 int runOnlyOneScanPerTrans(NDBT_Context* ctx, NDBT_Step* step){
920 return NDBT_OK;
921 }
922
runNoCloseTransaction(NDBT_Context * ctx,NDBT_Step * step)923 int runNoCloseTransaction(NDBT_Context* ctx, NDBT_Step* step){
924 const NdbDictionary::Table* pTab = ctx->getTab();
925 int loops = ctx->getNumLoops();
926 int records = ctx->getNumRecords();
927 int numFailed = 0;
928
929 ScanFunctions scanF(*pTab);
930 int l = 0;
931 while(l < loops){
932 if (scanF.scanReadFunctions(GETNDB(step),
933 records,
934 6,
935 ScanFunctions::NoCloseTransaction,
936 false) != 0){
937 numFailed++;
938 }
939 if (scanF.scanReadFunctions(GETNDB(step),
940 records,
941 6,
942 ScanFunctions::NoCloseTransaction,
943 true) != 0){
944 numFailed++;
945 }
946 l++;
947 }
948
949
950 if(numFailed > 0)
951 return NDBT_FAILED;
952 else
953 return NDBT_OK;
954
955 }
956
runCheckInactivityTimeOut(NDBT_Context * ctx,NDBT_Step * step)957 int runCheckInactivityTimeOut(NDBT_Context* ctx, NDBT_Step* step){
958 const NdbDictionary::Table* pTab = ctx->getTab();
959 int records = ctx->getNumRecords();
960 int numFailed = 0;
961
962 ScanFunctions scanF(*pTab);
963 if (scanF.scanReadFunctions(GETNDB(step),
964 records,
965 1,
966 ScanFunctions::CheckInactivityTimeOut,
967 false) != NDBT_OK){
968 numFailed++;
969 }
970 if (scanF.scanReadFunctions(GETNDB(step),
971 records,
972 240,
973 ScanFunctions::CheckInactivityTimeOut,
974 true) != NDBT_OK){
975 numFailed++;
976 }
977
978 if(numFailed > 0)
979 return NDBT_FAILED;
980 else
981 return NDBT_OK;
982
983 }
984
runCheckInactivityBeforeClose(NDBT_Context * ctx,NDBT_Step * step)985 int runCheckInactivityBeforeClose(NDBT_Context* ctx, NDBT_Step* step){
986 const NdbDictionary::Table* pTab = ctx->getTab();
987 int records = ctx->getNumRecords();
988 int numFailed = 0;
989
990 ScanFunctions scanF(*pTab);
991 if (scanF.scanReadFunctions(GETNDB(step),
992 records,
993 16,
994 ScanFunctions::CheckInactivityBeforeClose,
995 false) != 0){
996 numFailed++;
997 }
998 if (scanF.scanReadFunctions(GETNDB(step),
999 records,
1000 240,
1001 ScanFunctions::CheckInactivityBeforeClose,
1002 true) != 0){
1003 numFailed++;
1004 }
1005
1006 if(numFailed > 0)
1007 return NDBT_FAILED;
1008 else
1009 return NDBT_OK;
1010
1011 }
1012
runScanRestart(NDBT_Context * ctx,NDBT_Step * step)1013 int runScanRestart(NDBT_Context* ctx, NDBT_Step* step){
1014 int loops = ctx->getNumLoops();
1015 int records = ctx->getNumRecords();
1016 Ndb * pNdb = GETNDB(step);
1017 const NdbDictionary::Table* pTab = ctx->getTab();
1018
1019 HugoCalculator calc(* pTab);
1020 NDBT_ResultRow tmpRow(* pTab);
1021
1022 int i = 0;
1023 while (i<loops && !ctx->isTestStopped()) {
1024 g_info << i++ << ": ";
1025 const int record = (rand() % records);
1026 g_info << " row=" << record;
1027
1028 NdbConnection* pCon = pNdb->startTransaction();
1029 NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
1030 if (pOp == NULL) {
1031 ERR(pCon->getNdbError());
1032 return NDBT_FAILED;
1033 }
1034
1035 if( pOp->readTuples() ) {
1036 ERR(pCon->getNdbError());
1037 return NDBT_FAILED;
1038 }
1039
1040 int check = pOp->interpret_exit_ok();
1041 if( check == -1 ) {
1042 ERR(pCon->getNdbError());
1043 return NDBT_FAILED;
1044 }
1045
1046 // Define attributes to read
1047 for(int a = 0; a<pTab->getNoOfColumns(); a++){
1048 if((tmpRow.attributeStore(a) =
1049 pOp->getValue(pTab->getColumn(a)->getName())) == 0) {
1050 ERR(pCon->getNdbError());
1051 return NDBT_FAILED;
1052 }
1053 }
1054
1055 check = pCon->execute(NoCommit);
1056 if( check == -1 ) {
1057 ERR(pCon->getNdbError());
1058 return NDBT_FAILED;
1059 }
1060
1061 int res;
1062 int row = 0;
1063 while(row < record && (res = pOp->nextResult()) == 0) {
1064 if(calc.verifyRowValues(&tmpRow) != 0){
1065 abort();
1066 return NDBT_FAILED;
1067 }
1068 row++;
1069 }
1070 if(row != record){
1071 ERR(pCon->getNdbError());
1072 abort();
1073 return NDBT_FAILED;
1074 }
1075 g_info << " restarting" << endl;
1076 if((res = pOp->restart()) != 0){
1077 ERR(pCon->getNdbError());
1078 abort();
1079 return NDBT_FAILED;
1080 }
1081
1082 row = 0;
1083 while((res = pOp->nextResult()) == 0) {
1084 if(calc.verifyRowValues(&tmpRow) != 0){
1085 abort();
1086 return NDBT_FAILED;
1087 }
1088 row++;
1089 }
1090 if(res != 1 || row != records){
1091 ERR(pCon->getNdbError());
1092 abort();
1093 return NDBT_FAILED;
1094 }
1095 pCon->close();
1096 }
1097 return NDBT_OK;
1098 }
1099
1100
1101 int
runScanParallelism(NDBT_Context * ctx,NDBT_Step * step)1102 runScanParallelism(NDBT_Context* ctx, NDBT_Step* step){
1103 int loops = ctx->getNumLoops() + 3;
1104 int records = ctx->getNumRecords();
1105 int abort = ctx->getProperty("AbortProb", 15);
1106
1107 Uint32 fib[] = { 1, 2 };
1108 Uint32 parallelism = 0; // start with 0
1109 int i = 0;
1110 HugoTransactions hugoTrans(*ctx->getTab());
1111 while (i<loops && !ctx->isTestStopped()) {
1112 g_info << i << ": ";
1113
1114 if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism,
1115 NdbOperation::LM_Read) != 0){
1116 return NDBT_FAILED;
1117 }
1118 if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism,
1119 NdbOperation::LM_Exclusive) != 0){
1120 return NDBT_FAILED;
1121 }
1122 if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism,
1123 NdbOperation::LM_CommittedRead) != 0){
1124 return NDBT_FAILED;
1125 }
1126 if (hugoTrans.scanUpdateRecords(GETNDB(step), records, abort, parallelism)
1127 != 0){
1128 return NDBT_FAILED;
1129 }
1130 i++;
1131 parallelism = fib[0];
1132 Uint32 next = fib[0] + fib[1];
1133 fib[0] = fib[1];
1134 fib[1] = next;
1135 }
1136 return NDBT_OK;
1137 }
1138
1139 int
runScanVariants(NDBT_Context * ctx,NDBT_Step * step)1140 runScanVariants(NDBT_Context* ctx, NDBT_Step* step)
1141 {
1142 int loops = ctx->getNumLoops();
1143 int records = ctx->getNumRecords();
1144 Ndb * pNdb = GETNDB(step);
1145 const NdbDictionary::Table* pTab = ctx->getTab();
1146
1147 HugoCalculator calc(* pTab);
1148 NDBT_ResultRow tmpRow(* pTab);
1149
1150 for(int lm = 0; lm <= NdbOperation::LM_CommittedRead; lm++)
1151 {
1152 for(int flags = 0; flags < 4; flags++)
1153 {
1154 for (int batch = 0; batch < 100; batch += (1 + batch + (batch >> 3)))
1155 {
1156 for (int par = 0; par < 16; par += 1 + (rand() % 3))
1157 {
1158 bool disk = flags & 1;
1159 bool tups = flags & 2;
1160 g_info << "lm: " << lm
1161 << " disk: " << disk
1162 << " tup scan: " << tups
1163 << " par: " << par
1164 << " batch: " << batch
1165 << endl;
1166
1167 NdbConnection* pCon = pNdb->startTransaction();
1168 NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
1169 if (pOp == NULL) {
1170 ERR(pCon->getNdbError());
1171 return NDBT_FAILED;
1172 }
1173
1174 if( pOp->readTuples((NdbOperation::LockMode)lm,
1175 tups ? NdbScanOperation::SF_TupScan : 0,
1176 par,
1177 batch) != 0)
1178 {
1179 ERR(pCon->getNdbError());
1180 return NDBT_FAILED;
1181 }
1182
1183 int check = pOp->interpret_exit_ok();
1184 if( check == -1 ) {
1185 ERR(pCon->getNdbError());
1186 return NDBT_FAILED;
1187 }
1188
1189 // Define attributes to read
1190 bool found_disk = false;
1191 for(int a = 0; a<pTab->getNoOfColumns(); a++){
1192 if (pTab->getColumn(a)->getStorageType() ==
1193 NdbDictionary::Column::StorageTypeDisk)
1194 {
1195 found_disk = true;
1196 if (!disk)
1197 continue;
1198 }
1199
1200 if((pOp->getValue(pTab->getColumn(a)->getName())) == 0) {
1201 ERR(pCon->getNdbError());
1202 return NDBT_FAILED;
1203 }
1204 }
1205
1206 if (! (disk && !found_disk))
1207 {
1208 check = pCon->execute(NoCommit);
1209 if( check == -1 ) {
1210 ERR(pCon->getNdbError());
1211 return NDBT_FAILED;
1212 }
1213
1214 int res;
1215 int row = 0;
1216 while((res = pOp->nextResult()) == 0);
1217 }
1218 pCon->close();
1219 }
1220 }
1221 }
1222 }
1223 return NDBT_OK;
1224 }
1225
1226 int
runBug24447(NDBT_Context * ctx,NDBT_Step * step)1227 runBug24447(NDBT_Context* ctx, NDBT_Step* step){
1228 int loops = 1; //ctx->getNumLoops();
1229 int records = ctx->getNumRecords();
1230 int abort = ctx->getProperty("AbortProb", 15);
1231 NdbRestarter restarter;
1232 HugoTransactions hugoTrans(*ctx->getTab());
1233 int i = 0;
1234 while (i<loops && !ctx->isTestStopped())
1235 {
1236 g_info << i++ << ": ";
1237
1238 int nodeId = restarter.getRandomNotMasterNodeId(rand());
1239 if (nodeId == -1)
1240 nodeId = restarter.getMasterNodeId();
1241 if (restarter.insertErrorInNode(nodeId, 8038) != 0)
1242 {
1243 ndbout << "Could not insert error in node="<<nodeId<<endl;
1244 return NDBT_FAILED;
1245 }
1246
1247 for (Uint32 j = 0; i<10; i++)
1248 {
1249 hugoTrans.scanReadRecords(GETNDB(step), records, abort, 0,
1250 NdbOperation::LM_CommittedRead);
1251 }
1252
1253 }
1254 restarter.insertErrorInAllNodes(0);
1255
1256 return NDBT_OK;
1257 }
1258
1259 NDBT_TESTSUITE(testScan);
1260 TESTCASE("ScanRead",
1261 "Verify scan requirement: It should be possible "\
1262 "to read all records in a table without knowing their "\
1263 "primary key."){
1264 INITIALIZER(runLoadTable);
1265 TC_PROPERTY("Parallelism", 1);
1266 STEP(runScanRead);
1267 FINALIZER(runClearTable);
1268 }
1269 TESTCASE("ScanRead16",
1270 "Verify scan requirement: It should be possible to scan read "\
1271 "with parallelism, test with parallelism 16"){
1272 INITIALIZER(runLoadTable);
1273 TC_PROPERTY("Parallelism", 16);
1274 STEP(runScanRead);
1275 FINALIZER(runClearTable);
1276 }
1277 TESTCASE("ScanRead240",
1278 "Verify scan requirement: It should be possible to scan read with "\
1279 "parallelism, test with parallelism 240(240 would automatically be "\
1280 "downgraded to the maximum parallelism value for the current config)"){
1281 INITIALIZER(runLoadTable);
1282 TC_PROPERTY("Parallelism", 240);
1283 STEP(runScanRead);
1284 FINALIZER(runClearTable);
1285 }
1286 TESTCASE("ScanReadCommitted240",
1287 "Verify scan requirement: It should be possible to scan read committed with "\
1288 "parallelism, test with parallelism 240(240 would automatically be "\
1289 "downgraded to the maximum parallelism value for the current config)"){
1290 INITIALIZER(runLoadTable);
1291 TC_PROPERTY("Parallelism", 240);
1292 TC_PROPERTY("TupScan", (Uint32)0);
1293 STEP(runScanReadCommitted);
1294 FINALIZER(runClearTable);
1295 }
1296 TESTCASE("ScanUpdate",
1297 "Verify scan requirement: It should be possible "\
1298 "to update all records in a table without knowing their"\
1299 " primary key."){
1300 INITIALIZER(runLoadTable);
1301 STEP(runScanUpdate);
1302 FINALIZER(runClearTable);
1303 }
1304 TESTCASE("ScanUpdate2",
1305 "Verify scan requirement: It should be possible "\
1306 "to update all records in a table without knowing their"\
1307 " primary key. Do this efficently by calling nextScanResult(false) "\
1308 "in order to update the records already fetched to the api in one batch."){
1309 INITIALIZER(runLoadTable);
1310 TC_PROPERTY("Parallelism", 240);
1311 STEP(runScanUpdate2);
1312 FINALIZER(runClearTable);
1313 }
1314 TESTCASE("ScanDelete",
1315 "Verify scan requirement: It should be possible "\
1316 "to delete all records in a table without knowing their"\
1317 " primary key."){
1318 INITIALIZER(runLoadTable);
1319 STEP(runScanDelete);
1320 FINALIZER(runClearTable);
1321 }
1322 TESTCASE("ScanDelete2",
1323 "Verify scan requirement: It should be possible "\
1324 "to delete all records in a table without knowing their"\
1325 " primary key. Do this efficently by calling nextScanResult(false) "\
1326 "in order to delete the records already fetched to the api in one batch."){
1327 INITIALIZER(runLoadTable);
1328 TC_PROPERTY("Parallelism", 240);
1329 STEP(runScanDelete2);
1330 FINALIZER(runClearTable);
1331 }
1332 TESTCASE("ScanUpdateAndScanRead",
1333 "Verify scan requirement: It should be possible to run "\
1334 "scan read and scan update at the same time"){
1335 INITIALIZER(runLoadTable);
1336 TC_PROPERTY("Parallelism", 16);
1337 STEP(runScanRead);
1338 STEP(runScanUpdate);
1339 FINALIZER(runClearTable);
1340 }
1341 TESTCASE("ScanReadAndLocker",
1342 "Verify scan requirement: The locks are not kept throughout "\
1343 "the entire scan operation. This means that a scan does not "\
1344 "lock the entire table, only the records it's currently "\
1345 "operating on. This will test how scan performs when there are "\
1346 " a number of 1 second locks in the table"){
1347 INITIALIZER(runLoadTable);
1348 STEP(runScanReadUntilStopped);
1349 STEP(runLocker);
1350 FINALIZER(runClearTable);
1351 }
1352 TESTCASE("ScanReadAndPkRead",
1353 "Verify scan requirement: The locks are not kept throughout "\
1354 "the entire scan operation. This means that a scan does not "\
1355 "lock the entire table, only the records it's currently "\
1356 "operating on. This will test how scan performs when there are "\
1357 " a pk reads "){
1358 INITIALIZER(runLoadTable);
1359 STEPS(runScanRead, 2);
1360 STEPS(runPkRead, 2);
1361 FINALIZER(runClearTable);
1362 }
1363 TESTCASE("ScanRead488",
1364 "Verify scan requirement: It's only possible to have 11 concurrent "\
1365 "scans per fragment running in Ndb kernel at the same time. "\
1366 "When this limit is exceeded the scan will be aborted with errorcode "\
1367 "488."){
1368 INITIALIZER(runLoadTable);
1369 STEPS(runRandScanRead, 70);
1370 FINALIZER(runClearTable);
1371 }
1372 TESTCASE("ScanRead488T",
1373 "Verify scan requirement: It's only possible to have 11 concurrent "\
1374 "scans per fragment running in Ndb kernel at the same time. "\
1375 "When this limit is exceeded the scan will be aborted with errorcode "\
1376 "488."){
1377 TC_PROPERTY("TupScan", 1);
1378 INITIALIZER(runLoadTable);
1379 STEPS(runRandScanRead, 70);
1380 FINALIZER(runClearTable);
1381 }
1382 TESTCASE("ScanRead488O",
1383 "Verify scan requirement: It's only possible to have 11 concurrent "\
1384 "scans per fragment running in Ndb kernel at the same time. "\
1385 "When this limit is exceeded the scan will be aborted with errorcode "\
1386 "488."){
1387 INITIALIZER(createOrderedPkIndex);
1388 INITIALIZER(runLoadTable);
1389 STEPS(runScanReadIndex, 70);
1390 FINALIZER(createOrderedPkIndex_Drop);
1391 FINALIZER(runClearTable);
1392 }
1393 TESTCASE("ScanRead488_Mixed",
1394 "Verify scan requirement: It's only possible to have 11 concurrent "\
1395 "scans per fragment running in Ndb kernel at the same time. "\
1396 "When this limit is exceeded the scan will be aborted with errorcode "\
1397 "488."){
1398 TC_PROPERTY("TupScan", 2);
1399 INITIALIZER(createOrderedPkIndex);
1400 INITIALIZER(runLoadTable);
1401 STEPS(runRandScanRead, 50);
1402 STEPS(runScanReadIndex, 50);
1403 FINALIZER(createOrderedPkIndex_Drop);
1404 FINALIZER(runClearTable);
1405 }
1406 TESTCASE("ScanRead488Timeout",
1407 ""){
1408 INITIALIZER(runLoadTable);
1409 TC_PROPERTY("ErrorCode", 5034);
1410 STEPS(runScanRead, 30);
1411 STEP(runScanReadError);
1412 FINALIZER(runClearTable);
1413 }
1414 TESTCASE("ScanRead40",
1415 "Verify scan requirement: Scan with 40 simultaneous threads"){
1416 INITIALIZER(runLoadTable);
1417 STEPS(runScanRead, 40);
1418 FINALIZER(runClearTable);
1419 }
1420 TESTCASE("ScanRead100",
1421 "Verify scan requirement: Scan with 100 simultaneous threads"){
1422 INITIALIZER(runLoadTable);
1423 STEPS(runScanRead, 100);
1424 FINALIZER(runClearTable);
1425 }
1426 TESTCASE("Scan-bug8262",
1427 ""){
1428 TC_PROPERTY("Rows", 1);
1429 TC_PROPERTY("ErrorCode", 8035);
1430 INITIALIZER(runLoadTable);
1431 INITIALIZER(runInsertError); // Will reset error code
1432 STEPS(runScanRead, 25);
1433 FINALIZER(runInsertError);
1434 FINALIZER(runClearTable);
1435 }
1436 TESTCASE("ScanRead40RandomTable",
1437 "Verify scan requirement: Scan with 40 simultaneous threads. "\
1438 "Use random table for the scan"){
1439 INITIALIZER(runCreateAllTables);
1440 INITIALIZER(runLoadAllTables);
1441 STEPS(runScanReadRandomTable, 40);
1442 FINALIZER(runDropAllTablesExceptTestTable);
1443 }
1444 TESTCASE("ScanRead100RandomTable",
1445 "Verify scan requirement: Scan with 100 simultaneous threads. "\
1446 "Use random table for the scan"){
1447 INITIALIZER(runCreateAllTables);
1448 INITIALIZER(runLoadAllTables);
1449 STEPS(runScanReadRandomTable, 100);
1450 FINALIZER(runDropAllTablesExceptTestTable);
1451 }
1452 TESTCASE("ScanReadRandomPrepare",
1453 "Create and load tables for ScanRead40RandomNoTableCreate."){
1454 INITIALIZER(runCreateAllTables);
1455 INITIALIZER(runLoadAllTables);
1456 }
1457 TESTCASE("ScanRead40RandomNoTableCreate",
1458 "Verify scan requirement: Scan with 40 simultaneous threads. "\
1459 "Use random table for the scan. Dont create or load the tables."){
1460 STEPS(runScanReadRandomTable, 40);
1461 }
1462 TESTCASE("ScanRead100RandomNoTableCreate",
1463 "Verify scan requirement: Scan with 100 simultaneous threads. "\
1464 "Use random table for the scan. Dont create or load the tables."){
1465 STEPS(runScanReadRandomTable, 100);
1466 }
1467 TESTCASE("ScanWithLocksAndInserts",
1468 "TR457: This test is added to verify that an insert of a records "\
1469 "that is already in the database does not delete the record"){
1470 INITIALIZER(runLoadTable);
1471 STEPS(runScanReadUntilStopped, 2);
1472 STEP(runLocker);
1473 STEP(runInsertUntilStopped);
1474 FINALIZER(runClearTable);
1475 }
1476 TESTCASE("ScanReadAbort",
1477 "Scan requirement: A scan may be aborted by the application "\
1478 "at any time. This can be performed even if there are more "\
1479 "tuples to scan."){
1480 INITIALIZER(runLoadTable);
1481 TC_PROPERTY("AbortProb", 90);
1482 STEPS(runScanRead, 3);
1483 FINALIZER(runClearTable);
1484 }
1485 TESTCASE("ScanReadAbort15",
1486 "Scan requirement: A scan may be aborted by the application "\
1487 "at any time. This can be performed even if there are more "\
1488 "tuples to scan. Use parallelism 15"){
1489 INITIALIZER(runLoadTable);
1490 TC_PROPERTY("Parallelism", 15);
1491 TC_PROPERTY("AbortProb", 90);
1492 STEPS(runScanRead, 3);
1493 FINALIZER(runClearTable);
1494 }
1495 TESTCASE("ScanReadAbort240",
1496 "Scan requirement: A scan may be aborted by the application "\
1497 "at any time. This can be performed even if there are more "\
1498 "tuples to scan. Use parallelism 240(it will be downgraded to max para for this config)"){
1499 INITIALIZER(runLoadTable);
1500 TC_PROPERTY("Parallelism", 240);
1501 TC_PROPERTY("AbortProb", 90);
1502 STEPS(runScanRead, 3);
1503 FINALIZER(runClearTable);
1504 }
1505 TESTCASE("ScanUpdateAbort16",
1506 "Scan requirement: A scan may be aborted by the application "\
1507 "at any time. This can be performed even if there are more "\
1508 "tuples to scan. Use parallelism 16"){
1509 INITIALIZER(runLoadTable);
1510 TC_PROPERTY("Parallelism", 16);
1511 TC_PROPERTY("AbortProb", 90);
1512 STEPS(runScanUpdate, 3);
1513 FINALIZER(runClearTable);
1514 }
1515 TESTCASE("ScanUpdateAbort240",
1516 "Scan requirement: A scan may be aborted by the application "\
1517 "at any time. This can be performed even if there are more "\
1518 "tuples to scan. Use parallelism 240(it will be downgraded to max para for this config)"){
1519 INITIALIZER(runLoadTable);
1520 TC_PROPERTY("Parallelism", 240);
1521 TC_PROPERTY("AbortProb", 90);
1522 STEPS(runScanUpdate, 3);
1523 FINALIZER(runClearTable);
1524 }
1525 TESTCASE("CheckGetValue",
1526 "Check that we can call getValue to read attributes"\
1527 "Especially interesting to see if we can read only the"\
1528 " first, last or any two attributes from the table"){
1529 INITIALIZER(runLoadTable);
1530 STEP(runCheckGetValue);
1531 VERIFIER(runScanRead);
1532 FINALIZER(runClearTable);
1533 }
1534 TESTCASE("CloseWithoutStop",
1535 "Check that we can close the scanning transaction without calling "\
1536 "stopScan"){
1537 INITIALIZER(runLoadTable);
1538 STEP(runCloseWithoutStop);
1539 VERIFIER(runScanRead);
1540 FINALIZER(runClearTable);
1541 }
1542 TESTCASE("NextScanWhenNoMore",
1543 "Check that we can call nextScanResult when there are no more "\
1544 "records, and that it returns a valid value"){
1545 INITIALIZER(runLoadTable);
1546 STEP(runNextScanWhenNoMore);
1547 VERIFIER(runScanRead);
1548 FINALIZER(runClearTable);
1549 }
1550 TESTCASE("EqualAfterOpenScan",
1551 "Check that we can't call equal after openScan"){
1552 STEP(runEqualAfterOpenScan);
1553 }
1554 TESTCASE("ExecuteScanWithoutOpenScan",
1555 "Check that we can't call executeScan without defining a scan "\
1556 "with openScan"){
1557 INITIALIZER(runLoadTable);
1558 STEP(runExecuteScanWithoutOpenScan);
1559 VERIFIER(runScanRead);
1560 FINALIZER(runClearTable);
1561 }
1562 TESTCASE("OnlyOpenScanOnce",
1563 "Check that we may only call openScan once in the same trans"){
1564 INITIALIZER(runLoadTable);
1565 STEP(runOnlyOpenScanOnce);
1566 VERIFIER(runScanRead);
1567 FINALIZER(runClearTable);
1568 }
1569 TESTCASE("OnlyOneOpInScanTrans",
1570 "Check that we can have only one operation in a scan trans"){
1571 INITIALIZER(runLoadTable);
1572 STEP(runOnlyOneOpInScanTrans);
1573 VERIFIER(runScanRead);
1574 FINALIZER(runClearTable);
1575 }
1576 TESTCASE("OnlyOneOpBeforeOpenScan",
1577 "Check that we can have only one operation in a trans defined "\
1578 "when calling openScan "){
1579 INITIALIZER(runLoadTable);
1580 STEP(runOnlyOneOpBeforeOpenScan);
1581 VERIFIER(runScanRead);
1582 FINALIZER(runClearTable);
1583 }
1584 TESTCASE("OnlyOneScanPerTrans",
1585 "Check that we can have only one scan operation in a trans"){
1586 INITIALIZER(runLoadTable);
1587 STEP(runOnlyOneScanPerTrans);
1588 VERIFIER(runScanRead);
1589 FINALIZER(runClearTable);
1590 }
1591 TESTCASE("NoCloseTransaction",
1592 "Check behaviour when close transaction is not called "){
1593 INITIALIZER(runLoadTable);
1594 STEP(runNoCloseTransaction);
1595 VERIFIER(runScanRead);
1596 FINALIZER(runClearTable);
1597 }
1598 TESTCASE("CheckInactivityTimeOut",
1599 "Check behaviour when the api sleeps for a long time before continuing scan "){
1600 INITIALIZER(runLoadTable);
1601 STEP(runCheckInactivityTimeOut);
1602 VERIFIER(runScanRead);
1603 FINALIZER(runClearTable);
1604 }
1605 TESTCASE("CheckInactivityBeforeClose",
1606 "Check behaviour when the api sleeps for a long time before calling close scan "){
1607 INITIALIZER(runLoadTable);
1608 STEP(runCheckInactivityBeforeClose);
1609 VERIFIER(runScanRead);
1610 FINALIZER(runClearTable);
1611 }
1612 TESTCASE("ScanReadError5021",
1613 "Scan and insert error 5021, one node is expected to crash"){
1614 INITIALIZER(runLoadTable);
1615 TC_PROPERTY("ErrorCode", 5021);
1616 STEP(runScanReadErrorOneNode);
1617 FINALIZER(runClearTable);
1618 }
1619 TESTCASE("ScanReadError5022",
1620 "Scan and insert error 5022, one node is expected to crash"){
1621 INITIALIZER(runLoadTable);
1622 TC_PROPERTY("ErrorCode", 5022);
1623 TC_PROPERTY("NodeNumber", 2);
1624 STEP(runScanReadErrorOneNode);
1625 FINALIZER(runClearTable);
1626 }
1627 TESTCASE("ScanReadError5023",
1628 "Scan and insert error 5023"){
1629 INITIALIZER(runLoadTable);
1630 TC_PROPERTY("ErrorCode", 5023);
1631 STEP(runScanReadError);
1632 FINALIZER(runClearTable);
1633 }
1634 TESTCASE("ScanReadError5024",
1635 "Scan and insert error 5024"){
1636 INITIALIZER(runLoadTable);
1637 TC_PROPERTY("ErrorCode", 5024);
1638 STEP(runScanReadError);
1639 FINALIZER(runClearTable);
1640 }
1641 TESTCASE("ScanReadError5025",
1642 "Scan and insert error 5025"){
1643 INITIALIZER(runLoadTable);
1644 TC_PROPERTY("ErrorCode", 5025);
1645 STEP(runScanReadError);
1646 FINALIZER(runClearTable);
1647 }
1648 TESTCASE("ScanReadError5030",
1649 "Scan and insert error 5030."\
1650 "Drop all SCAN_NEXTREQ signals in LQH until the node is "\
1651 "shutdown with SYSTEM_ERROR because of scan fragment timeout"){
1652 INITIALIZER(runLoadTable);
1653 TC_PROPERTY("ErrorCode", 5030);
1654 STEP(runScanReadErrorOneNode);
1655 FINALIZER(runClearTable);
1656 }
1657 TESTCASE("ScanReadRestart",
1658 "Scan requirement:A scan should be able to start and "\
1659 "complete during node recovery and when one or more nodes "\
1660 "in the cluster is down.Use random parallelism "){
1661 INITIALIZER(runLoadTable);
1662 TC_PROPERTY("Parallelism", RANDOM_PARALLELISM); // Random
1663 STEP(runScanReadUntilStopped);
1664 STEP(runRestarter);
1665 FINALIZER(runClearTable);
1666 }
1667 TESTCASE("ScanUpdateRestart",
1668 "Scan requirement:A scan should be able to start and "\
1669 "complete during node recovery and when one or more nodes "\
1670 "in the cluster is down. Use random parallelism"){
1671 INITIALIZER(runLoadTable);
1672 TC_PROPERTY("Parallelism", RANDOM_PARALLELISM); // Random
1673 STEP(runScanUpdateUntilStopped);
1674 STEP(runRestarter);
1675 FINALIZER(runClearTable);
1676 }
1677 #if 0
1678 TESTCASE("ScanReadRestart9999",
1679 "Scan requirement:A scan should be able to start and "\
1680 "complete during node recovery and when one or more nodes "\
1681 "in the cluster is down. Use parallelism 240."\
1682 "Restart using error insert 9999"){
1683 INITIALIZER(runLoadTable);
1684 TC_PROPERTY("Parallelism", 240);
1685 STEP(runScanReadUntilStopped);
1686 STEP(runRestarter9999);
1687 FINALIZER(runClearTable);
1688 }
1689 TESTCASE("ScanUpdateRestart9999",
1690 "Scan requirement:A scan should be able to start and "\
1691 "complete during node recovery and when one or more nodes "\
1692 "in the cluster is down. Use parallelism 240."\
1693 "Restart using error insert 9999"){
1694 INITIALIZER(runLoadTable);
1695 TC_PROPERTY("Parallelism", 240);
1696 STEP(runScanReadUntilStopped);
1697 STEP(runScanUpdateUntilStopped);
1698 STEP(runRestarter9999);
1699 FINALIZER(runClearTable);
1700 }
1701 #endif
1702 TESTCASE("InsertDelete",
1703 "Load and delete all while scan updating and scan reading\n"\
1704 "Alexander Lukas special"){
1705 INITIALIZER(runClearTable);
1706 STEP(runScanReadUntilStoppedNoCount);
1707 STEP(runScanUpdateUntilStopped);
1708 STEP(runInsertDelete);
1709 FINALIZER(runClearTable);
1710 }
1711 TESTCASE("CheckAfterTerror",
1712 "Check that we can still scan read after this terror of NdbApi"){
1713 INITIALIZER(runLoadTable);
1714 STEPS(runScanRead, 5);
1715 FINALIZER(runClearTable);
1716 }
1717 TESTCASE("ScanReadWhileNodeIsDown",
1718 "Scan requirement:A scan should be able to run as fast when "\
1719 "one or more nodes in the cluster is down."){
1720 INITIALIZER(runLoadTable);
1721 STEP(runScanReadUntilStoppedPrintTime);
1722 STEP(runStopAndStartNode);
1723 FINALIZER(runClearTable);
1724 }
1725 TESTCASE("ScanRestart",
1726 "Verify restart functionallity"){
1727 INITIALIZER(runLoadTable);
1728 STEP(runScanRestart);
1729 FINALIZER(runClearTable);
1730 }
1731 TESTCASE("ScanParallelism",
1732 "Test scan with different parallelism"){
1733 INITIALIZER(runLoadTable);
1734 STEP(runScanParallelism);
1735 FINALIZER(runClearTable);
1736 }
1737 TESTCASE("ScanVariants",
1738 "Test different scan variants"){
1739 INITIALIZER(runLoadTable);
1740 STEP(runScanVariants);
1741 FINALIZER(runClearTable);
1742 }
1743 TESTCASE("Bug24447",
1744 ""){
1745 INITIALIZER(runLoadTable);
1746 STEP(runBug24447);
1747 FINALIZER(runClearTable);
1748 }
1749 NDBT_TESTSUITE_END(testScan);
1750
main(int argc,const char ** argv)1751 int main(int argc, const char** argv){
1752 ndb_init();
1753 myRandom48Init(NdbTick_CurrentMillisecond());
1754 return testScan.execute(argc, argv);
1755 }
1756
1757 template class Vector<Attrib*>;
1758