mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:08:38 +00:00
validation: delete pruned files after a failed flush #36735
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!36735
Loading…
Reference in a new issue
No description provided.
Delete branch "prune-unlink-after-retry"
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?
If a flush that prunes block files fails before the block index write, the files are already marked pruned in memory, but
setFilesToPruneis a local inFlushStateToDisk(). The next successful flush writes the pruned file info and never deletes the blk/rev files. OnlyScanAndUnlinkAlreadyPrunedFiles()deletes them, at the next startup.This is number 7 of ryanofsky's post-merge review of #35714. The block file flush failure from #35714 and the blocks directory
CheckDiskSpace()failure both return before that write.I worked on this because it lets me test my kernel pruning refactor (#36738, for #35627 and kernel-node/kernel-node#111) against the issue he describes. The refactor moves the flush, block index write and file deletion that a pruning flush runs from
FlushStateToDisk()intoWriteBlockStorage(), and no unit test ran that sequence in prune mode. I rebased the refactor onto this branch, and the new tests pass on each of its commits.The first three commits add tests that pass on master. The unit test fixtures apply
-pruneand-fastprunefromextra_args,chainstate_flush_failure_boundarychecks that a flush after a failed one writes what was skipped, andprune_flush_failureshows that a failed prune flush still leaves its files on disk after a retry.The last commit keeps the selected files in
BlockManagerand deletes them after the next block index write. If that write fails they are dropped with the dirty entries, which means a file is only deleted once it is marked pruned on disk. Pending files don't force a write. The next flush that writes deletes them.The disk-space failure and automatic pruning take the same path but have no test. Neither does the
FindNextBlockPos()line that drops a file from the pending set when a block is written to it, which can happen after an assumeutxo snapshot validates.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.
🔵 Suggestion · Pending-unlink cancellation lacks regression coverage
The new retry test never writes into a pending file, so it would not catch removal of the cancellation that protects reused block files.
Location:
src/node/blockstorage.cpp:899(head).🔵 Suggestion · Pending-unlink failure handling is split across classes
The ordering is correct today, but dropping pending deletions with a failed dirty batch relies on coordinated implementations in Chainstate and BlockManager.
Location:
src/validation.cpp:2865(head).🔵 Suggestion · The retry test does not cover deferred deletion scheduling
The immediate forced retry leaves untested the rule that pending deletions must not trigger a write on their own.
Location:
src/test/chainstate_write_tests.cpp:212(head).🔵 Suggestion · The pending-unlink scheduling rationale is undocumented
The exchange comment explains index-write failure handling, but not why pending files intentionally wait for an independently triggered write.
Location:
src/node/blockstorage.h:316(head).Review coverage was incomplete.
Reviewed:
d224fb87210b· Full review report · Previous reportspermalink
Is it actually possible for
nFileto be inm_files_to_unlinkhere?m_last_blockfilecontains the tip, and rolling over advances to a new file number.Also, if an old file were somehow reused here, opening it with
rb+would overwrite the head without truncating the existing block data on disk.If a flush fails after
PruneOneBlockFile()clearsnSize, retryingpruneblockchainwon't clean up the files.FindFilesToPruneManual()skips files withnSize == 0, sofFlushForPrunestays false. WithFlushStateMode::NONE,should_writeis false and the function returns early without ever unlinking them.In
chainstate_write_tests.cpp:211, the retry passes only because it callsFORCE_FLUSHinstead ofFlushStateMode::NONE, prune_height.Concept ACK
Sorry for the delay in response. You're right that the retry doesn't delete them. File 0 already has
nSize == 0, soFindFilesToPruneManual()selects nothing and aNONEflush doesn't write. The files are still inm_files_to_unlinkand the next flush that writes deletes them.That's deliberate on my part and I believe it matches item 6 of ryanofsky's post-merge review where skipped writes are kept in memory until a later flush writes them. A
NONEretry doesn't write the dirty block index or coins either. In the node a failed flush requests shutdown, and the shutdown flush callsForceFlushStateToDisk(), which usesFORCE_FLUSH, which is the retry that actually runs, so it's what the test uses. Item 9 suggests documenting that kernel users should stop the same way.Edit: item 4 of the same review fits better (arejula27 is working on it in #35731). A
falsefromFlushStateToDisk()only means the disk write failed, and in-memory state is still valid.pruneblockchainalready works that way. It logs the failure and returns the prune height from memory. The files are pruned in memory, and the disk catches up on the next write.Yes, after an assumeutxo snapshot validates. There's no single
m_last_blockfileanymore.m_blockfile_cursorshas aNORMALand anASSUMEDcursor, and until restart theNORMALone still points at the last file the background chainstate wrote to. Once the snapshot is validated,GetPruneRange()starts at 0 and that file isn'tMaxBlockfileNum()so it can be pruned. A block below the snapshot height (e.g. fromgetblockfrompeer) then goes into it at offset 0, becausePruneOneBlockFile()reset itsCBlockFileInfo. If the flush that pruned the file failed, it would still be pending, and without this line the next write would delete it with that block in it. I can put this in the comment above the line.With regard to
rb+master reuses the file the same way after a failed prune flush, since it never deletes the file. The old data after the new block isn't read, because reads use the stored positions. Overwriting the head is a problem if the node crashes before the next write, because the index on disk still lists the old blocks there. But I think that can be a fix in a separate / followup PR.test: characterize a failed prune flush (
108d7ff03c)We could use the helper function here.
tACK
d224fb8721Left a minor, non-blocking suggestion