diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index 1fc0f55f91..8f3fbde2b4 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -187,7 +187,7 @@ void Application::setup() mLedgerDB->getDB()->setupCheckpointing(&mJobQueue); if (!theConfig.RUN_STANDALONE) - updateTables(); + updateTables(theConfig.LDB_IMPORT); if (theConfig.START_UP == Config::FRESH) { diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index 769c915690..2758c248e0 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -103,7 +103,7 @@ class Application volatile bool mShutdown; - void updateTables(); + void updateTables(bool); void startNewLedger(); bool loadOldLedger(const std::string&); diff --git a/src/cpp/ripple/Config.cpp b/src/cpp/ripple/Config.cpp index c9c3571548..ca532763d4 100644 --- a/src/cpp/ripple/Config.cpp +++ b/src/cpp/ripple/Config.cpp @@ -248,6 +248,7 @@ Config::Config() SSL_VERIFY = true; + LDB_IMPORT = false; RUN_STANDALONE = false; START_UP = NORMAL; } diff --git a/src/cpp/ripple/Config.h b/src/cpp/ripple/Config.h index 8cfae2bb56..eb47e2e2c0 100644 --- a/src/cpp/ripple/Config.h +++ b/src/cpp/ripple/Config.h @@ -88,6 +88,7 @@ public: boost::filesystem::path DATA_DIR; boost::filesystem::path DEBUG_LOGFILE; boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg. + bool LDB_IMPORT; // Import into LevelDB std::string VALIDATORS_SITE; // Where to find validators.txt on the Internet. std::string VALIDATORS_URI; // URI of validators.txt. diff --git a/src/cpp/ripple/UpdateTables.cpp b/src/cpp/ripple/UpdateTables.cpp index 240c8fd1f7..73e4c61f0c 100644 --- a/src/cpp/ripple/UpdateTables.cpp +++ b/src/cpp/ripple/UpdateTables.cpp @@ -101,9 +101,28 @@ static void addTxnSeqField() db->executeSQL("END TRANSACTION;"); } -void Application::updateTables() +void Application::updateTables(bool ldbImport) { // perform any needed table updates assert(schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "TransID")); assert(!schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "foobar")); addTxnSeqField(); + +#ifdef USE_LEVELDB + boost::filesystem::path hashPath = theConfig.DATA_DIR / "hashnode.db"; + if (boost::filesystem::exists(hashPath)) + { + if (theConfig.LDB_IMPORT) + { + Log(lsWARNING) << "Importing SQLite -> LevelDB"; + theApp->getHashedObjectStore().import(hashPath.string(), true); + Log(lsWARNING) << "Remove or remname the hashnode.db file"; + } + else + { + Log(lsWARNING) << "SQLite hashnode database exists. Please either remove or import"; + Log(lsWARNING) << "To import, start with the '--import' option. Otherwise, remove hashnode.db"; + exit(1); + } + } +#endif } diff --git a/src/cpp/ripple/main.cpp b/src/cpp/ripple/main.cpp index a112843cdb..49e8371a79 100644 --- a/src/cpp/ripple/main.cpp +++ b/src/cpp/ripple/main.cpp @@ -150,6 +150,9 @@ int main(int argc, char* argv[]) ("start", "Start from a fresh Ledger.") ("net", "Get the initial ledger from the network.") ("fg", "Run in the foreground.") +#ifdef USE_LEVELDB + ("import", "Import SQLite node DB into LevelDB.") +#endif ; // Interpret positional arguments as --parameters. @@ -240,6 +243,7 @@ int main(int argc, char* argv[]) } if (vm.count("start")) theConfig.START_UP = Config::FRESH; + if (vm.count("import")) theConfig.LDB_IMPORT = true; if (vm.count("ledger")) { theConfig.START_LEDGER = vm["ledger"].as();