diff --git a/src/ripple/app/data/Database.cpp b/src/ripple/app/data/Database.cpp index ee3a9f3b12..6e5ab251b4 100644 --- a/src/ripple/app/data/Database.cpp +++ b/src/ripple/app/data/Database.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace ripple { diff --git a/src/ripple/app/data/DatabaseCon.cpp b/src/ripple/app/data/DatabaseCon.cpp index 0f77a3ef4b..844fb53339 100644 --- a/src/ripple/app/data/DatabaseCon.cpp +++ b/src/ripple/app/data/DatabaseCon.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace ripple { @@ -54,8 +55,8 @@ setup_DatabaseCon (Config const& c) { DatabaseCon::Setup setup; - if (c.nodeDatabase["online_delete"].isNotEmpty()) - setup.onlineDelete = c.nodeDatabase["online_delete"].getIntValue(); + auto const& sec = c.section (ConfigSection::nodeDatabase ()); + get_if_exists (sec, "online_delete", setup.onlineDelete); setup.startUp = c.START_UP; setup.standAlone = c.RUN_STANDALONE; setup.dataDir = c.legacy ("database_path"); diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index d5110906a6..d4520f9c33 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -337,7 +337,7 @@ public: m_logs.journal("TaggedCache")) , m_collectorManager (CollectorManager::New ( - getConfig().insightSettings, m_logs.journal("Collector"))) + getConfig().section (SECTION_INSIGHT), m_logs.journal("Collector"))) , family_ (*m_nodeStore, *m_collectorManager) @@ -1457,7 +1457,7 @@ static void addTxnSeqField () void ApplicationImp::updateTables () { - if (getConfig ().nodeDatabase.size () <= 0) + if (getConfig ().section (ConfigSection::nodeDatabase ()).empty ()) { WriteLog (lsFATAL, Application) << "The [node_db] configuration setting has been updated and must be set"; exitWithCode(1); @@ -1480,7 +1480,7 @@ void ApplicationImp::updateTables () std::unique_ptr source = NodeStore::Manager::instance().make_Database ("NodeStore.import", scheduler, deprecatedLogs().journal("NodeObject"), 0, - getConfig ().importNodeDatabase); + getConfig ()[ConfigSection::importNodeDatabase ()]); WriteLog (lsWARNING, NodeObject) << "Node import from '" << source->getName () << "' to '" diff --git a/src/ripple/app/main/CollectorManager.cpp b/src/ripple/app/main/CollectorManager.cpp index 5e5d2cfd34..664326cb86 100644 --- a/src/ripple/app/main/CollectorManager.cpp +++ b/src/ripple/app/main/CollectorManager.cpp @@ -30,17 +30,17 @@ public: beast::insight::Collector::ptr m_collector; std::unique_ptr m_groups; - CollectorManagerImp (beast::StringPairArray const& params, + CollectorManagerImp (Section const& params, beast::Journal journal) : m_journal (journal) { - std::string const& server (params ["server"].toStdString()); + std::string const& server = get (params, "server"); if (server == "statsd") { beast::IP::Endpoint const address (beast::IP::Endpoint::from_string ( - params ["address"].toStdString ())); - std::string const& prefix (params ["prefix"].toStdString ()); + get (params, "address"))); + std::string const& prefix (get (params, "prefix")); m_collector = beast::insight::StatsDCollector::New (address, prefix, journal); } @@ -73,7 +73,7 @@ CollectorManager::~CollectorManager () { } -CollectorManager* CollectorManager::New (beast::StringPairArray const& params, +CollectorManager* CollectorManager::New (Section const& params, beast::Journal journal) { return new CollectorManagerImp (params, journal); diff --git a/src/ripple/app/main/CollectorManager.h b/src/ripple/app/main/CollectorManager.h index c28b7697e2..a1cf4e711f 100644 --- a/src/ripple/app/main/CollectorManager.h +++ b/src/ripple/app/main/CollectorManager.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_APP_MAIN_COLLECTORMANAGER_H_INCLUDED #define RIPPLE_APP_MAIN_COLLECTORMANAGER_H_INCLUDED -#include +#include #include namespace ripple { @@ -29,7 +29,7 @@ namespace ripple { class CollectorManager { public: - static CollectorManager* New (beast::StringPairArray const& params, + static CollectorManager* New (Section const& params, beast::Journal journal); virtual ~CollectorManager () = 0; virtual beast::insight::Collector::ptr const& collector () = 0; diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 7fea087487..cb703613ef 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -163,9 +163,11 @@ static void setupConfigForUnitTests (Config* config) { - config->nodeDatabase = parseDelimitedKeyValueString ("type=memory|path=main"); - config->ephemeralNodeDatabase = beast::StringPairArray (); - config->importNodeDatabase = beast::StringPairArray (); + config->overwrite (ConfigSection::nodeDatabase (), "type", "memory"); + config->overwrite (ConfigSection::nodeDatabase (), "path", "main"); + + config->deprecatedClearSection (ConfigSection::tempNodeDatabase ()); + config->deprecatedClearSection (ConfigSection::importNodeDatabase ()); } static int runShutdownTests () diff --git a/src/ripple/app/misc/SHAMapStore.h b/src/ripple/app/misc/SHAMapStore.h index 796f3c87c3..5a1977ddaa 100644 --- a/src/ripple/app/misc/SHAMapStore.h +++ b/src/ripple/app/misc/SHAMapStore.h @@ -43,8 +43,8 @@ public: std::uint32_t deleteInterval = 0; bool advisoryDelete = false; std::uint32_t ledgerHistory = 0; - beast::StringPairArray nodeDatabase; - beast::StringPairArray ephemeralNodeDatabase; + Section nodeDatabase; + Section ephemeralNodeDatabase; std::string databasePath; std::uint32_t deleteBatch = 100; std::uint32_t backOff = 100; diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index 27b0f9768f..570a91f45e 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include // @@ -437,7 +438,7 @@ void SHAMapStoreImp::dbPaths() { boost::filesystem::path dbPath = - setup_.nodeDatabase["path"].toStdString(); + get(setup_.nodeDatabase, "path"); if (boost::filesystem::exists (dbPath)) { @@ -488,7 +489,7 @@ SHAMapStoreImp::dbPaths() << "remove the files matching " << stateDbPathName.string() << " and contents of the directory " - << setup_.nodeDatabase["path"].toStdString() + << get(setup_.nodeDatabase, "path") << std::endl; throw std::runtime_error ("state db error"); @@ -499,7 +500,7 @@ std::shared_ptr SHAMapStoreImp::makeBackendRotating (std::string path) { boost::filesystem::path newPath; - NodeStore::Parameters parameters = setup_.nodeDatabase; + Section parameters = setup_.nodeDatabase; if (path.size()) { @@ -507,7 +508,7 @@ SHAMapStoreImp::makeBackendRotating (std::string path) } else { - boost::filesystem::path p = parameters["path"].toStdString(); + boost::filesystem::path p = get(parameters, "path"); p /= dbPrefix_; p += ".%%%%"; newPath = boost::filesystem::unique_path (p); @@ -693,20 +694,20 @@ setup_SHAMapStore (Config const& c) { SHAMapStore::Setup setup; - if (c.nodeDatabase["online_delete"].isNotEmpty()) - setup.deleteInterval = c.nodeDatabase["online_delete"].getIntValue(); - if (c.nodeDatabase["advisory_delete"].isNotEmpty() && setup.deleteInterval) - setup.advisoryDelete = c.nodeDatabase["advisory_delete"].getIntValue(); + auto const& sec = c.section (ConfigSection::nodeDatabase ()); + get_if_exists (sec, "online_delete", setup.deleteInterval); + + if (setup.deleteInterval) + get_if_exists (sec, "advisory_delete", setup.advisoryDelete); + setup.ledgerHistory = c.LEDGER_HISTORY; - setup.nodeDatabase = c.nodeDatabase; - setup.ephemeralNodeDatabase = c.ephemeralNodeDatabase; + setup.nodeDatabase = c[ConfigSection::nodeDatabase ()]; + setup.ephemeralNodeDatabase = c[ConfigSection::tempNodeDatabase ()]; setup.databasePath = c.legacy("database_path"); - if (c.nodeDatabase["delete_batch"].isNotEmpty()) - setup.deleteBatch = c.nodeDatabase["delete_batch"].getIntValue(); - if (c.nodeDatabase["backOff"].isNotEmpty()) - setup.backOff = c.nodeDatabase["backOff"].getIntValue(); - if (c.nodeDatabase["age_threshold"].isNotEmpty()) - setup.ageThreshold = c.nodeDatabase["age_threshold"].getIntValue(); + + get_if_exists (sec, "delete_batch", setup.deleteBatch); + get_if_exists (sec, "backOff", setup.backOff); + get_if_exists (sec, "age_threshold", setup.ageThreshold); return setup; } diff --git a/src/ripple/app/node/SqliteFactory.cpp b/src/ripple/app/node/SqliteFactory.cpp index 2f85d60a48..c5f3e7ab56 100644 --- a/src/ripple/app/node/SqliteFactory.cpp +++ b/src/ripple/app/node/SqliteFactory.cpp @@ -249,11 +249,11 @@ public: } std::unique_ptr createInstance ( - size_t, NodeStore::Parameters const& keyValues, + size_t, Section const& keyValues, NodeStore::Scheduler&, beast::Journal) { return std::make_unique ( - keyValues ["path"].toStdString (), + get(keyValues, "path"), getConfig ().getSize(siHashNodeDBCache) * 1024); } }; diff --git a/src/ripple/basics/BasicConfig.h b/src/ripple/basics/BasicConfig.h index e8be781372..13068f522b 100644 --- a/src/ripple/basics/BasicConfig.h +++ b/src/ripple/basics/BasicConfig.h @@ -78,7 +78,7 @@ public: /** * Set the legacy value for this section. - */ + */ void legacy (std::string value) { @@ -182,6 +182,11 @@ public: overwrite (std::string const& section, std::string const& key, std::string const& value); + /** Remove all the key/value pairs from the section. + */ + void + deprecatedClearSection (std::string const& section); + /** * Set a value that is not a key/value pair. * @@ -232,7 +237,7 @@ set (T& target, std::string const& name, Section const& section) target = boost::lexical_cast (result.first); return true; } - catch(...) + catch (boost::bad_lexical_cast&) { } return false; @@ -256,7 +261,7 @@ set (T& target, T const& defaultValue, target = boost::lexical_cast (result.first); return true; } - catch(...) + catch (boost::bad_lexical_cast&) { target = defaultValue; } @@ -280,12 +285,46 @@ get (Section const& section, { return boost::lexical_cast (result.first); } - catch(...) + catch (boost::bad_lexical_cast&) { } return defaultValue; } +template +bool +get_if_exists (Section const& section, + std::string const& name, T& v) +{ + auto const result = section.find (name); + if (! result.second) + return false; + try + { + v = boost::lexical_cast (result.first); + return true; + } + catch (boost::bad_lexical_cast&) + { + } + return false; +} + +template <> +inline +bool +get_if_exists (Section const& section, + std::string const& name, bool& v) +{ + int intVal = 0; + if (get_if_exists (section, name, intVal)) + { + v = bool (intVal); + return true; + } + return false; +} + } // ripple #endif diff --git a/src/ripple/basics/StringUtilities.h b/src/ripple/basics/StringUtilities.h index a39e760eae..b325468731 100644 --- a/src/ripple/basics/StringUtilities.h +++ b/src/ripple/basics/StringUtilities.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -96,16 +95,6 @@ bool parseIpPort (std::string const& strSource, std::string& strIP, int& iPort); bool parseUrl (std::string const& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath); -/** Create a Parameters from a String. - - Parameter strings have the format: - - =['|'=] -*/ -extern beast::StringPairArray -parseDelimitedKeyValueString ( - beast::String s, beast::beast_wchar delimiter='|'); - } // ripple #endif diff --git a/src/ripple/basics/impl/BasicConfig.cpp b/src/ripple/basics/impl/BasicConfig.cpp index 36b24ca679..02ddb0ef31 100644 --- a/src/ripple/basics/impl/BasicConfig.cpp +++ b/src/ripple/basics/impl/BasicConfig.cpp @@ -115,6 +115,14 @@ BasicConfig::overwrite (std::string const& section, std::string const& key, result.first->second.set (key, value); } +void +BasicConfig::deprecatedClearSection (std::string const& section) +{ + auto i = map_.find(section); + if (i != map_.end()) + i->second = Section(section); +} + void BasicConfig::legacy(std::string const& section, std::string value) { diff --git a/src/ripple/basics/impl/StringUtilities.cpp b/src/ripple/basics/impl/StringUtilities.cpp index 76af616f7d..7a4cd4d541 100644 --- a/src/ripple/basics/impl/StringUtilities.cpp +++ b/src/ripple/basics/impl/StringUtilities.cpp @@ -221,45 +221,4 @@ bool parseUrl (std::string const& strUrl, std::string& strScheme, std::string& s return bMatch; } - -beast::StringPairArray parseDelimitedKeyValueString (beast::String parameters, - beast::beast_wchar delimiter) -{ - beast::StringPairArray keyValues; - - while (parameters.isNotEmpty ()) - { - beast::String pair; - - { - int const delimiterPos = parameters.indexOfChar (delimiter); - - if (delimiterPos != -1) - { - pair = parameters.substring (0, delimiterPos); - - parameters = parameters.substring (delimiterPos + 1); - } - else - { - pair = parameters; - - parameters = beast::String::empty; - } - } - - int const equalPos = pair.indexOfChar ('='); - - if (equalPos != -1) - { - beast::String const key = pair.substring (0, equalPos); - beast::String const value = pair.substring (equalPos + 1, pair.length ()); - - keyValues.set (key, value); - } - } - - return keyValues; -} - } // ripple diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 6f678d8129..8f207846c4 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -52,14 +51,6 @@ countSectionEntries (IniFileSections& secSource, std::string const& strSection); IniFileSections::mapped_type* getIniFileSection (IniFileSections& secSource, std::string const& strSection); -/** Parse a section of lines as a key/value array. - Each line is in the form =. - Spaces are considered part of the key and value. -*/ -// DEPRECATED -beast::StringPairArray -parseKeyValueSection (IniFileSections& secSource, std::string const& strSection); - //------------------------------------------------------------------------------ enum SizedItemName @@ -164,40 +155,7 @@ public: //-------------------------------------------------------------------------- - /** Parameters for the insight collection module */ - beast::StringPairArray insightSettings; - - /** Parameters for the main NodeStore database. - - This is 1 or more strings of the form = - The 'type' and 'path' keys are required, see rippled-example.cfg - - @see Database - */ - beast::StringPairArray nodeDatabase; - - /** Parameters for the ephemeral NodeStore database. - - This is an auxiliary database for the NodeStore, usually placed - on a separate faster volume. However, the volume data may not persist - between launches. Use of the ephemeral database is optional. - - The format is the same as that for @ref nodeDatabase - - @see Database - */ - beast::StringPairArray ephemeralNodeDatabase; - - /** Parameters for importing an old database in to the current node database. - If this is not empty, then it specifies the key/value parameters for - another node database from which to import all data into the current - node database specified by @ref nodeDatabase. - The format of this string is in the form: - '='['|''='value] - @see parseDelimitedKeyValueString - */ bool doImport; - beast::StringPairArray importNodeDatabase; // // diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 69c53ea547..188e1f911e 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -147,36 +147,6 @@ bool getSingleSection (IniFileSections& secSource, return bSingle; } -beast::StringPairArray -parseKeyValueSection (IniFileSections& secSource, std::string const& strSection) -{ - beast::StringPairArray result; - - typedef IniFileSections::mapped_type Entries; - - Entries* const entries = getIniFileSection (secSource, strSection); - - if (entries != nullptr) - { - for (Entries::const_iterator iter = entries->begin (); - iter != entries->end (); ++iter) - { - std::string const line (iter->c_str ()); - - int const equalPos = line.find ('='); - - if (equalPos != std::string::npos) - { - result.set ( - line.substr (0, equalPos), - line.substr (equalPos + 1)); - } - } - } - - return result; -} - /** Parses a set of strings into IP::Endpoint Strings which fail to parse are not included in the output. If a stream is provided, human readable diagnostic error messages are written for each @@ -469,17 +439,6 @@ void Config::loadFromString (std::string const& fileContents) parsedAddresses.cbegin (), parsedAddresses.cend ()); } - insightSettings = parseKeyValueSection (secConfig, SECTION_INSIGHT); - - nodeDatabase = parseKeyValueSection ( - secConfig, ConfigSection::nodeDatabase ()); - - ephemeralNodeDatabase = parseKeyValueSection ( - secConfig, ConfigSection::tempNodeDatabase ()); - - importNodeDatabase = parseKeyValueSection ( - secConfig, ConfigSection::importNodeDatabase ()); - if (getSingleSection (secConfig, SECTION_NODE_SIZE, strTemp)) { if (strTemp == "tiny") diff --git a/src/ripple/nodestore/Factory.h b/src/ripple/nodestore/Factory.h index 53e12ba9a3..ca6614dd59 100644 --- a/src/ripple/nodestore/Factory.h +++ b/src/ripple/nodestore/Factory.h @@ -48,7 +48,7 @@ public: */ virtual std::unique_ptr - createInstance (size_t keyBytes, Parameters const& parameters, + createInstance (size_t keyBytes, Section const& parameters, Scheduler& scheduler, beast::Journal journal) = 0; }; diff --git a/src/ripple/nodestore/Manager.h b/src/ripple/nodestore/Manager.h index 0367799f72..d6fb6ab55e 100644 --- a/src/ripple/nodestore/Manager.h +++ b/src/ripple/nodestore/Manager.h @@ -56,7 +56,7 @@ public: /** Create a backend. */ virtual std::unique_ptr - make_Backend (Parameters const& parameters, + make_Backend (Section const& parameters, Scheduler& scheduler, beast::Journal journal) = 0; /** Construct a NodeStore database. @@ -87,8 +87,8 @@ public: std::unique_ptr make_Database (std::string const& name, Scheduler& scheduler, beast::Journal journal, int readThreads, - Parameters const& backendParameters, - Parameters fastBackendParameters = Parameters()) = 0; + Section const& backendParameters, + Section fastBackendParameters = Section()) = 0; virtual std::unique_ptr diff --git a/src/ripple/nodestore/Types.h b/src/ripple/nodestore/Types.h index 73c5bbed19..1b9fa68187 100644 --- a/src/ripple/nodestore/Types.h +++ b/src/ripple/nodestore/Types.h @@ -21,7 +21,7 @@ #define RIPPLE_NODESTORE_TYPES_H_INCLUDED #include -#include +#include #include namespace ripple { @@ -48,11 +48,6 @@ enum Status /** A batch of NodeObjects to write at once. */ typedef std::vector Batch; - -/** A list of key/value parameter pairs passed to the backend. */ -// VFALCO TODO Use std::string, pair, vector -typedef beast::StringPairArray Parameters; - } } diff --git a/src/ripple/nodestore/backend/MemoryFactory.cpp b/src/ripple/nodestore/backend/MemoryFactory.cpp index 14525d7a65..2e1e5e2b22 100644 --- a/src/ripple/nodestore/backend/MemoryFactory.cpp +++ b/src/ripple/nodestore/backend/MemoryFactory.cpp @@ -51,7 +51,7 @@ public: std::unique_ptr createInstance ( size_t keyBytes, - Parameters const& keyValues, + Section const& keyValues, Scheduler& scheduler, beast::Journal journal); @@ -82,9 +82,9 @@ private: MemoryDB* db_; public: - MemoryBackend (size_t keyBytes, Parameters const& keyValues, + MemoryBackend (size_t keyBytes, Section const& keyValues, Scheduler& scheduler, beast::Journal journal) - : name_ (keyValues ["path"].toStdString ()) + : name_ (get(keyValues, "path")) , journal_ (journal) { if (name_.empty()) @@ -187,7 +187,7 @@ MemoryFactory::getName() const std::unique_ptr MemoryFactory::createInstance ( size_t keyBytes, - Parameters const& keyValues, + Section const& keyValues, Scheduler& scheduler, beast::Journal journal) { diff --git a/src/ripple/nodestore/backend/NuDBFactory.cpp b/src/ripple/nodestore/backend/NuDBFactory.cpp index e6272b2b43..e0ab376e5d 100644 --- a/src/ripple/nodestore/backend/NuDBFactory.cpp +++ b/src/ripple/nodestore/backend/NuDBFactory.cpp @@ -62,11 +62,11 @@ public: std::atomic deletePath_; Scheduler& scheduler_; - NuDBBackend (int keyBytes, Parameters const& keyValues, + NuDBBackend (int keyBytes, Section const& keyValues, Scheduler& scheduler, beast::Journal journal) : journal_ (journal) , keyBytes_ (keyBytes) - , name_ (keyValues ["path"].toStdString ()) + , name_ (get(keyValues, "path")) , deletePath_(false) , scheduler_ (scheduler) { @@ -259,7 +259,7 @@ public: std::unique_ptr createInstance ( size_t keyBytes, - Parameters const& keyValues, + Section const& keyValues, Scheduler& scheduler, beast::Journal journal) { diff --git a/src/ripple/nodestore/backend/NullFactory.cpp b/src/ripple/nodestore/backend/NullFactory.cpp index b2571afcd2..95a0f6d9a1 100644 --- a/src/ripple/nodestore/backend/NullFactory.cpp +++ b/src/ripple/nodestore/backend/NullFactory.cpp @@ -111,7 +111,7 @@ public: std::unique_ptr createInstance ( size_t, - Parameters const&, + Section const&, Scheduler&, beast::Journal) { return std::make_unique (); diff --git a/src/ripple/nodestore/backend/RocksDBFactory.cpp b/src/ripple/nodestore/backend/RocksDBFactory.cpp index 5f612c3bdc..f876a69675 100644 --- a/src/ripple/nodestore/backend/RocksDBFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBFactory.cpp @@ -99,16 +99,15 @@ public: std::string m_name; std::unique_ptr m_db; - RocksDBBackend (int keyBytes, Parameters const& keyValues, + RocksDBBackend (int keyBytes, Section const& keyValues, Scheduler& scheduler, beast::Journal journal, RocksDBEnv* env) : m_deletePath (false) , m_journal (journal) , m_keyBytes (keyBytes) , m_scheduler (scheduler) , m_batch (*this, scheduler) - , m_name (keyValues ["path"].toStdString ()) { - if (m_name.empty()) + if (!get_if_exists(keyValues, "path", m_name)) throw std::runtime_error ("Missing path in RocksDBFactory backend"); rocksdb::Options options; @@ -116,51 +115,45 @@ public: options.create_if_missing = true; options.env = env; - if (keyValues["cache_mb"].isEmpty()) + if (!keyValues.exists ("cache_mb")) { table_options.block_cache = rocksdb::NewLRUCache (getConfig ().getSize (siHashNodeDBCache) * 1024 * 1024); } else { - table_options.block_cache = rocksdb::NewLRUCache (keyValues["cache_mb"].getIntValue() * 1024L * 1024L); + table_options.block_cache = rocksdb::NewLRUCache (get(keyValues, "cache_mb") * 1024L * 1024L); } - if (keyValues["filter_bits"].isEmpty()) + if (!keyValues.exists ("filter_bits")) { if (getConfig ().NODE_SIZE >= 2) table_options.filter_policy.reset (rocksdb::NewBloomFilterPolicy (10)); } - else if (keyValues["filter_bits"].getIntValue() != 0) + else if (auto const v = get(keyValues, "filter_bits")) { - table_options.filter_policy.reset (rocksdb::NewBloomFilterPolicy (keyValues["filter_bits"].getIntValue())); + table_options.filter_policy.reset (rocksdb::NewBloomFilterPolicy (v)); } - if (! keyValues["open_files"].isEmpty()) - { - options.max_open_files = keyValues["open_files"].getIntValue(); - } + get_if_exists (keyValues, "open_files", options.max_open_files); - if (! keyValues["file_size_mb"].isEmpty()) + if (keyValues.exists ("file_size_mb")) { - options.target_file_size_base = 1024 * 1024 * keyValues["file_size_mb"].getIntValue(); + options.target_file_size_base = 1024 * 1024 * get(keyValues,"file_size_mb"); options.max_bytes_for_level_base = 5 * options.target_file_size_base; options.write_buffer_size = 2 * options.target_file_size_base; } - if (! keyValues["file_size_mult"].isEmpty()) - { - options.target_file_size_multiplier = keyValues["file_size_mult"].getIntValue(); - } + get_if_exists (keyValues, "file_size_mult", options.target_file_size_multiplier); - if (! keyValues["bg_threads"].isEmpty()) + if (keyValues.exists ("bg_threads")) { options.env->SetBackgroundThreads - (keyValues["bg_threads"].getIntValue(), rocksdb::Env::LOW); + (get(keyValues, "bg_threads"), rocksdb::Env::LOW); } - if (! keyValues["high_threads"].isEmpty()) + if (keyValues.exists ("high_threads")) { - auto const highThreads = keyValues["high_threads"].getIntValue(); + auto const highThreads = get(keyValues, "high_threads"); options.env->SetBackgroundThreads (highThreads, rocksdb::Env::HIGH); // If we have high-priority threads, presumably we want to @@ -169,28 +162,21 @@ public: options.max_background_flushes = highThreads; } - if (! keyValues["compression"].isEmpty ()) + if (keyValues.exists ("compression") && + (get(keyValues, "compression") == 0)) { - if (keyValues["compression"].getIntValue () == 0) - { - options.compression = rocksdb::kNoCompression; - } + options.compression = rocksdb::kNoCompression; } - if (! keyValues["block_size"].isEmpty ()) - { - table_options.block_size = keyValues["block_size"].getIntValue (); - } + get_if_exists (keyValues, "block_size", table_options.block_size); - if (! keyValues["universal_compaction"].isEmpty ()) + if (keyValues.exists ("universal_compaction") && + (get(keyValues, "universal_compaction") != 0)) { - if (keyValues["universal_compaction"].getIntValue () != 0) - { - options.compaction_style = rocksdb:: kCompactionStyleUniversal; - options.min_write_buffer_number_to_merge = 2; - options.max_write_buffer_number = 6; - options.write_buffer_size = 6 * options.target_file_size_base; - } + options.compaction_style = rocksdb::kCompactionStyleUniversal; + options.min_write_buffer_number_to_merge = 2; + options.max_write_buffer_number = 6; + options.write_buffer_size = 6 * options.target_file_size_base; } options.table_factory.reset(NewBlockBasedTableFactory(table_options)); @@ -400,7 +386,7 @@ public: std::unique_ptr createInstance ( size_t keyBytes, - Parameters const& keyValues, + Section const& keyValues, Scheduler& scheduler, beast::Journal journal) { diff --git a/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp b/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp index d60f07dc13..78873d926e 100644 --- a/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp @@ -95,12 +95,12 @@ public: std::string m_name; std::unique_ptr m_db; - RocksDBQuickBackend (int keyBytes, Parameters const& keyValues, + RocksDBQuickBackend (int keyBytes, Section const& keyValues, Scheduler& scheduler, beast::Journal journal, RocksDBQuickEnv* env) : m_deletePath (false) , m_journal (journal) , m_keyBytes (keyBytes) - , m_name (keyValues ["path"].toStdString ()) + , m_name (get(keyValues, "path")) { if (m_name.empty()) throw std::runtime_error ("Missing path in RocksDBQuickFactory backend"); @@ -110,14 +110,9 @@ public: std::string style("level"); std::uint64_t threads=4; - if (!keyValues["budget"].isEmpty()) - budget = keyValues["budget"].getIntValue(); - - if (!keyValues["style"].isEmpty()) - style = keyValues["style"].toStdString(); - - if (!keyValues["threads"].isEmpty()) - threads = keyValues["threads"].getIntValue(); + get_if_exists (keyValues, "budget", budget); + get_if_exists (keyValues, "style", style); + get_if_exists (keyValues, "threads", threads); // Set options @@ -163,18 +158,11 @@ public: // options.memtable_factory.reset( // rocksdb::NewHashCuckooRepFactory(options.write_buffer_size)); - if (! keyValues["open_files"].isEmpty()) - { - options.max_open_files = keyValues["open_files"].getIntValue(); - } - - if (! keyValues["compression"].isEmpty ()) - { - if (keyValues["compression"].getIntValue () == 0) - { - options.compression = rocksdb::kNoCompression; - } - } + get_if_exists (keyValues, "open_files", options.max_open_files); + + if (keyValues.exists ("compression") && + (get(keyValues, "compression") == 0)) + options.compression = rocksdb::kNoCompression; rocksdb::DB* db = nullptr; @@ -385,7 +373,7 @@ public: std::unique_ptr createInstance ( size_t keyBytes, - Parameters const& keyValues, + Section const& keyValues, Scheduler& scheduler, beast::Journal journal) { diff --git a/src/ripple/nodestore/impl/ManagerImp.cpp b/src/ripple/nodestore/impl/ManagerImp.cpp index a985f7a34c..028af98455 100644 --- a/src/ripple/nodestore/impl/ManagerImp.cpp +++ b/src/ripple/nodestore/impl/ManagerImp.cpp @@ -55,13 +55,13 @@ ManagerImp::~ManagerImp() std::unique_ptr ManagerImp::make_Backend ( - Parameters const& parameters, + Section const& parameters, Scheduler& scheduler, beast::Journal journal) { std::unique_ptr backend; - std::string const type (parameters ["type"].toStdString ()); + std::string const type (get(parameters, "type")); if (! type.empty ()) { @@ -91,8 +91,8 @@ ManagerImp::make_Database ( Scheduler& scheduler, beast::Journal journal, int readThreads, - Parameters const& backendParameters, - Parameters fastBackendParameters) + Section const& backendParameters, + Section fastBackendParameters) { std::unique_ptr backend (make_Backend ( backendParameters, scheduler, journal)); @@ -167,11 +167,8 @@ std::unique_ptr make_Backend (Section const& config, Scheduler& scheduler, beast::Journal journal) { - beast::StringPairArray v; - for (auto const& _ : config) - v.set (_.first, _.second); return Manager::instance().make_Backend ( - v, scheduler, journal); + config, scheduler, journal); } } diff --git a/src/ripple/nodestore/impl/ManagerImp.h b/src/ripple/nodestore/impl/ManagerImp.h index 9d802d4289..ecfd6224c0 100644 --- a/src/ripple/nodestore/impl/ManagerImp.h +++ b/src/ripple/nodestore/impl/ManagerImp.h @@ -57,7 +57,7 @@ public: std::unique_ptr make_Backend ( - Parameters const& parameters, + Section const& parameters, Scheduler& scheduler, beast::Journal journal) override; @@ -67,8 +67,8 @@ public: Scheduler& scheduler, beast::Journal journal, int readThreads, - Parameters const& backendParameters, - Parameters fastBackendParameters) override; + Section const& backendParameters, + Section fastBackendParameters) override; std::unique_ptr make_DatabaseRotating ( diff --git a/src/ripple/nodestore/tests/Backend.test.cpp b/src/ripple/nodestore/tests/Backend.test.cpp index 5558e97e1f..1f8552b33f 100644 --- a/src/ripple/nodestore/tests/Backend.test.cpp +++ b/src/ripple/nodestore/tests/Backend.test.cpp @@ -38,10 +38,10 @@ public: testcase ("Backend type=" + type); - beast::StringPairArray params; + Section params; beast::UnitTestUtilities::TempDirectory path ("node_db"); params.set ("type", type); - params.set ("path", path.getFullPathName ()); + params.set ("path", path.getFullPathName ().toStdString ()); // Create a batch Batch batch; diff --git a/src/ripple/nodestore/tests/Database.test.cpp b/src/ripple/nodestore/tests/Database.test.cpp index 4ef49ee91e..2168a72196 100644 --- a/src/ripple/nodestore/tests/Database.test.cpp +++ b/src/ripple/nodestore/tests/Database.test.cpp @@ -35,9 +35,9 @@ public: DummyScheduler scheduler; beast::UnitTestUtilities::TempDirectory node_db ("node_db"); - beast::StringPairArray srcParams; + Section srcParams; srcParams.set ("type", srcBackendType); - srcParams.set ("path", node_db.getFullPathName ()); + srcParams.set ("path", node_db.getFullPathName ().toStdString ()); // Create a batch Batch batch; @@ -61,9 +61,9 @@ public: // Set up the destination database beast::UnitTestUtilities::TempDirectory dest_db ("dest_db"); - beast::StringPairArray destParams; + Section destParams; destParams.set ("type", destBackendType); - destParams.set ("path", dest_db.getFullPathName ()); + destParams.set ("path", dest_db.getFullPathName ().toStdString ()); std::unique_ptr dest = Manager::instance().make_Database ( "test", scheduler, j, 2, destParams); @@ -101,16 +101,16 @@ public: testcase (s); beast::UnitTestUtilities::TempDirectory node_db ("node_db"); - beast::StringPairArray nodeParams; + Section nodeParams; nodeParams.set ("type", type); - nodeParams.set ("path", node_db.getFullPathName ()); + nodeParams.set ("path", node_db.getFullPathName ().toStdString ()); beast::UnitTestUtilities::TempDirectory temp_db ("temp_db"); - beast::StringPairArray tempParams; + Section tempParams; if (useEphemeralDatabase) { tempParams.set ("type", type); - tempParams.set ("path", temp_db.getFullPathName ()); + tempParams.set ("path", temp_db.getFullPathName ().toStdString ()); } // Create a batch @@ -164,7 +164,7 @@ public: { // Verify the ephemeral db std::unique_ptr db = Manager::instance().make_Database ("test", - scheduler, j, 2, tempParams, beast::StringPairArray ()); + scheduler, j, 2, tempParams, Section ()); // Read it back in Batch copy; diff --git a/src/ripple/shamap/tests/common.h b/src/ripple/shamap/tests/common.h index 2340c3bea4..0298aaa5fe 100644 --- a/src/ripple/shamap/tests/common.h +++ b/src/ripple/shamap/tests/common.h @@ -50,11 +50,12 @@ public: TestFamily (beast::Journal j) : treecache_ ("TreeNodeCache", 65536, 60, clock_, j) , fullbelow_ ("full_below", clock_) - , db_(NodeStore::Manager::instance().make_Database( - "test", scheduler_, j, 1, - parseDelimitedKeyValueString( - "type=memory|Path=SHAMap_test"))) { + Section testSection; + testSection.set("type", "memory"); + testSection.set("Path", "SHAMap_test"); + db_ = NodeStore::Manager::instance ().make_Database ( + "test", scheduler_, j, 1, testSection); } beast::manual_clock