5 #define isoLevel READ_REPEATABLE
6 void* runInsTest(void *p
);
7 void* runSelTest(void *p
);
8 void* runDelTest(void *p
);
13 DbRetVal rv
= conn
.open("root", "manager");
16 printf("Error during connection %d\n", rv
);
19 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
20 if (dbMgr
== NULL
) { printf("Auth failed\n"); return -1;}
22 tabDef
.addField("f1", typeInt
, 0, NULL
, true);
23 tabDef
.addField("f2", typeString
, 16);
24 rv
= dbMgr
->createTable("t1", tabDef
);
25 if (rv
!= OK
) { printf("Table creation failed\n"); return -1; }
26 HashIndexInitInfo
*idxInfo
= new HashIndexInitInfo();
27 strcpy(idxInfo
->tableName
, "t1");
28 idxInfo
->list
.append("f1");
29 idxInfo
->indType
= treeIndex
;
30 rv
= dbMgr
->createIndex("indx1", idxInfo
);
31 if (rv
!= OK
) { printf("Index creation failed\n"); return -1; }
33 pthread_t thr
[THREADS
];
36 for (int i
=0; i
<THREADS
; i
++) {
38 pthread_create (&thr
[i
], NULL
,
39 &runInsTest
, (void *) &message
[i
]);
41 for (int i
=0; i
<THREADS
; i
++) {
42 pthread_join(thr
[i
], (void**)&status
);
44 Table
*table
= dbMgr
->openTable("t1");
45 if (table
== NULL
) { printf("Unable to open table\n"); return -1; }
46 table
->setCondition(NULL
);
47 rv
= conn
.startTransaction();
48 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
52 while ((tuple
= (char*) table
->fetch())) {
55 printf("Tuples found: %d\n", count
);
62 p1
.setTerm("f1", OpEquals
, &valTerm
);
63 table
->setCondition(&p1
);
65 for(int i
= 0; i
< THREADS
* RECORDS
; i
++)
67 rv
= conn
.startTransaction();
68 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
70 rv
= table
->execute();
71 tuple
= (char*)table
->fetch() ;
72 //if (tuple == NULL) printf(" %d ", i); else icount++;
73 if (tuple
== NULL
) break; else icount
++;
77 printf("\nIndex Tuples found: %d\n", icount
);
81 dbMgr
->closeTable(table
);
83 for (int i
=0; i
<THREADS
; i
++) {
85 pthread_create (&thr
[i
], NULL
,
86 &runSelTest
, (void *) &message
[i
]);
88 for (int i
=0; i
<THREADS
; i
++) {
89 pthread_join(thr
[i
], (void**)&status
);
93 for (int i
=0; i
<THREADS
; i
++) {
95 pthread_create (&thr
[i
], NULL
,
96 &runDelTest
, (void *) &message
[i
]);
98 for (int i
=0; i
<THREADS
; i
++) {
99 pthread_join(thr
[i
], (void**)&status
);
102 //dbMgr->dropTable("t1");
106 void* runInsTest(void *message
)
109 DbRetVal rv
= conn
.open("root", "manager");
112 printf("Error during connection %d\n", rv
);
115 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
116 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
117 Table
*table
= dbMgr
->openTable("t1");
118 if (table
== NULL
) { printf("Unable to open table\n"); return NULL
; }
120 char name
[200] = "PRABAKARAN";
121 table
->bindFld("f1", &id
);
122 table
->bindFld("f2", name
);
128 int val
= *(int*)message
;
131 for(i
= val
* RECORDS
; i
< (val
*RECORDS
) +RECORDS
; i
++)
133 rv
= conn
.startTransaction();
134 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
136 strcpy(name
, "PRABAKARAN0123456750590");
137 ret
= table
->insertTuple();
139 while (ret
== ErrLockTimeOut
)
141 rv
= conn
.rollback();
143 while (rv
== ErrLockTimeOut
)
145 printf("retrying abort\n");
146 rv
= conn
.rollback();
149 if (retrycnt
== 10) { ret
= 1; break;}
150 rv
= conn
.startTransaction();
152 while (rv
== ErrLockTimeOut
)
154 printf("retrying startTransaction\n");
155 rv
= conn
.startTransaction();
158 ret
= table
->insertTuple();
160 //ret =1; break; //temp to analyse issue
162 if (ret
!= 0) { printf("RETURNING EARLY: %d with i:%d\n", ret
, i
); break;}
166 printf("COMMIT returned %d for record %d\n", rv
, i
);
167 if (rv
!= ErrLockTimeOut
)
169 printf("RETURNING EARLY: with i:%d\n", i
);
174 while (rv
== ErrLockTimeOut
) {
175 printf("retrying commit\n");
179 //if (icount %RECORDS ==0) printf("%d\n", i);
183 sprintf(msgBuf
,"Insert: Thread %lu %d: Total rows :%d Time taken:%lld ms\n",os::getthrid(), val
, icount
, timer
.avg()/1000/1000);
184 os::write(1,msgBuf
,strlen(msgBuf
));
185 dbMgr
->closeTable(table
);
189 void* runSelTest(void *message
)
192 DbRetVal rv
= conn
.open("root", "manager");
195 printf("Error during connection %d\n", rv
);
198 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
199 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
200 Table
*table
= dbMgr
->openTable("t1");
201 if (table
== NULL
) { printf("Unable to open table\n"); return NULL
; }
203 char name
[20] = "PRABAKARAN";
204 table
->bindFld("f1", &id
);
205 table
->bindFld("f2", name
);
210 int val
= *(int*)message
;
214 p1
.setTerm("f1", OpEquals
, &valTerm
);
215 table
->setCondition(&p1
);
218 for(i
= val
* RECORDS
; i
< (val
*RECORDS
) +RECORDS
; i
++)
220 rv
= conn
.startTransaction(isoLevel
);
221 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction(isoLevel
);
223 rv
= table
->execute();
225 printf("Execute returned %d\n", rv
);
228 while (rv
== ErrLockTimeOut
) {
229 if (retry
== 0) break;
230 printf("retrying execute\n");
231 rv
= table
->execute();
235 tuple
= (char*)table
->fetch() ;
236 if (tuple
== NULL
) break;
241 printf("Commit returned rv:%d for record:%d\n",rv
, i
);
242 while (rv
== ErrLockTimeOut
) {
243 printf("retrying commit\n");
251 sprintf(msgBuf
,"Select: Thread %lu %d: Total rows :%d Time taken:%lld ms\n",os::getthrid(), val
, icount
, timer
.avg()/1000/1000);
252 os::write(1,msgBuf
,strlen(msgBuf
));
253 dbMgr
->closeTable(table
);
259 void* runDelTest(void *message
)
262 DbRetVal rv
= conn
.open("root", "manager");
265 printf("Error during connection %d\n", rv
);
268 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
269 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
270 Table
*table
= dbMgr
->openTable("t1");
271 if (table
== NULL
) { printf("Unable to open table\n"); return NULL
; }
273 char name
[20] = "PRABAKARAN";
274 table
->bindFld("f1", &id
);
275 table
->bindFld("f2", name
);
282 int val
= *(int*)message
;
286 p1
.setTerm("f1", OpEquals
, &valTerm
);
287 table
->setCondition(&p1
);
290 for(i
= val
* RECORDS
; i
< (val
*RECORDS
) +RECORDS
; i
++)
292 rv
= conn
.startTransaction();
293 if (rv
!= OK
) while (rv
!=OK
) rv
= conn
.startTransaction();
296 rv
= table
->execute();
298 printf("Execute returned %d\n", rv
);
301 while (rv
== ErrLockTimeOut
) {
302 if (retry
== 0) { printf("DELETE:execute failed\n"); break;}
303 printf("retrying execute\n");
304 rv
= table
->execute();
308 tuple
= (char*)table
->fetch() ;
309 if (tuple
== NULL
) { printf("DELETE:fetch failed\n");break;}
310 ret
= table
->deleteTuple();
312 while (ret
== ErrLockTimeOut
)
315 rv
= conn
.rollback();
317 while (rv
== ErrLockTimeOut
)
319 printf("retrying abort\n");
320 rv
= conn
.rollback();
323 if (retrycnt
== 10) { ret
= 1; break;}
324 rv
= conn
.startTransaction();
326 while (rv
== ErrLockTimeOut
)
328 printf("retrying startTransaction\n");
329 rv
= conn
.startTransaction();
332 rv
= table
->execute();
334 printf("Execute returned %d\n", rv
);
337 while (rv
== ErrLockTimeOut
) {
338 if (retry
== 0) { printf("DELETE:execute failed\n"); break;}
339 printf("retrying execute\n");
340 rv
= table
->execute();
344 tuple
= (char*)table
->fetch() ;
345 if (tuple
== NULL
) { printf("DELETE:fetch failed\n");break;}
346 ret
= table
->deleteTuple();
348 //ret =1; break; //temp to analyse issue
350 if (ret
!= 0) { printf("RETURNING EARLY: %d with i:%d\n", ret
, i
); break;}
354 printf("COMMIT returned %d for record %d\n", rv
, i
);
355 if (rv
!= ErrLockTimeOut
)
357 printf("RETURNING EARLY: with i:%d\n", i
);
362 while (rv
== ErrLockTimeOut
) {
363 printf("retrying commit\n");
368 //if (icount %RECORDS ==0) printf("%d\n", i);
372 sprintf(msgBuf
,"Delete: Thread %lu %d: Total rows :%d Time taken:%lld ms\n",os::getthrid(), val
, icount
, timer
.avg()/1000/1000);
373 os::write(1,msgBuf
,strlen(msgBuf
));
374 dbMgr
->closeTable(table
);