mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 19:38:38 +00:00
coins: warn of low disk space before chainstate compaction #36586
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36586
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/chainstate-compaction-headroom"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: Full chainstate compaction can temporarily require nearly another copy of the database before old files are deleted.
Fix: Log automatic full compaction start and finish at info level. Before starting, check the free space on the chainstate filesystem, and if it is below
m_assumed_chain_state_size, log a warning and skip this compaction. Skipping avoids the temporary extra disk use but leaves obsolete data taking up space.Fixes #36585
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
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.
Earlier concerns remain unresolved; see the full report for their current assessments.
🟠 Minor · Compaction checks do not account for chainstates sharing a filesystem
At validation.cpp:2837-2839 each chainstate checks shared free space against one AssumedChainStateSize and compacts on its own. With AssumeUTXO, chainstate and chainstate_snapshot share the datadir, so overlapping compactions could together exceed the checked headroom. This needs both 1/320 draws to fire close together.
Location:
src/validation.cpp:2834(head).🔵 Suggestion · Zero estimates provide no compaction-specific disk headroom
On disk-backed regtest and custom signet nodes, the zero assumed size reduces this guard to 50 MiB regardless of the database size.
Location:
src/validation.cpp:2837(head).🔵 Suggestion · Deferral warning understates the required free space
Near the threshold, the warning can report more free space than “needed” because it omits CheckDiskSpace's 50 MiB reserve.
Location:
src/validation.cpp:2841(head).🔵 Suggestion · Low-space compaction scheduling has no deterministic regression test
Existing compaction tests bypass the scheduling gate, while the chainstate-write fixtures use in-memory databases, so these assertions cannot catch a removed or inverted space check.
Location:
src/validation.cpp:2838(head).Review coverage was incomplete.
Reviewed:
2fcfa1dae75c· Full review report · Previous reportspermalink
Would it make more sense to just skip compaction if we don't think there's enough free disk space to do it? This would have the tradeoff that some extra data would remain, but it would let users like the issue reporter continue running their node for likely several years without any problems.
Thanks @andrewtoth, updated as suggested.
Concept ACK
Concept ACK
My understanding of the worst case here is that this happens when all the data is on a single level L, with a very sparse (<32MiB) level L-1 above it. Because L-1 is so sparse, all L-1 files (with keys across the entire L level) get compacted in one go, causing the entire dense level L (~the entire database) to be temporarily copied, correct?
It seems like we're already being more adventurous with our LevelDB usage than we perhaps should be (the
CompactRangedocstring states "This operation should typically only be invoked by users who understand the underlying implementation."), but perhaps an alternative approach could be to callCompactRangeon slices, instead of on the entire (nullptr,nullptr) range in one go?Thanks for the hint, we should investigate that - I tried compacting smaller key ranges locally, which reduced peak disk usage in some cases but could still produce large spikes, defeating the purpose. Partial compaction could be investigated separately, but it seems fairly complicated, and I don't think the benefit is worth adding that complexity to this PR.
I've separated the free-space check from the database operation and unified the compaction logging, as @optout21 suggested in the original PR.
Concept ACK
Left minor comments on the wording of the warning.
Additionally logging here the currently observed available space is marginally helpful (guideline: if a log is a result of a decision based on several values, log each).
Could we add some more explanatory and call-to-action info here? Describing that the uncompacted DB takes up more disk space, and that the user should free up some disk space.
Also, I suggest changing the wording "Skipping" to "Deferring", to suggest that it's not without consequences.
ACK
ed0f6de810nit: I found the "may need another database copy" a bit confusing, and think the rest of the phrasing could be a bit more clear as well. Proposed alternative, if you like:
Yeah, I think I agree.
nit: any reason we're not using
CheckDiskSpace()here?For an in-memory database, the compaction memory usage problem is arguably even worse than the on-disk one? Since memory-only is quite ephemeral in nature, I think it's uncontroversial to just skip compaction entirely in that case?
Guess the extra 50 MiB reserve is fine here (seemed imprecise to me) - changed.
Done, thanks
Done
Sure, I was also wondering if someone would comment on bubbling this check up - thanks, done.
Did something similar, thanks.
Thanks for the reviews, updated to skip automatic in-memory compaction, use
CheckDiskSpace()with 50 mb additional overhead, include available space and recovery guidance in the warning, and clarify the release note.AssumedChainStateSize()is also rather imprecise here.crACK
2fcfa1dae7ACK
2fcfa1dae7I don't think this change warrants a release note.
If others disagree, at least the last part of this line should be struck."obsolete data" is not something a user reading the release notes will understand.
I'm not sure we should warn about this. Running on a system with < 2x the chainstate disk space should be supported. If that is the case there is nothing the user can do, and they shouldn't be getting warnings about it.
Do they need to understand more than garbage collection needs a bit more space?
We can't expect a node to run without compactions, so we have to let the user know that it's a temporary allowance and that they should do something about it: relocate to a bigger disk, delete some files, prune harder, etc.
Why not? From my understanding the compactions are just a way to reduce disk usage in the chainstate db, but don't affect node operation otherwise.
Right now the chainstate db is ~11 GB. With pruning we can run it on an instance with < 20 GB of disk space. In this scenario the user will get a warning for every attempted compaction. What is the benefit of having this user relocate to a bigger disk, just to save disk space? Is there a way to determine the total disk size and skip warning if it is < 2x chainstate size?
It might be fine to keep running for a while without regular full compaction, which is why this is a warning rather than an abort. But the operator should be aware that the machine lacks the disk headroom for normal database maintenance.
Allowing tombstones to accumulate can also make full database scans more expensive, since those records still need to be traversed and skipped.
I don't think we should encourage sizing a node's disk around the chainstate staying at roughly 10 GB (hypothetically, it could even double in a month) - nodes need some headroom, hence the warning.
Concept ACK.
nit: From commit
cef76701a8description:Maybe here we can more accurately reflect the intention of skipping in-memory chainstates (stated in https://github.com/bitcoin/bitcoin/pull/36586#discussion_r4357973303). Because if it weren't for compaction's temporary extra space coming out of RAM (even scarcer than disk) and in-memory chainstates being mostly used for short-lived purposes, compaction would also have been helpful to reclaim memory space?
I was wondering whether, if we want the node operator to act on the warning, we could surface it in a more visible/persistent way as well. But it looks like we reserve persistent warnings for more critical/consensus-related cases? (While looking into how we currently emit the more persistent warnings, I also noticed that the first-startup disk space check doesn't account for the space needed by the chainstate, so I opened #36811 to get feedback. If that lands, maybe a follow-up could extend the check with the headroom needed for compaction?)
light tACK
2fcfa1dae7Very new to this part of the code, but this looks good to me. I tested on my own system by:
ShouldCompactChainstateto always returns true if not in IBDfallocate:)bitcoin-cli gettxoutsetinfoto force flush to diskAnd saw the log:
ACK
2fcfa1dae7