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

@@ -41,10 +41,26 @@ TEST_F(LedgerCacheTest, defaultState)
{
EXPECT_FALSE(cache.isDisabled());
EXPECT_FALSE(cache.isFull());
EXPECT_FALSE(cache.isCurrentlyLoading());
EXPECT_EQ(cache.size(), 0u);
EXPECT_EQ(cache.latestLedgerSequence(), 0u);
}
TEST_F(LedgerCacheTest, startLoadingSetsIsCurrentlyLoading)
{
EXPECT_FALSE(cache.isCurrentlyLoading());
cache.startLoading();
EXPECT_TRUE(cache.isCurrentlyLoading());
}
TEST_F(LedgerCacheTest, setFullResetsIsCurrentlyLoading)
{
cache.startLoading();
ASSERT_TRUE(cache.isCurrentlyLoading());
cache.setFull();
EXPECT_FALSE(cache.isCurrentlyLoading());
}
struct LedgerCachePrometheusMetricTest : util::prometheus::WithMockPrometheus {
LedgerCache cache;
};
@@ -64,15 +80,28 @@ TEST_F(LedgerCachePrometheusMetricTest, setFull)
{
auto& fullMock = makeMock<util::prometheus::Bool>("ledger_cache_full", {});
auto& disabledMock = makeMock<util::prometheus::Bool>("ledger_cache_disabled", {});
auto& loadingMock = makeMock<util::prometheus::Bool>("ledger_cache_is_currently_loading", {});
EXPECT_CALL(disabledMock, value()).WillOnce(testing::Return(0));
EXPECT_CALL(fullMock, set(1));
EXPECT_CALL(loadingMock, set(0));
cache.setFull();
EXPECT_CALL(fullMock, value()).WillOnce(testing::Return(1));
EXPECT_TRUE(cache.isFull());
}
TEST_F(LedgerCachePrometheusMetricTest, startLoading)
{
auto& loadingMock = makeMock<util::prometheus::Bool>("ledger_cache_is_currently_loading", {});
EXPECT_CALL(loadingMock, set(1));
cache.startLoading();
EXPECT_CALL(loadingMock, value()).WillOnce(testing::Return(1));
EXPECT_TRUE(cache.isCurrentlyLoading());
}
struct LedgerCacheSaveLoadTest : LedgerCacheTest {
ripple::uint256 const key1{1};
ripple::uint256 const key2{2};