After #30611 we periodically do a non-erasing flush of the dbcache to disk roughly every hour during IBD. The intention was to also do this periodic flush during reindex-chainstate, so we would not risk losing progress during a system failure when reindexing with a high dbcache value.
It was discovered that reindex-chainstate does not perform a PERIODIC flush until it has already reached the tip. Since reindexing to tip usually happens within 24 hours, this behaviour was unnoticed with the previous periodic flush interval. Note that reindex-chainstate still does IF_NEEDED flushes during ConnectBlock
, so this also would not be noticed when running with a lower dbcache value.
This patch moves the PERIODIC flush from after the outer loop in ActivateBestChain
to inside the outer loop after we release cs_main
. This will periodically flush during IBD, reindex-chainstate, and steady state.