2#include <test/jtx/CheckMessageLogs.h>
3#include <test/jtx/envconfig.h>
4#include <test/nodestore/TestBase.h>
5#include <test/unit_test/SuiteJournal.h>
7#include <xrpld/core/DatabaseCon.h>
9#include <xrpl/beast/utility/temp_dir.h>
10#include <xrpl/nodestore/DummyScheduler.h>
11#include <xrpl/nodestore/Manager.h>
34 auto const integrityWarning =
35 "reducing the data integrity guarantees from the "
36 "default [sqlite] behavior is not recommended for "
37 "nodes storing large amounts of history, because of the "
38 "difficulty inherent in rebuilding corrupted data.";
45 if (BEAST_EXPECT(s.globalPragma->size() == 3))
48 s.globalPragma->at(0) ==
"PRAGMA journal_mode=wal;");
50 s.globalPragma->at(1) ==
"PRAGMA synchronous=normal;");
52 s.globalPragma->at(2) ==
"PRAGMA temp_store=file;");
63 auto& section = p->section(
"sqlite");
64 section.set(
"safety_level",
"high");
66 p->LEDGER_HISTORY = 100'000'000;
72 integrityWarning, &found),
78 if (BEAST_EXPECT(s.globalPragma->size() == 3))
81 s.globalPragma->at(0) ==
"PRAGMA journal_mode=wal;");
83 s.globalPragma->at(1) ==
"PRAGMA synchronous=normal;");
85 s.globalPragma->at(2) ==
"PRAGMA temp_store=file;");
96 auto& section = p->section(
"sqlite");
97 section.set(
"safety_level",
"low");
99 p->LEDGER_HISTORY = 100'000'000;
105 integrityWarning, &found),
111 if (BEAST_EXPECT(s.globalPragma->size() == 3))
114 s.globalPragma->at(0) ==
"PRAGMA journal_mode=memory;");
116 s.globalPragma->at(1) ==
"PRAGMA synchronous=off;");
118 s.globalPragma->at(2) ==
"PRAGMA temp_store=memory;");
129 auto& section = p->section(
"sqlite");
130 section.set(
"journal_mode",
"off");
131 section.set(
"synchronous",
"extra");
132 section.set(
"temp_store",
"default");
139 integrityWarning, &found),
145 BEAST_EXPECT(!found);
147 if (BEAST_EXPECT(s.globalPragma->size() == 3))
150 s.globalPragma->at(0) ==
"PRAGMA journal_mode=off;");
152 s.globalPragma->at(1) ==
"PRAGMA synchronous=extra;");
154 s.globalPragma->at(2) ==
"PRAGMA temp_store=default;");
165 auto& section = p->section(
"sqlite");
166 section.set(
"journal_mode",
"off");
167 section.set(
"synchronous",
"extra");
168 section.set(
"temp_store",
"default");
170 p->LEDGER_HISTORY = 50'000'000;
176 integrityWarning, &found),
184 if (BEAST_EXPECT(s.globalPragma->size() == 3))
187 s.globalPragma->at(0) ==
"PRAGMA journal_mode=off;");
189 s.globalPragma->at(1) ==
"PRAGMA synchronous=extra;");
191 s.globalPragma->at(2) ==
"PRAGMA temp_store=default;");
197 auto const expected =
198 "Failed to initialize SQL databases: "
199 "Configuration file may not define both \"safety_level\" and "
205 auto& section = p->section(
"sqlite");
206 section.set(
"safety_level",
"low");
207 section.set(
"journal_mode",
"off");
208 section.set(
"synchronous",
"extra");
209 section.set(
"temp_store",
"default");
229 auto const expected =
230 "Failed to initialize SQL databases: Configuration file may "
231 "not define both \"safety_level\" and \"journal_mode\"";
236 auto& section = p->section(
"sqlite");
237 section.set(
"safety_level",
"high");
238 section.set(
"journal_mode",
"off");
258 auto const expected =
259 "Failed to initialize SQL databases: Configuration file may "
260 "not define both \"safety_level\" and \"synchronous\"";
265 auto& section = p->section(
"sqlite");
266 section.set(
"safety_level",
"low");
267 section.set(
"synchronous",
"extra");
287 auto const expected =
288 "Failed to initialize SQL databases: Configuration file may "
289 "not define both \"safety_level\" and \"temp_store\"";
294 auto& section = p->section(
"sqlite");
295 section.set(
"safety_level",
"high");
296 section.set(
"temp_store",
"default");
316 auto const expected =
317 "Failed to initialize SQL databases: Invalid safety_level "
323 auto& section = p->section(
"sqlite");
324 section.set(
"safety_level",
"slow");
344 auto const expected =
345 "Failed to initialize SQL databases: Invalid journal_mode "
351 auto& section = p->section(
"sqlite");
352 section.set(
"journal_mode",
"fast");
372 auto const expected =
373 "Failed to initialize SQL databases: Invalid synchronous "
379 auto& section = p->section(
"sqlite");
380 section.set(
"synchronous",
"instant");
400 auto const expected =
401 "Failed to initialize SQL databases: Invalid temp_store "
407 auto& section = p->section(
"sqlite");
408 section.set(
"temp_store",
"network");
429 if (BEAST_EXPECT(s.txPragma.size() == 4))
431 BEAST_EXPECT(s.txPragma.at(0) ==
"PRAGMA page_size=4096;");
433 s.txPragma.at(1) ==
"PRAGMA journal_size_limit=1582080;");
435 s.txPragma.at(2) ==
"PRAGMA max_page_count=4294967294;");
437 s.txPragma.at(3) ==
"PRAGMA mmap_size=17179869184;");
445 auto& section = p->section(
"sqlite");
446 section.set(
"page_size",
"512");
447 section.set(
"journal_size_limit",
"2582080");
449 return Env(*
this, std::move(p));
452 if (BEAST_EXPECT(s.txPragma.size() == 4))
454 BEAST_EXPECT(s.txPragma.at(0) ==
"PRAGMA page_size=512;");
456 s.txPragma.at(1) ==
"PRAGMA journal_size_limit=2582080;");
458 s.txPragma.at(2) ==
"PRAGMA max_page_count=4294967294;");
460 s.txPragma.at(3) ==
"PRAGMA mmap_size=17179869184;");
465 auto const expected =
466 "Invalid page_size. Must be between 512 and 65536.";
470 auto& section = p->section(
"sqlite");
471 section.set(
"page_size",
"256");
489 auto const expected =
490 "Invalid page_size. Must be between 512 and 65536.";
494 auto& section = p->section(
"sqlite");
495 section.set(
"page_size",
"131072");
513 auto const expected =
"Invalid page_size. Must be a power of 2.";
517 auto& section = p->section(
"sqlite");
518 section.set(
"page_size",
"513");
548 srcParams.
set(
"type", srcBackendType);
549 srcParams.
set(
"path", node_db.
path());
571 destParams.
set(
"type", destBackendType);
572 destParams.
set(
"path", dest_db.
path());
578 "import into '" + destBackendType +
"' from '" +
579 srcBackendType +
"'");
582 dest->importDatabase(*src);
599 bool const testPersistence,
601 int numObjsToTest = 2000)
605 std::string s =
"NodeStore backend '" + type +
"'";
611 nodeParams.
set(
"type", type);
612 nodeParams.
set(
"path", node_db.
path());
659 if (type ==
"memory")
673 nodeParams.
set(
"earliest_seq",
"0");
686 nodeParams.
set(
"earliest_seq",
"1");
692 BEAST_EXPECT(db->earliestLedgerSeq() == 1);
729#if XRPL_ROCKSDB_AVAILABLE
738#if XRPL_ROCKSDB_AVAILABLE
742#if XRPL_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.