diff --git a/src/ripple/app/consensus/RCLValidations.cpp b/src/ripple/app/consensus/RCLValidations.cpp index ab9391385dd..6b626569e69 100644 --- a/src/ripple/app/consensus/RCLValidations.cpp +++ b/src/ripple/app/consensus/RCLValidations.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -126,7 +127,13 @@ RCLValidationsAdaptor::now() const std::optional RCLValidationsAdaptor::acquire(LedgerHash const& hash) { - auto ledger = app_.getLedgerMaster().getLedgerByHash(hash); + using namespace std::chrono_literals; + auto ledger = perf::measureDurationAndLog( + [&]() { return app_.getLedgerMaster().getLedgerByHash(hash); }, + "getLedgerByHash", + 10ms, + j_); + if (!ledger) { JLOG(j_.debug()) diff --git a/src/ripple/app/ledger/impl/InboundLedgers.cpp b/src/ripple/app/ledger/impl/InboundLedgers.cpp index 0bff434edbc..b9b8b9fcfd2 100644 --- a/src/ripple/app/ledger/impl/InboundLedgers.cpp +++ b/src/ripple/app/ledger/impl/InboundLedgers.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -69,76 +70,83 @@ class InboundLedgersImp : public InboundLedgers std::uint32_t seq, InboundLedger::Reason reason) override { - assert(hash.isNonZero()); - assert( - reason != InboundLedger::Reason::SHARD || - (seq != 0 && app_.getShardStore())); - - // probably not the right rule - if (app_.getOPs().isNeedNetworkLedger() && - (reason != InboundLedger::Reason::GENERIC) && - (reason != InboundLedger::Reason::CONSENSUS)) - return {}; - - bool isNew = true; - std::shared_ptr inbound; - { - ScopedLockType sl(mLock); - if (stopping_) - { + auto doAcquire = [&, seq, reason]() -> std::shared_ptr { + assert(hash.isNonZero()); + assert( + reason != InboundLedger::Reason::SHARD || + (seq != 0 && app_.getShardStore())); + + // probably not the right rule + if (app_.getOPs().isNeedNetworkLedger() && + (reason != InboundLedger::Reason::GENERIC) && + (reason != InboundLedger::Reason::CONSENSUS)) return {}; - } - auto it = mLedgers.find(hash); - if (it != mLedgers.end()) + bool isNew = true; + std::shared_ptr inbound; { - isNew = false; - inbound = it->second; - } - else - { - inbound = std::make_shared( - app_, - hash, - seq, - reason, - std::ref(m_clock), - mPeerSetBuilder->build()); - mLedgers.emplace(hash, inbound); - inbound->init(sl); - ++mCounter; + ScopedLockType sl(mLock); + if (stopping_) + { + return {}; + } + + auto it = mLedgers.find(hash); + if (it != mLedgers.end()) + { + isNew = false; + inbound = it->second; + } + else + { + inbound = std::make_shared( + app_, + hash, + seq, + reason, + std::ref(m_clock), + mPeerSetBuilder->build()); + mLedgers.emplace(hash, inbound); + inbound->init(sl); + ++mCounter; + } } - } - if (inbound->isFailed()) - return {}; + if (inbound->isFailed()) + return {}; - if (!isNew) - inbound->update(seq); + if (!isNew) + inbound->update(seq); - if (!inbound->isComplete()) - return {}; + if (!inbound->isComplete()) + return {}; - if (reason == InboundLedger::Reason::HISTORY) - { - if (inbound->getLedger()->stateMap().family().isShardBacked()) - app_.getNodeStore().storeLedger(inbound->getLedger()); - } - else if (reason == InboundLedger::Reason::SHARD) - { - auto shardStore = app_.getShardStore(); - if (!shardStore) + if (reason == InboundLedger::Reason::HISTORY) { - JLOG(j_.error()) - << "Acquiring shard with no shard store available"; - return {}; + if (inbound->getLedger()->stateMap().family().isShardBacked()) + app_.getNodeStore().storeLedger(inbound->getLedger()); } - if (inbound->getLedger()->stateMap().family().isShardBacked()) - shardStore->setStored(inbound->getLedger()); - else - shardStore->storeLedger(inbound->getLedger()); - } - return inbound->getLedger(); + else if (reason == InboundLedger::Reason::SHARD) + { + auto shardStore = app_.getShardStore(); + if (!shardStore) + { + JLOG(j_.error()) + << "Acquiring shard with no shard store available"; + return {}; + } + if (inbound->getLedger()->stateMap().family().isShardBacked()) + shardStore->setStored(inbound->getLedger()); + else + shardStore->storeLedger(inbound->getLedger()); + } + return inbound->getLedger(); + }; + using namespace std::chrono_literals; + std::shared_ptr ledger = perf::measureDurationAndLog( + doAcquire, "InboundLedgersImp::acquire", 500ms, j_); + + return ledger; } std::shared_ptr diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 55300a390c9..b1305e46672 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -942,7 +942,7 @@ class ApplicationImp : public Application, public BasicApp auto setup = setup_DatabaseCon(*config_, m_journal); setup.useGlobalPragma = false; - mWalletDB = makeWalletDB(setup); + mWalletDB = makeWalletDB(setup, m_journal); } catch (std::exception const& e) { diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 710e4e9674f..02989b9ee6c 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -595,7 +595,7 @@ run(int argc, char** argv) try { auto setup = setup_DatabaseCon(*config); - if (!doVacuumDB(setup)) + if (!doVacuumDB(setup, config->journal())) return -1; } catch (std::exception const& e) diff --git a/src/ripple/app/rdb/Download.h b/src/ripple/app/rdb/Download.h index b72b5ec57e7..a16c9aa8788 100644 --- a/src/ripple/app/rdb/Download.h +++ b/src/ripple/app/rdb/Download.h @@ -36,13 +36,15 @@ namespace ripple { * download process or continues an existing one. * @param setup Path to the database and other opening parameters. * @param path Path of the new file to download. + * @param j Journal. * @return Pair containing a unique pointer to the database and the amount of * bytes already downloaded if a download is being continued. */ std::pair, std::optional> openDatabaseBodyDb( DatabaseCon::Setup const& setup, - boost::filesystem::path const& path); + boost::filesystem::path const& path, + beast::Journal j); /** * @brief databaseBodyDoPut Saves a new fragment of a downloaded file. diff --git a/src/ripple/app/rdb/ShardArchive.h b/src/ripple/app/rdb/ShardArchive.h index 20c4382b056..27db8279718 100644 --- a/src/ripple/app/rdb/ShardArchive.h +++ b/src/ripple/app/rdb/ShardArchive.h @@ -30,10 +30,14 @@ namespace ripple { * descriptor. * @param dir Path to the database to open. * @param dbName Name of the database. + * @param j Journal. * @return Unique pointer to the opened database. */ std::unique_ptr -makeArchiveDB(boost::filesystem::path const& dir, std::string const& dbName); +makeArchiveDB( + boost::filesystem::path const& dir, + std::string const& dbName, + beast::Journal j); /** * @brief readArchiveDB Reads entries from the shard archive database and diff --git a/src/ripple/app/rdb/UnitaryShard.h b/src/ripple/app/rdb/UnitaryShard.h index d2ac773dbd3..e9a2ac93d2d 100644 --- a/src/ripple/app/rdb/UnitaryShard.h +++ b/src/ripple/app/rdb/UnitaryShard.h @@ -39,13 +39,15 @@ struct DatabasePair * and returns their descriptors. * @param config Config object. * @param setup Path to the databases and other opening parameters. + * @param j Journal. * @return Pair of unique pointers to the opened ledger and transaction * databases. */ DatabasePair makeShardCompleteLedgerDBs( Config const& config, - DatabaseCon::Setup const& setup); + DatabaseCon::Setup const& setup, + beast::Journal j); /** * @brief makeShardIncompleteLedgerDBs Opens shard databases for partially @@ -53,6 +55,7 @@ makeShardCompleteLedgerDBs( * @param config Config object. * @param setup Path to the databases and other opening parameters. * @param checkpointerSetup Checkpointer parameters. + * @param j Journal. * @return Pair of unique pointers to the opened ledger and transaction * databases. */ @@ -60,7 +63,8 @@ DatabasePair makeShardIncompleteLedgerDBs( Config const& config, DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup); + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j); /** * @brief updateLedgerDBs Saves the given ledger to shard databases. @@ -86,12 +90,14 @@ updateLedgerDBs( * descriptor. * @param setup Path to the database and other opening parameters. * @param checkpointerSetup Checkpointer parameters. + * @param j Journal. * @return Unique pointer to the opened database. */ std::unique_ptr makeAcquireDB( DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup); + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j); /** * @brief insertAcquireDBIndex Adds a new shard index to the shard acquire diff --git a/src/ripple/app/rdb/Vacuum.h b/src/ripple/app/rdb/Vacuum.h index 3db18da045a..463f046e0a5 100644 --- a/src/ripple/app/rdb/Vacuum.h +++ b/src/ripple/app/rdb/Vacuum.h @@ -27,10 +27,11 @@ namespace ripple { /** * @brief doVacuumDB Creates, initialises, and performs cleanup on a database. * @param setup Path to the database and other opening parameters. + * @param j Journal. * @return True if the vacuum process completed successfully. */ bool -doVacuumDB(DatabaseCon::Setup const& setup); +doVacuumDB(DatabaseCon::Setup const& setup, beast::Journal j); } // namespace ripple diff --git a/src/ripple/app/rdb/Wallet.h b/src/ripple/app/rdb/Wallet.h index e9846714ece..6a15997ffe4 100644 --- a/src/ripple/app/rdb/Wallet.h +++ b/src/ripple/app/rdb/Wallet.h @@ -32,19 +32,24 @@ namespace ripple { /** * @brief makeWalletDB Opens the wallet database and returns it. * @param setup Path to the database and other opening parameters. + * @param j Journal. * @return Unique pointer to the database descriptor. */ std::unique_ptr -makeWalletDB(DatabaseCon::Setup const& setup); +makeWalletDB(DatabaseCon::Setup const& setup, beast::Journal j); /** * @brief makeTestWalletDB Opens a test wallet database with an arbitrary name. * @param setup Path to the database and other opening parameters. * @param dbname Name of the database. + * @param j Journal. * @return Unique pointer to the database descriptor. */ std::unique_ptr -makeTestWalletDB(DatabaseCon::Setup const& setup, std::string const& dbname); +makeTestWalletDB( + DatabaseCon::Setup const& setup, + std::string const& dbname, + beast::Journal j); /** * @brief getManifests Loads a manifest from the wallet database and stores it diff --git a/src/ripple/app/rdb/backend/detail/Node.h b/src/ripple/app/rdb/backend/detail/Node.h index ab3a99f5f95..2c3f264d7a9 100644 --- a/src/ripple/app/rdb/backend/detail/Node.h +++ b/src/ripple/app/rdb/backend/detail/Node.h @@ -47,6 +47,7 @@ struct DatabasePairValid * @param config Config object. * @param setup Path to database and opening parameters. * @param checkpointerSetup Database checkpointer setup. + * @param j Journal. * @return Struct DatabasePairValid which contain unique pointers to ledger * and transaction databases and flag if opening was successfull. */ @@ -54,7 +55,8 @@ DatabasePairValid makeLedgerDBs( Config const& config, DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup); + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j); /** * @brief getMinLedgerSeq Returns minimum ledger sequence in given table. diff --git a/src/ripple/app/rdb/backend/detail/Shard.h b/src/ripple/app/rdb/backend/detail/Shard.h index ac88c24bd78..02e75d2aa64 100644 --- a/src/ripple/app/rdb/backend/detail/Shard.h +++ b/src/ripple/app/rdb/backend/detail/Shard.h @@ -37,6 +37,7 @@ namespace detail { * @param config Config object. * @param setup Path to database and opening parameters. * @param checkpointerSetup Database checkpointer setup. + * @param j Journal. * @return Struct DatabasePair which contains unique pointers to the ledger * and transaction databases. */ @@ -44,7 +45,8 @@ DatabasePair makeMetaDBs( Config const& config, DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup); + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j); /** * @brief saveLedgerMeta Stores (transaction ID -> shard index) and diff --git a/src/ripple/app/rdb/backend/detail/impl/Node.cpp b/src/ripple/app/rdb/backend/detail/impl/Node.cpp index 0905d6121ae..894cae1385c 100644 --- a/src/ripple/app/rdb/backend/detail/impl/Node.cpp +++ b/src/ripple/app/rdb/backend/detail/impl/Node.cpp @@ -67,11 +67,12 @@ DatabasePairValid makeLedgerDBs( Config const& config, DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup) + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j) { // ledger database auto lgr{std::make_unique( - setup, LgrDBName, LgrDBPragma, LgrDBInit, checkpointerSetup)}; + setup, LgrDBName, LgrDBPragma, LgrDBInit, checkpointerSetup, j)}; lgr->getSession() << boost::str( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::lgrDBCache))); @@ -80,7 +81,7 @@ makeLedgerDBs( { // transaction database auto tx{std::make_unique( - setup, TxDBName, TxDBPragma, TxDBInit, checkpointerSetup)}; + setup, TxDBName, TxDBPragma, TxDBInit, checkpointerSetup, j)}; tx->getSession() << boost::str( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::txnDBCache))); diff --git a/src/ripple/app/rdb/backend/detail/impl/Shard.cpp b/src/ripple/app/rdb/backend/detail/impl/Shard.cpp index f7a0ce4571b..540e8d1d221 100644 --- a/src/ripple/app/rdb/backend/detail/impl/Shard.cpp +++ b/src/ripple/app/rdb/backend/detail/impl/Shard.cpp @@ -32,7 +32,8 @@ DatabasePair makeMetaDBs( Config const& config, DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup) + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j) { // ledger meta database auto lgrMetaDB{std::make_unique( @@ -40,14 +41,20 @@ makeMetaDBs( LgrMetaDBName, LgrMetaDBPragma, LgrMetaDBInit, - checkpointerSetup)}; + checkpointerSetup, + j)}; if (!config.useTxTables()) return {std::move(lgrMetaDB), nullptr}; // transaction meta database auto txMetaDB{std::make_unique( - setup, TxMetaDBName, TxMetaDBPragma, TxMetaDBInit, checkpointerSetup)}; + setup, + TxMetaDBName, + TxMetaDBPragma, + TxMetaDBInit, + checkpointerSetup, + j)}; return {std::move(lgrMetaDB), std::move(txMetaDB)}; } diff --git a/src/ripple/app/rdb/backend/impl/SQLiteDatabase.cpp b/src/ripple/app/rdb/backend/impl/SQLiteDatabase.cpp index 547ab843b36..05a460819d0 100644 --- a/src/ripple/app/rdb/backend/impl/SQLiteDatabase.cpp +++ b/src/ripple/app/rdb/backend/impl/SQLiteDatabase.cpp @@ -447,7 +447,7 @@ SQLiteDatabaseImp::makeLedgerDBs( DatabaseCon::CheckpointerSetup const& checkpointerSetup) { auto [lgr, tx, res] = - detail::makeLedgerDBs(config, setup, checkpointerSetup); + detail::makeLedgerDBs(config, setup, checkpointerSetup, j_); txdb_ = std::move(tx); lgrdb_ = std::move(lgr); return res; @@ -460,7 +460,7 @@ SQLiteDatabaseImp::makeMetaDBs( DatabaseCon::CheckpointerSetup const& checkpointerSetup) { auto [lgrMetaDB, txMetaDB] = - detail::makeMetaDBs(config, setup, checkpointerSetup); + detail::makeMetaDBs(config, setup, checkpointerSetup, j_); txMetaDB_ = std::move(txMetaDB); lgrMetaDB_ = std::move(lgrMetaDB); diff --git a/src/ripple/app/rdb/impl/Download.cpp b/src/ripple/app/rdb/impl/Download.cpp index 0905ee577b1..6f6d6bf7577 100644 --- a/src/ripple/app/rdb/impl/Download.cpp +++ b/src/ripple/app/rdb/impl/Download.cpp @@ -25,14 +25,15 @@ namespace ripple { std::pair, std::optional> openDatabaseBodyDb( DatabaseCon::Setup const& setup, - boost::filesystem::path const& path) + boost::filesystem::path const& path, + beast::Journal j) { // SOCI requires boost::optional (not std::optional) as the parameter. boost::optional pathFromDb; boost::optional size; auto conn = std::make_unique( - setup, "Download", DownloaderDBPragma, DatabaseBodyDBInit); + setup, "Download", DownloaderDBPragma, DatabaseBodyDBInit, j); auto& session = *conn->checkoutDb(); diff --git a/src/ripple/app/rdb/impl/ShardArchive.cpp b/src/ripple/app/rdb/impl/ShardArchive.cpp index 6880aa00136..edad36f7099 100644 --- a/src/ripple/app/rdb/impl/ShardArchive.cpp +++ b/src/ripple/app/rdb/impl/ShardArchive.cpp @@ -22,10 +22,13 @@ namespace ripple { std::unique_ptr -makeArchiveDB(boost::filesystem::path const& dir, std::string const& dbName) +makeArchiveDB( + boost::filesystem::path const& dir, + std::string const& dbName, + beast::Journal j) { return std::make_unique( - dir, dbName, DownloaderDBPragma, ShardArchiveHandlerDBInit); + dir, dbName, DownloaderDBPragma, ShardArchiveHandlerDBInit, j); } void diff --git a/src/ripple/app/rdb/impl/UnitaryShard.cpp b/src/ripple/app/rdb/impl/UnitaryShard.cpp index ab1758b4852..786340f5955 100644 --- a/src/ripple/app/rdb/impl/UnitaryShard.cpp +++ b/src/ripple/app/rdb/impl/UnitaryShard.cpp @@ -27,16 +27,17 @@ namespace ripple { DatabasePair makeShardCompleteLedgerDBs( Config const& config, - DatabaseCon::Setup const& setup) + DatabaseCon::Setup const& setup, + beast::Journal j) { auto tx{std::make_unique( - setup, TxDBName, FinalShardDBPragma, TxDBInit)}; + setup, TxDBName, FinalShardDBPragma, TxDBInit, j)}; tx->getSession() << boost::str( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::txnDBCache, std::nullopt))); auto lgr{std::make_unique( - setup, LgrDBName, FinalShardDBPragma, LgrDBInit)}; + setup, LgrDBName, FinalShardDBPragma, LgrDBInit, j)}; lgr->getSession() << boost::str( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::lgrDBCache, std::nullopt))); @@ -48,18 +49,19 @@ DatabasePair makeShardIncompleteLedgerDBs( Config const& config, DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup) + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j) { // transaction database auto tx{std::make_unique( - setup, TxDBName, TxDBPragma, TxDBInit, checkpointerSetup)}; + setup, TxDBName, TxDBPragma, TxDBInit, checkpointerSetup, j)}; tx->getSession() << boost::str( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::txnDBCache))); // ledger database auto lgr{std::make_unique( - setup, LgrDBName, LgrDBPragma, LgrDBInit, checkpointerSetup)}; + setup, LgrDBName, LgrDBPragma, LgrDBInit, checkpointerSetup, j)}; lgr->getSession() << boost::str( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::lgrDBCache))); @@ -209,14 +211,16 @@ updateLedgerDBs( std::unique_ptr makeAcquireDB( DatabaseCon::Setup const& setup, - DatabaseCon::CheckpointerSetup const& checkpointerSetup) + DatabaseCon::CheckpointerSetup const& checkpointerSetup, + beast::Journal j) { return std::make_unique( setup, AcquireShardDBName, AcquireShardDBPragma, AcquireShardDBInit, - checkpointerSetup); + checkpointerSetup, + j); } void diff --git a/src/ripple/app/rdb/impl/Vacuum.cpp b/src/ripple/app/rdb/impl/Vacuum.cpp index aad456cc5a8..20386f07b18 100644 --- a/src/ripple/app/rdb/impl/Vacuum.cpp +++ b/src/ripple/app/rdb/impl/Vacuum.cpp @@ -23,7 +23,7 @@ namespace ripple { bool -doVacuumDB(DatabaseCon::Setup const& setup) +doVacuumDB(DatabaseCon::Setup const& setup, beast::Journal j) { boost::filesystem::path dbPath = setup.dataDir / TxDBName; @@ -41,7 +41,7 @@ doVacuumDB(DatabaseCon::Setup const& setup) } auto txnDB = - std::make_unique(setup, TxDBName, TxDBPragma, TxDBInit); + std::make_unique(setup, TxDBName, TxDBPragma, TxDBInit, j); auto& session = txnDB->getSession(); std::uint32_t pageSize; diff --git a/src/ripple/app/rdb/impl/Wallet.cpp b/src/ripple/app/rdb/impl/Wallet.cpp index 3715c4c7458..79734ab67dc 100644 --- a/src/ripple/app/rdb/impl/Wallet.cpp +++ b/src/ripple/app/rdb/impl/Wallet.cpp @@ -23,19 +23,22 @@ namespace ripple { std::unique_ptr -makeWalletDB(DatabaseCon::Setup const& setup) +makeWalletDB(DatabaseCon::Setup const& setup, beast::Journal j) { // wallet database return std::make_unique( - setup, WalletDBName, std::array(), WalletDBInit); + setup, WalletDBName, std::array(), WalletDBInit, j); } std::unique_ptr -makeTestWalletDB(DatabaseCon::Setup const& setup, std::string const& dbname) +makeTestWalletDB( + DatabaseCon::Setup const& setup, + std::string const& dbname, + beast::Journal j) { // wallet database return std::make_unique( - setup, dbname.data(), std::array(), WalletDBInit); + setup, dbname.data(), std::array(), WalletDBInit, j); } void diff --git a/src/ripple/basics/PerfLog.h b/src/ripple/basics/PerfLog.h index 3d1cb371715..49ed27338db 100644 --- a/src/ripple/basics/PerfLog.h +++ b/src/ripple/basics/PerfLog.h @@ -179,6 +179,30 @@ make_PerfLog( beast::Journal journal, std::function&& signalStop); +template +auto +measureDurationAndLog( + Func&& func, + const std::string& actionDescription, + std::chrono::duration maxDelay, + const beast::Journal& journal) +{ + auto start_time = std::chrono::high_resolution_clock::now(); + + auto result = func(); + + auto end_time = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast( + end_time - start_time); + if (duration > maxDelay) + { + JLOG(journal.warn()) + << actionDescription << " took " << duration.count() << " ms"; + } + + return result; +} + } // namespace perf } // namespace ripple diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index cf41678a16c..25852615185 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -396,6 +396,12 @@ class Config : public BasicConfig int getValueFor(SizedItem item, std::optional node = std::nullopt) const; + + beast::Journal + journal() const + { + return j_; + } }; FeeSetup diff --git a/src/ripple/core/DatabaseCon.h b/src/ripple/core/DatabaseCon.h index 59eec3a32e9..91d2a446668 100644 --- a/src/ripple/core/DatabaseCon.h +++ b/src/ripple/core/DatabaseCon.h @@ -21,6 +21,7 @@ #define RIPPLE_APP_DATA_DATABASECON_H_INCLUDED #include +#include #include #include #include @@ -115,7 +116,8 @@ class DatabaseCon Setup const& setup, std::string const& dbName, std::array const& pragma, - std::array const& initSQL) + std::array const& initSQL, + beast::Journal journal) // Use temporary files or regular DB files? : DatabaseCon( setup.standAlone && !setup.reporting && @@ -126,7 +128,8 @@ class DatabaseCon : (setup.dataDir / dbName), setup.commonPragma(), pragma, - initSQL) + initSQL, + journal) { } @@ -137,8 +140,9 @@ class DatabaseCon std::string const& dbName, std::array const& pragma, std::array const& initSQL, - CheckpointerSetup const& checkpointerSetup) - : DatabaseCon(setup, dbName, pragma, initSQL) + CheckpointerSetup const& checkpointerSetup, + beast::Journal journal) + : DatabaseCon(setup, dbName, pragma, initSQL, journal) { setupCheckpointing(checkpointerSetup.jobQueue, *checkpointerSetup.logs); } @@ -148,8 +152,9 @@ class DatabaseCon boost::filesystem::path const& dataDir, std::string const& dbName, std::array const& pragma, - std::array const& initSQL) - : DatabaseCon(dataDir / dbName, nullptr, pragma, initSQL) + std::array const& initSQL, + beast::Journal journal) + : DatabaseCon(dataDir / dbName, nullptr, pragma, initSQL, journal) { } @@ -160,8 +165,9 @@ class DatabaseCon std::string const& dbName, std::array const& pragma, std::array const& initSQL, - CheckpointerSetup const& checkpointerSetup) - : DatabaseCon(dataDir, dbName, pragma, initSQL) + CheckpointerSetup const& checkpointerSetup, + beast::Journal journal) + : DatabaseCon(dataDir, dbName, pragma, initSQL, journal) { setupCheckpointing(checkpointerSetup.jobQueue, *checkpointerSetup.logs); } @@ -177,7 +183,14 @@ class DatabaseCon LockedSociSession checkoutDb() { - return LockedSociSession(session_, lock_); + using namespace std::chrono_literals; + LockedSociSession session = perf::measureDurationAndLog( + [&]() { return LockedSociSession(session_, lock_); }, + "checkoutDb", + 10ms, + j_); + + return session; } private: @@ -189,8 +202,9 @@ class DatabaseCon boost::filesystem::path const& pPath, std::vector const* commonPragma, std::array const& pragma, - std::array const& initSQL) - : session_(std::make_shared()) + std::array const& initSQL, + beast::Journal journal) + : session_(std::make_shared()), j_(journal) { open(*session_, "sqlite", pPath.string()); @@ -224,6 +238,8 @@ class DatabaseCon // shared_ptr in this class. session_ will never be null. std::shared_ptr const session_; std::shared_ptr checkpointer_; + + beast::Journal const j_; }; // Return the checkpointer from its id. If the checkpointer no longer exists, an diff --git a/src/ripple/net/DatabaseBody.h b/src/ripple/net/DatabaseBody.h index c828e5bf123..4c74b879a59 100644 --- a/src/ripple/net/DatabaseBody.h +++ b/src/ripple/net/DatabaseBody.h @@ -102,13 +102,16 @@ class DatabaseBody::value_type @param io_service The asio context for running a strand. @param ec Set to the error, if any occurred + + @param j Journal. */ void open( boost::filesystem::path const& path, Config const& config, boost::asio::io_service& io_service, - boost::system::error_code& ec); + boost::system::error_code& ec, + beast::Journal j); }; /** Algorithm for storing buffers when parsing. diff --git a/src/ripple/net/DatabaseDownloader.h b/src/ripple/net/DatabaseDownloader.h index 3e920909417..476939e1ff4 100644 --- a/src/ripple/net/DatabaseDownloader.h +++ b/src/ripple/net/DatabaseDownloader.h @@ -43,7 +43,8 @@ class DatabaseDownloader : public HTTPDownloader getParser( boost::filesystem::path dstPath, std::function complete, - boost::system::error_code& ec) override; + boost::system::error_code& ec, + beast::Journal j) override; bool checkPath(boost::filesystem::path const& dstPath) override; diff --git a/src/ripple/net/HTTPDownloader.h b/src/ripple/net/HTTPDownloader.h index 39b9a904aa3..34e81ea1f06 100644 --- a/src/ripple/net/HTTPDownloader.h +++ b/src/ripple/net/HTTPDownloader.h @@ -113,7 +113,8 @@ class HTTPDownloader : public std::enable_shared_from_this getParser( boost::filesystem::path dstPath, std::function complete, - boost::system::error_code& ec) = 0; + boost::system::error_code& ec, + beast::Journal j) = 0; virtual bool checkPath(boost::filesystem::path const& dstPath) = 0; diff --git a/src/ripple/net/impl/DatabaseBody.ipp b/src/ripple/net/impl/DatabaseBody.ipp index cdc7da2bc41..875a883527f 100644 --- a/src/ripple/net/impl/DatabaseBody.ipp +++ b/src/ripple/net/impl/DatabaseBody.ipp @@ -46,7 +46,8 @@ DatabaseBody::value_type::open( boost::filesystem::path const& path, Config const& config, boost::asio::io_service& io_service, - boost::system::error_code& ec) + boost::system::error_code& ec, + beast::Journal j) { strand_.reset(new boost::asio::io_service::strand(io_service)); path_ = path; @@ -55,7 +56,7 @@ DatabaseBody::value_type::open( setup.dataDir = path.parent_path(); setup.useGlobalPragma = false; - auto [conn, size] = openDatabaseBodyDb(setup, path); + auto [conn, size] = openDatabaseBodyDb(setup, path, j); conn_ = std::move(conn); if (size) fileSize_ = *size; diff --git a/src/ripple/net/impl/DatabaseDownloader.cpp b/src/ripple/net/impl/DatabaseDownloader.cpp index eab0d74d7d9..52388cf0d1d 100644 --- a/src/ripple/net/impl/DatabaseDownloader.cpp +++ b/src/ripple/net/impl/DatabaseDownloader.cpp @@ -45,13 +45,14 @@ auto DatabaseDownloader::getParser( boost::filesystem::path dstPath, std::function complete, - boost::system::error_code& ec) -> std::shared_ptr + boost::system::error_code& ec, + beast::Journal j) -> std::shared_ptr { using namespace boost::beast; auto p = std::make_shared>(); p->body_limit(std::numeric_limits::max()); - p->get().body().open(dstPath, config_, io_service_, ec); + p->get().body().open(dstPath, config_, io_service_, ec, j); if (ec) p->get().body().close(); diff --git a/src/ripple/net/impl/HTTPDownloader.cpp b/src/ripple/net/impl/HTTPDownloader.cpp index 44d27466224..43bf8d92589 100644 --- a/src/ripple/net/impl/HTTPDownloader.cpp +++ b/src/ripple/net/impl/HTTPDownloader.cpp @@ -146,7 +146,7 @@ HTTPDownloader::do_session( if (stop_.load()) return exit(); - auto p = this->getParser(dstPath, complete, ec); + auto p = this->getParser(dstPath, complete, ec, j_); if (ec) return failAndExit("getParser", p); diff --git a/src/ripple/nodestore/impl/Shard.cpp b/src/ripple/nodestore/impl/Shard.cpp index 10adf298361..f05f56903d2 100644 --- a/src/ripple/nodestore/impl/Shard.cpp +++ b/src/ripple/nodestore/impl/Shard.cpp @@ -862,7 +862,8 @@ Shard::open(std::lock_guard const& lock) acquireInfo_ = std::make_unique(); acquireInfo_->SQLiteDB = makeAcquireDB( setup, - DatabaseCon::CheckpointerSetup{&app_.getJobQueue(), &app_.logs()}); + DatabaseCon::CheckpointerSetup{&app_.getJobQueue(), &app_.logs()}, + j_); state_ = ShardState::acquire; progress_ = 0; @@ -981,7 +982,7 @@ Shard::initSQLite(std::lock_guard const&) case ShardState::complete: case ShardState::finalizing: case ShardState::finalized: { - auto [lgr, tx] = makeShardCompleteLedgerDBs(config, setup); + auto [lgr, tx] = makeShardCompleteLedgerDBs(config, setup, j_); lgrSQLiteDB_ = std::move(lgr); lgrSQLiteDB_->getSession() << boost::str( @@ -1005,7 +1006,8 @@ Shard::initSQLite(std::lock_guard const&) config, setup, DatabaseCon::CheckpointerSetup{ - &app_.getJobQueue(), &app_.logs()}); + &app_.getJobQueue(), &app_.logs()}, + j_); lgrSQLiteDB_ = std::move(lgr); lgrSQLiteDB_->getSession() << boost::str( diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index f93c9f135ad..69ef6061d59 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -920,8 +921,16 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytes_transferred) while (read_buffer_.size() > 0) { std::size_t bytes_consumed; - std::tie(bytes_consumed, ec) = - invokeProtocolMessage(read_buffer_.data(), *this, hint); + + using namespace std::chrono_literals; + std::tie(bytes_consumed, ec) = perf::measureDurationAndLog( + [&]() { + return invokeProtocolMessage(read_buffer_.data(), *this, hint); + }, + "invokeProtocolMessage", + 350ms, + journal_); + if (ec) return fail("onReadMessage", ec); if (!socket_.is_open()) diff --git a/src/ripple/rpc/impl/ShardArchiveHandler.cpp b/src/ripple/rpc/impl/ShardArchiveHandler.cpp index d05744f483a..90bd5edc361 100644 --- a/src/ripple/rpc/impl/ShardArchiveHandler.cpp +++ b/src/ripple/rpc/impl/ShardArchiveHandler.cpp @@ -114,7 +114,7 @@ ShardArchiveHandler::init() { create_directories(downloadDir_); - sqlDB_ = makeArchiveDB(downloadDir_, stateDBName); + sqlDB_ = makeArchiveDB(downloadDir_, stateDBName, j_); } catch (std::exception const& e) { @@ -139,7 +139,7 @@ ShardArchiveHandler::initFromDB(std::lock_guard const& lock) exists(downloadDir_ / stateDBName) && is_regular_file(downloadDir_ / stateDBName)); - sqlDB_ = makeArchiveDB(downloadDir_, stateDBName); + sqlDB_ = makeArchiveDB(downloadDir_, stateDBName, j_); readArchiveDB(*sqlDB_, [&](std::string const& url_, int state) { parsedURL url; diff --git a/src/test/app/Manifest_test.cpp b/src/test/app/Manifest_test.cpp index b72623309e9..0f21cab0d63 100644 --- a/src/test/app/Manifest_test.cpp +++ b/src/test/app/Manifest_test.cpp @@ -255,7 +255,7 @@ class Manifest_test : public beast::unit_test::suite setup.dataDir = getDatabasePath(); assert(!setup.useGlobalPragma); - auto dbCon = makeTestWalletDB(setup, dbName); + auto dbCon = makeTestWalletDB(setup, dbName, env.journal); auto getPopulatedManifests = [](ManifestCache const& cache) -> std::vector {