Skip to content

cache: sentinel to invalidate the chunk index during fragment deletion#9908

Open
mr-raj12 wants to merge 2 commits into
borgbackup:masterfrom
mr-raj12:fix-9904-chunkindex-invalidated-sentinel
Open

cache: sentinel to invalidate the chunk index during fragment deletion#9908
mr-raj12 wants to merge 2 commits into
borgbackup:masterfrom
mr-raj12:fix-9904-chunkindex-invalidated-sentinel

Conversation

@mr-raj12

@mr-raj12 mr-raj12 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What

Deleting chunk index fragments is not crash safe: if the delete is interrupted partway, the leftover fragments look like a complete index and borg trusts them, so the index ends up missing entries or keeping stale ones.

This writes an "index invalid" marker before the first fragment delete and removes it after the last. While the marker is present, the index is rebuilt from packs on next load.

The marker lives out of band as a config/chunkindex-invalid object, not in the index/ namespace, so it can never collide with a real index/<sha256> fragment. Its presence is detected with a config/ listing, which bypasses the store cache.

The marker only guards non-superset rewrites (full replacements and the invalidate-all path). Repack does not need it, since the fragments it writes already contain the entries it deletes.

Closes #9904

…ex fragments (borgbackup#9904)

An interrupted fragment deletion could leave a subset that build_chunkindex_from_repo
trusts as a complete index; the sentinel now forces a rebuild from packs instead.
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.17%. Comparing base (7da670c) to head (3cad4fb).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/cache.py 86.20% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9908      +/-   ##
==========================================
+ Coverage   85.13%   85.17%   +0.04%     
==========================================
  Files          93       93              
  Lines       15899    15931      +32     
  Branches     2428     2435       +7     
==========================================
+ Hits        13535    13570      +35     
+ Misses       1654     1652       -2     
+ Partials      710      709       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann ThomasWaldmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in a future PR, we will also need to refactor these functions into a class dealing with index management.

Comment thread src/borg/cache.py Outdated
Comment thread src/borg/constants.py Outdated
Comment thread src/borg/constants.py Outdated
…pace

Store the marker as config/chunkindex-invalid instead of an all-zeros index/ fragment name, so it can never collide with a real fragment; detect it via a config listing.
@mr-raj12 mr-raj12 marked this pull request as ready for review July 14, 2026 20:31
Comment thread src/borg/repository.py
index_infos = store_list("index")
# a marker in config/ records that the chunk index is invalid (an interrupted fragment
# deletion); it will be rebuilt on next use, so warn rather than verify the leftover fragments.
if any(info.name == CHUNKINDEX_INVALID_SENTINEL for info in store_list("config")):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is duplicated at 3 places.

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.

borg2: partial index delete problematic

2 participants