19 #include <NDBT_Test.hpp>
20 #include <HugoTransactions.hpp>
21 #include <UtilTransactions.hpp>
22 #include <NdbBackup.hpp>
26 #define CHECK(b) if (!(b)) { \
27 g_err << "ERR: "<< step->getName() \
28 << " failed on line " << __LINE__ << endl; \
29 result = NDBT_FAILED; \
37 strcpy(tabname, ctx->getTab()->
getName());
38 NdbBackup backup(GETNDB(step)->getNodeId());
39 backup.clearOldBackups();
45 int records = ctx->getNumRecords();
47 if (hugoTrans.loadTable(GETNDB(step), records) != 0){
53 bool testMaster =
true;
54 bool testSlave =
false;
73 NdbBackup backup(GETNDB(step)->getNodeId()+1);
77 if (restarter.getNumDbNodes() < 2){
82 if(restarter.waitClusterStarted(60) != 0){
83 g_err <<
"Cluster failed to start" << endl;
89 if (backup.NFMasterAsSlave(restarter) != NDBT_OK){
93 if (backup.NFMaster(restarter) != NDBT_OK){
98 if (backup.NFSlave(restarter) != NDBT_OK){
107 NdbBackup backup(GETNDB(step)->getNodeId()+1);
111 if (restarter.getNumDbNodes() < 2){
116 if(restarter.waitClusterStarted(60) != 0){
117 g_err <<
"Cluster failed to start" << endl;
123 if (backup.FailMasterAsSlave(restarter) != NDBT_OK){
127 if (backup.FailMaster(restarter) != NDBT_OK){
132 if (backup.FailSlave(restarter) != NDBT_OK){
141 NdbBackup backup(GETNDB(step)->getNodeId()+1);
142 unsigned backupId = 0;
144 if (backup.start(backupId) == -1){
147 ndbout <<
"Started backup " << backupId << endl;
148 ctx->setProperty(
"BackupId", backupId);
154 NdbBackup backup(GETNDB(step)->getNodeId()+1);
155 unsigned backupId = rand() % (MAX_BACKUPS);
157 if (backup.start(backupId) == -1){
160 ndbout <<
"Started backup " << backupId << endl;
161 ctx->setProperty(
"BackupId", backupId);
168 NdbBackup backup(GETNDB(step)->getNodeId()+1);
170 int loops = ctx->getNumLoops();
171 while(!ctx->isTestStopped() && loops--)
173 if (backup.start() == -1)
190 Ndb* pNdb= GETNDB(step);
193 const int tables = NDBT_Tables::getNumTables();
194 while(!ctx->isTestStopped())
196 const int tab_no = rand() % (tables);
199 name.
appfmt(
"-%d", step->getStepNo());
204 if (hugoTrans.loadTable(pNdb, 10000) != 0){
223 if (runDropTable(ctx, step) != 0)
226 if (restarter.restartAll(
false) != 0)
229 if (restarter.waitClusterStarted() != 0)
236 NdbBackup backup(GETNDB(step)->getNodeId()+1);
237 unsigned backupId = ctx->getProperty(
"BackupId");
239 ndbout <<
"Restoring backup " << backupId << endl;
241 if (backup.restore(backupId) == -1){
245 Ndb* pNdb = GETNDB(step);
259 int records = ctx->getNumRecords();
260 Ndb* pNdb = GETNDB(step);
261 int result = NDBT_OK;
274 CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
276 g_err <<
"count = " << count;
277 g_err <<
" records = " << records;
280 CHECK(count == records);
283 CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
291 int records = ctx->getNumRecords();
294 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
304 GETNDB(step)->getDictionary()->dropTable(tab->
getName());
309 #include "bank/Bank.hpp"
312 Bank bank(ctx->m_cluster_connection);
313 bool overWriteExisting =
true;
314 if (bank.createAndLoadBank(overWriteExisting) != NDBT_OK)
320 Bank bank(ctx->m_cluster_connection);
324 while (ctx->isTestStopped() ==
false) {
325 bank.performIncreaseTime(wait, yield);
331 Bank bank(ctx->m_cluster_connection);
335 while (ctx->isTestStopped() ==
false) {
336 bank.performTransactions(wait, yield);
342 Bank bank(ctx->m_cluster_connection);
344 int result = NDBT_OK;
346 while (ctx->isTestStopped() ==
false) {
347 if (bank.performMakeGLs(yield) != NDBT_OK){
348 ndbout <<
"bank.performMakeGLs FAILED" << endl;
349 result = NDBT_FAILED;
356 Bank bank(ctx->m_cluster_connection);
359 int result = NDBT_OK;
361 while (ctx->isTestStopped() ==
false) {
362 if (bank.performSumAccounts(wait, yield) != NDBT_OK){
363 ndbout <<
"bank.performSumAccounts FAILED" << endl;
364 result = NDBT_FAILED;
371 Bank bank(ctx->m_cluster_connection);
372 if (bank.dropBank() != NDBT_OK)
378 int loops = ctx->getNumLoops();
381 Ndb* pNdb = GETNDB(step);
382 NdbBackup backup(GETNDB(step)->getNodeId()+1);
383 unsigned minBackupId = ~0;
384 unsigned maxBackupId = 0;
385 unsigned backupId = 0;
386 int result = NDBT_OK;
388 while (l < loops && result != NDBT_FAILED){
391 result = NDBT_FAILED;
396 NdbSleep_SecSleep(maxSleep);
399 if (backup.start(backupId) != 0){
400 ndbout <<
"backup.start failed" << endl;
401 result = NDBT_FAILED;
404 ndbout <<
"Started backup " << backupId << endl;
407 if (backupId < minBackupId)
408 minBackupId = backupId;
410 if (backupId > maxBackupId)
411 maxBackupId = backupId;
413 ndbout <<
" maxBackupId = " << maxBackupId
414 <<
", minBackupId = " << minBackupId << endl;
415 ctx->setProperty(
"MinBackupId", minBackupId);
416 ctx->setProperty(
"MaxBackupId", maxBackupId);
428 NdbBackup backup(GETNDB(step)->getNodeId()+1);
429 unsigned minBackupId = ctx->getProperty(
"MinBackupId");
430 unsigned maxBackupId = ctx->getProperty(
"MaxBackupId");
431 unsigned backupId = minBackupId;
432 int result = NDBT_OK;
433 int errSumAccounts = 0;
434 int errValidateGL = 0;
436 ndbout <<
" maxBackupId = " << maxBackupId << endl;
437 ndbout <<
" minBackupId = " << minBackupId << endl;
439 while (backupId <= maxBackupId){
445 Bank bank(ctx->m_cluster_connection);
447 if (bank.dropBank() != NDBT_OK){
448 result = NDBT_FAILED;
454 ndbout <<
"Performing restart" << endl;
455 if (restarter.restartAll(
false) != 0)
458 if (restarter.waitClusterStarted() != 0)
461 ndbout <<
"Dropping " << tabname << endl;
465 ndbout <<
"Restoring backup " << backupId << endl;
466 if (backup.restore(backupId) == -1){
469 ndbout <<
"Backup " << backupId <<
" restored" << endl;
472 Bank bank(ctx->m_cluster_connection);
476 if (bank.performSumAccounts(wait, yield) != 0){
477 ndbout <<
"bank.performSumAccounts FAILED" << endl;
478 ndbout <<
" backupId = " << backupId << endl << endl;
479 result = NDBT_FAILED;
483 if (bank.performValidateAllGLs() != 0){
484 ndbout <<
"bank.performValidateAllGLs FAILED" << endl;
485 ndbout <<
" backupId = " << backupId << endl << endl;
486 result = NDBT_FAILED;
493 if (result != NDBT_OK){
494 ndbout <<
"Verification of backup failed" << endl
495 <<
" errValidateGL="<<errValidateGL<<endl
496 <<
" errSumAccounts="<<errSumAccounts<<endl << endl;
502 NdbBackup backup(GETNDB(step)->getNodeId()+1);
503 unsigned backupId = 0;
504 int undoError = 10041;
507 if(restarter.waitClusterStarted(60)){
508 g_err <<
"waitClusterStarted failed"<< endl;
512 if (restarter.insertErrorInAllNodes(undoError) != 0) {
513 g_err <<
"Error insert failed" << endl;
517 if (backup.start(backupId, 1, 0, 1) == -1){
520 ndbout <<
"Started backup " << backupId << endl;
521 ctx->setProperty(
"BackupId", backupId);
526 Ndb* pNdb= GETNDB(step);
528 int records = ctx->getNumRecords();
536 if(hugoTrans.pkUpdateRecords(pNdb, records) != 0) {
537 g_err <<
"Can't update all the records" << endl;
542 if(hugoTrans.pkDelRecords(pNdb, num*2) != 0) {
543 g_err <<
"Can't delete first 5 rows" << endl;
549 if (pTransaction == NULL) {
550 g_err <<
"Can't get transaction pointer" << endl;
553 if(hugoTrans.setTransaction(pTransaction) != 0) {
554 g_err <<
"Set transaction error" << endl;
558 if(hugoTrans.pkInsertRecord(pNdb, 0, num, 2) != 0) {
559 g_err <<
"pkInsertRecord error" << endl;
563 if(pTransaction->
execute(Commit ) != 0) {
564 g_err <<
"Can't commit transaction delete" << endl;
567 hugoTrans.closeTransaction(pNdb);
570 NdbBackup backup(GETNDB(step)->getNodeId()+1);
573 if(backup.startLogEvent() != 0) {
574 g_err <<
"Can't create log event" << endl;
577 NdbSleep_SecSleep(15);
580 if (backup.checkBackupStatus() == 2)
583 g_err <<
"Backup timeout" << endl;
586 NdbSleep_SecSleep(2);
594 int records = ctx->getNumRecords();
595 Ndb* pNdb = GETNDB(step);
602 GETNDB(step)->getDictionary()->getTable(ctx->getTab()->
getName());
605 g_err <<
" Can't find table" << endl;
613 if(utilTrans.selectCount(pNdb, 64, &count) != 0) {
614 g_err <<
"Can't get records count" << endl;
618 g_err <<
"count = " << count;
619 g_err <<
" records = " << records;
622 if (count != records) {
623 g_err <<
"The records count is not correct" << endl;
629 if (pTransaction == NULL) {
630 g_err <<
"Can't get transaction pointer" << endl;
633 if(hugoTrans.setTransaction(pTransaction) != 0) {
634 g_err <<
"Set transaction error" << endl;
639 g_err <<
"Can't read record" << endl;
642 if(hugoTrans.verifyUpdatesValue(0, records) != 0) {
643 g_err <<
"The records restored with undo log is not correct" << endl;
646 hugoTrans.closeTransaction(pNdb);
654 NdbBackup backup(GETNDB(step)->getNodeId()+1);
657 int node0 = res.getNode(NdbRestarter::NS_RANDOM);
658 res.insertErrorInNode(node0, 5057);
660 unsigned backupId = 0;
661 if (backup.start(backupId) == -1)
667 NDBT_TESTSUITE(testBackup);
668 TESTCASE(
"BackupOne",
669 "Test that backup and restore works on one table \n"
672 "3. Drop tables and restart \n"
674 "5. Verify count and content of table\n"){
675 INITIALIZER(clearOldBackups);
676 INITIALIZER(runLoadTable);
677 INITIALIZER(runBackupOne);
678 INITIALIZER(runDropTablesRestart);
679 INITIALIZER(runRestoreOne);
680 VERIFIER(runVerifyOne);
681 FINALIZER(runClearTable);
683 TESTCASE(
"BackupRandom",
684 "Test that backup n and restore works on one table \n"
687 "3. Drop tables and restart \n"
689 "5. Verify count and content of table\n"){
690 INITIALIZER(clearOldBackups);
691 INITIALIZER(runLoadTable);
692 INITIALIZER(runBackupRandom);
693 INITIALIZER(runDropTablesRestart);
694 INITIALIZER(runRestoreOne);
695 VERIFIER(runVerifyOne);
696 FINALIZER(runClearTable);
698 TESTCASE(
"BackupDDL",
699 "Test that backup and restore works on with DDL ongoing\n"
700 "1. Backups and DDL (create,drop,table.index)"){
701 INITIALIZER(clearOldBackups);
702 INITIALIZER(runLoadTable);
706 FINALIZER(runClearTable);
708 TESTCASE(
"BackupBank",
709 "Test that backup and restore works during transaction load\n"
710 " by backing up the bank"
712 "2a. Start bank and let it run\n"
713 "2b. Perform loop number of backups of the bank\n"
714 " when backups are finished tell bank to close\n"
715 "3. Restart ndb -i and reload each backup\n"
716 " let bank verify that the backup is consistent\n"
718 INITIALIZER(clearOldBackups);
719 INITIALIZER(runCreateBank);
721 STEP(runBankTransactions);
722 STEP(runBankTransactions);
723 STEP(runBankTransactions);
724 STEP(runBankTransactions);
725 STEP(runBankTransactions);
726 STEP(runBankTransactions);
727 STEP(runBankTransactions);
728 STEP(runBankTransactions);
729 STEP(runBankTransactions);
730 STEP(runBankTransactions);
734 VERIFIER(runRestoreBankAndVerify);
735 FINALIZER(runDropBank);
737 TESTCASE(
"BackupUndoLog",
738 "Test for backup happen at start time\n"
740 "2. Start backup with wait started\n"
741 "3. Insert, delete, update data during backup\n"
742 "4. Drop tables and restart \n"
744 "6. Verify records of table\n"
745 "7. Clear tables\n"){
746 INITIALIZER(runLoadTable);
747 INITIALIZER(runBackupUndoWaitStarted);
748 INITIALIZER(runChangeUndoDataDuringBackup);
749 INITIALIZER(runDropTablesRestart);
750 INITIALIZER(runRestoreOne);
751 VERIFIER(runVerifyUndoData);
752 FINALIZER(runClearTable);
755 "Test that backup behaves during node failiure\n"){
756 INITIALIZER(clearOldBackups);
757 INITIALIZER(setMaster);
761 TESTCASE(
"NFMasterAsSlave",
762 "Test that backup behaves during node failiure\n"){
763 INITIALIZER(clearOldBackups);
764 INITIALIZER(setMasterAsSlave);
769 "Test that backup behaves during node failiure\n"){
770 INITIALIZER(clearOldBackups);
771 INITIALIZER(setSlave);
775 TESTCASE(
"FailMaster",
776 "Test that backup behaves during node failiure\n"){
777 INITIALIZER(clearOldBackups);
778 INITIALIZER(setMaster);
782 TESTCASE(
"FailMasterAsSlave",
783 "Test that backup behaves during node failiure\n"){
784 INITIALIZER(clearOldBackups);
785 INITIALIZER(setMasterAsSlave);
789 TESTCASE(
"FailSlave",
790 "Test that backup behaves during node failiure\n"){
791 INITIALIZER(clearOldBackups);
792 INITIALIZER(setSlave);
796 TESTCASE(
"Bug57650",
"")
798 INITIALIZER(runBug57650);
800 NDBT_TESTSUITE_END(testBackup);
802 int main(
int argc,
const char** argv){
804 NDBT_TESTSUITE_INSTANCE(testBackup);
805 return testBackup.execute(argc, argv);