chunkstore: fork claims on the parent snapshot entry

Replaces the separate hold objects with one conditional write on the
parent attempt's own entry (codex01's design):

- Fork adds its claim (target/request) to the entry before using it,
  conditioned on {state active, claims as read}; a deleting parent is
  refused. It removes its claim once its HEAD exists (or a sweep's
  tombstone settles the target).
- Retain marks deleting only conditioned on {state active, gen, no
  claims}; a lost condition re-reads and decides again. Claims that
  can never matter (target has a HEAD, or its VOLUME is another
  request's) are cleared conditionally first; any other claim keeps the
  snapshot, with no lifetime. No listing, so no paging.
- A dry run lists attempts a stopped pass left deleting, as apply
  frees them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-15 15:53:04 -08:00
1 parent 6a41bc40bb
commit 02d06311f9
2 files changed
+5 -9

No files matched your search

@@ -1297,9 +1297,6 @@ func (c *Catalog) claimForkParent(ctx context.Context, req ForkRequest) (Snapsho
return SnapshotInfo{}, catErr(CodeSnapshotDeleting, false, nil, "snapshot %s/%s is being deleted", req.Source, req.Snapshot)
}
claims := decodeClaims(ref.entry)
if red := true; red { // RED: no claim written
return ref.info, nil
}
for _, cl := range claims {
if cl == token {
return ref.info, nil
@@ -361,10 +361,8 @@ func (c *Catalog) Retain(ctx context.Context, vol string, dryRun bool) (Retentio
}
for _, s := range unfinished {
d := RetentionDecision{Name: s.Name, Attempt: s.attempt, CreatedNs: s.CreatedNs, Class: s.Class, Pinned: s.Pinned(), Reasons: []string{SnapDeleting}}
if red := true; !red { // RED: unfinished attempts not listed
res.Decisions = append(res.Decisions, d)
res.Expired++
}
res.Decisions = append(res.Decisions, d)
res.Expired++
expired = append(expired, d)
}
if dryRun {
@@ -454,8 +452,9 @@ func (c *Catalog) deleteRetainedAttempt(ctx context.Context, vol, name, attempt
next.Extended[extSnapState] = []byte(SnapDeleting)
next.Extended[extSnapDeletedNs] = []byte(strconv.FormatInt(c.now().UnixNano(), 10))
err = c.f.UpdateEntry(ctx, dir, next, map[string][]byte{
extSnapState: []byte(SnapActive), // RED: no claims condition
extSnapGen: e.Extended[extSnapGen],
extSnapState: []byte(SnapActive),
extSnapGen: e.Extended[extSnapGen],
extSnapClaims: nil, // no claims: a fork that claimed meanwhile wins
})
if errors.Is(err, ErrPrecondition) || errors.Is(err, ErrNotFound) {
continue // a claim, a delete or a replacement landed: decide again