mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-23 15:20:54 +00:00
refactor: Change config section and key string literals into constants (#7095)
Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com>
This commit is contained in:
@@ -4,15 +4,15 @@
|
||||
#include <xrpld/app/misc/SHAMapStore.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/basics/BasicConfig.h>
|
||||
#include <xrpl/basics/ByteUtilities.h>
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/beast/core/CurrentThreadName.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/config/BasicConfig.h>
|
||||
#include <xrpl/config/Constants.h>
|
||||
#include <xrpl/ledger/Ledger.h>
|
||||
#include <xrpl/nodestore/Database.h>
|
||||
#include <xrpl/nodestore/Scheduler.h>
|
||||
@@ -101,44 +101,45 @@ SHAMapStoreImp::SHAMapStoreImp(
|
||||
{
|
||||
Config& config{app.config()};
|
||||
|
||||
Section& section{config.section(ConfigSection::nodeDatabase())};
|
||||
Section& section{config.section(Sections::kNodeDatabase)};
|
||||
if (section.empty())
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"Missing [" + ConfigSection::nodeDatabase() + "] entry in configuration file");
|
||||
std::string("Missing [") + Sections::kNodeDatabase + "] entry in configuration file");
|
||||
}
|
||||
|
||||
// RocksDB only. Use sensible defaults if no values specified.
|
||||
if (boost::iequals(get(section, "type"), "RocksDB"))
|
||||
if (boost::iequals(get(section, Keys::kType), "RocksDB"))
|
||||
{
|
||||
if (!section.exists("cache_mb"))
|
||||
if (!section.exists(Keys::kCacheMb))
|
||||
{
|
||||
section.set("cache_mb", std::to_string(config.getValueFor(SizedItem::HashNodeDbCache)));
|
||||
section.set(
|
||||
Keys::kCacheMb, std::to_string(config.getValueFor(SizedItem::HashNodeDbCache)));
|
||||
}
|
||||
|
||||
if (!section.exists("filter_bits") && (config.nodeSize >= 2))
|
||||
section.set("filter_bits", "10");
|
||||
if (!section.exists(Keys::kFilterBits) && (config.nodeSize >= 2))
|
||||
section.set(Keys::kFilterBits, "10");
|
||||
}
|
||||
|
||||
getIfExists(section, "online_delete", deleteInterval_);
|
||||
getIfExists(section, Keys::kOnlineDelete, deleteInterval_);
|
||||
|
||||
if (deleteInterval_ != 0u)
|
||||
{
|
||||
// Configuration that affects the behavior of online delete
|
||||
getIfExists(section, "delete_batch", deleteBatch_);
|
||||
getIfExists(section, Keys::kDeleteBatch, deleteBatch_);
|
||||
std::uint32_t temp = 0;
|
||||
if (getIfExists(section, "back_off_milliseconds", temp) ||
|
||||
if (getIfExists(section, Keys::kBackOffMilliseconds, temp) ||
|
||||
// Included for backward compatibility with an undocumented setting
|
||||
getIfExists(section, "backOff", temp))
|
||||
getIfExists(section, Keys::kBackOff, temp))
|
||||
{
|
||||
backOff_ = std::chrono::milliseconds{temp};
|
||||
}
|
||||
if (getIfExists(section, "age_threshold_seconds", temp))
|
||||
if (getIfExists(section, Keys::kAgeThresholdSeconds, temp))
|
||||
ageThreshold_ = std::chrono::seconds{temp};
|
||||
if (getIfExists(section, "recovery_wait_seconds", temp))
|
||||
if (getIfExists(section, Keys::kRecoveryWaitSeconds, temp))
|
||||
recoveryWaitTime_ = std::chrono::seconds{temp};
|
||||
|
||||
getIfExists(section, "advisory_delete", advisoryDelete_);
|
||||
getIfExists(section, Keys::kAdvisoryDelete, advisoryDelete_);
|
||||
|
||||
auto const minInterval =
|
||||
config.standalone() ? kMinimumDeletionIntervalSa : kMinimumDeletionInterval;
|
||||
@@ -164,20 +165,20 @@ SHAMapStoreImp::SHAMapStoreImp(
|
||||
std::unique_ptr<NodeStore::Database>
|
||||
SHAMapStoreImp::makeNodeStore(int readThreads)
|
||||
{
|
||||
auto nscfg = app_.config().section(ConfigSection::nodeDatabase());
|
||||
auto nscfg = app_.config().section(Sections::kNodeDatabase);
|
||||
|
||||
// Provide default values.
|
||||
if (!nscfg.exists("cache_size"))
|
||||
if (!nscfg.exists(Keys::kCacheSize))
|
||||
{
|
||||
nscfg.set(
|
||||
"cache_size",
|
||||
Keys::kCacheSize,
|
||||
std::to_string(app_.config().getValueFor(SizedItem::TreeCacheSize, std::nullopt)));
|
||||
}
|
||||
|
||||
if (!nscfg.exists("cache_age"))
|
||||
if (!nscfg.exists(Keys::kCacheAge))
|
||||
{
|
||||
nscfg.set(
|
||||
"cache_age",
|
||||
Keys::kCacheAge,
|
||||
std::to_string(app_.config().getValueFor(SizedItem::TreeCacheAge, std::nullopt)));
|
||||
}
|
||||
|
||||
@@ -385,8 +386,8 @@ SHAMapStoreImp::run()
|
||||
void
|
||||
SHAMapStoreImp::dbPaths()
|
||||
{
|
||||
Section const section{app_.config().section(ConfigSection::nodeDatabase())};
|
||||
boost::filesystem::path dbPath = get(section, "path");
|
||||
Section const section{app_.config().section(Sections::kNodeDatabase)};
|
||||
boost::filesystem::path dbPath = get(section, Keys::kPath);
|
||||
|
||||
if (boost::filesystem::exists(dbPath))
|
||||
{
|
||||
@@ -451,7 +452,7 @@ SHAMapStoreImp::dbPaths()
|
||||
(!archiveDbExists && !state.archiveDb.empty()) || (writableDbExists != archiveDbExists) ||
|
||||
state.writableDb.empty() != state.archiveDb.empty())
|
||||
{
|
||||
boost::filesystem::path stateDbPathName = app_.config().legacy("database_path");
|
||||
boost::filesystem::path stateDbPathName = app_.config().legacy(Sections::kDatabasePath);
|
||||
stateDbPathName /= dbName_;
|
||||
stateDbPathName += "*";
|
||||
|
||||
@@ -463,7 +464,7 @@ SHAMapStoreImp::dbPaths()
|
||||
<< "The existing data is in a corrupted state.\n"
|
||||
<< "To resume operation, remove the files matching "
|
||||
<< stateDbPathName.string() << " and contents of the directory "
|
||||
<< get(section, "path") << '\n'
|
||||
<< get(section, Keys::kPath) << '\n'
|
||||
<< "Optionally, you can move those files to another\n"
|
||||
<< "location if you wish to analyze or back up the data.\n"
|
||||
<< "However, there is no guarantee that the data in its\n"
|
||||
@@ -480,7 +481,7 @@ SHAMapStoreImp::dbPaths()
|
||||
std::unique_ptr<NodeStore::Backend>
|
||||
SHAMapStoreImp::makeBackendRotating(std::string path)
|
||||
{
|
||||
Section section{app_.config().section(ConfigSection::nodeDatabase())};
|
||||
Section section{app_.config().section(Sections::kNodeDatabase)};
|
||||
boost::filesystem::path newPath;
|
||||
|
||||
if (!path.empty())
|
||||
@@ -489,12 +490,12 @@ SHAMapStoreImp::makeBackendRotating(std::string path)
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::filesystem::path p = get(section, "path");
|
||||
boost::filesystem::path p = get(section, Keys::kPath);
|
||||
p /= dbPrefix_;
|
||||
p += ".%%%%";
|
||||
newPath = boost::filesystem::unique_path(p);
|
||||
}
|
||||
section.set("path", newPath.string());
|
||||
section.set(Keys::kPath, newPath.string());
|
||||
|
||||
auto backend{NodeStore::Manager::instance().makeBackend(
|
||||
section,
|
||||
|
||||
Reference in New Issue
Block a user