52 #include <ndb_global.h>
59 #include <NdbTimer.hpp>
60 #include <NdbThread.h>
62 #include <NdbTest.hpp>
67 #define MAXATTRSIZE 1000
68 #define MAXNOLONGKEY 16 // Max number of long keys.
69 #define MAXLONGKEYTOTALSIZE 1023 // words = 4092 bytes
71 extern "C" {
static void* flexBenchThread(
void*); }
72 static int readArguments(
int argc,
const char** argv);
73 static int createTables(
Ndb*);
74 static int dropTables(
Ndb*);
75 static void sleepBeforeStartingTest(
int seconds);
76 static void input_error();
95 StartType threadStart;
99 static int tNodeId = 0 ;
100 static char tableName[MAXTABLES][MAXSTRLEN+1];
101 static char attrName[MAXATTR][MAXSTRLEN+1];
102 static char** longKeyAttrName;
105 static int tNoOfLoops = 1;
106 static int tAttributeSize = 1;
107 static unsigned int tNoOfThreads = 1;
108 static unsigned int tNoOfTables = 1;
109 static unsigned int tNoOfAttributes = 25;
110 static unsigned int tNoOfOperations = 500;
111 static unsigned int tSleepTime = 0;
112 static unsigned int tNoOfLongPK = 1;
113 static unsigned int tSizeOfLongPK = 1;
116 static int theSimpleFlag = 0;
117 static int theWriteFlag = 0;
118 static int theStdTableNameFlag = 0;
119 static int theTableCreateFlag = 0;
120 static bool theTempTable =
false;
121 static bool VerifyFlag =
true;
122 static bool useLongKeys =
false;
127 #define START_TIMER { NdbTimer timer; timer.doStart();
128 #define STOP_TIMER timer.doStop();
129 #define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
134 #include <NdbMutex.h>
135 static bool statEnable =
false;
136 static char statHost[100];
137 static int statFreq = 100;
138 static int statPort = 0;
139 static int statSock = -1;
140 static enum { statError = -1, statClosed, statOpen } statState;
141 static NdbMutex statMutex = NDB_MUTEX_INITIALIZER;
151 statReport(
enum StartType st,
int ops)
155 if (NdbMutex_Lock(&statMutex) < 0) {
156 if (statState != statError) {
157 ndbout_c(
"stat: lock mutex failed: %s", strerror(errno));
158 statState = statError;
164 if (statState != statOpen) {
165 char *p = getenv(
"NDB_NODEID");
166 nodeid = p == 0 ? 0 : atoi(p);
167 if ((statSock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
168 if (statState != statError) {
169 ndbout_c(
"stat: create socket failed: %s", strerror(socket_errno));
170 statState = statError;
172 (void)NdbMutex_Unlock(&statMutex);
175 struct sockaddr_in saddr;
176 memset(&saddr, 0,
sizeof(saddr));
177 saddr.sin_family = AF_INET;
178 saddr.sin_port = htons(statPort);
179 if (Ndb_getInAddr(&saddr.sin_addr, statHost) < 0) {
180 if (statState != statError) {
181 ndbout_c(
"stat: host %s not found", statHost);
182 statState = statError;
184 (void)close(statSock);
185 (void)NdbMutex_Unlock(&statMutex);
188 if (connect(statSock, (
struct sockaddr *)&saddr,
sizeof(saddr)) < 0) {
189 if (statState != statError) {
190 ndbout_c(
"stat: connect failed: %s", strerror(socket_errno));
191 statState = statError;
193 (void)close(statSock);
194 (void)NdbMutex_Unlock(&statMutex);
197 statState = statOpen;
198 ndbout_c(
"stat: connection to %s:%d opened", statHost, (
int)statPort);
218 text =
"verifydelete";
225 sprintf(buf,
"%d %s %d\n", nodeid, text, ops);
226 int len = strlen(buf);
228 if (send(statSock, buf, len, 0) != len) {
229 if (statState != statError) {
230 ndbout_c(
"stat: write failed: %s", strerror(socket_errno));
231 statState = statError;
233 (void)close(statSock);
234 (void)NdbMutex_Unlock(&statMutex);
237 (void)NdbMutex_Unlock(&statMutex);
243 for (
unsigned int i = 0;
i < tNoOfThreads;
i++){
244 pt[
i].threadReady = 0;
245 pt[
i].threadResult = 0;
246 pt[
i].threadStart = stIdle;
252 for (
unsigned int i = 0;
i < tNoOfThreads;
i++){
253 if(pt[
i].threadResult != 0){
254 ndbout_c(
"Thread%d reported fatal error %d",
i, pt[
i].threadResult);
267 NdbSleep_MilliSleep(100);
269 for (
unsigned int i = 0;
i < tNoOfThreads;
i++){
270 if (pt[
i].threadReady == 0)
279 for (
unsigned int i = 0;
i < tNoOfThreads;
i++)
280 pt[
i].threadStart = what;
285 NDB_COMMAND(flexBench,
"flexBench",
"flexBench",
"flexbench", 65535)
290 int returnValue = NDBT_OK;
292 if (readArguments(argc, argv) != 0){
294 return NDBT_ProgramExit(NDBT_WRONGARGS);
298 longKeyAttrName = (
char **) malloc(
sizeof(
char*) * tNoOfLongPK);
299 for (Uint32
i = 0;
i < tNoOfLongPK;
i++) {
300 longKeyAttrName[
i] = (
char *) malloc(strlen(
"KEYATTR ") + 1);
301 memset(longKeyAttrName[
i], 0, strlen(
"KEYATTR ") + 1);
302 sprintf(longKeyAttrName[i],
"KEYATTR%i", i);
308 ndbout << endl <<
"FLEXBENCH - Starting normal mode" << endl;
309 ndbout <<
"Perform benchmark of insert, update and delete transactions"<< endl;
310 ndbout <<
" " << tNoOfThreads <<
" thread(s) " << endl;
311 ndbout <<
" " << tNoOfLoops <<
" iterations " << endl;
312 ndbout <<
" " << tNoOfTables <<
" table(s) and " << 1 <<
" operation(s) per transaction " <<endl;
313 ndbout <<
" " << tNoOfAttributes <<
" attributes per table " << endl;
314 ndbout <<
" " << tNoOfOperations <<
" transaction(s) per thread and round " << endl;
315 ndbout <<
" " << tAttributeSize <<
" is the number of 32 bit words per attribute "<< endl;
316 ndbout <<
" " <<
"Table(s) without logging: " << (Uint32)theTempTable << endl;
319 ndbout <<
" " <<
"Using long keys with " << tNoOfLongPK <<
" keys a' " <<
320 tSizeOfLongPK * 4 <<
" bytes each." << endl;
322 ndbout <<
" " <<
"Verification is " ;
324 ndbout <<
"enabled" << endl ;
326 ndbout <<
"disabled" << endl ;
330 NdbThread_SetConcurrencyLevel(tNoOfThreads + 2);
335 return NDBT_ProgramExit(NDBT_FAILED);
338 g_cluster_connection= &con;
341 pNdb =
new Ndb(&con,
"TEST_DB" );
345 ndbout <<
" NdbAPI node with id = " << tNodeId << endl;
348 ndbout <<
"Waiting for ndb to become ready..." <<endl;
350 ndbout <<
"NDB is not ready" << endl;
351 ndbout <<
"Benchmark failed!" << endl;
352 returnValue = NDBT_FAILED;
355 if(returnValue == NDBT_OK){
356 if (createTables(pNdb) != 0){
357 returnValue = NDBT_FAILED;
361 if(returnValue == NDBT_OK){
363 sleepBeforeStartingTest(tSleepTime);
368 resetThreads(pThreadsData);
370 for (
int i = 0;
i < (int)tNoOfThreads;
i++){
371 pThreadsData[
i].threadNo =
i;
372 pThreadsData[
i].threadLife = NdbThread_Create(flexBenchThread,
373 (
void**)&pThreadsData[
i],
376 NDB_THREAD_PRIO_LOW);
379 waitForThreads(pThreadsData);
381 ndbout << endl <<
"All threads started" << endl << endl;
389 int loopCount = tLoops + 1;
390 ndbout << endl <<
"Loop # " << loopCount << endl << endl;
398 resetThreads(pThreadsData);
399 tellThreads(pThreadsData, stInsert);
400 waitForThreads(pThreadsData);
401 if (checkThreadResults(pThreadsData) != 0){
402 ndbout <<
"Error: Threads failed in performing insert" << endl;
403 returnValue = NDBT_FAILED;
408 PRINT_TIMER(
"insert", tNoOfOperations*tNoOfThreads, tNoOfTables);
413 resetThreads(pThreadsData);
414 ndbout <<
"Verifying inserts...\t" ;
415 tellThreads(pThreadsData, stVerify);
416 waitForThreads(pThreadsData);
417 if (checkThreadResults(pThreadsData) != 0){
418 ndbout <<
"Error: Threads failed while verifying inserts" << endl;
419 returnValue = NDBT_FAILED;
422 ndbout <<
"\t\tOK" << endl << endl ;
432 resetThreads(pThreadsData);
433 tellThreads(pThreadsData, stRead);
434 waitForThreads(pThreadsData);
435 if (checkThreadResults(pThreadsData) != 0){
436 ndbout <<
"Error: Threads failed in performing read" << endl;
437 returnValue = NDBT_FAILED;
442 PRINT_TIMER(
"read", tNoOfOperations*tNoOfThreads, tNoOfTables);
450 resetThreads(pThreadsData);
451 tellThreads(pThreadsData, stUpdate);
452 waitForThreads(pThreadsData);
453 if (checkThreadResults(pThreadsData) != 0){
454 ndbout <<
"Error: Threads failed in performing update" << endl;
455 returnValue = NDBT_FAILED;
460 PRINT_TIMER(
"update", tNoOfOperations*tNoOfThreads, tNoOfTables);
466 resetThreads(pThreadsData);
467 ndbout <<
"Verifying updates...\t" ;
468 tellThreads(pThreadsData, stVerify);
469 waitForThreads(pThreadsData);
470 if (checkThreadResults(pThreadsData) != 0){
471 ndbout <<
"Error: Threads failed while verifying updates" << endl;
472 returnValue = NDBT_FAILED;
475 ndbout <<
"\t\tOK" << endl << endl ;
485 resetThreads(pThreadsData);
486 tellThreads(pThreadsData, stRead);
487 waitForThreads(pThreadsData);
488 if (checkThreadResults(pThreadsData) != 0){
489 ndbout <<
"Error: Threads failed in performing read" << endl;
490 returnValue = NDBT_FAILED;
495 PRINT_TIMER(
"read", tNoOfOperations*tNoOfThreads, tNoOfTables);
503 resetThreads(pThreadsData);
504 tellThreads(pThreadsData, stDelete);
505 waitForThreads(pThreadsData);
506 if (checkThreadResults(pThreadsData) != 0){
507 ndbout <<
"Error: Threads failed in performing delete" << endl;
508 returnValue = NDBT_FAILED;
513 PRINT_TIMER(
"delete", tNoOfOperations*tNoOfThreads, tNoOfTables);
519 resetThreads(pThreadsData);
520 ndbout <<
"Verifying tuple deletion..." ;
521 tellThreads(pThreadsData, stVerifyDelete);
522 waitForThreads(pThreadsData);
523 if (checkThreadResults(pThreadsData) != 0){
524 ndbout <<
"Error: Threads failed in verifying deletes" << endl;
525 returnValue = NDBT_FAILED;
528 ndbout <<
"\t\tOK" << endl << endl ;
532 ndbout <<
"--------------------------------------------------" << endl;
536 if ( 0 != tNoOfLoops && tNoOfLoops <= tLoops )
541 resetThreads(pThreadsData);
542 tellThreads(pThreadsData, stStop);
543 waitForThreads(pThreadsData);
546 for(
int i = 0;
i<(int)tNoOfThreads;
i++){
547 NdbThread_WaitFor(pThreadsData[
i].threadLife, &tmp);
548 NdbThread_Destroy(&pThreadsData[
i].threadLife);
552 if (useLongKeys ==
true) {
555 for (
int i = 0;
i < (int)tNoOfLongPK;
i++)
556 free(longKeyAttrName[
i]);
557 free(longKeyAttrName);
562 delete [] pThreadsData;
565 return NDBT_ProgramExit(returnValue);
570 unsigned long get_hash(
unsigned long * hash_key,
int len)
572 unsigned long hash_value = 147;
575 for (i = 0; i < len; i++)
578 hash_value = (hash_value << 5) + hash_value + (h_key & 255);
579 hash_value = (hash_value << 5) + hash_value + ((h_key >> 8) & 255);
580 hash_value = (hash_value << 5) + hash_value + ((h_key >> 16) & 255);
581 hash_value = (hash_value << 5) + hash_value + ((h_key >> 24) & 255);
590 static void* flexBenchThread(
void* pArg)
593 unsigned int threadNo, threadBase;
599 StartType tSaveType ;
600 int* attrValue = NULL ;
601 int* attrRefValue = NULL ;
603 int loopCountOps, loopCountTables, loopCountAttributes;
605 int tRetryAttempts = 20;
607 int tSpecialTrans = 0;
608 int nRefLocalOpOffset = 0 ;
610 tNoOfTables * tNoOfAttributes *
sizeof(int) * tAttributeSize ;
612 tNoOfOperations * tNoOfAttributes *
sizeof(int) * tAttributeSize ;
613 unsigned** longKeyAttrValue;
615 unsigned char** pAttrSet= NULL;
620 threadNo = pThreadData->threadNo ;
624 nReadBuffSize+= tNoOfTables*
sizeof(unsigned)*tSizeOfLongPK*tNoOfLongPK;
626 attrValue = (
int*)malloc(nReadBuffSize) ;
627 attrRefValue = (
int*)malloc(nRefBuffSize) ;
629 pNdb =
new Ndb(g_cluster_connection,
"TEST_DB" );
630 pRec= (
NdbRecord **)calloc(tNoOfTables*3,
sizeof(*pRec));
631 pAttrSet= (
unsigned char **)calloc(tNoOfTables,
sizeof(*pAttrSet));
633 if (!attrValue || !attrRefValue || !pOps || !pNdb || !pRec || !pAttrSet)
636 ndbout <<
"One or more memory allocations failed when starting thread #";
637 ndbout << threadNo << endl ;
638 ndbout <<
"Thread #" << threadNo <<
" will now exit" << endl ;
648 threadBase = (threadNo * 2000000) + (tNodeId * 260000000);
652 for (
int tab= 0; tab<(int)tNoOfTables; tab++)
655 int numPKs= (useLongKeys ? tNoOfLongPK : 1);
661 recSpec[0].offset= 0;
662 pRec[tab]= dict->createRecord(table,
669 for (Uint32 i= 0; i<tNoOfLongPK; i++)
671 recSpec[
i].column= table->
getColumn(longKeyAttrName[i]);
672 recSpec[
i].offset=
sizeof(unsigned)*tSizeOfLongPK*i;
674 pRec[tab]= dict->createRecord(table,
682 for (Uint32 i= 1; i<tNoOfAttributes; i++)
684 recSpec[count].column= table->
getColumn(i+numPKs-1);
685 recSpec[count].offset=
sizeof(int)*tAttributeSize*i;
688 pRec[tab+tNoOfTables]= dict->createRecord(table,
696 for (Uint32 i= (useLongKeys?1:0); i<tNoOfAttributes; i++)
698 recSpec[count].column= table->
getColumn(i-1+numPKs);
699 recSpec[count].offset=
sizeof(int)*tAttributeSize*i;
704 for (Uint32 i= 0; i<tNoOfLongPK; i++)
706 recSpec[count].column= table->
getColumn(longKeyAttrName[i]);
707 recSpec[count].offset=
sizeof(int)*tAttributeSize*tNoOfAttributes +
708 sizeof(
unsigned)*tSizeOfLongPK*
i;
712 pRec[tab+2*tNoOfTables]= dict->createRecord(table,
717 if (pRec[tab]==NULL ||
718 pRec[tab+tNoOfTables]==NULL ||
719 pRec[tab+2*tNoOfTables]==NULL) {
721 ndbout <<
"Failed to allocate NdbRecord in thread" << threadNo;
729 (
unsigned char *)calloc(tNoOfAttributes-1+numPKs,
sizeof(
char));
730 if (pAttrSet[tab]==NULL) {
732 ndbout <<
"Failed to allocate NdbRecAttrSet in thread" << threadNo;
737 pAttrSet[tab][0]|= 1;
742 longKeyAttrValue= (
unsigned **) calloc(tNoOfOperations,
sizeof(
unsigned*));
743 if (longKeyAttrValue==NULL) {
744 ndbout <<
"Memory allocation failed for longKeyAttrValue in thread"
751 for (n = 0; n < tNoOfOperations; n++)
754 (
unsigned *) malloc(
sizeof(
unsigned) * tSizeOfLongPK * tNoOfLongPK );
755 if (longKeyAttrValue[n]==NULL) {
756 ndbout <<
"Memory allocation failed for longKeyAttrValue in thread"
763 for (Uint32 i = 0; i < tNoOfLongPK ; i++) {
764 for(Uint32 j = 0; j < tSizeOfLongPK; j++) {
766 longKeyAttrValue[
n][i*tSizeOfLongPK+j]= threadBase +
n;
774 for(Uint32 ops = 1 ; ops < tNoOfOperations ; ops++){
776 nRefOpOffset = tAttributeSize*tNoOfAttributes*(ops-1) ;
777 for(Uint32 a = 0 ; a < tNoOfAttributes ; a++)
778 for(Uint32 b= 0; b<(Uint32)tAttributeSize; b++)
779 attrRefValue[nRefOpOffset + tAttributeSize*a + b] =
780 (
int)(threadBase + ops + a) ;
788 pThreadData->threadResult = tResult;
790 pThreadData->threadReady = 1;
792 while (pThreadData->threadStart == stIdle){
793 NdbSleep_MilliSleep(100);
797 if (pThreadData->threadStart == stStop){
798 pThreadData->threadReady = 1;
806 tType = pThreadData->threadStart;
808 pThreadData->threadStart = stIdle;
812 loopCountOps = tNoOfOperations;
813 loopCountTables = tNoOfTables;
814 loopCountAttributes = tNoOfAttributes;
817 for (
int count = 1; count < loopCountOps && tResult == 0;){
820 if (pTrans == NULL) {
822 ndbout <<
"Could not start transaction in thread" << threadNo;
830 nRefLocalOpOffset = tAttributeSize*tNoOfAttributes*(count - 1) ;
832 for (
int countTables = 0;
833 countTables < loopCountTables && tResult == 0;
835 int nTableOffset= tAttributeSize*tNoOfAttributes*countTables;
836 int *pRow= &attrValue[nTableOffset];
837 char *pRowAttr= (
char *)(&attrRefValue[nRefLocalOpOffset]);
838 char *pRowPK= (useLongKeys ?
839 (
char *)longKeyAttrValue[count-1] :
840 (
char *)(&attrRefValue[nRefLocalOpOffset]));
843 if (tType==stInsert && theWriteFlag!=1)
846 if (tNoOfAttributes>1)
847 memcpy(&pRow[tAttributeSize],
848 &attrRefValue[nRefLocalOpOffset+tAttributeSize],
849 (tNoOfAttributes-1)*tAttributeSize*
sizeof(
int));
853 memcpy(pRow+tAttributeSize*tNoOfAttributes,
854 longKeyAttrValue[count-1],
855 tNoOfLongPK*tSizeOfLongPK*
sizeof(
unsigned));
859 pRow[0]= attrRefValue[nRefLocalOpOffset];
863 const NdbRecord *pk_record= pRec[countTables];
864 const NdbRecord *attr_record= pRec[countTables+tNoOfTables];
865 const NdbRecord *all_record= pRec[countTables+2*tNoOfTables];
869 if (theWriteFlag == 1)
870 pOps[countTables]= pTrans->writeTuple(pk_record, pRowPK,
871 attr_record, pRowAttr);
873 pOps[countTables]= pTrans->insertTuple(all_record, (
char *)pRow);
876 if (theSimpleFlag == 1)
878 pOps[countTables]= pTrans->readTuple(pk_record, pRowPK,
879 attr_record, (
char *)pRow,
882 pOps[countTables]= pTrans->readTuple(pk_record, pRowPK,
883 attr_record, (
char *)pRow);
886 if (theWriteFlag == 1)
887 pOps[countTables]= pTrans->writeTuple(pk_record, pRowPK,
888 attr_record, pRowAttr);
890 pOps[countTables]= pTrans->updateTuple(pk_record, pRowPK,
891 attr_record, pRowAttr);
894 pOps[countTables]= pTrans->deleteTuple(pk_record, pRowPK,
898 pOps[countTables]= pTrans->readTuple(pk_record, pRowPK,
899 attr_record, (
char *)pRow);
902 pOps[countTables]= pTrans->readTuple(pk_record, pRowPK,
903 pk_record, (
char *)pRow,
905 pAttrSet[countTables]);
911 if (pOps[countTables] == NULL) {
913 ndbout <<
"getNdbOperation: " << pTrans->
getNdbError();
922 check = pTrans->
execute(Commit);
925 if ((tSpecialTrans == 1) &&
935 ndbout <<
"Insert with 4007 was successful" << endl;
941 ndbout <<
"Delete with 4007 was successful" << endl;
950 if ((stVerifyDelete == tType) &&
959 theErrorData.handleErrorCommon(pTrans->
getNdbError());
961 ndbout_c(
"execute: %d, %d, %s", count, tType,
965 }
else if (retCode == 2) {
966 ndbout <<
"4115 should not happen in flexBench" << endl;
968 }
else if (retCode == 3) {
976 if ((tType == stInsert) || (tType == stDelete)) {
983 if (check == -1 && tResult == 0) {
984 if (tAttemptNo < tRetryAttempts){
990 ndbout <<
"Thread" << threadNo;
991 ndbout <<
": too many errors reported" << endl;
1004 statOps += loopCountTables;
1005 if (statOps >= statFreq) {
1006 statReport(tType, statOps);
1013 if (stVerify == tType && 0 == check){
1014 int nTableOffset = 0 ;
1015 for (
int a = 1 ; a < loopCountAttributes ; a++){
1016 for (
int tables = 0 ; tables < loopCountTables ; tables++){
1017 nTableOffset = tables*loopCountAttributes*tAttributeSize ;
1018 if (*(
int*)&attrValue[nTableOffset + tAttributeSize*a] != *(
int*)&attrRefValue[nRefLocalOpOffset + tAttributeSize*a]){
1019 ndbout <<
"Error in verify:" << endl ;
1020 ndbout <<
"attrValue[" << nTableOffset + tAttributeSize*a <<
"] = " << attrValue[a] << endl ;
1021 ndbout <<
"attrRefValue[" << nRefLocalOpOffset + tAttributeSize*a <<
"]" << attrRefValue[nRefLocalOpOffset + tAttributeSize*a] << endl ;
1034 statReport(tType, statOps);
1044 for (Uint32 i= 0; i<tNoOfTables; i++)
1051 for (Uint32 i= 0; i<tNoOfTables*3; i++)
1053 dict->releaseRecord(pRec[i]);
1064 if (useLongKeys ==
true) {
1067 for (Uint32 n = 0; n < tNoOfOperations; n++)
1068 if (longKeyAttrValue[n])
1069 free(longKeyAttrValue[n]);
1070 free(longKeyAttrValue);
1077 static int readArguments(
int argc,
const char** argv)
1082 if (strcmp(argv[i],
"-t") == 0){
1083 tNoOfThreads = atoi(argv[i+1]);
1084 if ((tNoOfThreads < 1))
1088 }
else if (strcmp(argv[i],
"-o") == 0){
1089 tNoOfOperations = atoi(argv[i+1]);
1090 if (tNoOfOperations < 1)
1094 }
else if (strcmp(argv[i],
"-a") == 0){
1095 tNoOfAttributes = atoi(argv[i+1]);
1096 if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR))
1100 }
else if (strcmp(argv[i],
"-lkn") == 0){
1101 tNoOfLongPK = atoi(argv[i+1]);
1103 if ((tNoOfLongPK < 1) || (tNoOfLongPK > MAXNOLONGKEY) ||
1104 (tNoOfLongPK * tSizeOfLongPK) > MAXLONGKEYTOTALSIZE){
1105 ndbout <<
"Argument -lkn is not in the proper range." << endl;
1110 }
else if (strcmp(argv[i],
"-lks") == 0){
1111 tSizeOfLongPK = atoi(argv[i+1]);
1113 if ((tSizeOfLongPK < 1) || (tNoOfLongPK * tSizeOfLongPK) > MAXLONGKEYTOTALSIZE){
1114 ndbout <<
"Argument -lks is not in the proper range 1 to " <<
1115 MAXLONGKEYTOTALSIZE << endl;
1120 }
else if (strcmp(argv[i],
"-c") == 0){
1121 tNoOfTables = atoi(argv[i+1]);
1122 if ((tNoOfTables < 1) || (tNoOfTables > MAXTABLES))
1126 }
else if (strcmp(argv[i],
"-stdtables") == 0){
1127 theStdTableNameFlag = 1;
1128 }
else if (strcmp(argv[i],
"-l") == 0){
1129 tNoOfLoops = atoi(argv[i+1]);
1130 if ((tNoOfLoops < 0) || (tNoOfLoops > 100000))
1134 }
else if (strcmp(argv[i],
"-s") == 0){
1135 tAttributeSize = atoi(argv[i+1]);
1136 if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE))
1140 }
else if (strcmp(argv[i],
"-sleep") == 0){
1141 tSleepTime = atoi(argv[i+1]);
1142 if ((tSleepTime < 1) || (tSleepTime > 3600))
1146 }
else if (strcmp(argv[i],
"-simple") == 0){
1148 }
else if (strcmp(argv[i],
"-write") == 0){
1150 }
else if (strcmp(argv[i],
"-no_table_create") == 0){
1151 theTableCreateFlag = 1;
1152 }
else if (strcmp(argv[i],
"-temp") == 0){
1153 theTempTable =
true;
1154 }
else if (strcmp(argv[i],
"-noverify") == 0){
1155 VerifyFlag = false ;
1158 }
else if (strcmp(argv[i],
"-verify") == 0){
1161 }
else if (strcmp(argv[i],
"-statserv") == 0){
1164 const char *p = argv[i+1];
1165 const char *q = strrchr(p,
':');
1169 statPort = atoi(q+1);
1173 }
else if (strcmp(argv[i],
"-statfreq") == 0){
1176 statFreq = atoi(argv[i+1]);
1191 static void sleepBeforeStartingTest(
int seconds){
1193 ndbout <<
"Sleeping(" <<seconds <<
")...";
1194 NdbSleep_SecSleep(seconds);
1195 ndbout <<
" done!" << endl;
1201 createTables(
Ndb* pMyNdb){
1202 for (Uint32 i = 0; i < tNoOfAttributes; i++){
1208 for (Uint32 i = 0; i < tNoOfTables; i++){
1209 if (theStdTableNameFlag == 0){
1211 (
int)(NdbTick_CurrentMillisecond() / 1000));
1217 for(Uint32 i = 0; i < tNoOfTables; i++){
1218 ndbout <<
"Creating " << tableName[
i] <<
"... ";
1222 tmpTable.setStoredTable(!theTempTable);
1225 for(Uint32 i = 0; i < tNoOfLongPK; i++) {
1228 col.setLength(tSizeOfLongPK);
1229 col.setPrimaryKey(
true);
1230 tmpTable.addColumn(col);
1236 col.setPrimaryKey(
true);
1237 tmpTable.addColumn(col);
1244 for (
unsigned j = 1; j < tNoOfAttributes; j++){
1246 tmpTable.addColumn(col);
1252 ndbout <<
"done" << endl;
1259 dropTables(
Ndb* pMyNdb){
1264 for(i = 0; i < tNoOfTables; i++){
1265 ndbout <<
"Dropping " << tableName[
i] <<
"... ";
1267 ndbout <<
"done" << endl;
1274 static void input_error(){
1275 ndbout << endl <<
"Invalid argument!" << endl;
1276 ndbout << endl <<
"Arguments:" << endl;
1277 ndbout <<
" -t Number of threads to start, default 1" << endl;
1278 ndbout <<
" -o Number of operations per loop, default 500" << endl;
1279 ndbout <<
" -l Number of loops to run, default 1, 0=infinite" << endl;
1280 ndbout <<
" -a Number of attributes, default 25" << endl;
1281 ndbout <<
" -c Number of tables, default 1" << endl;
1282 ndbout <<
" -s Size of each attribute, default 1 (Primary Key is always of size 1," << endl;
1283 ndbout <<
" independent of this value)" << endl;
1284 ndbout <<
" -lkn Number of long primary keys, default 1" << endl;
1285 ndbout <<
" -lks Size of each long primary key, default 1" << endl;
1287 ndbout <<
" -simple Use simple read to read from database" << endl;
1288 ndbout <<
" -write Use writeTuple in insert and update" << endl;
1289 ndbout <<
" -stdtables Use standard table names" << endl;
1290 ndbout <<
" -no_table_create Don't create tables in db" << endl;
1291 ndbout <<
" -sleep Sleep a number of seconds before running the test, this" << endl;
1292 ndbout <<
" can be used so that another flexBench have time to create tables" << endl;
1293 ndbout <<
" -temp Use tables without logging" << endl;
1294 ndbout <<
" -verify Verify inserts, updates and deletes" << endl ;
1296 ndbout << endl <<
"Returns:" << endl;
1297 ndbout <<
"\t 0 - Test passed" << endl;
1298 ndbout <<
"\t 1 - Test failed" << endl;
1299 ndbout <<
"\t 2 - Invalid arguments" << endl << endl;