~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <NDBT.hpp>
 
17
#include <NDBT_Test.hpp>
 
18
#include <HugoTransactions.hpp>
 
19
#include <UtilTransactions.hpp>
 
20
#include <NdbRestarter.hpp>
 
21
#include <NdbRestarts.hpp>
 
22
#include <Vector.hpp>
 
23
#include <signaldata/DumpStateOrd.hpp>
 
24
 
 
25
#define CHECK(b) if (!(b)) { \
 
26
  g_err << "ERR: "<< step->getName() \
 
27
         << " failed on line " << __LINE__ << endl; \
 
28
  result = NDBT_FAILED; break;\
 
29
 
30
 
 
31
 
 
32
struct Attrib {
 
33
  bool indexCreated;
 
34
  int numAttribs;
 
35
  int attribs[1024];
 
36
  Attrib(){
 
37
    numAttribs = 0;
 
38
    indexCreated = false;
 
39
  }
 
40
};
 
41
class AttribList {
 
42
public:
 
43
  AttribList(){};
 
44
  ~AttribList(){
 
45
    for(size_t i = 0; i < attriblist.size(); i++){      
 
46
      delete attriblist[i];
 
47
    }
 
48
  };
 
49
  void buildAttribList(const NdbDictionary::Table* pTab); 
 
50
  Vector<Attrib*> attriblist;
 
51
};
 
52
 
 
53
void AttribList::buildAttribList(const NdbDictionary::Table* pTab){
 
54
  attriblist.clear();
 
55
 
 
56
  Attrib* attr;
 
57
  // Build attrib definitions that describes which attributes to build index
 
58
  // Try to build strange combinations, not just "all" or all PK's
 
59
 
 
60
  int i;
 
61
 
 
62
  for(i = 1; i <= pTab->getNoOfColumns(); i++){
 
63
    attr = new Attrib;
 
64
    attr->numAttribs = i;
 
65
    for(int a = 0; a<i; a++)
 
66
      attr->attribs[a] = a;
 
67
    attriblist.push_back(attr);
 
68
  }
 
69
  int b = 0;
 
70
  for(i = pTab->getNoOfColumns()-1; i > 0; i--){
 
71
    attr = new Attrib;
 
72
    attr->numAttribs = i;
 
73
    b++;
 
74
    for(int a = 0; a<i; a++)
 
75
      attr->attribs[a] = a+b;
 
76
    attriblist.push_back(attr);
 
77
  }
 
78
  for(i = pTab->getNoOfColumns(); i > 0;  i--){
 
79
    attr = new Attrib;
 
80
    attr->numAttribs = pTab->getNoOfColumns() - i;
 
81
    for(int a = 0; a<pTab->getNoOfColumns() - i; a++)
 
82
      attr->attribs[a] = pTab->getNoOfColumns()-a-1;
 
83
    attriblist.push_back(attr); 
 
84
  }  
 
85
  for(i = 1; i < pTab->getNoOfColumns(); i++){
 
86
    attr = new Attrib;
 
87
    attr->numAttribs = pTab->getNoOfColumns() - i;
 
88
    for(int a = 0; a<pTab->getNoOfColumns() - i; a++)
 
89
      attr->attribs[a] = pTab->getNoOfColumns()-a-1;
 
90
    attriblist.push_back(attr); 
 
91
  }  
 
92
  for(i = 1; i < pTab->getNoOfColumns(); i++){
 
93
    attr = new Attrib;
 
94
    attr->numAttribs = 2;
 
95
    for(int a = 0; a<2; a++){
 
96
      attr->attribs[a] = i%pTab->getNoOfColumns();
 
97
    }
 
98
    attriblist.push_back(attr);
 
99
  }
 
100
 
 
101
  // Last 
 
102
  attr = new Attrib;
 
103
  attr->numAttribs = 1;
 
104
  attr->attribs[0] = pTab->getNoOfColumns()-1;
 
105
  attriblist.push_back(attr);
 
106
 
 
107
  // Last and first
 
108
  attr = new Attrib;
 
109
  attr->numAttribs = 2;
 
110
  attr->attribs[0] = pTab->getNoOfColumns()-1;
 
111
  attr->attribs[1] = 0;
 
112
  attriblist.push_back(attr); 
 
113
 
 
114
  // First and last
 
115
  attr = new Attrib;
 
116
  attr->numAttribs = 2;
 
117
  attr->attribs[0] = 0;
 
118
  attr->attribs[1] = pTab->getNoOfColumns()-1;
 
119
  attriblist.push_back(attr);  
 
120
 
 
121
#if 0
 
122
  for(size_t i = 0; i < attriblist.size(); i++){
 
123
 
 
124
    ndbout << attriblist[i]->numAttribs << ": " ;
 
125
    for(int a = 0; a < attriblist[i]->numAttribs; a++)
 
126
      ndbout << attriblist[i]->attribs[a] << ", ";
 
127
    ndbout << endl;
 
128
  }
 
129
#endif
 
130
 
 
131
}
 
132
 
 
133
char idxName[255];
 
134
char pkIdxName[255];
 
135
 
 
136
static const int SKIP_INDEX = 99;
 
137
 
 
138
int create_index(NDBT_Context* ctx, int indxNum, 
 
139
                 const NdbDictionary::Table* pTab, 
 
140
                 Ndb* pNdb, Attrib* attr, bool logged){
 
141
  bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
 
142
  int result  = NDBT_OK;
 
143
 
 
144
  HugoCalculator calc(*pTab);
 
145
 
 
146
  if (attr->numAttribs == 1 && 
 
147
      calc.isUpdateCol(attr->attribs[0]) == true){
 
148
    // Don't create index for the Hugo update column
 
149
    // since it's not unique
 
150
    return SKIP_INDEX;
 
151
  }
 
152
 
 
153
  // Create index    
 
154
  BaseString::snprintf(idxName, 255, "IDC%d", indxNum);
 
155
  if (orderedIndex)
 
156
    ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "<<idxName << " (";
 
157
  else
 
158
    ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "<<idxName << " (";
 
159
  ndbout << flush;
 
160
  NdbDictionary::Index pIdx(idxName);
 
161
  pIdx.setTable(pTab->getName());
 
162
  if (orderedIndex)
 
163
    pIdx.setType(NdbDictionary::Index::OrderedIndex);
 
164
  else
 
165
    pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
 
166
  for (int c = 0; c< attr->numAttribs; c++){
 
167
    int attrNo = attr->attribs[c];
 
168
    pIdx.addIndexColumn(pTab->getColumn(attrNo)->getName());
 
169
    ndbout << pTab->getColumn(attrNo)->getName()<<" ";
 
170
  }
 
171
  
 
172
  pIdx.setStoredIndex(logged);
 
173
  ndbout << ") ";
 
174
  if (pNdb->getDictionary()->createIndex(pIdx) != 0){
 
175
    attr->indexCreated = false;
 
176
    ndbout << "FAILED!" << endl;
 
177
    const NdbError err = pNdb->getDictionary()->getNdbError();
 
178
    ERR(err);
 
179
    if(err.classification == NdbError::ApplicationError)
 
180
      return SKIP_INDEX;
 
181
    
 
182
    return NDBT_FAILED;
 
183
  } else {
 
184
    ndbout << "OK!" << endl;
 
185
    attr->indexCreated = true;
 
186
  }
 
187
  return result;
 
188
}
 
189
 
 
190
 
 
191
int drop_index(int indxNum, Ndb* pNdb, 
 
192
               const NdbDictionary::Table* pTab, Attrib* attr){
 
193
  int result = NDBT_OK;
 
194
 
 
195
  if (attr->indexCreated == false)
 
196
    return NDBT_OK;     
 
197
 
 
198
  BaseString::snprintf(idxName, 255, "IDC%d", indxNum);
 
199
  
 
200
  // Drop index
 
201
  ndbout << "Dropping index "<<idxName<<"(" << pTab->getName() << ") ";
 
202
  if (pNdb->getDictionary()->dropIndex(idxName, pTab->getName()) != 0){
 
203
    ndbout << "FAILED!" << endl;
 
204
    ERR(pNdb->getDictionary()->getNdbError());
 
205
    result = NDBT_FAILED;
 
206
  } else {
 
207
    ndbout << "OK!" << endl;
 
208
  }     
 
209
  return result;
 
210
}
 
211
 
 
212
int runCreateIndexes(NDBT_Context* ctx, NDBT_Step* step){
 
213
  int loops = ctx->getNumLoops();
 
214
  int l = 0;
 
215
  const NdbDictionary::Table* pTab = ctx->getTab();
 
216
  Ndb* pNdb = GETNDB(step);
 
217
  int result = NDBT_OK;
 
218
  // NOTE If we need to test creating both logged and non logged indexes
 
219
  // this should be divided into two testcases
 
220
  // The paramater logged should then be specified 
 
221
  // as a TC_PROPERTY. ex TC_PROPERTY("LoggedIndexes", 1);
 
222
  // and read into the test step like
 
223
  bool logged = ctx->getProperty("LoggedIndexes", 1);
 
224
 
 
225
  AttribList attrList;
 
226
  attrList.buildAttribList(pTab);
 
227
 
 
228
 
 
229
  while (l < loops && result == NDBT_OK){
 
230
    unsigned int i;
 
231
    for (i = 0; i < attrList.attriblist.size(); i++){
 
232
      
 
233
      // Try to create index
 
234
      if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED)
 
235
        result = NDBT_FAILED;      
 
236
    }
 
237
    
 
238
    // Now drop all indexes that where created
 
239
    for (i = 0; i < attrList.attriblist.size(); i++){
 
240
            
 
241
      // Try to drop index
 
242
      if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK)
 
243
        result = NDBT_FAILED;                        
 
244
    }
 
245
    
 
246
    l++;
 
247
  }
 
248
  
 
249
  return result;
 
250
}
 
251
 
 
252
int createRandomIndex(NDBT_Context* ctx, NDBT_Step* step){
 
253
  const NdbDictionary::Table* pTab = ctx->getTab();
 
254
  Ndb* pNdb = GETNDB(step);
 
255
  bool logged = ctx->getProperty("LoggedIndexes", 1);
 
256
 
 
257
  AttribList attrList;
 
258
  attrList.buildAttribList(pTab);
 
259
 
 
260
  int retries = 100;
 
261
  while(retries > 0){
 
262
    const Uint32 i = rand() % attrList.attriblist.size();
 
263
    int res = create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], 
 
264
                           logged);
 
265
    if (res == SKIP_INDEX){
 
266
      retries--;
 
267
      continue;
 
268
    }
 
269
 
 
270
    if (res == NDBT_FAILED){
 
271
      return NDBT_FAILED;
 
272
    }
 
273
    
 
274
    ctx->setProperty("createRandomIndex", i);
 
275
    // Now drop all indexes that where created
 
276
    
 
277
    return NDBT_OK;
 
278
  }
 
279
  
 
280
  return NDBT_FAILED;
 
281
}
 
282
 
 
283
int createRandomIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
 
284
  Ndb* pNdb = GETNDB(step);
 
285
 
 
286
  Uint32 i = ctx->getProperty("createRandomIndex");
 
287
  
 
288
  BaseString::snprintf(idxName, 255, "IDC%d", i);
 
289
  
 
290
  // Drop index
 
291
  ndbout << "Dropping index " << idxName << " ";
 
292
  if (pNdb->getDictionary()->dropIndex(idxName, 
 
293
                                       ctx->getTab()->getName()) != 0){
 
294
    ndbout << "FAILED!" << endl;
 
295
    ERR(pNdb->getDictionary()->getNdbError());
 
296
    return NDBT_FAILED;
 
297
  } else {
 
298
    ndbout << "OK!" << endl;
 
299
  }     
 
300
  
 
301
  return NDBT_OK;
 
302
}
 
303
 
 
304
int createPkIndex(NDBT_Context* ctx, NDBT_Step* step){
 
305
  bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
 
306
 
 
307
  const NdbDictionary::Table* pTab = ctx->getTab();
 
308
  Ndb* pNdb = GETNDB(step);
 
309
 
 
310
  bool logged = ctx->getProperty("LoggedIndexes", 1);
 
311
 
 
312
  // Create index    
 
313
  BaseString::snprintf(pkIdxName, 255, "IDC_PK_%s", pTab->getName());
 
314
  if (orderedIndex)
 
315
    ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "
 
316
           << pkIdxName << " (";
 
317
  else
 
318
    ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "
 
319
           << pkIdxName << " (";
 
320
 
 
321
  NdbDictionary::Index pIdx(pkIdxName);
 
322
  pIdx.setTable(pTab->getName());
 
323
  if (orderedIndex)
 
324
    pIdx.setType(NdbDictionary::Index::OrderedIndex);
 
325
  else
 
326
    pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
 
327
  for (int c = 0; c< pTab->getNoOfColumns(); c++){
 
328
    const NdbDictionary::Column * col = pTab->getColumn(c);
 
329
    if(col->getPrimaryKey()){
 
330
      pIdx.addIndexColumn(col->getName());
 
331
      ndbout << col->getName() <<" ";
 
332
    }
 
333
  }
 
334
  
 
335
  pIdx.setStoredIndex(logged);
 
336
  ndbout << ") ";
 
337
  if (pNdb->getDictionary()->createIndex(pIdx) != 0){
 
338
    ndbout << "FAILED!" << endl;
 
339
    const NdbError err = pNdb->getDictionary()->getNdbError();
 
340
    ERR(err);
 
341
    return NDBT_FAILED;
 
342
  }
 
343
 
 
344
  ndbout << "OK!" << endl;
 
345
  return NDBT_OK;
 
346
}
 
347
 
 
348
int createPkIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
 
349
  const NdbDictionary::Table* pTab = ctx->getTab();
 
350
  Ndb* pNdb = GETNDB(step);
 
351
 
 
352
  // Drop index
 
353
  ndbout << "Dropping index " << pkIdxName << " ";
 
354
  if (pNdb->getDictionary()->dropIndex(pkIdxName, 
 
355
                                       pTab->getName()) != 0){
 
356
    ndbout << "FAILED!" << endl;
 
357
    ERR(pNdb->getDictionary()->getNdbError());
 
358
    return NDBT_FAILED;
 
359
  } else {
 
360
    ndbout << "OK!" << endl;
 
361
  }
 
362
  
 
363
  return NDBT_OK;
 
364
}
 
365
 
 
366
int
 
367
runVerifyIndex(NDBT_Context* ctx, NDBT_Step* step){
 
368
  // Verify that data in index match 
 
369
  // table data
 
370
  Ndb* pNdb = GETNDB(step);
 
371
  UtilTransactions utilTrans(*ctx->getTab());
 
372
  const int batchSize = ctx->getProperty("BatchSize", 16);
 
373
  const int parallelism = batchSize > 240 ? 240 : batchSize;
 
374
 
 
375
  do {
 
376
    if (utilTrans.verifyIndex(pNdb, idxName, parallelism, true) != 0){
 
377
      g_err << "Inconsistent index" << endl;
 
378
      return NDBT_FAILED;
 
379
    }
 
380
  } while(ctx->isTestStopped() == false);
 
381
  return NDBT_OK;
 
382
}
 
383
 
 
384
int
 
385
runTransactions1(NDBT_Context* ctx, NDBT_Step* step){
 
386
  // Verify that data in index match 
 
387
  // table data
 
388
  Ndb* pNdb = GETNDB(step);
 
389
  HugoTransactions hugoTrans(*ctx->getTab());
 
390
  const int batchSize = ctx->getProperty("BatchSize", 50);
 
391
 
 
392
  int rows = ctx->getNumRecords();
 
393
  while (ctx->isTestStopped() == false) {
 
394
    if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
 
395
      g_err << "Updated table failed" << endl;
 
396
      return NDBT_FAILED;
 
397
    }    
 
398
 
 
399
    ctx->sync_down("PauseThreads");
 
400
    if(ctx->isTestStopped())
 
401
      break;
 
402
    
 
403
    if (hugoTrans.scanUpdateRecords(pNdb, rows, batchSize) != 0){
 
404
      g_err << "Updated table failed" << endl;
 
405
      return NDBT_FAILED;
 
406
    }    
 
407
    
 
408
    ctx->sync_down("PauseThreads");
 
409
  }
 
410
  return NDBT_OK;
 
411
}
 
412
 
 
413
int
 
414
runTransactions2(NDBT_Context* ctx, NDBT_Step* step){
 
415
  // Verify that data in index match 
 
416
  // table data
 
417
  Ndb* pNdb = GETNDB(step);
 
418
  HugoTransactions hugoTrans(*ctx->getTab());
 
419
  const int batchSize = ctx->getProperty("BatchSize", 50);
 
420
 
 
421
  int rows = ctx->getNumRecords();
 
422
  while (ctx->isTestStopped() == false) {
 
423
#if 1
 
424
    if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchSize) != 0){
 
425
      g_err << "Index read failed" << endl;
 
426
      return NDBT_FAILED;
 
427
    }
 
428
#endif
 
429
    ctx->sync_down("PauseThreads");
 
430
    if(ctx->isTestStopped())
 
431
      break;
 
432
#if 1
 
433
    if (hugoTrans.indexUpdateRecords(pNdb, pkIdxName, rows, batchSize) != 0){
 
434
      g_err << "Index update failed" << endl;
 
435
      return NDBT_FAILED;
 
436
    }
 
437
#endif
 
438
    ctx->sync_down("PauseThreads");
 
439
  }
 
440
  return NDBT_OK;
 
441
}
 
442
 
 
443
int
 
444
runTransactions3(NDBT_Context* ctx, NDBT_Step* step){
 
445
  // Verify that data in index match 
 
446
  // table data
 
447
  Ndb* pNdb = GETNDB(step);
 
448
  HugoTransactions hugoTrans(*ctx->getTab());
 
449
  UtilTransactions utilTrans(*ctx->getTab());
 
450
  const int batchSize = ctx->getProperty("BatchSize", 32);
 
451
  const int parallel = batchSize > 240 ? 240 : batchSize;
 
452
 
 
453
  int rows = ctx->getNumRecords();
 
454
  while (ctx->isTestStopped() == false) {
 
455
    if(hugoTrans.loadTable(pNdb, rows, batchSize, false) != 0){
 
456
      g_err << "Load table failed" << endl;
 
457
      return NDBT_FAILED;
 
458
    }
 
459
    ctx->sync_down("PauseThreads");
 
460
    if(ctx->isTestStopped())
 
461
      break;
 
462
 
 
463
    if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
 
464
      g_err << "Updated table failed" << endl;
 
465
      return NDBT_FAILED;
 
466
    }    
 
467
 
 
468
    ctx->sync_down("PauseThreads");
 
469
    if(ctx->isTestStopped())
 
470
      break;
 
471
    
 
472
    if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchSize) != 0){
 
473
      g_err << "Index read failed" << endl;
 
474
      return NDBT_FAILED;
 
475
    }
 
476
    
 
477
    ctx->sync_down("PauseThreads");
 
478
    if(ctx->isTestStopped())
 
479
      break;
 
480
    
 
481
    if (hugoTrans.indexUpdateRecords(pNdb, pkIdxName, rows, batchSize) != 0){
 
482
      g_err << "Index update failed" << endl;
 
483
      return NDBT_FAILED;
 
484
    }
 
485
    
 
486
    ctx->sync_down("PauseThreads");
 
487
    if(ctx->isTestStopped())
 
488
      break;
 
489
 
 
490
    if (hugoTrans.scanUpdateRecords(pNdb, rows, 5, parallel) != 0){
 
491
      g_err << "Scan updated table failed" << endl;
 
492
      return NDBT_FAILED;
 
493
    }
 
494
 
 
495
    ctx->sync_down("PauseThreads");
 
496
    if(ctx->isTestStopped())
 
497
      break;
 
498
 
 
499
    if(utilTrans.clearTable(pNdb, rows, parallel) != 0){
 
500
      g_err << "Clear table failed" << endl;
 
501
      return NDBT_FAILED;
 
502
    }
 
503
 
 
504
    ctx->sync_down("PauseThreads");
 
505
    if(ctx->isTestStopped())
 
506
      break;
 
507
    
 
508
    int count = -1;
 
509
    if(utilTrans.selectCount(pNdb, 64, &count) != 0 || count != 0)
 
510
      return NDBT_FAILED;
 
511
    ctx->sync_down("PauseThreads");
 
512
  }
 
513
  return NDBT_OK;
 
514
}
 
515
 
 
516
int runRestarts(NDBT_Context* ctx, NDBT_Step* step){
 
517
  int result = NDBT_OK;
 
518
  int loops = ctx->getNumLoops();
 
519
  NDBT_TestCase* pCase = ctx->getCase();
 
520
  NdbRestarts restarts;
 
521
  int i = 0;
 
522
  int timeout = 240;
 
523
  int sync_threads = ctx->getProperty("Threads", (unsigned)0);
 
524
 
 
525
  while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
 
526
    if(restarts.executeRestart("RestartRandomNodeAbort", timeout) != 0){
 
527
      g_err << "Failed to executeRestart(" <<pCase->getName() <<")" << endl;
 
528
      result = NDBT_FAILED;
 
529
      break;
 
530
    }    
 
531
    ctx->sync_up_and_wait("PauseThreads", sync_threads);
 
532
    i++;
 
533
  }
 
534
  ctx->stopTest();
 
535
  return result;
 
536
}
 
537
 
 
538
int runCreateLoadDropIndex(NDBT_Context* ctx, NDBT_Step* step){
 
539
  int loops = ctx->getNumLoops();
 
540
  int records = ctx->getNumRecords();
 
541
  int l = 0;
 
542
  const NdbDictionary::Table* pTab = ctx->getTab();
 
543
  Ndb* pNdb = GETNDB(step);
 
544
  int result = NDBT_OK;
 
545
  int batchSize = ctx->getProperty("BatchSize", 1);
 
546
  int parallelism = batchSize > 240? 240: batchSize;
 
547
  ndbout << "batchSize="<<batchSize<<endl;
 
548
  bool logged = ctx->getProperty("LoggedIndexes", 1);
 
549
 
 
550
  HugoTransactions hugoTrans(*pTab);
 
551
  UtilTransactions utilTrans(*pTab);
 
552
  AttribList attrList;
 
553
  attrList.buildAttribList(pTab);
 
554
 
 
555
  for (unsigned int i = 0; i < attrList.attriblist.size(); i++){
 
556
        
 
557
    while (l < loops && result == NDBT_OK){
 
558
 
 
559
      if ((l % 2) == 0){
 
560
        // Create index first and then load
 
561
        
 
562
        // Try to create index
 
563
        if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED){
 
564
          result = NDBT_FAILED;      
 
565
        }
 
566
        
 
567
        // Load the table with data
 
568
        ndbout << "Loading data after" << endl;
 
569
        CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
 
570
        
 
571
        
 
572
      } else {
 
573
        // Load table then create index
 
574
        
 
575
        // Load the table with data
 
576
        ndbout << "Loading data before" << endl;
 
577
        CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
 
578
        
 
579
        // Try to create index
 
580
        if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED)
 
581
          result = NDBT_FAILED;      
 
582
        
 
583
      }
 
584
      
 
585
      // Verify that data in index match 
 
586
      // table data
 
587
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
588
      
 
589
      // Do it all...
 
590
      ndbout <<"Doing it all"<<endl;
 
591
      int count;
 
592
      ndbout << "  pkUpdateRecords" << endl;
 
593
      CHECK(hugoTrans.pkUpdateRecords(pNdb, records, batchSize) == 0);
 
594
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
595
      CHECK(hugoTrans.pkUpdateRecords(pNdb, records, batchSize) == 0);
 
596
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
597
      ndbout << "  pkDelRecords half" << endl;
 
598
      CHECK(hugoTrans.pkDelRecords(pNdb, records/2, batchSize) == 0);
 
599
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
600
      ndbout << "  scanUpdateRecords" << endl;
 
601
      CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2, parallelism) == 0);
 
602
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
603
      ndbout << "  clearTable" << endl;
 
604
      CHECK(utilTrans.clearTable(pNdb, records/2, parallelism) == 0);
 
605
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
606
      CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
607
      CHECK(count == 0);
 
608
      ndbout << "  loadTable" << endl;
 
609
      CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
 
610
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
611
      ndbout << "  loadTable again" << endl;
 
612
      CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
 
613
      CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
614
      CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
615
      CHECK(count == records);
 
616
 
 
617
 
 
618
      if ((l % 2) == 0){
 
619
        // Drop index first and then clear
 
620
        
 
621
        // Try to create index
 
622
        if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK){
 
623
          result = NDBT_FAILED;      
 
624
        }
 
625
        
 
626
        // Clear table
 
627
        ndbout << "Clearing table after" << endl;
 
628
        CHECK(hugoTrans.clearTable(pNdb, records, parallelism) == 0);
 
629
        
 
630
        
 
631
      } else {
 
632
        // Clear table then drop index
 
633
        
 
634
        //Clear table
 
635
        ndbout << "Clearing table before" << endl;
 
636
        CHECK(hugoTrans.clearTable(pNdb, records, parallelism) == 0);
 
637
        
 
638
        // Try to drop index
 
639
        if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK)
 
640
          result = NDBT_FAILED;         
 
641
      }
 
642
      
 
643
      ndbout << "  Done!" << endl;
 
644
      l++;
 
645
    }
 
646
      
 
647
    // Make sure index is dropped
 
648
    drop_index(i, pNdb, pTab, attrList.attriblist[i]);
 
649
 
 
650
  }
 
651
 
 
652
  return result;
 
653
}
 
654
 
 
655
int runInsertDelete(NDBT_Context* ctx, NDBT_Step* step){
 
656
  int loops = ctx->getNumLoops();
 
657
  int records = ctx->getNumRecords();
 
658
  const NdbDictionary::Table* pTab = ctx->getTab();
 
659
  Ndb* pNdb = GETNDB(step);
 
660
  int result = NDBT_OK;
 
661
  int batchSize = ctx->getProperty("BatchSize", 1);
 
662
  int parallelism = batchSize > 240? 240: batchSize;
 
663
  ndbout << "batchSize="<<batchSize<<endl;
 
664
  bool logged = ctx->getProperty("LoggedIndexes", 1);
 
665
 
 
666
  HugoTransactions hugoTrans(*pTab);
 
667
  UtilTransactions utilTrans(*pTab);  
 
668
 
 
669
  AttribList attrList;
 
670
  attrList.buildAttribList(pTab);
 
671
 
 
672
  for (unsigned int i = 0; i < attrList.attriblist.size(); i++){
 
673
    
 
674
    Attrib* attr = attrList.attriblist[i]; 
 
675
    // Create index
 
676
    if (create_index(ctx, i, pTab, pNdb, attr, logged) == NDBT_OK){
 
677
      int l = 1;
 
678
      while (l <= loops && result == NDBT_OK){
 
679
  
 
680
        CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
 
681
        CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
682
        CHECK(utilTrans.clearTable(pNdb, records, parallelism) == 0);
 
683
        CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
 
684
        l++;        
 
685
      }            
 
686
      
 
687
      // Drop index
 
688
      if (drop_index(i, pNdb, pTab, attr) != NDBT_OK)
 
689
        result = NDBT_FAILED;                        
 
690
    }    
 
691
  }
 
692
  
 
693
  return result;
 
694
}
 
695
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
 
696
  int records = ctx->getNumRecords();
 
697
  
 
698
  HugoTransactions hugoTrans(*ctx->getTab());
 
699
  int batchSize = ctx->getProperty("BatchSize", 1);
 
700
  if(hugoTrans.loadTable(GETNDB(step), records, batchSize) != 0){
 
701
    return NDBT_FAILED;
 
702
  }
 
703
  return NDBT_OK;
 
704
}
 
705
 
 
706
 
 
707
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
 
708
  int records = ctx->getNumRecords();
 
709
  
 
710
  UtilTransactions utilTrans(*ctx->getTab());
 
711
  if (utilTrans.clearTable(GETNDB(step),  records) != 0){
 
712
    return NDBT_FAILED;
 
713
  }
 
714
  return NDBT_OK;
 
715
}
 
716
 
 
717
int runSystemRestart1(NDBT_Context* ctx, NDBT_Step* step){
 
718
  Ndb* pNdb = GETNDB(step);
 
719
  int result = NDBT_OK;
 
720
  int timeout = 300;
 
721
  Uint32 loops = ctx->getNumLoops();
 
722
  int records = ctx->getNumRecords();
 
723
  int count;
 
724
  NdbRestarter restarter;
 
725
  Uint32 i = 1;
 
726
 
 
727
  UtilTransactions utilTrans(*ctx->getTab());
 
728
  HugoTransactions hugoTrans(*ctx->getTab());
 
729
  const char * name = ctx->getTab()->getName();
 
730
  while(i<=loops && result != NDBT_FAILED){
 
731
 
 
732
    ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
 
733
    /*
 
734
      1. Load data
 
735
      2. Restart cluster and verify records
 
736
      3. Update records
 
737
      4. Restart cluster and verify records
 
738
      5. Delete half of the records
 
739
      6. Restart cluster and verify records
 
740
      7. Delete all records
 
741
      8. Restart cluster and verify records
 
742
      9. Insert, update, delete records
 
743
      10. Restart cluster and verify records
 
744
      11. Insert, update, delete records
 
745
      12. Restart cluster with error insert 5020 and verify records
 
746
    */
 
747
    ndbout << "Loading records..." << endl;
 
748
    CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
 
749
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
750
    
 
751
    ndbout << "Restarting cluster" << endl;
 
752
    CHECK(restarter.restartAll() == 0);
 
753
    CHECK(restarter.waitClusterStarted(timeout) == 0);
 
754
    CHECK(pNdb->waitUntilReady(timeout) == 0);
 
755
 
 
756
    ndbout << "Verifying records..." << endl;
 
757
    CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
 
758
    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
759
    CHECK(count == records);
 
760
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
761
 
 
762
    ndbout << "Updating records..." << endl;
 
763
    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
 
764
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
765
 
 
766
    ndbout << "Restarting cluster..." << endl;
 
767
    CHECK(restarter.restartAll() == 0);
 
768
    CHECK(restarter.waitClusterStarted(timeout) == 0);
 
769
    CHECK(pNdb->waitUntilReady(timeout) == 0);
 
770
 
 
771
    ndbout << "Verifying records..." << endl;
 
772
    CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
 
773
    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
774
    CHECK(count == records);
 
775
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
776
    
 
777
    ndbout << "Deleting 50% of records..." << endl;
 
778
    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
 
779
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
780
 
 
781
    ndbout << "Restarting cluster..." << endl;
 
782
    CHECK(restarter.restartAll() == 0);
 
783
    CHECK(restarter.waitClusterStarted(timeout) == 0);
 
784
    CHECK(pNdb->waitUntilReady(timeout) == 0);
 
785
 
 
786
    ndbout << "Verifying records..." << endl;
 
787
    CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
 
788
    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
789
    CHECK(count == (records/2));
 
790
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
791
 
 
792
    ndbout << "Deleting all records..." << endl;
 
793
    CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
 
794
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
795
 
 
796
    ndbout << "Restarting cluster..." << endl;
 
797
    CHECK(restarter.restartAll() == 0);
 
798
    CHECK(restarter.waitClusterStarted(timeout) == 0);
 
799
    CHECK(pNdb->waitUntilReady(timeout) == 0);
 
800
 
 
801
    ndbout << "Verifying records..." << endl;
 
802
    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
803
    CHECK(count == 0);
 
804
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
805
 
 
806
    ndbout << "Doing it all..." << endl;
 
807
    CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
 
808
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
809
    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
 
810
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
811
    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
 
812
    CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
 
813
    CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
 
814
    CHECK(utilTrans.clearTable(pNdb, records) == 0);
 
815
    CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
 
816
    CHECK(utilTrans.clearTable(pNdb, records) == 0);
 
817
    CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
 
818
    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
 
819
    CHECK(utilTrans.clearTable(pNdb, records) == 0);
 
820
 
 
821
    ndbout << "Restarting cluster..." << endl;
 
822
    CHECK(restarter.restartAll() == 0);
 
823
    CHECK(restarter.waitClusterStarted(timeout) == 0);
 
824
    CHECK(pNdb->waitUntilReady(timeout) == 0);
 
825
 
 
826
    ndbout << "Verifying records..." << endl;
 
827
    CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
 
828
    CHECK(count == 0);
 
829
 
 
830
    ndbout << "Doing it all..." << endl;
 
831
    CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
 
832
    CHECK(utilTrans.verifyIndex(pNdb, idxName,  16, false) == 0);
 
833
    CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
 
834
    CHECK(utilTrans.verifyIndex(pNdb, idxName,  16, false) == 0);
 
835
    CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
 
836
    CHECK(utilTrans.verifyIndex(pNdb, idxName,  16, false) == 0);
 
837
    CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
 
838
    CHECK(utilTrans.verifyIndex(pNdb, idxName,  16, false) == 0);
 
839
    CHECK(utilTrans.clearTable(pNdb, records) == 0);
 
840
    CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
 
841
    CHECK(utilTrans.clearTable(pNdb, records) == 0);
 
842
 
 
843
    ndbout << "Restarting cluster with error insert 5020..." << endl;
 
844
    CHECK(restarter.restartAll(false, true) == 0);
 
845
    CHECK(restarter.waitClusterNoStart(timeout) == 0);
 
846
    CHECK(restarter.insertErrorInAllNodes(5020) == 0);
 
847
    CHECK(restarter.startAll() == 0);
 
848
    CHECK(restarter.waitClusterStarted(timeout) == 0);
 
849
    CHECK(pNdb->waitUntilReady(timeout) == 0);
 
850
    
 
851
    i++;
 
852
  }
 
853
 
 
854
  ctx->stopTest();
 
855
  ndbout << "runSystemRestart1 finished" << endl;  
 
856
 
 
857
  return result;
 
858
}
 
859
 
 
860
#define CHECK2(b, t) if(!b){ g_err << __LINE__ << ": " << t << endl; break;}
 
861
 
 
862
int
 
863
runMixed1(NDBT_Context* ctx, NDBT_Step* step){
 
864
  // Verify that data in index match 
 
865
  // table data
 
866
  Ndb* pNdb = GETNDB(step);
 
867
  HugoOperations hugoOps(*ctx->getTab());
 
868
 
 
869
 
 
870
  do {
 
871
    // TC1
 
872
    g_err << "pkRead, indexRead, Commit" << endl;
 
873
    CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction");
 
874
    CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
 
875
    CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord");
 
876
    CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
 
877
    CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction");
 
878
 
 
879
    // TC1
 
880
    g_err << "pkRead, indexRead, Commit" << endl;
 
881
    CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction");
 
882
    CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord");
 
883
    CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
 
884
    CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
 
885
    CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction");
 
886
    
 
887
 
 
888
    // TC2
 
889
    g_err << "pkRead, indexRead, NoCommit, Commit" << endl;
 
890
    CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction");
 
891
    CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord");
 
892
    CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0,
 
893
           "indexReadRecords");
 
894
    CHECK2(hugoOps.execute_NoCommit(pNdb) == 0, "executeNoCommit");
 
895
    CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
 
896
    CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction");
 
897
 
 
898
    // TC3
 
899
    g_err << "pkRead, pkRead, Commit" << endl;
 
900
    CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction ");
 
901
    CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecords ");
 
902
    CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecords ");
 
903
    CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
 
904
    CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction ");
 
905
 
 
906
    // TC4
 
907
    g_err << "indexRead, indexRead, Commit" << endl;
 
908
 
 
909
    CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction ");
 
910
    CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
 
911
    CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
 
912
    CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
 
913
 
 
914
    CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction ");
 
915
 
 
916
    return NDBT_OK;
 
917
  } while(false);
 
918
 
 
919
 
 
920
  hugoOps.closeTransaction(pNdb);
 
921
  return NDBT_FAILED;
 
922
}
 
923
 
 
924
int
 
925
runBuildDuring(NDBT_Context* ctx, NDBT_Step* step){
 
926
  // Verify that data in index match 
 
927
  // table data
 
928
  const int Threads = ctx->getProperty("Threads", (Uint32)0);
 
929
  const int loops = ctx->getNumLoops();
 
930
 
 
931
  for(int i = 0; i<loops; i++){
 
932
#if 1
 
933
    if(createPkIndex(ctx, step) != NDBT_OK){
 
934
      g_err << "Failed to create index" << endl;
 
935
      return NDBT_FAILED;
 
936
    }
 
937
#endif
 
938
 
 
939
    if(ctx->isTestStopped())
 
940
      break;
 
941
 
 
942
#if 1
 
943
    if(createRandomIndex(ctx, step) != NDBT_OK){
 
944
      g_err << "Failed to create index" << endl;
 
945
      return NDBT_FAILED;
 
946
    }
 
947
#endif
 
948
 
 
949
    if(ctx->isTestStopped())
 
950
      break;
 
951
 
 
952
    ctx->setProperty("pause", 1);
 
953
    int count = 0;
 
954
    for(int j = 0; count < Threads && !ctx->isTestStopped(); 
 
955
        j = (j+1) % Threads){
 
956
      char buf[255];
 
957
      sprintf(buf, "Thread%d_paused", j);
 
958
      int tmp = ctx->getProperty(buf, (Uint32)0);
 
959
      count += tmp;
 
960
    }
 
961
    
 
962
    if(ctx->isTestStopped())
 
963
      break;
 
964
 
 
965
#if 1
 
966
    if(createPkIndex_Drop(ctx, step) != NDBT_OK){
 
967
      g_err << "Failed to drop index" << endl;
 
968
      return NDBT_FAILED;
 
969
    }
 
970
#endif
 
971
 
 
972
    if(ctx->isTestStopped())
 
973
      break;
 
974
    
 
975
#if 1
 
976
    if(createRandomIndex_Drop(ctx, step) != NDBT_OK){
 
977
      g_err << "Failed to drop index" << endl;
 
978
      return NDBT_FAILED;
 
979
    }
 
980
#endif
 
981
 
 
982
    ctx->setProperty("pause", (Uint32)0);
 
983
    NdbSleep_SecSleep(2);
 
984
  }
 
985
 
 
986
  ctx->stopTest();
 
987
  return NDBT_OK;
 
988
}
 
989
 
 
990
static NdbLockable g_lock;
 
991
static int threadCounter = 0;
 
992
 
 
993
void
 
994
wait_paused(NDBT_Context* ctx, int id){
 
995
  if(ctx->getProperty("pause", (Uint32)0) == 1){
 
996
    char buf[255];
 
997
    sprintf(buf, "Thread%d_paused", id);
 
998
    ctx->setProperty(buf, 1);
 
999
    while(!ctx->isTestStopped() && ctx->getProperty("pause", (Uint32)0) == 1){
 
1000
      NdbSleep_MilliSleep(250);
 
1001
    }
 
1002
    ctx->setProperty(buf, (Uint32)0);
 
1003
  }
 
1004
}
 
1005
 
 
1006
int
 
1007
runTransactions4(NDBT_Context* ctx, NDBT_Step* step){
 
1008
 
 
1009
  g_lock.lock();
 
1010
  const int ThreadId = threadCounter++;
 
1011
  g_lock.unlock();
 
1012
  
 
1013
  // Verify that data in index match 
 
1014
  // table data
 
1015
  Ndb* pNdb = GETNDB(step);
 
1016
  HugoTransactions hugoTrans(*ctx->getTab());
 
1017
  UtilTransactions utilTrans(*ctx->getTab());
 
1018
  const int batchSize = ctx->getProperty("BatchSize", 32);
 
1019
  const int parallel = batchSize > 240 ? 240 : batchSize;
 
1020
 
 
1021
  int rows = ctx->getNumRecords();
 
1022
  while (ctx->isTestStopped() == false) {
 
1023
    if(hugoTrans.loadTable(pNdb, rows, batchSize, false) != 0){
 
1024
      g_err << "Load table failed" << endl;
 
1025
      return NDBT_FAILED;
 
1026
    }
 
1027
 
 
1028
    wait_paused(ctx, ThreadId);
 
1029
 
 
1030
    if(ctx->isTestStopped())
 
1031
      break;
 
1032
 
 
1033
    if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
 
1034
      g_err << "Updated table failed" << endl;
 
1035
      return NDBT_FAILED;
 
1036
    }    
 
1037
 
 
1038
    wait_paused(ctx, ThreadId);
 
1039
    
 
1040
    if(ctx->isTestStopped())
 
1041
      break;
 
1042
    
 
1043
    if (hugoTrans.scanUpdateRecords(pNdb, rows, 5, parallel) != 0){
 
1044
      g_err << "Scan updated table failed" << endl;
 
1045
      return NDBT_FAILED;
 
1046
    }
 
1047
 
 
1048
    wait_paused(ctx, ThreadId);
 
1049
 
 
1050
    if(ctx->isTestStopped())
 
1051
      break;
 
1052
 
 
1053
    if(utilTrans.clearTable(pNdb, rows, parallel) != 0){
 
1054
      g_err << "Clear table failed" << endl;
 
1055
      return NDBT_FAILED;
 
1056
    }
 
1057
  }
 
1058
  return NDBT_OK;
 
1059
}
 
1060
 
 
1061
int
 
1062
runUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){
 
1063
  Ndb* pNdb = GETNDB(step);
 
1064
 
 
1065
  bool logged = ctx->getProperty("LoggedIndexes", 1);
 
1066
  bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
 
1067
  NdbConnection * pTrans = 0;
 
1068
 
 
1069
  const NdbDictionary::Table* pTab = ctx->getTab();
 
1070
  // Create index    
 
1071
  char nullIndex[255];
 
1072
  BaseString::snprintf(nullIndex, 255, "IDC_PK_%s_NULL", pTab->getName());
 
1073
  if (orderedIndex)
 
1074
    ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "
 
1075
           << pkIdxName << " (";
 
1076
  else
 
1077
    ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "
 
1078
           << pkIdxName << " (";
 
1079
 
 
1080
  NdbDictionary::Index pIdx(pkIdxName);
 
1081
  pIdx.setTable(pTab->getName());
 
1082
  if (orderedIndex)
 
1083
    pIdx.setType(NdbDictionary::Index::OrderedIndex);
 
1084
  else
 
1085
    pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
 
1086
  pIdx.setStoredIndex(logged);
 
1087
  int c;
 
1088
  for (c = 0; c< pTab->getNoOfColumns(); c++){
 
1089
    const NdbDictionary::Column * col = pTab->getColumn(c);
 
1090
    if(col->getPrimaryKey()){
 
1091
      pIdx.addIndexColumn(col->getName());
 
1092
      ndbout << col->getName() <<" ";
 
1093
    }
 
1094
  }
 
1095
  
 
1096
  int colId = -1;
 
1097
  for (c = 0; c< pTab->getNoOfColumns(); c++){
 
1098
    const NdbDictionary::Column * col = pTab->getColumn(c);
 
1099
    if(col->getNullable()){
 
1100
      pIdx.addIndexColumn(col->getName());
 
1101
      ndbout << col->getName() <<" ";
 
1102
      colId = c;
 
1103
      break;
 
1104
    }
 
1105
  }
 
1106
  ndbout << ") ";
 
1107
 
 
1108
  if(colId == -1){
 
1109
    ndbout << endl << "No nullable column found -> NDBT_FAILED" << endl; 
 
1110
    return NDBT_FAILED;
 
1111
  }
 
1112
  
 
1113
  if (pNdb->getDictionary()->createIndex(pIdx) != 0){
 
1114
    ndbout << "FAILED!" << endl;
 
1115
    const NdbError err = pNdb->getDictionary()->getNdbError();
 
1116
    ERR(err);
 
1117
    return NDBT_FAILED;
 
1118
  }
 
1119
  
 
1120
  int result = NDBT_OK;
 
1121
 
 
1122
  HugoTransactions hugoTrans(*ctx->getTab());
 
1123
  const int batchSize = ctx->getProperty("BatchSize", 50);
 
1124
  int loops = ctx->getNumLoops();
 
1125
  int rows = ctx->getNumRecords();
 
1126
  while (loops-- > 0 && ctx->isTestStopped() == false) {
 
1127
    if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
 
1128
      g_err << "Updated table failed" << endl;
 
1129
      result = NDBT_FAILED;
 
1130
      goto done;
 
1131
    }    
 
1132
  }
 
1133
 
 
1134
  if(ctx->isTestStopped()){
 
1135
    goto done;
 
1136
  }
 
1137
 
 
1138
  ctx->stopTest();
 
1139
  while(ctx->getNoOfRunningSteps() > 1){
 
1140
    NdbSleep_MilliSleep(100);
 
1141
  }
 
1142
 
 
1143
  result = NDBT_FAILED;
 
1144
  pTrans = pNdb->startTransaction();
 
1145
  NdbScanOperation * sOp;
 
1146
  NdbOperation * uOp;
 
1147
  int eof;
 
1148
  if(!pTrans) goto done;
 
1149
  sOp = pTrans->getNdbScanOperation(pTab->getName());
 
1150
  if(!sOp) goto done;
 
1151
  if(sOp->readTuples(NdbScanOperation::LM_Exclusive)) goto done;
 
1152
  if(pTrans->execute(NoCommit) == -1) goto done;
 
1153
  while((eof = sOp->nextResult(true)) == 0){
 
1154
    do {
 
1155
      NdbOperation * uOp = sOp->updateCurrentTuple();
 
1156
      if(uOp == 0) goto done;
 
1157
      uOp->setValue(colId, 0);
 
1158
    } while((eof = sOp->nextResult(false)) == 0);
 
1159
    eof = pTrans->execute(Commit);
 
1160
    if(eof == -1) goto done;
 
1161
  }
 
1162
  
 
1163
 done:
 
1164
  if(pTrans) pNdb->closeTransaction(pTrans);
 
1165
  pNdb->getDictionary()->dropIndex(nullIndex, pTab->getName());
 
1166
  return result;
 
1167
}
 
1168
 
 
1169
int runLQHKEYREF(NDBT_Context* ctx, NDBT_Step* step){
 
1170
  int result = NDBT_OK;
 
1171
  int loops = ctx->getNumLoops() * 100;
 
1172
  NdbRestarter restarter;
 
1173
  
 
1174
  myRandom48Init(NdbTick_CurrentMillisecond());
 
1175
 
 
1176
#if 0
 
1177
  int val = DumpStateOrd::DihMinTimeBetweenLCP;
 
1178
  if(restarter.dumpStateAllNodes(&val, 1) != 0){
 
1179
    g_err << "Failed to dump DihMinTimeBetweenLCP" << endl;
 
1180
    return NDBT_FAILED;
 
1181
  }
 
1182
#endif
 
1183
 
 
1184
  for(int i = 0; i<loops && !ctx->isTestStopped(); i++){
 
1185
    int randomId = myRandom48(restarter.getNumDbNodes());
 
1186
    int nodeId = restarter.getDbNodeId(randomId);
 
1187
 
 
1188
    const Uint32 error = 5031 + (i % 3);
 
1189
    
 
1190
    if(restarter.insertErrorInNode(nodeId, error) != 0){
 
1191
      g_err << "Failed to error insert( " << error << ") in node "
 
1192
            << nodeId << endl;
 
1193
      return NDBT_FAILED;
 
1194
    }
 
1195
  }
 
1196
  
 
1197
  ctx->stopTest();
 
1198
  return NDBT_OK;
 
1199
}
 
1200
 
 
1201
int 
 
1202
runBug21384(NDBT_Context* ctx, NDBT_Step* step)
 
1203
{
 
1204
  Ndb* pNdb = GETNDB(step);
 
1205
  HugoTransactions hugoTrans(*ctx->getTab());
 
1206
  NdbRestarter restarter;
 
1207
  
 
1208
  int loops = ctx->getNumLoops();
 
1209
  const int rows = ctx->getNumRecords();
 
1210
  const int batchsize = ctx->getProperty("BatchSize", 50);
 
1211
  
 
1212
  while (loops--)
 
1213
  {
 
1214
    if(restarter.insertErrorInAllNodes(8037) != 0)
 
1215
    {
 
1216
      g_err << "Failed to error insert(8037)" << endl;
 
1217
      return NDBT_FAILED;
 
1218
    }
 
1219
    
 
1220
    if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchsize) == 0)
 
1221
    {
 
1222
      g_err << "Index succeded (it should have failed" << endl;
 
1223
      return NDBT_FAILED;
 
1224
    }
 
1225
    
 
1226
    if(restarter.insertErrorInAllNodes(0) != 0)
 
1227
    {
 
1228
      g_err << "Failed to error insert(0)" << endl;
 
1229
      return NDBT_FAILED;
 
1230
    }
 
1231
    
 
1232
    if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchsize) != 0){
 
1233
      g_err << "Index read failed" << endl;
 
1234
      return NDBT_FAILED;
 
1235
    }
 
1236
  }
 
1237
  
 
1238
  return NDBT_OK;
 
1239
}
 
1240
 
 
1241
int 
 
1242
runBug25059(NDBT_Context* ctx, NDBT_Step* step)
 
1243
{
 
1244
  Ndb* pNdb = GETNDB(step);
 
1245
  NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
1246
  const NdbDictionary::Index * idx = dict->getIndex(pkIdxName, 
 
1247
                                                    ctx->getTab()->getName());
 
1248
 
 
1249
  HugoOperations ops(*ctx->getTab(), idx);
 
1250
  
 
1251
  int res = NDBT_OK;
 
1252
  int loops = ctx->getNumLoops();
 
1253
  const int rows = ctx->getNumRecords();
 
1254
  
 
1255
  while (res == NDBT_OK && loops--)
 
1256
  {
 
1257
    ops.startTransaction(pNdb);
 
1258
    ops.pkReadRecord(pNdb, 10 + rand() % rows, rows);
 
1259
    int tmp;
 
1260
    if (tmp = ops.execute_Commit(pNdb, AO_IgnoreError))
 
1261
    {
 
1262
      if (tmp == 4012)
 
1263
        res = NDBT_FAILED;
 
1264
      else
 
1265
        if (ops.getTransaction()->getNdbError().code == 4012)
 
1266
          res = NDBT_FAILED;
 
1267
    }
 
1268
    ops.closeTransaction(pNdb);
 
1269
  }
 
1270
  
 
1271
  loops = ctx->getNumLoops();
 
1272
  while (res == NDBT_OK && loops--)
 
1273
  {
 
1274
    ops.startTransaction(pNdb);
 
1275
    ops.pkUpdateRecord(pNdb, 10 + rand() % rows, rows);
 
1276
    int tmp;
 
1277
    int arg;
 
1278
    switch(rand() % 2){
 
1279
    case 0:
 
1280
      arg = AbortOnError;
 
1281
      break;
 
1282
    case 1:
 
1283
      arg = AO_IgnoreError;
 
1284
      ndbout_c("ignore error");
 
1285
      break;
 
1286
    }
 
1287
    if (tmp = ops.execute_Commit(pNdb, (AbortOption)arg))
 
1288
    {
 
1289
      if (tmp == 4012)
 
1290
        res = NDBT_FAILED;
 
1291
      else
 
1292
        if (ops.getTransaction()->getNdbError().code == 4012)
 
1293
          res = NDBT_FAILED;
 
1294
    }
 
1295
    ops.closeTransaction(pNdb);
 
1296
  }  
 
1297
  
 
1298
  return res;
 
1299
}
 
1300
 
 
1301
int tcSaveINDX_test(NDBT_Context* ctx, NDBT_Step* step, int inject_err)
 
1302
{
 
1303
  int result= NDBT_OK;
 
1304
  Ndb* pNdb = GETNDB(step);
 
1305
  NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
1306
  const NdbDictionary::Index * idx = dict->getIndex(pkIdxName, 
 
1307
                                                    ctx->getTab()->getName());
 
1308
 
 
1309
  HugoOperations ops(*ctx->getTab(), idx);
 
1310
 
 
1311
  g_err << "Using INDEX: " << pkIdxName << endl;
 
1312
 
 
1313
  NdbRestarter restarter;
 
1314
 
 
1315
  int loops = ctx->getNumLoops();
 
1316
  const int rows = ctx->getNumRecords();
 
1317
  const int batchsize = ctx->getProperty("BatchSize", 1);
 
1318
 
 
1319
  for(int bs=1; bs < loops; bs++)
 
1320
  {
 
1321
    int c= 0;
 
1322
    while (c++ < loops)
 
1323
    {
 
1324
      g_err << "BS " << bs << " LOOP #" << c << endl;
 
1325
 
 
1326
      g_err << "inserting error on op#" << c << endl;
 
1327
 
 
1328
      CHECK(ops.startTransaction(pNdb) == 0);
 
1329
      for(int i=1;i<=c;i++)
 
1330
      {
 
1331
        if(i==c)
 
1332
        {
 
1333
          if(restarter.insertErrorInAllNodes(inject_err)!=0)
 
1334
          {
 
1335
            g_err << "**** FAILED to insert error" << endl;
 
1336
            result= NDBT_FAILED;
 
1337
            break;
 
1338
          }
 
1339
        }
 
1340
        CHECK(ops.indexReadRecords(pNdb, pkIdxName, i,false,1) == 0);
 
1341
        if(i%bs==0 || i==c)
 
1342
        {
 
1343
          if(i<c)
 
1344
          {
 
1345
            if(ops.execute_NoCommit(pNdb, AO_IgnoreError)!=NDBT_OK)
 
1346
            {
 
1347
              g_err << "**** executeNoCommit should have succeeded" << endl;
 
1348
              result= NDBT_FAILED;
 
1349
            }
 
1350
          }
 
1351
          else
 
1352
          {
 
1353
            if(ops.execute_NoCommit(pNdb, AO_IgnoreError)!=289)
 
1354
            {
 
1355
              g_err << "**** executeNoCommit should have failed with 289"
 
1356
                    << endl;
 
1357
              result= NDBT_FAILED;
 
1358
            }
 
1359
            g_err << "NdbError.code= " <<
 
1360
              ops.getTransaction()->getNdbError().code << endl;
 
1361
            break;
 
1362
          }
 
1363
        }
 
1364
      }
 
1365
 
 
1366
      CHECK(ops.closeTransaction(pNdb) == 0);
 
1367
 
 
1368
      if(restarter.insertErrorInAllNodes(0) != 0)
 
1369
      {
 
1370
        g_err << "**** Failed to error insert(0)" << endl;
 
1371
        return NDBT_FAILED;
 
1372
      }
 
1373
 
 
1374
      CHECK(ops.startTransaction(pNdb) == 0);
 
1375
      if (ops.indexReadRecords(pNdb, pkIdxName,0,0,rows) != 0){
 
1376
        g_err << "**** Index read failed" << endl;
 
1377
        return NDBT_FAILED;
 
1378
      }
 
1379
      CHECK(ops.closeTransaction(pNdb) == 0);
 
1380
    }
 
1381
  }
 
1382
 
 
1383
  return result;
 
1384
}
 
1385
 
 
1386
int
 
1387
runBug28804(NDBT_Context* ctx, NDBT_Step* step)
 
1388
{
 
1389
  return tcSaveINDX_test(ctx, step, 8052);
 
1390
}
 
1391
 
 
1392
int
 
1393
runBug28804_ATTRINFO(NDBT_Context* ctx, NDBT_Step* step)
 
1394
{
 
1395
  return tcSaveINDX_test(ctx, step, 8051);
 
1396
}
 
1397
 
 
1398
NDBT_TESTSUITE(testIndex);
 
1399
TESTCASE("CreateAll", 
 
1400
         "Test that we can create all various indexes on each table\n"
 
1401
         "Then drop the indexes\n"){
 
1402
  INITIALIZER(runCreateIndexes);
 
1403
}
 
1404
TESTCASE("CreateAll_O",
 
1405
         "Test that we can create all various indexes on each table\n"
 
1406
         "Then drop the indexes\n"){
 
1407
  TC_PROPERTY("OrderedIndex", 1);
 
1408
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1409
  INITIALIZER(runCreateIndexes);
 
1410
}
 
1411
TESTCASE("InsertDeleteGentle", 
 
1412
         "Create one index, then perform insert and delete in the table\n"
 
1413
         "loop number of times. Use batch size 1."){
 
1414
  TC_PROPERTY("BatchSize", 1);
 
1415
  INITIALIZER(runInsertDelete);
 
1416
  FINALIZER(runClearTable);
 
1417
}
 
1418
TESTCASE("InsertDeleteGentle_O",
 
1419
         "Create one index, then perform insert and delete in the table\n"
 
1420
         "loop number of times. Use batch size 1."){
 
1421
  TC_PROPERTY("OrderedIndex", 1);
 
1422
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1423
  TC_PROPERTY("BatchSize", 1);
 
1424
  INITIALIZER(runInsertDelete);
 
1425
  FINALIZER(runClearTable);
 
1426
}
 
1427
TESTCASE("InsertDelete", 
 
1428
         "Create one index, then perform insert and delete in the table\n"
 
1429
         "loop number of times. Use batchsize 512 to stress db more"){
 
1430
  TC_PROPERTY("BatchSize", 512);
 
1431
  INITIALIZER(runInsertDelete);
 
1432
  FINALIZER(runClearTable);
 
1433
 
 
1434
}
 
1435
TESTCASE("InsertDelete_O", 
 
1436
         "Create one index, then perform insert and delete in the table\n"
 
1437
         "loop number of times. Use batchsize 512 to stress db more"){
 
1438
  TC_PROPERTY("OrderedIndex", 1);
 
1439
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1440
  TC_PROPERTY("BatchSize", 512);
 
1441
  INITIALIZER(runInsertDelete);
 
1442
  FINALIZER(runClearTable);
 
1443
 
 
1444
}
 
1445
TESTCASE("CreateLoadDropGentle", 
 
1446
         "Try to create, drop and load various indexes \n"
 
1447
         "on table loop number of times.Usa batch size 1.\n"){
 
1448
  TC_PROPERTY("BatchSize", 1);
 
1449
  INITIALIZER(runCreateLoadDropIndex);
 
1450
}
 
1451
TESTCASE("CreateLoadDropGentle_O", 
 
1452
         "Try to create, drop and load various indexes \n"
 
1453
         "on table loop number of times.Usa batch size 1.\n"){
 
1454
  TC_PROPERTY("OrderedIndex", 1);
 
1455
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1456
  TC_PROPERTY("BatchSize", 1);
 
1457
  INITIALIZER(runCreateLoadDropIndex);
 
1458
}
 
1459
TESTCASE("CreateLoadDrop", 
 
1460
         "Try to create, drop and load various indexes \n"
 
1461
         "on table loop number of times. Use batchsize 512 to stress db more\n"){
 
1462
  TC_PROPERTY("BatchSize", 512);
 
1463
  INITIALIZER(runCreateLoadDropIndex);
 
1464
}
 
1465
TESTCASE("CreateLoadDrop_O", 
 
1466
         "Try to create, drop and load various indexes \n"
 
1467
         "on table loop number of times. Use batchsize 512 to stress db more\n"){
 
1468
  TC_PROPERTY("OrderedIndex", 1);
 
1469
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1470
  TC_PROPERTY("BatchSize", 512);
 
1471
  INITIALIZER(runCreateLoadDropIndex);
 
1472
}
 
1473
TESTCASE("NFNR1", 
 
1474
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1475
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1476
  TC_PROPERTY("PauseThreads", 2);
 
1477
  INITIALIZER(runClearTable);
 
1478
  INITIALIZER(createRandomIndex);
 
1479
  INITIALIZER(runLoadTable);
 
1480
  STEP(runRestarts);
 
1481
  STEP(runTransactions1);
 
1482
  STEP(runTransactions1);
 
1483
  FINALIZER(runVerifyIndex);
 
1484
  FINALIZER(createRandomIndex_Drop);
 
1485
  FINALIZER(runClearTable);
 
1486
}
 
1487
TESTCASE("NFNR1_O", 
 
1488
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1489
  TC_PROPERTY("OrderedIndex", 1);
 
1490
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1491
  TC_PROPERTY("PauseThreads", 2);
 
1492
  INITIALIZER(runClearTable);
 
1493
  INITIALIZER(createRandomIndex);
 
1494
  INITIALIZER(runLoadTable);
 
1495
  STEP(runRestarts);
 
1496
  STEP(runTransactions1);
 
1497
  STEP(runTransactions1);
 
1498
  FINALIZER(runVerifyIndex);
 
1499
  FINALIZER(createRandomIndex_Drop);
 
1500
  FINALIZER(runClearTable);
 
1501
}
 
1502
TESTCASE("NFNR2", 
 
1503
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1504
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1505
  TC_PROPERTY("PauseThreads", 2);
 
1506
  INITIALIZER(runClearTable);
 
1507
  INITIALIZER(createRandomIndex);
 
1508
  INITIALIZER(createPkIndex);
 
1509
  INITIALIZER(runLoadTable);
 
1510
  STEP(runRestarts);
 
1511
  STEP(runTransactions2);
 
1512
  STEP(runTransactions2);
 
1513
  FINALIZER(runVerifyIndex);
 
1514
  FINALIZER(createRandomIndex_Drop);
 
1515
  FINALIZER(createPkIndex_Drop);
 
1516
  FINALIZER(runClearTable);
 
1517
}
 
1518
TESTCASE("NFNR2_O", 
 
1519
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1520
  TC_PROPERTY("OrderedIndex", 1);
 
1521
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1522
  TC_PROPERTY("PauseThreads", 1);
 
1523
  INITIALIZER(runClearTable);
 
1524
  INITIALIZER(createRandomIndex);
 
1525
  INITIALIZER(createPkIndex);
 
1526
  INITIALIZER(runLoadTable);
 
1527
  STEP(runRestarts);
 
1528
  STEP(runTransactions2);
 
1529
  //STEP(runTransactions2);
 
1530
  FINALIZER(runVerifyIndex);
 
1531
  FINALIZER(createRandomIndex_Drop);
 
1532
  FINALIZER(createPkIndex_Drop);
 
1533
  FINALIZER(runClearTable);
 
1534
}
 
1535
TESTCASE("NFNR3", 
 
1536
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1537
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1538
  TC_PROPERTY("PauseThreads", 2);
 
1539
  INITIALIZER(runClearTable);
 
1540
  INITIALIZER(createRandomIndex);
 
1541
  INITIALIZER(createPkIndex);
 
1542
  STEP(runRestarts);
 
1543
  STEP(runTransactions3);
 
1544
  STEP(runVerifyIndex);
 
1545
  FINALIZER(runVerifyIndex);
 
1546
  FINALIZER(createPkIndex_Drop);
 
1547
  FINALIZER(createRandomIndex_Drop);
 
1548
  FINALIZER(runClearTable);
 
1549
}
 
1550
TESTCASE("NFNR3_O", 
 
1551
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1552
  TC_PROPERTY("OrderedIndex", 1);
 
1553
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1554
  TC_PROPERTY("PauseThreads", 2);
 
1555
  INITIALIZER(runClearTable);
 
1556
  INITIALIZER(createRandomIndex);
 
1557
  INITIALIZER(createPkIndex);
 
1558
  STEP(runRestarts);
 
1559
  STEP(runTransactions3);
 
1560
  STEP(runVerifyIndex);
 
1561
  FINALIZER(runVerifyIndex);
 
1562
  FINALIZER(createPkIndex_Drop);
 
1563
  FINALIZER(createRandomIndex_Drop);
 
1564
  FINALIZER(runClearTable);
 
1565
}
 
1566
TESTCASE("NFNR4", 
 
1567
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1568
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1569
  TC_PROPERTY("PauseThreads", 4);
 
1570
  INITIALIZER(runClearTable);
 
1571
  INITIALIZER(createRandomIndex);
 
1572
  INITIALIZER(createPkIndex);
 
1573
  INITIALIZER(runLoadTable);
 
1574
  STEP(runRestarts);
 
1575
  STEP(runTransactions1);
 
1576
  STEP(runTransactions1);
 
1577
  STEP(runTransactions2);
 
1578
  STEP(runTransactions2);
 
1579
  FINALIZER(runVerifyIndex);
 
1580
  FINALIZER(createRandomIndex_Drop);
 
1581
  FINALIZER(createPkIndex_Drop);
 
1582
  FINALIZER(runClearTable);
 
1583
}
 
1584
TESTCASE("NFNR4_O", 
 
1585
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1586
  TC_PROPERTY("OrderedIndex", 1);
 
1587
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1588
  TC_PROPERTY("PauseThreads", 4);
 
1589
  INITIALIZER(runClearTable);
 
1590
  INITIALIZER(createRandomIndex);
 
1591
  INITIALIZER(createPkIndex);
 
1592
  INITIALIZER(runLoadTable);
 
1593
  STEP(runRestarts);
 
1594
  STEP(runTransactions1);
 
1595
  STEP(runTransactions1);
 
1596
  STEP(runTransactions2);
 
1597
  STEP(runTransactions2);
 
1598
  FINALIZER(runVerifyIndex);
 
1599
  FINALIZER(createRandomIndex_Drop);
 
1600
  FINALIZER(createPkIndex_Drop);
 
1601
  FINALIZER(runClearTable);
 
1602
}
 
1603
TESTCASE("NFNR5", 
 
1604
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1605
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1606
  TC_PROPERTY("BatchSize", (unsigned)1);
 
1607
  INITIALIZER(runClearTable);
 
1608
  INITIALIZER(createRandomIndex);
 
1609
  INITIALIZER(createPkIndex);
 
1610
  INITIALIZER(runLoadTable);
 
1611
  STEP(runLQHKEYREF);
 
1612
  STEP(runTransactions1);
 
1613
  STEP(runTransactions1);
 
1614
  STEP(runTransactions2);
 
1615
  STEP(runTransactions2);
 
1616
  FINALIZER(runVerifyIndex);
 
1617
  FINALIZER(createRandomIndex_Drop);
 
1618
  FINALIZER(createPkIndex_Drop);
 
1619
  FINALIZER(runClearTable);
 
1620
}
 
1621
TESTCASE("NFNR5_O", 
 
1622
         "Test that indexes are correctly maintained during node fail and node restart"){ 
 
1623
  TC_PROPERTY("OrderedIndex", 1);
 
1624
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1625
  TC_PROPERTY("BatchSize", (unsigned)1);
 
1626
  INITIALIZER(runClearTable);
 
1627
  INITIALIZER(createRandomIndex);
 
1628
  INITIALIZER(createPkIndex);
 
1629
  INITIALIZER(runLoadTable);
 
1630
  STEP(runLQHKEYREF);
 
1631
  STEP(runTransactions1);
 
1632
  STEP(runTransactions1);
 
1633
  STEP(runTransactions2);
 
1634
  STEP(runTransactions2);
 
1635
  FINALIZER(runVerifyIndex);
 
1636
  FINALIZER(createRandomIndex_Drop);
 
1637
  FINALIZER(createPkIndex_Drop);
 
1638
  FINALIZER(runClearTable);
 
1639
}
 
1640
TESTCASE("SR1", 
 
1641
         "Test that indexes are correctly maintained during SR"){ 
 
1642
  INITIALIZER(runClearTable);
 
1643
  INITIALIZER(createRandomIndex);
 
1644
  INITIALIZER(createPkIndex);
 
1645
  STEP(runSystemRestart1);
 
1646
  FINALIZER(runVerifyIndex);
 
1647
  FINALIZER(createPkIndex_Drop);
 
1648
  FINALIZER(createRandomIndex_Drop);
 
1649
  FINALIZER(runClearTable);
 
1650
}
 
1651
TESTCASE("MixedTransaction", 
 
1652
         "Test mixing of index and normal operations"){ 
 
1653
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1654
  INITIALIZER(runClearTable);
 
1655
  INITIALIZER(createPkIndex);
 
1656
  INITIALIZER(runLoadTable);
 
1657
  STEP(runMixed1);
 
1658
  FINALIZER(createPkIndex_Drop);
 
1659
  FINALIZER(runClearTable);
 
1660
}
 
1661
TESTCASE("SR1_O", 
 
1662
         "Test that indexes are correctly maintained during SR"){ 
 
1663
  TC_PROPERTY("OrderedIndex", 1);
 
1664
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1665
  INITIALIZER(runClearTable);
 
1666
  INITIALIZER(createRandomIndex);
 
1667
  INITIALIZER(createPkIndex);
 
1668
  STEP(runSystemRestart1);
 
1669
  FINALIZER(runVerifyIndex);
 
1670
  FINALIZER(createPkIndex_Drop);
 
1671
  FINALIZER(createRandomIndex_Drop);
 
1672
  FINALIZER(runClearTable);
 
1673
}
 
1674
TESTCASE("BuildDuring", 
 
1675
         "Test that index build when running transactions work"){ 
 
1676
  TC_PROPERTY("OrderedIndex", (unsigned)0);
 
1677
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1678
  TC_PROPERTY("Threads", 1); // # runTransactions4
 
1679
  INITIALIZER(runClearTable);
 
1680
  STEP(runBuildDuring);
 
1681
  STEP(runTransactions4);
 
1682
  //STEP(runTransactions4);
 
1683
  FINALIZER(runClearTable);
 
1684
}
 
1685
TESTCASE("BuildDuring_O", 
 
1686
         "Test that index build when running transactions work"){ 
 
1687
  TC_PROPERTY("OrderedIndex", (unsigned)1);
 
1688
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1689
  TC_PROPERTY("Threads", 1); // # runTransactions4
 
1690
  INITIALIZER(runClearTable);
 
1691
  STEP(runBuildDuring);
 
1692
  STEP(runTransactions4);
 
1693
  //STEP(runTransactions4);
 
1694
  FINALIZER(runClearTable);
 
1695
}
 
1696
TESTCASE("UniqueNull", 
 
1697
         "Test that unique indexes and nulls"){ 
 
1698
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1699
  INITIALIZER(runClearTable);
 
1700
  INITIALIZER(createRandomIndex);
 
1701
  INITIALIZER(createPkIndex);
 
1702
  INITIALIZER(runLoadTable);
 
1703
  STEP(runTransactions1);
 
1704
  STEP(runTransactions2);
 
1705
  STEP(runUniqueNullTransactions);
 
1706
  FINALIZER(runVerifyIndex);
 
1707
  FINALIZER(createRandomIndex_Drop);
 
1708
  FINALIZER(createPkIndex_Drop);
 
1709
  FINALIZER(runClearTable);
 
1710
}
 
1711
TESTCASE("Bug21384", 
 
1712
         "Test that unique indexes and nulls"){ 
 
1713
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1714
  INITIALIZER(runClearTable);
 
1715
  INITIALIZER(createPkIndex);
 
1716
  INITIALIZER(runLoadTable);
 
1717
  STEP(runBug21384);
 
1718
  FINALIZER(createPkIndex_Drop);
 
1719
  FINALIZER(runClearTable);
 
1720
}
 
1721
TESTCASE("Bug25059", 
 
1722
         "Test that unique indexes and nulls"){ 
 
1723
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1724
  INITIALIZER(createPkIndex);
 
1725
  INITIALIZER(runLoadTable);
 
1726
  STEP(runBug25059);
 
1727
  FINALIZER(createPkIndex_Drop);
 
1728
}
 
1729
TESTCASE("Bug28804",
 
1730
         "Test behaviour on out of TransactionBufferMemory for index lookup"){
 
1731
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1732
  INITIALIZER(runClearTable);
 
1733
  INITIALIZER(createPkIndex);
 
1734
  INITIALIZER(runLoadTable);
 
1735
  STEP(runBug28804);
 
1736
  FINALIZER(createPkIndex_Drop);
 
1737
  FINALIZER(runClearTable);
 
1738
}
 
1739
TESTCASE("Bug28804_ATTRINFO",
 
1740
         "Test behaviour on out of TransactionBufferMemory for index lookup"
 
1741
         " in saveINDXATTRINFO"){
 
1742
  TC_PROPERTY("LoggedIndexes", (unsigned)0);
 
1743
  INITIALIZER(runClearTable);
 
1744
  INITIALIZER(createPkIndex);
 
1745
  INITIALIZER(runLoadTable);
 
1746
  STEP(runBug28804_ATTRINFO);
 
1747
  FINALIZER(createPkIndex_Drop);
 
1748
  FINALIZER(runClearTable);
 
1749
}
 
1750
NDBT_TESTSUITE_END(testIndex);
 
1751
 
 
1752
int main(int argc, const char** argv){
 
1753
  ndb_init();
 
1754
  return testIndex.execute(argc, argv);
 
1755
}
 
1756
 
 
1757
template class Vector<Attrib*>;