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

@@ -20,7 +20,10 @@
#include "cluster/ClusterCommunicationService.hpp"
#include "data/BackendInterface.hpp"
#include "data/LedgerCacheLoadingState.hpp"
#include "etl/SystemState.hpp"
#include "etl/WriterState.hpp"
#include "util/config/ConfigDefinition.hpp"
#include <chrono>
#include <ctime>
@@ -32,11 +35,20 @@ namespace cluster {
ClusterCommunicationService::ClusterCommunicationService(
std::shared_ptr<data::BackendInterface> backend,
std::unique_ptr<etl::WriterStateInterface> writerState,
std::unique_ptr<data::LedgerCacheLoadingStateInterface> cacheLoadingState,
std::chrono::steady_clock::duration readInterval,
std::chrono::steady_clock::duration writeInterval
)
: backend_(ctx_, std::move(backend), writerState->clone(), readInterval, writeInterval)
: backend_(
ctx_,
std::move(backend),
writerState->clone(),
cacheLoadingState->clone(),
readInterval,
writeInterval
)
, writerDecider_(ctx_, std::move(writerState))
, cacheLoaderDecider_(ctx_, std::move(cacheLoadingState))
{
}
@@ -49,6 +61,9 @@ ClusterCommunicationService::run()
backend_.subscribeToNewState([this](auto&&... args) {
writerDecider_.onNewState(std::forward<decltype(args)>(args)...);
});
backend_.subscribeToNewState([this](auto&&... args) {
cacheLoaderDecider_.onNewState(std::forward<decltype(args)>(args)...);
});
backend_.run();
}
@@ -63,4 +78,27 @@ ClusterCommunicationService::stop()
backend_.stop();
}
ClusterCommunicationService::MakeResult
ClusterCommunicationService::make(
util::config::ClioConfigDefinition const& config,
std::shared_ptr<BackendInterface> backend,
std::shared_ptr<etl::SystemState> state
)
{
auto const& cache = backend->cache();
auto cacheLoadingState = std::make_unique<data::LedgerCacheLoadingState>(cache);
if (not config.get<bool>("cache.limit_load_in_cluster")) {
cacheLoadingState->allowLoading();
}
auto cacheLoadingStateClone = cacheLoadingState->clone();
return MakeResult{
.service = std::make_unique<ClusterCommunicationService>(
std::move(backend),
std::make_unique<etl::WriterState>(std::move(state), cache),
std::move(cacheLoadingState)
),
.cacheLoadingState = std::move(cacheLoadingStateClone)
};
}
} // namespace cluster