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>
26#include <xrpld/core/DatabaseCon.h>
27#include <xrpld/nodestore/DummyScheduler.h>
28#include <xrpld/nodestore/Manager.h>
30#include <xrpl/beast/utility/temp_dir.h>
53 auto const integrityWarning =
54 "reducing the data integrity guarantees from the "
55 "default [sqlite] behavior is not recommended for "
56 "nodes storing large amounts of history, because of the "
57 "difficulty inherent in rebuilding corrupted data.";
64 if (BEAST_EXPECT(s.globalPragma->size() == 3))
67 s.globalPragma->at(0) ==
"PRAGMA journal_mode=wal;");
69 s.globalPragma->at(1) ==
"PRAGMA synchronous=normal;");
71 s.globalPragma->at(2) ==
"PRAGMA temp_store=file;");
82 auto& section = p->section(
"sqlite");
83 section.set(
"safety_level",
"high");
85 p->LEDGER_HISTORY = 100'000'000;
91 integrityWarning, &found),
97 if (BEAST_EXPECT(s.globalPragma->size() == 3))
100 s.globalPragma->at(0) ==
"PRAGMA journal_mode=wal;");
102 s.globalPragma->at(1) ==
"PRAGMA synchronous=normal;");
104 s.globalPragma->at(2) ==
"PRAGMA temp_store=file;");
115 auto& section = p->section(
"sqlite");
116 section.set(
"safety_level",
"low");
118 p->LEDGER_HISTORY = 100'000'000;
124 integrityWarning, &found),
130 if (BEAST_EXPECT(s.globalPragma->size() == 3))
133 s.globalPragma->at(0) ==
"PRAGMA journal_mode=memory;");
135 s.globalPragma->at(1) ==
"PRAGMA synchronous=off;");
137 s.globalPragma->at(2) ==
"PRAGMA temp_store=memory;");
148 auto& section = p->section(
"sqlite");
149 section.set(
"journal_mode",
"off");
150 section.set(
"synchronous",
"extra");
151 section.set(
"temp_store",
"default");
158 integrityWarning, &found),
164 BEAST_EXPECT(!found);
166 if (BEAST_EXPECT(s.globalPragma->size() == 3))
169 s.globalPragma->at(0) ==
"PRAGMA journal_mode=off;");
171 s.globalPragma->at(1) ==
"PRAGMA synchronous=extra;");
173 s.globalPragma->at(2) ==
"PRAGMA temp_store=default;");
184 auto& section = p->section(
"sqlite");
185 section.set(
"journal_mode",
"off");
186 section.set(
"synchronous",
"extra");
187 section.set(
"temp_store",
"default");
189 p->LEDGER_HISTORY = 50'000'000;
195 integrityWarning, &found),
203 if (BEAST_EXPECT(s.globalPragma->size() == 3))
206 s.globalPragma->at(0) ==
"PRAGMA journal_mode=off;");
208 s.globalPragma->at(1) ==
"PRAGMA synchronous=extra;");
210 s.globalPragma->at(2) ==
"PRAGMA temp_store=default;");
216 auto const expected =
217 "Failed to initialize SQL databases: "
218 "Configuration file may not define both \"safety_level\" and "
224 auto& section = p->section(
"sqlite");
225 section.set(
"safety_level",
"low");
226 section.set(
"journal_mode",
"off");
227 section.set(
"synchronous",
"extra");
228 section.set(
"temp_store",
"default");
248 auto const expected =
249 "Failed to initialize SQL databases: Configuration file may "
250 "not define both \"safety_level\" and \"journal_mode\"";
255 auto& section = p->section(
"sqlite");
256 section.set(
"safety_level",
"high");
257 section.set(
"journal_mode",
"off");
277 auto const expected =
278 "Failed to initialize SQL databases: Configuration file may "
279 "not define both \"safety_level\" and \"synchronous\"";
284 auto& section = p->section(
"sqlite");
285 section.set(
"safety_level",
"low");
286 section.set(
"synchronous",
"extra");
306 auto const expected =
307 "Failed to initialize SQL databases: Configuration file may "
308 "not define both \"safety_level\" and \"temp_store\"";
313 auto& section = p->section(
"sqlite");
314 section.set(
"safety_level",
"high");
315 section.set(
"temp_store",
"default");
335 auto const expected =
336 "Failed to initialize SQL databases: Invalid safety_level "
342 auto& section = p->section(
"sqlite");
343 section.set(
"safety_level",
"slow");
363 auto const expected =
364 "Failed to initialize SQL databases: Invalid journal_mode "
370 auto& section = p->section(
"sqlite");
371 section.set(
"journal_mode",
"fast");
391 auto const expected =
392 "Failed to initialize SQL databases: Invalid synchronous "
398 auto& section = p->section(
"sqlite");
399 section.set(
"synchronous",
"instant");
419 auto const expected =
420 "Failed to initialize SQL databases: Invalid temp_store "
426 auto& section = p->section(
"sqlite");
427 section.set(
"temp_store",
"network");
448 if (BEAST_EXPECT(s.txPragma.size() == 4))
450 BEAST_EXPECT(s.txPragma.at(0) ==
"PRAGMA page_size=4096;");
452 s.txPragma.at(1) ==
"PRAGMA journal_size_limit=1582080;");
454 s.txPragma.at(2) ==
"PRAGMA max_page_count=4294967294;");
456 s.txPragma.at(3) ==
"PRAGMA mmap_size=17179869184;");
464 auto& section = p->section(
"sqlite");
465 section.set(
"page_size",
"512");
466 section.set(
"journal_size_limit",
"2582080");
468 return Env(*
this, std::move(p));
471 if (BEAST_EXPECT(s.txPragma.size() == 4))
473 BEAST_EXPECT(s.txPragma.at(0) ==
"PRAGMA page_size=512;");
475 s.txPragma.at(1) ==
"PRAGMA journal_size_limit=2582080;");
477 s.txPragma.at(2) ==
"PRAGMA max_page_count=4294967294;");
479 s.txPragma.at(3) ==
"PRAGMA mmap_size=17179869184;");
484 auto const expected =
485 "Invalid page_size. Must be between 512 and 65536.";
489 auto& section = p->section(
"sqlite");
490 section.set(
"page_size",
"256");
508 auto const expected =
509 "Invalid page_size. Must be between 512 and 65536.";
513 auto& section = p->section(
"sqlite");
514 section.set(
"page_size",
"131072");
532 auto const expected =
"Invalid page_size. Must be a power of 2.";
536 auto& section = p->section(
"sqlite");
537 section.set(
"page_size",
"513");
567 srcParams.
set(
"type", srcBackendType);
568 srcParams.
set(
"path", node_db.
path());
590 destParams.
set(
"type", destBackendType);
591 destParams.
set(
"path", dest_db.
path());
597 "import into '" + destBackendType +
"' from '" +
598 srcBackendType +
"'");
601 dest->importDatabase(*src);
618 bool const testPersistence,
620 int numObjsToTest = 2000)
624 std::string s =
"NodeStore backend '" + type +
"'";
630 nodeParams.
set(
"type", type);
631 nodeParams.
set(
"path", node_db.
path());
678 if (type ==
"memory")
692 nodeParams.
set(
"earliest_seq",
"0");
705 nodeParams.
set(
"earliest_seq",
"1");
711 BEAST_EXPECT(db->earliestLedgerSeq() == 1);
748#if RIPPLE_ROCKSDB_AVAILABLE
757#if RIPPLE_ROCKSDB_AVAILABLE
761#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.