fix: validate snapshot is unreferenced before expiration removal#716
Closed
dhananjaykrutika wants to merge 2 commits intoapache:mainfrom
Closed
fix: validate snapshot is unreferenced before expiration removal#716dhananjaykrutika wants to merge 2 commits intoapache:mainfrom
dhananjaykrutika wants to merge 2 commits intoapache:mainfrom
Conversation
added 2 commits
February 6, 2026 12:16
Snapshot expiration maintenance can race with concurrent client commits that reference the same snapshot being expired. Consider: 1. Maintenance identifies snap-1 as expired and eligible for removal 2. Client commits AddSnapshotRef linking snap-1 to "feature-branch" 3. Maintenance loads metadata (now contains feature-branch → snap-1) 4. Maintenance commits RemoveSnapshot for snap-1 The CAS succeeds because maintenance has the latest pointer, but the resulting metadata is corrupt: feature-branch references a deleted snapshot. CAS only guarantees the pointer hasn't changed since we read it - it does not validate that our operation is semantically correct against the current state. By checking isSnapshotReferenced() against the freshly loaded metadata, we detect that snap-1 is now in use and skip its removal. The CAS then guarantees this validated state remains current through the commit.
zeroshade
reviewed
Feb 6, 2026
Member
zeroshade
left a comment
There was a problem hiding this comment.
Looks good overall, just one nitpick
Comment on lines
+516
to
+522
| for _, ref := range b.refs { | ||
| if ref.SnapshotID == snapshotID { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false |
Member
There was a problem hiding this comment.
could this be replaced with just slices.ContainsFunc(b.refs, func(r Ref) bool { return r.SnapshotID == snapshotID })?
Contributor
Author
|
Abandoning it in favor of #720 |
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.
Snapshot expiration maintenance can race with concurrent client commits that reference the same snapshot being expired. Consider:
The CAS succeeds because maintenance has the latest pointer, but the resulting metadata is corrupt: feature-branch references a deleted snapshot.
CAS only guarantees the pointer hasn't changed since we read it - it does not validate that our operation is semantically correct against the current state. By checking isSnapshotReferenced() against the freshly loaded metadata, we detect that snap-1 is now in use and skip its removal. The CAS then guarantees this validated state remains current through the commit.