summaryrefslogtreecommitdiff
path: root/storage/ndb/tools/restore/restore_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'storage/ndb/tools/restore/restore_main.cpp')
-rw-r--r--storage/ndb/tools/restore/restore_main.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/storage/ndb/tools/restore/restore_main.cpp b/storage/ndb/tools/restore/restore_main.cpp
index 62fccfa3082..af7c751fb67 100644
--- a/storage/ndb/tools/restore/restore_main.cpp
+++ b/storage/ndb/tools/restore/restore_main.cpp
@@ -20,6 +20,7 @@
#include <ndb_limits.h>
#include <NdbTCP.h>
#include <NdbOut.hpp>
+#include <NDBT_ReturnCodes.h>
#include "consumer_restore.hpp"
#include "consumer_printer.hpp"
@@ -118,14 +119,14 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
if (ga_nodeId == 0)
{
printf("Error in --nodeid,-n setting, see --help\n");
- exit(1);
+ exit(NDBT_ProgramExit(NDBT_WRONGARGS));
}
break;
case 'b':
if (ga_backupId == 0)
{
printf("Error in --backupid,-b setting, see --help\n");
- exit(1);
+ exit(NDBT_ProgramExit(NDBT_WRONGARGS));
}
break;
}
@@ -138,7 +139,7 @@ readArguments(int *pargc, char*** pargv)
load_defaults("my",load_default_groups,pargc,pargv);
if (handle_options(pargc, pargv, my_long_options, get_one_option))
{
- exit(1);
+ exit(NDBT_ProgramExit(NDBT_WRONGARGS));
}
BackupPrinter* printer = new BackupPrinter();
@@ -229,6 +230,14 @@ free_data_callback()
}
const char * g_connect_string = 0;
+static void exitHandler(int code)
+{
+ NDBT_ProgramExit(code);
+ if (opt_core)
+ abort();
+ else
+ exit(code);
+}
int
main(int argc, char** argv)
@@ -237,7 +246,7 @@ main(int argc, char** argv)
if (!readArguments(&argc, &argv))
{
- return -1;
+ exitHandler(NDBT_FAILED);
}
g_connect_string = opt_connect_str;
@@ -249,7 +258,7 @@ main(int argc, char** argv)
if (!metaData.readHeader())
{
ndbout << "Failed to read " << metaData.getFilename() << endl << endl;
- return -1;
+ exitHandler(NDBT_FAILED);
}
const BackupFormat::FileHeader & tmp = metaData.getFileHeader();
@@ -267,20 +276,20 @@ main(int argc, char** argv)
if (res == 0)
{
ndbout_c("Restore: Failed to load content");
- return -1;
+ exitHandler(NDBT_FAILED);
}
if (metaData.getNoOfTables() == 0)
{
ndbout_c("Restore: The backup contains no tables ");
- return -1;
+ exitHandler(NDBT_FAILED);
}
if (!metaData.validateFooter())
{
ndbout_c("Restore: Failed to validate footer.");
- return -1;
+ exitHandler(NDBT_FAILED);
}
Uint32 i;
@@ -289,7 +298,7 @@ main(int argc, char** argv)
if (!g_consumers[i]->init())
{
clearConsumers();
- return -11;
+ exitHandler(NDBT_FAILED);
}
}
@@ -304,7 +313,7 @@ main(int argc, char** argv)
ndbout_c("Restore: Failed to restore table: %s. "
"Exiting...",
metaData[i]->getTableName());
- return -11;
+ exitHandler(NDBT_FAILED);
}
}
}
@@ -313,7 +322,7 @@ main(int argc, char** argv)
if (!g_consumers[i]->endOfTables())
{
ndbout_c("Restore: Failed while closing tables");
- return -11;
+ exitHandler(NDBT_FAILED);
}
if (ga_restore || ga_print)
@@ -326,7 +335,7 @@ main(int argc, char** argv)
if (!dataIter.readHeader())
{
ndbout << "Failed to read header of data file. Exiting..." ;
- return -11;
+ exitHandler(NDBT_FAILED);
}
@@ -344,12 +353,12 @@ main(int argc, char** argv)
{
ndbout_c("Restore: An error occured while restoring data. "
"Exiting...");
- return -1;
+ exitHandler(NDBT_FAILED);
}
if (!dataIter.validateFragmentFooter()) {
ndbout_c("Restore: Error validating fragment footer. "
"Exiting...");
- return -1;
+ exitHandler(NDBT_FAILED);
}
} // while (dataIter.readFragmentHeader(res))
@@ -357,7 +366,7 @@ main(int argc, char** argv)
{
err << "Restore: An error occured while restoring data. Exiting... "
<< "res=" << res << endl;
- return -1;
+ exitHandler(NDBT_FAILED);
}
@@ -373,7 +382,7 @@ main(int argc, char** argv)
if (!logIter.readHeader())
{
err << "Failed to read header of data file. Exiting..." << endl;
- return -1;
+ exitHandler(NDBT_FAILED);
}
const LogEntry * logEntry = 0;
@@ -387,7 +396,7 @@ main(int argc, char** argv)
{
err << "Restore: An restoring the data log. Exiting... res="
<< res << endl;
- return -1;
+ exitHandler(NDBT_FAILED);
}
logIter.validateFooter(); //not implemented
for (i= 0; i < g_consumers.size(); i++)
@@ -406,14 +415,14 @@ main(int argc, char** argv)
ndbout_c("Restore: Failed to finalize restore table: %s. "
"Exiting...",
metaData[i]->getTableName());
- return -11;
+ exitHandler(NDBT_FAILED);
}
}
}
}
}
clearConsumers();
- return 0;
+ return NDBT_ProgramExit(NDBT_OK);
} // main
template class Vector<BackupConsumer*>;