19 #include <NDBT_Test.hpp>
20 #include <HugoTransactions.hpp>
21 #include <UtilTransactions.hpp>
22 #include <NdbRestarter.hpp>
23 #include <NdbRestarts.hpp>
29 #define MAX_NDB_OBJECTS 32678
31 #define CHECK(b) if (!(b)) { \
32 ndbout << "ERR: failed on line " << __LINE__ << endl; \
35 #define CHECKE(b) if (!(b)) { \
37 ndbout << "ERR: "<< step->getName() \
38 << " failed on line " << __LINE__ << endl; \
39 result = NDBT_FAILED; \
42 static const char* ApiFailTestRun =
"ApiFailTestRun";
43 static const char* ApiFailTestComplete =
"ApiFailTestComplete";
44 static const char* ApiFailTestsRunning =
"ApiFailTestsRunning";
45 static const char* ApiFailNumberPkSteps =
"ApiFailNumberPkSteps";
46 static const int MAX_STEPS = 10;
48 static Ndb* stepNdbs[MAX_STEPS];
52 Uint32 loops = ctx->getNumLoops();
57 while (l < loops && result == NDBT_OK){
58 ndbout_c(
"loop %d", l + 1);
66 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
68 ndbout <<
"pNdb == NULL" << endl;
75 ndbVector.push_back(pNdb);
85 }
while (errors == 0);
87 ndbout << i <<
" ndb objects created" << endl;
89 if (l > 0 && i != oldi && init != MAX_NDB_OBJECTS){
90 ndbout << l <<
": not as manyNdb objects created" << endl
91 << i <<
" != " << oldi << endl;
98 for(
size_t j = 0; j < ndbVector.size(); j++){
100 if(((j+1) % 250) == 0){
101 ndbout <<
"Deleted " << (Uint64) j <<
" ndb objects " << endl;
113 Uint32 loops = ctx->getNumLoops();
116 int result = NDBT_OK;
118 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
120 ndbout <<
"pNdb == NULL" << endl;
123 if (pNdb->
init(2048)){
130 if (pTab == 0) abort();
132 while (l < loops && result == NDBT_OK){
153 ndbout_c(
"%s", key.
c_str());
169 conVector.push_back(pCon);
172 }
while (errors < maxErrors);
174 ndbout << i <<
" connections created" << endl;
176 if (l > 0 && i != oldi){
177 ndbout << l <<
": not as many transactions created" << endl
178 << i <<
" != " << oldi << endl;
179 result = NDBT_FAILED;
185 for(
size_t j = 0; j < conVector.size(); j++){
204 int result = NDBT_OK;
208 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
210 ndbout <<
"pNdb == NULL" << endl;
213 if (pNdb->
init(2048)){
221 bool endTest =
false;
222 while (!endTest && result == NDBT_OK){
226 maxOpsLimit = l*1000;
228 if (hugoOps.startTransaction(pNdb) != NDBT_OK){
234 while (errors < maxErrors){
236 if(hugoOps.pkReadRecord(pNdb,1, 1) != NDBT_OK){
243 if (i >= maxOpsLimit){
249 ndbout << i <<
" operations used" << endl;
251 int execResult = hugoOps.execute_Commit(pNdb);
260 result = NDBT_FAILED;
264 hugoOps.closeTransaction(pNdb);
277 int result = NDBT_OK;
280 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
282 ndbout <<
"pNdb == NULL" << endl;
285 if (pNdb->
init(2048)){
293 for (
int m = 1; m < 100; m++){
318 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
328 int maxLimit = 1000*m;
335 result = NDBT_FAILED;
342 }
while (errors < maxErrors && i < maxLimit);
344 ndbout << i <<
" getValues called" << endl;
347 if (pCon->
execute(Commit) != 0){
359 ndbout <<
"Illegal error" << endl;
376 Uint32 loops = ctx->getNumLoops();
378 int result = NDBT_OK;
381 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
383 ndbout <<
"pNdb == NULL" << endl;
386 if (pNdb->
init(2048)){
395 for(
int m = 1; m < 10; m++){
401 ndbout <<
"Could not start transaction" << endl;
422 int maxLimit = 1000*m;
429 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
433 result = NDBT_FAILED;
442 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
446 result = NDBT_FAILED;
455 }
while (errors < maxErrors && i < maxLimit);
462 if (err.
code == 4225) {
469 ndbout << i <<
" equal called" << endl;
472 int check = pCon->
execute(Commit);
489 Uint32 loops = ctx->getNumLoops();
491 int result = NDBT_OK;
496 int records = ctx->getNumRecords();
498 while (l < loops && result == NDBT_OK){
501 for(
int i = 0; i < 5; i++){
502 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
504 ndbout <<
"pNdb == NULL" << endl;
505 result = NDBT_FAILED;
508 ndbVector.push_back(pNdb);
512 result = NDBT_FAILED;
517 result = NDBT_FAILED;
520 if (hugoTrans.pkReadRecords(pNdb, records) != 0){
521 result = NDBT_FAILED;
528 ndbout <<
"Restart random node " << endl;
529 if(restarts.executeRestart(ctx,
"RestartRandomNodeAbort", 120) != 0){
530 g_err <<
"Failed to executeRestart(RestartRandomNode)"<<endl;
531 result = NDBT_FAILED;
536 ndbout <<
"Restart all nodes " << endl;
537 if(restarts.executeRestart(ctx,
"RestartAllNodesAbort", 120) != 0){
538 g_err <<
"Failed to executeRestart(RestartAllNodes)"<<endl;
539 result = NDBT_FAILED;
545 for(
size_t j = 0; j < ndbVector.size(); j++)
554 for(
size_t i = 0; i < ndbVector.size(); i++)
563 int records = ctx->getNumRecords();
566 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
573 int records = ctx->getNumRecords();
575 if (hugoTrans.loadTable(GETNDB(step), records) != 0){
583 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
588 ndbout <<
"waitUntilReady returned OK" << endl;
596 if (err.
code != 4256)
604 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
606 ndbout <<
"pNdb == NULL" << endl;
641 int result = NDBT_OK;
645 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
647 ndbout <<
"pNdb == NULL" << endl;
659 for (i= 0; i < CASES; i++)
661 ndbout <<
"Case " << i << endl;
680 int expectedError= 0;
695 failed= (pOp->
getValue(
"MOST_IMPROBABLE2") == NULL);
709 failed= (pOp->
equal(
"MOST_IMPROBABLE2", 0) != 0);
723 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
736 failed= (pOp->
setValue(
"MOST_IMPROBABLE2", 0) != 0);
766 ndbout <<
"About to call getBlobHandle" << endl;
784 ndbout <<
"Error reporting mismatch, expected "
785 << expectedError << endl;
786 result = NDBT_FAILED;
788 if (opErr.
code != expectedError){
789 ndbout <<
"No or bad error detected, expected "
790 << expectedError << endl;
791 result = NDBT_FAILED;
794 ndbout <<
"Case " << i <<
" did not fail" << endl;
795 result = NDBT_FAILED;
800 if (result == NDBT_FAILED)
810 int result = NDBT_OK;
814 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
816 ndbout <<
"pNdb == NULL" << endl;
847 ndbout <<
"hupp" << endl;
848 result = NDBT_FAILED;
851 ndbout <<
"hupp2" << endl;
852 result = NDBT_FAILED;
864 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
866 ndbout <<
"pNdb == NULL" << endl;
913 int check = pCon->
execute(Commit);
925 int result = NDBT_OK;
930 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
932 ndbout <<
"pNdb == NULL" << endl;
965 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
977 int check = pCon->
execute(Commit);
979 ndbout <<
"execute worked" << endl;
982 result = NDBT_FAILED;
992 int result = NDBT_OK;
996 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
998 ndbout <<
"pNdb == NULL" << endl;
1032 int check = pCon->
execute(Commit);
1034 ndbout <<
"execute worked" << endl;
1035 result = NDBT_FAILED;
1048 int result = NDBT_OK;
1053 Ndb* pNdb = GETNDB(step);
1056 for(Uint32 cm= 0; cm < 2; cm++)
1081 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
1092 int check = pCon->
execute(cm == 0 ? NoCommit : Commit);
1094 ndbout <<
"execute worked" << endl;
1097 result = NDBT_FAILED;
1132 int check = pCon->
execute(NoCommit);
1134 ndbout <<
"execute worked" << endl;
1137 result = NDBT_FAILED;
1145 result = NDBT_FAILED;
1153 int result = NDBT_OK;
1156 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
1158 ndbout <<
"pNdb == NULL" << endl;
1161 if (pNdb->
init(2048)){
1172 ndbout <<
"Could not start transaction" << endl;
1190 if(hugoOps.equalForAttr(pOp, a, 1) != 0){
1196 result = NDBT_FAILED;
1200 result = NDBT_FAILED;
1205 result = NDBT_FAILED;
1217 #define C2(x) { int _x= (x); if(_x == 0){ ndbout << "line: " << __LINE__ << endl; return NDBT_FAILED;} }
1220 int result = NDBT_OK;
1225 Ndb* pNdb = GETNDB(step);
1226 C2(hugoOps.startTransaction(pNdb) == 0);
1227 C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
1228 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1229 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1230 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1231 C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
1232 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1233 C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
1234 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1235 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1236 C2(hugoOps.execute_Commit(pNdb) == 0);
1237 C2(hugoOps.closeTransaction(pNdb) == 0);
1239 C2(hugoOps.startTransaction(pNdb) == 0);
1240 C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
1241 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1242 C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
1243 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1244 C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
1245 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1246 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1247 C2(hugoOps.execute_Commit(pNdb) == 0);
1248 C2(hugoOps.closeTransaction(pNdb) == 0);
1250 C2(hugoOps.startTransaction(pNdb) == 0);
1251 C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
1252 C2(hugoOps.execute_Commit(pNdb) == 0);
1253 C2(hugoOps.closeTransaction(pNdb) == 0);
1255 C2(hugoOps.startTransaction(pNdb) == 0);
1257 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1258 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1259 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1260 C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
1261 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1262 C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
1263 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1264 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1265 C2(hugoOps.execute_Commit(pNdb) == 0);
1266 C2(hugoOps.closeTransaction(pNdb) == 0);
1268 Ndb ndb2(&ctx->m_cluster_connection,
"TEST_DB");
1269 C2(ndb2.init() == 0);
1270 C2(ndb2.waitUntilReady() == 0);
1273 C2(hugoOps.startTransaction(pNdb) == 0);
1274 C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
1275 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1276 C2(hugoOps2.startTransaction(&ndb2) == 0);
1277 C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0);
1279 C2(hugoOps.execute_Commit(pNdb) == 0);
1280 C2(hugoOps2.wait_async(&ndb2) == 0);
1281 C2(hugoOps.closeTransaction(pNdb) == 0);
1282 C2(hugoOps2.closeTransaction(&ndb2) == 0);
1284 C2(hugoOps.startTransaction(pNdb) == 0);
1285 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1286 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1287 C2(hugoOps2.startTransaction(&ndb2) == 0);
1288 C2(hugoOps2.pkWriteRecord(&ndb2, 0, 1) == 0);
1290 C2(hugoOps.execute_Commit(pNdb) == 0);
1291 C2(hugoOps2.wait_async(&ndb2) == 0);
1292 C2(hugoOps2.execute_Commit(pNdb) == 0);
1293 C2(hugoOps.closeTransaction(pNdb) == 0);
1294 C2(hugoOps2.closeTransaction(&ndb2) == 0);
1296 C2(hugoOps.startTransaction(pNdb) == 0);
1297 C2(hugoOps.pkUpdateRecord(pNdb, 0, 1) == 0);
1298 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1299 C2(hugoOps2.startTransaction(&ndb2) == 0);
1300 C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0);
1302 C2(hugoOps.execute_Commit(pNdb) == 0);
1303 C2(hugoOps2.wait_async(&ndb2) == 0);
1304 C2(hugoOps.closeTransaction(pNdb) == 0);
1305 C2(hugoOps2.closeTransaction(&ndb2) == 0);
1307 C2(hugoOps.startTransaction(pNdb) == 0);
1308 C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
1309 C2(hugoOps.execute_NoCommit(pNdb) == 0);
1310 C2(hugoOps2.startTransaction(&ndb2) == 0);
1311 C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0);
1313 C2(hugoOps.execute_Commit(pNdb) == 0);
1314 C2(hugoOps2.wait_async(&ndb2) != 0);
1315 C2(hugoOps.closeTransaction(pNdb) == 0);
1316 C2(hugoOps2.closeTransaction(&ndb2) == 0);
1322 int result = NDBT_OK;
1327 Ndb* pNdb = GETNDB(step);
1328 C2(hugoOps.startTransaction(pNdb) == 0);
1329 C2(hugoOps.pkWritePartialRecord(pNdb, 0, 1) == 0);
1330 C2(hugoOps.execute_Commit(pNdb, AO_IgnoreError) == 839);
1331 C2(hugoOps.closeTransaction(pNdb) == 0);
1337 int result = NDBT_OK;
1338 const Uint32 max= 5;
1341 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
1343 ndbout <<
"pNdb == NULL" << endl;
1346 if (pNdb->
init(max)){
1361 for(i = 0; i<10*max; i++)
1377 scans.push_back(pOp);
1383 int check = pCon->
execute(NoCommit);
1385 ndbout <<
"execute worked" << endl;
1390 for(i= 0; i<scans.size(); i++)
1406 for(i= 0; i<10*max; i++)
1410 cons.push_back(pCon);
1415 for(i= 0; i<cons.size(); i++)
1420 if(cons.size() != max)
1422 result= NDBT_FAILED;
1430 char pkIdxName[255];
1433 bool orderedIndex = ctx->getProperty(
"OrderedIndex", (
unsigned)0);
1436 Ndb* pNdb = GETNDB(step);
1438 bool logged = ctx->getProperty(
"LoggedIndexes", 1);
1443 ndbout <<
"Creating " << ((logged)?
"logged ":
"temporary ") <<
"ordered index "
1444 << pkIdxName <<
" (";
1446 ndbout <<
"Creating " << ((logged)?
"logged ":
"temporary ") <<
"unique index "
1447 << pkIdxName <<
" (";
1450 pIdx.setTable(pTab->
getName());
1458 pIdx.addIndexColumn(col->
getName());
1459 ndbout << col->
getName() <<
" ";
1463 pIdx.setStoredIndex(logged);
1466 ndbout <<
"FAILED!" << endl;
1472 ndbout <<
"OK!" << endl;
1478 Ndb* pNdb = GETNDB(step);
1481 ndbout <<
"Dropping index " << pkIdxName <<
" ";
1484 ndbout <<
"FAILED!" << endl;
1488 ndbout <<
"OK!" << endl;
1556 if(hugoOps.equalForAttr(pOp, a, row) != 0){
1579 if(hugoOps.setValueForAttr(pOp, a, row, 2) != 0){
1597 static void print(
int op)
1599 const char * str = 0;
1601 case 0: str =
"pk read-sh";
break;
1602 case 1: str =
"pk read-nl";
break;
1603 case 2: str =
"pk read-ex";
break;
1604 case 3: str =
"pk insert ";
break;
1605 case 4: str =
"pk update ";
break;
1606 case 5: str =
"pk delete ";
break;
1607 case 6: str =
"uk read-sh";
break;
1608 case 7: str =
"uk read-nl";
break;
1609 case 8: str =
"uk read-ex";
break;
1610 case 9: str =
"noop ";
break;
1611 case 10: str =
"uk update ";
break;
1612 case 11: str =
"uk delete ";
break;
1613 case 12: str =
"pk read-si";
break;
1624 Uint32 loops = ctx->getNumRecords();
1630 Ndb* pNdb = GETNDB(step);
1636 { Commit, AbortOnError },
1637 { Commit, AO_IgnoreError },
1638 { NoCommit, AbortOnError },
1639 { NoCommit, AO_IgnoreError },
1642 printf(
"case: <op1> <op2> c/nc ao/ie\n");
1644 for (Uint32 op1 = 0; op1 < 13; op1++)
1647 for (Uint32 op2 = op1; op2 < 13; op2++)
1652 for (Uint32 i = 0; i<4; i++, tno++)
1654 if (loops != 1000 && loops != tno)
1656 ExecType et = tests[
i].et;
1657 AbortOption ao = tests[
i].ao;
1659 printf(
"%.3d : ", tno);
1663 case Commit: printf(
"c ");
break;
1664 case NoCommit: printf(
"nc ");
break;
1665 default: printf(
"bad exectype : %d\n", et);
return NDBT_FAILED;
1668 case AbortOnError: printf(
"aoe ");
break;
1669 case AO_IgnoreError: printf(
"ie ");
break;
1670 default: printf(
"bad abortoption : %d\n", ao);
return NDBT_FAILED;
1675 hugoTrans.loadTable(pNdb, 1);
1677 CHECK(!op_row(pTrans, hugoOps, pTab, op1, 0));
1678 ret = pTrans->
execute(et, ao);
1681 hugoTrans.clearTable(pNdb);
1683 hugoTrans.loadTable(pNdb, 1);
1685 CHECK(!op_row(pTrans, hugoOps, pTab, op1, 1));
1686 ret = pTrans->
execute(et, ao);
1689 hugoTrans.clearTable(pNdb);
1691 hugoTrans.loadTable(pNdb, 1);
1693 CHECK(!op_row(pTrans, hugoOps, pTab, op1, 0));
1694 CHECK(!op_row(pTrans, hugoOps, pTab, op2, 1));
1695 ret = pTrans->
execute(et, ao);
1697 printf(
"%d\n", ret);
1698 hugoTrans.clearTable(pNdb);
1700 hugoTrans.clearTable(pNdb);
1723 Uint32 cnt1 = do_cnt(con);
1725 for (Uint32 i = 0; i<100; i++)
1727 Uint32 add = 1 + (rand() % 5);
1728 for (Uint32 j = 0; j<add; j++)
1730 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
1732 ndbout <<
"pNdb == NULL" << endl;
1735 objs.push_back(pNdb);
1737 if (do_cnt(con) != (cnt1 + objs.size()))
1741 for (Uint32 i = 0; i<100 && objs.size(); i++)
1743 Uint32 sub = 1 + rand() % objs.size();
1744 for (Uint32 j = 0; j<sub && objs.size(); j++)
1746 Uint32 idx = rand() % objs.size();
1750 if (do_cnt(con) != (cnt1 + objs.size()))
1754 for (Uint32 i = 0; i<objs.size(); i++)
1757 return (cnt1 == do_cnt(con)) ? NDBT_OK : NDBT_FAILED;
1761 testExecuteAsynchCallback(
int res,
NdbTransaction *con,
void *data_ptr)
1763 int *res_ptr= (
int *)data_ptr;
1770 int result = NDBT_OK;
1773 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
1775 ndbout <<
"pNdb == NULL" << endl;
1778 if (pNdb->
init(2048)){
1806 if (pOp->
getValue(NdbDictionary::Column::FRAGMENT) == 0){
1813 pCon->
executeAsynch(NoCommit, testExecuteAsynchCallback, &res);
1814 while(pNdb->
pollNdb(100000) == 0)
1818 ndbout <<
"Error returned from execute: " << res << endl;
1819 result= NDBT_FAILED;
1834 int result = NDBT_OK;
1835 int records = ctx->getNumRecords();
1839 restarter.insertErrorInAllNodes(9003);
1841 for (
int i = 0; i<ctx->getNumLoops(); i++)
1844 if (hugoTrans.loadTable(GETNDB(step), records, 2048) != 0)
1846 result = NDBT_FAILED;
1849 if (runClearTable(ctx, step) != 0)
1851 result = NDBT_FAILED;
1857 restarter.insertErrorInAllNodes(9003);
1865 int result = NDBT_OK;
1866 Ndb* pNdb = GETNDB(step);
1868 for (
int i = 0; i<ctx->getNumLoops(); i++)
1871 hugoOps.startTransaction(pNdb);
1872 if (hugoOps.pkWriteRecord(pNdb, 0) != 0)
1874 result = NDBT_FAILED;
1879 if (hugoOps.pkWritePartialRecord(pNdb, 1) != 0)
1881 result = NDBT_FAILED;
1885 if (hugoOps.pkWriteRecord(pNdb, 2) != 0)
1887 result = NDBT_FAILED;
1891 if (hugoOps.pkUpdateRecord(pNdb, 0) != 0)
1893 result = NDBT_FAILED;
1897 if (hugoOps.execute_Commit(pNdb, AO_IgnoreError) == 4011)
1899 result = NDBT_FAILED;
1902 hugoOps.closeTransaction(pNdb);
1904 if (runClearTable(ctx, step) != 0)
1906 result = NDBT_FAILED;
1922 Ndb* pNdb = GETNDB(step);
1927 hugoOps.startTransaction(pNdb);
1928 CHECK(!hugoOps.pkWriteRecord(pNdb,0));
1929 CHECK(!hugoOps.execute_Commit(pNdb, AbortOnError));
1939 restarter.insertErrorInAllNodes(5047);
1945 CHECK(op= trans->getNdbOperation(pTab));
1951 if(hugoOps.equalForAttr(op, a, 0) != 0){
1952 restarter.insertErrorInAllNodes(0);
1965 CHECK(op2= trans->getNdbOperation(pTab));
1967 CHECK(!op2->readTuple());
1971 if(hugoOps.equalForAttr(op2, a, 0) != 0){
1972 restarter.insertErrorInAllNodes(0);
1978 CHECK(op2->getValue(a));
1984 CHECK(trans->execute(NoCommit) == -1);
1986 CHECK(trans->getNdbError().code == 1218);
1988 restarter.insertErrorInAllNodes(0);
2008 Ndb* pNdb = GETNDB(step);
2011 const Uint32 sizeOfTabRec= NdbDictionary::getRecordRowLength(tabRec);
2012 char keyRowBuf[ NDB_MAX_TUPLE_SIZE_IN_WORDS << 2 ];
2013 char attrRowBuf[ NDB_MAX_TUPLE_SIZE_IN_WORDS << 2 ];
2014 bzero(keyRowBuf,
sizeof(keyRowBuf));
2015 bzero(attrRowBuf,
sizeof(attrRowBuf));
2019 const int numRecords= 100;
2021 for (
int optype=0; optype < 2; optype++)
2030 char* valPtr= NdbDictionary::getValuePtr(tabRec,
2033 CHECK(valPtr != NULL);
2035 int len= pTab->
getColumn(col)->getSizeInBytes();
2037 bool isNull= (calc.calcValue(
record, col, updates, valPtr,
2038 len, &real_len) == NULL);
2041 NdbDictionary::setNull(tabRec,
2049 memcpy(attrRowBuf, keyRowBuf, sizeOfTabRec);
2051 Uint32 mippleAttempts= 3;
2053 while (memcmp(keyRowBuf, attrRowBuf, sizeOfTabRec) == 0)
2060 char* valPtr= NdbDictionary::getValuePtr(tabRec,
2063 CHECK(valPtr != NULL);
2065 int len= pTab->
getColumn(col)->getSizeInBytes();
2068 int badRecord=
record + (rand() % 1000);
2069 bool isNull= (calc.calcValue(badRecord, col, updates, valPtr,
2070 len, &real_len) == NULL);
2076 CHECK(mippleAttempts-- != 0);
2089 op= trans->insertTuple(tabRec,
2097 op= trans->writeTuple(tabRec,
2104 CHECK(trans->
execute(Commit) == 0);
2108 memset(attrRowBuf, 0, sizeOfTabRec);
2111 memcpy(&pkVal, NdbDictionary::getValuePtr(tabRec,
2117 op= trans->readTuple(tabRec,
2122 CHECK(trans->
execute(Commit) == 0);
2129 const char* valPtr= NdbDictionary::getValuePtr(tabRec,
2132 CHECK(valPtr != NULL);
2134 char calcBuff[ NDB_MAX_TUPLE_SIZE_IN_WORDS << 2 ];
2135 int len= pTab->
getColumn(col)->getSizeInBytes();
2137 bool isNull= (calc.calcValue(
record, col, updates, calcBuff,
2138 len, &real_len) == NULL);
2142 CHECK(colIsNullable);
2143 if (!NdbDictionary::isNull(tabRec,
2147 ndbout <<
"Error, col " << col
2149 <<
") should be Null, but is not" << endl;
2157 if (NdbDictionary::isNull(tabRec,
2161 ndbout <<
"Error, col " << col
2163 <<
") should be non-Null but is null" << endl;
2169 if( memcmp(calcBuff, valPtr, real_len) != 0 )
2171 ndbout <<
"Error, col " << col
2173 <<
") should be equal, but isn't for record "
2175 ndbout <<
"Expected :";
2176 for (Uint32 i=0; i < real_len; i++)
2178 ndbout_c(
"%x ", calcBuff[i]);
2180 ndbout << endl <<
"Received :";
2181 for (Uint32 i=0; i < real_len; i++)
2183 ndbout_c(
"%x ", valPtr[i]);
2194 op= trans->deleteTuple(tabRec,
2198 CHECK(trans->
execute(Commit) == 0);
2220 Ndb* pNdb = GETNDB(step);
2223 char rowBuf[ NDB_MAX_TUPLE_SIZE_IN_WORDS << 2 ];
2224 char badKeyRowBuf[ NDB_MAX_TUPLE_SIZE_IN_WORDS << 2 ];
2228 const int numRecords= 100;
2236 char* valPtr= NdbDictionary::getValuePtr(tabRec,
2239 CHECK(valPtr != NULL);
2241 int len= pTab->
getColumn(col)->getSizeInBytes();
2243 bool isNull= (calc.calcValue(
record, col, updates, valPtr,
2244 len, &real_len) == NULL);
2247 NdbDictionary::setNull(tabRec,
2257 memcpy(badKeyRowBuf, rowBuf, NDB_MAX_TUPLE_SIZE_IN_WORDS << 2);
2260 if (calc.isIdCol(col))
2262 char* valPtr= NdbDictionary::getValuePtr(tabRec,
2265 Uint32 badId=
record+333;
2266 memcpy(valPtr, &badId,
sizeof(badId));
2277 CHECK(trans->
execute(Commit) == 0);
2282 op= trans->updateTuple(tabRec,
2287 CHECK(trans->
execute(Commit) == 0);
2298 CHECK(trans->
execute(NoCommit) == 0);
2302 CHECK(scanOp->
nextResult(&rowPtr,
true,
true) == 0);
2309 CHECK(trans->
execute(Commit) == 0);
2330 CHECK(trans->
execute(NoCommit) == 0);
2333 CHECK(scanOp->
nextResult(&rowPtr,
true,
true) == 0);
2340 CHECK(trans->
execute(Commit) == -1);
2347 op= trans->deleteTuple(tabRec,
2351 CHECK(trans->
execute(Commit) == 0);
2367 char c=
'a' + (record % (
'z' -
'a'));
2369 keyData.
appfmt(
"%cblahblah%d", c, record);
2386 Ndb* pNdb = GETNDB(step);
2390 if (strcmp(pTab->
getName(),
"T1") != 0)
2394 const char* csname=
"latin1_general_ci";
2395 charset= get_charset_by_name(csname, MYF(0));
2397 if (charset == NULL)
2399 ndbout <<
"Couldn't get charset " << csname << endl;
2405 tab.
setName(
"TAB_CICHARPKUPD");
2426 ndbout <<
"Create table failed with error : "
2437 const NdbRecord* tabRec= pTab->getDefaultRecord();
2438 const Uint32 rowLen= NDB_MAX_TUPLE_SIZE_IN_WORDS << 2;
2439 char ucRowBuf[ rowLen ];
2440 char lcRowBuf[ rowLen ];
2441 char readBuf[ rowLen ];
2442 char* ucPkPtr= NdbDictionary::getValuePtr(tabRec,
2445 Uint32* ucDataPtr= (Uint32*) NdbDictionary::getValuePtr(tabRec,
2448 char* lcPkPtr= NdbDictionary::getValuePtr(tabRec,
2451 Uint32* lcDataPtr= (Uint32*) NdbDictionary::getValuePtr(tabRec,
2455 char* readPkPtr= NdbDictionary::getValuePtr(tabRec,
2458 Uint32* readDataPtr= (Uint32*) NdbDictionary::getValuePtr(tabRec,
2463 const int numRecords= 100;
2467 for (
int record=0; record < numRecords; record++)
2469 upperKey.
assign(getKeyVal(record,
true).c_str());
2470 lowerKey.
assign(getKeyVal(record,
false).c_str());
2472 memcpy(ucPkPtr, upperKey.
c_str(), upperKey.
length());
2473 memcpy(lcPkPtr, lowerKey.
c_str(), lowerKey.
length());
2474 memcpy(ucDataPtr, &record,
sizeof(record));
2475 memcpy(lcDataPtr, &record,
sizeof(record));
2485 int rc= trans->
execute(Commit);
2494 op= trans->readTuple(tabRec,
2499 CHECK(trans->
execute(Commit) == 0);
2503 CHECK(memcmp(ucPkPtr, readPkPtr, ucPkPtr[0]) == 0);
2504 CHECK(memcmp(ucDataPtr, readDataPtr,
sizeof(
int)) == 0);
2506 memset(readBuf, 0, NDB_MAX_TUPLE_SIZE_IN_WORDS << 2);
2511 op= trans->readTuple(tabRec,
2516 CHECK(trans->
execute(Commit) == 0);
2520 CHECK(memcmp(ucPkPtr, readPkPtr, ucPkPtr[0]) == 0);
2521 CHECK(memcmp(ucDataPtr, readDataPtr,
sizeof(
int)) == 0);
2523 memset(readBuf, 0, NDB_MAX_TUPLE_SIZE_IN_WORDS << 2);
2527 unsigned char mask[1];
2529 op= trans->updateTuple(tabRec,
2535 CHECK(trans->
execute(Commit) == 0);
2540 memset(readBuf, 0, NDB_MAX_TUPLE_SIZE_IN_WORDS << 2);
2544 op= trans->readTuple(tabRec,
2549 CHECK(trans->
execute(Commit) == 0);
2553 CHECK(memcmp(lcPkPtr, readPkPtr, lcPkPtr[0]) == 0);
2554 CHECK(memcmp(lcDataPtr, readDataPtr,
sizeof(
int)) == 0);
2557 memset(readBuf, 0, NDB_MAX_TUPLE_SIZE_IN_WORDS << 2);
2561 op= trans->readTuple(tabRec,
2566 CHECK(trans->
execute(Commit) == 0);
2570 CHECK(memcmp(lcPkPtr, readPkPtr, lcPkPtr[0]) == 0);
2571 CHECK(memcmp(lcDataPtr, readDataPtr,
sizeof(
int)) == 0);
2576 op= trans->deleteTuple(tabRec,
2580 CHECK(trans->
execute(Commit) == 0);
2598 Ndb* pNdb = GETNDB(step);
2609 bool hasNullable=
false;
2610 Uint32 highestUsed= 9000;
2611 for (
int attrId=0; attrId< numCols; attrId++)
2616 CHECK(NdbDictionary::getOffset(defaultRecord,
2619 CHECK(NdbDictionary::getNullBitOffset(defaultRecord,
2621 rs.nullbit_byte_offset,
2622 rs.nullbit_bit_in_byte));
2627 rs.nullbit_byte_offset= highestUsed++;
2628 rs.nullbit_bit_in_byte= 0;
2639 CHECK(myRecord != 0);
2640 Uint32 rowLength= NdbDictionary::getRecordRowLength(myRecord);
2641 if (rowLength != highestUsed)
2643 ndbout <<
"Failure, expected row length " << highestUsed
2644 <<
" got row length " << rowLength
2666 Ndb* pNdb = GETNDB(step);
2669 int numIterations= 100;
2670 int numRecords= 1024;
2675 for (
int iter=0; iter < numIterations; iter++)
2677 ndbout <<
"Iter : " << iter << endl;
2680 CHECK(hugoOps.setTransaction(trans) == 0);
2682 CHECK(hugoOps.pkInsertRecord(pNdb,
2689 ndbout <<
"Execute failed, error is "
2700 CHECK(hugoOps.pkDeleteRecord(pNdb,
2711 hugoOps.setTransaction(NULL,
true);
2720 int result = NDBT_OK;
2722 int scan_flags = NdbScanOperation::SF_TupScan;
2728 while (ctx->isTestStopped() ==
false) {
2729 g_info << i <<
": ";
2730 if (hugoTrans.scanReadRecords(GETNDB(step), 0, 0, 0,
2731 lm, scan_flags) != 0){
2747 Ndb* pNdb = GETNDB(step);
2750 int numOuterIterations= 50;
2751 int numInnerIterations= 20;
2752 int numRecords= 200;
2756 for (
int outerIter=0; outerIter < numOuterIterations; outerIter++)
2760 int offset= (outerIter * numRecords);
2761 ndbout <<
"Outer Iter : " << outerIter
2762 <<
" " << offset <<
"-" << (offset + numRecords - 1) << endl;
2766 CHECK(trans.loadTableStartFrom(pNdb, offset, numRecords) == 0);
2769 for (
int iter=0; iter < numInnerIterations; iter++)
2774 CHECK(hugoOps.setTransaction(trans) == 0);
2777 CHECK(hugoOps.pkDeleteRecord(pNdb,
2782 CHECK(hugoOps.pkInsertRecord(pNdb,
2791 ndbout <<
"Execute failed, error is "
2792 << err.
code <<
" " << endl;
2795 NdbSleep_MilliSleep(50);
2802 hugoOps.setTransaction(NULL,
true);
2811 static volatile int aValue = 0;
2816 ndbout_c(
"callback received!");
2830 Ndb* pNdb = GETNDB(step);
2831 Ndb * pNdb2 =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
2838 CHECK(hugoOps1.startTransaction(pNdb) == 0);
2839 CHECK(hugoOps1.pkInsertRecord(pNdb, rowno) == 0);
2840 CHECK(hugoOps1.execute_NoCommit(pNdb) == 0);
2844 CHECK(hugoOps2.startTransaction(pNdb2) == 0);
2846 CHECK(hugoOps2.pkDeleteRecord(pNdb2, rowno) == 0);
2847 CHECK(hugoOps2.pkInsertRecord(pNdb2, rowno) == 0);
2854 CHECK(hugoOps1.execute_Commit(pNdb) == 0);
2855 ndbout_c(
"waiting for callback");
2859 NdbSleep_MilliSleep(100);
2861 CHECK(hugoOps2.execute_Rollback(pNdb2) == 0);
2876 if (otherConnection != NULL)
2878 ndbout <<
"Connection not null" << endl;
2882 char connectString[256];
2883 ctx->m_cluster_connection.get_connectstring(connectString,
2884 sizeof(connectString));
2888 if (otherConnection == NULL)
2890 ndbout <<
"Connection is null" << endl;
2894 int rc= otherConnection->
connect();
2898 ndbout <<
"Connect failed with rc " << rc << endl;
2907 ndbout <<
"Cluster connection was not ready" << endl;
2911 for (
int i=0; i < MAX_STEPS; i++)
2916 stepNdbs[
i]=
new Ndb(otherConnection,
2918 stepNdbs[
i]->
init();
2923 ndbout <<
"Ndb " << i <<
" was not ready" << endl;
2932 ctx->setProperty(ApiFailTestRun, 1);
2935 ctx->getPropertyWait(ApiFailTestsRunning,
2936 ctx->getProperty(ApiFailNumberPkSteps));
2938 if (ctx->isTestStopped())
2946 ctx->setProperty(ApiFailTestRun, (Uint32)0);
2959 ndbout <<
"Activating 8078" << endl;
2960 restarter.insertErrorInAllNodes(8078);
2971 int otherNodeId = otherConnection->node_id();
2973 ndbout <<
"Forcing disconnect of node "
2974 << otherNodeId << endl;
2977 int args[2]= {900, otherNodeId};
2979 restarter.dumpStateAllNodes( args, 2 );
2985 ctx->getPropertyWait(ApiFailTestsRunning, (Uint32)0);
2987 if (ctx->isTestStopped())
2993 restarter.insertErrorInAllNodes(0);
2996 for (
int i= 0; i < MAX_STEPS; i++)
3002 delete otherConnection;
3003 otherConnection= NULL;
3015 Uint32 iterations = 10;
3018 while (iterations --)
3020 rc= testApiFailReqImpl(ctx, step);
3022 if (rc == NDBT_FAILED)
3029 ctx->setProperty(ApiFailTestComplete, (Uint32) 1);
3041 while ((ctx->getProperty(ApiFailTestRun) == 0) &&
3042 (ctx->getProperty(ApiFailTestComplete) == 0) &&
3043 !ctx->isTestStopped())
3045 ctx->wait_timeout(500);
3048 if (ctx->isTestStopped() ||
3049 (ctx->getProperty(ApiFailTestComplete) != 0))
3055 ctx->incProperty(ApiFailTestsRunning);
3057 Ndb* otherNdb = stepNdbs[step->getStepNo()];
3059 Uint32 numRecords = ctx->getNumRecords();
3060 Uint32 batchSize = (1000 < numRecords)? 1000 : numRecords;
3062 ndbout <<
"Step number " << step->getStepNo()
3063 <<
" reading batches of " << batchSize
3064 <<
" rows " << endl;
3068 if (hugoOps.startTransaction(otherNdb) != 0)
3080 ndbout <<
"Failed to start transaction. Error : "
3085 for (Uint32 op = 0; op < batchSize; op++)
3087 if (hugoOps.pkReadRecord(otherNdb,
3090 ndbout <<
"Failed to define read of record number " << op << endl;
3097 if (hugoOps.execute_Commit(otherNdb) != 0)
3100 ndbout <<
"Execute failed with Error : "
3104 hugoOps.closeTransaction(otherNdb);
3106 if ((err.
code == 4002) ||
3107 (err.
code == 4010) ||
3108 (err.
code == 4025) ||
3121 hugoOps.closeTransaction(otherNdb);
3125 ctx->decProperty(ApiFailTestsRunning);
3133 int result = NDBT_OK;
3136 Uint32 numRecords = ctx->getNumRecords();
3138 Ndb* pNdb =
new Ndb(&ctx->m_cluster_connection,
"TEST_DB");
3140 ndbout <<
"pNdb == NULL" << endl;
3151 for (
int m = 1; m < 100; m++){
3152 Uint32 record = (100 - m) % numRecords;
3174 for(
int a = 0; a < numCols; a++){
3176 if(hugoOps.equalForAttr(pOp, a, record) != 0){
3185 int dupColNum = m % numCols;
3186 int numReads = m + 1;
3189 ndbout <<
"Reading record "
3190 << record <<
" Column "
3191 << dupColNum <<
" " << numReads
3192 <<
" times" << endl;
3196 if (recAttr == NULL) {
3199 result = NDBT_FAILED;
3203 first = (first == NULL) ? recAttr : first;
3206 if (result == NDBT_FAILED)
3209 if (pCon->
execute(Commit) != 0){
3212 result = NDBT_FAILED;
3220 if (err.
code == 880)
3226 ndbout <<
"Reading too much in one op, skipping..." << endl;
3230 ndbout <<
"Error at execute time : " << err.
code
3231 <<
":" << err.
message << endl;
3233 result = NDBT_FAILED;
3242 for (
int c= 0; c < (m+1); c++)
3244 if (hc.verifyRecAttr(record,
3248 ndbout <<
"Mismatch on record "
3249 << record <<
" column "
3250 << dupColNum <<
" read number "
3252 result = NDBT_FAILED;
3258 curr = curr->next();
3265 if (result == NDBT_FAILED)
3270 ndbout <<
"Error - extra RecAttr(s) found" << endl;
3271 result = NDBT_FAILED;
3293 Ndb* pNdb = GETNDB(step);
3296 if (pTrans1 == NULL)
3304 if (pTrans2 == NULL)
3328 hugoOps.setValues(pOp, 0, 0);
3346 hugoOps.equalForRow(pOp, 0);
3347 pOp->
getValue(NdbDictionary::Column::FRAGMENT);
3357 int res = pNdb->
pollNdb(1, 1000);
3358 ndbout_c(
"res: %u", res);
3360 NdbSleep_SecSleep(10);
3361 ndbout_c(
"pollNdb()");
3362 while (pNdb->
pollNdb() + res == 0);
3373 if (otherConnection != NULL)
3375 ndbout <<
"FragApiFail : Connection not null" << endl;
3379 char connectString[256];
3380 ctx->m_cluster_connection.get_connectstring(connectString,
3381 sizeof(connectString));
3385 if (otherConnection == NULL)
3387 ndbout <<
"FragApiFail : Connection is null" << endl;
3391 int rc= otherConnection->
connect();
3395 ndbout <<
"FragApiFail : Connect failed with rc " << rc << endl;
3404 ndbout <<
"FragApiFail : Cluster connection was not ready" << endl;
3408 for (
int i=0; i < MAX_STEPS; i++)
3413 stepNdbs[
i]=
new Ndb(otherConnection,
3415 stepNdbs[
i]->
init();
3420 ndbout <<
"FragApiFail : Ndb " << i <<
" was not ready" << endl;
3429 ctx->setProperty(ApiFailTestRun, 1);
3432 ctx->getPropertyWait(ApiFailTestsRunning,
3433 ctx->getProperty(ApiFailNumberPkSteps));
3435 if (ctx->isTestStopped())
3443 ctx->setProperty(ApiFailTestRun, (Uint32)0);
3453 int otherNodeId = otherConnection->node_id();
3455 ndbout <<
"FragApiFail : Forcing disconnect of node "
3456 << otherNodeId << endl;
3459 int args[2]= {900, otherNodeId};
3462 restarter.dumpStateAllNodes( args, 2 );
3467 ctx->getPropertyWait(ApiFailTestsRunning, (Uint32)0);
3469 if (ctx->isTestStopped())
3475 for (
int i= 0; i < MAX_STEPS; i++)
3481 delete otherConnection;
3482 otherConnection= NULL;
3493 Uint32 iterations = 10;
3496 while (iterations --)
3498 rc= testFragmentedApiFailImpl(ctx, step);
3500 if (rc == NDBT_FAILED)
3507 ctx->setProperty(ApiFailTestComplete, (Uint32) 1);
3527 const Uint32 PROG_WORDS= 16500;
3532 Uint32* buff=
new Uint32[ PROG_WORDS + 10 ];
3533 Uint32 stepNo = step->getStepNo();
3538 while ((ctx->getProperty(ApiFailTestRun) == 0) &&
3539 (ctx->getProperty(ApiFailTestComplete) == 0) &&
3540 !ctx->isTestStopped())
3542 ctx->wait_timeout(500);
3545 if (ctx->isTestStopped() ||
3546 (ctx->getProperty(ApiFailTestComplete) != 0))
3548 ndbout << stepNo <<
": Test stopped, exiting thread" << endl;
3554 ctx->incProperty(ApiFailTestsRunning);
3556 Ndb* otherNdb = stepNdbs[stepNo];
3564 ndbout << stepNo <<
": Failed to start transaction from Ndb object"
3584 CHECK(scan != NULL);
3590 buff, PROG_WORDS + 10);
3592 for (Uint32 w=0; w < PROG_WORDS; w++)
3593 CHECK(0 == prog.load_const_null(1));
3595 CHECK(0 == prog.interpret_exit_ok());
3596 CHECK(0 == prog.finalise());
3607 if ((execError != 0) &&
3608 (execError != 874) &&
3609 (execError != 4002))
3611 ndbout_c(
"%u incorrect error code: %u", __LINE__, execError);
3624 if (scanError.code != 874)
3631 ndbout << stepNo <<
": Scan failed due to node failure/disconnect" << endl;
3637 ndbout_c(
"%u incorrect error code: %u", __LINE__, execError);
3651 ndbout << stepNo <<
": Scan thread finished iteration" << endl;
3654 ctx->decProperty(ApiFailTestsRunning);
3666 ndbout <<
"LM_Exclusive";
3669 ndbout <<
"LM_Read";
3672 ndbout <<
"LM_SimpleRead";
3674 case NdbOperation::LM_CommittedRead:
3675 ndbout <<
"LM_CommittedRead";
3686 choice = rand() % 2;
3690 choice = rand() % 4;
3725 conflicting = (((rand() % 2) == 0) ?
3737 ndbout <<
"conflicting with ";
3739 ndbout <<
" using ";
3740 outputLockMode(conflicting);
3745 #define CHECKN(c, o, e) { if (!(c)) { \
3746 ndbout << "Failed on line " << __LINE__ << endl; \
3747 ndbout << (o)->getNdbError() << endl; \
3757 CHECKN(op != NULL, trans, NULL);
3759 CHECKN(op->
readTuple(lm) == 0, op, NULL);
3761 hugoOps->equalForRow(op, rowNum);
3782 CHECKN(trans != NULL, ndb,
false);
3789 CHECKN(readOp != NULL, trans,
false);
3791 int execRc = trans->
execute(Commit);
3800 ndbout <<
"Expected " << expectedRc <<
" at " << __LINE__ << endl;
3807 CHECKN(execRc == 0, trans,
false);
3822 return checkReadRc(hugoOps, ndb, pTab, lm, rowNum, 266);
3831 return checkReadRc(hugoOps, ndb, pTab, lm, rowNum, 0);
3846 const Uint32 iterations = 200;
3848 for (Uint32 iter = 0; iter < iterations; iter++)
3850 Uint32 rowNum = iter % ctx->getNumRecords();
3853 CHECKN(trans != NULL, GETNDB(step), NDBT_FAILED);
3855 ndbout <<
"First transaction operation using ";
3863 CHECKN(op != NULL, trans, NDBT_FAILED);
3865 if (op->getLockHandle() == NULL)
3867 if ((lm == NdbOperation::LM_CommittedRead) ||
3873 ndbout <<
"Definition error as expected, moving to next" << endl;
3877 ndbout <<
"Expected 4549, got :" << endl;
3880 ndbout <<
" at "<<__FILE__ <<
":" <<__LINE__ << endl;
3884 CHECKN(trans->
execute(NoCommit) == 0, trans, NDBT_FAILED);
3887 CHECKN(lh != NULL, op, NDBT_FAILED);
3893 CHECKN(trans2 != NULL, GETNDB(step), NDBT_FAILED);
3896 ndbout <<
"Second transaction operation using ";
3904 CHECKN(op2 != NULL, trans2, NDBT_FAILED);
3920 if (trans2->
execute(NoCommit) != 0)
3926 ndbout <<
" at "<<__FILE__ <<
":" <<__LINE__ << endl;
3932 if (!expectOk && !unknownCase)
3934 ndbout <<
"Expected deadlock but had success!" << endl;
3945 CHECKN(unlockOp != NULL, trans, NDBT_FAILED);
3947 CHECKN(trans->
execute(NoCommit) == 0, trans, NDBT_FAILED);
3953 CHECK(checkReadSucceeds(&hugoOps,
3958 ndbout <<
"Third transaction operation using LM_Exclusive succeeded" << endl;
3960 Uint32 choice = rand() % 3;
3964 ndbout <<
"Closing transaction" << endl;
3968 ndbout <<
"Releasing handle and closing transaction" << endl;
3969 CHECKN(trans->releaseLockHandle(lh) == 0, trans, NDBT_FAILED);
3973 ndbout <<
"Attempting to release the handle twice" << endl;
3974 CHECKN(trans->releaseLockHandle(lh) == 0, trans, NDBT_FAILED);
3976 if ((trans->releaseLockHandle(lh) != -1) ||
3979 ndbout <<
"Expected 4551, but got no error " << endl;
3980 ndbout <<
" at "<<__FILE__ <<
":" <<__LINE__ << endl;
4009 const Uint32 outerLoops = 2;
4010 const Uint32 iterations = 10;
4012 Ndb* ndb = GETNDB(step);
4018 Uint32 otherRowNum = ctx->getNumRecords() - 1;
4020 for (Uint32 outerLoop = 0; outerLoop < outerLoops; outerLoop ++)
4023 CHECKN(transA != NULL, ndb, NDBT_FAILED);
4026 ndbout <<
"TransA : Try to lock otherRowNum in mode ";
4028 switch (outerLoop % 2) {
4030 ndbout <<
"LM_Exclusive" << endl;
4034 ndbout <<
"LM_Read" << endl;
4039 NdbOperation* lockAOtherRowNum = defineReadAllColsOp(&hugoOps,
4044 CHECKN(lockAOtherRowNum != NULL, transA, NDBT_FAILED);
4046 CHECKN(transA->
execute(NoCommit) == 0, transA, NDBT_FAILED);
4048 ndbout <<
"TransA : Got initial lock on otherRowNum" << endl;
4050 for (Uint32 iter = 0; iter < iterations; iter++)
4052 Uint32 rowNum = iter % (ctx->getNumRecords() - 1);
4054 ndbout <<
" TransA : Try to lock rowNum with mode ";
4058 NdbOperation* lockARowNum = defineReadAllColsOp(&hugoOps,
4063 CHECKN(lockARowNum != NULL, transA, NDBT_FAILED);
4065 const NdbLockHandle* lockAHandle = lockARowNum->getLockHandle();
4066 CHECKN(lockAHandle != NULL, lockARowNum, NDBT_FAILED);
4068 CHECKN(transA->
execute(NoCommit) == 0, transA, NDBT_FAILED);
4070 ndbout <<
" TransA : Got lock on rowNum" << endl;
4075 ndbout <<
" TransB : Try to lock rowNum by ";
4077 CHECK(checkReadDeadlocks(&hugoOps,
4080 chooseConflictingLockMode(lockAMode),
4083 ndbout <<
" TransB : Failed to get lock on rowNum as expected" << endl;
4086 const NdbOperation* unlockOpA = transA->unlock(lockAHandle);
4087 CHECKN(unlockOpA != NULL, transA, NDBT_FAILED);
4089 CHECKN(transA->
execute(NoCommit) == 0, transA, NDBT_FAILED);
4091 ndbout <<
" TransA : Unlocked rowNum" << endl;
4095 CHECKN(transB != NULL, ndb, NDBT_FAILED);
4097 ndbout <<
" TransB : Try to lock rowNum with mode ";
4100 NdbOperation* tryLockBRowNum2 = defineReadAllColsOp(&hugoOps,
4105 CHECKN(tryLockBRowNum2 != NULL, transB, NDBT_FAILED);
4107 CHECKN(transB->
execute(NoCommit) == 0, transB, NDBT_FAILED);
4109 ndbout <<
" TransB : Got lock on rowNum" << endl;
4111 ndbout <<
" TransB : Try to lock other row by ";
4117 NdbOperation* tryLockBOtherRowNum = defineReadAllColsOp(&hugoOps,
4122 CHECKN(tryLockBOtherRowNum != NULL, transB, NDBT_FAILED);
4124 CHECKN(transB->
execute(NoCommit) == -1, transB, NDBT_FAILED);
4128 ndbout <<
"Error was expecting 266, but got " << transB->
getNdbError() << endl;
4129 ndbout <<
"At line " << __LINE__ << endl;
4133 ndbout <<
" TransB : Failed to get lock on otherRowNum as expected" << endl;
4172 const Uint32 MinLocks = 3;
4173 const Uint32 MaxLocksPerTrans = 20;
4174 Uint32 rowNum = ctx->getNumRecords() - 1;
4175 Uint32 numLocksInTransA = rand() % MaxLocksPerTrans;
4176 numLocksInTransA = (numLocksInTransA > MinLocks) ?
4177 numLocksInTransA : MinLocks;
4178 bool useExclusiveInA = ((rand() % 2) == 0);
4180 Uint32 numLocksInTransB = useExclusiveInA ? 0 :
4181 (rand() % MaxLocksPerTrans);
4183 Uint32 maxLocks = (numLocksInTransA > numLocksInTransB) ?
4184 numLocksInTransA : numLocksInTransB;
4186 ndbout <<
"NumLocksInTransA " << numLocksInTransA
4187 <<
" NumLocksInTransB " << numLocksInTransB
4188 <<
" useExclusiveInA " << useExclusiveInA
4199 Ndb* ndb = GETNDB(step);
4202 CHECKN(transA != NULL, ndb, NDBT_FAILED);
4205 CHECKN(transB != NULL, ndb, NDBT_FAILED);
4207 ndbout <<
"Locking phase" << endl << endl;
4208 for(Uint32 depth=0; depth < maxLocks; depth++)
4210 ndbout <<
"Depth " << depth << endl;
4213 if (depth < numLocksInTransA)
4215 ndbout <<
" TransA : Locking with mode ";
4216 if ((depth == 0) && useExclusiveInA)
4219 ndbout <<
"LM_Exclusive" << endl;
4221 else if (!useExclusiveInA)
4224 ndbout <<
"LM_Read" << endl;
4228 lmA = chooseLockMode(
true);
4236 CHECKN(lockA != NULL, transA, NDBT_FAILED);
4237 CHECKN(lockA->getLockHandle() != NULL, lockA, NDBT_FAILED);
4239 transAOps[ depth ] = lockA;
4241 CHECKN(transA->
execute(NoCommit) == 0, transA, NDBT_FAILED);
4242 ndbout <<
" TransA : Succeeded" << endl;
4246 if (depth < numLocksInTransB)
4248 ndbout <<
" TransB : Locking with mode LM_Read" << endl;
4255 CHECKN(lockB != NULL, transB, NDBT_FAILED);
4256 CHECKN(lockB->getLockHandle() != NULL, lockB, NDBT_FAILED);
4258 transBOps[ depth ] = lockB;
4260 CHECKN(transB->
execute(NoCommit) == 0, transB, NDBT_FAILED);
4261 ndbout <<
" TransB : Succeeded" << endl;
4265 ndbout <<
"Unlocking phase" << endl << endl;
4267 for(Uint32 depth = 0; depth < maxLocks; depth++)
4269 Uint32
level = maxLocks - depth - 1;
4271 ndbout <<
"Depth " << level << endl;
4273 ndbout <<
" TransC : Trying to lock row with lockmode ";
4275 if (useExclusiveInA)
4277 lmC = chooseLockMode(
true);
4281 ndbout <<
"LM_Exclusive" << endl;
4285 CHECK(checkReadDeadlocks(&hugoOps,
4291 ndbout <<
" TransC failed as expected" << endl;
4293 if (level < numLocksInTransB)
4296 CHECKN(lockHandleB != NULL, transBOps[ level ], NDBT_FAILED);
4298 const NdbOperation* unlockB = transB->unlock(lockHandleB);
4299 CHECKN(unlockB != NULL, transB, NDBT_FAILED);
4301 CHECKN(transB->
execute(NoCommit) == 0, transB, NDBT_FAILED);
4302 ndbout <<
" TransB unlock succeeded" << endl;
4305 if (level < numLocksInTransA)
4308 CHECKN(lockHandleA != NULL, transAOps[ level ], NDBT_FAILED);
4310 const NdbOperation* unlockA = transA->unlock(lockHandleA);
4311 CHECKN(unlockA != NULL, transA, NDBT_FAILED);
4313 CHECKN(transA->
execute(NoCommit) == 0, transA, NDBT_FAILED);
4314 ndbout <<
" TransA unlock succeeded" << endl;
4322 CHECK(checkReadSucceeds(&hugoOps,
4328 ndbout <<
"TransC LM_Exclusive lock succeeded" << endl;
4356 Ndb* ndb = GETNDB(step);
4358 const int iterations = 2;
4360 const int maxNumTakeovers = 15;
4362 Uint32 takeoverColIds[ maxNumTakeovers ];
4364 int numTakeovers = MIN(maxNumTakeovers, ctx->getNumRecords());
4365 int takeoverMod = ctx->getNumRecords() / numTakeovers;
4367 ndbout <<
"numTakeovers is " << numTakeovers
4368 <<
" takeoverMod is " << takeoverMod << endl;
4370 for (
int iter = 0; iter < iterations; iter++)
4372 ndbout <<
"Scanning table with lock mode : ";
4376 CHECKN(trans != NULL, ndb, NDBT_FAILED);
4380 CHECKN(scan != NULL, trans, NDBT_FAILED);
4382 Uint32 scanFlags = NdbScanOperation::SF_KeyInfo;
4384 CHECKN(scan->
readTuples(lmScan, scanFlags) == 0, scan, NDBT_FAILED);
4391 CHECKN(ra != NULL, scan, NDBT_FAILED);
4392 if (calc.isIdCol(c))
4394 CHECK(idColRecAttr == NULL);
4398 CHECK(idColRecAttr != NULL);
4400 CHECKN(trans->
execute(NoCommit) == 0, trans, NDBT_FAILED);
4403 int rowsTakenover = 0;
4406 if ((rowsTakenover < maxNumTakeovers) &&
4407 (0 == (rowsRead % takeoverMod)))
4412 Uint32 rowId = idColRecAttr->u_32_value();
4413 ndbout <<
" Taking over lock on result num " << rowsRead
4414 <<
" row (" << rowId <<
")" << endl;
4416 CHECKN(readTakeoverOp != NULL, scan, NDBT_FAILED);
4418 CHECKN(readTakeoverOp->getLockHandle() != NULL, readTakeoverOp, NDBT_FAILED);
4419 takeoverOps[ rowsTakenover ] = readTakeoverOp;
4420 takeoverColIds[ rowsTakenover ] = rowId;
4422 CHECKN(trans->
execute(NoCommit) == 0, trans, NDBT_FAILED);
4424 CHECKN(readTakeoverOp->getNdbError().code == 0, readTakeoverOp, NDBT_FAILED);
4449 ndbout <<
"Scan complete : rows read : " << rowsRead
4450 <<
" rows locked : " << rowsTakenover << endl;
4452 ndbout <<
"Now unlocking rows individually" << endl;
4453 for (
int lockedRows = 0; lockedRows < rowsTakenover; lockedRows ++)
4455 if (0 == (lockedRows % 3))
4457 ndbout <<
" First validating that lock holds on rowid "
4458 << takeoverColIds[ lockedRows ]
4461 CHECK(checkReadDeadlocks(&hugoOps,
4464 chooseConflictingLockMode(lmScan),
4465 takeoverColIds[ lockedRows ]));
4466 ndbout <<
" Lock is held" << endl;
4470 const NdbLockHandle* lockHandle = takeoverOps[ lockedRows ]->getLockHandle();
4471 CHECKN(lockHandle != NULL, takeoverOps[ lockedRows ], NDBT_FAILED);
4473 const NdbOperation* unlockOp = trans->unlock(lockHandle);
4474 CHECKN(unlockOp, trans, NDBT_FAILED);
4476 CHECKN(trans->
execute(NoCommit) == 0, trans, NDBT_FAILED);
4479 CHECK(checkReadSucceeds(&hugoOps,
4483 takeoverColIds[ lockedRows ]));
4484 ndbout <<
" Row " << takeoverColIds[ lockedRows ]
4485 <<
" unlocked successfully" << endl;
4491 ndbout <<
"Validating unlocking code with LM_Exclusive table scan" << endl;
4494 CHECKN(otherTrans != NULL, ndb, NDBT_FAILED);
4497 CHECKN(otherScan != NULL, otherTrans, NDBT_FAILED);
4504 CHECKN(ra != NULL, otherScan, NDBT_FAILED);
4507 CHECKN(otherTrans->
execute(NoCommit) == 0, trans, NDBT_FAILED);
4510 while (0 == (nextRc = otherScan->
nextResult(
true)))
4515 ndbout <<
"Final scan with lock did not complete successfully" << endl;
4517 ndbout <<
"at line " << __LINE__ << endl;
4522 otherTrans->
close();
4524 ndbout <<
"All locked rows unlocked" << endl;
4532 NDBT_TESTSUITE(testNdbApi);
4534 "Create Ndb objects until no more can be created\n"){
4535 INITIALIZER(runTestMaxNdb);
4537 TESTCASE(
"MaxTransactions",
4538 "Start transactions until no more can be created\n"){
4539 INITIALIZER(runTestMaxTransaction);
4541 TESTCASE(
"MaxOperations",
4542 "Get operations until no more can be created\n"){
4543 INITIALIZER(runLoadTable);
4544 INITIALIZER(runTestMaxOperations);
4545 FINALIZER(runClearTable);
4547 TESTCASE(
"MaxGetValue",
4548 "Call getValue loads of time\n"){
4549 INITIALIZER(runLoadTable);
4550 INITIALIZER(runTestGetValue);
4551 FINALIZER(runClearTable);
4553 TESTCASE(
"MaxEqual",
4554 "Call equal loads of time\n"){
4555 INITIALIZER(runTestEqual);
4557 TESTCASE(
"DeleteNdb",
4558 "Make sure that a deleted Ndb object is properly deleted\n"
4559 "and removed from transporter\n"){
4560 INITIALIZER(runLoadTable);
4561 INITIALIZER(runTestDeleteNdb);
4562 FINALIZER(runClearTable);
4564 TESTCASE(
"WaitUntilReady",
4565 "Make sure you get an error message when calling waitUntilReady\n"
4566 "without an init'ed Ndb\n"){
4567 INITIALIZER(runTestWaitUntilReady);
4569 TESTCASE(
"GetOperationNoTab",
4570 "Call getNdbOperation on a table that does not exist\n"){
4571 INITIALIZER(runGetNdbOperationNoTab);
4573 TESTCASE(
"BadColNameHandling",
4574 "Call methods with an invalid column name and check error handling\n"){
4575 INITIALIZER(runBadColNameHandling);
4577 TESTCASE(
"MissingOperation",
4578 "Missing operation request(insertTuple) should give an error code\n"){
4579 INITIALIZER(runMissingOperation);
4581 TESTCASE(
"GetValueInUpdate",
4582 "Test that it's not possible to perform getValue in an update\n"){
4583 INITIALIZER(runLoadTable);
4584 INITIALIZER(runGetValueInUpdate);
4585 FINALIZER(runClearTable);
4587 TESTCASE(
"UpdateWithoutKeys",
4588 "Test that it's not possible to perform update without setting\n"
4590 INITIALIZER(runLoadTable);
4591 INITIALIZER(runUpdateWithoutKeys);
4592 FINALIZER(runClearTable);
4594 TESTCASE(
"UpdateWithoutValues",
4595 "Test that it's not possible to perform update without setValues\n"){
4596 INITIALIZER(runLoadTable);
4597 INITIALIZER(runUpdateWithoutValues);
4598 FINALIZER(runClearTable);
4600 TESTCASE(
"NdbErrorOperation",
4601 "Test that NdbErrorOperation is properly set"){
4602 INITIALIZER(runCheckGetNdbErrorOperation);
4604 TESTCASE(
"ReadWithoutGetValue",
4605 "Test that it's possible to perform read wo/ getvalue's\n"){
4606 INITIALIZER(runLoadTable);
4607 INITIALIZER(runReadWithoutGetValue);
4608 FINALIZER(runClearTable);
4610 TESTCASE(
"Bug_11133",
4611 "Test ReadEx-Delete-Write\n"){
4612 INITIALIZER(runBug_11133);
4613 FINALIZER(runClearTable);
4615 TESTCASE(
"Bug_WritePartialIgnoreError",
4616 "Test WritePartialIgnoreError\n"){
4617 INITIALIZER(runBug_WritePartialIgnoreError);
4618 FINALIZER(runClearTable);
4620 TESTCASE(
"Scan_4006",
4621 "Check that getNdbScanOperation does not get 4006\n"){
4622 INITIALIZER(runLoadTable);
4623 INITIALIZER(runScan_4006);
4624 FINALIZER(runClearTable);
4626 TESTCASE(
"IgnoreError",
""){
4627 INITIALIZER(createPkIndex);
4628 STEP(runTestIgnoreError);
4629 FINALIZER(runClearTable);
4630 FINALIZER(createPkIndex_Drop);
4632 TESTCASE(
"CheckNdbObjectList",
4634 INITIALIZER(runCheckNdbObjectList);
4636 TESTCASE(
"ExecuteAsynch",
4637 "Check that executeAsync() works (BUG#27495)\n"){
4638 INITIALIZER(runTestExecuteAsynch);
4640 TESTCASE(
"Bug28443",
4642 INITIALIZER(runBug28443);
4644 TESTCASE(
"Bug37158",
4646 INITIALIZER(runBug37158);
4648 TESTCASE(
"SimpleReadAbortOnError",
4649 "Test behaviour of Simple reads with Abort On Error"){
4650 INITIALIZER(simpleReadAbortOnError);
4652 TESTCASE(
"NdbRecordPKAmbiguity",
4653 "Test behaviour of NdbRecord insert with ambig. pk values"){
4654 INITIALIZER(testNdbRecordPkAmbiguity);
4656 TESTCASE(
"NdbRecordPKUpdate",
4657 "Verify that primary key columns can be updated"){
4658 INITIALIZER(testNdbRecordPKUpdate);
4660 TESTCASE(
"NdbRecordCICharPKUpdate",
4661 "Verify that a case-insensitive char pk column can be updated"){
4662 INITIALIZER(testNdbRecordCICharPKUpdate);
4664 TESTCASE(
"NdbRecordRowLength",
4665 "Verify that the record row length calculation is correct") {
4666 INITIALIZER(testNdbRecordRowLength);
4668 TESTCASE(
"Bug44015",
4669 "Rollback insert followed by delete to get corruption") {
4671 STEPS(runScanReadUntilStopped, 10);
4673 TESTCASE(
"Bug44065_org",
4674 "Rollback no-change update on top of existing data") {
4675 INITIALIZER(runBug44065_org);
4677 TESTCASE(
"Bug44065",
4678 "Rollback no-change update on top of existing data") {
4679 INITIALIZER(runBug44065);
4681 TESTCASE(
"ApiFailReqBehaviour",
4682 "Check ApiFailReq cleanly marks Api disconnect") {
4684 TC_PROPERTY(ApiFailTestRun, (Uint32)0);
4685 TC_PROPERTY(ApiFailTestComplete, (Uint32)0);
4686 TC_PROPERTY(ApiFailTestsRunning, (Uint32)0);
4687 TC_PROPERTY(ApiFailNumberPkSteps, (Uint32)5);
4688 INITIALIZER(runLoadTable);
4691 STEP(runBulkPkReads);
4692 STEP(runBulkPkReads);
4693 STEP(runBulkPkReads);
4694 STEP(runBulkPkReads);
4695 STEP(runBulkPkReads);
4696 STEP(testApiFailReq);
4697 FINALIZER(runClearTable);
4699 TESTCASE(
"ReadColumnDuplicates",
4700 "Check NdbApi behaves ok when reading same column multiple times") {
4701 INITIALIZER(runLoadTable);
4702 STEP(runReadColumnDuplicates);
4703 FINALIZER(runClearTable);
4705 TESTCASE(
"Bug51775",
"")
4707 INITIALIZER(runBug51775);
4709 TESTCASE(
"FragmentedApiFailure",
4710 "Test in-assembly fragment cleanup code for API failure") {
4712 TC_PROPERTY(ApiFailTestRun, (Uint32)0);
4713 TC_PROPERTY(ApiFailTestComplete, (Uint32)0);
4714 TC_PROPERTY(ApiFailTestsRunning, (Uint32)0);
4715 TC_PROPERTY(ApiFailNumberPkSteps, (Uint32)5);
4718 STEP(runFragmentedScanOtherApi);
4719 STEP(runFragmentedScanOtherApi);
4720 STEP(runFragmentedScanOtherApi);
4721 STEP(runFragmentedScanOtherApi);
4722 STEP(runFragmentedScanOtherApi);
4723 STEP(testFragmentedApiFail);
4725 TESTCASE(
"UnlockBasic",
4726 "Check basic op unlock behaviour") {
4727 INITIALIZER(runLoadTable);
4728 STEP(runTestUnlockBasic);
4729 FINALIZER(runClearTable);
4731 TESTCASE(
"UnlockRepeat",
4732 "Check repeated lock/unlock behaviour") {
4733 INITIALIZER(runLoadTable);
4734 STEP(runTestUnlockRepeat);
4735 FINALIZER(runClearTable);
4737 TESTCASE(
"UnlockMulti",
4738 "Check unlock behaviour with multiple operations") {
4739 INITIALIZER(runLoadTable);
4740 STEP(runTestUnlockMulti);
4741 FINALIZER(runClearTable);
4743 TESTCASE(
"UnlockScan",
4744 "Check unlock behaviour with scan lock-takeover") {
4745 INITIALIZER(runLoadTable);
4746 STEP(runTestUnlockScan);
4747 FINALIZER(runClearTable);
4749 NDBT_TESTSUITE_END(testNdbApi);
4751 int main(
int argc,
const char** argv){
4753 NDBT_TESTSUITE_INSTANCE(testNdbApi);
4755 return testNdbApi.execute(argc, argv);