Make use of #17487.
Benchmark results available here: #17487 (comment)
Make use of #17487.
Benchmark results available here: #17487 (comment)
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | Sjors |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
5032 | @@ -5033,15 +5033,19 @@ bool ChainstateManager::ActivateSnapshot( 5033 | return true; 5034 | } 5035 | 5036 | -static void FlushSnapshotToDisk(CCoinsViewCache& coins_cache, bool snapshot_loaded) 5037 | +static void FlushSnapshotToDisk(CCoinsViewCache& coins_cache, bool snapshot_loaded, bool erase=true) 5038 | { 5039 | LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE( 5040 | strprintf("%s (%.2f MB)", 5041 | snapshot_loaded ? "saving snapshot chainstate" : "flushing coins cache",
nit: (erase ? "syncing" : "flushing") + "coins cache"
Good idea, thanks.
5035 | @@ -5036,12 +5036,12 @@ bool ChainstateManager::ActivateSnapshot( 5036 | static void FlushSnapshotToDisk(CCoinsViewCache& coins_cache, bool snapshot_loaded) 5037 | { 5038 | LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE( 5039 | - strprintf("%s (%.2f MB)", 5040 | - snapshot_loaded ? "saving snapshot chainstate" : "flushing coins cache", 5041 | + strprintf("%s coins cache (%.2f MB)",
If you're touching this, maybe use LogPrintf and add [snapshot].
Maybe make it [[nodiscard]]?
Sounds good, fixed.
4257 | @@ -4258,7 +4258,9 @@ bool Chainstate::ReplayBlocks() 4258 | } 4259 | 4260 | cache.SetBestBlock(pindexNew->GetBlockHash()); 4261 | - cache.Flush(); 4262 | + if (!cache.Flush()) { 4263 | + return AbortNode("Failed to write to coin database");
2834617be0e47842dd015b105d2ddc38237c5e98: earlier calls in this function fail with return error(…). What's the difference with AbortNode?
Good point! Fixed.
Benchmark results available here:
https://github.com/bitcoin/bitcoin/pull/17487#issuecomment-557226923
We've historically done this check in most places, so make sure we're
doing it uniformly.
re-utACK 937016b1917a0a07fa579c96fc797237f5027cd1
5046 | 5047 | - snapshot_loaded ? coins_cache.Sync() : coins_cache.Flush(); 5048 | + if (snapshot_loaded ? coins_cache.Sync() : coins_cache.Flush()) { 5049 | + return true; 5050 | + } else { 5051 | + return AbortNode("Failed to write to coin database");
Same question about AbortNode vs. error though.
AbortNode() is used elsewhere in the function that this function is called from, although I did change another reference that you pointed out was inconsistent.
From my testing of #15606 - without this PR - I get the impression that flushing isn't working, specifically that RAM is not freed up. It could just be confusion on my end from rebase hell, but I'd like to make sure we're not obscuring a bug by merging this. (I initially assumed the main assumeutxo PR already contained this PR because RAM didn't go down)
@Sjors how did you detect that RAM wasn't being freed? Did you verify that the flush did not happen based on an absence of logs?
Measures of memory can be deceptive; I remember bitcoinperf spuriously detecting an increase in memory usage because once claimed, the process' resident set size (RSS) doesn't necessarily go down upon free.
Actually this is broken at the moment, since although we don't flush after snapshot load, we do flush (and not sync) in the MaybeRebalanceCaches() -> FlushStateToDisk() call right after activating the chainstate snapshot. Will close this and think about how to rework it.