26 #include "NdbSchemaCon.hpp"
29 #include <NdbTest.hpp>
35 #define NDB_MAXTHREADS 256
43 #define MAXATTRSIZE 8000
45 static unsigned int tNoOfRecords;
46 static unsigned int tNoOfLoops;
47 static unsigned int tNoOfTables;
48 static int tAttributeSize;
50 static unsigned int tValue;
51 static unsigned int tNoOfOperations;
52 static char tableName[MAXTABLES][MAXSTRLEN];
53 static char attrName[MAXATTR][MAXSTRLEN];
55 inline int InsertRecords(
Ndb*,
int) ;
57 NDB_COMMAND(initronja,
"initronja",
"initronja",
"initronja", 65535){
65 int check, status,
i, j, cont ;
66 check = status = i = j = cont = 0 ;
68 tNoOfLoops = tNoOfRecords / 10;
73 if (strcmp(argv[i],
"-r") == 0){
74 if( NULL == argv[i+1] )
goto error_input ;
75 tNoOfRecords = atoi(argv[i+1]);
76 tNoOfRecords = tNoOfRecords - (tNoOfRecords % 10);
77 tNoOfLoops = tNoOfRecords / 10;
78 if ((tNoOfRecords < 1) || (tNoOfRecords > 1000000000))
goto error_input;
87 pNdb =
new Ndb(
"TEST_DB" ) ;
88 ndbout <<
"Initialisation started. " << endl;
90 ndbout <<
"Initialisation completed. " << endl;
93 ndbout << endl <<
"Initial loading of Ronja Database" << endl;
94 ndbout <<
" NdbAPI node with id = " << tNodeId << endl;
97 ndbout <<
"Benchmark failed - NDB is not ready" << endl;
99 return NDBT_ProgramExit(NDBT_FAILED) ;
102 ndbout << endl <<
"Creating the table SHORT_REC" <<
"..." << endl;
104 MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
105 if(!MySchemaTransaction)
goto error_handler;
107 if(!MySchemaOp)
goto error_handler;
113 if (check == -1)
goto error_handler;
115 ndbout <<
"Key attribute..." ;
117 UnSigned, MMBased, NotNullAttribute );
118 if (check == -1)
goto error_handler;
119 ndbout <<
"\t\tOK" << endl ;
121 ndbout <<
"Flip attribute..." ;
123 UnSigned, MMBased, NotNullAttribute );
124 if (check == -1)
goto error_handler;
125 ndbout <<
"\t\tOK" << endl ;
127 ndbout <<
"Count attribute..." ;
129 UnSigned, MMBased, NotNullAttribute );
130 if (check == -1)
goto error_handler;
131 ndbout <<
"\t\tOK" << endl ;
133 ndbout <<
"Placeholder attribute..." ;
135 UnSigned, MMBased, NotNullAttribute );
136 if (check == -1)
goto error_handler;
137 ndbout <<
"\tOK" << endl ;
139 if (MySchemaTransaction->
execute() == -1) {
140 if(721 == MySchemaOp->getNdbError().
code){
141 ndbout <<
"Table SHORT_REC already exists" << endl ;
143 ndbout << MySchemaTransaction->
getNdbError() << endl;
146 ndbout <<
"SHORT_REC created " << endl;
149 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
151 ndbout << endl <<
"Creating the table LONG_REC..." << endl;
153 MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
154 if(!MySchemaTransaction)
goto error_handler;
157 if(!MySchemaOp)
goto error_handler;
164 if (check == -1)
goto error_handler;
166 ndbout <<
"Key attribute..." ;
168 UnSigned, MMBased, NotNullAttribute );
169 if (check == -1)
goto error_handler;
170 ndbout <<
"\t\tOK" << endl ;
172 ndbout <<
"Flip attribute..." ;
174 UnSigned, MMBased, NotNullAttribute );
175 if (check == -1)
goto error_handler;
176 ndbout <<
"\t\tOK" << endl ;
178 ndbout <<
"Count attribute..." ;
180 UnSigned, MMBased, NotNullAttribute );
181 if (check == -1)
goto error_handler;
182 ndbout <<
"\t\tOK" << endl ;
184 ndbout <<
"Placeholder attribute..." ;
186 UnSigned, MMBased, NotNullAttribute );
187 if (check == -1)
goto error_handler;
188 ndbout <<
"\tOK" << endl ;
190 if (MySchemaTransaction->
execute() == -1) {
191 if(721 == MySchemaOp->getNdbError().
code){
192 ndbout <<
"Table LONG_REC already exists" << endl ;
194 ndbout << MySchemaTransaction->
getNdbError() << endl;
197 ndbout <<
"LONG_REC created" << endl;
200 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
203 check = InsertRecords(pNdb, tNoOfRecords);
208 ndbout << endl <<
"Initial loading of Ronja Database failed" << endl;
209 return NDBT_ProgramExit(NDBT_FAILED) ;
211 ndbout << endl <<
"Initial loading of Ronja Database completed" << endl;
212 return NDBT_ProgramExit(NDBT_OK) ;
220 ndbout <<
"SchemaTransaction returned error:" ;
221 ndbout << MySchemaTransaction->
getNdbError() << endl;
222 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
224 NDBT_ProgramExit(NDBT_FAILED) ;
228 ndbout << endl <<
" Ivalid parameter(s)" << endl;
229 ndbout <<
" Usage: initronja [-r n] , where 'n' is the number of records to be inserted" << endl;
230 ndbout <<
" If omitted, 500 records will be created by default" << endl;
231 ndbout <<
" Note: use this number in combination with '-r' argument when running 'benchronja'" << endl << endl;
232 NDBT_ProgramExit(NDBT_WRONGARGS) ;
237 inline int InsertRecords(
Ndb* pNdb,
int nNoRecords){
243 int loop_count_ops = 2 * tNoOfLoops;
244 int loop_count_tables = 10;
245 int loop_count_attributes = 0 ;
248 int count_tables = 0;
249 int count_attributes = 0 ;
252 unsigned int attrValue[1000];
253 unsigned int setAttrValue = 0;
254 unsigned int keyValue[3];
256 for (i = 0; i < 1000; i ++) attrValue[i] = 1;
258 for (count=0 ; count < loop_count_ops ; count++){
259 if ((((count / 100)* 100) == count) && (count != 0)){
260 ndbout <<
"1000 records inserted again, " << (count/100) <<
"000 records now inserted" << endl;
265 ndbout <<
"startTransaction: " << pNdb->
getNdbError();
266 ndbout <<
" count = " << count << endl;
270 for (count_tables = 0; count_tables < loop_count_tables; count_tables++) {
271 if (count < tNoOfLoops) {
272 keyValue[0] = count*10 + count_tables ;
273 MyOperation[count_tables] = MyTransaction->
getNdbOperation(
"SHORT_REC") ;
275 keyValue[0] = (count - tNoOfLoops)*10 + count_tables;
276 MyOperation[count_tables] = MyTransaction->
getNdbOperation(
"LONG_REC");
279 if (!MyOperation[count_tables])
goto error_handler1;
282 if (check == -1)
goto error_handler2;
284 check = MyOperation[count_tables]->
equal(
"Key",(
char*)&keyValue[0]);
285 if (check == -1)
goto error_handler4;
287 check = MyOperation[count_tables]->
setValue(
"Flip",(
char*)&setAttrValue);
288 if (check == -1)
goto error_handler5;
290 check = MyOperation[count_tables]->
setValue(
"Count",(
char*)&setAttrValue);
291 if (check == -1)
goto error_handler5;
293 check = MyOperation[count_tables]->
setValue(
"Placeholder",(
char*)&attrValue[0]);
294 if (check == -1)
goto error_handler5;
297 if (MyTransaction->
execute( Commit ) == -1){
299 ndbout <<
"count = " << count << endl;
307 ndbout <<
"Error occured in getNdbOperation " << endl;
313 ndbout <<
"Error occured in defining operation " << endl;
314 ndbout << MyOperation[count_tables]->
getNdbError() << endl;
323 ndbout <<
"Error occured in equal " << endl;
324 ndbout << MyOperation[count_tables]->
getNdbError() << endl;
329 ndbout <<
"Error occured in get/setValue " << endl;
330 ndbout << MyOperation[count_tables]->
getNdbError() << endl;