19 #include <NDBT_Test.hpp>
20 #include <HugoTransactions.hpp>
21 #include <UtilTransactions.hpp>
23 #include <NdbConfig.hpp>
24 #include <signaldata/DumpStateOrd.hpp>
26 #define TIMEOUT (Uint32)3000
27 Uint32 g_org_timeout = 3000;
28 Uint32 g_org_deadlock = 3000;
33 int timeout = ctx->getProperty(
"TransactionInactiveTimeout",TIMEOUT);
35 NdbConfig conf(GETNDB(step)->getNodeId()+1);
36 unsigned int nodeId = conf.getMasterNodeId();
37 if (!conf.getProperty(nodeId,
39 CFG_DB_TRANSACTION_INACTIVE_TIMEOUT,
44 int val[] = { DumpStateOrd::TcSetApplTransactionTimeout, timeout };
45 if(restarter.dumpStateAllNodes(val, 2) != 0){
56 int val[] = { DumpStateOrd::TcSetApplTransactionTimeout, g_org_timeout };
57 if(restarter.dumpStateAllNodes(val, 2) != 0){
67 int timeout = ctx->getProperty(
"TransactionDeadlockTimeout", TIMEOUT);
69 NdbConfig conf(GETNDB(step)->getNodeId()+1);
70 unsigned int nodeId = conf.getMasterNodeId();
71 if (!conf.getProperty(nodeId,
73 CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT,
77 g_err <<
"Setting timeout: " << timeout << endl;
78 int val[] = { DumpStateOrd::TcSetTransactionTimeout, timeout };
79 if(restarter.dumpStateAllNodes(val, 2) != 0){
91 NdbConfig conf(GETNDB(step)->getNodeId()+1);
92 unsigned int nodeId = conf.getMasterNodeId();
93 if (!conf.getProperty(nodeId,
95 CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT,
101 ctx->setProperty(
"TransactionDeadlockTimeout", 4*val);
110 int val[] = { DumpStateOrd::TcSetTransactionTimeout, g_org_deadlock };
111 if(restarter.dumpStateAllNodes(val, 2) != 0){
121 int records = ctx->getNumRecords();
123 if (hugoTrans.loadTable(GETNDB(step), records) != 0){
130 int records = ctx->getNumRecords();
133 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
140 #define CHECK(b) if (!(b)) { \
141 ndbout << "ERR: "<< step->getName() \
142 << " failed on line " << __LINE__ << endl; \
143 result = NDBT_FAILED; \
147 int result = NDBT_OK;
148 int loops = ctx->getNumLoops();
149 int stepNo = step->getStepNo();
150 int mul1 = ctx->getProperty(
"Op1", (Uint32)0);
151 int mul2 = ctx->getProperty(
"Op2", (Uint32)0);
152 int records = ctx->getNumRecords();
154 int timeout = ctx->getProperty(
"TransactionInactiveTimeout",TIMEOUT);
156 int minSleep = (int)(timeout * 1.5);
157 int maxSleep = timeout * 2;
160 Ndb* pNdb = GETNDB(step);
162 for (
int l = 0; l<loops && !ctx->isTestStopped() && result == NDBT_OK; l++){
164 int op1 = 0 + (l + stepNo) * mul1;
165 int op2 = 0 + (l + stepNo) * mul2;
170 ndbout << stepNo <<
": TransactionInactiveTimeout="<< timeout
171 <<
", minSleep="<<minSleep
172 <<
", maxSleep="<<maxSleep
174 <<
", op2=" << op2 << endl;;
178 CHECK(hugoOps.startTransaction(pNdb) == 0);
184 if(hugoOps.pkReadRecord(pNdb, stepNo) != 0){
185 g_err << stepNo <<
": Fail" << __LINE__ << endl;
186 result = NDBT_FAILED;
break;
190 if(hugoOps.pkUpdateRecord(pNdb, stepNo) != 0){
191 g_err << stepNo <<
": Fail" << __LINE__ << endl;
192 result = NDBT_FAILED;
break;
196 if(hugoOps.pkDeleteRecord(pNdb, stepNo) != 0){
197 g_err << stepNo <<
": Fail" << __LINE__ << endl;
198 result = NDBT_FAILED;
break;
202 if(hugoOps.pkInsertRecord(pNdb, stepNo+records+l) != 0){
203 g_err << stepNo <<
": Fail" << __LINE__ << endl;
204 result = NDBT_FAILED;
break;
209 if(result != NDBT_OK)
212 int res = hugoOps.execute_NoCommit(pNdb);
214 g_err << stepNo <<
": Fail" << __LINE__ << endl;
215 result = NDBT_FAILED;
break;
218 int sleep = minSleep + myRandom48(maxSleep-minSleep);
219 ndbout << stepNo <<
": Sleeping for "<< sleep <<
" milliseconds" << endl;
220 NdbSleep_MilliSleep(sleep);
226 if(hugoOps.pkReadRecord(pNdb, stepNo) != 0){
227 g_err << stepNo <<
": Fail" << __LINE__ << endl;
228 result = NDBT_FAILED;
break;
232 if(hugoOps.pkUpdateRecord(pNdb, stepNo) != 0){
233 g_err << stepNo <<
": Fail" << __LINE__ << endl;
234 result = NDBT_FAILED;
break;
238 if(hugoOps.pkDeleteRecord(pNdb, stepNo) != 0){
239 g_err << stepNo <<
": Fail" << __LINE__ << endl;
240 result = NDBT_FAILED;
break;
244 if(hugoOps.pkInsertRecord(pNdb, stepNo+2*records+l) != 0){
245 g_err << stepNo <<
": Fail" << __LINE__ << endl;
246 result = NDBT_FAILED;
break;
252 res = hugoOps.execute_Commit(pNdb);
253 if(op1 != 0 && res != 266){
254 g_err << stepNo <<
": Fail: " << res <<
"!= 237, op1="
255 << op1 <<
", op2=" << op2 << endl;
256 result = NDBT_FAILED;
break;
261 hugoOps.closeTransaction(pNdb);
268 int result = NDBT_OK;
269 int loops = ctx->getNumLoops();
270 int stepNo = step->getStepNo();
272 int timeout = ctx->getProperty(
"TransactionInactiveTimeout",TIMEOUT);
274 int maxSleep = (int)(timeout * 0.5);
275 ndbout <<
"TransactionInactiveTimeout="<< timeout
276 <<
", maxSleep="<<maxSleep<<endl;
280 Ndb* pNdb = GETNDB(step);
282 for (
int l = 0; l < loops && result == NDBT_OK; l++){
286 CHECK(hugoOps.startTransaction(pNdb) == 0);
287 CHECK(hugoOps.pkReadRecord(pNdb, stepNo) == 0);
288 CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
290 int sleep = myRandom48(maxSleep);
291 ndbout <<
"Sleeping for " << sleep <<
" milliseconds" << endl;
292 NdbSleep_MilliSleep(sleep);
295 CHECK(hugoOps.execute_Commit(pNdb) == 0);
299 hugoOps.closeTransaction(pNdb);
306 int result = NDBT_OK;
307 int loops = ctx->getNumLoops();
308 int stepNo = step->getStepNo();
310 Uint32 deadlock_timeout;
311 NdbConfig conf(GETNDB(step)->getNodeId()+1);
312 unsigned int nodeId = conf.getMasterNodeId();
313 if (!conf.getProperty(nodeId,
315 CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT,
321 int do_sleep = (int)(deadlock_timeout * 0.5);
325 Ndb* pNdb = GETNDB(step);
327 for (
int l = 0; l < loops && result == NDBT_OK; l++){
331 CHECK(hugoOps.startTransaction(pNdb) == 0);
332 CHECK(hugoOps.pkReadRecord(pNdb, stepNo) == 0);
333 CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
335 int sleep = int(deadlock_timeout * 1.5 + myRandom48(do_sleep));
336 ndbout <<
"Sleeping for " << sleep <<
" milliseconds" << endl;
337 NdbSleep_MilliSleep(sleep);
340 CHECK(hugoOps.execute_Commit(pNdb) == 0);
344 hugoOps.closeTransaction(pNdb);
351 int result = NDBT_OK;
352 int loops = ctx->getNumLoops();
353 int records = ctx->getNumRecords();
354 int stepNo = step->getStepNo();
355 int maxSleep = (int)(TIMEOUT * 0.3);
356 ndbout <<
"TransactionInactiveTimeout="<< TIMEOUT
357 <<
", maxSleep="<<maxSleep<<endl;
360 Ndb* pNdb = GETNDB(step);
362 for (
int l = 1; l < loops && result == NDBT_OK; l++){
366 CHECK(hugoOps.startTransaction(pNdb) == 0);
367 int recordNo = records + (stepNo*loops) + l;
368 CHECK(hugoOps.pkInsertRecord(pNdb, recordNo) == 0);
369 CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
371 int remain = maxSleep;
372 for (
int i = 0;
i < 3;
i++)
380 CHECK(pTrans->
execute(NoCommit) == 0);
383 int sleep = myRandom48(remain);
384 remain = remain - sleep + 1;
385 ndbout <<
"Sleeping for " << sleep <<
" milliseconds" << endl;
386 NdbSleep_MilliSleep(sleep);
390 CHECK(hugoOps.execute_Commit(pNdb) == 0);
394 hugoOps.closeTransaction(pNdb);
401 int result = NDBT_OK;
402 int loops = ctx->getNumLoops();
405 ndbout <<
"TransactionInactiveTimeout="<< TIMEOUT <<endl;
408 Ndb* pNdb = GETNDB(step);
410 for (
int l = 1; l < loops && result == NDBT_OK; l++){
414 pTrans = pNdb->startTransaction();
417 CHECK(pTrans->
execute(NoCommit) == 0);
419 int sleep = 2 * TIMEOUT;
420 ndbout <<
"Sleeping for " << sleep <<
" milliseconds" << endl;
421 NdbSleep_MilliSleep(sleep);
425 ndbout_c(
"res: %d", res);
440 int result = NDBT_OK;
441 int loops = ctx->getNumLoops();
442 int records = ctx->getNumRecords();
443 int stepNo = step->getStepNo();
444 int maxSleep = (int)(TIMEOUT * 0.3);
445 ndbout <<
"TransactionInactiveTimeout="<< TIMEOUT
446 <<
", maxSleep="<<maxSleep<<endl;
449 Ndb* pNdb = GETNDB(step);
451 for (
int l = 1; l < loops && result == NDBT_OK; l++){
455 CHECK(hugoOps.startTransaction(pNdb) == 0);
456 int recordNo = records + (stepNo*loops) + l;
457 CHECK(hugoOps.pkInsertRecord(pNdb, recordNo) == 0);
458 CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
460 for (
int i = 0;
i < 3;
i++)
465 for (
int j = 0; j <=
i; j++)
473 CHECK(pTrans->
execute(NoCommit) == 0);
475 for (
unsigned i = 0;
i<TIMEOUT;
i += 1000)
478 NdbSleep_MilliSleep(1000);
482 for (
size_t j = 0; j < ops.size(); j++)
484 while((res = ops[j]->nextResult()) == 0);
490 CHECK(hugoOps.execute_Commit(pNdb) == 0);
494 hugoOps.closeTransaction(pNdb);
502 int result = NDBT_OK;
506 int timeout = ctx->getProperty(
"TransactionDeadlockTimeout", TIMEOUT);
509 Ndb* pNdb = GETNDB(step);
513 CHECK(hugoOps.startTransaction(pNdb) == 0);
514 CHECK(hugoOps.pkUpdateRecord(pNdb, 0) == 0);
515 int ret = hugoOps.execute_NoCommit(pNdb);
519 ndbout <<
"Sleeping for " << sleep <<
" milliseconds" << endl;
520 NdbSleep_MilliSleep(sleep);
523 CHECK(hugoOps.execute_Commit(pNdb) == 0);
531 hugoOps.closeTransaction(pNdb);
537 NDBT_TESTSUITE(testTimeout);
538 TESTCASE(
"DontTimeoutTransaction",
539 "Test that the transaction does not timeout "\
540 "if we sleep during the transaction. Use a sleep "\
541 "value which is smaller than TransactionInactiveTimeout"){
542 INITIALIZER(runLoadTable);
543 INITIALIZER(setTransactionTimeout);
544 STEPS(runDontTimeoutTrans, 1);
545 FINALIZER(resetTransactionTimeout);
546 FINALIZER(runClearTable);
549 "Setting TransactionInactiveTimeout to 0(zero) "\
550 "should result in infinite timeout, and not as "\
551 "was the bug, a timeout that is equal to the deadlock timeout"){
552 TC_PROPERTY(
"TransactionInactiveTimeout",(Uint32)0);
553 INITIALIZER(runLoadTable);
554 INITIALIZER(setTransactionTimeout);
555 STEPS(runDeadlockTimeoutTrans, 1);
556 FINALIZER(resetTransactionTimeout);
557 FINALIZER(runClearTable);
559 TESTCASE(
"DontTimeoutTransaction5",
560 "Test that the transaction does not timeout "\
561 "if we sleep during the transaction. Use a sleep "\
562 "value which is smaller than TransactionInactiveTimeout" \
563 "Five simultaneous threads"){
564 INITIALIZER(runLoadTable);
565 INITIALIZER(setTransactionTimeout);
566 STEPS(runDontTimeoutTrans, 5);
567 FINALIZER(resetTransactionTimeout);
568 FINALIZER(runClearTable);
570 TESTCASE(
"TimeoutRandTransaction",
571 "Test that the transaction does timeout "\
572 "if we sleep during the transaction. Use a sleep "\
573 "value which is larger than TransactionInactiveTimeout"){
574 INITIALIZER(runLoadTable);
575 INITIALIZER(setTransactionTimeout);
576 TC_PROPERTY(
"Op1", 7);
577 TC_PROPERTY(
"Op2", 11);
578 STEPS(runTimeoutTrans2, 5);
579 FINALIZER(resetTransactionTimeout);
580 FINALIZER(runClearTable);
582 TESTCASE(
"BuddyTransNoTimeout",
583 "Start a transaction and perform an insert with NoCommit. " \
584 "Start a buddy transaction wich performs long running scans " \
586 "The total sleep time is longer than TransactionInactiveTimeout" \
587 "Commit the first transaction, it should not have timed out."){
588 INITIALIZER(runLoadTable);
589 INITIALIZER(setTransactionTimeout);
590 STEPS(runBuddyTransNoTimeout, 1);
591 FINALIZER(resetTransactionTimeout);
592 FINALIZER(runClearTable);
594 TESTCASE(
"BuddyTransNoTimeout5",
595 "Start a transaction and perform an insert with NoCommit. " \
596 "Start a buddy transaction wich performs long running scans " \
598 "The total sleep time is longer than TransactionInactiveTimeout" \
599 "Commit the first transaction, it should not have timed out." \
600 "Five simultaneous threads"){
601 INITIALIZER(runLoadTable);
602 INITIALIZER(setTransactionTimeout);
603 STEPS(runBuddyTransNoTimeout, 5);
604 FINALIZER(resetTransactionTimeout);
605 FINALIZER(runClearTable);
607 TESTCASE(
"BuddyTransTimeout1",
608 "Start a scan and check that it gets aborted"){
609 INITIALIZER(runLoadTable);
610 INITIALIZER(setTransactionTimeout);
611 STEPS(runBuddyTransTimeout, 1);
612 FINALIZER(resetTransactionTimeout);
613 FINALIZER(runClearTable);
615 TESTCASE(
"ScanRefreshNoTimeout",
618 INITIALIZER(runLoadTable);
619 INITIALIZER(setTransactionTimeout);
620 STEPS(runScanRefreshNoTimeout, 1);
621 FINALIZER(resetTransactionTimeout);
622 FINALIZER(runClearTable);
625 TESTCASE(
"Error4012",
""){
626 TC_PROPERTY(
"TransactionDeadlockTimeout", 120000);
627 INITIALIZER(runLoadTable);
628 INITIALIZER(getDeadlockTimeout);
629 INITIALIZER(setDeadlockTimeout);
630 STEPS(runError4012, 2);
631 FINALIZER(runClearTable);
634 NDBT_TESTSUITE_END(testTimeout);
636 int main(
int argc,
const char** argv){
638 myRandom48Init((
long)NdbTick_CurrentMillisecond());
639 NDBT_TESTSUITE_INSTANCE(testTimeout);
640 return testTimeout.execute(argc, argv);