Skip to content

Commit 9010b81

Browse files
authored
fix: Flush chainstate (and evodb) cache whenever evodb mem usage is getting too high (#5007)
* fix: Flush chainstate (and evodb) cache whenever evodb mem usage is getting too high * Bump evodb cache to 64MiB
1 parent 3e9d136 commit 9010b81

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
19921992
nTotalCache -= nCoinDBCache;
19931993
int64_t nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
19941994
int64_t nMempoolSizeMax = args.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
1995-
int64_t nEvoDbCache = 1024 * 1024 * 16; // TODO
1995+
int64_t nEvoDbCache = 1024 * 1024 * 64; // TODO
19961996
LogPrintf("Cache configuration:\n");
19971997
LogPrintf("* Using %.1f MiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
19981998
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {

src/validation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,8 +2440,6 @@ CoinsCacheSizeState CChainState::GetCoinsCacheSizeState(
24402440
int64_t nTotalSpace =
24412441
max_coins_cache_size_bytes + std::max<int64_t>(max_mempool_size_bytes - nMempoolUsage, 0);
24422442

2443-
cacheSize += evoDb->GetMemoryUsage();
2444-
24452443
//! No need to periodic flush if at least this much space still available.
24462444
static constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = 10 * 1024 * 1024; // 10MB
24472445
int64_t large_threshold =
@@ -2509,12 +2507,14 @@ bool CChainState::FlushStateToDisk(
25092507
bool fCacheLarge = mode == FlushStateMode::PERIODIC && cache_state >= CoinsCacheSizeState::LARGE;
25102508
// The cache is over the limit, we have to write now.
25112509
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cache_state >= CoinsCacheSizeState::CRITICAL;
2510+
// The evodb cache is too large
2511+
bool fEvoDbCacheCritical = mode == FlushStateMode::IF_NEEDED && evoDb != nullptr && evoDb->GetMemoryUsage() >= (64 << 20);
25122512
// It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash.
25132513
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > nLastWrite + DATABASE_WRITE_INTERVAL;
25142514
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
25152515
bool fPeriodicFlush = mode == FlushStateMode::PERIODIC && nNow > nLastFlush + DATABASE_FLUSH_INTERVAL;
25162516
// Combine all conditions that result in a full cache flush.
2517-
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
2517+
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fEvoDbCacheCritical || fPeriodicFlush || fFlushForPrune;
25182518
// Write blocks and block index to disk.
25192519
if (fDoFullFlush || fPeriodicWrite) {
25202520
// Depend on nMinDiskSpace to ensure we can write block index

0 commit comments

Comments
 (0)