From da6130636d64d1f23fc4e2f5168c9dd976a22038 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 14:10:23 -0800 Subject: [PATCH] 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 --- seaweed-block/core/storage/chunk_layer.go | 8 +++++ .../core/storage/chunk_v11_outcomes_test.go | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 9f4d6c18f3..4cefc76529 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -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) diff --git a/seaweed-block/core/storage/chunk_v11_outcomes_test.go b/seaweed-block/core/storage/chunk_v11_outcomes_test.go index e0d660c7c5..c4e660e6f9 100644 --- a/seaweed-block/core/storage/chunk_v11_outcomes_test.go +++ b/seaweed-block/core/storage/chunk_v11_outcomes_test.go @@ -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) + } + }) +}