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

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/benchronja.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
 
 
17
/* ***************************************************
 
18
       NODEREC
 
19
       Perform benchmark of insert, update and delete transactions
 
20
 
 
21
       Arguments:
 
22
        -t Number of threads to start, default 1
 
23
        -o Number of loops per thread, default 100000
 
24
        
 
25
 
 
26
 * *************************************************** */
 
27
 
 
28
#include <ndb_global.h>
 
29
 
 
30
#include <NdbApi.hpp>
 
31
#include <NdbTest.hpp>
 
32
#include <NdbOut.hpp>
 
33
#include <NdbThread.h>
 
34
#include <NdbSleep.h>
 
35
#include <NdbMain.h>
 
36
#include <NdbTimer.hpp>
 
37
#include <NdbTick.h>
 
38
#include <random.h>
 
39
 
 
40
#define MAX_TIMERS 4 
 
41
#define MAXSTRLEN 16 
 
42
#define MAXATTR 64
 
43
#define MAXTABLES 64
 
44
#define NDB_MAXTHREADS 256
 
45
/*
 
46
  NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
 
47
  #define from <sys/thread.h> on AIX (IBM compiler).  We explicitly
 
48
  #undef it here lest someone use it by habit and get really funny
 
49
  results.  K&R says we may #undef non-existent symbols, so let's go.
 
50
*/
 
51
#undef MAXTHREADS
 
52
#define MAXATTRSIZE 8000
 
53
#define START_TIMER NdbTimer timer; timer.doStart();
 
54
#define STOP_TIMER timer.doStop();
 
55
#define START_TIMER_TOP NdbTimer timer_top; timer_top.doStart();
 
56
#define STOP_TIMER_TOP timer_top.doStop();
 
57
 
 
58
void* ThreadExec(void*);
 
59
struct ThreadNdb
 
60
{
 
61
  int NoOfOps;
 
62
  int ThreadNo;
 
63
  Ndb* NdbRef;
 
64
};
 
65
 
 
66
static NdbThread* threadLife[NDB_MAXTHREADS];
 
67
static unsigned int tNoOfThreads;
 
68
static unsigned int tNoOfOpsPerExecute;
 
69
static unsigned int tNoOfRecords;
 
70
static unsigned int tNoOfOperations;
 
71
static int ThreadReady[NDB_MAXTHREADS];
 
72
static int ThreadStart[NDB_MAXTHREADS];
 
73
 
 
74
NDB_COMMAND(benchronja, "benchronja", "benchronja", "benchronja", 65535){
 
75
  ndb_init();
 
76
 
 
77
  ThreadNdb             tabThread[NDB_MAXTHREADS];
 
78
  int                   i = 0 ;
 
79
  int                   cont = 0 ;
 
80
  Ndb*                  pMyNdb = NULL ; //( "TEST_DB" );        
 
81
  int           tmp = 0 ;
 
82
  int                   nTest = 0 ;
 
83
  char inp[100] ;
 
84
 
 
85
  tNoOfThreads = 1;                     // Default Value
 
86
  tNoOfOpsPerExecute = 1;       // Default Value
 
87
  tNoOfOperations = 100000;     // Default Value
 
88
  tNoOfRecords = 500 ;          // Default Value <epaulsa: changed from original 500,000 to match 'initronja's' default  
 
89
  i = 1;
 
90
  while (argc > 1)
 
91
  {
 
92
    if (strcmp(argv[i], "-t") == 0){
 
93
      tNoOfThreads = atoi(argv[i+1]);
 
94
      if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS)) goto error_input;
 
95
    }else if (strcmp(argv[i], "-o") == 0){
 
96
      tNoOfOperations = atoi(argv[i+1]);
 
97
      if (tNoOfOperations < 1) goto error_input;
 
98
    }else if (strcmp(argv[i], "-r") == 0){
 
99
      tNoOfRecords = atoi(argv[i+1]);
 
100
      if ((tNoOfRecords < 1) || (tNoOfRecords > 1000000000)) goto error_input;
 
101
        }else if (strcmp(argv[i], "-p") == 0){
 
102
                nTest = atoi(argv[i+1]) ;
 
103
                if (0 > nTest || 18 < nTest) goto error_input ;
 
104
    }else if (strcmp(argv[i], "-c") == 0){
 
105
      tNoOfOpsPerExecute = atoi(argv[i+1]);
 
106
      if ((tNoOfOpsPerExecute < 1) || (tNoOfOpsPerExecute > 1024)) goto error_input;
 
107
    }else{
 
108
      goto error_input;
 
109
    }
 
110
    argc -= 2;
 
111
    i = i + 2;
 
112
  }
 
113
 
 
114
  ndbout << "Initialisation started. " << endl;
 
115
  pMyNdb = new Ndb("TEST_DB") ;
 
116
  pMyNdb->init();
 
117
  ndbout << "Initialisation completed. " << endl;
 
118
 
 
119
  ndbout << endl << "Execute Ronja Benchmark" << endl;
 
120
  ndbout << "  NdbAPI node with id = " << pMyNdb->getNodeId() << endl;
 
121
  ndbout << "  " << tNoOfThreads << " thread(s) " << endl;
 
122
  ndbout << "  " << tNoOfOperations << " transaction(s) per thread and round " << endl;
 
123
 
 
124
  if (pMyNdb->waitUntilReady(120) != 0) {
 
125
    ndbout << "Benchmark failed - NDB is not ready" << endl;
 
126
        delete pMyNdb ;
 
127
    return NDBT_ProgramExit(NDBT_FAILED);
 
128
  }//if
 
129
 
 
130
  NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
 
131
 
 
132
  for (i = 0; i < tNoOfThreads ; i++) {
 
133
    ThreadReady[i] = 0;
 
134
    ThreadStart[i] = 0;
 
135
  }//for
 
136
 
 
137
  for (i = 0; i < tNoOfThreads ; i++) {
 
138
    tabThread[i].ThreadNo = i;
 
139
    tabThread[i].NdbRef = NULL;
 
140
    tabThread[i].NoOfOps = tNoOfOperations;
 
141
    threadLife[i] = NdbThread_Create(ThreadExec,
 
142
                                       (void**)&tabThread[i],
 
143
                                       32768,
 
144
                                       "RonjaThread",
 
145
                                       NDB_THREAD_PRIO_LOW);
 
146
  }//for
 
147
  
 
148
  cont = 1;
 
149
  while (cont) {
 
150
        NdbSleep_MilliSleep(10);
 
151
    cont = 0;
 
152
    for (i = 0; i < tNoOfThreads ; i++)
 
153
      if (!ThreadReady[i]) cont = 1;
 
154
  }//while
 
155
 
 
156
  ndbout << "All threads started" << endl;
 
157
  
 
158
  if(!nTest){
 
159
 
 
160
          for (;;){
 
161
 
 
162
                  inp[0] = 0;
 
163
                  ndbout << endl << "What to do next:" << endl;
 
164
                  ndbout << "1 \t=> Perform lookups in short table" << endl;
 
165
                  ndbout << "2 \t=> Perform lookups in long table" << endl;
 
166
                  ndbout << "3 \t=> Perform updates in short table" << endl;
 
167
                  ndbout << "4 \t=> Perform updates in long table" << endl;
 
168
                  ndbout << "5 \t=> Perform 50% lookups/50% updates in short table" << endl;
 
169
                  ndbout << "6 \t=> Perform 50% lookups/50% updates in long table" << endl;
 
170
                  ndbout << "7 \t=> Perform 80% lookups/20% updates in short table" << endl;
 
171
                  ndbout << "8 \t=> Perform 80% lookups/20% updates in long table" << endl;
 
172
                  ndbout << "9 \t=> Perform 25% lookups short/25% lookups long/25% updates short/25% updates long" << endl;
 
173
                  ndbout << "10\t=> Test bug with replicated interpreted updates, short table" << endl;
 
174
                  ndbout << "11\t=> Test interpreter functions, short table" << endl;
 
175
                  ndbout << "12\t=> Test bug with replicated interpreted updates, long table" << endl;
 
176
                  ndbout << "13\t=> Test interpreter functions, long table" << endl;
 
177
                  ndbout << "14\t=> Perform lookups in short table, no guess of TC" << endl;
 
178
                  ndbout << "15\t=> Perform lookups in long table, no guess of TC" << endl;
 
179
                  ndbout << "16\t=> Perform updates in short table, no guess of TC" << endl;
 
180
                  ndbout << "17\t=> Perform updates in long table, no guess of TC" << endl;
 
181
                  ndbout << "18\t=> Multi record updates of transactions" << endl;
 
182
                  ndbout << "All other responses will exit" << endl;
 
183
                  ndbout << "_____________________________" << endl << endl ;
 
184
                  
 
185
                  int inp_i = 0;
 
186
                  do {
 
187
                    inp[inp_i] = (char) fgetc(stdin);               
 
188
                    if (inp[inp_i] == '\n' || inp[inp_i] == EOF) {
 
189
                      inp[inp_i] ='\0';
 
190
                      break;
 
191
                    }           
 
192
                    inp_i++;
 
193
 
 
194
                  } while (inp[inp_i - 1] != '\n' && inp[inp_i - 1] != EOF);
 
195
                  
 
196
                  tmp = atoi(inp);
 
197
                  
 
198
                  if ((tmp > 18) || (tmp <= 0)) break;
 
199
                  
 
200
                  ndbout << "Starting test " << tmp << "..." << endl;
 
201
 
 
202
                  for (i = 0; i < tNoOfThreads ; i++){ ThreadStart[i] = tmp; }
 
203
                  
 
204
                  cont = 1;
 
205
                  while (cont) {
 
206
                          NdbSleep_MilliSleep(10);
 
207
                          cont = 0;
 
208
                          for (i = 0; i < tNoOfThreads ; i++){
 
209
                                  if (!ThreadReady[i]) cont = 1;
 
210
                          }
 
211
                  }//while
 
212
          }//for(;;)
 
213
 
 
214
  }else{
 
215
 
 
216
          if(19 == nTest){
 
217
                  ndbout << "Executing all 18 available tests..." << endl << endl;
 
218
                  for (int count = 1; count < nTest; count++){
 
219
                          ndbout << "Test " << count << endl ;
 
220
                          ndbout << "------" << endl << endl ;
 
221
                          for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = count ; }
 
222
                          cont = 1;
 
223
                          while (cont) {
 
224
                                  NdbSleep_MilliSleep(10);
 
225
                                  cont = 0;
 
226
                                  for (i = 0; i < tNoOfThreads ; i++){
 
227
                                          if (!ThreadReady[i]) cont = 1;
 
228
                                  }
 
229
                          }
 
230
                  }//for
 
231
          }else{
 
232
                  ndbout << endl << "Executing test " << nTest << endl << endl;
 
233
                  for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = nTest ; }
 
234
                  cont = 1;
 
235
                  while (cont) {
 
236
                          NdbSleep_MilliSleep(10);
 
237
                          cont = 0;
 
238
                          for (i = 0; i < tNoOfThreads ; i++){
 
239
                                  if (!ThreadReady[i]) cont = 1;
 
240
                          }
 
241
                  }
 
242
          }//if(18 == nTest)
 
243
  } //if(!nTest)
 
244
 
 
245
  ndbout << "--------------------------------------------------" << endl;
 
246
 
 
247
  for (i = 0; i < tNoOfThreads ; i++) ThreadReady[i] = 0;
 
248
  // Signaling threads to stop 
 
249
  for (i = 0; i < tNoOfThreads ; i++) ThreadStart[i] = 999;
 
250
 
 
251
    // Wait for threads to stop
 
252
  cont = 1;
 
253
  do {
 
254
     NdbSleep_MilliSleep(1);
 
255
         cont = 0;
 
256
         for (i = 0; i < tNoOfThreads ; i++){
 
257
      if (ThreadReady[i] == 0) cont = 1;
 
258
         }
 
259
  } while (cont == 1);
 
260
 
 
261
  delete pMyNdb ;
 
262
  ndbout << endl << "Ronja Benchmark completed" << endl;
 
263
  return NDBT_ProgramExit(NDBT_OK) ;
 
264
 
 
265
error_input:
 
266
  ndbout << endl << "  Ivalid parameter(s)" << endl;
 
267
  ndbout <<         "  Usage: benchronja [-t threads][-r rec] [-o ops] [-c ops_per_exec] [-p test], where:" << endl;
 
268
  ndbout <<                     "  threads - the number of threads to start; default: 1" << endl;
 
269
  ndbout <<                     "  rec - the number of records in the tables; default: 500" << endl;
 
270
  ndbout <<                     "  ops - the number of operations per transaction; default: 100000" << endl;
 
271
  ndbout <<                     "  ops_per_exec - the number of operations per execution; default: 1" << endl ;
 
272
  ndbout <<                     "  test - the number of test to execute; 19 executes all available tests; default: 0"<< endl ;
 
273
  ndbout <<                     "  which enters a loop expecting manual input of test number to execute." << endl << endl ;
 
274
  delete pMyNdb ;
 
275
  return NDBT_ProgramExit(NDBT_WRONGARGS) ;
 
276
 
 
277
  }
 
278
////////////////////////////////////////
 
279
 
 
280
void commitTrans(Ndb* aNdb, NdbConnection* aCon)
 
281
{
 
282
  int ret = aCon->execute(Commit);
 
283
  assert (ret != -1);
 
284
  aNdb->closeTransaction(aCon);
 
285
}
 
286
 
 
287
void rollbackTrans(Ndb* aNdb, NdbConnection* aCon)
 
288
{
 
289
  int ret = aCon->execute(Rollback);
 
290
  assert (ret != -1);
 
291
  aNdb->closeTransaction(aCon);
 
292
}
 
293
 
 
294
void updateNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
 
295
{
 
296
  NdbOperation* theOperation;
 
297
 
 
298
  *flip = *flip + 1;
 
299
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
300
  theOperation->updateTuple();
 
301
  theOperation->equal((Uint32)0, key);
 
302
  theOperation->setValue((Uint32)1, (char*)flip);
 
303
  int ret = aCon->execute(NoCommit);
 
304
  assert (ret != -1);
 
305
}
 
306
 
 
307
void updateNoCommitFail(NdbConnection* aCon, unsigned int key)
 
308
{
 
309
  NdbOperation* theOperation;
 
310
 
 
311
  Uint32 flip = 0;
 
312
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
313
  theOperation->updateTuple();
 
314
  theOperation->equal((Uint32)0, key);
 
315
  theOperation->setValue((Uint32)1, (char*)flip);
 
316
  int ret = aCon->execute(NoCommit);
 
317
  assert (ret == -1);
 
318
}
 
319
 
 
320
void deleteNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
 
321
{
 
322
  NdbOperation* theOperation;
 
323
 
 
324
  *flip = 0;
 
325
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
326
  theOperation->deleteTuple();
 
327
  theOperation->equal((Uint32)0, key);
 
328
  int ret = aCon->execute(NoCommit);
 
329
  assert (ret != -1);
 
330
}
 
331
 
 
332
void insertNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
 
333
{
 
334
  NdbOperation* theOperation;
 
335
  Uint32 placeholder[100];
 
336
 
 
337
  *flip = *flip + 1;
 
338
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
339
  theOperation->insertTuple();
 
340
  theOperation->equal((Uint32)0, key);
 
341
  theOperation->setValue((Uint32)1, (char*)flip);
 
342
  theOperation->setValue((Uint32)2, (char*)&placeholder[0]);
 
343
  theOperation->setValue((Uint32)3, (char*)&placeholder[0]);
 
344
  int ret = aCon->execute(NoCommit);
 
345
  assert (ret != -1);
 
346
}
 
347
 
 
348
void writeNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
 
349
{
 
350
  NdbOperation* theOperation;
 
351
  Uint32 placeholder[100];
 
352
 
 
353
  *flip = *flip + 1;
 
354
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
355
  theOperation->writeTuple();
 
356
  theOperation->equal((Uint32)0, key);
 
357
  theOperation->setValue((Uint32)1, (char*)flip);
 
358
  theOperation->setValue((Uint32)2, (char*)&placeholder[0]);
 
359
  theOperation->setValue((Uint32)3, (char*)&placeholder[0]);
 
360
  int ret = aCon->execute(NoCommit);
 
361
  assert (ret != -1);
 
362
}
 
363
 
 
364
void readNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
 
365
{
 
366
  NdbOperation* theOperation;
 
367
  Uint32 readFlip;
 
368
 
 
369
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
370
  theOperation->readTuple();
 
371
  theOperation->equal((Uint32)0, key);
 
372
  theOperation->getValue((Uint32)1, (char*)&readFlip);
 
373
  int ret = aCon->execute(NoCommit);
 
374
  assert (ret == expected_ret);
 
375
  if (ret == 0) 
 
376
    assert (*flip == readFlip);
 
377
}
 
378
 
 
379
void readDirtyNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
 
380
{
 
381
  NdbOperation* theOperation;
 
382
  Uint32 readFlip;
 
383
 
 
384
  theOperation = aCon->getNdbOperation("SHORT_REC");
 
385
  theOperation->committedRead();
 
386
  theOperation->equal((Uint32)0, key);
 
387
  theOperation->getValue((Uint32)1, (char*)&readFlip);
 
388
  int ret = aCon->execute(NoCommit);
 
389
  assert (ret == expected_ret);
 
390
  if (ret == 0) 
 
391
    assert (*flip == readFlip);
 
392
}
 
393
 
 
394
void readVerify(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
 
395
{
 
396
  NdbConnection* theTransaction;
 
397
  theTransaction = aNdb->startTransaction();
 
398
  readNoCommit(theTransaction, flip, key, expected_ret);
 
399
  commitTrans(aNdb, theTransaction);
 
400
}
 
401
 
 
402
void readDirty(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
 
403
{
 
404
  NdbOperation* theOperation;
 
405
  NdbConnection* theTransaction;
 
406
  Uint32 readFlip;
 
407
 
 
408
  theTransaction = aNdb->startTransaction();
 
409
  theOperation = theTransaction->getNdbOperation("SHORT_REC");
 
410
  theOperation->committedRead();
 
411
  theOperation->equal((Uint32)0, key);
 
412
  theOperation->getValue((Uint32)1, (char*)&readFlip);
 
413
  int ret = theTransaction->execute(Commit);
 
414
  assert (ret == expected_ret);
 
415
  if (ret == 0) 
 
416
    assert (*flip == readFlip);
 
417
  aNdb->closeTransaction(theTransaction);
 
418
}
 
419
 
 
420
int multiRecordTest(Ndb* aNdb, unsigned int key)
 
421
{
 
422
  NdbConnection* theTransaction;
 
423
  Uint32 flip = 0;
 
424
  Uint32 save_flip;
 
425
  ndbout << "0" << endl;
 
426
 
 
427
  theTransaction = aNdb->startTransaction();
 
428
 
 
429
  updateNoCommit(theTransaction, &flip, key);
 
430
 
 
431
  readNoCommit(theTransaction, &flip, key, 0);
 
432
 
 
433
  updateNoCommit(theTransaction, &flip, key);
 
434
 
 
435
  readNoCommit(theTransaction, &flip, key, 0);
 
436
 
 
437
  commitTrans(aNdb, theTransaction);
 
438
 
 
439
  ndbout << "1 " << endl;
 
440
 
 
441
  readVerify(aNdb, &flip, key, 0);
 
442
  readDirty(aNdb, &flip, key, 0);
 
443
  save_flip = flip;
 
444
  ndbout << "1.1 " << endl;
 
445
 
 
446
  theTransaction = aNdb->startTransaction();
 
447
 
 
448
  deleteNoCommit(theTransaction, &flip, key);
 
449
 
 
450
  readNoCommit(theTransaction, &flip, key, -1);
 
451
  readDirty(aNdb, &save_flip, key, 0);           // COMMITTED READ!!!
 
452
  readDirtyNoCommit(theTransaction, &flip, key, -1);
 
453
  ndbout << "1.2 " << endl;
 
454
 
 
455
  insertNoCommit(theTransaction, &flip, key);
 
456
 
 
457
  readNoCommit(theTransaction, &flip, key, 0);
 
458
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
459
  readDirty(aNdb, &save_flip, key, 0);           // COMMITTED READ!!!
 
460
  ndbout << "1.3 " << endl;
 
461
 
 
462
  updateNoCommit(theTransaction, &flip, key);
 
463
 
 
464
  readNoCommit(theTransaction, &flip, key, 0);
 
465
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
466
  readDirty(aNdb, &save_flip, key, 0);           // COMMITTED READ!!!
 
467
  ndbout << "1.4 " << endl;
 
468
 
 
469
  commitTrans(aNdb, theTransaction);
 
470
 
 
471
  ndbout << "2 " << endl;
 
472
 
 
473
  readDirty(aNdb, &flip, key, 0);           // COMMITTED READ!!!
 
474
  readVerify(aNdb, &flip, key, 0);
 
475
 
 
476
  save_flip = flip;
 
477
  theTransaction = aNdb->startTransaction();
 
478
 
 
479
  deleteNoCommit(theTransaction, &flip, key);
 
480
 
 
481
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
482
  readDirtyNoCommit(theTransaction, &flip, key, -1);       // COMMITTED READ!!!
 
483
  readNoCommit(theTransaction, &flip, key, -1);
 
484
 
 
485
  insertNoCommit(theTransaction, &flip, key);
 
486
 
 
487
  readNoCommit(theTransaction, &flip, key, 0);
 
488
 
 
489
  updateNoCommit(theTransaction, &flip, key);
 
490
 
 
491
  readNoCommit(theTransaction, &flip, key, 0);
 
492
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
493
  readDirtyNoCommit(theTransaction, &flip, key, 0);        // COMMITTED READ!!!
 
494
 
 
495
  deleteNoCommit(theTransaction, &flip, key);
 
496
 
 
497
  readNoCommit(theTransaction, &flip, key, -1);
 
498
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
499
  readDirtyNoCommit(theTransaction, &flip, key, -1);
 
500
 
 
501
  rollbackTrans(aNdb, theTransaction);
 
502
 
 
503
  ndbout << "3 " << endl;
 
504
 
 
505
  flip = save_flip;
 
506
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
507
  readVerify(aNdb, &flip, key, 0);
 
508
 
 
509
  theTransaction = aNdb->startTransaction();
 
510
 
 
511
  updateNoCommit(theTransaction, &flip, key);
 
512
 
 
513
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
514
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
515
  readNoCommit(theTransaction, &flip, key, 0);
 
516
 
 
517
  deleteNoCommit(theTransaction, &flip, key);
 
518
 
 
519
  readNoCommit(theTransaction, &flip, key, -1);
 
520
  readDirtyNoCommit(theTransaction, &flip, key, -1);
 
521
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
522
 
 
523
  insertNoCommit(theTransaction, &flip, key);
 
524
 
 
525
  readNoCommit(theTransaction, &flip, key, 0);
 
526
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
527
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
528
 
 
529
  updateNoCommit(theTransaction, &flip, key);
 
530
 
 
531
  readNoCommit(theTransaction, &flip, key, 0);
 
532
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
533
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
534
 
 
535
  deleteNoCommit(theTransaction, &flip, key);
 
536
 
 
537
  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!
 
538
  readNoCommit(theTransaction, &flip, key, -1);
 
539
  readDirtyNoCommit(theTransaction, &flip, key, -1);
 
540
 
 
541
  commitTrans(aNdb, theTransaction);
 
542
 
 
543
  ndbout << "4 " << endl;
 
544
 
 
545
  readVerify(aNdb, &flip, key, -1);
 
546
 
 
547
  theTransaction = aNdb->startTransaction();
 
548
 
 
549
  insertNoCommit(theTransaction, &flip, key);
 
550
 
 
551
  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!
 
552
  readNoCommit(theTransaction, &flip, key, 0);
 
553
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
554
 
 
555
  deleteNoCommit(theTransaction, &flip, key);
 
556
 
 
557
  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!
 
558
  readNoCommit(theTransaction, &flip, key, -1);
 
559
  readDirtyNoCommit(theTransaction, &flip, key, -1);
 
560
 
 
561
  insertNoCommit(theTransaction, &flip, key);
 
562
 
 
563
  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!
 
564
  readNoCommit(theTransaction, &flip, key, 0);
 
565
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
566
 
 
567
  updateNoCommit(theTransaction, &flip, key);
 
568
 
 
569
  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!
 
570
  readNoCommit(theTransaction, &flip, key, 0);
 
571
  readDirtyNoCommit(theTransaction, &flip, key, 0);
 
572
 
 
573
  deleteNoCommit(theTransaction, &flip, key);
 
574
 
 
575
  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!
 
576
  readNoCommit(theTransaction, &flip, key, -1);
 
577
  readDirtyNoCommit(theTransaction, &flip, key, -1);
 
578
 
 
579
  commitTrans(aNdb, theTransaction);
 
580
 
 
581
  ndbout << "5 " << endl;
 
582
 
 
583
  readDirty(aNdb, &flip, key, -1);                         // COMMITTED READ!!!
 
584
  readVerify(aNdb, &flip, key, -1);
 
585
 
 
586
  theTransaction = aNdb->startTransaction();
 
587
 
 
588
  insertNoCommit(theTransaction, &flip, key);
 
589
 
 
590
  readDirty(aNdb, &flip, key, -1);                         // COMMITTED READ!!!
 
591
  readDirtyNoCommit(theTransaction, &flip, key, 0);        // COMMITTED READ!!!
 
592
 
 
593
  commitTrans(aNdb, theTransaction);
 
594
  readDirty(aNdb, &flip, key, 0);                          // COMMITTED READ!!!
 
595
 
 
596
  ndbout << "6 " << endl;
 
597
 
 
598
  theTransaction = aNdb->startTransaction();
 
599
 
 
600
  deleteNoCommit(theTransaction, &flip, key);
 
601
  updateNoCommitFail(theTransaction, key);
 
602
  rollbackTrans(aNdb, theTransaction);
 
603
  return 0;
 
604
}
 
605
 
 
606
int lookup(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess){
 
607
 
 
608
  int placeholder[500];
 
609
  unsigned int flip, count;
 
610
  int ret_value, i;
 
611
  NdbConnection* theTransaction;
 
612
  NdbOperation* theOperation;
 
613
  if ( !aNdb ) return -1 ;
 
614
        
 
615
  if (guess != 0)
 
616
    theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
 
617
  else
 
618
    theTransaction = aNdb->startTransaction();
 
619
 
 
620
  for (i = 0; i < tNoOfOpsPerExecute; i++) {
 
621
    if (long_short == 0)
 
622
      theOperation = theTransaction->getNdbOperation("SHORT_REC");
 
623
    else
 
624
      theOperation = theTransaction->getNdbOperation("LONG_REC");
 
625
    if (theOperation == NULL) {
 
626
      ndbout << "Table missing" << endl;
 
627
          aNdb->closeTransaction(theTransaction) ;
 
628
          return -1;
 
629
    }//if
 
630
    theOperation->simpleRead();
 
631
    theOperation->equal((Uint32)0, key);
 
632
    theOperation->getValue((Uint32)1, (char*)&flip);
 
633
    theOperation->getValue((Uint32)2, (char*)&count);
 
634
    if (theOperation->getValue((Uint32)3, (char*)&placeholder[0]) == NULL) {
 
635
      ndbout << "Error in definition phase = " << theTransaction->getNdbError() << endl;  
 
636
      aNdb->closeTransaction(theTransaction);
 
637
      return -1;
 
638
    }//if
 
639
  }//for
 
640
  ret_value = theTransaction->execute(Commit);
 
641
  if (ret_value == -1)
 
642
    ndbout << "Error in lookup:" << theTransaction->getNdbError() << endl;
 
643
    aNdb->closeTransaction(theTransaction);
 
644
        return ret_value;
 
645
}//lookup()
 
646
 
 
647
int update(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess)
 
648
{
 
649
  int placeholder[500];
 
650
  int ret_value, i;
 
651
  unsigned int flip, count;
 
652
  NdbConnection* theTransaction;
 
653
  NdbOperation* theOperation;
 
654
 
 
655
  if ( !aNdb ) return -1 ;
 
656
 
 
657
  if (guess != 0)
 
658
    theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
 
659
  else
 
660
    theTransaction = aNdb->startTransaction();
 
661
 
 
662
  for (i = 0; i < tNoOfOpsPerExecute; i++) {
 
663
    if (long_short == 0)
 
664
      theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
 
665
    else
 
666
      theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
 
667
    if (theOperation == NULL) {
 
668
      ndbout << "Table missing" << endl;
 
669
          aNdb->closeTransaction(theTransaction) ;
 
670
          delete aNdb ;
 
671
      return -1;
 
672
    }//if
 
673
    theOperation->interpretedUpdateTuple();                       // Send interpreted program to NDB kernel
 
674
    theOperation->equal((Uint32)0, key);                          // Search key
 
675
    theOperation->getValue((Uint32)1, (char*)&flip);              // Read value of flip
 
676
    theOperation->getValue((Uint32)2, (char*)&count);             // Read value of count
 
677
    theOperation->getValue((Uint32)3, (char*)&placeholder[0]);    // Read value of placeholder
 
678
    theOperation->load_const_u32((Uint32)1, (Uint32)0);           // Load register 1 with 0
 
679
    theOperation->read_attr((Uint32)1, (Uint32)2);                // Read Flip value into register 2
 
680
    theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0);     // If Flip (register 2) == 0 (register 1) goto label 0
 
681
    theOperation->branch_label((Uint32)1);                        // Goto label 1
 
682
    theOperation->def_label((Uint32)0);                           // Define label 0
 
683
    theOperation->load_const_u32((Uint32)1, (Uint32)1);           // Load register 1 with 1
 
684
    theOperation->def_label((Uint32)1);                           // Define label 0
 
685
    theOperation->write_attr((Uint32)1, (Uint32)1);               // Write 1 (register 1) into Flip
 
686
    ret_value = theOperation->incValue((Uint32)2, (Uint32)1);     // Increment Count by 1
 
687
    if (ret_value == -1) {
 
688
      ndbout << "Error in definition phase " << endl;  
 
689
      aNdb->closeTransaction(theTransaction);
 
690
      return ret_value;
 
691
    }//if
 
692
  }//for
 
693
  ret_value = theTransaction->execute(Commit);                  // Perform the actual read and update
 
694
  if (ret_value == -1) {
 
695
    ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
 
696
    aNdb->closeTransaction(theTransaction); // < epaulsa
 
697
        return ret_value ;
 
698
  }//if
 
699
  aNdb->closeTransaction(theTransaction);
 
700
  return ret_value;
 
701
}//update()
 
702
 
 
703
int update_bug(Ndb* aNdb, unsigned int key, unsigned int long_short)
 
704
{
 
705
  int placeholder[500];
 
706
  int ret_value, i;
 
707
  unsigned int flip, count;
 
708
  NdbConnection* theTransaction;
 
709
  NdbOperation* theOperation;
 
710
 
 
711
  if ( !aNdb ) return -1 ;
 
712
 
 
713
  theTransaction = aNdb->startTransaction();
 
714
  for (i = 0; i < tNoOfOpsPerExecute; i++) {
 
715
    if (long_short == 0)
 
716
      theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
 
717
    else
 
718
      theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
 
719
    if (theOperation == NULL) {
 
720
      ndbout << "Table missing" << endl;
 
721
          aNdb->closeTransaction(theTransaction) ;
 
722
      return -1;
 
723
    }//if
 
724
    theOperation->interpretedUpdateTuple();                       // Send interpreted program to NDB kernel
 
725
    theOperation->equal((Uint32)0, key);                          // Search key
 
726
    theOperation->getValue((Uint32)1, (char*)&flip);              // Read value of flip
 
727
    theOperation->getValue((Uint32)2, (char*)&count);             // Read value of count
 
728
    theOperation->getValue((Uint32)3, (char*)&placeholder[0]);    // Read value of placeholder
 
729
    theOperation->load_const_u32((Uint32)1, (Uint32)0);           // Load register 1 with 0
 
730
    theOperation->read_attr((Uint32)1, (Uint32)2);                // Read Flip value into register 2
 
731
    theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0);     // If Flip (register 2) == 0 (register 1) goto label 0
 
732
    theOperation->branch_label((Uint32)1);                        // Goto label 1
 
733
    theOperation->def_label((Uint32)0);                           // Define label 0
 
734
    theOperation->load_const_u32((Uint32)1, (Uint32)1);           // Load register 1 with 1
 
735
    theOperation->def_label((Uint32)1);                           // Define label 0
 
736
    theOperation->write_attr((Uint32)1, (Uint32)1);               // Write 1 (register 1) into Flip
 
737
    ret_value = theOperation->incValue((Uint32)2, (Uint32)1);     // Increment Count by 1
 
738
    if (ret_value == -1) {
 
739
      ndbout << "Error in definition phase " << endl;  
 
740
      aNdb->closeTransaction(theTransaction);
 
741
      return ret_value;
 
742
    }//if
 
743
  }//for
 
744
  ret_value = theTransaction->execute(NoCommit);                  // Perform the actual read and update
 
745
  if (ret_value == -1) {
 
746
    ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
 
747
    aNdb->closeTransaction(theTransaction);
 
748
        return ret_value ;
 
749
  }//if
 
750
  aNdb->closeTransaction(theTransaction);
 
751
  return ret_value;
 
752
}//update_bug()
 
753
 
 
754
int update_interpreter_test(Ndb* aNdb, unsigned int key, unsigned int long_short)
 
755
{
 
756
  int placeholder[500];
 
757
  int ret_value, i;
 
758
  unsigned int flip, count;
 
759
  NdbConnection* theTransaction;
 
760
  NdbOperation* theOperation;
 
761
  Uint32 Tlabel = 0;
 
762
 
 
763
  if ( !aNdb ) return -1 ; 
 
764
 
 
765
//------------------------------------------------------------------------------
 
766
// Start the transaction and get a unique transaction id
 
767
//------------------------------------------------------------------------------
 
768
  theTransaction = aNdb->startTransaction();
 
769
  for (i = 0; i < tNoOfOpsPerExecute; i++) {
 
770
//------------------------------------------------------------------------------
 
771
// Get the proper table object and load schema information if not already
 
772
// present.
 
773
//------------------------------------------------------------------------------
 
774
    if (long_short == 0)
 
775
      theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
 
776
    else
 
777
      theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
 
778
    if (theOperation == NULL) {
 
779
      ndbout << "Table missing" << endl;
 
780
          aNdb->closeTransaction(theTransaction) ;
 
781
      return -1;
 
782
    }//if
 
783
//------------------------------------------------------------------------------
 
784
// Define the operation type and the tuple key (primary key in this case).
 
785
//------------------------------------------------------------------------------
 
786
    theOperation->interpretedUpdateTuple();                       // Send interpreted program to NDB kernel
 
787
    theOperation->equal((Uint32)0, key);                          // Search key
 
788
 
 
789
//------------------------------------------------------------------------------
 
790
// Perform initial read of attributes before updating them
 
791
//------------------------------------------------------------------------------
 
792
    theOperation->getValue((Uint32)1, (char*)&flip);              // Read value of flip
 
793
    theOperation->getValue((Uint32)2, (char*)&count);             // Read value of count
 
794
    theOperation->getValue((Uint32)3, (char*)&placeholder[0]);    // Read value of placeholder
 
795
 
 
796
//------------------------------------------------------------------------------
 
797
// Test that the various branch operations can handle things correctly.
 
798
// Test first 2 + 3 = 5 with 32 bit registers
 
799
// Next test the same with 32 bit + 64 bit = 64 
 
800
//------------------------------------------------------------------------------
 
801
    theOperation->load_const_u32((Uint32)4, (Uint32)0);           // Load register 4 with 0
 
802
 
 
803
    theOperation->load_const_u32((Uint32)0, (Uint32)0);
 
804
    theOperation->load_const_u32((Uint32)1, (Uint32)3);
 
805
    theOperation->load_const_u32((Uint32)2, (Uint32)5);
 
806
    theOperation->load_const_u32((Uint32)3, (Uint32)1);
 
807
    theOperation->def_label(Tlabel++);
 
808
    theOperation->def_label(Tlabel++);
 
809
    theOperation->sub_reg((Uint32)2, (Uint32)3, (Uint32)2);
 
810
    theOperation->branch_ne((Uint32)2, (Uint32)0, (Uint32)0);
 
811
    theOperation->load_const_u32((Uint32)2, (Uint32)5);
 
812
    theOperation->sub_reg((Uint32)1, (Uint32)3, (Uint32)1);
 
813
    theOperation->branch_ne((Uint32)1, (Uint32)0, (Uint32)1);  
 
814
 
 
815
    theOperation->load_const_u32((Uint32)1, (Uint32)2);           // Load register 1 with 2
 
816
    theOperation->load_const_u32((Uint32)2, (Uint32)3);           // Load register 2 with 3
 
817
    theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);       // 2+3 = 5 into reg 1
 
818
    theOperation->load_const_u32((Uint32)2, (Uint32)5);           // Load register 2 with 5
 
819
 
 
820
    theOperation->def_label(Tlabel++);
 
821
 
 
822
    theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
 
823
    theOperation->interpret_exit_nok((Uint32)6001);
 
824
 
 
825
    theOperation->def_label(Tlabel++);
 
826
    theOperation->branch_ne((Uint32)1, (Uint32)2, Tlabel);
 
827
    theOperation->branch_label(Tlabel + 1);
 
828
    theOperation->def_label(Tlabel++);
 
829
    theOperation->interpret_exit_nok((Uint32)6002);
 
830
 
 
831
    theOperation->def_label(Tlabel++);
 
832
    theOperation->branch_lt((Uint32)1, (Uint32)2, Tlabel);
 
833
    theOperation->branch_label(Tlabel + 1);
 
834
    theOperation->def_label(Tlabel++);
 
835
    theOperation->interpret_exit_nok((Uint32)6003);
 
836
 
 
837
    theOperation->def_label(Tlabel++);
 
838
    theOperation->branch_gt((Uint32)1, (Uint32)2, Tlabel);
 
839
    theOperation->branch_label(Tlabel + 1);
 
840
    theOperation->def_label(Tlabel++);
 
841
    theOperation->interpret_exit_nok((Uint32)6005);
 
842
 
 
843
    theOperation->def_label(Tlabel++);
 
844
    theOperation->branch_eq_null((Uint32)1, Tlabel);
 
845
    theOperation->branch_label(Tlabel + 1);
 
846
    theOperation->def_label(Tlabel++);
 
847
    theOperation->interpret_exit_nok((Uint32)6006);
 
848
 
 
849
    theOperation->def_label(Tlabel++);
 
850
    theOperation->branch_ne_null((Uint32)1,Tlabel);
 
851
    theOperation->interpret_exit_nok((Uint32)6007);
 
852
 
 
853
    theOperation->def_label(Tlabel++);
 
854
    theOperation->branch_ge((Uint32)1, (Uint32)2, Tlabel);
 
855
    theOperation->interpret_exit_nok((Uint32)6008);
 
856
 
 
857
    theOperation->def_label(Tlabel++);
 
858
    theOperation->branch_eq_null((Uint32)6,Tlabel);
 
859
    theOperation->interpret_exit_nok((Uint32)6009);
 
860
 
 
861
    theOperation->def_label(Tlabel++);
 
862
    theOperation->branch_ne_null((Uint32)6, Tlabel);
 
863
    theOperation->branch_label(Tlabel + 1);
 
864
    theOperation->def_label(Tlabel++);
 
865
    theOperation->interpret_exit_nok((Uint32)6010);
 
866
 
 
867
    theOperation->def_label(Tlabel++);
 
868
 
 
869
    theOperation->load_const_u32((Uint32)5, (Uint32)1);
 
870
    theOperation->add_reg((Uint32)4, (Uint32)5, (Uint32)4);
 
871
 
 
872
    theOperation->load_const_u32((Uint32)5, (Uint32)1);
 
873
    theOperation->branch_eq((Uint32)4, (Uint32)5, Tlabel);
 
874
 
 
875
 
 
876
    theOperation->load_const_u32((Uint32)5, (Uint32)2);
 
877
    theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 1));
 
878
 
 
879
    theOperation->load_const_u32((Uint32)5, (Uint32)3);
 
880
    theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 2));
 
881
 
 
882
    theOperation->load_const_u32((Uint32)5, (Uint32)4);
 
883
    theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 3));
 
884
       
 
885
    theOperation->branch_label(Tlabel + 4);
 
886
 
 
887
    theOperation->def_label(Tlabel++);
 
888
    theOperation->load_const_u32((Uint32)1, (Uint32)200000);
 
889
    theOperation->load_const_u32((Uint32)2, (Uint32)300000);
 
890
    theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
 
891
    theOperation->load_const_u32((Uint32)2, (Uint32)500000);
 
892
    theOperation->branch_label((Uint32)2);
 
893
 
 
894
    theOperation->def_label(Tlabel++);
 
895
    theOperation->load_const_u32((Uint32)1, (Uint32)200000);
 
896
    theOperation->load_const_u32((Uint32)2, (Uint32)300000);
 
897
    theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
 
898
    theOperation->load_const_u32((Uint32)2, (Uint32)500000);
 
899
    theOperation->branch_label((Uint32)2);
 
900
 
 
901
    theOperation->def_label(Tlabel++);
 
902
    theOperation->load_const_u32((Uint32)1, (Uint32)2);
 
903
    Uint64 x = 0;
 
904
    theOperation->load_const_u64((Uint32)2, (Uint64)(x - 1));
 
905
    theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
 
906
    theOperation->load_const_u32((Uint32)2, (Uint32)1);
 
907
    theOperation->branch_label((Uint32)2);
 
908
 
 
909
    theOperation->def_label(Tlabel++);
 
910
    theOperation->load_const_u32((Uint32)1, (Uint32)2);
 
911
    theOperation->load_const_u64((Uint32)2, (Uint64)(x - 1));
 
912
    theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
 
913
    theOperation->load_const_u64((Uint32)2, (Uint64)1);
 
914
    theOperation->branch_label((Uint32)2);
 
915
 
 
916
    theOperation->def_label(Tlabel++);
 
917
    theOperation->read_attr((Uint32)1, (Uint32)2);
 
918
    theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
 
919
    theOperation->load_const_u32((Uint32)1, (Uint32)0);
 
920
    theOperation->branch_label(Tlabel + 1);
 
921
    theOperation->def_label(Tlabel++);
 
922
    theOperation->load_const_u32((Uint32)1, (Uint32)1);
 
923
    theOperation->def_label(Tlabel++);
 
924
    theOperation->write_attr((Uint32)1, (Uint32)1);
 
925
    ret_value = theOperation->incValue((Uint32)2, (Uint32)1);
 
926
    if (ret_value == -1) {
 
927
      ndbout << "Error in definition phase " << endl;
 
928
      ndbout << "Error = " << theOperation->getNdbError() << " on line = " << theOperation->getNdbErrorLine() << endl;
 
929
      aNdb->closeTransaction(theTransaction);
 
930
      return ret_value;
 
931
    }//if
 
932
  }//for
 
933
//------------------------------------------------------------------------------
 
934
//------------------------------------------------------------------------------
 
935
  ret_value = theTransaction->execute(Commit);                  // Perform the actual read and update
 
936
  if (ret_value == -1) {
 
937
    ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
 
938
    aNdb->closeTransaction(theTransaction); // < epaulsa
 
939
        return ret_value ;
 
940
  }//if
 
941
//------------------------------------------------------------------------------
 
942
//------------------------------------------------------------------------------
 
943
  aNdb->closeTransaction(theTransaction);
 
944
  return ret_value;
 
945
}//update_interpreter_test()
 
946
 
 
947
void* ThreadExec(void* ThreadData){
 
948
 
 
949
  ThreadNdb* tabThread = (ThreadNdb*)ThreadData;
 
950
  Ndb*             pMyNdb = NULL ;
 
951
  myRandom48Init(NdbTick_CurrentMillisecond());
 
952
 
 
953
  int              Tsuccess = 0 ;
 
954
  int          check = 0 ;
 
955
  int          loop_count_ops = 0;
 
956
  int              count, i, Ti;
 
957
  int              tType =  0 ;
 
958
  int          remType = 0 ;
 
959
  unsigned int thread_no = 0 ;
 
960
  unsigned long total_milliseconds;
 
961
  unsigned int key = 0 ;
 
962
  unsigned int prob = 0 ;
 
963
  unsigned long transaction_time = 0 ;
 
964
  unsigned long transaction_max_time = 0 ;
 
965
  unsigned long min_time, max_time[MAX_TIMERS];
 
966
  double           mean_time, mean_square_time, std_time; 
 
967
  
 
968
  thread_no = tabThread->ThreadNo;
 
969
  pMyNdb = tabThread->NdbRef;
 
970
  if (!pMyNdb) {
 
971
    pMyNdb = new Ndb( "TEST_DB" );
 
972
    pMyNdb->init();
 
973
  }//if
 
974
 
 
975
  for (;;){
 
976
 
 
977
    min_time = 0xFFFFFFFF;
 
978
    //for (Ti = 0; Ti < MAX_TIMERS ; Ti++) max_time[Ti] = 0;
 
979
        memset(&max_time, 0, sizeof max_time) ;
 
980
    mean_time = 0;
 
981
    mean_square_time = 0;
 
982
    ThreadReady[thread_no] = 1;
 
983
 
 
984
    while (!ThreadStart[thread_no]){
 
985
                NdbSleep_MilliSleep(1);
 
986
        }
 
987
 
 
988
    // Check if signal to exit is received
 
989
    if (ThreadStart[thread_no] == 999){
 
990
                delete pMyNdb;
 
991
                pMyNdb = NULL ;
 
992
                ThreadReady[thread_no] = 1;
 
993
                return 0 ;
 
994
    }//if
 
995
 
 
996
    tType = ThreadStart[thread_no];
 
997
    remType = tType;
 
998
    ThreadStart[thread_no] = 0;
 
999
        ThreadReady[thread_no] = 0 ;
 
1000
 
 
1001
    // Start transaction, type of transaction
 
1002
    // is received in the array ThreadStart
 
1003
    loop_count_ops = tNoOfOperations;
 
1004
 
 
1005
    START_TIMER_TOP
 
1006
    for (count=0 ; count < loop_count_ops ; count++) {
 
1007
      
 
1008
                Tsuccess = 0;
 
1009
//----------------------------------------------------
 
1010
// Generate a random key between 0 and tNoOfRecords - 1
 
1011
//----------------------------------------------------
 
1012
      key = myRandom48(tNoOfRecords); 
 
1013
//----------------------------------------------------
 
1014
// Start time measurement of transaction.
 
1015
//----------------------------------------------------
 
1016
      START_TIMER
 
1017
      //do {
 
1018
        switch (remType){
 
1019
          case 1:
 
1020
//----------------------------------------------------
 
1021
// Only lookups in short record table
 
1022
//----------------------------------------------------
 
1023
            Tsuccess = lookup(pMyNdb, key, 0, 1);
 
1024
            break;
 
1025
 
 
1026
          case 2:
 
1027
//----------------------------------------------------
 
1028
// Only lookups in long record table
 
1029
//----------------------------------------------------
 
1030
            Tsuccess = lookup(pMyNdb, key, 1, 1);
 
1031
            break;
 
1032
          case 3:
 
1033
//----------------------------------------------------
 
1034
// Only updates in short record table
 
1035
//----------------------------------------------------
 
1036
            Tsuccess = update(pMyNdb, key, 0, 1);
 
1037
            break;
 
1038
          case 4:
 
1039
//----------------------------------------------------
 
1040
// Only updates in long record table
 
1041
//----------------------------------------------------
 
1042
            Tsuccess = update(pMyNdb, key, 1, 1);
 
1043
            break;
 
1044
          case 5:
 
1045
//----------------------------------------------------
 
1046
// 50% read/50 % update in short record table
 
1047
//----------------------------------------------------
 
1048
            prob = myRandom48(100);
 
1049
            if (prob < 50)
 
1050
              Tsuccess = update(pMyNdb, key, 0, 1);
 
1051
            else
 
1052
              Tsuccess = lookup(pMyNdb, key, 0, 1);
 
1053
            break;
 
1054
          case 6:
 
1055
//----------------------------------------------------
 
1056
// 50% read/50 % update in long record table
 
1057
//----------------------------------------------------
 
1058
            prob = myRandom48(100);
 
1059
            if (prob < 50)
 
1060
              Tsuccess = update(pMyNdb, key, 1, 1);
 
1061
            else
 
1062
              Tsuccess = lookup(pMyNdb, key, 1, 1);
 
1063
            break;
 
1064
          case 7:
 
1065
//----------------------------------------------------
 
1066
// 80 read/20 % update in short record table
 
1067
//----------------------------------------------------
 
1068
            prob = myRandom48(100);
 
1069
            if (prob < 20)
 
1070
              Tsuccess = update(pMyNdb, key, 0, 1);
 
1071
            else
 
1072
              Tsuccess = lookup(pMyNdb, key, 0, 1);
 
1073
            break;
 
1074
          case 8:
 
1075
//----------------------------------------------------
 
1076
// 80 read/20 % update in long record table
 
1077
//----------------------------------------------------
 
1078
            prob = myRandom48(100);
 
1079
            if (prob < 20)
 
1080
              Tsuccess = update(pMyNdb, key, 1, 1);
 
1081
            else
 
1082
              Tsuccess = lookup(pMyNdb, key, 1, 1);
 
1083
            break;
 
1084
          case 9:
 
1085
//----------------------------------------------------
 
1086
// 25 read short/25 % read long/25 % update short/25 % update long
 
1087
//----------------------------------------------------
 
1088
            prob = myRandom48(100);
 
1089
            if (prob < 25)
 
1090
              Tsuccess = update(pMyNdb, key, 0, 1);
 
1091
            else if (prob < 50)
 
1092
              Tsuccess = update(pMyNdb, key, 1, 1);
 
1093
            else if (prob < 75)
 
1094
              Tsuccess = lookup(pMyNdb, key, 0, 1);
 
1095
            else
 
1096
              Tsuccess = lookup(pMyNdb, key, 1, 1);
 
1097
            break;
 
1098
          case 10:
 
1099
//----------------------------------------------------
 
1100
// Test bug with replicated interpreted update, short table
 
1101
//----------------------------------------------------
 
1102
            Tsuccess = update_bug(pMyNdb, key, 0);
 
1103
            break;
 
1104
          case 11:
 
1105
//----------------------------------------------------
 
1106
// Test interpreter functions, short table
 
1107
//----------------------------------------------------
 
1108
            Tsuccess = update_interpreter_test(pMyNdb, key, 0);
 
1109
            break;
 
1110
          case 12:
 
1111
//----------------------------------------------------
 
1112
// Test bug with replicated interpreted update, long table
 
1113
//----------------------------------------------------
 
1114
            Tsuccess = update_bug(pMyNdb, key, 1);
 
1115
            break;
 
1116
          case 13:
 
1117
//----------------------------------------------------
 
1118
// Test interpreter functions, long table
 
1119
//----------------------------------------------------
 
1120
            Tsuccess = update_interpreter_test(pMyNdb, key, 1);
 
1121
            break;
 
1122
          case 14:
 
1123
//----------------------------------------------------
 
1124
// Only lookups in short record table
 
1125
//----------------------------------------------------
 
1126
            Tsuccess = lookup(pMyNdb, key, 0, 0);
 
1127
            break;
 
1128
          case 15:
 
1129
//----------------------------------------------------
 
1130
// Only lookups in long record table
 
1131
//----------------------------------------------------
 
1132
            Tsuccess = lookup(pMyNdb, key, 1, 0);
 
1133
            break;
 
1134
          case 16:
 
1135
//----------------------------------------------------
 
1136
// Only updates in short record table
 
1137
//----------------------------------------------------
 
1138
            Tsuccess = update(pMyNdb, key, 0, 0);
 
1139
            break;
 
1140
          case 17:
 
1141
//----------------------------------------------------
 
1142
// Only updates in long record table
 
1143
//----------------------------------------------------
 
1144
            Tsuccess = update(pMyNdb, key, 1, 0);
 
1145
            break;
 
1146
          case 18:
 
1147
            Tsuccess = multiRecordTest(pMyNdb, key);
 
1148
            break;
 
1149
          default:
 
1150
            break;
 
1151
        }//switch
 
1152
      //} while (0);//
 
1153
          if(-1 == Tsuccess) {
 
1154
                  NDBT_ProgramExit(NDBT_FAILED);
 
1155
                  exit(-1);
 
1156
          } // for
 
1157
//----------------------------------------------------
 
1158
// Stop time measurement of transaction.
 
1159
//----------------------------------------------------     
 
1160
          STOP_TIMER      
 
1161
          transaction_time = (unsigned long)timer.elapsedTime() ;//stopTimer(&theStartTime);
 
1162
//----------------------------------------------------
 
1163
// Perform calculations of time measurements.
 
1164
//----------------------------------------------------
 
1165
      transaction_max_time = transaction_time;
 
1166
      for (Ti = 0; Ti < MAX_TIMERS; Ti++) {
 
1167
        if (transaction_max_time > max_time[Ti]) {
 
1168
          Uint32 tmp = max_time[Ti];
 
1169
          max_time[Ti] = transaction_max_time;
 
1170
          transaction_max_time = tmp;
 
1171
        }//if
 
1172
      }//if
 
1173
      if (transaction_time < min_time) min_time = transaction_time;
 
1174
      mean_time = (double)transaction_time + mean_time;
 
1175
      mean_square_time = (double)(transaction_time * transaction_time) + mean_square_time;
 
1176
    }//for
 
1177
//----------------------------------------------------
 
1178
// Calculate mean and standard deviation
 
1179
//----------------------------------------------------
 
1180
    STOP_TIMER_TOP
 
1181
    total_milliseconds = (unsigned long)timer_top.elapsedTime() ;//stopTimer(&total_time);
 
1182
    mean_time = mean_time / loop_count_ops;
 
1183
    mean_square_time = mean_square_time / loop_count_ops;
 
1184
    std_time = sqrt(mean_square_time - (mean_time * mean_time));
 
1185
//----------------------------------------------------
 
1186
// Report statistics
 
1187
//----------------------------------------------------
 
1188
        ndbout << "Thread = " << thread_no << " reporting:" << endl ;
 
1189
        ndbout << "------------------------------" << endl ;
 
1190
    ndbout << "Total time is " << (unsigned int)(total_milliseconds /1000);
 
1191
    ndbout << " seconds and " << (unsigned int)(total_milliseconds % 1000);
 
1192
    ndbout << " milliseconds" << endl;
 
1193
    ndbout << "Minimum time = " << (unsigned int)min_time << " milliseconds" << endl;
 
1194
    for (Ti = 0; Ti < MAX_TIMERS; Ti++) {
 
1195
      ndbout << "Maximum timer " << Ti << " = " << (unsigned int)max_time[Ti] << " milliseconds" << endl;
 
1196
      ndbout << "Mean time = " << (unsigned int)mean_time << " milliseconds" << endl;
 
1197
      ndbout << "Standard deviation on time = " << (unsigned int)std_time;
 
1198
      ndbout << " milliseconds" << endl << endl ;
 
1199
    }//for
 
1200
    ndbout << endl ;
 
1201
  
 
1202
  } // for(;;)
 
1203
  
 
1204
  delete pMyNdb ;
 
1205
  return 0 ;
 
1206
}
 
1207