mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-29 15:05:50 +00:00
Fix node auto-configuration code:
The `node_size` configuration option is used to automatically
configure various parameters (cache sizes, timeouts, etc) for
the server.
A previous commit included changes that caused incorrect values
to be returned which can result in sub-optimal performance that
can manifest as difficulty syncing to the network, or increased
disk I/O and/or memory usage. The problem was introduced with
commit 66fad62e66.
This commit, if merged, fixes the code to ensure that the correct
values are returned and introduces a compile-time check to prevent
this issue from reoccurring.
This commit is contained in:
@@ -422,24 +422,25 @@ Shard::setCache(std::lock_guard<std::mutex> const&)
|
||||
if (!pCache_)
|
||||
{
|
||||
auto const name {"shard " + std::to_string(index_)};
|
||||
auto const sz {complete_ ?
|
||||
Config::getSize(siNodeCacheSize, 0) :
|
||||
app_.config().getSize(siNodeCacheSize)};
|
||||
auto const age {std::chrono::seconds{complete_ ?
|
||||
Config::getSize(siNodeCacheAge, 0) :
|
||||
app_.config().getSize(siNodeCacheAge)}};
|
||||
auto const sz = app_.config().getValueFor(SizedItem::nodeCacheSize,
|
||||
complete_ ? boost::optional<std::size_t>(0) : boost::none);
|
||||
auto const age = std::chrono::seconds{
|
||||
app_.config().getValueFor(SizedItem::nodeCacheAge,
|
||||
complete_ ? boost::optional<std::size_t>(0) : boost::none)};
|
||||
|
||||
pCache_ = std::make_shared<PCache>(name, sz, age, stopwatch(), j_);
|
||||
nCache_ = std::make_shared<NCache>(name, stopwatch(), sz, age);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const sz {Config::getSize(siNodeCacheSize, 0)};
|
||||
auto const sz = app_.config().getValueFor(
|
||||
SizedItem::nodeCacheSize, 0);
|
||||
pCache_->setTargetSize(sz);
|
||||
nCache_->setTargetSize(sz);
|
||||
|
||||
auto const age {std::chrono::seconds{
|
||||
Config::getSize(siNodeCacheAge, 0)}};
|
||||
auto const age = std::chrono::seconds{
|
||||
app_.config().getValueFor(
|
||||
SizedItem::nodeCacheAge, 0)};
|
||||
pCache_->setTargetAge(age);
|
||||
nCache_->setTargetAge(age);
|
||||
}
|
||||
@@ -496,7 +497,7 @@ Shard::initSQLite(std::lock_guard<std::mutex> const&)
|
||||
LgrDBInit);
|
||||
lgrSQLiteDB_->getSession() <<
|
||||
boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||
kilobytes(Config::getSize(siLgrDBCache, 0)));
|
||||
kilobytes(config.getValueFor(SizedItem::lgrDBCache, boost::none)));
|
||||
|
||||
txSQLiteDB_ = std::make_unique <DatabaseCon>(
|
||||
setup,
|
||||
@@ -505,7 +506,7 @@ Shard::initSQLite(std::lock_guard<std::mutex> const&)
|
||||
TxDBInit);
|
||||
txSQLiteDB_->getSession() <<
|
||||
boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||
kilobytes(Config::getSize(siTxnDBCache, 0)));
|
||||
kilobytes(config.getValueFor(SizedItem::txnDBCache, boost::none)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -517,7 +518,7 @@ Shard::initSQLite(std::lock_guard<std::mutex> const&)
|
||||
LgrDBInit);
|
||||
lgrSQLiteDB_->getSession() <<
|
||||
boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||
kilobytes(config.getSize(siLgrDBCache)));
|
||||
kilobytes(config.getValueFor(SizedItem::lgrDBCache)));
|
||||
lgrSQLiteDB_->setupCheckpointing(&app_.getJobQueue(), app_.logs());
|
||||
|
||||
txSQLiteDB_ = std::make_unique <DatabaseCon>(
|
||||
@@ -527,7 +528,7 @@ Shard::initSQLite(std::lock_guard<std::mutex> const&)
|
||||
TxDBInit);
|
||||
txSQLiteDB_->getSession() <<
|
||||
boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||
kilobytes(config.getSize(siTxnDBCache)));
|
||||
kilobytes(config.getValueFor(SizedItem::txnDBCache)));
|
||||
txSQLiteDB_->setupCheckpointing(&app_.getJobQueue(), app_.logs());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user