20 #include <NDBT_Test.hpp>
21 #include <HugoTransactions.hpp>
22 #include <UtilTransactions.hpp>
53 static const char * g_ops[] = {
56 "serial uniq index access",
57 "batch uniq index access",
65 static Uint64 g_times[P_OP_TYPES];
70 {
"operation", 0, 0, 6 },
71 {
"range", 1000, 1, ~0 },
72 {
"size", 1000000, 1, ~0 },
73 {
"iterations", 3, 1, ~0 },
74 {
"create_drop", 0, 0, 1 },
78 static Ndb* g_ndb = 0;
82 static char g_table[256];
83 static char g_unique[256];
84 static char g_ordered[256];
94 main(
int argc,
const char** argv){
99 struct getargs args[1+P_MAX] = {
100 {
"verbose",
'v', arg_flag, &verbose,
"Print verbose status",
"verbose" }
102 const int num_args = 1 + P_MAX;
104 for(i = 0; i<P_MAX; i++){
105 args[i+1].long_name = g_paramters[
i].name;
106 args[i+1].short_name = * g_paramters[
i].name;
107 args[i+1].type = arg_integer;
108 args[i+1].value = &g_paramters[
i].value;
110 tmp.
assfmt(
"min: %d max: %d", g_paramters[i].min, g_paramters[i].max);
111 args[i+1].help = strdup(tmp.
c_str());
112 args[i+1].arg_help = 0;
115 if(getarg(args, num_args, argc, argv, &optind)) {
116 arg_printusage(args, num_args, argv[0],
"tabname1 tabname2 ...");
117 return NDBT_WRONGARGS;
120 myRandom48Init((
long)NdbTick_CurrentMillisecond());
121 memset(g_times, 0,
sizeof(g_times));
126 return NDBT_ProgramExit(NDBT_FAILED);
129 g_ndb =
new Ndb(&con,
"TEST_DB");
130 if(g_ndb->
init() != 0){
131 g_err <<
"init() failed" << endl;
135 g_err <<
"Wait until ready failed" << endl;
138 for(i = optind; i<argc; i++){
139 const char * T = argv[
i];
140 g_info <<
"Testing " << T << endl;
148 for(
int l = 0; l<(int)g_paramters[P_LOOPS].value; l++){
149 for(
int j = 0; j<P_OP_TYPES; j++){
150 g_paramters[P_OPER].value = j;
158 if(g_ndb)
delete g_ndb;
161 if(g_ndb)
delete g_ndb;
169 if(g_paramters[P_CREATE].value){
175 g_err <<
"Failed to create table: " << g_table << endl;
190 g_err <<
"Failed to create index: " << endl;
197 g_err <<
"Failed to create index: " << endl;
202 g_i_unique = dict->
getIndex(g_unique, g_table);
203 g_i_ordered = dict->
getIndex(g_ordered, g_table);
212 if(!g_paramters[P_CREATE].value)
215 g_err <<
"Failed to drop table: " << g_tab->
getName() << endl;
224 if(!g_paramters[P_LOAD].value)
227 int rows = g_paramters[P_ROWS].value;
229 if (hugoTrans.loadTable(g_ndb, rows)){
230 g_err.println(
"Failed to load %s with %d rows", g_tab->
getName(), rows);
238 if(!g_paramters[P_LOAD].value)
240 int rows = g_paramters[P_ROWS].value;
243 if (utilTrans.clearTable(g_ndb, rows) != 0){
244 g_err.println(
"Failed to clear table %s", g_tab->
getName());
258 NDB_TICKS start1, stop;
261 const Uint32 rows = g_paramters[P_ROWS].value;
262 const Uint32 range = g_paramters[P_RANGE].value;
264 start1 = NdbTick_CurrentMillisecond();
267 g_err <<
"Failed to start transaction" << endl;
276 Uint32 start_row = rand() % (rows - range);
277 Uint32 stop_row = start_row + range;
289 void* res = (
void*)~0;
292 for(; start_row < stop_row; start_row++){
293 switch(g_paramters[P_OPER].value){
297 check = pOp->
equal(pk, start_row);
300 for(; start_row<stop_row; start_row++){
303 check = pOp->
equal(pk, start_row);
313 check = pOp->
equal(pk, start_row);
316 for(; start_row<stop_row; start_row++){
319 check = pOp->
equal(pk, start_row);
336 start_row = stop_row;
343 start_row = stop_row;
350 filter.ge(pk, start_row);
351 filter.lt(pk, stop_row);
353 start_row = stop_row;
369 check = pTrans->
execute(NoCommit);
374 if(g_paramters[P_OPER].value >= 4){
387 assert(g_paramters[P_OPER].value < 4 || (cnt == range));
391 stop = NdbTick_CurrentMillisecond();
392 g_times[g_paramters[P_OPER].value] += (stop - start1);
399 tmp *= g_paramters[P_RANGE].value;
400 tmp *= g_paramters[P_LOOPS].value;
402 for(
int i = 0; i<P_OP_TYPES; i++){
403 g_err << g_ops[
i] <<
" avg: "
404 << (int)((1000*g_times[i])/tmp)
406 << (1000 * tmp)/g_times[
i] <<
" rows / sec)" << endl;