Skip to content

Clean up BFTree data files on RangeIndex deletion#1738

Merged
tiagonapoli merged 5 commits into
devfrom
tiagonapoli/cleanup-snapshot-files
Apr 30, 2026
Merged

Clean up BFTree data files on RangeIndex deletion#1738
tiagonapoli merged 5 commits into
devfrom
tiagonapoli/cleanup-snapshot-files

Conversation

@tiagonapoli

Copy link
Copy Markdown
Collaborator

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.

@tiagonapoli tiagonapoli force-pushed the tiagonapoli/cleanup-snapshot-files branch 5 times, most recently from b6149ed to 7bdc2ae Compare April 24, 2026 23:37
@tiagonapoli tiagonapoli marked this pull request as ready for review April 24, 2026 23:39
Copilot AI review requested due to automatic review settings April 24, 2026 23:39
@tiagonapoli tiagonapoli force-pushed the tiagonapoli/cleanup-snapshot-files branch from 7bdc2ae to e0d4c0f Compare April 24, 2026 23:39
@tiagonapoli tiagonapoli force-pushed the tiagonapoli/cleanup-snapshot-files branch from e0d4c0f to 58fabd0 Compare April 24, 2026 23:41
Comment thread checkpoints/rangeindex/78f58cdcb2159a11e8e6b7e6f3f98d8d/data.bftree Outdated
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>
@tiagonapoli tiagonapoli force-pushed the tiagonapoli/cleanup-snapshot-files branch from 58fabd0 to 8d9d62d Compare April 24, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 deleteFiles parameter to RangeIndexManager.DisposeTreeUnderLock and invoke it with true for DEL/UNLINK and false for 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.

Comment thread libs/server/Resp/RangeIndex/RangeIndexManager.Index.cs
Comment thread test/Garnet.test/RespRangeIndexTests.cs
@microsoft microsoft deleted a comment from Copilot AI Apr 30, 2026
Tiago Napoli and others added 3 commits April 30, 2026 12:15
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>
@tiagonapoli tiagonapoli merged commit 9323e37 into dev Apr 30, 2026
22 of 23 checks passed
@tiagonapoli tiagonapoli deleted the tiagonapoli/cleanup-snapshot-files branch April 30, 2026 20:52
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.

3 participants