20#include <xrpld/core/DatabaseCon.h>
21#include <xrpld/core/SociDB.h>
22#include <xrpl/basics/Log.h>
23#include <xrpl/basics/contract.h>
25#include <boost/algorithm/string.hpp>
26#include <boost/format.hpp>
115 Throw<std::runtime_error>(
"database_path must be set.");
121 auto const& sqlite = c.
section(
"sqlite");
122 auto result = std::make_unique<std::vector<std::string>>();
130 bool showRiskWarning =
false;
132 if (
set(safety_level,
"safety_level", sqlite))
134 if (boost::iequals(safety_level,
"low"))
137 journal_mode =
"memory";
139 temp_store =
"memory";
140 showRiskWarning =
true;
142 else if (!boost::iequals(safety_level,
"high"))
144 Throw<std::runtime_error>(
145 "Invalid safety_level value: " + safety_level);
152 if (
set(journal_mode,
"journal_mode", sqlite) &&
153 !safety_level.
empty())
155 Throw<std::runtime_error>(
156 "Configuration file may not define both "
157 "\"safety_level\" and \"journal_mode\"");
159 bool higherRisk = boost::iequals(journal_mode,
"memory") ||
160 boost::iequals(journal_mode,
"off");
161 showRiskWarning = showRiskWarning || higherRisk;
162 if (higherRisk || boost::iequals(journal_mode,
"delete") ||
163 boost::iequals(journal_mode,
"truncate") ||
164 boost::iequals(journal_mode,
"persist") ||
165 boost::iequals(journal_mode,
"wal"))
167 result->emplace_back(boost::str(
172 Throw<std::runtime_error>(
173 "Invalid journal_mode value: " + journal_mode);
179 if (
set(synchronous,
"synchronous", sqlite) &&
180 !safety_level.
empty())
182 Throw<std::runtime_error>(
183 "Configuration file may not define both "
184 "\"safety_level\" and \"synchronous\"");
186 bool higherRisk = boost::iequals(synchronous,
"off");
187 showRiskWarning = showRiskWarning || higherRisk;
188 if (higherRisk || boost::iequals(synchronous,
"normal") ||
189 boost::iequals(synchronous,
"full") ||
190 boost::iequals(synchronous,
"extra"))
192 result->emplace_back(boost::str(
197 Throw<std::runtime_error>(
198 "Invalid synchronous value: " + synchronous);
204 if (
set(temp_store,
"temp_store", sqlite) &&
205 !safety_level.
empty())
207 Throw<std::runtime_error>(
208 "Configuration file may not define both "
209 "\"safety_level\" and \"temp_store\"");
211 bool higherRisk = boost::iequals(temp_store,
"memory");
212 showRiskWarning = showRiskWarning || higherRisk;
213 if (higherRisk || boost::iequals(temp_store,
"default") ||
214 boost::iequals(temp_store,
"file"))
216 result->emplace_back(boost::str(
221 Throw<std::runtime_error>(
222 "Invalid temp_store value: " + temp_store);
229 <<
"reducing the data integrity guarantees from the "
230 "default [sqlite] behavior is not recommended for "
231 "nodes storing large amounts of history, because of the "
232 "difficulty inherent in rebuilding corrupted data.";
236 "ripple::setup_DatabaseCon::globalPragma : result size is 3");
248 setPragma(setup.
lgrPragma[0],
"journal_size_limit", 1582080);
251 int64_t page_size = 4096;
252 int64_t journal_size_limit = 1582080;
256 set(journal_size_limit,
"journal_size_limit", s);
257 set(page_size,
"page_size", s);
258 if (page_size < 512 || page_size > 65536)
259 Throw<std::runtime_error>(
260 "Invalid page_size. Must be between 512 and 65536.");
262 if (page_size & (page_size - 1))
263 Throw<std::runtime_error>(
264 "Invalid page_size. Must be a power of 2.");
267 setPragma(setup.
txPragma[0],
"page_size", page_size);
268 setPragma(setup.
txPragma[1],
"journal_size_limit", journal_size_limit);
269 setPragma(setup.
txPragma[2],
"max_page_count", 4294967294);
270 setPragma(setup.
txPragma[3],
"mmap_size", 17179869184);
282 Throw<std::logic_error>(
"No JobQueue");
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
void erase(std::uintptr_t id)
std::shared_ptr< Checkpointer > create(std::shared_ptr< soci::session > const &session, JobQueue &jobQueue, Logs &logs)
std::shared_ptr< Checkpointer > fromId(std::uintptr_t id)
std::unordered_map< std::uintptr_t, std::shared_ptr< Checkpointer > > checkpointers_
std::uint32_t LEDGER_HISTORY
void setupCheckpointing(JobQueue *, Logs &)
std::shared_ptr< soci::session > const session_
std::shared_ptr< Checkpointer > checkpointer_
A pool of threads to perform work.
Manages partitions for logging.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
constexpr char const * CommonDBPragmaSync
CheckpointersCollection checkpointers
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
constexpr char const * CommonDBPragmaTemp
constexpr std::uint32_t SQLITE_TUNING_CUTOFF
constexpr char const * CommonDBPragmaJournal
std::shared_ptr< Checkpointer > makeCheckpointer(std::uintptr_t id, std::weak_ptr< soci::session > session, JobQueue &queue, Logs &logs)
Returns a new checkpointer which makes checkpoints of a soci database every checkpointPageCount pages...
std::shared_ptr< Checkpointer > checkpointerFromId(std::uintptr_t id)
boost::filesystem::path dataDir
static std::unique_ptr< std::vector< std::string > const > globalPragma
std::array< std::string, 1 > lgrPragma
Config::StartUpType startUp
std::array< std::string, 4 > txPragma