Clean up BFTree data files on RangeIndex deletion#1738
Merged
Conversation
b6149ed to
7bdc2ae
Compare
7bdc2ae to
e0d4c0f
Compare
e0d4c0f to
58fabd0
Compare
badrishc
reviewed
Apr 24, 2026
When a RangeIndex key is deleted via DEL/UNLINK, the native BfTree was freed in memory but its disk files (data.bftree, flush.bftree, snapshot files) were never removed, causing orphaned files to accumulate. Add a deleteFiles parameter to DisposeTreeUnderLock so that OnDispose (Deleted) deletes the entire key directory while OnEvict preserves files for lazy restore. This also handles the edge case where TreeHandle is already zero (e.g., stub was read back from disk after a flush) at the time DEL is issued. Remove an accidentally committed data.bftree artifact from the repo. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
58fabd0 to
8d9d62d
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses orphaned on-disk BfTree artifacts for disk-backed RangeIndex keys by extending RangeIndex disposal to optionally delete the key’s on-disk directory when the key is removed via DEL/UNLINK, while preserving files on eviction to enable lazy restore.
Changes:
- Add a
deleteFilesparameter toRangeIndexManager.DisposeTreeUnderLockand invoke it withtruefor DEL/UNLINK andfalsefor eviction. - Implement best-effort deletion of the per-key RangeIndex directory (
data.bftree,flush.bftree, checkpoint snapshots) on key deletion. - Add/adjust documentation and tests around file cleanup behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/dev/range-index-resp-api.md | Documents that eviction preserves files while DEL/UNLINK deletes the RangeIndex key directory. |
| test/Garnet.test/RespRangeIndexTests.cs | Adds tests intended to validate disk file cleanup on DEL, including an eviction-related scenario. |
| libs/server/Storage/Functions/GarnetRecordTriggers.cs | Routes OnDispose(Deleted) vs OnEvict to DisposeTreeUnderLock(..., deleteFiles: true/false). |
| libs/server/Resp/RangeIndex/RangeIndexManager.Index.cs | Adds deleteFiles behavior and directory deletion helper for disk artifacts. |
| checkpoints/rangeindex/78f58cdcb2159a11e8e6b7e6f3f98d8d/data.bftree | Appears to be a generated runtime/checkpoint artifact added to the PR. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
badrishc
approved these changes
Apr 27, 2026
The test doc comment claimed to cover TreeHandle == 0 (on-disk-only) deletion, but the unified Delete path does not trigger lazy restore, so DEL on a fully evicted key returns NOTFOUND. The RI.GET before DEL is necessary to bring the record back in-memory. Fix the doc comment to accurately describe the tested flow (evict -> lazy restore -> delete -> verify file cleanup) and add an assertion confirming the tree was restored before deletion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
badrishc
approved these changes
Apr 30, 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.
When a RangeIndex key is deleted via DEL/UNLINK, the native BfTree was freed in memory but its disk files (data.bftree, flush.bftree, snapshot files) were never removed, causing orphaned files to accumulate.
Add a deleteFiles parameter to DisposeTreeUnderLock so that OnDispose (Deleted) deletes the entire key directory while OnEvict preserves files for lazy restore.