21#include <test/jtx/CheckMessageLogs.h>
22#include <test/jtx/envconfig.h>
23#include <test/nodestore/TestBase.h>
24#include <test/unit_test/SuiteJournal.h>
25#include <xrpld/core/DatabaseCon.h>
26#include <xrpld/nodestore/DummyScheduler.h>
27#include <xrpld/nodestore/Manager.h>
28#include <xrpl/beast/utility/temp_dir.h>
51 auto const integrityWarning =
52 "reducing the data integrity guarantees from the "
53 "default [sqlite] behavior is not recommended for "
54 "nodes storing large amounts of history, because of the "
55 "difficulty inherent in rebuilding corrupted data.";
62 if (BEAST_EXPECT(s.globalPragma->size() == 3))
65 s.globalPragma->at(0) ==
"PRAGMA journal_mode=wal;");
67 s.globalPragma->at(1) ==
"PRAGMA synchronous=normal;");
69 s.globalPragma->at(2) ==
"PRAGMA temp_store=file;");
80 auto& section = p->section(
"sqlite");
81 section.set(
"safety_level",
"high");
83 p->LEDGER_HISTORY = 100'000'000;
88 std::make_unique<CheckMessageLogs>(
89 integrityWarning, &found),
95 if (BEAST_EXPECT(s.globalPragma->size() == 3))
98 s.globalPragma->at(0) ==
"PRAGMA journal_mode=wal;");
100 s.globalPragma->at(1) ==
"PRAGMA synchronous=normal;");
102 s.globalPragma->at(2) ==
"PRAGMA temp_store=file;");
113 auto& section = p->section(
"sqlite");
114 section.set(
"safety_level",
"low");
116 p->LEDGER_HISTORY = 100'000'000;
121 std::make_unique<CheckMessageLogs>(
122 integrityWarning, &found),
128 if (BEAST_EXPECT(s.globalPragma->size() == 3))
131 s.globalPragma->at(0) ==
"PRAGMA journal_mode=memory;");
133 s.globalPragma->at(1) ==
"PRAGMA synchronous=off;");
135 s.globalPragma->at(2) ==
"PRAGMA temp_store=memory;");
146 auto& section = p->section(
"sqlite");
147 section.set(
"journal_mode",
"off");
148 section.set(
"synchronous",
"extra");
149 section.set(
"temp_store",
"default");
155 std::make_unique<CheckMessageLogs>(
156 integrityWarning, &found),
162 BEAST_EXPECT(!found);
164 if (BEAST_EXPECT(s.globalPragma->size() == 3))
167 s.globalPragma->at(0) ==
"PRAGMA journal_mode=off;");
169 s.globalPragma->at(1) ==
"PRAGMA synchronous=extra;");
171 s.globalPragma->at(2) ==
"PRAGMA temp_store=default;");
182 auto& section = p->section(
"sqlite");
183 section.set(
"journal_mode",
"off");
184 section.set(
"synchronous",
"extra");
185 section.set(
"temp_store",
"default");
187 p->LEDGER_HISTORY = 50'000'000;
192 std::make_unique<CheckMessageLogs>(
193 integrityWarning, &found),
201 if (BEAST_EXPECT(s.globalPragma->size() == 3))
204 s.globalPragma->at(0) ==
"PRAGMA journal_mode=off;");
206 s.globalPragma->at(1) ==
"PRAGMA synchronous=extra;");
208 s.globalPragma->at(2) ==
"PRAGMA temp_store=default;");
214 auto const expected =
215 "Failed to initialize SQL databases: "
216 "Configuration file may not define both \"safety_level\" and "
222 auto& section = p->section(
"sqlite");
223 section.set(
"safety_level",
"low");
224 section.set(
"journal_mode",
"off");
225 section.set(
"synchronous",
"extra");
226 section.set(
"temp_store",
"default");
234 std::make_unique<CheckMessageLogs>(expected, &found),
246 auto const expected =
247 "Failed to initialize SQL databases: Configuration file may "
248 "not define both \"safety_level\" and \"journal_mode\"";
253 auto& section = p->section(
"sqlite");
254 section.set(
"safety_level",
"high");
255 section.set(
"journal_mode",
"off");
263 std::make_unique<CheckMessageLogs>(expected, &found),
275 auto const expected =
276 "Failed to initialize SQL databases: Configuration file may "
277 "not define both \"safety_level\" and \"synchronous\"";
282 auto& section = p->section(
"sqlite");
283 section.set(
"safety_level",
"low");
284 section.set(
"synchronous",
"extra");
292 std::make_unique<CheckMessageLogs>(expected, &found),
304 auto const expected =
305 "Failed to initialize SQL databases: Configuration file may "
306 "not define both \"safety_level\" and \"temp_store\"";
311 auto& section = p->section(
"sqlite");
312 section.set(
"safety_level",
"high");
313 section.set(
"temp_store",
"default");
321 std::make_unique<CheckMessageLogs>(expected, &found),
333 auto const expected =
334 "Failed to initialize SQL databases: Invalid safety_level "
340 auto& section = p->section(
"sqlite");
341 section.set(
"safety_level",
"slow");
349 std::make_unique<CheckMessageLogs>(expected, &found),
361 auto const expected =
362 "Failed to initialize SQL databases: Invalid journal_mode "
368 auto& section = p->section(
"sqlite");
369 section.set(
"journal_mode",
"fast");
377 std::make_unique<CheckMessageLogs>(expected, &found),
389 auto const expected =
390 "Failed to initialize SQL databases: Invalid synchronous "
396 auto& section = p->section(
"sqlite");
397 section.set(
"synchronous",
"instant");
405 std::make_unique<CheckMessageLogs>(expected, &found),
417 auto const expected =
418 "Failed to initialize SQL databases: Invalid temp_store "
424 auto& section = p->section(
"sqlite");
425 section.set(
"temp_store",
"network");
433 std::make_unique<CheckMessageLogs>(expected, &found),
446 if (BEAST_EXPECT(s.txPragma.size() == 4))
448 BEAST_EXPECT(s.txPragma.at(0) ==
"PRAGMA page_size=4096;");
450 s.txPragma.at(1) ==
"PRAGMA journal_size_limit=1582080;");
452 s.txPragma.at(2) ==
"PRAGMA max_page_count=4294967294;");
454 s.txPragma.at(3) ==
"PRAGMA mmap_size=17179869184;");
462 auto& section = p->section(
"sqlite");
463 section.set(
"page_size",
"512");
464 section.set(
"journal_size_limit",
"2582080");
466 return Env(*
this, std::move(p));
469 if (BEAST_EXPECT(s.txPragma.size() == 4))
471 BEAST_EXPECT(s.txPragma.at(0) ==
"PRAGMA page_size=512;");
473 s.txPragma.at(1) ==
"PRAGMA journal_size_limit=2582080;");
475 s.txPragma.at(2) ==
"PRAGMA max_page_count=4294967294;");
477 s.txPragma.at(3) ==
"PRAGMA mmap_size=17179869184;");
482 auto const expected =
483 "Invalid page_size. Must be between 512 and 65536.";
487 auto& section = p->section(
"sqlite");
488 section.set(
"page_size",
"256");
495 std::make_unique<CheckMessageLogs>(expected, &found),
506 auto const expected =
507 "Invalid page_size. Must be between 512 and 65536.";
511 auto& section = p->section(
"sqlite");
512 section.set(
"page_size",
"131072");
519 std::make_unique<CheckMessageLogs>(expected, &found),
530 auto const expected =
"Invalid page_size. Must be a power of 2.";
534 auto& section = p->section(
"sqlite");
535 section.set(
"page_size",
"513");
542 std::make_unique<CheckMessageLogs>(expected, &found),
565 srcParams.
set(
"type", srcBackendType);
566 srcParams.
set(
"path", node_db.
path());
588 destParams.
set(
"type", destBackendType);
589 destParams.
set(
"path", dest_db.
path());
595 "import into '" + destBackendType +
"' from '" +
596 srcBackendType +
"'");
599 dest->importDatabase(*src);
616 bool const testPersistence,
618 int numObjsToTest = 2000)
622 std::string s =
"NodeStore backend '" + type +
"'";
628 nodeParams.
set(
"type", type);
629 nodeParams.
set(
"path", node_db.
path());
676 if (type ==
"memory")
690 nodeParams.
set(
"earliest_seq",
"0");
703 nodeParams.
set(
"earliest_seq",
"1");
709 BEAST_EXPECT(db->earliestLedgerSeq() == 1);
746#if RIPPLE_ROCKSDB_AVAILABLE
755#if RIPPLE_ROCKSDB_AVAILABLE
759#if RIPPLE_ENABLE_SQLITE_BACKEND_TESTS
RAII temporary directory.
std::string path() const
Get the native path for the temporary directory.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
virtual Config & config()=0
test::SuiteJournal journal_
void testImport(std::string const &destBackendType, std::string const &srcBackendType, std::int64_t seedValue)
void testNodeStore(std::string const &type, bool const testPersistence, std::int64_t const seedValue, int numObjsToTest=2000)
void run() override
Runs the suite.
Persistency layer for NodeObject.
Simple NodeStore Scheduler that just peforms the tasks synchronously.
virtual std::unique_ptr< Database > make_Database(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
static Manager & instance()
Returns the instance of the manager singleton.
static int const numObjectsToTest
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
void fetchCopyOfBatch(Backend &backend, Batch *pCopy, Batch const &batch)
void storeBatch(Backend &backend, Batch const &batch)
Holds a collection of configuration values.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
A transaction testing environment.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr auto megabytes(T value) noexcept
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
static constexpr std::uint32_t XRP_LEDGER_EARLIEST_SEQ
The XRP ledger network's earliest allowed sequence.
static std::unique_ptr< std::vector< std::string > const > globalPragma
Binary function that satisfies the strict-weak-ordering requirement.