1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
/* ***************************************************
19
Perform benchmark of insert, update and delete transactions
22
-t Number of threads to start, default 1
23
-o Number of loops per thread, default 100000
26
* *************************************************** */
28
#include <ndb_global.h>
31
#include <NdbTest.hpp>
33
#include <NdbThread.h>
36
#include <NdbTimer.hpp>
44
#define NDB_MAXTHREADS 256
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.
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();
58
void* ThreadExec(void*);
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];
74
NDB_COMMAND(benchronja, "benchronja", "benchronja", "benchronja", 65535){
77
ThreadNdb tabThread[NDB_MAXTHREADS];
80
Ndb* pMyNdb = NULL ; //( "TEST_DB" );
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
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;
114
ndbout << "Initialisation started. " << endl;
115
pMyNdb = new Ndb("TEST_DB") ;
117
ndbout << "Initialisation completed. " << endl;
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;
124
if (pMyNdb->waitUntilReady(120) != 0) {
125
ndbout << "Benchmark failed - NDB is not ready" << endl;
127
return NDBT_ProgramExit(NDBT_FAILED);
130
NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
132
for (i = 0; i < tNoOfThreads ; i++) {
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],
145
NDB_THREAD_PRIO_LOW);
150
NdbSleep_MilliSleep(10);
152
for (i = 0; i < tNoOfThreads ; i++)
153
if (!ThreadReady[i]) cont = 1;
156
ndbout << "All threads started" << endl;
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 ;
187
inp[inp_i] = (char) fgetc(stdin);
188
if (inp[inp_i] == '\n' || inp[inp_i] == EOF) {
194
} while (inp[inp_i - 1] != '\n' && inp[inp_i - 1] != EOF);
198
if ((tmp > 18) || (tmp <= 0)) break;
200
ndbout << "Starting test " << tmp << "..." << endl;
202
for (i = 0; i < tNoOfThreads ; i++){ ThreadStart[i] = tmp; }
206
NdbSleep_MilliSleep(10);
208
for (i = 0; i < tNoOfThreads ; i++){
209
if (!ThreadReady[i]) cont = 1;
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 ; }
224
NdbSleep_MilliSleep(10);
226
for (i = 0; i < tNoOfThreads ; i++){
227
if (!ThreadReady[i]) cont = 1;
232
ndbout << endl << "Executing test " << nTest << endl << endl;
233
for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = nTest ; }
236
NdbSleep_MilliSleep(10);
238
for (i = 0; i < tNoOfThreads ; i++){
239
if (!ThreadReady[i]) cont = 1;
245
ndbout << "--------------------------------------------------" << endl;
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;
251
// Wait for threads to stop
254
NdbSleep_MilliSleep(1);
256
for (i = 0; i < tNoOfThreads ; i++){
257
if (ThreadReady[i] == 0) cont = 1;
262
ndbout << endl << "Ronja Benchmark completed" << endl;
263
return NDBT_ProgramExit(NDBT_OK) ;
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 ;
275
return NDBT_ProgramExit(NDBT_WRONGARGS) ;
278
////////////////////////////////////////
280
void commitTrans(Ndb* aNdb, NdbConnection* aCon)
282
int ret = aCon->execute(Commit);
284
aNdb->closeTransaction(aCon);
287
void rollbackTrans(Ndb* aNdb, NdbConnection* aCon)
289
int ret = aCon->execute(Rollback);
291
aNdb->closeTransaction(aCon);
294
void updateNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
296
NdbOperation* theOperation;
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);
307
void updateNoCommitFail(NdbConnection* aCon, unsigned int key)
309
NdbOperation* theOperation;
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);
320
void deleteNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
322
NdbOperation* theOperation;
325
theOperation = aCon->getNdbOperation("SHORT_REC");
326
theOperation->deleteTuple();
327
theOperation->equal((Uint32)0, key);
328
int ret = aCon->execute(NoCommit);
332
void insertNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
334
NdbOperation* theOperation;
335
Uint32 placeholder[100];
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);
348
void writeNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
350
NdbOperation* theOperation;
351
Uint32 placeholder[100];
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);
364
void readNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
366
NdbOperation* theOperation;
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);
376
assert (*flip == readFlip);
379
void readDirtyNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
381
NdbOperation* theOperation;
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);
391
assert (*flip == readFlip);
394
void readVerify(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
396
NdbConnection* theTransaction;
397
theTransaction = aNdb->startTransaction();
398
readNoCommit(theTransaction, flip, key, expected_ret);
399
commitTrans(aNdb, theTransaction);
402
void readDirty(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
404
NdbOperation* theOperation;
405
NdbConnection* theTransaction;
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);
416
assert (*flip == readFlip);
417
aNdb->closeTransaction(theTransaction);
420
int multiRecordTest(Ndb* aNdb, unsigned int key)
422
NdbConnection* theTransaction;
425
ndbout << "0" << endl;
427
theTransaction = aNdb->startTransaction();
429
updateNoCommit(theTransaction, &flip, key);
431
readNoCommit(theTransaction, &flip, key, 0);
433
updateNoCommit(theTransaction, &flip, key);
435
readNoCommit(theTransaction, &flip, key, 0);
437
commitTrans(aNdb, theTransaction);
439
ndbout << "1 " << endl;
441
readVerify(aNdb, &flip, key, 0);
442
readDirty(aNdb, &flip, key, 0);
444
ndbout << "1.1 " << endl;
446
theTransaction = aNdb->startTransaction();
448
deleteNoCommit(theTransaction, &flip, key);
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;
455
insertNoCommit(theTransaction, &flip, key);
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;
462
updateNoCommit(theTransaction, &flip, key);
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;
469
commitTrans(aNdb, theTransaction);
471
ndbout << "2 " << endl;
473
readDirty(aNdb, &flip, key, 0); // COMMITTED READ!!!
474
readVerify(aNdb, &flip, key, 0);
477
theTransaction = aNdb->startTransaction();
479
deleteNoCommit(theTransaction, &flip, key);
481
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
482
readDirtyNoCommit(theTransaction, &flip, key, -1); // COMMITTED READ!!!
483
readNoCommit(theTransaction, &flip, key, -1);
485
insertNoCommit(theTransaction, &flip, key);
487
readNoCommit(theTransaction, &flip, key, 0);
489
updateNoCommit(theTransaction, &flip, key);
491
readNoCommit(theTransaction, &flip, key, 0);
492
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
493
readDirtyNoCommit(theTransaction, &flip, key, 0); // COMMITTED READ!!!
495
deleteNoCommit(theTransaction, &flip, key);
497
readNoCommit(theTransaction, &flip, key, -1);
498
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
499
readDirtyNoCommit(theTransaction, &flip, key, -1);
501
rollbackTrans(aNdb, theTransaction);
503
ndbout << "3 " << endl;
506
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
507
readVerify(aNdb, &flip, key, 0);
509
theTransaction = aNdb->startTransaction();
511
updateNoCommit(theTransaction, &flip, key);
513
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
514
readDirtyNoCommit(theTransaction, &flip, key, 0);
515
readNoCommit(theTransaction, &flip, key, 0);
517
deleteNoCommit(theTransaction, &flip, key);
519
readNoCommit(theTransaction, &flip, key, -1);
520
readDirtyNoCommit(theTransaction, &flip, key, -1);
521
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
523
insertNoCommit(theTransaction, &flip, key);
525
readNoCommit(theTransaction, &flip, key, 0);
526
readDirtyNoCommit(theTransaction, &flip, key, 0);
527
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
529
updateNoCommit(theTransaction, &flip, key);
531
readNoCommit(theTransaction, &flip, key, 0);
532
readDirtyNoCommit(theTransaction, &flip, key, 0);
533
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
535
deleteNoCommit(theTransaction, &flip, key);
537
readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
538
readNoCommit(theTransaction, &flip, key, -1);
539
readDirtyNoCommit(theTransaction, &flip, key, -1);
541
commitTrans(aNdb, theTransaction);
543
ndbout << "4 " << endl;
545
readVerify(aNdb, &flip, key, -1);
547
theTransaction = aNdb->startTransaction();
549
insertNoCommit(theTransaction, &flip, key);
551
readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
552
readNoCommit(theTransaction, &flip, key, 0);
553
readDirtyNoCommit(theTransaction, &flip, key, 0);
555
deleteNoCommit(theTransaction, &flip, key);
557
readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
558
readNoCommit(theTransaction, &flip, key, -1);
559
readDirtyNoCommit(theTransaction, &flip, key, -1);
561
insertNoCommit(theTransaction, &flip, key);
563
readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
564
readNoCommit(theTransaction, &flip, key, 0);
565
readDirtyNoCommit(theTransaction, &flip, key, 0);
567
updateNoCommit(theTransaction, &flip, key);
569
readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
570
readNoCommit(theTransaction, &flip, key, 0);
571
readDirtyNoCommit(theTransaction, &flip, key, 0);
573
deleteNoCommit(theTransaction, &flip, key);
575
readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
576
readNoCommit(theTransaction, &flip, key, -1);
577
readDirtyNoCommit(theTransaction, &flip, key, -1);
579
commitTrans(aNdb, theTransaction);
581
ndbout << "5 " << endl;
583
readDirty(aNdb, &flip, key, -1); // COMMITTED READ!!!
584
readVerify(aNdb, &flip, key, -1);
586
theTransaction = aNdb->startTransaction();
588
insertNoCommit(theTransaction, &flip, key);
590
readDirty(aNdb, &flip, key, -1); // COMMITTED READ!!!
591
readDirtyNoCommit(theTransaction, &flip, key, 0); // COMMITTED READ!!!
593
commitTrans(aNdb, theTransaction);
594
readDirty(aNdb, &flip, key, 0); // COMMITTED READ!!!
596
ndbout << "6 " << endl;
598
theTransaction = aNdb->startTransaction();
600
deleteNoCommit(theTransaction, &flip, key);
601
updateNoCommitFail(theTransaction, key);
602
rollbackTrans(aNdb, theTransaction);
606
int lookup(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess){
608
int placeholder[500];
609
unsigned int flip, count;
611
NdbConnection* theTransaction;
612
NdbOperation* theOperation;
613
if ( !aNdb ) return -1 ;
616
theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
618
theTransaction = aNdb->startTransaction();
620
for (i = 0; i < tNoOfOpsPerExecute; i++) {
622
theOperation = theTransaction->getNdbOperation("SHORT_REC");
624
theOperation = theTransaction->getNdbOperation("LONG_REC");
625
if (theOperation == NULL) {
626
ndbout << "Table missing" << endl;
627
aNdb->closeTransaction(theTransaction) ;
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);
640
ret_value = theTransaction->execute(Commit);
642
ndbout << "Error in lookup:" << theTransaction->getNdbError() << endl;
643
aNdb->closeTransaction(theTransaction);
647
int update(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess)
649
int placeholder[500];
651
unsigned int flip, count;
652
NdbConnection* theTransaction;
653
NdbOperation* theOperation;
655
if ( !aNdb ) return -1 ;
658
theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
660
theTransaction = aNdb->startTransaction();
662
for (i = 0; i < tNoOfOpsPerExecute; i++) {
664
theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
666
theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
667
if (theOperation == NULL) {
668
ndbout << "Table missing" << endl;
669
aNdb->closeTransaction(theTransaction) ;
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);
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
699
aNdb->closeTransaction(theTransaction);
703
int update_bug(Ndb* aNdb, unsigned int key, unsigned int long_short)
705
int placeholder[500];
707
unsigned int flip, count;
708
NdbConnection* theTransaction;
709
NdbOperation* theOperation;
711
if ( !aNdb ) return -1 ;
713
theTransaction = aNdb->startTransaction();
714
for (i = 0; i < tNoOfOpsPerExecute; i++) {
716
theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
718
theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
719
if (theOperation == NULL) {
720
ndbout << "Table missing" << endl;
721
aNdb->closeTransaction(theTransaction) ;
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);
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);
750
aNdb->closeTransaction(theTransaction);
754
int update_interpreter_test(Ndb* aNdb, unsigned int key, unsigned int long_short)
756
int placeholder[500];
758
unsigned int flip, count;
759
NdbConnection* theTransaction;
760
NdbOperation* theOperation;
763
if ( !aNdb ) return -1 ;
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
773
//------------------------------------------------------------------------------
775
theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
777
theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
778
if (theOperation == NULL) {
779
ndbout << "Table missing" << endl;
780
aNdb->closeTransaction(theTransaction) ;
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
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
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
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);
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
820
theOperation->def_label(Tlabel++);
822
theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
823
theOperation->interpret_exit_nok((Uint32)6001);
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);
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);
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);
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);
849
theOperation->def_label(Tlabel++);
850
theOperation->branch_ne_null((Uint32)1,Tlabel);
851
theOperation->interpret_exit_nok((Uint32)6007);
853
theOperation->def_label(Tlabel++);
854
theOperation->branch_ge((Uint32)1, (Uint32)2, Tlabel);
855
theOperation->interpret_exit_nok((Uint32)6008);
857
theOperation->def_label(Tlabel++);
858
theOperation->branch_eq_null((Uint32)6,Tlabel);
859
theOperation->interpret_exit_nok((Uint32)6009);
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);
867
theOperation->def_label(Tlabel++);
869
theOperation->load_const_u32((Uint32)5, (Uint32)1);
870
theOperation->add_reg((Uint32)4, (Uint32)5, (Uint32)4);
872
theOperation->load_const_u32((Uint32)5, (Uint32)1);
873
theOperation->branch_eq((Uint32)4, (Uint32)5, Tlabel);
876
theOperation->load_const_u32((Uint32)5, (Uint32)2);
877
theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 1));
879
theOperation->load_const_u32((Uint32)5, (Uint32)3);
880
theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 2));
882
theOperation->load_const_u32((Uint32)5, (Uint32)4);
883
theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 3));
885
theOperation->branch_label(Tlabel + 4);
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);
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);
901
theOperation->def_label(Tlabel++);
902
theOperation->load_const_u32((Uint32)1, (Uint32)2);
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);
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);
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);
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
941
//------------------------------------------------------------------------------
942
//------------------------------------------------------------------------------
943
aNdb->closeTransaction(theTransaction);
945
}//update_interpreter_test()
947
void* ThreadExec(void* ThreadData){
949
ThreadNdb* tabThread = (ThreadNdb*)ThreadData;
951
myRandom48Init(NdbTick_CurrentMillisecond());
955
int loop_count_ops = 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;
968
thread_no = tabThread->ThreadNo;
969
pMyNdb = tabThread->NdbRef;
971
pMyNdb = new Ndb( "TEST_DB" );
977
min_time = 0xFFFFFFFF;
978
//for (Ti = 0; Ti < MAX_TIMERS ; Ti++) max_time[Ti] = 0;
979
memset(&max_time, 0, sizeof max_time) ;
981
mean_square_time = 0;
982
ThreadReady[thread_no] = 1;
984
while (!ThreadStart[thread_no]){
985
NdbSleep_MilliSleep(1);
988
// Check if signal to exit is received
989
if (ThreadStart[thread_no] == 999){
992
ThreadReady[thread_no] = 1;
996
tType = ThreadStart[thread_no];
998
ThreadStart[thread_no] = 0;
999
ThreadReady[thread_no] = 0 ;
1001
// Start transaction, type of transaction
1002
// is received in the array ThreadStart
1003
loop_count_ops = tNoOfOperations;
1006
for (count=0 ; count < loop_count_ops ; count++) {
1009
//----------------------------------------------------
1010
// Generate a random key between 0 and tNoOfRecords - 1
1011
//----------------------------------------------------
1012
key = myRandom48(tNoOfRecords);
1013
//----------------------------------------------------
1014
// Start time measurement of transaction.
1015
//----------------------------------------------------
1020
//----------------------------------------------------
1021
// Only lookups in short record table
1022
//----------------------------------------------------
1023
Tsuccess = lookup(pMyNdb, key, 0, 1);
1027
//----------------------------------------------------
1028
// Only lookups in long record table
1029
//----------------------------------------------------
1030
Tsuccess = lookup(pMyNdb, key, 1, 1);
1033
//----------------------------------------------------
1034
// Only updates in short record table
1035
//----------------------------------------------------
1036
Tsuccess = update(pMyNdb, key, 0, 1);
1039
//----------------------------------------------------
1040
// Only updates in long record table
1041
//----------------------------------------------------
1042
Tsuccess = update(pMyNdb, key, 1, 1);
1045
//----------------------------------------------------
1046
// 50% read/50 % update in short record table
1047
//----------------------------------------------------
1048
prob = myRandom48(100);
1050
Tsuccess = update(pMyNdb, key, 0, 1);
1052
Tsuccess = lookup(pMyNdb, key, 0, 1);
1055
//----------------------------------------------------
1056
// 50% read/50 % update in long record table
1057
//----------------------------------------------------
1058
prob = myRandom48(100);
1060
Tsuccess = update(pMyNdb, key, 1, 1);
1062
Tsuccess = lookup(pMyNdb, key, 1, 1);
1065
//----------------------------------------------------
1066
// 80 read/20 % update in short record table
1067
//----------------------------------------------------
1068
prob = myRandom48(100);
1070
Tsuccess = update(pMyNdb, key, 0, 1);
1072
Tsuccess = lookup(pMyNdb, key, 0, 1);
1075
//----------------------------------------------------
1076
// 80 read/20 % update in long record table
1077
//----------------------------------------------------
1078
prob = myRandom48(100);
1080
Tsuccess = update(pMyNdb, key, 1, 1);
1082
Tsuccess = lookup(pMyNdb, key, 1, 1);
1085
//----------------------------------------------------
1086
// 25 read short/25 % read long/25 % update short/25 % update long
1087
//----------------------------------------------------
1088
prob = myRandom48(100);
1090
Tsuccess = update(pMyNdb, key, 0, 1);
1092
Tsuccess = update(pMyNdb, key, 1, 1);
1094
Tsuccess = lookup(pMyNdb, key, 0, 1);
1096
Tsuccess = lookup(pMyNdb, key, 1, 1);
1099
//----------------------------------------------------
1100
// Test bug with replicated interpreted update, short table
1101
//----------------------------------------------------
1102
Tsuccess = update_bug(pMyNdb, key, 0);
1105
//----------------------------------------------------
1106
// Test interpreter functions, short table
1107
//----------------------------------------------------
1108
Tsuccess = update_interpreter_test(pMyNdb, key, 0);
1111
//----------------------------------------------------
1112
// Test bug with replicated interpreted update, long table
1113
//----------------------------------------------------
1114
Tsuccess = update_bug(pMyNdb, key, 1);
1117
//----------------------------------------------------
1118
// Test interpreter functions, long table
1119
//----------------------------------------------------
1120
Tsuccess = update_interpreter_test(pMyNdb, key, 1);
1123
//----------------------------------------------------
1124
// Only lookups in short record table
1125
//----------------------------------------------------
1126
Tsuccess = lookup(pMyNdb, key, 0, 0);
1129
//----------------------------------------------------
1130
// Only lookups in long record table
1131
//----------------------------------------------------
1132
Tsuccess = lookup(pMyNdb, key, 1, 0);
1135
//----------------------------------------------------
1136
// Only updates in short record table
1137
//----------------------------------------------------
1138
Tsuccess = update(pMyNdb, key, 0, 0);
1141
//----------------------------------------------------
1142
// Only updates in long record table
1143
//----------------------------------------------------
1144
Tsuccess = update(pMyNdb, key, 1, 0);
1147
Tsuccess = multiRecordTest(pMyNdb, key);
1153
if(-1 == Tsuccess) {
1154
NDBT_ProgramExit(NDBT_FAILED);
1157
//----------------------------------------------------
1158
// Stop time measurement of transaction.
1159
//----------------------------------------------------
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;
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;
1177
//----------------------------------------------------
1178
// Calculate mean and standard deviation
1179
//----------------------------------------------------
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 ;