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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16
#include <NDBT_Test.hpp>
17
#include <NDBT_ReturnCodes.h>
18
#include <HugoTransactions.hpp>
19
#include <UtilTransactions.hpp>
20
#include <NdbRestarter.hpp>
22
#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
27
* dirtyWrite, write, dirtyUpdate
28
* delete should be visible to same transaction
31
int runLoadTable2(NDBT_Context* ctx, NDBT_Step* step)
33
int records = ctx->getNumRecords();
34
HugoTransactions hugoTrans(*ctx->getTab());
35
if (hugoTrans.loadTable(GETNDB(step), records, 512, false, 0, true) != 0){
41
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step)
43
int records = ctx->getNumRecords();
44
HugoTransactions hugoTrans(*ctx->getTab());
45
if (hugoTrans.loadTable(GETNDB(step), records) != 0){
51
int runInsert(NDBT_Context* ctx, NDBT_Step* step){
53
int records = ctx->getNumRecords();
54
HugoTransactions hugoTrans(*ctx->getTab());
55
// Insert records, dont allow any
56
// errors(except temporary) while inserting
57
if (hugoTrans.loadTable(GETNDB(step), records, 1, false) != 0){
63
int runInsertTwice(NDBT_Context* ctx, NDBT_Step* step){
65
int records = ctx->getNumRecords();
66
HugoTransactions hugoTrans(*ctx->getTab());
67
// Insert records, expect primary key violation 630
68
if (hugoTrans.loadTable(GETNDB(step), records, 1, false) != 630){
74
int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
75
int records = ctx->getNumRecords();
77
HugoTransactions hugoTrans(*ctx->getTab());
78
if (hugoTrans.pkDelRecords(GETNDB(step), records, 1, false) != 0){
84
int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
85
int records = ctx->getNumRecords();
87
HugoTransactions hugoTrans(*ctx->getTab());
88
while (ctx->isTestStopped() == false) {
90
if (hugoTrans.loadTable(GETNDB(step), records) != 0){
100
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
101
int records = ctx->getNumRecords();
102
int batchSize = ctx->getProperty("BatchSize", 1);
104
HugoTransactions hugoTrans(*ctx->getTab());
105
if (hugoTrans.pkDelRecords(GETNDB(step), records, batchSize) != 0){
111
int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
112
int loops = ctx->getNumLoops();
113
int records = ctx->getNumRecords();
116
HugoTransactions hugoTrans(*ctx->getTab());
119
if (hugoTrans.pkDelRecords(GETNDB(step), records) != 0){
123
// Load table, don't allow any primary key violations
124
if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
135
int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
136
int loops = ctx->getNumLoops();
137
int records = ctx->getNumRecords();
138
int batchSize = ctx->getProperty("BatchSize", 1);
139
int lm = ctx->getProperty("LockMode", NdbOperation::LM_Read);
141
HugoTransactions hugoTrans(*ctx->getTab());
144
if (hugoTrans.pkReadRecords(GETNDB(step), records, batchSize,
145
(NdbOperation::LockMode)lm) != NDBT_OK){
155
int runPkReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
156
int records = ctx->getNumRecords();
157
int batchSize = ctx->getProperty("BatchSize", 1);
159
HugoTransactions hugoTrans(*ctx->getTab());
160
while (ctx->isTestStopped() == false) {
162
if (hugoTrans.pkReadRecords(GETNDB(step), records, batchSize) != 0){
172
int runPkUpdate(NDBT_Context* ctx, NDBT_Step* step){
173
int loops = ctx->getNumLoops();
174
int records = ctx->getNumRecords();
175
int batchSize = ctx->getProperty("BatchSize", 1);
177
HugoTransactions hugoTrans(*ctx->getTab());
179
g_info << "|- " << i << ": ";
180
if (hugoTrans.pkUpdateRecords(GETNDB(step), records, batchSize) != 0){
190
int runPkUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
191
int records = ctx->getNumRecords();
192
int batchSize = ctx->getProperty("BatchSize", 1);
194
HugoTransactions hugoTrans(*ctx->getTab());
195
while (ctx->isTestStopped()) {
197
if (hugoTrans.pkUpdateRecords(GETNDB(step), records, batchSize) != 0){
207
int runLocker(NDBT_Context* ctx, NDBT_Step* step){
208
int result = NDBT_OK;
209
int records = ctx->getNumRecords();
210
HugoTransactions hugoTrans(*ctx->getTab());
212
if (hugoTrans.lockRecords(GETNDB(step), records, 10, 500) != 0){
213
result = NDBT_FAILED;
221
runInsertOne(NDBT_Context* ctx, NDBT_Step* step){
223
if(ctx->getProperty("InsertCommitted", (Uint32)0) != 0){
227
while(ctx->getProperty("Read1Performed", (Uint32)0) == 0){
228
NdbSleep_MilliSleep(20);
231
HugoTransactions hugoTrans(*ctx->getTab());
233
if (hugoTrans.loadTable(GETNDB(step), 1, 1) != 0){
237
ctx->setProperty("InsertCommitted", 1);
239
NdbSleep_SecSleep(2);
246
readOneNoCommit(Ndb* pNdb, NdbConnection* pTrans,
247
const NdbDictionary::Table* tab,NDBT_ResultRow * row){
249
NdbOperation * pOp = pTrans->getNdbOperation(tab->getName());
251
ERR(pTrans->getNdbError());
255
HugoTransactions tmp(*tab);
257
int check = pOp->readTuple();
259
ERR(pTrans->getNdbError());
263
// Define primary keys
264
for(a = 0; a<tab->getNoOfColumns(); a++){
265
if (tab->getColumn(a)->getPrimaryKey() == true){
266
if(tmp.equalForAttr(pOp, a, 0) != 0){
267
ERR(pTrans->getNdbError());
273
// Define attributes to read
274
for(a = 0; a<tab->getNoOfColumns(); a++){
275
if((row->attributeStore(a) =
276
pOp->getValue(tab->getColumn(a)->getName())) == 0) {
277
ERR(pTrans->getNdbError());
282
check = pTrans->execute(NoCommit);
284
const NdbError err = pTrans->getNdbError();
292
runReadOne(NDBT_Context* ctx, NDBT_Step* step){
294
Ndb* pNdb = GETNDB(step);
295
const NdbDictionary::Table* tab = ctx->getTab();
296
NDBT_ResultRow row1(*tab);
297
NDBT_ResultRow row2(*tab);
299
if(ctx->getProperty("Read1Performed", (Uint32)0) != 0){
303
if(ctx->getProperty("InsertCommitted", (Uint32)0) != 0){
307
NdbConnection * pTrans = pNdb->startTransaction();
308
if (pTrans == NULL) {
312
// Read a record with NoCommit
313
// Since the record isn't inserted yet it wil return 626
314
const int res1 = readOneNoCommit(pNdb, pTrans, tab, &row1);
315
g_info << "|- res1 = " << res1 << endl;
317
ctx->setProperty("Read1Performed", 1);
319
while(ctx->getProperty("InsertCommitted", (Uint32)0) == 0 &&
320
!ctx->isTestStopped()){
321
g_info << "|- Waiting for insert" << endl;
322
NdbSleep_MilliSleep(20);
325
if(ctx->isTestStopped()){
329
// Now the record should have been inserted
330
// Read it once again in the same transaction
331
// Should also reutrn 626 if reads are consistent
333
// NOTE! Currently it's not possible to start a new operation
334
// on a transaction that has returned an error code
335
// This is wat fail in this test
337
const int res2 = readOneNoCommit(pNdb, pTrans, tab, &row2);
339
pTrans->execute(Commit);
340
pNdb->closeTransaction(pTrans);
341
g_info << "|- res2 = " << res2 << endl;
343
if (res2 == 626 && res1 == res2)
349
int runFillTable(NDBT_Context* ctx, NDBT_Step* step){
350
int batch = 512; //4096;
351
HugoTransactions hugoTrans(*ctx->getTab());
352
if (hugoTrans.fillTable(GETNDB(step), batch ) != 0){
358
int runClearTable2(NDBT_Context* ctx, NDBT_Step* step){
359
int records = ctx->getNumRecords();
361
UtilTransactions utilTrans(*ctx->getTab());
362
if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
368
#define CHECK(b) if (!(b)) { \
369
ndbout << "ERR: "<< step->getName() \
370
<< " failed on line " << __LINE__ << endl; \
371
result = NDBT_FAILED; \
374
int runNoCommitSleep(NDBT_Context* ctx, NDBT_Step* step){
375
int result = NDBT_OK;
376
HugoOperations hugoOps(*ctx->getTab());
377
Ndb* pNdb = GETNDB(step);
378
int sleepTime = 100; // ms
379
for (int i = 2; i < 8; i++){
381
CHECK(hugoOps.startTransaction(pNdb) == 0);
382
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
383
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
385
ndbout << i <<": Sleeping for " << sleepTime << " ms" << endl;
386
NdbSleep_MilliSleep(sleepTime);
388
// Dont care about result of these ops
389
hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive);
390
hugoOps.closeTransaction(pNdb);
392
sleepTime = sleepTime *i;
395
hugoOps.closeTransaction(pNdb);
400
int runCommit626(NDBT_Context* ctx, NDBT_Step* step){
401
int result = NDBT_OK;
402
HugoOperations hugoOps(*ctx->getTab());
403
Ndb* pNdb = GETNDB(step);
406
// Commit transaction
407
CHECK(hugoOps.startTransaction(pNdb) == 0);
408
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
409
CHECK(hugoOps.execute_Commit(pNdb) == 626);
410
CHECK(hugoOps.closeTransaction(pNdb) == 0);
412
// Commit transaction
413
// Multiple operations
414
CHECK(hugoOps.startTransaction(pNdb) == 0);
415
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
416
CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
417
CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
418
CHECK(hugoOps.execute_Commit(pNdb) == 626);
421
hugoOps.closeTransaction(pNdb);
426
int runCommit630(NDBT_Context* ctx, NDBT_Step* step){
427
int result = NDBT_OK;
428
HugoOperations hugoOps(*ctx->getTab());
429
Ndb* pNdb = GETNDB(step);
432
// Commit transaction
433
CHECK(hugoOps.startTransaction(pNdb) == 0);
434
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
435
CHECK(hugoOps.execute_Commit(pNdb) == 630);
438
hugoOps.closeTransaction(pNdb);
443
int runCommit_TryCommit626(NDBT_Context* ctx, NDBT_Step* step){
444
int result = NDBT_OK;
445
HugoOperations hugoOps(*ctx->getTab());
446
Ndb* pNdb = GETNDB(step);
449
// Commit transaction, TryCommit
450
CHECK(hugoOps.startTransaction(pNdb) == 0);
451
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
452
CHECK(hugoOps.execute_Commit(pNdb, TryCommit) == 626);
453
CHECK(hugoOps.closeTransaction(pNdb) == 0);
455
// Commit transaction, TryCommit
456
// Several operations in one transaction
458
CHECK(hugoOps.startTransaction(pNdb) == 0);
459
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
460
CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
461
CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
462
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
463
CHECK(hugoOps.pkReadRecord(pNdb, 4, 1, NdbOperation::LM_Exclusive) == 0);
464
CHECK(hugoOps.execute_Commit(pNdb, TryCommit) == 626);
467
hugoOps.closeTransaction(pNdb);
472
int runCommit_TryCommit630(NDBT_Context* ctx, NDBT_Step* step){
473
int result = NDBT_OK;
474
HugoOperations hugoOps(*ctx->getTab());
475
Ndb* pNdb = GETNDB(step);
478
// Commit transaction, TryCommit
479
CHECK(hugoOps.startTransaction(pNdb) == 0);
480
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
481
CHECK(hugoOps.execute_Commit(pNdb, TryCommit) == 630);
484
hugoOps.closeTransaction(pNdb);
489
int runCommit_CommitAsMuchAsPossible626(NDBT_Context* ctx, NDBT_Step* step){
490
int result = NDBT_OK;
491
HugoOperations hugoOps(*ctx->getTab());
492
Ndb* pNdb = GETNDB(step);
495
// Commit transaction, CommitAsMuchAsPossible
496
CHECK(hugoOps.startTransaction(pNdb) == 0);
497
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
498
CHECK(hugoOps.execute_Commit(pNdb, CommitAsMuchAsPossible) == 626);
499
CHECK(hugoOps.closeTransaction(pNdb) == 0);
501
// Commit transaction, CommitAsMuchAsPossible
502
CHECK(hugoOps.startTransaction(pNdb) == 0);
503
CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
504
CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
505
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
506
CHECK(hugoOps.execute_Commit(pNdb, CommitAsMuchAsPossible) == 626);
507
CHECK(hugoOps.closeTransaction(pNdb) == 0);
509
CHECK(hugoOps.startTransaction(pNdb) == 0);
510
CHECK(hugoOps.pkReadRecord(pNdb, 1) == 0);
511
CHECK(hugoOps.execute_Commit(pNdb) == 0);
512
CHECK(hugoOps.closeTransaction(pNdb) == 0);
515
hugoOps.closeTransaction(pNdb);
520
int runCommit_CommitAsMuchAsPossible630(NDBT_Context* ctx, NDBT_Step* step){
521
int result = NDBT_OK;
522
HugoOperations hugoOps(*ctx->getTab());
523
Ndb* pNdb = GETNDB(step);
526
// Commit transaction, CommitAsMuchAsPossible
527
CHECK(hugoOps.startTransaction(pNdb) == 0);
528
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
529
CHECK(hugoOps.pkDeleteRecord(pNdb, 2) == 0);
530
CHECK(hugoOps.execute_Commit(pNdb, CommitAsMuchAsPossible) == 630);
531
CHECK(hugoOps.closeTransaction(pNdb) == 0);
533
CHECK(hugoOps.startTransaction(pNdb) == 0);
534
CHECK(hugoOps.pkReadRecord(pNdb, 2) == 0);
535
CHECK(hugoOps.execute_Commit(pNdb) == 0);
538
hugoOps.closeTransaction(pNdb);
543
int runNoCommit626(NDBT_Context* ctx, NDBT_Step* step){
544
int result = NDBT_OK;
545
HugoOperations hugoOps(*ctx->getTab());
546
Ndb* pNdb = GETNDB(step);
549
// No commit transaction, readTuple
550
CHECK(hugoOps.startTransaction(pNdb) == 0);
551
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
552
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
553
CHECK(hugoOps.closeTransaction(pNdb) == 0);
555
// No commit transaction, readTupleExcluive
556
CHECK(hugoOps.startTransaction(pNdb) == 0);
557
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
558
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
561
hugoOps.closeTransaction(pNdb);
566
int runNoCommit630(NDBT_Context* ctx, NDBT_Step* step){
567
int result = NDBT_OK;
568
HugoOperations hugoOps(*ctx->getTab());
569
Ndb* pNdb = GETNDB(step);
572
// No commit transaction
573
CHECK(hugoOps.startTransaction(pNdb) == 0);
574
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
575
CHECK(hugoOps.execute_NoCommit(pNdb) == 630);
578
hugoOps.closeTransaction(pNdb);
583
int runNoCommitRollback626(NDBT_Context* ctx, NDBT_Step* step){
584
int result = NDBT_OK;
585
HugoOperations hugoOps(*ctx->getTab());
586
Ndb* pNdb = GETNDB(step);
589
// No commit transaction, rollback
590
CHECK(hugoOps.startTransaction(pNdb) == 0);
591
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
592
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
593
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
594
CHECK(hugoOps.closeTransaction(pNdb) == 0);
596
// No commit transaction, rollback
597
// Multiple operations
598
CHECK(hugoOps.startTransaction(pNdb) == 0);
599
CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
600
CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
601
CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
602
CHECK(hugoOps.pkReadRecord(pNdb, 4, 1, NdbOperation::LM_Exclusive) == 0);
603
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
604
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
607
hugoOps.closeTransaction(pNdb);
612
int runNoCommitRollback630(NDBT_Context* ctx, NDBT_Step* step){
613
int result = NDBT_OK;
614
HugoOperations hugoOps(*ctx->getTab());
615
Ndb* pNdb = GETNDB(step);
618
// No commit transaction, rollback
619
CHECK(hugoOps.startTransaction(pNdb) == 0);
620
CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
621
CHECK(hugoOps.execute_NoCommit(pNdb) == 630);
622
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
625
hugoOps.closeTransaction(pNdb);
631
int runNoCommitAndClose(NDBT_Context* ctx, NDBT_Step* step){
632
int i, result = NDBT_OK;
633
HugoOperations hugoOps(*ctx->getTab());
634
Ndb* pNdb = GETNDB(step);
638
CHECK(hugoOps.startTransaction(pNdb) == 0);
639
for (i = 0; i < 10; i++)
640
CHECK(hugoOps.pkReadRecord(pNdb, i, 1, NdbOperation::LM_Exclusive) == 0);
641
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
642
CHECK(hugoOps.closeTransaction(pNdb) == 0);
645
CHECK(hugoOps.startTransaction(pNdb) == 0);
646
for (i = 0; i < 10; i++)
647
CHECK(hugoOps.pkUpdateRecord(pNdb, i) == 0);
648
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
649
CHECK(hugoOps.closeTransaction(pNdb) == 0);
652
CHECK(hugoOps.startTransaction(pNdb) == 0);
653
for (i = 0; i < 10; i++)
654
CHECK(hugoOps.pkDeleteRecord(pNdb, i) == 0);
655
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
656
CHECK(hugoOps.closeTransaction(pNdb) == 0);
658
// Try to insert, record should already exist
659
CHECK(hugoOps.startTransaction(pNdb) == 0);
660
for (i = 0; i < 10; i++)
661
CHECK(hugoOps.pkInsertRecord(pNdb, i) == 0);
662
CHECK(hugoOps.execute_Commit(pNdb) == 630);
663
CHECK(hugoOps.closeTransaction(pNdb) == 0);
667
hugoOps.closeTransaction(pNdb);
674
int runCheckRollbackDelete(NDBT_Context* ctx, NDBT_Step* step){
675
int result = NDBT_OK;
676
HugoOperations hugoOps(*ctx->getTab());
677
Ndb* pNdb = GETNDB(step);
681
// Read value and save it for later
682
CHECK(hugoOps.startTransaction(pNdb) == 0);
683
CHECK(hugoOps.pkReadRecord(pNdb, 5) == 0);
684
CHECK(hugoOps.execute_Commit(pNdb) == 0);
685
CHECK(hugoOps.saveCopyOfRecord() == NDBT_OK);
686
CHECK(hugoOps.closeTransaction(pNdb) == 0);
689
CHECK(hugoOps.startTransaction(pNdb) == 0);
690
CHECK(hugoOps.pkDeleteRecord(pNdb, 5) == 0);
691
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
693
// Check record is deleted
694
CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
695
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
696
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
698
CHECK(hugoOps.closeTransaction(pNdb) == 0);
700
// Check record is not deleted
701
CHECK(hugoOps.startTransaction(pNdb) == 0);
702
CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
703
CHECK(hugoOps.execute_Commit(pNdb) == 0);
704
CHECK(hugoOps.closeTransaction(pNdb) == 0);
706
// Check record is back to original value
707
CHECK(hugoOps.startTransaction(pNdb) == 0);
708
CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
709
CHECK(hugoOps.execute_Commit(pNdb) == 0);
710
CHECK(hugoOps.compareRecordToCopy() == NDBT_OK);
715
hugoOps.closeTransaction(pNdb);
720
int runCheckRollbackUpdate(NDBT_Context* ctx, NDBT_Step* step){
721
int result = NDBT_OK;
722
HugoOperations hugoOps(*ctx->getTab());
723
Ndb* pNdb = GETNDB(step);
727
// Read value and save it for later
728
CHECK(hugoOps.startTransaction(pNdb) == 0);
729
CHECK(hugoOps.pkReadRecord(pNdb, 1, numRecords) == 0);
730
CHECK(hugoOps.execute_Commit(pNdb) == 0);
731
CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK); // Update value 0
732
CHECK(hugoOps.closeTransaction(pNdb) == 0);
735
CHECK(hugoOps.startTransaction(pNdb) == 0);
736
CHECK(hugoOps.pkUpdateRecord(pNdb, 1, numRecords, 5) == 0);// Updates value 5
737
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
739
// Check record is updated
740
CHECK(hugoOps.pkReadRecord(pNdb, 1, numRecords, NdbOperation::LM_Exclusive) == 0);
741
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
742
CHECK(hugoOps.verifyUpdatesValue(5) == NDBT_OK); // Updates value 5
743
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
745
CHECK(hugoOps.closeTransaction(pNdb) == 0);
747
// Check record is back to original value
748
CHECK(hugoOps.startTransaction(pNdb) == 0);
749
CHECK(hugoOps.pkReadRecord(pNdb, 1, numRecords, NdbOperation::LM_Exclusive) == 0);
750
CHECK(hugoOps.execute_Commit(pNdb) == 0);
751
CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK); // Updates value 0
755
hugoOps.closeTransaction(pNdb);
760
int runCheckRollbackDeleteMultiple(NDBT_Context* ctx, NDBT_Step* step){
761
int result = NDBT_OK;
762
HugoOperations hugoOps(*ctx->getTab());
763
Ndb* pNdb = GETNDB(step);
766
// Read value and save it for later
767
CHECK(hugoOps.startTransaction(pNdb) == 0);
768
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10) == 0);
769
CHECK(hugoOps.execute_Commit(pNdb) == 0);
770
CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK);
771
CHECK(hugoOps.closeTransaction(pNdb) == 0);
773
Uint32 updatesValue = 0;
775
for(Uint32 i = 0; i<1; i++){
776
// Read record 5 - 10
777
CHECK(hugoOps.startTransaction(pNdb) == 0);
778
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
779
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
781
for(j = 0; j<10; j++){
782
// Update record 5 - 10
784
CHECK(hugoOps.pkUpdateRecord(pNdb, 5, 10, updatesValue) == 0);
785
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
787
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
788
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
789
CHECK(hugoOps.verifyUpdatesValue(updatesValue) == 0);
792
for(j = 0; j<10; j++){
793
// Delete record 5 - 10 times
794
CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
795
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
798
// Check records are deleted
799
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
800
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
804
CHECK(hugoOps.pkInsertRecord(pNdb, 5, 10, updatesValue) == 0);
805
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
807
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
808
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
809
CHECK(hugoOps.verifyUpdatesValue(updatesValue) == 0);
812
CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
813
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
815
// Check records are deleted
816
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
817
CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
818
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
820
CHECK(hugoOps.closeTransaction(pNdb) == 0);
823
// Check records are not deleted
825
CHECK(hugoOps.startTransaction(pNdb) == 0);
826
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
827
CHECK(hugoOps.execute_Commit(pNdb) == 0);
828
CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK);
832
hugoOps.closeTransaction(pNdb);
838
int runCheckImplicitRollbackDelete(NDBT_Context* ctx, NDBT_Step* step){
839
int result = NDBT_OK;
840
HugoOperations hugoOps(*ctx->getTab());
841
Ndb* pNdb = GETNDB(step);
845
CHECK(hugoOps.startTransaction(pNdb) == 0);
846
CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
847
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
848
CHECK(hugoOps.closeTransaction(pNdb) == 0);
851
CHECK(hugoOps.startTransaction(pNdb) == 0);
852
CHECK(hugoOps.pkUpdateRecord(pNdb, 5) == 0);
853
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
854
CHECK(hugoOps.closeTransaction(pNdb) == 0);
857
CHECK(hugoOps.startTransaction(pNdb) == 0);
858
CHECK(hugoOps.pkDeleteRecord(pNdb, 5) == 0);
859
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
860
CHECK(hugoOps.closeTransaction(pNdb) == 0);
862
// Check record is not deleted
863
// Close transaction should have rollbacked
864
CHECK(hugoOps.startTransaction(pNdb) == 0);
865
CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
866
CHECK(hugoOps.execute_Commit(pNdb) == 0);
869
hugoOps.closeTransaction(pNdb);
874
int runCheckCommitDelete(NDBT_Context* ctx, NDBT_Step* step){
875
int result = NDBT_OK;
876
HugoOperations hugoOps(*ctx->getTab());
877
Ndb* pNdb = GETNDB(step);
881
CHECK(hugoOps.startTransaction(pNdb) == 0);
882
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
883
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
886
CHECK(hugoOps.pkUpdateRecord(pNdb, 5, 10) == 0);
887
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
890
CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
891
CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
893
CHECK(hugoOps.execute_Commit(pNdb) == 0);
894
CHECK(hugoOps.closeTransaction(pNdb) == 0);
896
// Check record's are deleted
897
CHECK(hugoOps.startTransaction(pNdb) == 0);
898
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
899
CHECK(hugoOps.execute_Commit(pNdb) == 626);
903
hugoOps.closeTransaction(pNdb);
908
int runRollbackNothing(NDBT_Context* ctx, NDBT_Step* step){
909
int result = NDBT_OK;
910
HugoOperations hugoOps(*ctx->getTab());
911
Ndb* pNdb = GETNDB(step);
914
// Delete record 5 - 15
915
CHECK(hugoOps.startTransaction(pNdb) == 0);
916
CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
918
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
919
CHECK(hugoOps.closeTransaction(pNdb) == 0);
921
// Check records are not deleted
922
CHECK(hugoOps.startTransaction(pNdb) == 0);
923
CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
924
CHECK(hugoOps.execute_Commit(pNdb) == 0);
925
CHECK(hugoOps.closeTransaction(pNdb) == 0);
927
CHECK(hugoOps.startTransaction(pNdb) == 0);
928
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
932
hugoOps.closeTransaction(pNdb);
937
int runMassiveRollback(NDBT_Context* ctx, NDBT_Step* step){
939
NdbRestarter restarter;
940
const int records = 4 * restarter.getNumDbNodes();
942
HugoTransactions hugoTrans(*ctx->getTab());
943
if (hugoTrans.loadTable(GETNDB(step), records) != 0){
947
int result = NDBT_OK;
948
HugoOperations hugoOps(*ctx->getTab());
949
Ndb* pNdb = GETNDB(step);
951
const Uint32 OPS_PER_TRANS = 256;
952
const Uint32 OPS_TOTAL = 4096;
954
for(int row = 0; row < records; row++){
956
CHECK(hugoOps.startTransaction(pNdb) == 0);
957
for(Uint32 i = 0; i<OPS_TOTAL; i += OPS_PER_TRANS){
958
for(Uint32 j = 0; j<OPS_PER_TRANS; j++){
959
CHECK(hugoOps.pkUpdateRecord(pNdb, row, 1, i) == 0);
961
g_info << "Performed " << (i+OPS_PER_TRANS) << " updates on row: " << row
963
if(result != NDBT_OK){
966
res = hugoOps.execute_NoCommit(pNdb);
968
NdbError err = pNdb->getNdbError(res);
969
CHECK(err.classification == NdbError::TimeoutExpired);
973
if(result != NDBT_OK){
976
g_info << "executeRollback" << endl;
977
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
978
CHECK(hugoOps.closeTransaction(pNdb) == 0);
981
hugoOps.closeTransaction(pNdb);
986
runMassiveRollback2(NDBT_Context* ctx, NDBT_Step* step){
988
HugoTransactions hugoTrans(*ctx->getTab());
989
if (hugoTrans.loadTable(GETNDB(step), 1) != 0){
993
int result = NDBT_OK;
994
HugoOperations hugoOps(*ctx->getTab());
995
Ndb* pNdb = GETNDB(step);
997
const Uint32 OPS_TOTAL = 4096;
998
const Uint32 LOOPS = 10;
1000
for(Uint32 loop = 0; loop<LOOPS; loop++){
1001
CHECK(hugoOps.startTransaction(pNdb) == 0);
1002
for(Uint32 i = 0; i<OPS_TOTAL-1; i ++){
1004
CHECK(hugoOps.pkUpdateRecord(pNdb, 0, 1, loop) == 0);
1006
CHECK(hugoOps.pkUpdateRecord(pNdb, 1, 1, loop) == 0);
1009
CHECK(hugoOps.execute_Commit(pNdb) == 626);
1010
CHECK(hugoOps.execute_Rollback(pNdb) == 0);
1011
CHECK(hugoOps.closeTransaction(pNdb) == 0);
1014
hugoOps.closeTransaction(pNdb);
1019
runMassiveRollback3(NDBT_Context* ctx, NDBT_Step* step){
1021
int result = NDBT_OK;
1022
HugoOperations hugoOps(*ctx->getTab());
1023
Ndb* pNdb = GETNDB(step);
1025
const Uint32 BATCH = 10;
1026
const Uint32 OPS_TOTAL = 50;
1027
const Uint32 LOOPS = 100;
1029
for(Uint32 loop = 0; loop<LOOPS; loop++)
1031
CHECK(hugoOps.startTransaction(pNdb) == 0);
1033
for (Uint32 i = 0; i<OPS_TOTAL; i+= BATCH)
1035
CHECK(hugoOps.pkInsertRecord(pNdb, i, BATCH, 0) == 0);
1036
if (hugoOps.execute_NoCommit(pNdb) != 0)
1042
hugoOps.execute_Rollback(pNdb);
1043
CHECK(hugoOps.closeTransaction(pNdb) == 0);
1046
hugoOps.closeTransaction(pNdb);
1051
runMassiveRollback4(NDBT_Context* ctx, NDBT_Step* step){
1053
int result = NDBT_OK;
1054
HugoOperations hugoOps(*ctx->getTab());
1055
Ndb* pNdb = GETNDB(step);
1057
const Uint32 BATCH = 10;
1058
const Uint32 OPS_TOTAL = 20;
1059
const Uint32 LOOPS = 100;
1061
for(Uint32 loop = 0; loop<LOOPS; loop++)
1063
CHECK(hugoOps.startTransaction(pNdb) == 0);
1065
for (Uint32 i = 0; i<OPS_TOTAL; i+= BATCH)
1067
CHECK(hugoOps.pkInsertRecord(pNdb, i, BATCH, 0) == 0);
1068
CHECK(hugoOps.pkDeleteRecord(pNdb, i, BATCH) == 0);
1069
if (hugoOps.execute_NoCommit(pNdb) != 0)
1075
hugoOps.execute_Rollback(pNdb);
1076
CHECK(hugoOps.closeTransaction(pNdb) == 0);
1079
hugoOps.closeTransaction(pNdb);
1103
{ NdbOperation::InsertRequest, 4014, 0 }, // Out of undo buffer
1104
{ NdbOperation::InsertRequest, 4015, TupError::TE_DISK }, // Out of log space
1105
{ NdbOperation::InsertRequest, 4016, 0 }, // AI Inconsistency
1106
{ NdbOperation::InsertRequest, 4017, 0 }, // Out of memory
1107
{ NdbOperation::InsertRequest, 4018, 0 }, // Null check error
1108
{ NdbOperation::InsertRequest, 4019, TupError::TE_REPLICA }, //Alloc rowid error
1109
{ NdbOperation::InsertRequest, 4020, TupError::TE_MULTI_OP }, // Size change error
1110
{ NdbOperation::InsertRequest, 4021, TupError::TE_DISK }, // Out of disk space
1115
runTupErrors(NDBT_Context* ctx, NDBT_Step* step){
1117
NdbRestarter restarter;
1118
HugoTransactions hugoTrans(*ctx->getTab());
1119
HugoOperations hugoOps(*ctx->getTab());
1120
Ndb* pNdb = GETNDB(step);
1122
const NdbDictionary::Table * tab = ctx->getTab();
1124
int bits = TupError::TE_MULTI_OP;
1125
for(i = 0; i<tab->getNoOfColumns(); i++)
1127
if (tab->getColumn(i)->getArrayType() != NdbDictionary::Column::ArrayTypeFixed)
1128
bits |= TupError::TE_VARSIZE;
1129
if (tab->getColumn(i)->getStorageType()!= NdbDictionary::Column::StorageTypeMemory)
1130
bits |= TupError::TE_DISK;
1133
if (restarter.getNumDbNodes() >= 2)
1135
bits |= TupError::TE_REPLICA;
1141
for(i = 0; f_tup_errors[i].op != -1; i++)
1143
if (f_tup_errors[i].op != NdbOperation::InsertRequest)
1145
g_info << "Skipping " << f_tup_errors[i].error
1146
<< " - not insert" << endl;
1150
if ((f_tup_errors[i].bits & bits) != f_tup_errors[i].bits)
1152
g_info << "Skipping " << f_tup_errors[i].error
1153
<< " - req bits: " << hex << f_tup_errors[i].bits
1154
<< " bits: " << hex << bits << endl;
1158
g_info << "Testing error insert: " << f_tup_errors[i].error << endl;
1159
restarter.insertErrorInAllNodes(f_tup_errors[i].error);
1160
if (f_tup_errors[i].bits & TupError::TE_MULTI_OP)
1166
hugoTrans.loadTable(pNdb, 5);
1168
restarter.insertErrorInAllNodes(0);
1169
if (hugoTrans.clearTable(pNdb, 5) != 0)
1179
runInsertError(NDBT_Context* ctx, NDBT_Step* step){
1181
int result = NDBT_OK;
1182
HugoOperations hugoOp1(*ctx->getTab());
1183
HugoOperations hugoOp2(*ctx->getTab());
1184
Ndb* pNdb = GETNDB(step);
1186
NdbRestarter restarter;
1187
restarter.insertErrorInAllNodes(4017);
1188
const Uint32 LOOPS = 10;
1189
for (Uint32 i = 0; i<LOOPS; i++)
1191
CHECK(hugoOp1.startTransaction(pNdb) == 0);
1192
CHECK(hugoOp1.pkInsertRecord(pNdb, 1) == 0);
1194
CHECK(hugoOp2.startTransaction(pNdb) == 0);
1195
CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1) == 0);
1197
CHECK(hugoOp1.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
1198
CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
1199
hugoOp1.wait_async(pNdb);
1200
hugoOp2.wait_async(pNdb);
1201
CHECK(hugoOp1.closeTransaction(pNdb) == 0);
1202
CHECK(hugoOp2.closeTransaction(pNdb) == 0);
1205
restarter.insertErrorInAllNodes(0);
1211
runInsertError2(NDBT_Context* ctx, NDBT_Step* step){
1212
int result = NDBT_OK;
1213
HugoOperations hugoOp1(*ctx->getTab());
1214
Ndb* pNdb = GETNDB(step);
1216
NdbRestarter restarter;
1217
restarter.insertErrorInAllNodes(4017);
1219
const Uint32 LOOPS = 1;
1220
for (Uint32 i = 0; i<LOOPS; i++)
1222
CHECK(hugoOp1.startTransaction(pNdb) == 0);
1223
CHECK(hugoOp1.pkInsertRecord(pNdb, 1) == 0);
1224
CHECK(hugoOp1.pkDeleteRecord(pNdb, 1) == 0);
1226
hugoOp1.execute_NoCommit(pNdb);
1227
CHECK(hugoOp1.closeTransaction(pNdb) == 0);
1230
restarter.insertErrorInAllNodes(0);
1235
runBug25090(NDBT_Context* ctx, NDBT_Step* step){
1237
Ndb* pNdb = GETNDB(step);
1238
NdbDictionary::Dictionary * dict = pNdb->getDictionary();
1240
HugoOperations ops(*ctx->getTab());
1242
int loops = ctx->getNumLoops();
1243
const int rows = ctx->getNumRecords();
1247
ops.startTransaction(pNdb);
1248
ops.pkReadRecord(pNdb, 1, 1);
1249
ops.execute_Commit(pNdb, AO_IgnoreError);
1251
ops.closeTransaction(pNdb);
1258
runDeleteRead(NDBT_Context* ctx, NDBT_Step* step){
1260
Ndb* pNdb = GETNDB(step);
1262
const NdbDictionary::Table* tab = ctx->getTab();
1263
NDBT_ResultRow row(*ctx->getTab());
1264
HugoTransactions tmp(*ctx->getTab());
1267
int loops = ctx->getNumLoops();
1268
const int rows = ctx->getNumRecords();
1272
NdbTransaction* pTrans = pNdb->startTransaction();
1273
NdbOperation* pOp = pTrans->getNdbOperation(tab->getName());
1275
tmp.equalForRow(pOp, loops);
1277
// Define attributes to read
1278
for(a = 0; a<tab->getNoOfColumns(); a++)
1280
if((row.attributeStore(a) = pOp->getValue(tab->getColumn(a)->getName())) == 0) {
1281
ERR(pTrans->getNdbError());
1286
pTrans->execute(Commit);
1289
pTrans = pNdb->startTransaction();
1290
pOp = pTrans->getNdbOperation(tab->getName());
1292
tmp.setValues(pOp, loops, 0);
1294
pOp = pTrans->getNdbOperation(tab->getName());
1296
tmp.equalForRow(pOp, loops);
1297
for(a = 0; a<tab->getNoOfColumns(); a++)
1299
if((row.attributeStore(a) = pOp->getValue(tab->getColumn(a)->getName())) == 0)
1301
ERR(pTrans->getNdbError());
1305
if (pTrans->execute(Commit) != 0)
1307
ERR(pTrans->getNdbError());
1318
runBug27756(NDBT_Context* ctx, NDBT_Step* step)
1321
Ndb* pNdb = GETNDB(step);
1322
NdbDictionary::Dictionary * dict = pNdb->getDictionary();
1324
HugoOperations ops(*ctx->getTab());
1326
int loops = ctx->getNumLoops();
1327
const int rows = ctx->getNumRecords();
1329
Vector<Uint64> copies;
1332
ops.startTransaction(pNdb);
1333
ops.pkInsertRecord(pNdb, 1, 1);
1334
ops.execute_NoCommit(pNdb);
1336
NdbTransaction* pTrans = ops.getTransaction();
1337
NdbOperation* op = pTrans->getNdbOperation(ctx->getTab()->getName());
1338
op->interpretedUpdateTuple();
1339
ops.equalForRow(op, 1);
1340
NdbRecAttr* attr = op->getValue(NdbDictionary::Column::COPY_ROWID);
1341
ops.execute_NoCommit(pNdb);
1343
copies.push_back(attr->u_64_value());
1344
ndbout_c("copy at: %llx", copies.back());
1345
ops.execute_NoCommit(pNdb);
1347
ops.pkDeleteRecord(pNdb, 1, 1);
1348
ops.execute_NoCommit(pNdb);
1352
ops.execute_Rollback(pNdb);
1353
ops.closeTransaction(pNdb);
1357
ops.execute_Commit(pNdb);
1358
ops.closeTransaction(pNdb);
1359
ops.clearTable(pNdb, 100);
1363
for (Uint32 i = 0; i<copies.size(); i++)
1364
if (copies[i] != copies.back())
1366
ndbout_c("Memleak detected");
1374
runBug28073(NDBT_Context *ctx, NDBT_Step* step)
1376
int result = NDBT_OK;
1377
const NdbDictionary::Table *table= ctx->getTab();
1378
HugoOperations hugoOp1(*table);
1379
HugoOperations hugoOp2(*table);
1380
Ndb* pNdb = GETNDB(step);
1381
int loops = ctx->getNumLoops();
1382
bool inserted= false;
1388
CHECK(hugoOp1.startTransaction(pNdb) == 0);
1389
CHECK(hugoOp1.pkInsertRecord(pNdb, 1, 1) == 0);
1390
CHECK(hugoOp1.execute_Commit(pNdb) == 0);
1391
CHECK(hugoOp1.closeTransaction(pNdb) == 0);
1395
// Use TC hint to hit the same node in both transactions.
1397
const char *key= (const char *)(&key_val);
1398
CHECK(hugoOp1.startTransaction(pNdb, table, key, 4) == 0);
1399
CHECK(hugoOp2.startTransaction(pNdb, table, key, 4) == 0);
1401
// First take 2*read lock on the tuple in transaction 1.
1402
for (Uint32 i= 0; i < 2; i++)
1404
CHECK(hugoOp1.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
1405
CHECK(hugoOp1.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
1407
CHECK(hugoOp1.execute_NoCommit(pNdb) == 0);
1409
// Now send ops in two transactions, one batch.
1410
// First 2*read in transaction 2.
1411
for (Uint32 i= 0; i < 2; i++)
1413
CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
1414
CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
1416
CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::NoCommit) == 0);
1418
// Second op an update in transaction 1.
1419
CHECK(hugoOp1.pkUpdateRecord(pNdb, 1, 1) == 0);
1420
CHECK(hugoOp1.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
1422
// Transaction 1 will now hang waiting on transaction 2 to commit before it
1423
// can upgrade its read lock to a write lock.
1424
// With the bug, we get a node failure due to watchdog timeout here.
1425
CHECK(hugoOp2.wait_async(pNdb) == 0);
1427
// Now commit transaction 2, we should see transaction 1 finish with the
1429
CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
1430
CHECK(hugoOp2.wait_async(pNdb) == 0);
1431
// No error check, as transaction 1 may have terminated already.
1432
hugoOp1.wait_async(pNdb);
1434
CHECK(hugoOp1.closeTransaction(pNdb) == 0);
1435
CHECK(hugoOp2.closeTransaction(pNdb) == 0);
1441
template class Vector<Uint64>;
1444
runBug20535(NDBT_Context* ctx, NDBT_Step* step)
1447
Ndb* pNdb = GETNDB(step);
1448
const NdbDictionary::Table * tab = ctx->getTab();
1449
NdbDictionary::Dictionary * dict = pNdb->getDictionary();
1452
for (i = 0; i<tab->getNoOfColumns(); i++)
1454
if (tab->getColumn(i)->getNullable())
1464
HugoTransactions hugoTrans(* tab);
1465
hugoTrans.loadTable(pNdb, 1);
1467
NdbTransaction* pTrans = pNdb->startTransaction();
1468
NdbOperation* pOp = pTrans->getNdbOperation(tab->getName());
1470
hugoTrans.equalForRow(pOp, 0);
1471
if (pTrans->execute(NoCommit) != 0)
1474
pOp = pTrans->getNdbOperation(tab->getName());
1476
hugoTrans.equalForRow(pOp, 0);
1477
for (i = 0; i<tab->getNoOfColumns(); i++)
1479
if (!tab->getColumn(i)->getPrimaryKey() &&
1480
!tab->getColumn(i)->getNullable())
1482
hugoTrans.setValueForAttr(pOp, i, 0, 1);
1486
if (pTrans->execute(Commit) != 0)
1491
pTrans = pNdb->startTransaction();
1492
pOp = pTrans->getNdbOperation(tab->getName());
1494
hugoTrans.equalForRow(pOp, 0);
1495
Vector<NdbRecAttr*> values;
1496
for (i = 0; i<tab->getNoOfColumns(); i++)
1498
if (!tab->getColumn(i)->getPrimaryKey() &&
1499
tab->getColumn(i)->getNullable())
1501
values.push_back(pOp->getValue(i));
1505
if (pTrans->execute(Commit) != 0)
1509
for (i = 0; i<values.size(); i++)
1511
if (!values[i]->isNULL())
1514
ndbout_c("column %s is not NULL", values[i]->getColumn()->getName());
1526
template class Vector<NdbRecAttr*>;
1528
NDBT_TESTSUITE(testBasic);
1529
TESTCASE("PkInsert",
1530
"Verify that we can insert and delete from this table using PK"
1531
"NOTE! No errors are allowed!" ){
1532
INITIALIZER(runInsert);
1533
VERIFIER(runVerifyInsert);
1536
"Verify that we can insert, read and delete from this table using PK"){
1537
TC_PROPERTY("LockMode", NdbOperation::LM_Read);
1538
INITIALIZER(runLoadTable);
1540
FINALIZER(runClearTable);
1542
TESTCASE("PkDirtyRead",
1543
"Verify that we can insert, dirty read and delete from this table using PK"){
1544
TC_PROPERTY("LockMode", NdbOperation::LM_Dirty);
1545
INITIALIZER(runLoadTable);
1547
FINALIZER(runClearTable);
1549
TESTCASE("PkSimpleRead",
1550
"Verify that we can insert, simple read and delete from this table using PK"){
1551
TC_PROPERTY("LockMode", NdbOperation::LM_SimpleRead);
1552
INITIALIZER(runLoadTable);
1554
FINALIZER(runClearTable);
1556
TESTCASE("PkUpdate",
1557
"Verify that we can insert, update and delete from this table using PK"){
1558
INITIALIZER(runLoadTable);
1560
FINALIZER(runClearTable);
1562
TESTCASE("PkDelete",
1563
"Verify that we can delete from this table using PK"){
1564
INITIALIZER(runLoadTable);
1566
FINALIZER(runClearTable);
1568
TESTCASE("UpdateAndRead",
1569
"Verify that we can read and update at the same time"){
1570
INITIALIZER(runLoadTable);
1577
FINALIZER(runClearTable);
1579
TESTCASE("PkReadAndLocker",
1580
"Verify that we can read although there are "\
1581
" a number of 1 second locks in the table"){
1582
INITIALIZER(runLoadTable);
1583
STEP(runPkReadUntilStopped);
1585
FINALIZER(runClearTable);
1587
TESTCASE("PkReadAndLocker2",
1588
"Verify that we can read and update although there are "\
1589
" a number of 1 second locks in the table"){
1590
INITIALIZER(runLoadTable);
1591
STEP(runPkReadUntilStopped);
1592
STEP(runPkReadUntilStopped);
1593
STEP(runPkReadUntilStopped);
1594
STEP(runPkReadUntilStopped);
1595
STEP(runPkReadUntilStopped);
1596
STEP(runPkReadUntilStopped);
1598
FINALIZER(runClearTable);
1600
TESTCASE("PkReadUpdateAndLocker",
1601
"Verify that we can read and update although there are "\
1602
" a number of 1 second locks in the table"){
1603
INITIALIZER(runLoadTable);
1604
STEP(runPkReadUntilStopped);
1605
STEP(runPkReadUntilStopped);
1606
STEP(runPkUpdateUntilStopped);
1607
STEP(runPkUpdateUntilStopped);
1609
FINALIZER(runClearTable);
1611
TESTCASE("ReadWithLocksAndInserts",
1612
"TR457: This test is added to verify that an insert of a records "\
1613
"that is already in the database does not delete the record"){
1614
INITIALIZER(runLoadTable);
1615
STEP(runPkReadUntilStopped);
1616
STEP(runPkReadUntilStopped);
1618
STEP(runInsertUntilStopped);
1619
FINALIZER(runClearTable);
1621
TESTCASE("PkInsertTwice",
1622
"Verify that we can't insert an already inserted record."
1623
"Error should be returned" ){
1624
INITIALIZER(runLoadTable);
1625
STEP(runInsertTwice);
1626
FINALIZER(runClearTable);
1628
TESTCASE("NoCommitSleep",
1629
"Verify what happens when a NoCommit transaction is aborted by "
1630
"NDB because the application is sleeping" ){
1631
INITIALIZER(runLoadTable);
1632
INITIALIZER(runNoCommitSleep);
1633
FINALIZER(runClearTable2);
1635
TESTCASE("Commit626",
1636
"Verify what happens when a Commit transaction is aborted by "
1637
"NDB because the record does no exist" ){
1638
INITIALIZER(runClearTable2);
1639
INITIALIZER(runCommit626);
1640
FINALIZER(runClearTable2);
1642
TESTCASE("CommitTry626",
1643
"Verify what happens when a Commit(TryCommit) \n"
1644
"transaction is aborted by "
1645
"NDB because the record does no exist" ){
1646
INITIALIZER(runClearTable2);
1647
INITIALIZER(runCommit_TryCommit626);
1648
FINALIZER(runClearTable2);
1650
TESTCASE("CommitAsMuch626",
1651
"Verify what happens when a Commit(CommitAsMuchAsPossible) \n"
1652
"transaction is aborted by\n"
1653
"NDB because the record does no exist" ){
1654
INITIALIZER(runClearTable2);
1655
INITIALIZER(runCommit_CommitAsMuchAsPossible626);
1656
FINALIZER(runClearTable2);
1658
TESTCASE("NoCommit626",
1659
"Verify what happens when a NoCommit transaction is aborted by "
1660
"NDB because the record does no exist" ){
1661
INITIALIZER(runClearTable2);
1662
INITIALIZER(runNoCommit626);
1663
FINALIZER(runClearTable2);
1665
TESTCASE("NoCommitRollback626",
1666
"Verify what happens when a NoCommit transaction is aborted by "
1667
"NDB because the record does no exist and then we try to rollback\n"
1668
"the transaction" ){
1669
INITIALIZER(runClearTable2);
1670
INITIALIZER(runNoCommitRollback626);
1671
FINALIZER(runClearTable2);
1673
TESTCASE("Commit630",
1674
"Verify what happens when a Commit transaction is aborted by "
1675
"NDB because the record already exist" ){
1676
INITIALIZER(runLoadTable);
1677
INITIALIZER(runCommit630);
1678
FINALIZER(runClearTable2);
1680
TESTCASE("CommitTry630",
1681
"Verify what happens when a Commit(TryCommit) \n"
1682
"transaction is aborted by "
1683
"NDB because the record already exist" ){
1684
INITIALIZER(runLoadTable);
1685
INITIALIZER(runCommit_TryCommit630);
1686
FINALIZER(runClearTable2);
1688
TESTCASE("CommitAsMuch630",
1689
"Verify what happens when a Commit(CommitAsMuchAsPossible) \n"
1690
"transaction is aborted by\n"
1691
"NDB because the record already exist" ){
1692
INITIALIZER(runLoadTable);
1693
INITIALIZER(runCommit_CommitAsMuchAsPossible630);
1694
FINALIZER(runClearTable2);
1696
TESTCASE("NoCommit630",
1697
"Verify what happens when a NoCommit transaction is aborted by "
1698
"NDB because the record already exist" ){
1699
INITIALIZER(runLoadTable);
1700
INITIALIZER(runNoCommit630);
1701
FINALIZER(runClearTable2);
1703
TESTCASE("NoCommitRollback630",
1704
"Verify what happens when a NoCommit transaction is aborted by "
1705
"NDB because the record already exist and then we try to rollback\n"
1706
"the transaction" ){
1707
INITIALIZER(runLoadTable);
1708
INITIALIZER(runNoCommitRollback630);
1709
FINALIZER(runClearTable2);
1711
TESTCASE("NoCommitAndClose",
1712
"Verify what happens when a NoCommit transaction is closed "
1713
"without rolling back the transaction " ){
1714
INITIALIZER(runLoadTable);
1715
INITIALIZER(runNoCommitAndClose);
1716
FINALIZER(runClearTable2);
1718
TESTCASE("RollbackDelete",
1719
"Test rollback of a no committed delete"){
1720
INITIALIZER(runLoadTable);
1721
INITIALIZER(runCheckRollbackDelete);
1722
FINALIZER(runClearTable2);
1724
TESTCASE("RollbackUpdate",
1725
"Test rollback of a no committed update"){
1726
INITIALIZER(runLoadTable);
1727
INITIALIZER(runCheckRollbackUpdate);
1728
FINALIZER(runClearTable2);
1730
TESTCASE("RollbackDeleteMultiple",
1731
"Test rollback of 10 non committed delete"){
1732
INITIALIZER(runLoadTable);
1733
INITIALIZER(runCheckRollbackDeleteMultiple);
1734
FINALIZER(runClearTable2);
1736
TESTCASE("ImplicitRollbackDelete",
1737
"Test close transaction after a no commited delete\n"
1738
"this would give an implicit rollback of the delete\n"){
1739
INITIALIZER(runLoadTable);
1740
INITIALIZER(runCheckImplicitRollbackDelete);
1741
FINALIZER(runClearTable2);
1743
TESTCASE("CommitDelete",
1744
"Test close transaction after a no commited delete\n"
1745
"this would give an implicit rollback of the delete\n"){
1746
INITIALIZER(runLoadTable);
1747
INITIALIZER(runCheckCommitDelete);
1748
FINALIZER(runClearTable2);
1750
TESTCASE("RollbackNothing",
1751
"Test rollback of nothing"){
1752
INITIALIZER(runLoadTable);
1753
INITIALIZER(runRollbackNothing);
1754
FINALIZER(runClearTable2);
1756
TESTCASE("MassiveRollback",
1757
"Test rollback of 4096 operations"){
1758
INITIALIZER(runClearTable2);
1759
INITIALIZER(runMassiveRollback);
1760
FINALIZER(runClearTable2);
1762
TESTCASE("MassiveRollback2",
1763
"Test rollback of 4096 operations"){
1764
INITIALIZER(runClearTable2);
1765
INITIALIZER(runMassiveRollback2);
1766
FINALIZER(runClearTable2);
1768
TESTCASE("MassiveRollback3",
1769
"Test rollback of 4096 operations"){
1770
INITIALIZER(runClearTable2);
1771
STEP(runMassiveRollback3);
1772
STEP(runMassiveRollback3);
1773
FINALIZER(runClearTable2);
1775
TESTCASE("MassiveRollback4",
1776
"Test rollback of 4096 operations"){
1777
INITIALIZER(runClearTable2);
1778
STEP(runMassiveRollback4);
1779
STEP(runMassiveRollback4);
1780
FINALIZER(runClearTable2);
1782
TESTCASE("MassiveTransaction",
1783
"Test very large insert transaction"){
1784
INITIALIZER(runLoadTable2);
1785
FINALIZER(runClearTable2);
1787
TESTCASE("TupError",
1788
"Verify what happens when we fill the db" ){
1789
INITIALIZER(runTupErrors);
1791
TESTCASE("InsertError", "" ){
1792
INITIALIZER(runInsertError);
1794
TESTCASE("InsertError2", "" ){
1795
INITIALIZER(runInsertError2);
1798
"Verify what happens when we fill the db" ){
1799
INITIALIZER(runFillTable);
1800
INITIALIZER(runPkRead);
1801
FINALIZER(runClearTable2);
1803
TESTCASE("Bug25090",
1804
"Verify what happens when we fill the db" ){
1807
TESTCASE("DeleteRead",
1808
"Verify Delete+Read" ){
1809
INITIALIZER(runLoadTable);
1810
INITIALIZER(runDeleteRead);
1811
FINALIZER(runClearTable2);
1813
TESTCASE("Bug27756",
1814
"Verify what happens when we fill the db" ){
1817
TESTCASE("Bug28073",
1818
"Infinite loop in lock queue" ){
1821
TESTCASE("Bug20535",
1822
"Verify what happens when we fill the db" ){
1825
NDBT_TESTSUITE_END(testBasic);
1828
TESTCASE("ReadConsistency",
1829
"Check that a read within a transaction returns the " \
1830
"same result no matter"){
1833
FINALIZER(runClearTable2);
1836
"Verify what happens when we fill the db" ){
1837
INITIALIZER(runFillTable);
1838
INITIALIZER(runPkRead);
1839
FINALIZER(runClearTable2);
1843
int main(int argc, const char** argv){
1845
return testBasic.execute(argc, argv);