From 28e4a54fe4da4f153e5fafc93877b645f289f0f7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 10:41:49 -0800 Subject: [PATCH] chunkstore: a no-op cut after the token moved under the holder's own identity reads the whole HEAD Co-Authored-By: Claude Opus 5.5 --- .../chunkstore/layout_head_read_root_test.go | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/seaweed-block/core/frontend/chunkstore/layout_head_read_root_test.go b/seaweed-block/core/frontend/chunkstore/layout_head_read_root_test.go index 5f1de99dce..3f79bbbedc 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_head_read_root_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout_head_read_root_test.go @@ -128,3 +128,60 @@ func TestANoOpCutOverAForeignClaimFences(t *testing.T) { t.Fatal("the layer is not fenced after a no-op cut over a foreign claim") } } + +// The generation token can move while HEAD keeps this holder's own identity +// and image: a session ended without its commit (a stop's abort), seen by a +// HEAD read before the abandonment notice, forces the view. A no-op cut then reads the whole HEAD and completes on the newer +// generation; keeping the base because epoch and holder still match would +// leave the layer on a generation HEAD no longer has. +func TestANoOpCutAfterTheTokenMovedUnderTheHoldersOwnIdentityReadsTheWholeHead(t *testing.T) { + ctx := context.Background() + lh := newLayoutHost(t) + s, l, r := lh.attach("a", true, true) + defer s.Close() + writeSync(t, s, map[uint32][]byte{2: block(2)}) + first, err := l.Cut(ctx) + if err != nil { + t.Fatal(err) + } + session, err := r.Begin(ctx) + if err != nil { + t.Fatal(err) + } + st, err := lh.cat.Store(lh.v) + if err != nil { + t.Fatal(err) + } + if _, err := layout.RunAbort(ctx, st, lh.me, session, layout.CauseSessionRollback); err != nil { + t.Fatal(err) + } + // An adapter HEAD read in progress observes the ended session before the + // abandonment notice and forces the view: the token moves, identity and + // image stay. + if _, err := r.GetHead(ctx); err != nil { + t.Fatal(err) + } + r.Abort() + var reads atomic.Int64 + lh.ff.afterLookup = func(p string) { + if strings.Contains(p, "/root/") || strings.Contains(p, "/seg/") { + reads.Add(1) + } + } + second, err := l.Cut(ctx) + if err != nil { + t.Fatalf("no-op cut after the token moved: %v", err) + } + if !second.Noop { + t.Fatalf("setup: the cut after the abort was not a no-op: %+v", second) + } + if second.Head.Gen == first.Head.Gen { + t.Fatalf("the no-op cut kept generation %d; HEAD's token moved, so it must complete on the newer one", first.Head.Gen) + } + if reads.Load() == 0 { + t.Fatal("the no-op cut read no root or segment although HEAD's token moved; want the whole HEAD") + } + if e, h := second.Head.Epoch, second.Head.Holder; e != first.Head.Epoch || h != first.Head.Holder { + t.Fatalf("setup: the holder's identity changed: %d/%s, was %d/%s", e, h, first.Head.Epoch, first.Head.Holder) + } +}