storage: a v1.1 no-op cut fences a foreign root at its own identity

Commit by change made a v1.1 no-op cut compare only its captured chunks,
so a HEAD read whole that had moved, at this holder's identity, to another
chunk root was installed instead of fenced. A whole read's chunk root must
again be the one the layer holds (the ref table), as the full comparison
required; a HEAD moved with the same root still completes the no-op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-01 14:10:23 -08:00
1 parent 774f2ef4a4
commit da6130636d
2 files changed
+37

No files matched your search

@@ -1548,6 +1548,14 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
same := sameProposal(cur, baseHead)
if byChange {
same = sameByChange(cur, baseHead, headLookup(cur), nil, commitMarks(baseHead, captured, capturedVersions, map[uint64]*chunkRef{}))
if same && !fromBase {
// HEAD read whole: its chunk root must be the one the layer
// holds (the ref table), as the full comparison required; a
// HEAD moved at this identity to another root is fenced.
l.stMu.Lock()
same = sameChunkRoot(l.headChunksLocked(), cur.Chunks)
l.stMu.Unlock()
}
}
if !same {
l.requeueCut(all)
@@ -172,3 +172,32 @@ func TestV11OutcomesKeepNoChunkMap(t *testing.T) {
noMap(t, "the settled layer's kept result", kept)
})
}
// A no-op cut on the v1.1 format that reads HEAD whole and finds it moved,
// at this holder's own identity, to another chunk root is fenced, as on the
// v1.0 format: its captured chunks alone (none here) cannot tell that HEAD
// no longer names what the layer holds. A HEAD moved with the same root
// (only its generation) completes.
func TestV11NoOpCutFencesAForeignRootAtItsOwnIdentity(t *testing.T) {
t.Run("foreign root", func(t *testing.T) {
_, f, l, _, _ := v11ReportLayer(t)
f.mu.Lock()
f.head = copyChunkHead(f.head)
f.head.Gen++
f.head.Chunks[0] = f.head.Chunks[1] // HEAD now names another chunk at 0
f.mu.Unlock()
if _, err := l.Cut(ctTimeout(t)); !errors.Is(err, errChunkLayerFenced) {
t.Fatalf("a no-op cut over a foreign root at its own identity: %v, want fenced", err)
}
})
t.Run("same root", func(t *testing.T) {
_, f, l, _, _ := v11ReportLayer(t)
f.mu.Lock()
f.head = copyChunkHead(f.head)
f.head.Gen++
f.mu.Unlock()
if r, err := l.Cut(ctTimeout(t)); err != nil || !r.Noop {
t.Fatalf("a no-op cut over the same root at a newer generation: %+v %v, want a no-op", r, err)
}
})
}