Skip to content

Commit 5709718

Browse files
l0rinctheuni
andcommitted
coins: warn on shutdown for big UTXO set flushes
Setting a large `-dbcache` size postpones the index writes until the coins cache size exceeds the specified limit. This causes the final flush after manual termination to seemingly hang forever (e.g. tens of minutes for 20 GiB); Now that the `dbcache` upper cap has been lifted, this will become even more apparent, so a warning will be shown when large UTXO sets are flushed (currently >1 GiB), such as: > 2024-12-18T18:25:03Z Flushed fee estimates to fee_estimates.dat. > 2024-12-18T18:25:03Z [warning] Flushing large (1 GiB) UTXO set to disk, it may take several minutes > 2024-12-18T18:25:09Z Shutdown: done Note that the related BCLog::BENCH units were also converted to `KiB` from `kB` to unify the bases. Co-authored-by: Cory Fields <[email protected]>
1 parent 477b357 commit 5709718

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/validation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ using node::CBlockIndexHeightOnlyComparator;
8888
using node::CBlockIndexWorkComparator;
8989
using node::SnapshotMetadata;
9090

91+
/** Size threshold for warning about slow UTXO set flush to disk. */
92+
static constexpr size_t WARN_FLUSH_COINS_SIZE = 1 << 30; // 1 GiB
9193
/** Time to wait between writing blocks/block index to disk. */
9294
static constexpr std::chrono::hours DATABASE_WRITE_INTERVAL{1};
9395
/** Time to wait between flushing chainstate to disk. */
@@ -2929,8 +2931,9 @@ bool Chainstate::FlushStateToDisk(
29292931
}
29302932
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
29312933
if (fDoFullFlush && !CoinsTip().GetBestBlock().IsNull()) {
2932-
LOG_TIME_MILLIS_WITH_CATEGORY(strprintf("write coins cache to disk (%d coins, %.2fkB)",
2933-
coins_count, coins_mem_usage / 1000), BCLog::BENCH);
2934+
if (coins_mem_usage >= WARN_FLUSH_COINS_SIZE) LogWarning("Flushing large (%d GiB) UTXO set to disk, it may take several minutes", coins_mem_usage >> 30);
2935+
LOG_TIME_MILLIS_WITH_CATEGORY(strprintf("write coins cache to disk (%d coins, %.2fKiB)",
2936+
coins_count, coins_mem_usage >> 10), BCLog::BENCH);
29342937

29352938
// Typical Coin structures on disk are around 48 bytes in size.
29362939
// Pushing a new one to the database can cause it to be written

0 commit comments

Comments
 (0)