feat: Limit cache loading in cluster (#2985)

This PR adds an option to limit simultaneous cache loading in a cluster
to one node at a time.
Fixes #2707
This commit is contained in:
Sergey Kuznetsov
2026-03-09 17:11:20 +00:00
committed by GitHub
parent 53d9617b26
commit fbdd6d6105
34 changed files with 1283 additions and 79 deletions

View File

@@ -21,6 +21,7 @@
#include "cluster/ClioNode.hpp"
#include "data/BackendInterface.hpp"
#include "data/LedgerCacheLoadingState.hpp"
#include "etl/WriterState.hpp"
#include <boost/asio/spawn.hpp>
@@ -45,11 +46,13 @@ Backend::Backend(
boost::asio::thread_pool& ctx,
std::shared_ptr<data::BackendInterface> backend,
std::unique_ptr<etl::WriterStateInterface const> writerState,
std::unique_ptr<data::LedgerCacheLoadingStateInterface const> cacheLoadingState,
std::chrono::steady_clock::duration readInterval,
std::chrono::steady_clock::duration writeInterval
)
: backend_(std::move(backend))
, writerState_(std::move(writerState))
, cacheLoadingState_(std::move(cacheLoadingState))
, readerTask_(readInterval, ctx)
, writerTask_(writeInterval, ctx)
, selfUuid_(std::make_shared<boost::uuids::uuid>(boost::uuids::random_generator{}()))
@@ -120,14 +123,14 @@ Backend::doRead(boost::asio::yield_context yield)
*expectedNodeData->uuid = uuid;
otherNodesData.push_back(std::move(expectedNodeData).value());
}
otherNodesData.push_back(ClioNode::from(selfUuid_, *writerState_));
otherNodesData.push_back(ClioNode::from(selfUuid_, *writerState_, *cacheLoadingState_));
return otherNodesData;
}
void
Backend::doWrite()
{
auto const selfData = ClioNode::from(selfUuid_, *writerState_);
auto const selfData = ClioNode::from(selfUuid_, *writerState_, *cacheLoadingState_);
boost::json::value jsonValue{};
boost::json::value_from(selfData, jsonValue);
backend_->writeNodeMessage(*selfData.uuid, boost::json::serialize(jsonValue.as_object()));