19 #include "UtilTransactions.hpp"
21 #include <NdbScanFilter.hpp>
27 tab(_tab), idx(_idx), pTrans(0)
29 m_defaultClearMethod = 3;
32 UtilTransactions::UtilTransactions(
Ndb* ndb,
35 tab(* ndb->getDictionary()->getTable(name)),
36 idx(index ? ndb->getDictionary()->getIndex(index, name) : 0),
39 m_defaultClearMethod = 3;
42 #define RESTART_SCAN 99
44 #define RETURN_FAIL(err) return (err.code != 0 ? err.code : NDBT_FAILED)
47 UtilTransactions::clearTable(
Ndb* pNdb,
54 const int retryMax = 10;
60 int par = parallelism;
63 if (retryAttempt++ >= retryMax){
64 g_info <<
"ERROR: has retried this operation " << retryAttempt
65 <<
" times, failing!" << endl;
74 NdbSleep_MilliSleep(50);
80 pOp = getScanOperation(pTrans);
85 closeTransaction(pNdb);
86 NdbSleep_MilliSleep(50);
98 if(pTrans->
execute(NoCommit, AbortOnError) != 0){
102 closeTransaction(pNdb);
103 NdbSleep_MilliSleep(50);
115 }
while((check = pOp->
nextResult(
false)) == 0);
118 check = pTrans->
execute(Commit, AbortOnError);
126 closeTransaction(pNdb);
127 NdbSleep_MilliSleep(50);
138 closeTransaction(pNdb);
139 NdbSleep_MilliSleep(50);
145 closeTransaction(pNdb);
151 if(pTrans != 0) closeTransaction(pNdb);
153 return (err.
code != 0 ? err.
code : NDBT_FAILED);
157 UtilTransactions::clearTable(
Ndb* pNdb,
162 records, parallelism);
167 UtilTransactions::clearTable1(
Ndb* pNdb,
176 UtilTransactions::clearTable2(
Ndb* pNdb,
181 records, parallelism);
185 UtilTransactions::clearTable3(
Ndb* pNdb,
190 records, parallelism);
194 UtilTransactions::copyTableData(
Ndb* pNdb,
195 const char* destName){
198 int retryAttempt = 0;
199 const int retryMax = 10;
200 int insertedRows = 0;
201 int parallelism = 240;
208 if (retryAttempt >= retryMax){
209 g_info <<
"ERROR: has retried this operation " << retryAttempt
210 <<
" times, failing!" << endl;
216 if (pTrans == NULL) {
221 NdbSleep_MilliSleep(50);
232 closeTransaction(pNdb);
238 closeTransaction(pNdb);
244 if ((row.attributeStore(a) =
247 closeTransaction(pNdb);
252 check = pTrans->
execute(NoCommit, AbortOnError);
255 closeTransaction(pNdb);
263 if (addRowToInsert(pNdb, pTrans, row, destName) != 0){
264 closeTransaction(pNdb);
269 check = pTrans->
execute(Commit, AbortOnError);
274 closeTransaction(pNdb);
283 closeTransaction(pNdb);
284 NdbSleep_MilliSleep(50);
291 closeTransaction(pNdb);
295 closeTransaction(pNdb);
297 g_info << insertedRows <<
" rows copied" << endl;
305 UtilTransactions::addRowToInsert(
Ndb* pNdb,
308 const char *insertTabName){
314 if (pInsOp == NULL) {
342 UtilTransactions::scanReadRecords(
Ndb* pNdb,
350 int retryAttempt = 0;
351 const int retryMax = 100;
358 if (retryAttempt >= retryMax){
359 g_info <<
"ERROR: has retried this operation " << retryAttempt
360 <<
" times, failing!" << endl;
365 if (pTrans == NULL) {
370 NdbSleep_MilliSleep(50);
378 pOp = getScanOperation(pTrans);
381 closeTransaction(pNdb);
385 NdbSleep_MilliSleep(50);
395 closeTransaction(pNdb);
401 for (
int a = 0; a < noAttribs; a++){
403 g_info <<
"getValue(" << attrib_list[a] <<
")" << endl;
404 if ((row.attributeStore(attrib_list[a]) =
407 closeTransaction(pNdb);
414 check = pTrans->
execute(NoCommit, AbortOnError);
420 closeTransaction(pNdb);
421 NdbSleep_MilliSleep(50);
426 closeTransaction(pNdb);
446 closeTransaction(pNdb);
447 NdbSleep_MilliSleep(50);
452 closeTransaction(pNdb);
456 closeTransaction(pNdb);
457 g_info << rows <<
" rows have been read" << endl;
458 if (records != 0 && rows != records){
459 g_info <<
"Check expected number of records failed" << endl
460 <<
" expected=" << records <<
", " << endl
461 <<
" read=" << rows << endl;
471 UtilTransactions::selectCount(
Ndb* pNdb,
477 int retryAttempt = 0;
478 const int retryMax = 100;
483 if (retryAttempt >= retryMax){
484 g_info <<
"ERROR: has retried this operation " << retryAttempt
485 <<
" times, failing!" << endl;
494 NdbSleep_MilliSleep(50);
507 closeTransaction(pNdb);
510 NdbSleep_MilliSleep(50);
521 closeTransaction(pNdb);
528 sf.eq(2, (Uint32)30);
532 check = pTrans->
execute(NoCommit, AbortOnError);
536 closeTransaction(pNdb);
539 NdbSleep_MilliSleep(50);
558 closeTransaction(pNdb);
562 NdbSleep_MilliSleep(50);
567 closeTransaction(pNdb);
571 closeTransaction(pNdb);
573 if (count_rows != NULL){
583 UtilTransactions::verifyIndex(
Ndb* pNdb,
584 const char* indexName,
592 ndbout <<
" Index " << indexName <<
" does not exist!" << endl;
598 return verifyUniqueIndex(pNdb, pIndex, parallelism, transactional);
600 return verifyOrderedIndex(pNdb, pIndex, parallelism, transactional);
603 ndbout <<
"Unknown index type" << endl;
611 UtilTransactions::verifyUniqueIndex(
Ndb* pNdb,
623 if (scanAndCompareUniqueIndex(pNdb,
626 transactional) != NDBT_OK){
637 UtilTransactions::scanAndCompareUniqueIndex(
Ndb* pNdb,
642 int retryAttempt = 0;
643 const int retryMax = 100;
652 if (retryAttempt >= retryMax){
653 g_info <<
"ERROR: has retried this operation " << retryAttempt
654 <<
" times, failing!" << endl;
659 if (pTrans == NULL) {
664 NdbSleep_MilliSleep(50);
675 closeTransaction(pNdb);
679 NdbSleep_MilliSleep(50);
695 closeTransaction(pNdb);
701 if ((row.attributeStore(a) =
704 closeTransaction(pNdb);
709 check = pTrans->
execute(NoCommit, AbortOnError);
715 closeTransaction(pNdb);
716 NdbSleep_MilliSleep(50);
721 closeTransaction(pNdb);
734 if (readRowFromTableAndIndex(pNdb,
748 closeTransaction(pNdb);
749 NdbSleep_MilliSleep(50);
754 closeTransaction(pNdb);
763 closeTransaction(pNdb);
764 NdbSleep_MilliSleep(50);
769 closeTransaction(pNdb);
773 closeTransaction(pNdb);
780 UtilTransactions::readRowFromTableAndIndex(
Ndb* pNdb,
787 int retryAttempt = 0;
788 const int retryMax = 100;
793 int return_code= NDBT_FAILED;
798 const char * indexName = pIndex->
getName();
802 ndbout_c(
"retryAttempt %d", retryAttempt);
803 if (retryAttempt >= retryMax){
804 g_info <<
"ERROR: has retried this operation " << retryAttempt
805 <<
" times, failing!" << endl;
809 pTrans1 = pNdb->hupp(scanTrans);
810 if (pTrans1 == NULL) {
813 if (err.
code == 4006)
818 NdbSleep_MilliSleep(50);
824 return_code = NDBT_OK;
858 printf(
"%s = %d: ", attr->
getName(), row.attributeStore(a)->
aRef());
870 if((tabRow.attributeStore(a) =
890 bool null_found=
false;
894 if (row.attributeStore(col->
getName())->isNULL())
901 const char * tabName= tab.
getName();
936 if ( !row.attributeStore(col->
getName())->isNULL() ) {
938 row.attributeStore(col->
getName())->aRef()) != 0){
944 printf(
"%s = %d: ", col->
getName(), row.attributeStore(a)->
aRef());
958 pCheck= indexRow.attributeStore(a)=
974 check = pTrans1->
execute(Commit, AbortOnError);
981 NdbSleep_MilliSleep(50);
985 ndbout <<
"Error when comparing records - normal op" << endl;
987 ndbout <<
"row: " << row.c_str().
c_str() << endl;
999 ndbout <<
"Error when comparing records - index op next_result missing" << endl;
1000 ndbout <<
"row: " << row.c_str().
c_str() << endl;
1004 if (!(tabRow.c_str() == indexRow.c_str())){
1005 ndbout <<
"Error when comapring records" << endl;
1006 ndbout <<
" tabRow: \n" << tabRow.c_str().c_str() << endl;
1007 ndbout <<
" indexRow: \n" << indexRow.c_str().c_str() << endl;
1012 ndbout <<
"Error when comparing records - index op next_result to many" << endl;
1013 ndbout <<
"row: " << row.c_str().
c_str() << endl;
1018 return_code= NDBT_OK;
1030 UtilTransactions::verifyOrderedIndex(
Ndb* pNdb,
1033 bool transactional){
1035 int retryAttempt = 0;
1036 const int retryMax = 100;
1044 const char * indexName = pIndex->
getName();
1051 if (retryAttempt >= retryMax){
1052 g_info <<
"ERROR: has retried this operation " << retryAttempt
1053 <<
" times, failing!" << endl;
1058 if (pTrans == NULL) {
1063 NdbSleep_MilliSleep(50);
1074 closeTransaction(pNdb);
1080 closeTransaction(pNdb);
1084 if(get_values(pOp, scanRow))
1089 check = pTrans->
execute(NoCommit, AbortOnError);
1095 closeTransaction(pNdb);
1096 NdbSleep_MilliSleep(50);
1101 closeTransaction(pNdb);
1107 while(check == 0 && (eof = pOp->
nextResult()) == 0){
1110 bool null_found=
false;
1113 if (scanRow.attributeStore(col->
getName())->isNULL())
1124 if(equal(&tab, pk, scanRow) || get_values(pk, pkRow))
1135 if(get_values(iop, indexRow))
1137 if(equal(pIndex, iop, scanRow))
1146 check = pTrans->
execute(NoCommit, AbortOnError);
1150 if(scanRow.c_str() != pkRow.c_str()){
1151 g_err <<
"Error when comapring records" << endl;
1152 g_err <<
" scanRow: \n" << scanRow.c_str().c_str() << endl;
1153 g_err <<
" pkRow: \n" << pkRow.c_str().c_str() << endl;
1154 closeTransaction(pNdb);
1162 g_err <<
"Failed to find row using index: " << res << endl;
1164 closeTransaction(pNdb);
1168 if(scanRow.c_str() != indexRow.c_str()){
1169 g_err <<
"Error when comapring records" << endl;
1170 g_err <<
" scanRow: \n" << scanRow.c_str().c_str() << endl;
1171 g_err <<
" indexRow: \n" << indexRow.c_str().c_str() << endl;
1172 closeTransaction(pNdb);
1177 g_err <<
"Found extra row!!" << endl;
1178 g_err <<
" indexRow: \n" << indexRow.c_str().c_str() << endl;
1179 closeTransaction(pNdb);
1185 if (eof == -1 || check == -1) {
1192 closeTransaction(pNdb);
1193 NdbSleep_MilliSleep(50);
1199 closeTransaction(pNdb);
1203 closeTransaction(pNdb);
1230 src.attributeStore(col->
getName())->aRef()) != 0){
1320 #include <HugoOperations.hpp>
1323 UtilTransactions::closeTransaction(
Ndb* pNdb)
1325 if (pTrans != NULL){
1337 int return_code= 0, row_count= 0;
1338 int retryAttempt = 0, retryMax = 10;
1345 g_err <<
"Unable to lookup table: " << tab_name2
1356 if (retryAttempt++ >= retryMax){
1357 g_err <<
"ERROR: compare has retried this operation " << retryAttempt
1358 <<
" times, failing!" << endl;
1364 if (pTrans == NULL) {
1383 if ((row.attributeStore(a) =
1391 if( pTrans->
execute(NoCommit, AbortOnError) == -1 ) {
1403 if(cmp.startTransaction(pNdb) != NDBT_OK)
1408 int rowNo= calc.getIdValue(&row);
1409 if(cmp.pkReadRecord(pNdb, rowNo, 1) != NDBT_OK)
1414 if(cmp.execute_Commit(pNdb) != NDBT_OK ||
1420 if(row != cmp.get_row(0))
1422 g_err <<
"COMPARE FAILED" << endl;
1423 g_err << row << endl;
1424 g_err << cmp.get_row(0) << endl;
1428 cmp.closeTransaction(pNdb);
1429 }
while((eof = pOp->
nextResult(
false)) == 0);
1438 closeTransaction(pNdb);
1440 g_info << row_count <<
" rows compared" << endl;
1443 if(count.selectCount(pNdb, 0, &row_count2) != NDBT_OK)
1445 g_err <<
"Failed to count rows in tab_name2" << endl;
1449 g_info << row_count2 <<
" rows in tab_name2 - failed " << return_code
1451 return (row_count == row_count2 ? return_code : 1);
1456 g_err << err << endl;
1457 NdbSleep_MilliSleep(50);
1458 closeTransaction(pNdb);
1459 if(cmp.getTransaction())
1460 cmp.closeTransaction(pNdb);
1464 g_err <<
"ERROR" << endl;
1465 g_err << err << endl;
1470 closeTransaction(pNdb);