Skip to content

feat: add background database pruning for large prune operations#7739

Merged
SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden:sw_background_prune
Apr 8, 2026
Merged

feat: add background database pruning for large prune operations#7739
SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden:sw_background_prune

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

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.

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>
@SWvheerden SWvheerden requested a review from a team as a code owner April 8, 2026 13:01
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SWvheerden SWvheerden merged commit 0e5f9ca into tari-project:development Apr 8, 2026
16 of 17 checks passed
@SWvheerden SWvheerden deleted the sw_background_prune branch April 9, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants