~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/testBasic.cpp

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
 
15
 
 
16
#include <NDBT_Test.hpp>
 
17
#include <NDBT_ReturnCodes.h>
 
18
#include <HugoTransactions.hpp>
 
19
#include <UtilTransactions.hpp>
 
20
#include <NdbRestarter.hpp>
 
21
 
 
22
#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
 
23
 
 
24
 
 
25
/**
 
26
 * TODO 
 
27
 *  dirtyWrite, write, dirtyUpdate
 
28
 *  delete should be visible to same transaction
 
29
 *  
 
30
 */
 
31
int runLoadTable2(NDBT_Context* ctx, NDBT_Step* step)
 
32
{
 
33
  int records = ctx->getNumRecords();
 
34
  HugoTransactions hugoTrans(*ctx->getTab());
 
35
  if (hugoTrans.loadTable(GETNDB(step), records, 512, false, 0, true) != 0){
 
36
    return NDBT_FAILED;
 
37
  }
 
38
  return NDBT_OK;
 
39
}
 
40
 
 
41
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step)
 
42
{
 
43
  int records = ctx->getNumRecords();
 
44
  HugoTransactions hugoTrans(*ctx->getTab());
 
45
  if (hugoTrans.loadTable(GETNDB(step), records) != 0){
 
46
    return NDBT_FAILED;
 
47
  }
 
48
  return NDBT_OK;
 
49
}
 
50
 
 
51
int runInsert(NDBT_Context* ctx, NDBT_Step* step){
 
52
 
 
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){
 
58
    return NDBT_FAILED;
 
59
  }
 
60
  return NDBT_OK;
 
61
}
 
62
 
 
63
int runInsertTwice(NDBT_Context* ctx, NDBT_Step* step){
 
64
 
 
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){
 
69
    return NDBT_FAILED;
 
70
  }
 
71
  return NDBT_OK;
 
72
}
 
73
 
 
74
int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
 
75
  int records = ctx->getNumRecords();
 
76
  
 
77
  HugoTransactions hugoTrans(*ctx->getTab());
 
78
  if (hugoTrans.pkDelRecords(GETNDB(step),  records, 1, false) != 0){
 
79
    return NDBT_FAILED;
 
80
  }
 
81
  return NDBT_OK;
 
82
}
 
83
 
 
84
int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
 
85
  int records = ctx->getNumRecords();
 
86
  int i = 0;
 
87
  HugoTransactions hugoTrans(*ctx->getTab());
 
88
  while (ctx->isTestStopped() == false) {
 
89
    g_info << i << ": ";    
 
90
    if (hugoTrans.loadTable(GETNDB(step), records) != 0){
 
91
      g_info << endl;
 
92
      return NDBT_FAILED;
 
93
    }
 
94
    i++;
 
95
  }
 
96
  g_info << endl;
 
97
  return NDBT_OK;
 
98
}
 
99
 
 
100
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
 
101
  int records = ctx->getNumRecords();
 
102
  int batchSize = ctx->getProperty("BatchSize", 1);
 
103
  
 
104
  HugoTransactions hugoTrans(*ctx->getTab());
 
105
  if (hugoTrans.pkDelRecords(GETNDB(step),  records, batchSize) != 0){
 
106
    return NDBT_FAILED;
 
107
  }
 
108
  return NDBT_OK;
 
109
}
 
110
 
 
111
int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
 
112
  int loops = ctx->getNumLoops();
 
113
  int records = ctx->getNumRecords();
 
114
 
 
115
  int i = 0;
 
116
  HugoTransactions hugoTrans(*ctx->getTab());
 
117
  while (i<loops) {
 
118
    g_info << i << ": ";
 
119
    if (hugoTrans.pkDelRecords(GETNDB(step),  records) != 0){
 
120
      g_info << endl;
 
121
      return NDBT_FAILED;
 
122
    }
 
123
    // Load table, don't allow any primary key violations
 
124
    if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
 
125
      g_info << endl;
 
126
      return NDBT_FAILED;
 
127
    }
 
128
    i++;
 
129
  }  
 
130
  g_info << endl;
 
131
  return NDBT_OK;
 
132
}
 
133
 
 
134
 
 
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);
 
140
  int i = 0;
 
141
  HugoTransactions hugoTrans(*ctx->getTab());
 
142
  while (i<loops) {
 
143
    g_info << i << ": ";
 
144
    if (hugoTrans.pkReadRecords(GETNDB(step), records, batchSize,
 
145
                                (NdbOperation::LockMode)lm) != NDBT_OK){
 
146
      g_info << endl;
 
147
      return NDBT_FAILED;
 
148
    }
 
149
    i++;
 
150
  }
 
151
  g_info << endl;
 
152
  return NDBT_OK;
 
153
}
 
154
 
 
155
int runPkReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
 
156
  int records = ctx->getNumRecords();
 
157
  int batchSize = ctx->getProperty("BatchSize", 1);
 
158
  int i = 0;
 
159
  HugoTransactions hugoTrans(*ctx->getTab());
 
160
  while (ctx->isTestStopped() == false) {
 
161
    g_info << i << ": ";
 
162
    if (hugoTrans.pkReadRecords(GETNDB(step), records, batchSize) != 0){
 
163
      g_info << endl;
 
164
      return NDBT_FAILED;
 
165
    }
 
166
    i++;
 
167
  }
 
168
  g_info << endl;
 
169
  return NDBT_OK;
 
170
}
 
171
 
 
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);
 
176
  int i = 0;
 
177
  HugoTransactions hugoTrans(*ctx->getTab());
 
178
  while (i<loops) {
 
179
    g_info << "|- " << i << ": ";
 
180
    if (hugoTrans.pkUpdateRecords(GETNDB(step), records, batchSize) != 0){
 
181
      g_info << endl;
 
182
      return NDBT_FAILED;
 
183
    }
 
184
    i++;
 
185
  }
 
186
  g_info << endl;
 
187
  return NDBT_OK;
 
188
}
 
189
 
 
190
int runPkUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
 
191
  int records = ctx->getNumRecords();
 
192
  int batchSize = ctx->getProperty("BatchSize", 1);
 
193
  int i = 0;
 
194
  HugoTransactions hugoTrans(*ctx->getTab());
 
195
  while (ctx->isTestStopped()) {
 
196
    g_info << i << ": ";
 
197
    if (hugoTrans.pkUpdateRecords(GETNDB(step), records, batchSize) != 0){
 
198
      g_info << endl;
 
199
      return NDBT_FAILED;
 
200
    }
 
201
    i++;
 
202
  }
 
203
  g_info << endl;
 
204
  return NDBT_OK;
 
205
}
 
206
 
 
207
int runLocker(NDBT_Context* ctx, NDBT_Step* step){
 
208
  int result = NDBT_OK;
 
209
  int records = ctx->getNumRecords();
 
210
  HugoTransactions hugoTrans(*ctx->getTab());
 
211
  
 
212
  if (hugoTrans.lockRecords(GETNDB(step), records, 10, 500) != 0){
 
213
    result = NDBT_FAILED;
 
214
  }
 
215
  ctx->stopTest();
 
216
  
 
217
  return result;
 
218
}
 
219
 
 
220
int
 
221
runInsertOne(NDBT_Context* ctx, NDBT_Step* step){
 
222
  
 
223
  if(ctx->getProperty("InsertCommitted", (Uint32)0) != 0){
 
224
    abort();
 
225
  }
 
226
 
 
227
  while(ctx->getProperty("Read1Performed", (Uint32)0) == 0){
 
228
    NdbSleep_MilliSleep(20);
 
229
  }
 
230
  
 
231
  HugoTransactions hugoTrans(*ctx->getTab());
 
232
  
 
233
  if (hugoTrans.loadTable(GETNDB(step), 1, 1) != 0){
 
234
    return NDBT_FAILED;
 
235
  }
 
236
 
 
237
  ctx->setProperty("InsertCommitted", 1);
 
238
 
 
239
  NdbSleep_SecSleep(2);
 
240
 
 
241
  return NDBT_OK;
 
242
}
 
243
 
 
244
static
 
245
int
 
246
readOneNoCommit(Ndb* pNdb, NdbConnection* pTrans, 
 
247
                const NdbDictionary::Table* tab,NDBT_ResultRow * row){
 
248
  int a;
 
249
  NdbOperation * pOp = pTrans->getNdbOperation(tab->getName());
 
250
  if (pOp == NULL){
 
251
    ERR(pTrans->getNdbError());
 
252
    return NDBT_FAILED;
 
253
  }
 
254
  
 
255
  HugoTransactions tmp(*tab);
 
256
 
 
257
  int check = pOp->readTuple();
 
258
  if( check == -1 ) {
 
259
    ERR(pTrans->getNdbError());
 
260
    return NDBT_FAILED;
 
261
  }
 
262
  
 
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());
 
268
        return NDBT_FAILED;
 
269
      }
 
270
    }
 
271
  }
 
272
  
 
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());
 
278
      return NDBT_FAILED;
 
279
    }
 
280
  }
 
281
 
 
282
  check = pTrans->execute(NoCommit);     
 
283
  if( check == -1 ) {
 
284
    const NdbError err = pTrans->getNdbError(); 
 
285
    ERR(err);
 
286
    return err.code;
 
287
  }
 
288
  return NDBT_OK;
 
289
}
 
290
 
 
291
int
 
292
runReadOne(NDBT_Context* ctx, NDBT_Step* step){
 
293
 
 
294
  Ndb* pNdb = GETNDB(step);
 
295
  const NdbDictionary::Table* tab = ctx->getTab();
 
296
  NDBT_ResultRow row1(*tab);
 
297
  NDBT_ResultRow row2(*tab);  
 
298
 
 
299
  if(ctx->getProperty("Read1Performed", (Uint32)0) != 0){
 
300
    abort();
 
301
  }
 
302
 
 
303
  if(ctx->getProperty("InsertCommitted", (Uint32)0) != 0){
 
304
    abort();
 
305
  }
 
306
  
 
307
  NdbConnection * pTrans = pNdb->startTransaction();
 
308
  if (pTrans == NULL) {
 
309
    abort();
 
310
  }    
 
311
 
 
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;
 
316
 
 
317
  ctx->setProperty("Read1Performed", 1);
 
318
  
 
319
  while(ctx->getProperty("InsertCommitted", (Uint32)0) == 0 && 
 
320
        !ctx->isTestStopped()){
 
321
    g_info << "|- Waiting for insert" << endl;
 
322
    NdbSleep_MilliSleep(20);
 
323
  }
 
324
  
 
325
  if(ctx->isTestStopped()){
 
326
    abort();
 
327
  }
 
328
 
 
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
 
332
 
 
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
 
336
  // MASV 20030624
 
337
  const int res2 = readOneNoCommit(pNdb, pTrans, tab, &row2);
 
338
 
 
339
  pTrans->execute(Commit);
 
340
  pNdb->closeTransaction(pTrans);
 
341
  g_info << "|- res2 = " << res2 << endl;
 
342
 
 
343
  if (res2 == 626 && res1 == res2)    
 
344
    return NDBT_OK;
 
345
  else
 
346
    return NDBT_FAILED;
 
347
}
 
348
 
 
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){
 
353
    return NDBT_FAILED;
 
354
  }
 
355
  return NDBT_OK;
 
356
}
 
357
 
 
358
int runClearTable2(NDBT_Context* ctx, NDBT_Step* step){
 
359
  int records = ctx->getNumRecords();
 
360
  
 
361
  UtilTransactions utilTrans(*ctx->getTab());
 
362
  if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
 
363
    return NDBT_FAILED;
 
364
  }
 
365
  return NDBT_OK;
 
366
}
 
367
 
 
368
#define CHECK(b) if (!(b)) { \
 
369
  ndbout << "ERR: "<< step->getName() \
 
370
         << " failed on line " << __LINE__ << endl; \
 
371
  result = NDBT_FAILED; \
 
372
  break; }
 
373
 
 
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++){
 
380
 
 
381
    CHECK(hugoOps.startTransaction(pNdb) == 0);
 
382
    CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
 
383
    CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
384
 
 
385
    ndbout << i <<": Sleeping for " << sleepTime << " ms" << endl;
 
386
    NdbSleep_MilliSleep(sleepTime);
 
387
 
 
388
    // Dont care about result of these ops
 
389
    hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive);
 
390
    hugoOps.closeTransaction(pNdb);
 
391
 
 
392
    sleepTime = sleepTime *i;
 
393
  }
 
394
 
 
395
  hugoOps.closeTransaction(pNdb);
 
396
 
 
397
  return result;
 
398
}
 
399
 
 
400
int runCommit626(NDBT_Context* ctx, NDBT_Step* step){
 
401
  int result = NDBT_OK;
 
402
  HugoOperations hugoOps(*ctx->getTab());
 
403
  Ndb* pNdb = GETNDB(step);
 
404
 
 
405
  do{
 
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);
 
411
 
 
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);
 
419
  }while(false);
 
420
 
 
421
  hugoOps.closeTransaction(pNdb);
 
422
  
 
423
  return result;
 
424
}
 
425
 
 
426
int runCommit630(NDBT_Context* ctx, NDBT_Step* step){
 
427
  int result = NDBT_OK;
 
428
  HugoOperations hugoOps(*ctx->getTab());
 
429
  Ndb* pNdb = GETNDB(step);
 
430
 
 
431
  do{
 
432
    // Commit transaction
 
433
    CHECK(hugoOps.startTransaction(pNdb) == 0);
 
434
    CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
 
435
    CHECK(hugoOps.execute_Commit(pNdb) == 630);
 
436
  }while(false);
 
437
 
 
438
  hugoOps.closeTransaction(pNdb);
 
439
 
 
440
  return result;
 
441
}
 
442
 
 
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);
 
447
 
 
448
  do{
 
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);
 
454
 
 
455
    // Commit transaction, TryCommit
 
456
    // Several operations in one transaction
 
457
    // The insert is OK
 
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);
 
465
  }while(false);
 
466
 
 
467
  hugoOps.closeTransaction(pNdb);
 
468
 
 
469
  return result;
 
470
}
 
471
 
 
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);
 
476
  
 
477
  do{
 
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);
 
482
  }while(false);
 
483
  
 
484
  hugoOps.closeTransaction(pNdb);
 
485
  
 
486
  return result;
 
487
}
 
488
 
 
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);
 
493
 
 
494
  do{
 
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);
 
500
 
 
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);
 
508
 
 
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);
 
513
  } while(false);
 
514
 
 
515
  hugoOps.closeTransaction(pNdb);
 
516
 
 
517
  return result;
 
518
}
 
519
 
 
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);
 
524
 
 
525
  do{
 
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);
 
532
 
 
533
    CHECK(hugoOps.startTransaction(pNdb) == 0);
 
534
    CHECK(hugoOps.pkReadRecord(pNdb, 2) == 0);
 
535
    CHECK(hugoOps.execute_Commit(pNdb) == 0);
 
536
  } while(false);
 
537
 
 
538
  hugoOps.closeTransaction(pNdb);
 
539
  
 
540
  return result;
 
541
}
 
542
 
 
543
int runNoCommit626(NDBT_Context* ctx, NDBT_Step* step){
 
544
  int result = NDBT_OK;
 
545
  HugoOperations hugoOps(*ctx->getTab());
 
546
  Ndb* pNdb = GETNDB(step);
 
547
 
 
548
  do{
 
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);
 
554
 
 
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);
 
559
  }while(false);
 
560
 
 
561
  hugoOps.closeTransaction(pNdb);
 
562
  
 
563
  return result;
 
564
}
 
565
 
 
566
int runNoCommit630(NDBT_Context* ctx, NDBT_Step* step){
 
567
  int result = NDBT_OK;
 
568
  HugoOperations hugoOps(*ctx->getTab());
 
569
  Ndb* pNdb = GETNDB(step);
 
570
 
 
571
  do{
 
572
    // No commit transaction
 
573
    CHECK(hugoOps.startTransaction(pNdb) == 0);
 
574
    CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
 
575
    CHECK(hugoOps.execute_NoCommit(pNdb) == 630);
 
576
  }while(false);
 
577
 
 
578
  hugoOps.closeTransaction(pNdb);
 
579
  
 
580
  return result;
 
581
}
 
582
 
 
583
int runNoCommitRollback626(NDBT_Context* ctx, NDBT_Step* step){
 
584
  int result = NDBT_OK;
 
585
  HugoOperations hugoOps(*ctx->getTab());
 
586
  Ndb* pNdb = GETNDB(step);
 
587
 
 
588
  do{
 
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);
 
595
 
 
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);
 
605
  }while(false);
 
606
 
 
607
  hugoOps.closeTransaction(pNdb);
 
608
  
 
609
  return result;
 
610
}
 
611
 
 
612
int runNoCommitRollback630(NDBT_Context* ctx, NDBT_Step* step){
 
613
  int result = NDBT_OK;
 
614
  HugoOperations hugoOps(*ctx->getTab());
 
615
  Ndb* pNdb = GETNDB(step);
 
616
 
 
617
  do{
 
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);
 
623
  }while(false);
 
624
 
 
625
  hugoOps.closeTransaction(pNdb);
 
626
 
 
627
  return result;
 
628
}
 
629
 
 
630
 
 
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);
 
635
 
 
636
  do{
 
637
    // Read 
 
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);
 
643
  
 
644
    // Update
 
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);
 
650
  
 
651
    // Delete
 
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);
 
657
 
 
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);
 
664
 
 
665
  }while(false);
 
666
 
 
667
  hugoOps.closeTransaction(pNdb);
 
668
 
 
669
  return result;
 
670
}
 
671
 
 
672
 
 
673
 
 
674
int runCheckRollbackDelete(NDBT_Context* ctx, NDBT_Step* step){
 
675
  int result = NDBT_OK;
 
676
  HugoOperations hugoOps(*ctx->getTab());
 
677
  Ndb* pNdb = GETNDB(step);
 
678
 
 
679
  do{
 
680
 
 
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);
 
687
 
 
688
    // Delete record 5
 
689
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
690
    CHECK(hugoOps.pkDeleteRecord(pNdb, 5) == 0);
 
691
    CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
692
 
 
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);
 
697
 
 
698
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
699
 
 
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);
 
705
 
 
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);
 
711
 
 
712
 
 
713
  }while(false);
 
714
 
 
715
  hugoOps.closeTransaction(pNdb);
 
716
 
 
717
  return result;
 
718
}
 
719
 
 
720
int runCheckRollbackUpdate(NDBT_Context* ctx, NDBT_Step* step){
 
721
  int result = NDBT_OK;
 
722
  HugoOperations hugoOps(*ctx->getTab());
 
723
  Ndb* pNdb = GETNDB(step);
 
724
  int numRecords = 5;
 
725
  do{
 
726
    
 
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);
 
733
 
 
734
    // Update  record 5
 
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);
 
738
  
 
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);
 
744
 
 
745
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
746
 
 
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
 
752
 
 
753
  }while(false);
 
754
 
 
755
  hugoOps.closeTransaction(pNdb);
 
756
 
 
757
  return result;
 
758
}
 
759
 
 
760
int runCheckRollbackDeleteMultiple(NDBT_Context* ctx, NDBT_Step* step){
 
761
  int result = NDBT_OK;
 
762
  HugoOperations hugoOps(*ctx->getTab());
 
763
  Ndb* pNdb = GETNDB(step);
 
764
 
 
765
  do{
 
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);
 
772
    
 
773
    Uint32 updatesValue = 0;
 
774
    Uint32 j;
 
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);
 
780
      
 
781
      for(j = 0; j<10; j++){
 
782
        // Update  record 5 - 10
 
783
        updatesValue++;
 
784
        CHECK(hugoOps.pkUpdateRecord(pNdb, 5, 10, updatesValue) == 0);
 
785
        CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
786
 
 
787
        CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
 
788
        CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
789
        CHECK(hugoOps.verifyUpdatesValue(updatesValue) == 0);
 
790
      }      
 
791
      
 
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);
 
796
 
 
797
#if 0
 
798
        // Check records are deleted
 
799
        CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
 
800
        CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
 
801
#endif
 
802
 
 
803
        updatesValue++;
 
804
        CHECK(hugoOps.pkInsertRecord(pNdb, 5, 10, updatesValue) == 0);
 
805
        CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
806
        
 
807
        CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
 
808
        CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
809
        CHECK(hugoOps.verifyUpdatesValue(updatesValue) == 0);
 
810
      }
 
811
 
 
812
      CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
 
813
      CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
814
 
 
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);
 
819
      
 
820
      CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
821
    }
 
822
    
 
823
    // Check records are not deleted
 
824
    // after rollback
 
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);
 
829
    
 
830
  }while(false);
 
831
 
 
832
  hugoOps.closeTransaction(pNdb);
 
833
 
 
834
  return result;
 
835
}
 
836
 
 
837
 
 
838
int runCheckImplicitRollbackDelete(NDBT_Context* ctx, NDBT_Step* step){
 
839
  int result = NDBT_OK;
 
840
  HugoOperations hugoOps(*ctx->getTab());
 
841
  Ndb* pNdb = GETNDB(step);
 
842
 
 
843
  do{
 
844
    // Read  record 5
 
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);
 
849
    
 
850
    // Update  record 5
 
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);
 
855
  
 
856
    // Delete record 5
 
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);
 
861
 
 
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);
 
867
  }while(false);
 
868
 
 
869
  hugoOps.closeTransaction(pNdb);
 
870
 
 
871
  return result;
 
872
}
 
873
 
 
874
int runCheckCommitDelete(NDBT_Context* ctx, NDBT_Step* step){
 
875
  int result = NDBT_OK;
 
876
  HugoOperations hugoOps(*ctx->getTab());
 
877
  Ndb* pNdb = GETNDB(step);
 
878
 
 
879
  do{
 
880
    // Read  10 records
 
881
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
882
    CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
 
883
    CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
884
  
 
885
    // Update 10 records
 
886
    CHECK(hugoOps.pkUpdateRecord(pNdb, 5, 10) == 0);
 
887
    CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
888
  
 
889
    // Delete 10 records
 
890
    CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
 
891
    CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
 
892
 
 
893
    CHECK(hugoOps.execute_Commit(pNdb) == 0);
 
894
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
895
 
 
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);
 
900
 
 
901
  }while(false);
 
902
 
 
903
  hugoOps.closeTransaction(pNdb);
 
904
 
 
905
  return result;
 
906
}
 
907
 
 
908
int runRollbackNothing(NDBT_Context* ctx, NDBT_Step* step){
 
909
  int result = NDBT_OK;
 
910
  HugoOperations hugoOps(*ctx->getTab());
 
911
  Ndb* pNdb = GETNDB(step);
 
912
 
 
913
  do{
 
914
    // Delete record 5 - 15
 
915
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
916
    CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
 
917
    // Rollback 
 
918
    CHECK(hugoOps.execute_Rollback(pNdb) == 0);
 
919
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
920
 
 
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);  
 
926
 
 
927
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
928
    CHECK(hugoOps.execute_Rollback(pNdb) == 0);
 
929
 
 
930
  }while(false);
 
931
 
 
932
  hugoOps.closeTransaction(pNdb);
 
933
 
 
934
  return result;
 
935
}
 
936
 
 
937
int runMassiveRollback(NDBT_Context* ctx, NDBT_Step* step){
 
938
 
 
939
  NdbRestarter restarter;
 
940
  const int records = 4 * restarter.getNumDbNodes();
 
941
 
 
942
  HugoTransactions hugoTrans(*ctx->getTab());
 
943
  if (hugoTrans.loadTable(GETNDB(step), records) != 0){
 
944
    return NDBT_FAILED;
 
945
  }
 
946
  
 
947
  int result = NDBT_OK;
 
948
  HugoOperations hugoOps(*ctx->getTab());
 
949
  Ndb* pNdb = GETNDB(step);
 
950
 
 
951
  const Uint32 OPS_PER_TRANS = 256;
 
952
  const Uint32 OPS_TOTAL = 4096;
 
953
 
 
954
  for(int row = 0; row < records; row++){
 
955
    int res;
 
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);
 
960
      }
 
961
      g_info << "Performed " << (i+OPS_PER_TRANS) << " updates on row: " << row
 
962
             << endl;
 
963
      if(result != NDBT_OK){
 
964
        break;
 
965
      }
 
966
      res = hugoOps.execute_NoCommit(pNdb);
 
967
      if(res != 0){
 
968
        NdbError err = pNdb->getNdbError(res);
 
969
        CHECK(err.classification == NdbError::TimeoutExpired);
 
970
        break;
 
971
      }
 
972
    }
 
973
    if(result != NDBT_OK){
 
974
      break;
 
975
    }
 
976
    g_info << "executeRollback" << endl;
 
977
    CHECK(hugoOps.execute_Rollback(pNdb) == 0);
 
978
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
979
  }
 
980
  
 
981
  hugoOps.closeTransaction(pNdb);
 
982
  return result;
 
983
}
 
984
 
 
985
int
 
986
runMassiveRollback2(NDBT_Context* ctx, NDBT_Step* step){
 
987
 
 
988
  HugoTransactions hugoTrans(*ctx->getTab());
 
989
  if (hugoTrans.loadTable(GETNDB(step), 1) != 0){
 
990
    return NDBT_FAILED;
 
991
  }
 
992
 
 
993
  int result = NDBT_OK;
 
994
  HugoOperations hugoOps(*ctx->getTab());
 
995
  Ndb* pNdb = GETNDB(step);
 
996
 
 
997
  const Uint32 OPS_TOTAL = 4096;
 
998
  const Uint32 LOOPS = 10;
 
999
  
 
1000
  for(Uint32 loop = 0; loop<LOOPS; loop++){
 
1001
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
1002
    for(Uint32 i = 0; i<OPS_TOTAL-1; i ++){
 
1003
      if((i & 1) == 0){
 
1004
        CHECK(hugoOps.pkUpdateRecord(pNdb, 0, 1, loop) == 0);
 
1005
      } else {
 
1006
        CHECK(hugoOps.pkUpdateRecord(pNdb, 1, 1, loop) == 0);
 
1007
      }
 
1008
    }
 
1009
    CHECK(hugoOps.execute_Commit(pNdb) == 626);
 
1010
    CHECK(hugoOps.execute_Rollback(pNdb) == 0);
 
1011
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
1012
  }
 
1013
  
 
1014
  hugoOps.closeTransaction(pNdb);
 
1015
  return result;
 
1016
}
 
1017
 
 
1018
int
 
1019
runMassiveRollback3(NDBT_Context* ctx, NDBT_Step* step){
 
1020
 
 
1021
  int result = NDBT_OK;
 
1022
  HugoOperations hugoOps(*ctx->getTab());
 
1023
  Ndb* pNdb = GETNDB(step);
 
1024
 
 
1025
  const Uint32 BATCH = 10;
 
1026
  const Uint32 OPS_TOTAL = 50;
 
1027
  const Uint32 LOOPS = 100;
 
1028
  
 
1029
  for(Uint32 loop = 0; loop<LOOPS; loop++)
 
1030
  {
 
1031
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
1032
    bool ok = true;
 
1033
    for (Uint32 i = 0; i<OPS_TOTAL; i+= BATCH)
 
1034
    {
 
1035
      CHECK(hugoOps.pkInsertRecord(pNdb, i, BATCH, 0) == 0);
 
1036
      if (hugoOps.execute_NoCommit(pNdb) != 0)
 
1037
      {
 
1038
        ok = false;
 
1039
        break;
 
1040
      }
 
1041
    }
 
1042
    hugoOps.execute_Rollback(pNdb);
 
1043
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
1044
  }
 
1045
  
 
1046
  hugoOps.closeTransaction(pNdb);
 
1047
  return result;
 
1048
}
 
1049
 
 
1050
int
 
1051
runMassiveRollback4(NDBT_Context* ctx, NDBT_Step* step){
 
1052
 
 
1053
  int result = NDBT_OK;
 
1054
  HugoOperations hugoOps(*ctx->getTab());
 
1055
  Ndb* pNdb = GETNDB(step);
 
1056
 
 
1057
  const Uint32 BATCH = 10;
 
1058
  const Uint32 OPS_TOTAL = 20;
 
1059
  const Uint32 LOOPS = 100;
 
1060
  
 
1061
  for(Uint32 loop = 0; loop<LOOPS; loop++)
 
1062
  {
 
1063
    CHECK(hugoOps.startTransaction(pNdb) == 0);  
 
1064
    bool ok = true;
 
1065
    for (Uint32 i = 0; i<OPS_TOTAL; i+= BATCH)
 
1066
    {
 
1067
      CHECK(hugoOps.pkInsertRecord(pNdb, i, BATCH, 0) == 0);
 
1068
      CHECK(hugoOps.pkDeleteRecord(pNdb, i, BATCH) == 0);
 
1069
      if (hugoOps.execute_NoCommit(pNdb) != 0)
 
1070
      {
 
1071
        ok = false;
 
1072
        break;
 
1073
      }
 
1074
    }
 
1075
    hugoOps.execute_Rollback(pNdb);
 
1076
    CHECK(hugoOps.closeTransaction(pNdb) == 0);
 
1077
  }
 
1078
  
 
1079
  hugoOps.closeTransaction(pNdb);
 
1080
  return result;
 
1081
}
 
1082
 
 
1083
/**
 
1084
 * TUP errors
 
1085
 */
 
1086
struct TupError 
 
1087
{
 
1088
  enum Bits {
 
1089
    TE_VARSIZE  = 0x1,
 
1090
    TE_MULTI_OP = 0x2,
 
1091
    TE_DISK     = 0x4,
 
1092
    TE_REPLICA  = 0x8
 
1093
  };
 
1094
  int op;
 
1095
  int error;
 
1096
  int bits;
 
1097
};
 
1098
 
 
1099
static
 
1100
TupError 
 
1101
f_tup_errors[] = 
 
1102
{
 
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
 
1111
  { -1, 0, 0 }
 
1112
};
 
1113
 
 
1114
int
 
1115
runTupErrors(NDBT_Context* ctx, NDBT_Step* step){
 
1116
 
 
1117
  NdbRestarter restarter;
 
1118
  HugoTransactions hugoTrans(*ctx->getTab());
 
1119
  HugoOperations hugoOps(*ctx->getTab());
 
1120
  Ndb* pNdb = GETNDB(step);
 
1121
  
 
1122
  const NdbDictionary::Table * tab = ctx->getTab();
 
1123
  Uint32 i;
 
1124
  int bits = TupError::TE_MULTI_OP;
 
1125
  for(i = 0; i<tab->getNoOfColumns(); i++)
 
1126
  {
 
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;
 
1131
  }
 
1132
 
 
1133
  if (restarter.getNumDbNodes() >= 2)
 
1134
  {
 
1135
    bits |= TupError::TE_REPLICA;
 
1136
  }
 
1137
 
 
1138
  /**
 
1139
   * Insert
 
1140
   */
 
1141
  for(i = 0; f_tup_errors[i].op != -1; i++)
 
1142
  {
 
1143
    if (f_tup_errors[i].op != NdbOperation::InsertRequest)
 
1144
    {
 
1145
      g_info << "Skipping " << f_tup_errors[i].error 
 
1146
             << " -  not insert" << endl;
 
1147
      continue;
 
1148
    }
 
1149
 
 
1150
    if ((f_tup_errors[i].bits & bits) != f_tup_errors[i].bits)
 
1151
    {
 
1152
      g_info << "Skipping " << f_tup_errors[i].error 
 
1153
             << " - req bits: " << hex << f_tup_errors[i].bits
 
1154
             << " bits: " << hex << bits << endl;
 
1155
      continue;
 
1156
    }
 
1157
    
 
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)
 
1161
    {
 
1162
      
 
1163
    }
 
1164
    else
 
1165
    {
 
1166
      hugoTrans.loadTable(pNdb, 5);
 
1167
    }
 
1168
    restarter.insertErrorInAllNodes(0);
 
1169
    if (hugoTrans.clearTable(pNdb, 5) != 0)
 
1170
    {
 
1171
      return NDBT_FAILED;
 
1172
    }      
 
1173
  }
 
1174
  
 
1175
  return NDBT_OK;
 
1176
}
 
1177
 
 
1178
int
 
1179
runInsertError(NDBT_Context* ctx, NDBT_Step* step){
 
1180
 
 
1181
  int result = NDBT_OK;
 
1182
  HugoOperations hugoOp1(*ctx->getTab());
 
1183
  HugoOperations hugoOp2(*ctx->getTab());
 
1184
  Ndb* pNdb = GETNDB(step);
 
1185
 
 
1186
  NdbRestarter restarter;
 
1187
  restarter.insertErrorInAllNodes(4017);
 
1188
  const Uint32 LOOPS = 10;
 
1189
  for (Uint32 i = 0; i<LOOPS; i++)
 
1190
  {
 
1191
    CHECK(hugoOp1.startTransaction(pNdb) == 0);  
 
1192
    CHECK(hugoOp1.pkInsertRecord(pNdb, 1) == 0);
 
1193
    
 
1194
    CHECK(hugoOp2.startTransaction(pNdb) == 0);
 
1195
    CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1) == 0);
 
1196
    
 
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);
 
1203
  }
 
1204
  
 
1205
  restarter.insertErrorInAllNodes(0);
 
1206
  
 
1207
  return result;
 
1208
}
 
1209
 
 
1210
int
 
1211
runInsertError2(NDBT_Context* ctx, NDBT_Step* step){
 
1212
  int result = NDBT_OK;
 
1213
  HugoOperations hugoOp1(*ctx->getTab());
 
1214
  Ndb* pNdb = GETNDB(step);
 
1215
  
 
1216
  NdbRestarter restarter;
 
1217
  restarter.insertErrorInAllNodes(4017);
 
1218
  
 
1219
  const Uint32 LOOPS = 1;
 
1220
  for (Uint32 i = 0; i<LOOPS; i++)
 
1221
  {
 
1222
    CHECK(hugoOp1.startTransaction(pNdb) == 0);  
 
1223
    CHECK(hugoOp1.pkInsertRecord(pNdb, 1) == 0);
 
1224
    CHECK(hugoOp1.pkDeleteRecord(pNdb, 1) == 0);
 
1225
    
 
1226
    hugoOp1.execute_NoCommit(pNdb);
 
1227
    CHECK(hugoOp1.closeTransaction(pNdb) == 0);
 
1228
  }
 
1229
  
 
1230
  restarter.insertErrorInAllNodes(0);
 
1231
  return NDBT_OK;
 
1232
}
 
1233
  
 
1234
int
 
1235
runBug25090(NDBT_Context* ctx, NDBT_Step* step){
 
1236
  
 
1237
  Ndb* pNdb = GETNDB(step);
 
1238
  NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
1239
 
 
1240
  HugoOperations ops(*ctx->getTab());
 
1241
  
 
1242
  int loops = ctx->getNumLoops();
 
1243
  const int rows = ctx->getNumRecords();
 
1244
  
 
1245
  while (loops--)
 
1246
  {
 
1247
    ops.startTransaction(pNdb);
 
1248
    ops.pkReadRecord(pNdb, 1, 1);
 
1249
    ops.execute_Commit(pNdb, AO_IgnoreError);
 
1250
    sleep(10);
 
1251
    ops.closeTransaction(pNdb);
 
1252
  }
 
1253
  
 
1254
  return NDBT_OK;
 
1255
}
 
1256
 
 
1257
int
 
1258
runDeleteRead(NDBT_Context* ctx, NDBT_Step* step){
 
1259
  
 
1260
  Ndb* pNdb = GETNDB(step);
 
1261
 
 
1262
  const NdbDictionary::Table* tab = ctx->getTab();
 
1263
  NDBT_ResultRow row(*ctx->getTab());
 
1264
  HugoTransactions tmp(*ctx->getTab());
 
1265
 
 
1266
  int a;
 
1267
  int loops = ctx->getNumLoops();
 
1268
  const int rows = ctx->getNumRecords();
 
1269
  
 
1270
  while (loops--)
 
1271
  {
 
1272
    NdbTransaction* pTrans = pNdb->startTransaction();
 
1273
    NdbOperation* pOp = pTrans->getNdbOperation(tab->getName());
 
1274
    pOp->deleteTuple();
 
1275
    tmp.equalForRow(pOp, loops);
 
1276
    
 
1277
    // Define attributes to read  
 
1278
    for(a = 0; a<tab->getNoOfColumns(); a++)
 
1279
    {
 
1280
      if((row.attributeStore(a) = pOp->getValue(tab->getColumn(a)->getName())) == 0) {
 
1281
        ERR(pTrans->getNdbError());
 
1282
        return NDBT_FAILED;
 
1283
      }
 
1284
    }
 
1285
 
 
1286
    pTrans->execute(Commit);
 
1287
    pTrans->close();
 
1288
 
 
1289
    pTrans = pNdb->startTransaction();    
 
1290
    pOp = pTrans->getNdbOperation(tab->getName());
 
1291
    pOp->insertTuple();
 
1292
    tmp.setValues(pOp, loops, 0);
 
1293
 
 
1294
    pOp = pTrans->getNdbOperation(tab->getName());
 
1295
    pOp->deleteTuple();
 
1296
    tmp.equalForRow(pOp, loops);
 
1297
    for(a = 0; a<tab->getNoOfColumns(); a++)
 
1298
    {
 
1299
      if((row.attributeStore(a) = pOp->getValue(tab->getColumn(a)->getName())) == 0) 
 
1300
      {
 
1301
        ERR(pTrans->getNdbError());
 
1302
        return NDBT_FAILED;
 
1303
      }
 
1304
    }
 
1305
    if (pTrans->execute(Commit) != 0)
 
1306
    {
 
1307
      ERR(pTrans->getNdbError());
 
1308
      return NDBT_FAILED;
 
1309
    }
 
1310
 
 
1311
    pTrans->close();    
 
1312
  }
 
1313
  
 
1314
  return NDBT_OK;
 
1315
}
 
1316
 
 
1317
int
 
1318
runBug27756(NDBT_Context* ctx, NDBT_Step* step)
 
1319
{
 
1320
  
 
1321
  Ndb* pNdb = GETNDB(step);
 
1322
  NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
1323
  
 
1324
  HugoOperations ops(*ctx->getTab());
 
1325
 
 
1326
  int loops = ctx->getNumLoops();
 
1327
  const int rows = ctx->getNumRecords();
 
1328
  
 
1329
  Vector<Uint64> copies;
 
1330
  while (loops--)
 
1331
  {
 
1332
    ops.startTransaction(pNdb);
 
1333
    ops.pkInsertRecord(pNdb, 1, 1);
 
1334
    ops.execute_NoCommit(pNdb);
 
1335
    
 
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);
 
1342
    
 
1343
    copies.push_back(attr->u_64_value());
 
1344
    ndbout_c("copy at: %llx", copies.back());
 
1345
    ops.execute_NoCommit(pNdb);
 
1346
    
 
1347
    ops.pkDeleteRecord(pNdb, 1, 1);
 
1348
    ops.execute_NoCommit(pNdb);
 
1349
    
 
1350
    if (loops & 1)
 
1351
    {
 
1352
      ops.execute_Rollback(pNdb);
 
1353
      ops.closeTransaction(pNdb);
 
1354
    }
 
1355
    else
 
1356
    {
 
1357
      ops.execute_Commit(pNdb);
 
1358
      ops.closeTransaction(pNdb);
 
1359
      ops.clearTable(pNdb, 100);
 
1360
    }
 
1361
  }
 
1362
  
 
1363
  for (Uint32 i = 0; i<copies.size(); i++)
 
1364
    if (copies[i] != copies.back())
 
1365
    {
 
1366
      ndbout_c("Memleak detected");
 
1367
      return NDBT_FAILED;
 
1368
    }
 
1369
  
 
1370
  return NDBT_OK;
 
1371
}
 
1372
 
 
1373
int
 
1374
runBug28073(NDBT_Context *ctx, NDBT_Step* step)
 
1375
{
 
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;
 
1383
 
 
1384
  while (loops--)
 
1385
  {
 
1386
    if (!inserted)
 
1387
    {
 
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);
 
1392
      inserted= 1;
 
1393
    }
 
1394
 
 
1395
    // Use TC hint to hit the same node in both transactions.
 
1396
    Uint32 key_val= 0;
 
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);
 
1400
 
 
1401
    // First take 2*read lock on the tuple in transaction 1.
 
1402
    for (Uint32 i= 0; i < 2; i++)
 
1403
    {
 
1404
      CHECK(hugoOp1.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
 
1405
      CHECK(hugoOp1.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
 
1406
    }
 
1407
    CHECK(hugoOp1.execute_NoCommit(pNdb) == 0);
 
1408
 
 
1409
    // Now send ops in two transactions, one batch.
 
1410
    // First 2*read in transaction 2.
 
1411
    for (Uint32 i= 0; i < 2; i++)
 
1412
    {
 
1413
      CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
 
1414
      CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
 
1415
    }
 
1416
    CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::NoCommit) == 0);
 
1417
 
 
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);
 
1421
 
 
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);
 
1426
 
 
1427
    // Now commit transaction 2, we should see transaction 1 finish with the
 
1428
    // update.
 
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);
 
1433
 
 
1434
    CHECK(hugoOp1.closeTransaction(pNdb) == 0);
 
1435
    CHECK(hugoOp2.closeTransaction(pNdb) == 0);
 
1436
  }
 
1437
 
 
1438
  return result;
 
1439
}
 
1440
 
 
1441
template class Vector<Uint64>;
 
1442
 
 
1443
int
 
1444
runBug20535(NDBT_Context* ctx, NDBT_Step* step)
 
1445
{
 
1446
  Uint32 i;
 
1447
  Ndb* pNdb = GETNDB(step);
 
1448
  const NdbDictionary::Table * tab = ctx->getTab();
 
1449
  NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
1450
 
 
1451
  bool null = false;
 
1452
  for (i = 0; i<tab->getNoOfColumns(); i++)
 
1453
  {
 
1454
    if (tab->getColumn(i)->getNullable())
 
1455
    {
 
1456
      null = true;
 
1457
      break;
 
1458
    }
 
1459
  }
 
1460
  
 
1461
  if (!null)
 
1462
    return NDBT_OK;
 
1463
 
 
1464
  HugoTransactions hugoTrans(* tab);
 
1465
  hugoTrans.loadTable(pNdb, 1);
 
1466
 
 
1467
  NdbTransaction* pTrans = pNdb->startTransaction();
 
1468
  NdbOperation* pOp = pTrans->getNdbOperation(tab->getName());
 
1469
  pOp->deleteTuple();
 
1470
  hugoTrans.equalForRow(pOp, 0);
 
1471
  if (pTrans->execute(NoCommit) != 0)
 
1472
    return NDBT_FAILED;
 
1473
 
 
1474
  pOp = pTrans->getNdbOperation(tab->getName());
 
1475
  pOp->insertTuple();
 
1476
  hugoTrans.equalForRow(pOp, 0);
 
1477
  for (i = 0; i<tab->getNoOfColumns(); i++)
 
1478
  {
 
1479
    if (!tab->getColumn(i)->getPrimaryKey() &&
 
1480
        !tab->getColumn(i)->getNullable())
 
1481
    {
 
1482
      hugoTrans.setValueForAttr(pOp, i, 0, 1);
 
1483
    }
 
1484
  }
 
1485
  
 
1486
  if (pTrans->execute(Commit) != 0)
 
1487
    return NDBT_FAILED;
 
1488
  
 
1489
  pTrans->close();
 
1490
 
 
1491
  pTrans = pNdb->startTransaction();
 
1492
  pOp = pTrans->getNdbOperation(tab->getName());
 
1493
  pOp->readTuple();
 
1494
  hugoTrans.equalForRow(pOp, 0);
 
1495
  Vector<NdbRecAttr*> values;
 
1496
  for (i = 0; i<tab->getNoOfColumns(); i++)
 
1497
  {
 
1498
    if (!tab->getColumn(i)->getPrimaryKey() &&
 
1499
        tab->getColumn(i)->getNullable())
 
1500
    {
 
1501
      values.push_back(pOp->getValue(i));
 
1502
    }
 
1503
  }
 
1504
  
 
1505
  if (pTrans->execute(Commit) != 0)
 
1506
    return NDBT_FAILED;
 
1507
 
 
1508
  null = true;
 
1509
  for (i = 0; i<values.size(); i++)
 
1510
  {
 
1511
    if (!values[i]->isNULL())
 
1512
    {
 
1513
      null = false;
 
1514
      ndbout_c("column %s is not NULL", values[i]->getColumn()->getName());
 
1515
    }
 
1516
  }
 
1517
  
 
1518
  pTrans->close();  
 
1519
  
 
1520
  if (null)
 
1521
    return NDBT_OK;
 
1522
  else
 
1523
    return NDBT_FAILED;
 
1524
}
 
1525
 
 
1526
template class Vector<NdbRecAttr*>;
 
1527
 
 
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);
 
1534
}
 
1535
TESTCASE("PkRead", 
 
1536
           "Verify that we can insert, read and delete from this table using PK"){
 
1537
  TC_PROPERTY("LockMode", NdbOperation::LM_Read);
 
1538
  INITIALIZER(runLoadTable);
 
1539
  STEP(runPkRead);
 
1540
  FINALIZER(runClearTable);
 
1541
}
 
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);
 
1546
  STEP(runPkRead);
 
1547
  FINALIZER(runClearTable);
 
1548
}
 
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);
 
1553
  STEP(runPkRead);
 
1554
  FINALIZER(runClearTable);
 
1555
}
 
1556
TESTCASE("PkUpdate", 
 
1557
           "Verify that we can insert, update and delete from this table using PK"){
 
1558
  INITIALIZER(runLoadTable);
 
1559
  STEP(runPkUpdate);
 
1560
  FINALIZER(runClearTable);
 
1561
}
 
1562
TESTCASE("PkDelete", 
 
1563
         "Verify that we can delete from this table using PK"){
 
1564
  INITIALIZER(runLoadTable);
 
1565
  STEP(runPkDelete);
 
1566
  FINALIZER(runClearTable);
 
1567
}
 
1568
TESTCASE("UpdateAndRead", 
 
1569
         "Verify that we can read and update at the same time"){
 
1570
  INITIALIZER(runLoadTable);
 
1571
  STEP(runPkRead);
 
1572
  STEP(runPkRead);
 
1573
  STEP(runPkRead);
 
1574
  STEP(runPkUpdate);  
 
1575
  STEP(runPkUpdate);
 
1576
  STEP(runPkUpdate);
 
1577
  FINALIZER(runClearTable);
 
1578
}
 
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);
 
1584
  STEP(runLocker);
 
1585
  FINALIZER(runClearTable);
 
1586
}
 
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);
 
1597
  STEP(runLocker);
 
1598
  FINALIZER(runClearTable);
 
1599
}
 
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);
 
1608
  STEP(runLocker);
 
1609
  FINALIZER(runClearTable);
 
1610
}
 
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);
 
1617
  STEP(runLocker);
 
1618
  STEP(runInsertUntilStopped);
 
1619
  FINALIZER(runClearTable);
 
1620
}
 
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);
 
1627
}
 
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);
 
1634
}
 
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);
 
1641
}
 
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);
 
1649
}
 
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);
 
1657
}
 
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);
 
1664
}
 
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);
 
1672
}
 
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);
 
1679
}
 
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);
 
1687
}
 
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);
 
1695
}
 
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);
 
1702
}
 
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);
 
1710
}
 
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);
 
1717
}
 
1718
TESTCASE("RollbackDelete", 
 
1719
         "Test rollback of a no committed delete"){
 
1720
  INITIALIZER(runLoadTable);
 
1721
  INITIALIZER(runCheckRollbackDelete);
 
1722
  FINALIZER(runClearTable2);
 
1723
}
 
1724
TESTCASE("RollbackUpdate", 
 
1725
         "Test rollback of a no committed update"){
 
1726
  INITIALIZER(runLoadTable);
 
1727
  INITIALIZER(runCheckRollbackUpdate);
 
1728
  FINALIZER(runClearTable2);
 
1729
}
 
1730
TESTCASE("RollbackDeleteMultiple", 
 
1731
         "Test rollback of 10 non committed delete"){
 
1732
  INITIALIZER(runLoadTable);
 
1733
  INITIALIZER(runCheckRollbackDeleteMultiple);
 
1734
  FINALIZER(runClearTable2);
 
1735
}
 
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);
 
1742
}
 
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);
 
1749
}
 
1750
TESTCASE("RollbackNothing", 
 
1751
         "Test rollback of nothing"){
 
1752
  INITIALIZER(runLoadTable);
 
1753
  INITIALIZER(runRollbackNothing);
 
1754
  FINALIZER(runClearTable2);
 
1755
}
 
1756
TESTCASE("MassiveRollback", 
 
1757
         "Test rollback of 4096 operations"){
 
1758
  INITIALIZER(runClearTable2);
 
1759
  INITIALIZER(runMassiveRollback);
 
1760
  FINALIZER(runClearTable2);
 
1761
}
 
1762
TESTCASE("MassiveRollback2", 
 
1763
         "Test rollback of 4096 operations"){
 
1764
  INITIALIZER(runClearTable2);
 
1765
  INITIALIZER(runMassiveRollback2);
 
1766
  FINALIZER(runClearTable2);
 
1767
}
 
1768
TESTCASE("MassiveRollback3", 
 
1769
         "Test rollback of 4096 operations"){
 
1770
  INITIALIZER(runClearTable2);
 
1771
  STEP(runMassiveRollback3);
 
1772
  STEP(runMassiveRollback3);
 
1773
  FINALIZER(runClearTable2);
 
1774
}
 
1775
TESTCASE("MassiveRollback4", 
 
1776
         "Test rollback of 4096 operations"){
 
1777
  INITIALIZER(runClearTable2);
 
1778
  STEP(runMassiveRollback4);
 
1779
  STEP(runMassiveRollback4);
 
1780
  FINALIZER(runClearTable2);
 
1781
}
 
1782
TESTCASE("MassiveTransaction",
 
1783
         "Test very large insert transaction"){
 
1784
  INITIALIZER(runLoadTable2);
 
1785
  FINALIZER(runClearTable2);
 
1786
}
 
1787
TESTCASE("TupError", 
 
1788
         "Verify what happens when we fill the db" ){
 
1789
  INITIALIZER(runTupErrors);
 
1790
}
 
1791
TESTCASE("InsertError", "" ){
 
1792
  INITIALIZER(runInsertError);
 
1793
}
 
1794
TESTCASE("InsertError2", "" ){
 
1795
  INITIALIZER(runInsertError2);
 
1796
}
 
1797
TESTCASE("Fill", 
 
1798
         "Verify what happens when we fill the db" ){
 
1799
  INITIALIZER(runFillTable);
 
1800
  INITIALIZER(runPkRead);
 
1801
  FINALIZER(runClearTable2);
 
1802
}
 
1803
TESTCASE("Bug25090", 
 
1804
         "Verify what happens when we fill the db" ){
 
1805
  STEP(runBug25090);
 
1806
}
 
1807
TESTCASE("DeleteRead", 
 
1808
         "Verify Delete+Read" ){
 
1809
  INITIALIZER(runLoadTable);
 
1810
  INITIALIZER(runDeleteRead);
 
1811
  FINALIZER(runClearTable2);
 
1812
}
 
1813
TESTCASE("Bug27756", 
 
1814
         "Verify what happens when we fill the db" ){
 
1815
  STEP(runBug27756);
 
1816
}
 
1817
TESTCASE("Bug28073", 
 
1818
         "Infinite loop in lock queue" ){
 
1819
  STEP(runBug28073);
 
1820
}
 
1821
TESTCASE("Bug20535", 
 
1822
         "Verify what happens when we fill the db" ){
 
1823
  STEP(runBug20535);
 
1824
}
 
1825
NDBT_TESTSUITE_END(testBasic);
 
1826
 
 
1827
#if 0
 
1828
TESTCASE("ReadConsistency",
 
1829
         "Check that a read within a transaction returns the " \
 
1830
         "same result no matter"){
 
1831
  STEP(runInsertOne);
 
1832
  STEP(runReadOne);
 
1833
  FINALIZER(runClearTable2);
 
1834
}
 
1835
TESTCASE("Fill", 
 
1836
         "Verify what happens when we fill the db" ){
 
1837
  INITIALIZER(runFillTable);
 
1838
  INITIALIZER(runPkRead);
 
1839
  FINALIZER(runClearTable2);
 
1840
}
 
1841
#endif
 
1842
 
 
1843
int main(int argc, const char** argv){
 
1844
  ndb_init();
 
1845
  return testBasic.execute(argc, argv);
 
1846
}
 
1847
 
 
1848
 
 
1849