4 void* runInsTest(void *p
);
5 void* runSelTest(void *p
);
10 DbRetVal rv
= conn
.open("root", "manager");
13 printf("Error during connection %d\n", rv
);
16 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
17 if (dbMgr
== NULL
) { printf("Auth failed\n"); return -1;}
19 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
20 tabDef
.addField("f2", typeString
, 196);
21 rv
= dbMgr
->createTable("t1", tabDef
);
22 if (rv
!= OK
) { printf("Table creation failed\n"); return -1; }
23 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
24 strcpy(idxInfo
->tableName
, "t1");
25 idxInfo
->list
.append("f1");
26 idxInfo
->indType
= hashIndex
;
27 rv
= dbMgr
->createIndex("indx1", idxInfo
);
28 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
30 pthread_t thr
[THREADS
];
33 for (int i
=0; i
<THREADS
; i
++) {
35 pthread_create (&thr
[i
], NULL
,
36 &runInsTest
, (void *) &message
[i
]);
38 for (int i
=0; i
<THREADS
; i
++) {
39 pthread_join(thr
[i
], (void**)&status
);
41 Table
*table
= dbMgr
->openTable("t1");
42 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
43 table
->setCondition(NULL
);
44 rv
= conn
.startTransaction();
45 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
49 while ((tuple
= (char*) table
->fetch())) {
52 printf("Tuples found: %d\n", count
);
59 p1
.setTerm("f1", OpEquals
, &valTerm
);
60 table
->setCondition(&p1
);
62 for(int i
= 0; i
< 20000; i
++)
64 rv
= conn
.startTransaction();
65 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
67 rv
= table
->execute();
68 tuple
= (char*)table
->fetch() ;
69 if (tuple
== NULL
) break;
74 printf("Index Tuples found: %d\n", icount
);
78 dbMgr
->closeTable(table
);
80 for (int i
=0; i
<THREADS
; i
++) {
82 pthread_create (&thr
[i
], NULL
,
83 &runSelTest
, (void *) &message
[i
]);
85 for (int i
=0; i
<THREADS
; i
++) {
86 pthread_join(thr
[i
], (void**)&status
);
89 dbMgr
->dropTable("t1");
93 void* runInsTest(void *message
)
96 DbRetVal rv
= conn
.open("root", "manager");
99 printf("Error during connection %d\n", rv
);
102 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
103 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
104 Table
*table
= dbMgr
->openTable("t1");
105 if (table
== NULL
) { printf("Unable to open table\n"); return NULL
; }
107 char name
[1020] = "PRABAKARAN";
108 table
->bindFld("f1", &id
);
109 table
->bindFld("f2", name
);
115 int val
= *(int*)message
;
117 for(i
= val
* 10000; i
< (val
*10000) +10000; i
++)
119 rv
= conn
.startTransaction();
120 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
122 strcpy(name
, "PRABAKARAN0123456750590");
123 ret
= table
->insertTuple();
124 while (ret
== ErrLockTimeOut
)
127 conn
.startTransaction();
128 ret
= table
->insertTuple();
130 if (ret
!= 0) { printf("RETURNING EARLY: %d\n", ret
); break;}
133 //if (icount %10000 ==0) printf("%d\n", i);
137 sprintf(msgBuf
,"Insert: Thread %lu %d: Total rows :%d Time taken:%lld ms\n",os::getthrid(), val
, icount
, timer
.avg()/1000/1000);
138 os::write(1,msgBuf
,strlen(msgBuf
));
139 dbMgr
->closeTable(table
);
143 void* runSelTest(void *message
)
146 DbRetVal rv
= conn
.open("root", "manager");
149 printf("Error during connection %d\n", rv
);
152 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
153 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
154 Table
*table
= dbMgr
->openTable("t1");
155 if (table
== NULL
) { printf("Unable to open table\n"); return NULL
; }
157 char name
[1020] = "PRABAKARAN";
158 table
->bindFld("f1", &id
);
159 table
->bindFld("f2", name
);
164 int val
= *(int*)message
;
168 p1
.setTerm("f1", OpEquals
, &valTerm
);
169 table
->setCondition(&p1
);
172 for(i
= val
* 10000; i
< (val
*10000) +10000; i
++)
174 rv
= conn
.startTransaction();
175 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
177 rv
= table
->execute();
178 tuple
= (char*)table
->fetch() ;
179 if (tuple
== NULL
) break;
187 sprintf(msgBuf
,"Select: Thread %d: Total rows :%d Time taken:%lld ms\n",val
, icount
, timer
.avg()/1000/1000);
188 os::write(1,msgBuf
,strlen(msgBuf
));
189 dbMgr
->closeTable(table
);