From e51bcb41b908b64928a7ef3107da27b43dcfe8a3 Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Tue, 24 Sep 2024 09:27:37 +0200 Subject: [PATCH] fixup --- src/ripple/app/ledger/Ledger.cpp | 14 +++++ src/ripple/app/misc/SHAMapStoreImp.cpp | 45 ++++++++++++++ src/ripple/app/misc/impl/Transaction.cpp | 15 ++++- .../app/rdb/backend/detail/impl/Node.cpp | 40 +++++++------ .../app/rdb/impl/RelationalDatabase.cpp | 60 +++++++++---------- src/ripple/core/Config.h | 2 +- src/ripple/core/impl/DatabaseCon.cpp | 3 +- 7 files changed, 126 insertions(+), 53 deletions(-) diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index c7263059b..14e15f64a 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -1011,6 +1011,20 @@ saveValidatedLedger( return true; } + if (app.config().RELATIONAL_DB == 0) + { + auto const db = dynamic_cast(&app.getRelationalDatabase()); + if (!db) + Throw("Failed to get relational database"); + + auto const res = db->saveValidatedLedger(ledger, current); + // Clients can now trust the database for + // information about this ledger sequence. + + app.pendingSaves().finishWork(seq); + return res; + } + auto const db = dynamic_cast(&app.getRelationalDatabase()); if (!db) Throw("Failed to get relational database"); diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index 55c49bc0c..a3d19349c 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -635,6 +635,51 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated) if (healthWait() == stopping) return; + if (app_.config().RELATIONAL_DB == 0) + { + + SQLiteDatabase* const db = + dynamic_cast(&app_.getRelationalDatabase()); + + if (!db) + Throw("Failed to get relational database"); + + clearSql( + lastRotated, + "Ledgers", + [db]() -> std::optional { return db->getMinLedgerSeq(); }, + [db](LedgerIndex min) -> void { db->deleteBeforeLedgerSeq(min); }); + if (healthWait() == stopping) + return; + + if (!app_.config().useTxTables()) + return; + + clearSql( + lastRotated, + "Transactions", + [&db]() -> std::optional { + return db->getTransactionsMinLedgerSeq(); + }, + [&db](LedgerIndex min) -> void { + db->deleteTransactionsBeforeLedgerSeq(min); + }); + if (healthWait() == stopping) + return; + + clearSql( + lastRotated, + "AccountTransactions", + [&db]() -> std::optional { + return db->getAccountTransactionsMinLedgerSeq(); + }, + [&db](LedgerIndex min) -> void { + db->deleteAccountTransactionsBeforeLedgerSeq(min); + }); + if (healthWait() == stopping) + return; + } + LMDBDatabase* const db = dynamic_cast(&app_.getRelationalDatabase()); diff --git a/src/ripple/app/misc/impl/Transaction.cpp b/src/ripple/app/misc/impl/Transaction.cpp index 1a5ffed08..84b11e0fe 100644 --- a/src/ripple/app/misc/impl/Transaction.cpp +++ b/src/ripple/app/misc/impl/Transaction.cpp @@ -163,7 +163,20 @@ Transaction::load( std::optional> const& range, error_code_i& ec) { - auto const db = dynamic_cast(&app.getRelationalDatabase()); + + if (app.config().RELATIONAL_DB == 0) + { + auto const db = dynamic_cast(&app.getRelationalDatabase()); + + if (!db) + { + Throw("Failed to get relational database"); + } + + return db->getTransaction(id, range, ec); + } + + auto const db = dynamic_cast(&app.getRelationalDatabase()); if (!db) { diff --git a/src/ripple/app/rdb/backend/detail/impl/Node.cpp b/src/ripple/app/rdb/backend/detail/impl/Node.cpp index 4b1a8ab85..63916b845 100644 --- a/src/ripple/app/rdb/backend/detail/impl/Node.cpp +++ b/src/ripple/app/rdb/backend/detail/impl/Node.cpp @@ -150,13 +150,15 @@ makeLedgerDBs( DatabaseCon::CheckpointerSetup const& checkpointerSetup) { if (setup.sqlite3) + { return makeSQLLedgerDBs(config, setup, checkpointerSetup); + } return makeLMDBLedgerDBs(config, setup, checkpointerSetup); } std::optional -getMinLedgerSeq(MDB_env* env, TableType type) +getMinLedgerSeq(MDB_env *env, TableType type) { MDB_txn* txn; MDB_dbi dbi; @@ -182,7 +184,7 @@ getMinLedgerSeq(MDB_env* env, TableType type) } std::optional -getMaxLedgerSeq(MDB_env* env, TableType type) +getMaxLedgerSeq(MDB_env *env, TableType type) { MDB_txn* txn; MDB_dbi dbi; @@ -208,7 +210,7 @@ getMaxLedgerSeq(MDB_env* env, TableType type) } void -deleteByLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq) +deleteByLedgerSeq(MDB_env *env, TableType type, LedgerIndex ledgerSeq) { MDB_txn* txn; MDB_dbi dbi; @@ -227,7 +229,7 @@ deleteByLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq) } void -deleteBeforeLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq) +deleteBeforeLedgerSeq(MDB_env *env, TableType type, LedgerIndex ledgerSeq) { MDB_txn* txn; MDB_dbi dbi; @@ -294,7 +296,7 @@ deleteBeforeLedgerSeq( } std::size_t -getRows(MDB_env* env, TableType type) +getRows(MDB_env *env, TableType type) { MDB_txn* txn; MDB_dbi dbi; @@ -323,7 +325,7 @@ getRows(MDB_env* env, TableType type) } RelationalDatabase::CountMinMax -getRowsMinMax(MDB_env* env, TableType type) +getRowsMinMax(MDB_env *env, TableType type) { MDB_txn* txn; MDB_dbi dbi; @@ -455,7 +457,7 @@ saveLMDBValidatedLedger( MDB_dbi dbi; MDB_txn* txn; auto db = ldgDB.checkoutLMDB(); - MDB_env* env = db.get(); + MDB_env *env = db.get(); mdb_txn_begin(env, nullptr, 0, &txn); try { @@ -538,7 +540,7 @@ saveLMDBValidatedLedger( MDB_dbi dbi; MDB_txn* txn; auto db = ldgDB.checkoutLMDB(); - MDB_env* env = db.get(); + MDB_env *env = db.get(); mdb_txn_begin(env, nullptr, 0, &txn); try @@ -797,7 +799,7 @@ saveValidatedLedger( // Function to get the ledger info from the LMDB database static std::optional -getLedgerInfo(MDB_env* env, std::string const& key, beast::Journal j) +getLedgerInfo(MDB_env *env, std::string const& key, beast::Journal j) { MDB_txn* txn; MDB_dbi dbi; @@ -842,7 +844,7 @@ getLedgerInfo(MDB_env* env, std::string const& key, beast::Journal j) } std::optional -getLedgerInfoByIndex(MDB_env* env, LedgerIndex ledgerSeq, beast::Journal j) +getLedgerInfoByIndex(MDB_env *env, LedgerIndex ledgerSeq, beast::Journal j) { std::ostringstream s; s << "LedgerSeq_" << ledgerSeq; @@ -850,7 +852,7 @@ getLedgerInfoByIndex(MDB_env* env, LedgerIndex ledgerSeq, beast::Journal j) } std::optional -getNewestLedgerInfo(MDB_env* env, beast::Journal j) +getNewestLedgerInfo(MDB_env *env, beast::Journal j) { // LMDB does not support SQL-like queries directly // You need to implement a way to find the newest ledger info @@ -861,7 +863,7 @@ getNewestLedgerInfo(MDB_env* env, beast::Journal j) std::optional getLimitedOldestLedgerInfo( - MDB_env* env, + MDB_env *env, LedgerIndex ledgerFirstIndex, beast::Journal j) { @@ -873,7 +875,7 @@ getLimitedOldestLedgerInfo( std::optional getLimitedNewestLedgerInfo( - MDB_env* env, + MDB_env *env, LedgerIndex ledgerFirstIndex, beast::Journal j) { @@ -884,7 +886,7 @@ getLimitedNewestLedgerInfo( } std::optional -getLedgerInfoByHash(MDB_env* env, uint256 const& ledgerHash, beast::Journal j) +getLedgerInfoByHash(MDB_env *env, uint256 const& ledgerHash, beast::Journal j) { std::ostringstream s; s << "LedgerHash_" << ledgerHash; @@ -1024,7 +1026,7 @@ getLedgerInfoByHash( } uint256 -getHashByIndex(MDB_env* env, LedgerIndex ledgerIndex) +getHashByIndex(MDB_env *env, LedgerIndex ledgerIndex) { uint256 ret; MDB_txn* txn; @@ -1098,7 +1100,7 @@ getHashByIndex(soci::session& session, LedgerIndex ledgerIndex) } std::optional -getHashesByIndex(MDB_env* env, LedgerIndex ledgerIndex, beast::Journal j) +getHashesByIndex(MDB_env *env, LedgerIndex ledgerIndex, beast::Journal j) { MDB_txn* txn; MDB_dbi dbi; @@ -1158,7 +1160,7 @@ getHashesByIndex(MDB_env* env, LedgerIndex ledgerIndex, beast::Journal j) std::map getHashesByIndex( - MDB_env* env, + MDB_env *env, LedgerIndex minSeq, LedgerIndex maxSeq, beast::Journal j) @@ -1982,7 +1984,7 @@ newestAccountTxPage( std::variant getTransaction( - MDB_env* env, + MDB_env *env, Application& app, uint256 const& id, std::optional> const& range, @@ -2185,7 +2187,7 @@ getTransaction( } bool -dbHasSpace(MDB_env* env, Config const& config, beast::Journal j) +dbHasSpace(MDB_env *env, Config const& config, beast::Journal j) { boost::filesystem::space_info space = boost::filesystem::space(config.legacy("database_path")); diff --git a/src/ripple/app/rdb/impl/RelationalDatabase.cpp b/src/ripple/app/rdb/impl/RelationalDatabase.cpp index a261b9da2..c3f1dcc8f 100644 --- a/src/ripple/app/rdb/impl/RelationalDatabase.cpp +++ b/src/ripple/app/rdb/impl/RelationalDatabase.cpp @@ -41,37 +41,37 @@ RelationalDatabase::init( { bool use_sqlite = false; bool use_postgres = false; - bool use_lmdb = false; + bool use_lmdb = true; - if (config.reporting()) - { - use_postgres = true; - } - else - { - const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)}; - if (!rdb_section.empty()) - { - if (boost::iequals(get(rdb_section, "backend"), "sqlite")) - { - use_sqlite = true; - } - else if (boost::iequals(get(rdb_section, "backend"), "lmdb")) - { - use_lmdb = true; - } - else - { - Throw( - "Invalid rdb_section backend value: " + - get(rdb_section, "backend")); - } - } - else - { - use_sqlite = true; - } - } + // if (config.reporting()) + // { + // use_postgres = true; + // } + // else + // { + // const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)}; + // if (!rdb_section.empty()) + // { + // if (boost::iequals(get(rdb_section, "backend"), "sqlite")) + // { + // use_sqlite = true; + // } + // else if (boost::iequals(get(rdb_section, "backend"), "lmdb")) + // { + // use_lmdb = true; + // } + // else + // { + // Throw( + // "Invalid rdb_section backend value: " + + // get(rdb_section, "backend")); + // } + // } + // else + // { + // use_sqlite = true; + // } + // } if (use_sqlite) { diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index de6aff52e..ef3f2715b 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -169,7 +169,7 @@ class Config : public BasicConfig std::string START_LEDGER; - uint32_t RELATIONAL_DB = 0; // 0 == SQLite, 1 == LMDB + uint32_t RELATIONAL_DB = 1; // 0 == SQLite, 1 == LMDB // Network parameters uint32_t NETWORK_ID = 0; diff --git a/src/ripple/core/impl/DatabaseCon.cpp b/src/ripple/core/impl/DatabaseCon.cpp index 8b8ab193b..7847475b7 100644 --- a/src/ripple/core/impl/DatabaseCon.cpp +++ b/src/ripple/core/impl/DatabaseCon.cpp @@ -110,8 +110,7 @@ setup_DatabaseCon(Config const& c, std::optional j) setup.startUp = c.START_UP; setup.standAlone = c.standalone(); setup.reporting = c.reporting(); - std::cout << c.RELATIONAL_DB; - setup.sqlite3 = true; + setup.sqlite3 = false; setup.dataDir = c.legacy("database_path"); if (!setup.standAlone && setup.dataDir.empty()) {