feat: add background database pruning for large prune operations#7739
Merged
SWvheerden merged 2 commits intotari-project:developmentfrom Apr 8, 2026
Merged
feat: add background database pruning for large prune operations#7739SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden merged 2 commits intotari-project:developmentfrom
Conversation
When >25,000 blocks need pruning (e.g. switching to a prune node), spawns a background task that prunes in 10,000-block chunks with independent write locks per chunk. This prevents the node from blocking for extended periods. An AtomicBool flag ensures only one background prune runs at a time and skips inline pruning during the operation. A single write lock per chunk is used for both the metadata check and the prune operation to avoid TOCTOU issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a background pruning mechanism for the blockchain database to offload large pruning operations from the main execution flow. It adds a background task that prunes blocks in chunks when the number of blocks to prune exceeds a defined threshold. Feedback suggests that the background task should continue until the database is fully caught up to avoid subsequent synchronous pruning spikes. Additionally, it is recommended to reduce the pruning chunk size to a single block to prevent large database transactions from exceeding size limits and to minimize write lock duration.
martinserts
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When >25,000 blocks need pruning (e.g. switching to a prune node), spawns a background task that prunes in 10,000-block chunks with independent write locks per chunk. This prevents the node from blocking for extended periods. An AtomicBool flag ensures only one background prune runs at a time and skips inline pruning during the operation.