1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
|
/* Copyright (c) 2003-2005, 2007 MySQL AB
Use is subject to license terms
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
/* ***************************************************
FLEXTIMEDASYNCH
Perform benchmark of insert, update and delete transactions.
Arguments:
-t Number of threads to start, i.e., number of parallel loops, default 1
-p Number of transactions in a batch, default 32
-o Number of batches per loop, default 200
-i Time between batch starts, default 0
-l Number of loops to run, default 1, 0=infinite
-a Number of attributes, default 25
-c Number of operations per transaction
-s Size of each attribute in 32 bit word, default 1 (Primary Key is always of size 1,
independent of this value)
-simple Use simple read to read from database
-dirty Use dirty read to read from database
-write Use writeTuple in insert and update
-n Use standard table names
-no_table_create Don't create tables in db
-temp Use temporary tables, no writing to disk.
Returns:
0 - Test passed
-1 - Test failed
1 - Invalid arguments
* *************************************************** */
#include "NdbApi.hpp"
#include <NdbThread.h>
#include <NdbSleep.h>
#include <NdbTick.h>
#include <NdbOut.hpp>
#include <NdbTimer.hpp>
#include <string.h>
#include <NdbMain.h>
#include <NdbTest.hpp>
#include <NDBT_Error.hpp>
#define MAXSTRLEN 16
#define MAXATTR 64
#define MAXTABLES 64
#define NDB_MAXTHREADS 256
/*
NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
#define from <sys/thread.h> on AIX (IBM compiler). We explicitly
#undef it here lest someone use it by habit and get really funny
results. K&R says we may #undef non-existent symbols, so let's go.
*/
#undef MAXTHREADS
#define MAXATTRSIZE 1000
#define PKSIZE 1
enum StartType { stIdle,
stInsert,
stRead,
stUpdate,
stDelete,
stStop } ;
ErrorData * flexTimedAsynchErrorData;
struct ThreadNdb
{
int NoOfOps;
int ThreadNo;
unsigned int threadBase;
unsigned int transactionCompleted;
};
extern "C" void* threadLoop(void*);
void setAttrNames(void);
void setTableNames(void);
void readArguments(int argc, const char** argv);
void createAttributeSpace();
void createTables(Ndb*);
void defineOperation(NdbConnection* aTransObject, StartType aType, unsigned int key, int *);
void execute(StartType aType);
void executeThread(StartType aType, Ndb* aNdbObject, ThreadNdb* threadInfo);
void executeCallback(int result, NdbConnection* NdbObject, void* aObject);
/* epaulsa > *************************************************************/
bool error_handler(const NdbError &) ; //replaces 'goto' things
static int failed = 0 ; // lame global variable that keeps track of failed transactions
// incremented in executeCallback() and reset in main()
/************************************************************* < epaulsa */
static NdbThread* threadLife[NDB_MAXTHREADS];
static int tNodeId;
static int ThreadReady[NDB_MAXTHREADS];
static StartType ThreadStart[NDB_MAXTHREADS];
static char tableName[MAXTABLES][MAXSTRLEN+1];
static char attrName[MAXATTR][MAXSTRLEN+1];
static int *getAttrValueTable;
// Program Parameters
static int tNoOfLoops = 1;
static int tAttributeSize = 1;
static unsigned int tNoOfThreads = 1;
static unsigned int tNoOfTransInBatch = 32;
static unsigned int tNoOfAttributes = 25;
static unsigned int tNoOfBatchesInLoop = 200;
static unsigned int tNoOfOpsPerTrans = 1;
static unsigned int tTimeBetweenBatches = 0;
//Program Flags
static int theTestFlag = 0;
static int theTempFlag = 1;
static int theSimpleFlag = 0;
static int theDirtyFlag = 0;
static int theWriteFlag = 0;
static int theStdTableNameFlag = 0;
static int theTableCreateFlag = 0;
#define START_REAL_TIME NdbTimer timer; timer.doStart();
#define STOP_REAL_TIME timer.doStop();
#define START_TIMER { NdbTimer timer; timer.doStart();
#define STOP_TIMER timer.doStop();
#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
void
resetThreads(){
for (int i = 0; i < tNoOfThreads ; i++) {
ThreadReady[i] = 0;
ThreadStart[i] = stIdle;
}
}
void
waitForThreads(void)
{
int cont;
do {
cont = 0;
NdbSleep_MilliSleep(20);
for (int i = 0; i < tNoOfThreads ; i++) {
if (ThreadReady[i] == 0) {
cont = 1;
}
}
} while (cont == 1);
}
void
tellThreads(StartType what)
{
for (int i = 0; i < tNoOfThreads ; i++)
ThreadStart[i] = what;
}
void createAttributeSpace(){
getAttrValueTable = new int[tAttributeSize*
tNoOfThreads *
tNoOfAttributes ];
}
void deleteAttributeSpace(){
delete [] getAttrValueTable;
}
NDB_COMMAND(flexTimedAsynch, "flexTimedAsynch", "flexTimedAsynch [-tpoilcas]", "flexTimedAsynch", 65535)
{
ndb_init();
ThreadNdb tabThread[NDB_MAXTHREADS];
int tLoops=0;
int returnValue;
//NdbOut flexTimedAsynchNdbOut;
flexTimedAsynchErrorData = new ErrorData;
flexTimedAsynchErrorData->resetErrorCounters();
Ndb* pNdb;
pNdb = new Ndb( "TEST_DB" );
pNdb->init();
readArguments(argc, argv);
createAttributeSpace();
ndbout << endl << "FLEXTIMEDASYNCH - Starting normal mode" << endl;
ndbout << "Perform benchmark of insert, update and delete transactions" << endl << endl;
if(theTempFlag == 0)
ndbout << " " << "Using temporary tables. " << endl;
// -t, tNoOfThreads
ndbout << " " << tNoOfThreads << " number of concurrent threads " << endl;
// -c, tNoOfOpsPerTrans
ndbout << " " << tNoOfOpsPerTrans << " operations per transaction " << endl;
// -p, tNoOfTransInBatch
ndbout << " " << tNoOfTransInBatch << " number of transactions in a batch per thread " << endl;
// -o, tNoOfBatchesInLoop
ndbout << " " << tNoOfBatchesInLoop << " number of batches per loop " << endl;
// -i, tTimeBetweenBatches
ndbout << " " << tTimeBetweenBatches << " milli seconds at least between batch starts " << endl;
// -l, tNoOfLoops
ndbout << " " << tNoOfLoops << " loops " << endl;
// -a, tNoOfAttributes
ndbout << " " << tNoOfAttributes << " attributes per table " << endl;
// -s, tAttributeSize
ndbout << " " << tAttributeSize << " is the number of 32 bit words per attribute " << endl << endl;
NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
/* print Setting */
flexTimedAsynchErrorData->printSettings(ndbout);
setAttrNames();
setTableNames();
ndbout << "Waiting for ndb to become ready..." <<endl;
if (pNdb->waitUntilReady() == 0) {
tNodeId = pNdb->getNodeId();
ndbout << " NdbAPI node with id = " << tNodeId << endl;
createTables(pNdb);
/****************************************************************
* Create NDB objects. *
****************************************************************/
resetThreads();
for (int i = 0; i < tNoOfThreads ; i++) {
tabThread[i].ThreadNo = i;
threadLife[i] = NdbThread_Create(threadLoop,
(void**)&tabThread[i],
32768,
"flexTimedAsynchThread",
NDB_THREAD_PRIO_LOW);
}
ndbout << endl << "All NDB objects and table created" << endl << endl;
int noOfTransacts = tNoOfTransInBatch*tNoOfBatchesInLoop*tNoOfThreads;
/****************************************************************
* Execute program. *
****************************************************************/
for(;;) {
int loopCount = tLoops + 1 ;
ndbout << endl << "Loop # " << loopCount << endl << endl ;
/****************************************************************
* Perform inserts. *
****************************************************************/
failed = 0 ;
START_TIMER;
execute(stInsert);
STOP_TIMER;
PRINT_TIMER("insert", noOfTransacts, tNoOfOpsPerTrans);
if (0 < failed) {
ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
}
/****************************************************************
* Perform read. *
****************************************************************/
failed = 0 ;
START_TIMER;
execute(stRead);
STOP_TIMER;
PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
if (0 < failed) {
ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
}
/****************************************************************
* Perform update. *
***************************************************************/
failed = 0 ;
START_TIMER;
execute(stUpdate);
STOP_TIMER;
PRINT_TIMER("update", noOfTransacts, tNoOfOpsPerTrans) ;
if (0 < failed) {
ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
}
/****************************************************************
* Perform read after update.
****************************************************************/
failed = 0 ;
START_TIMER;
execute(stRead);
STOP_TIMER;
PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
if (0 < failed) {
ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
}
/****************************************************************
* Perform delete. *
****************************************************************/
failed = 0;
START_TIMER;
execute(stDelete);
STOP_TIMER;
PRINT_TIMER("delete", noOfTransacts, tNoOfOpsPerTrans);
if (0 < failed) {
ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
}
tLoops++;
ndbout << "--------------------------------------------------" << endl;
if(tNoOfLoops != 0){
if(tNoOfLoops <= tLoops)
break ;
}
}
ndbout << endl << "Benchmark completed!" << endl;
returnValue = NDBT_OK;
execute(stStop);
void * tmp;
for(int i = 0; i<tNoOfThreads; i++){
NdbThread_WaitFor(threadLife[i], &tmp);
NdbThread_Destroy(&threadLife[i]);
}
} else {
ndbout << "NDB is not ready" << endl;
ndbout << "Benchmark failed!" << endl;
returnValue = NDBT_FAILED;
}
deleteAttributeSpace();
delete pNdb;
//printing errorCounters
flexTimedAsynchErrorData->printErrorCounters(ndbout);
return NDBT_ProgramExit(returnValue);
}//main()
////////////////////////////////////////
void execute(StartType aType)
{
resetThreads();
tellThreads(aType);
waitForThreads();
}
void*
threadLoop(void* ThreadData)
{
// Do work until signaled to stop.
Ndb* localNdb;
StartType tType;
ThreadNdb* threadInfo = (ThreadNdb*)ThreadData;
int threadNo = threadInfo->ThreadNo;
localNdb = new Ndb("TEST_DB");
localNdb->init(512);
localNdb->waitUntilReady();
threadInfo->threadBase = (threadNo * 2000000) + (tNodeId * 260000000);
for (;;) {
while (ThreadStart[threadNo] == stIdle) {
NdbSleep_MilliSleep(10);
}
// Check if signal to exit is received
if (ThreadStart[threadNo] == stStop) {
break;
}
tType = ThreadStart[threadNo];
ThreadStart[threadNo] = stIdle;
executeThread(tType, localNdb, threadInfo);
ThreadReady[threadNo] = 1;
}
delete localNdb;
ThreadReady[threadNo] = 1;
return NULL; // thread exits
}
void executeThread(StartType aType, Ndb* aNdbObject, ThreadNdb* threadInfo)
{
// Do all batch job in loop with start specified delay
int i, j, k;
NdbConnection* tConArray[1024];
unsigned int tBase;
unsigned int tBase2;
int threadId = threadInfo->ThreadNo;
int *getValueRowAddress = NULL;
NdbTimer timer;
timer.doStart();
for (i = 0; i < tNoOfBatchesInLoop; i++) {
//tBase = threadBase + (i * tNoOfTransInBatch * tNoOfOpsPerTrans);
tBase = threadInfo->threadBase + (i * tNoOfTransInBatch * tNoOfOpsPerTrans);
//tCompleted = 0;
threadInfo->transactionCompleted = 0;
for (j = 0; j < tNoOfTransInBatch; j++) {
tBase2 = tBase + (j * tNoOfOpsPerTrans);
tConArray[j] = aNdbObject->startTransaction();
if ( tConArray[j] == NULL && !error_handler(aNdbObject->getNdbError())) {
ndbout << endl << "Unable to recover! Quiting now" << endl ;
exit (-1) ;
return ;
}
for (k = 0; k < tNoOfOpsPerTrans; k++) {
//-------------------------------------------------------
// Define the operation, but do not execute it yet.
//-------------------------------------------------------
if(aType == stRead){
getValueRowAddress = getAttrValueTable +
threadId * tNoOfAttributes * tAttributeSize;
}
defineOperation(tConArray[j], aType, (tBase2 + k), getValueRowAddress);
}
tConArray[j]->executeAsynchPrepare(Commit, &executeCallback, threadInfo);
}
//-------------------------------------------------------
// Now we have defined a set of transactions (= batch), it is now time
// to execute all of them.
//-------------------------------------------------------
aNdbObject->sendPollNdb(3000, 0, 0);
//while (tCompleted < tNoOfTransInBatch) {
while (threadInfo->transactionCompleted < tNoOfTransInBatch) {
aNdbObject->pollNdb(3000, 0);
ndbout << "threadInfo->transactionCompleted = " <<
threadInfo->transactionCompleted << endl;
}
for (j = 0 ; j < tNoOfTransInBatch ; j++) {
aNdbObject->closeTransaction(tConArray[j]);
}
// Control the elapsed time since the last batch start.
// Wait at least tTimeBetweenBatches milli seconds.
timer.doStop();
while(timer.elapsedTime() < tTimeBetweenBatches){
NdbSleep_MilliSleep(1);
timer.doStop();
}
// Ready to start new batch
timer.doStart();
}
return;
}
void
executeCallback(int result, NdbConnection* NdbObject, void* aObject)
{
//tCompleted++;
ThreadNdb *threadInfo = (ThreadNdb *)aObject;
threadInfo->transactionCompleted++;
if (result == -1) {
// Add complete error handling here
int retCode = flexTimedAsynchErrorData->handleErrorCommon(NdbObject->getNdbError());
if (retCode == 1) {
if (NdbObject->getNdbError().code != 626 && NdbObject->getNdbError().code != 630){
ndbout_c("execute: %s", NdbObject->getNdbError().message);
ndbout_c("Error code = %d", NdbObject->getNdbError().code);}
} else if (retCode == 2) {
ndbout << "4115 should not happen in flexAsynch" << endl;
} else if (retCode == 3) {
/* What can we do here? */
ndbout_c("execute: %s", NdbObject->getNdbError().message);
}//if(retCode == 3)
// ndbout << "Error occured in poll:" << NdbObject->getNdbError() <<
// " ErrorCode = " << NdbObject->getNdbError() << endl;
ndbout << "executeCallback threadInfo->transactionCompleted = " <<
threadInfo->transactionCompleted << endl;
failed++ ;
return;
}
return;
}
void
defineOperation(NdbConnection* localNdbConnection,
StartType aType,
unsigned int threadBase,
int *pRow )
{
NdbOperation* localNdbOperation;
unsigned int loopCountAttributes = tNoOfAttributes;
unsigned int countAttributes;
int attrValue[MAXATTRSIZE];
//-------------------------------------------------------
// Set-up the attribute values for this operation.
//-------------------------------------------------------
for (int k = 0; k < loopCountAttributes; k++) {
*(int *)&attrValue[k] = (int)threadBase;
}
localNdbOperation = localNdbConnection->getNdbOperation(tableName[0]);
if (localNdbOperation == NULL) {
error_handler(localNdbOperation->getNdbError()) ;
}
switch (aType) {
case stInsert: { // Insert case
if (theWriteFlag == 1 && theDirtyFlag == 1) {
localNdbOperation->dirtyWrite();
} else if (theWriteFlag == 1) {
localNdbOperation->writeTuple();
} else {
localNdbOperation->insertTuple();
}
break;
}
case stRead: { // Read Case
if (theSimpleFlag == 1) {
localNdbOperation->simpleRead();
} else if (theDirtyFlag == 1) {
localNdbOperation->dirtyRead();
} else {
localNdbOperation->readTuple();
}
break;
}
case stUpdate: { // Update Case
if (theWriteFlag == 1 && theDirtyFlag == 1) {
localNdbOperation->dirtyWrite();
} else if (theWriteFlag == 1) {
localNdbOperation->writeTuple();
} else if (theDirtyFlag == 1) {
localNdbOperation->dirtyUpdate();
} else {
localNdbOperation->updateTuple();
}
break;
}
case stDelete: { // Delete Case
localNdbOperation->deleteTuple();
break;
}
default: {
error_handler(localNdbOperation->getNdbError());
}
}
localNdbOperation->equal((char*)attrName[0],(char*)&attrValue[0]);
switch (aType) {
case stInsert: // Insert case
case stUpdate: // Update Case
{
for (countAttributes = 1; countAttributes < loopCountAttributes; countAttributes++) {
localNdbOperation->setValue( (char*)attrName[countAttributes],(char*)&attrValue[0]);
}
break;
}
case stRead: { // Read Case
for (countAttributes = 1; countAttributes < loopCountAttributes; countAttributes++) {
//localNdbOperation->getValue((char*)attrName[countAttributes],(char*)&attrValue[0]);
localNdbOperation->getValue((char*)attrName[countAttributes],
(char *) (pRow + countAttributes*tAttributeSize));
}
break;
}
case stDelete: { // Delete Case
break;
}
default: {
error_handler(localNdbOperation->getNdbError());
}
}
return;
}
void readArguments(int argc, const char** argv)
{
int i = 1;
while (argc > 1)
{
if (strcmp(argv[i], "-t") == 0)
{
tNoOfThreads = atoi(argv[i+1]);
// if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS))
if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS))
exit(-1);
}
else if (strcmp(argv[i], "-i") == 0)
{
tTimeBetweenBatches = atoi(argv[i+1]);
if (tTimeBetweenBatches < 0)
exit(-1);
}
else if (strcmp(argv[i], "-p") == 0)
{
tNoOfTransInBatch = atoi(argv[i+1]);
//if ((tNoOfTransInBatch < 1) || (tNoOfTransInBatch > NDB_MAXTHREADS))
if ((tNoOfTransInBatch < 1) || (tNoOfTransInBatch > 10000))
exit(-1);
}
else if (strcmp(argv[i], "-c") == 0)
{
tNoOfOpsPerTrans = atoi(argv[i+1]);
if (tNoOfOpsPerTrans < 1)
exit(-1);
}
else if (strcmp(argv[i], "-o") == 0)
{
tNoOfBatchesInLoop = atoi(argv[i+1]);
if (tNoOfBatchesInLoop < 1)
exit(-1);
}
else if (strcmp(argv[i], "-a") == 0)
{
tNoOfAttributes = atoi(argv[i+1]);
if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR))
exit(-1);
}
else if (strcmp(argv[i], "-n") == 0)
{
theStdTableNameFlag = 1;
argc++;
i--;
}
else if (strcmp(argv[i], "-l") == 0)
{
tNoOfLoops = atoi(argv[i+1]);
if ((tNoOfLoops < 0) || (tNoOfLoops > 100000))
exit(-1);
}
else if (strcmp(argv[i], "-s") == 0)
{
tAttributeSize = atoi(argv[i+1]);
if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE))
exit(-1);
}
else if (strcmp(argv[i], "-simple") == 0)
{
theSimpleFlag = 1;
argc++;
i--;
}
else if (strcmp(argv[i], "-write") == 0)
{
theWriteFlag = 1;
argc++;
i--;
}
else if (strcmp(argv[i], "-dirty") == 0)
{
theDirtyFlag = 1;
argc++;
i--;
}
else if (strcmp(argv[i], "-test") == 0)
{
theTestFlag = 1;
argc++;
i--;
}
else if (strcmp(argv[i], "-temp") == 0)
{
theTempFlag = 0; // 0 if temporary tables.
argc++;
i--;
}
else if (strcmp(argv[i], "-no_table_create") == 0)
{
theTableCreateFlag = 1;
argc++;
i--;
}
else
{
ndbout << "Arguments: " << endl;
ndbout << "-t Number of threads to start, i.e., number of parallel loops, default 1 " << endl;
ndbout << "-p Number of transactions in a batch, default 32 " << endl;
ndbout << "-o Number of batches per loop, default 200 " << endl;
ndbout << "-i Minimum time between batch starts in milli seconds, default 0 " << endl;
ndbout << "-l Number of loops to run, default 1, 0=infinite " << endl;
ndbout << "-a Number of attributes, default 25 " << endl;
ndbout << "-c Number of operations per transaction, default 1 " << endl;
ndbout << "-s Size of each attribute in 32 bit word, default 1"
"(Primary Key is always of size 1, independent of this value) " << endl;
ndbout << "-simple Use simple read to read from database " << endl;
ndbout << "-dirty Use dirty read to read from database " << endl;
ndbout << "-write Use writeTuple in insert and update " << endl;
ndbout << "-n Use standard table names " << endl;
ndbout << "-no_table_create Don't create tables in db " << endl;
ndbout << "-temp Use temporary tables, no writing to disk. " << endl;
exit(-1);
}
argc -= 2;
i = i + 2;
}
}
void setAttrNames()
{
int i;
for (i = 0; i < MAXATTR ; i++)
{
sprintf(attrName[i], "COL%d", i);
}
}
void setTableNames()
{
// Note! Uses only uppercase letters in table name's
// so that we can look at the tables with SQL
int i;
for (i = 0; i < MAXTABLES ; i++)
{
if (theStdTableNameFlag==1)
{
sprintf(tableName[i], "TAB%d_%d", tNoOfAttributes,
NdbTick_CurrentMillisecond()/1000);
} else {
sprintf(tableName[i], "TAB%d_%d", tNoOfAttributes, tAttributeSize*4);
}
}
}
void createTables(Ndb* pMyNdb)
{
NdbSchemaCon *MySchemaTransaction;
NdbSchemaOp *MySchemaOp;
int check;
if (theTableCreateFlag == 0)
{
for(int i=0; i < 1 ;i++)
{
ndbout << "Creating " << tableName[i] << "..." << endl;
MySchemaTransaction = pMyNdb->startSchemaTransaction();
if( MySchemaTransaction ==
NULL && (!error_handler(MySchemaTransaction->getNdbError())))
exit(-1) ;/*goto error_handler; <epaulsa*/
MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
if( MySchemaOp == NULL
&& (!error_handler(MySchemaTransaction->getNdbError())))
exit(-1) ;
check = MySchemaOp->createTable( tableName[i],
8, // Table Size
TupleKey, // Key Type
40, // Nr of Pages
All, // FragmentType
6,
78,
80,
1, // MemoryType
theTempFlag // 0 if temporary tables else 1
);
if ( check == -1 && (!error_handler(MySchemaTransaction->getNdbError())))
exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
check = MySchemaOp->createAttribute( (char*)attrName[0],
TupleKey,
32,
PKSIZE,
UnSigned,
MMBased,
NotNullAttribute );
if ( check == -1 &&(!error_handler(MySchemaTransaction->getNdbError())))
exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
for (int j = 1; j < tNoOfAttributes ; j++)
{
check = MySchemaOp->createAttribute( (char*)attrName[j],
NoKey,
32,
tAttributeSize,
UnSigned,
MMBased,
NotNullAttribute );
if ( check == -1
&& (!error_handler(MySchemaTransaction->getNdbError())))
exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
}
if ( MySchemaTransaction->execute() == -1
&&(!error_handler(MySchemaTransaction->getNdbError())))
exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
pMyNdb->closeSchemaTransaction(MySchemaTransaction);
}
}
return;
}
bool error_handler(const NdbError & err) {
ndbout << err << endl ;
if ( 4008==err.code || 721==err.code || 266==err.code ){
ndbout << endl << "Attempting to recover and continue now..." << endl ;
return true ; // return true to retry
}
return false ; // return false to abort
}
//*******************************************************************************************
|