Track latencies of certain code blocks, and log if they take too long

This commit is contained in:
Valentin Balaschenko
2024-08-23 14:43:02 -04:00
committed by Ed Hennis
parent e6ef0fc26c
commit 00ed7c9424
32 changed files with 250 additions and 130 deletions

View File

@@ -25,6 +25,7 @@
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/misc/ValidatorList.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/PerfLog.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/basics/chrono.h>
#include <ripple/consensus/LedgerTiming.h>
@@ -126,7 +127,13 @@ RCLValidationsAdaptor::now() const
std::optional<RCLValidatedLedger>
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())

View File

@@ -23,6 +23,7 @@
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/basics/DecayingSample.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/PerfLog.h>
#include <ripple/beast/container/aged_map.h>
#include <ripple/beast/core/LexicalCast.h>
#include <ripple/core/JobQueue.h>
@@ -69,76 +70,83 @@ public:
std::uint32_t seq,
InboundLedger::Reason reason) override
{
assert(hash.isNonZero());
assert(
reason != InboundLedger::Reason::SHARD ||
(seq != 0 && app_.getShardStore()));
auto doAcquire = [&, seq, reason]() -> std::shared_ptr<Ledger const> {
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<InboundLedger> inbound;
{
ScopedLockType sl(mLock);
if (stopping_)
{
// probably not the right rule
if (app_.getOPs().isNeedNetworkLedger() &&
(reason != InboundLedger::Reason::GENERIC) &&
(reason != InboundLedger::Reason::CONSENSUS))
return {};
bool isNew = true;
std::shared_ptr<InboundLedger> inbound;
{
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<InboundLedger>(
app_,
hash,
seq,
reason,
std::ref(m_clock),
mPeerSetBuilder->build());
mLedgers.emplace(hash, inbound);
inbound->init(sl);
++mCounter;
}
}
auto it = mLedgers.find(hash);
if (it != mLedgers.end())
{
isNew = false;
inbound = it->second;
}
else
{
inbound = std::make_shared<InboundLedger>(
app_,
hash,
seq,
reason,
std::ref(m_clock),
mPeerSetBuilder->build());
mLedgers.emplace(hash, inbound);
inbound->init(sl);
++mCounter;
}
}
if (inbound->isFailed())
return {};
if (!isNew)
inbound->update(seq);
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)
{
JLOG(j_.error())
<< "Acquiring shard with no shard store available";
if (inbound->isFailed())
return {};
if (!isNew)
inbound->update(seq);
if (!inbound->isComplete())
return {};
if (reason == InboundLedger::Reason::HISTORY)
{
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 const> ledger = perf::measureDurationAndLog(
doAcquire, "InboundLedgersImp::acquire", 500ms, j_);
return ledger;
}
std::shared_ptr<InboundLedger>

View File

@@ -942,7 +942,7 @@ public:
auto setup = setup_DatabaseCon(*config_, m_journal);
setup.useGlobalPragma = false;
mWalletDB = makeWalletDB(setup);
mWalletDB = makeWalletDB(setup, m_journal);
}
catch (std::exception const& e)
{

View File

@@ -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)

View File

@@ -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::unique_ptr<DatabaseCon>, std::optional<std::uint64_t>>
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.

View File

@@ -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<DatabaseCon>
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

View File

@@ -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<DatabaseCon>
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

View File

@@ -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

View File

@@ -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<DatabaseCon>
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<DatabaseCon>
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

View File

@@ -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.

View File

@@ -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

View File

@@ -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<DatabaseCon>(
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<DatabaseCon>(
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)));

View File

@@ -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<DatabaseCon>(
@@ -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<DatabaseCon>(
setup, TxMetaDBName, TxMetaDBPragma, TxMetaDBInit, checkpointerSetup)};
setup,
TxMetaDBName,
TxMetaDBPragma,
TxMetaDBInit,
checkpointerSetup,
j)};
return {std::move(lgrMetaDB), std::move(txMetaDB)};
}

View File

@@ -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);

View File

@@ -25,14 +25,15 @@ namespace ripple {
std::pair<std::unique_ptr<DatabaseCon>, std::optional<std::uint64_t>>
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<std::string> pathFromDb;
boost::optional<std::uint64_t> size;
auto conn = std::make_unique<DatabaseCon>(
setup, "Download", DownloaderDBPragma, DatabaseBodyDBInit);
setup, "Download", DownloaderDBPragma, DatabaseBodyDBInit, j);
auto& session = *conn->checkoutDb();

View File

@@ -22,10 +22,13 @@
namespace ripple {
std::unique_ptr<DatabaseCon>
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<DatabaseCon>(
dir, dbName, DownloaderDBPragma, ShardArchiveHandlerDBInit);
dir, dbName, DownloaderDBPragma, ShardArchiveHandlerDBInit, j);
}
void

View File

@@ -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<DatabaseCon>(
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<DatabaseCon>(
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<DatabaseCon>(
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<DatabaseCon>(
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<DatabaseCon>
makeAcquireDB(
DatabaseCon::Setup const& setup,
DatabaseCon::CheckpointerSetup const& checkpointerSetup)
DatabaseCon::CheckpointerSetup const& checkpointerSetup,
beast::Journal j)
{
return std::make_unique<DatabaseCon>(
setup,
AcquireShardDBName,
AcquireShardDBPragma,
AcquireShardDBInit,
checkpointerSetup);
checkpointerSetup,
j);
}
void

View File

@@ -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<DatabaseCon>(setup, TxDBName, TxDBPragma, TxDBInit);
std::make_unique<DatabaseCon>(setup, TxDBName, TxDBPragma, TxDBInit, j);
auto& session = txnDB->getSession();
std::uint32_t pageSize;

View File

@@ -23,19 +23,22 @@
namespace ripple {
std::unique_ptr<DatabaseCon>
makeWalletDB(DatabaseCon::Setup const& setup)
makeWalletDB(DatabaseCon::Setup const& setup, beast::Journal j)
{
// wallet database
return std::make_unique<DatabaseCon>(
setup, WalletDBName, std::array<char const*, 0>(), WalletDBInit);
setup, WalletDBName, std::array<char const*, 0>(), WalletDBInit, j);
}
std::unique_ptr<DatabaseCon>
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<DatabaseCon>(
setup, dbname.data(), std::array<char const*, 0>(), WalletDBInit);
setup, dbname.data(), std::array<char const*, 0>(), WalletDBInit, j);
}
void

View File

@@ -179,6 +179,30 @@ make_PerfLog(
beast::Journal journal,
std::function<void()>&& signalStop);
template <typename Func, class Rep, class Period>
auto
measureDurationAndLog(
Func&& func,
const std::string& actionDescription,
std::chrono::duration<Rep, Period> 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<std::chrono::milliseconds>(
end_time - start_time);
if (duration > maxDelay)
{
JLOG(journal.warn())
<< actionDescription << " took " << duration.count() << " ms";
}
return result;
}
} // namespace perf
} // namespace ripple

View File

@@ -396,6 +396,12 @@ public:
int
getValueFor(SizedItem item, std::optional<std::size_t> node = std::nullopt)
const;
beast::Journal
journal() const
{
return j_;
}
};
FeeSetup

View File

@@ -21,6 +21,7 @@
#define RIPPLE_APP_DATA_DATABASECON_H_INCLUDED
#include <ripple/app/main/DBInit.h>
#include <ripple/basics/PerfLog.h>
#include <ripple/core/Config.h>
#include <ripple/core/SociDB.h>
#include <boost/filesystem/path.hpp>
@@ -115,7 +116,8 @@ public:
Setup const& setup,
std::string const& dbName,
std::array<char const*, N> const& pragma,
std::array<char const*, M> const& initSQL)
std::array<char const*, M> const& initSQL,
beast::Journal journal)
// Use temporary files or regular DB files?
: DatabaseCon(
setup.standAlone && !setup.reporting &&
@@ -126,7 +128,8 @@ public:
: (setup.dataDir / dbName),
setup.commonPragma(),
pragma,
initSQL)
initSQL,
journal)
{
}
@@ -137,8 +140,9 @@ public:
std::string const& dbName,
std::array<char const*, N> const& pragma,
std::array<char const*, M> 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 @@ public:
boost::filesystem::path const& dataDir,
std::string const& dbName,
std::array<char const*, N> const& pragma,
std::array<char const*, M> const& initSQL)
: DatabaseCon(dataDir / dbName, nullptr, pragma, initSQL)
std::array<char const*, M> const& initSQL,
beast::Journal journal)
: DatabaseCon(dataDir / dbName, nullptr, pragma, initSQL, journal)
{
}
@@ -160,8 +165,9 @@ public:
std::string const& dbName,
std::array<char const*, N> const& pragma,
std::array<char const*, M> 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 @@ public:
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 @@ private:
boost::filesystem::path const& pPath,
std::vector<std::string> const* commonPragma,
std::array<char const*, N> const& pragma,
std::array<char const*, M> const& initSQL)
: session_(std::make_shared<soci::session>())
std::array<char const*, M> const& initSQL,
beast::Journal journal)
: session_(std::make_shared<soci::session>()), j_(journal)
{
open(*session_, "sqlite", pPath.string());
@@ -224,6 +238,8 @@ private:
// shared_ptr in this class. session_ will never be null.
std::shared_ptr<soci::session> const session_;
std::shared_ptr<Checkpointer> checkpointer_;
beast::Journal const j_;
};
// Return the checkpointer from its id. If the checkpointer no longer exists, an

View File

@@ -102,13 +102,16 @@ public:
@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.

View File

@@ -43,7 +43,8 @@ private:
getParser(
boost::filesystem::path dstPath,
std::function<void(boost::filesystem::path)> complete,
boost::system::error_code& ec) override;
boost::system::error_code& ec,
beast::Journal j) override;
bool
checkPath(boost::filesystem::path const& dstPath) override;

View File

@@ -113,7 +113,8 @@ private:
getParser(
boost::filesystem::path dstPath,
std::function<void(boost::filesystem::path)> 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;

View File

@@ -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;

View File

@@ -45,13 +45,14 @@ auto
DatabaseDownloader::getParser(
boost::filesystem::path dstPath,
std::function<void(boost::filesystem::path)> complete,
boost::system::error_code& ec) -> std::shared_ptr<parser>
boost::system::error_code& ec,
beast::Journal j) -> std::shared_ptr<parser>
{
using namespace boost::beast;
auto p = std::make_shared<http::response_parser<DatabaseBody>>();
p->body_limit(std::numeric_limits<std::uint64_t>::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();

View File

@@ -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);

View File

@@ -862,7 +862,8 @@ Shard::open(std::lock_guard<std::mutex> const& lock)
acquireInfo_ = std::make_unique<AcquireInfo>();
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<std::mutex> 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<std::mutex> const&)
config,
setup,
DatabaseCon::CheckpointerSetup{
&app_.getJobQueue(), &app_.logs()});
&app_.getJobQueue(), &app_.logs()},
j_);
lgrSQLiteDB_ = std::move(lgr);
lgrSQLiteDB_->getSession() << boost::str(

View File

@@ -28,6 +28,7 @@
#include <ripple/app/misc/Transaction.h>
#include <ripple/app/misc/ValidatorList.h>
#include <ripple/app/tx/apply.h>
#include <ripple/basics/PerfLog.h>
#include <ripple/basics/UptimeClock.h>
#include <ripple/basics/base64.h>
#include <ripple/basics/random.h>
@@ -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())

View File

@@ -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<std::mutex> 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;

View File

@@ -255,7 +255,7 @@ public:
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<Manifest const*> {