From 34636c5f4da8ef41b40cd92a971fac92aa4ced07 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 08:38:32 -0800 Subject: [PATCH 01/19] storage: read only HEAD where a HEAD read compares identity; bound a whole-manifest read per fetch Co-Authored-By: Claude Opus 5.5 --- .../frontend/chunkstore/head_readers_test.go | 4 + .../head_generation_source_guard_test.go | 1 + .../chunkstore/layout_head_read_root_test.go | 108 ++++++++++++++++++ .../core/frontend/chunkstore/layout_remote.go | 62 ++++++---- seaweed-block/core/storage/chunk_head_belt.go | 21 ++++ .../storage/chunk_head_read_bound_test.go | 46 ++++++++ seaweed-block/core/storage/chunk_layer.go | 19 ++- seaweed-block/docs/design/invariants.md | 1 + 8 files changed, 241 insertions(+), 21 deletions(-) create mode 100644 seaweed-block/core/frontend/chunkstore/layout_head_read_root_test.go create mode 100644 seaweed-block/core/storage/chunk_head_read_bound_test.go diff --git a/seaweed-block/core/frontend/chunkstore/head_readers_test.go b/seaweed-block/core/frontend/chunkstore/head_readers_test.go index 9ea1486c23..60c07d8e22 100644 --- a/seaweed-block/core/frontend/chunkstore/head_readers_test.go +++ b/seaweed-block/core/frontend/chunkstore/head_readers_test.go @@ -66,6 +66,7 @@ var headReaders = map[string]string{ "core/storage/chunk_head_belt.go confirmChunkHead -> GetHead": "ErrHeadAbsent from the layout remote: not confirmed (probe LayoutRemote)", "core/storage/chunk_head_belt.go confirmChunkHead -> GetHeadRoot": "ErrHeadAbsent from the layout remote: not confirmed (probe LayoutRemote)", "core/storage/chunk_head_belt.go readChunkHead -> GetHead": "ErrHeadAbsent from the layout remote (probe LayoutRemote)", + "core/storage/chunk_head_belt.go readChunkHeadRoot -> GetHeadRoot": "ErrHeadAbsent from the layout remote (probe LayoutRemote)", "core/storage/chunk_layer.go attachChunkLayerImpl -> GetHead": "ErrHeadAbsent from the layout remote (probe LayoutRemote)", } @@ -217,6 +218,9 @@ func TestHeadReaders_AbsentHeadProbes(t *testing.T) { if _, err := r.GetHead(ctx); !errors.Is(err, layout.ErrHeadAbsent) { t.Fatalf("engine HEAD read of an absent HEAD: %v; want ErrHeadAbsent", err) } + if _, err := r.GetHeadRoot(ctx); !errors.Is(err, layout.ErrHeadAbsent) { + t.Fatalf("engine HEAD identity read of an absent HEAD: %v; want ErrHeadAbsent", err) + } if _, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: 0, Epoch: 1}, storage.ChunkHead{Epoch: 1}); !errors.Is(err, layout.ErrHeadAbsent) || len(f.written) != 0 { t.Fatalf("engine commit over an absent HEAD: %v (%d writes); want ErrHeadAbsent and none", err, len(f.written)) } diff --git a/seaweed-block/core/frontend/chunkstore/layout/head_generation_source_guard_test.go b/seaweed-block/core/frontend/chunkstore/layout/head_generation_source_guard_test.go index d0cd99704b..6fa8fc5547 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/head_generation_source_guard_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/head_generation_source_guard_test.go @@ -185,6 +185,7 @@ func TestHeadGenerationComparedOnlyByConditionalUpdate(t *testing.T) { allowed := map[string]int{ "core/storage/chunk_head_belt.go confirmChunkHead got.Gen != want.Gen": 1, // publication confirmation "core/storage/chunk_layer.go captureLocked sc.headGen == l.head.Gen": 1, // staged image cache + "core/storage/chunk_layer.go noopCutHead root.Gen == baseHead.Gen": 1, // no-op cut keeps its base while HEAD's image token is unchanged "core/storage/chunk_layer.go captureLocked cur.Gen == expected.Gen": 1, // unresolved CAS base "core/storage/chunk_layer.go SettleDetach cur.Gen == base.Gen": 2, // pending and cancelled CAS base "core/storage/chunk_layer.go resolvePending cur.Gen == base.Gen": 2, // pending and cancelled CAS base 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 new file mode 100644 index 0000000000..93ca45adef --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/layout_head_read_root_test.go @@ -0,0 +1,108 @@ +package chunkstore + +import ( + "context" + "path/filepath" + "strings" + "sync/atomic" + "testing" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// afterCASRemote is the holder's layout remote, marking when a HEAD write +// has returned, so a test can count what the layer reads after it. +type afterCASRemote struct { + *LayoutRemote + after atomic.Bool + onAfter func() +} + +func (r *afterCASRemote) CASHead(ctx context.Context, e storage.ChunkHeadVersion, n storage.ChunkHead) (uint64, error) { + gen, err := r.LayoutRemote.CASHead(ctx, e, n) + r.after.Store(true) + if r.onAfter != nil { + r.onAfter() + } + return gen, err +} + +// manifestReads attaches a chunk layer over the holder's layout remote, one +// block written in every chunk, and counts every lookup of a root or a +// segment made while counting is on. +func manifestReads(t *testing.T) (*storage.WALStore, *afterCASRemote, storage.ChunkLayer, *atomic.Bool, *atomic.Int64) { + t.Helper() + lh := newLayoutHost(t) + s, err := storage.CreateWALStoreWithOptions(filepath.Join(lh.dir, "a"), lrBlocks, 4096, storage.WALStoreOptions{ChunkBlocks: lrChunkBlocks}) + if err != nil { + t.Fatal(err) + } + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + r, err := NewLayoutRemote(lh.cat, lh.v, lh.me) + if err != nil { + t.Fatal(err) + } + w := &afterCASRemote{LayoutRemote: r} + l, err := storage.AttachChunkLayer(s, w, storage.ChunkLayerConfig{ChunkBlocks: lrChunkBlocks, Epoch: lh.me.Epoch, Holder: lh.me.Holder, FreshFromHead: true}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = l.Close(); _ = s.Close() }) + blocks := map[uint32][]byte{} + for c := uint32(0); c < lrBlocks/lrChunkBlocks; c++ { + blocks[c*lrChunkBlocks] = block(byte(c + 1)) + } + writeSync(t, s, blocks) + var counting atomic.Bool + var reads atomic.Int64 + lh.ff.afterLookup = func(p string) { + if counting.Load() && (strings.Contains(p, "/root/") || strings.Contains(p, "/seg/")) { + reads.Add(1) + } + } + return s, w, l, &counting, &reads +} + +// The confirmation after a HEAD write compares HEAD's generation, epoch and +// holder only, inside the HEAD step's fixed 2 s limit, so it reads HEAD and +// nothing else: no root and no segment, whose number grows with the volume. +func TestTheConfirmationAfterAHeadWriteReadsNoManifest(t *testing.T) { + _, w, l, counting, reads := manifestReads(t) + w.onAfter = func() { counting.Store(true) } // count what is read once the HEAD write returns + if _, err := l.Cut(context.Background()); err != nil { + t.Fatal(err) + } + if !w.after.Load() { + t.Fatal("setup: the cut wrote no HEAD") + } + if n := reads.Load(); n != 0 { + t.Fatalf("the confirmation after the HEAD write read %d roots or segments; want 0 (HEAD only)", n) + } +} + +// A cut with nothing new (a no-op cut, run each interval on an idle volume) +// still reads HEAD to observe authority. While HEAD is the image the layer +// already holds, it reads HEAD only and keeps its chunk list: no root and no +// segment. +func TestANoOpCutReadsNoManifestWhileHeadIsUnchanged(t *testing.T) { + _, _, l, counting, reads := manifestReads(t) + if _, err := l.Cut(context.Background()); err != nil { // publish the written chunks + t.Fatal(err) + } + counting.Store(true) + res, err := l.Cut(context.Background()) + if err != nil { + t.Fatal(err) + } + if !res.Noop { + t.Fatalf("setup: the second cut was not a no-op: %+v", res) + } + if n := reads.Load(); n != 0 { + t.Fatalf("a no-op cut over an unchanged HEAD read %d roots or segments; want 0", n) + } + if len(res.Head.Chunks) != lrBlocks/lrChunkBlocks { + t.Fatalf("the no-op cut's HEAD names %d chunks; want the %d it already held", len(res.Head.Chunks), lrBlocks/lrChunkBlocks) + } +} diff --git a/seaweed-block/core/frontend/chunkstore/layout_remote.go b/seaweed-block/core/frontend/chunkstore/layout_remote.go index cfc80ca47e..010d71da8e 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_remote.go +++ b/seaweed-block/core/frontend/chunkstore/layout_remote.go @@ -299,26 +299,9 @@ func (l *LayoutRemote) Get(ctx context.Context, key string) ([]byte, error) { func (l *LayoutRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { l.mu.Lock() defer l.mu.Unlock() - l.takeAbandonLocked() - h, err := l.rollBackLocked(ctx) - if err != nil { - return storage.ChunkHead{}, err - } - if h.State == layout.StateDeleting || h.State == layout.StateDeleted { - return storage.ChunkHead{}, storage.ErrChunkHeadDeleted - } - // Another claim at this holder's own epoch is another owner of HEAD: the - // head the engine sees carries no claim id, so it must not read as its own. - if h.Epoch == l.me.Epoch && h.Holder == l.me.Holder && h.ClaimID != l.me.ClaimID { - return storage.ChunkHead{}, fmt.Errorf("%w: HEAD is held by %s at epoch %d (claim %q)", storage.ErrChunkLayerFenced, h.Holder, h.Epoch, h.ClaimID) - } - out := storage.ChunkHead{Gen: l.visible, Epoch: h.Epoch, Holder: h.Holder, RemoteLSN: h.Position, Chunks: map[uint64]storage.ChunkRef{}, State: "active"} - if h.State == layout.StateDetached { - out.State = "detached" - out.DetachedBy = &storage.ChunkDetachedBy{Holder: h.Holder, Epoch: h.Epoch, Gen: h.Gen} - } - if h.Current == nil { - return out, nil + h, out, err := l.headIdentityLocked(ctx) + if err != nil || h.Current == nil { + return out, err } m, err := l.manifest(ctx, *h.Current) if err != nil { @@ -342,6 +325,45 @@ func (l *LayoutRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { return out, nil } +// GetHeadRoot is GetHead without the manifest (storage.ChunkHeadRootReader): +// the same view of HEAD, its generation token, epoch, holder, position and +// state, after the same rollback and refusals, with no chunk listed. It reads +// HEAD only, never a root or a segment, so it does not grow with the volume. +// The token changes whenever HEAD's root does, so a caller that kept the +// chunks of a HEAD with the same token still has them. +func (l *LayoutRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) { + l.mu.Lock() + defer l.mu.Unlock() + _, out, err := l.headIdentityLocked(ctx) + out.Chunks = nil + return out, err +} + +// headIdentityLocked reads HEAD as the engine's view, without its manifest: +// the rollback of a session this process does not hold, the deleted and +// other-claim refusals, and HEAD's identity (Chunks empty). +func (l *LayoutRemote) headIdentityLocked(ctx context.Context) (layout.Head, storage.ChunkHead, error) { + l.takeAbandonLocked() + h, err := l.rollBackLocked(ctx) + if err != nil { + return layout.Head{}, storage.ChunkHead{}, err + } + if h.State == layout.StateDeleting || h.State == layout.StateDeleted { + return layout.Head{}, storage.ChunkHead{}, storage.ErrChunkHeadDeleted + } + // Another claim at this holder's own epoch is another owner of HEAD: the + // head the engine sees carries no claim id, so it must not read as its own. + if h.Epoch == l.me.Epoch && h.Holder == l.me.Holder && h.ClaimID != l.me.ClaimID { + return layout.Head{}, storage.ChunkHead{}, fmt.Errorf("%w: HEAD is held by %s at epoch %d (claim %q)", storage.ErrChunkLayerFenced, h.Holder, h.Epoch, h.ClaimID) + } + out := storage.ChunkHead{Gen: l.visible, Epoch: h.Epoch, Holder: h.Holder, RemoteLSN: h.Position, Chunks: map[uint64]storage.ChunkRef{}, State: "active"} + if h.State == layout.StateDetached { + out.State = "detached" + out.DetachedBy = &storage.ChunkDetachedBy{Holder: h.Holder, Epoch: h.Epoch, Gen: h.Gen} + } + return h, out, nil +} + // manifest is the chunk map root names. Within an attach (ctx carries // storage.AttachFetch) it is read fetch by fetch: the root and each segment // under their own bound, each completed segment reported as progress, and diff --git a/seaweed-block/core/storage/chunk_head_belt.go b/seaweed-block/core/storage/chunk_head_belt.go index ea21ccdf81..0fca73811c 100644 --- a/seaweed-block/core/storage/chunk_head_belt.go +++ b/seaweed-block/core/storage/chunk_head_belt.go @@ -68,12 +68,33 @@ func casChunkHead(ctx context.Context, remote chunkRemote, expected chunkHeadVer return remote.CASHead(ctx, expected, next) } +// readChunkHead reads HEAD with its whole manifest. A remote that bounds +// its own HEAD step reads it fetch by fetch (the root, then each segment), +// each fetch bounded by chunkHeadOperationTimeout and the read as a whole by +// ctx only: the segment count grows with the volume. Any other remote's read +// is bounded as one call. func readChunkHead(ctx context.Context, remote chunkRemote) (chunkHead, error) { + if b, ok := remote.(chunkHeadStepBounder); ok && b.BoundsHeadStep() { + return remote.GetHead(WithAttachFetch(ctx, AttachFetch{Bound: chunkHeadOperationTimeout})) + } ctx, cancel := context.WithTimeout(ctx, chunkHeadOperationTimeout) defer cancel() return remote.GetHead(ctx) } +// readChunkHeadRoot reads HEAD's identity without its manifest when the +// remote can (ChunkHeadRootReader); ok is false otherwise. +func readChunkHeadRoot(ctx context.Context, remote chunkRemote) (head chunkHead, ok bool, err error) { + reader, ok := remote.(ChunkHeadRootReader) + if !ok { + return chunkHead{}, false, nil + } + ctx, cancel := context.WithTimeout(ctx, chunkHeadOperationTimeout) + defer cancel() + head, err = reader.GetHeadRoot(ctx) + return head, true, err +} + // ChunkHeadRootReader confirms publication identity without resolving every // immutable manifest. The returned Chunks need not be populated. type ChunkHeadRootReader interface { diff --git a/seaweed-block/core/storage/chunk_head_read_bound_test.go b/seaweed-block/core/storage/chunk_head_read_bound_test.go new file mode 100644 index 0000000000..b03f21c9cc --- /dev/null +++ b/seaweed-block/core/storage/chunk_head_read_bound_test.go @@ -0,0 +1,46 @@ +package storage + +import ( + "context" + "testing" +) + +// readRemote records the context its GetHead got; bounds says whether it +// declares that it bounds its own HEAD step. +type readRemote struct { + chunkRemote + bounds bool + deadline bool + fetch AttachFetch + perFetch bool +} + +func (r *readRemote) BoundsHeadStep() bool { return r.bounds } + +func (r *readRemote) GetHead(ctx context.Context) (chunkHead, error) { + _, r.deadline = ctx.Deadline() + r.fetch, r.perFetch = AttachFetchFrom(ctx) + return chunkHead{}, nil +} + +// A whole-manifest HEAD read from a remote that bounds its own step is read +// fetch by fetch: each fetch bounded by the HEAD operation limit, the read as +// a whole only by the caller (its segment count grows with the volume). Any +// other remote's read is bounded as one call, as before. +func TestAWholeHeadReadIsBoundedPerFetchWhenTheRemoteBoundsItsStep(t *testing.T) { + stepped := &readRemote{bounds: true} + if _, err := readChunkHead(context.Background(), stepped); err != nil { + t.Fatal(err) + } + if stepped.deadline || !stepped.perFetch || stepped.fetch.Bound != chunkHeadOperationTimeout { + t.Fatalf("a remote that bounds its step: deadline=%v per-fetch=%v bound=%v; want no deadline and a per-fetch bound of %v", + stepped.deadline, stepped.perFetch, stepped.fetch.Bound, chunkHeadOperationTimeout) + } + plain := &readRemote{bounds: false} + if _, err := readChunkHead(context.Background(), plain); err != nil { + t.Fatal(err) + } + if !plain.deadline || plain.perFetch { + t.Fatalf("a remote that does not bound its step: deadline=%v per-fetch=%v; want the whole read bounded", plain.deadline, plain.perFetch) + } +} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 6a890b43ee..b4775c96d5 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1176,7 +1176,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { // A no-op cut still observes authority: a fresh host may have // claimed HEAD without uploading a single chunk since our last cut. - cur, err := readCapturedHead() + cur, err := l.noopCutHead(ctx, baseHead, readCapturedHead) if err != nil { l.requeueCut(all) return chunkCutResult{}, fmt.Errorf("storage: no-op cut authority read: %w: %w", errChunkRemoteUnavailable, err) @@ -1423,6 +1423,23 @@ func (l *chunkLayerImpl) supersededBy(cur chunkHead) bool { // and who detached; the segments; per chunk its key, content hash and // encoding. A value the store does not keep (a chunk's birth) or that it // owns (a generation) would make an applied commit look foreign. +// noopCutHead is a no-op cut's authority read. When the remote reads HEAD's +// identity alone (ChunkHeadRootReader) and HEAD is still the image baseHead +// names (the same generation token, epoch, holder, position and detach +// state; the token changes whenever HEAD's root does), it is baseHead with +// its chunks, and no manifest is read. Otherwise it is the whole HEAD (full). +func (l *chunkLayerImpl) noopCutHead(ctx context.Context, baseHead chunkHead, full func() (chunkHead, error)) (chunkHead, error) { + root, ok, err := readChunkHeadRoot(ctx, l.remote) + if err != nil { + return chunkHead{}, err + } + if ok && root.Gen == baseHead.Gen && root.Epoch == baseHead.Epoch && root.Holder == baseHead.Holder && + root.RemoteLSN == baseHead.RemoteLSN && chunkHeadIsDetached(root) == chunkHeadIsDetached(baseHead) { + return copyHead(baseHead), nil + } + return full() +} + func sameProposal(cur, next chunkHead) bool { if (cur.Segments == nil) != (next.Segments == nil) || cur.ChunkBytes != next.ChunkBytes || cur.ManifestChunkCount != next.ManifestChunkCount || len(cur.Segments) != len(next.Segments) { return false diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 7d21261498..ea7351d744 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1204,6 +1204,7 @@ One row per fixed time limit on a volume's path that surrounds, or once surround |---|---|---|---|---|---| | `core/storage/chunk_head_belt.go` `casChunkHead`, applied by `LayoutRemote.commitStepLocked` | 2 s per attempt | one HEAD step: the HEAD read, the commit's decision from its plan, the conditional write | no | the commit's preparation (the previous manifest, the next root and segments, the plan) and its object lookups, under the cut's limit; a commit after a passed check reuses the preparation | `TestHolderCommitAtOneTiBKeepsItsPreparationOutOfTheHeadStep`, `TestCommitUpdateStepDoesNotRereadTheManifests` | | the same step, for a commit that was NOT checked first | 2 s per attempt | the step and the object lookups of every new chunk, and of a new root's segments and root even when no chunk is new | **yes** | nothing: no production caller commits without the check; a new caller must check first | none: a known gap, stated here so it is not claimed. Kept true by `TestEveryHeadCommitIsCheckedFirst`: every HEAD commit of the chunk layer (a cut's commit, a detach's cancellation, an unresolved cut's re-proposal) runs the object check before its CAS, and a new site fails until it does. `TestDetachCancellationAfterALostUpdateLooksUpNothingInTheHeadStep` measures the cancellation. The snapshot of an unchanged image commits under its caller's limit, not in this step | +| `core/storage/chunk_head_belt.go` the chunk layer's HEAD reads: `confirmChunkHead` after a HEAD write, a no-op cut's authority read (`noopCutHead`), and `readChunkHead` when a write's outcome is settled | 2 s per remote call | the confirmation and a no-op cut over an unchanged HEAD read HEAD only (`GetHeadRoot`), no root and no segment; a settlement reads the whole manifest, one root fetch and one fetch per segment, each bounded on its own | the confirmation and the no-op read: no; a settlement's fetch count: **yes** | a settlement's read as a whole, under the cut's limit; a no-op cut over a changed HEAD reads the whole manifest the same way | `TestTheConfirmationAfterAHeadWriteReadsNoManifest`, `TestANoOpCutReadsNoManifestWhileHeadIsUnchanged` (count 0 fetches whatever the size), `TestAWholeHeadReadIsBoundedPerFetchWhenTheRemoteBoundsItsStep` | | `DurableProvider.chunkCutContext` (`ChunkCutTimeout`) | 5 min per attempt | staging the changed chunks, the check, the commit | yes | uploads finished by an attempt are kept; the next attempt uploads only the rest (same process) | `TestACutAttemptThatRunsOutOfTimeLeavesUploadsTheNextAttemptKeeps` | | the cleaning pass (`boundedPass`) | the configured pass limit | listing and removing by page | yes | the pass resumes at its cursor; a session after a restart starts at the root page | the cleaning cursor's tests | | `core/host/volume/chunk_control.go` `chunkContext` (a chunk control operation: a cut, a snapshot or a detach, each of which takes a cut; the chunk status read also runs under it and reads one HEAD) | 5 min, or the request's shorter limit | the operation, including the cut it takes | yes | the cut's uploads, as the cut's row: an attempt that runs out of time keeps what it uploaded | STUB: no test at the control operation's level yet | From c38a049327e791083e0bd84459aee165a5c5ad56 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 09:38:59 -0800 Subject: [PATCH 02/19] storage: a no-op cut's identity read is its settle phase and counts as HEAD read-back; controls for a foreign claim and the caller's deadline Co-Authored-By: Claude Opus 5.5 --- .../chunkstore/layout_head_read_root_test.go | 22 +++++ .../storage/chunk_head_read_bound_test.go | 84 ++++++++++++++++++- seaweed-block/core/storage/chunk_layer.go | 19 +++-- 3 files changed, 119 insertions(+), 6 deletions(-) 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 93ca45adef..5f1de99dce 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 @@ -2,11 +2,13 @@ package chunkstore import ( "context" + "errors" "path/filepath" "strings" "sync/atomic" "testing" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" "github.com/seaweedfs/seaweed-block/core/storage" ) @@ -106,3 +108,23 @@ func TestANoOpCutReadsNoManifestWhileHeadIsUnchanged(t *testing.T) { t.Fatalf("the no-op cut's HEAD names %d chunks; want the %d it already held", len(res.Head.Chunks), lrBlocks/lrChunkBlocks) } } + +// A no-op cut over a HEAD another holder has claimed since the last cut reads +// HEAD's identity through the root reader, finds it changed, and fences: it +// never keeps its base over a changed HEAD. +func TestANoOpCutOverAForeignClaimFences(t *testing.T) { + ctx := context.Background() + _, w, l, _, _ := manifestReads(t) + if _, err := l.Cut(ctx); err != nil { // publish the written chunks + t.Fatal(err) + } + if _, err := layout.RunClaim(ctx, w.st, okClaimLease{}, layout.HolderID{Epoch: w.me.Epoch + 1, Holder: "foreign", ClaimID: "foreign-claim"}); err != nil { + t.Fatal(err) + } + if _, err := l.Cut(ctx); !errors.Is(err, storage.ErrChunkLayerFenced) { + t.Fatalf("a no-op cut over a foreign claim: %v; want ErrChunkLayerFenced", err) + } + if !l.Fenced() { + t.Fatal("the layer is not fenced after a no-op cut over a foreign claim") + } +} diff --git a/seaweed-block/core/storage/chunk_head_read_bound_test.go b/seaweed-block/core/storage/chunk_head_read_bound_test.go index b03f21c9cc..8de0241de3 100644 --- a/seaweed-block/core/storage/chunk_head_read_bound_test.go +++ b/seaweed-block/core/storage/chunk_head_read_bound_test.go @@ -2,7 +2,9 @@ package storage import ( "context" + "errors" "testing" + "time" ) // readRemote records the context its GetHead got; bounds says whether it @@ -11,6 +13,8 @@ type readRemote struct { chunkRemote bounds bool deadline bool + at time.Time + err error fetch AttachFetch perFetch bool } @@ -18,7 +22,8 @@ type readRemote struct { func (r *readRemote) BoundsHeadStep() bool { return r.bounds } func (r *readRemote) GetHead(ctx context.Context) (chunkHead, error) { - _, r.deadline = ctx.Deadline() + r.at, r.deadline = ctx.Deadline() + r.err = ctx.Err() r.fetch, r.perFetch = AttachFetchFrom(ctx) return chunkHead{}, nil } @@ -44,3 +49,80 @@ func TestAWholeHeadReadIsBoundedPerFetchWhenTheRemoteBoundsItsStep(t *testing.T) t.Fatalf("a remote that does not bound its step: deadline=%v per-fetch=%v; want the whole read bounded", plain.deadline, plain.perFetch) } } + +// A caller's deadline and cancellation reach a stepped whole read: the +// per-fetch bound is added, the caller's context is kept. +func TestAWholeHeadReadKeepsTheCallersDeadlineAndCancellation(t *testing.T) { + want := time.Now().Add(time.Hour) + ctx, cancel := context.WithDeadline(context.Background(), want) + defer cancel() + stepped := &readRemote{bounds: true} + if _, err := readChunkHead(ctx, stepped); err != nil { + t.Fatal(err) + } + if !stepped.deadline || !stepped.at.Equal(want) || !stepped.perFetch { + t.Fatalf("caller deadline: got deadline=%v at=%v per-fetch=%v; want the caller's %v with the per-fetch bound", stepped.deadline, stepped.at, stepped.perFetch, want) + } + gone, stop := context.WithCancel(context.Background()) + stop() + if _, err := readChunkHead(gone, stepped); err != nil { + t.Fatal(err) + } + if !errors.Is(stepped.err, context.Canceled) { + t.Fatalf("caller cancellation: the read's context reports %v; want context.Canceled", stepped.err) + } +} + +// gatedRootRemote reads HEAD's whole identity alone and runs during while it +// does, so a test can observe the cut while the read is in progress. +type gatedRootRemote struct { + *fakeChunkRemote + during func() +} + +func (r *gatedRootRemote) GetHeadRoot(ctx context.Context) (ChunkHead, error) { + if r.during != nil { + r.during() + } + r.mu.Lock() + defer r.mu.Unlock() + h := r.head + return ChunkHead{Gen: h.Gen, Epoch: h.Epoch, Holder: h.Holder, RemoteLSN: h.RemoteLSN, State: h.State, DetachedBy: h.DetachedBy}, nil +} + +// A no-op cut's identity read is the cut's settle phase and its time counts +// as HEAD read-back, as the whole read it replaces did. +func TestANoOpCutsRootReadIsTheSettlePhaseAndCountsItsTime(t *testing.T) { + s, _ := newChunkTestStore(t) + f := newFakeChunkRemote() + r := &gatedRootRemote{fakeChunkRemote: f} + layer := mustAttach(t, s, r, ctConfig(1)) + if _, err := s.Write(0, makeBlock(4096, 0x42)); err != nil { + t.Fatal(err) + } + if _, err := layer.Cut(ctTimeout(t)); err != nil { + t.Fatal(err) + } + impl := layer.(*chunkLayerImpl) + const pause = 20 * time.Millisecond + phase := "" + r.during = func() { + if c := impl.Stats().CurrentCut; c != nil { + phase = c.Phase + } + time.Sleep(pause) + } + res, err := layer.Cut(ctTimeout(t)) + if err != nil { + t.Fatal(err) + } + if !res.Noop { + t.Fatalf("setup: the second cut was not a no-op: %+v", res) + } + if phase != "settle" { + t.Fatalf("phase during the no-op cut's identity read: %q; want settle", phase) + } + if got := time.Duration(res.Stats.HeadReadbackNs); got < pause { + t.Fatalf("HEAD read-back time %v; want at least the %v the identity read took", got, pause) + } +} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index b4775c96d5..a6a7c20143 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -798,6 +798,15 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.HeadReadbackNs += time.Since(start).Nanoseconds() return head, err } + // readCapturedRoot is the same read of HEAD's identity alone, when the + // remote can; each read counts only its own time. + readCapturedRoot := func() (chunkHead, bool, error) { + l.cutPhase("settle") + start := time.Now() + head, ok, err := readChunkHeadRoot(ctx, l.remote) + st.HeadReadbackNs += time.Since(start).Nanoseconds() + return head, ok, err + } finishCapturedCut := func(head chunkHead, h uint64, changed []uint64, keys map[uint64]string) { start := time.Now() l.finishCut(head, h, changed, keys) @@ -1176,7 +1185,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { // A no-op cut still observes authority: a fresh host may have // claimed HEAD without uploading a single chunk since our last cut. - cur, err := l.noopCutHead(ctx, baseHead, readCapturedHead) + cur, err := noopCutHead(baseHead, readCapturedRoot, readCapturedHead) if err != nil { l.requeueCut(all) return chunkCutResult{}, fmt.Errorf("storage: no-op cut authority read: %w: %w", errChunkRemoteUnavailable, err) @@ -1423,13 +1432,13 @@ func (l *chunkLayerImpl) supersededBy(cur chunkHead) bool { // and who detached; the segments; per chunk its key, content hash and // encoding. A value the store does not keep (a chunk's birth) or that it // owns (a generation) would make an applied commit look foreign. -// noopCutHead is a no-op cut's authority read. When the remote reads HEAD's -// identity alone (ChunkHeadRootReader) and HEAD is still the image baseHead +// noopCutHead is a no-op cut's authority read. When rootRead reads HEAD's +// identity alone (a ChunkHeadRootReader remote) and HEAD is still the image baseHead // names (the same generation token, epoch, holder, position and detach // state; the token changes whenever HEAD's root does), it is baseHead with // its chunks, and no manifest is read. Otherwise it is the whole HEAD (full). -func (l *chunkLayerImpl) noopCutHead(ctx context.Context, baseHead chunkHead, full func() (chunkHead, error)) (chunkHead, error) { - root, ok, err := readChunkHeadRoot(ctx, l.remote) +func noopCutHead(baseHead chunkHead, rootRead func() (chunkHead, bool, error), full func() (chunkHead, error)) (chunkHead, error) { + root, ok, err := rootRead() if err != nil { return chunkHead{}, err } From 1ad3be0ebd34aa1a3d53f98ca3e38557b4271979 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 09:57:26 -0800 Subject: [PATCH 03/19] docs: supported replicated volumes are planned for v1.1.0, not v1.0.1 Co-Authored-By: Claude Opus 5.5 --- seaweed-block/docs/operator-guide.md | 11 +++-------- .../docs/releases/replicated-volumes-preview.md | 8 +++----- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 7f37bed1d6..c1afee580d 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -449,14 +449,9 @@ acts. The limits, as they show on a running system: In the acknowledging modes, acknowledged writes were read back intact in every run that found these limits. What the release supports without these limits is the single-replica volume. -**Planned for v1.0.1.** Two replicated configurations are planned to become supported: -- **RF3 `sync-quorum`, installed on hosts:** writes continue through one replica's fault, and that replica returns - by itself. -- **RF2 `sync-quorum`, with its limit:** no acknowledged write is lost and failover is automatic, but writes stop - while either replica is out. - -`sync-all` and Kubernetes RF3 stay a preview. In every replicated configuration, an old primary cut off from -blockmaster by a partition may keep serving reads of older data until its lease ends. +**Planned for v1.1.0.** Supported replicated volumes are planned for v1.1.0; v1.0.1 keeps every replicated +configuration a preview. In every replicated configuration, an old primary cut off from blockmaster by a partition +may keep serving reads of older data until its lease ends. ## When a host is lost diff --git a/seaweed-block/docs/releases/replicated-volumes-preview.md b/seaweed-block/docs/releases/replicated-volumes-preview.md index a53f391031..7c65dc2caa 100644 --- a/seaweed-block/docs/releases/replicated-volumes-preview.md +++ b/seaweed-block/docs/releases/replicated-volumes-preview.md @@ -26,11 +26,9 @@ writing guest: replica, so a replica whose connection dropped can keep showing `healthy` while it misses writes. Use `sync-quorum` when the replicas must hold the data. -**Planned for v1.0.1.** Supported: RF3 `sync-quorum` installed on hosts (writes continue through one replica's -fault, and that replica returns by itself), and RF2 `sync-quorum` with its limit (no acknowledged write is lost and -failover is automatic, but writes stop while either replica is out). `sync-all` and Kubernetes RF3 stay a preview. In -every replicated configuration, an old primary cut off from blockmaster by a partition may keep serving reads of -older data until its lease ends. +**Planned for v1.1.0.** Supported replicated volumes are planned for v1.1.0; v1.0.1 keeps every replicated +configuration a preview. In every replicated configuration, an old primary cut off from blockmaster by a partition +may keep serving reads of older data until its lease ends. **Carrying over.** No change to the store format is planned for the release that lifts the preview, so a replicated volume created under it is expected to carry over without re-creating it. That release's design is still under From 09699673c72cf55ec8229d77a14a7489f294f34f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 10:04:21 -0800 Subject: [PATCH 04/19] test: reject missing layout capabilities and unsafe wrapper fallbacks --- .../durable/remote_capabilities_test.go | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 seaweed-block/core/frontend/durable/remote_capabilities_test.go diff --git a/seaweed-block/core/frontend/durable/remote_capabilities_test.go b/seaweed-block/core/frontend/durable/remote_capabilities_test.go new file mode 100644 index 0000000000..1a91efa091 --- /dev/null +++ b/seaweed-block/core/frontend/durable/remote_capabilities_test.go @@ -0,0 +1,149 @@ +package durable + +import ( + "context" + "errors" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +type incompleteRemote struct { + storage.ChunkRemote + fullReads int +} + +func (r *incompleteRemote) GetHead(context.Context) (storage.ChunkHead, error) { + r.fullReads++ + return storage.ChunkHead{}, nil +} + +func TestCloseBoundRemoteRefusesMissingCapabilities(t *testing.T) { + inner := &incompleteRemote{} + r := &closeBoundRemote{ChunkRemote: inner, done: context.Background()} + if err := r.CheckCommit(context.Background(), storage.ChunkHeadVersion{}, storage.ChunkHead{}); err == nil { + t.Error("missing CheckCommit silently passed") + } + if _, err := r.GetHeadRoot(context.Background()); err == nil { + t.Error("missing GetHeadRoot silently passed") + } + if inner.fullReads != 0 { + t.Errorf("root-only read fell back to %d full manifest reads", inner.fullReads) + } + if r.BoundsHeadStep() { + t.Error("missing BoundsHeadStep claimed a bounded step") + } +} + +type missingCheckRemote struct { + storage.ChunkRemote + storage.ChunkKeyer + storage.ChunkHeadStepBounder + storage.ChunkHeadRootReader +} +type missingBoundRemote struct { + storage.ChunkRemote + storage.ChunkKeyer + storage.ChunkCommitChecker + storage.ChunkHeadRootReader +} +type missingRootRemote struct { + storage.ChunkRemote + storage.ChunkKeyer + storage.ChunkCommitChecker + storage.ChunkHeadStepBounder +} + +func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing.T) { + for _, missing := range []string{"CheckCommit", "BoundsHeadStep", "GetHeadRoot"} { + t.Run(missing, func(t *testing.T) { + fixture := newKZLayout(t) + cfg := ProviderConfig{Impl: ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 256, BlockSize: 4096, ChunkBlocks: 16, + ChunkLayoutHeadFor: func(string) (layout.StartStore, error) { return fixture.cat.Store(fixture.ref) }, + ChunkLayoutRemoteFor: func(_ string, me layout.HolderID) (storage.ChunkRemote, error) { + lr, err := chunkstore.NewLayoutRemote(fixture.cat, fixture.ref, me) + if err != nil { + return nil, err + } + switch missing { + case "CheckCommit": + return &missingCheckRemote{lr, lr, lr, lr}, nil + case "BoundsHeadStep": + return &missingBoundRemote{lr, lr, lr, lr}, nil + default: + return &missingRootRemote{lr, lr, lr, lr}, nil + } + }, + } + p, err := NewDurableProvider(cfg, precopyQueueView{frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 3, EndpointVersion: 1}}) + if err != nil { + t.Fatal(err) + } + defer p.Close() + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + if _, err := p.RecoverVolume(context.Background(), "v1"); err == nil { + t.Fatalf("layout remote missing %s was accepted at startup", missing) + } + for _, s := range p.DurableStatuses() { + if s.Operational { + t.Fatal("unsupported layout remote served") + } + } + }) + } +} + +type capabilityProbe struct { + storage.ChunkRemote + got context.Context + expected storage.ChunkHeadVersion + next storage.ChunkHead + rootCalls int +} + +var errProbeCheck = errors.New("object check refused") + +func (r *capabilityProbe) CheckCommit(c context.Context, e storage.ChunkHeadVersion, n storage.ChunkHead) error { + r.got = c + r.expected = e + r.next = n + return errProbeCheck +} +func (r *capabilityProbe) BoundsHeadStep() bool { return true } +func (r *capabilityProbe) GetHeadRoot(c context.Context) (storage.ChunkHead, error) { + r.got = c + r.rootCalls++ + return storage.ChunkHead{Gen: 17, Epoch: 3, Holder: "host-a/replica"}, nil +} +func TestCloseBoundRemoteForwardsCapabilitiesAndClose(t *testing.T) { + done, cancel := context.WithCancel(context.Background()) + defer cancel() + probe := &capabilityProbe{} + r := &closeBoundRemote{ChunkRemote: probe, done: done} + expected := storage.ChunkHeadVersion{Gen: 16, Epoch: 3} + next := storage.ChunkHead{Gen: 17, Epoch: 3, Holder: "host-a/replica"} + if err := r.CheckCommit(context.Background(), expected, next); !errors.Is(err, errProbeCheck) || probe.expected != expected || probe.next.Holder != next.Holder { + t.Fatalf("check not forwarded: err=%v expected=%+v next=%+v", err, probe.expected, probe.next) + } + if !r.BoundsHeadStep() { + t.Fatal("bounded step lost") + } + h, err := r.GetHeadRoot(context.Background()) + if err != nil || h.Gen != 17 || h.Epoch != 3 || h.Holder != "host-a/replica" || probe.rootCalls != 1 { + t.Fatalf("root not forwarded: %+v %v", h, err) + } + cancel() + _ = r.CheckCommit(context.Background(), expected, next) + if !errors.Is(probe.got.Err(), context.Canceled) { + t.Fatal("CheckCommit not canceled on Close") + } + _, _ = r.GetHeadRoot(context.Background()) + if !errors.Is(probe.got.Err(), context.Canceled) { + t.Fatal("GetHeadRoot not canceled on Close") + } +} From 1dca8789e479ee4f612acb28ec8eb528ed2634e4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 10:08:47 -0800 Subject: [PATCH 05/19] fix: require layout capabilities before attaching and refuse missing forwards --- .../core/frontend/chunkstore/layout_remote.go | 7 +++-- .../durable/cut_durable_before_cas_test.go | 14 ++++++++++ .../core/frontend/durable/provider_chunk.go | 27 ++++++++++++++----- .../durable/provider_chunk_lifetime_test.go | 20 ++++++++++++-- .../durable/provider_seal_progress_test.go | 8 ++++++ .../durable/remote_capabilities_test.go | 19 ++++++++----- seaweed-block/docs/design/invariants.md | 5 ++-- 7 files changed, 81 insertions(+), 19 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/layout_remote.go b/seaweed-block/core/frontend/chunkstore/layout_remote.go index 010d71da8e..6bc82e7602 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_remote.go +++ b/seaweed-block/core/frontend/chunkstore/layout_remote.go @@ -117,8 +117,11 @@ func (l *LayoutRemote) ProbeSnapshots(ctx context.Context) (map[string]struct{}, } var ( - _ storage.ChunkRemote = (*LayoutRemote)(nil) - _ storage.ChunkKeyer = (*LayoutRemote)(nil) + _ storage.ChunkRemote = (*LayoutRemote)(nil) + _ storage.ChunkKeyer = (*LayoutRemote)(nil) + _ storage.ChunkCommitChecker = (*LayoutRemote)(nil) + _ storage.ChunkHeadStepBounder = (*LayoutRemote)(nil) + _ storage.ChunkHeadRootReader = (*LayoutRemote)(nil) ) // NewLayoutRemote returns the remote of volume v for the holder me (the diff --git a/seaweed-block/core/frontend/durable/cut_durable_before_cas_test.go b/seaweed-block/core/frontend/durable/cut_durable_before_cas_test.go index 5e6da7e12d..9639ee00d5 100644 --- a/seaweed-block/core/frontend/durable/cut_durable_before_cas_test.go +++ b/seaweed-block/core/frontend/durable/cut_durable_before_cas_test.go @@ -40,6 +40,20 @@ func (r *casObservedRemote) GetHead(ctx context.Context) (storage.ChunkHead, err return r.ChunkRemote.GetHead(ctx) } +func (r *casObservedRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) { + r.reads++ + if r.onGetHead != nil { + r.onGetHead(r.reads) + } + return r.ChunkRemote.(storage.ChunkHeadRootReader).GetHeadRoot(ctx) +} +func (r *casObservedRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error { + return r.ChunkRemote.(storage.ChunkCommitChecker).CheckCommit(ctx, expected, next) +} +func (r *casObservedRemote) BoundsHeadStep() bool { + return r.ChunkRemote.(storage.ChunkHeadStepBounder).BoundsHeadStep() +} + func (r *casObservedRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) { r.cass++ gen, err := r.ChunkRemote.CASHead(ctx, expected, next) diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index fab1a4a412..2a4a770c7c 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -56,9 +56,10 @@ var ( var ErrChunkStaleLocalRoot = errors.New("durable: local volume predates a HEAD published by another holder") var ( - errProviderClosed = errors.New("durable: provider closed") - errChunkForeignClaim = errors.New("durable: HEAD claim refused by another holder") - errChunkNoAuthority = errors.New("durable: projection carries no master authority for the chunk layer") + errProviderClosed = errors.New("durable: provider closed") + errChunkForeignClaim = errors.New("durable: HEAD claim refused by another holder") + errChunkNoAuthority = errors.New("durable: projection carries no master authority for the chunk layer") + errChunkRemoteCapabilities = errors.New("durable: layout remote requires CheckCommit, BoundsHeadStep and GetHeadRoot") ) const ( @@ -506,6 +507,10 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h inner, err = p.cfg.ChunkLayoutRemoteFor(volumeID, me) } if err == nil { + capabilities, ok := inner.(layoutRemoteCapabilities) + if !ok || !capabilities.BoundsHeadStep() { + return nil, errChunkRemoteCapabilities + } p.mu.Lock() h.layoutHolder, h.layoutHead, h.layoutRemote = me, st, inner p.mu.Unlock() @@ -595,6 +600,14 @@ func (p *DurableProvider) attachProgress() func(uint64) { return func(n uint64) { report(storage.RecoveryAttach, done.Add(n)) } } +// Layout adapters must keep the object's check outside the HEAD step and +// provide an identity-only read. Wrapping must not manufacture these features. +type layoutRemoteCapabilities interface { + storage.ChunkCommitChecker + storage.ChunkHeadStepBounder + storage.ChunkHeadRootReader +} + // closeBoundRemote ends every remote call when the provider closes, so a // shutdown never waits on the remote for an attach or a cut. While an // attach runs, its calls also end with the attach caller's context. @@ -710,7 +723,7 @@ func (r *closeBoundRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, if reader, ok := r.ChunkRemote.(storage.ChunkHeadRootReader); ok { return reader.GetHeadRoot(c) } - return r.ChunkRemote.GetHead(c) + return storage.ChunkHead{}, fmt.Errorf("%w: GetHeadRoot unavailable", errChunkRemoteCapabilities) } func (r *closeBoundRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) { @@ -720,15 +733,15 @@ func (r *closeBoundRemote) CASHead(ctx context.Context, expected storage.ChunkHe } // CheckCommit forwards the commit's object check (storage.ChunkCommitChecker) -// with the same binding as CASHead. A remote without it passes: its CAS then -// runs the check itself. +// with the same binding as CASHead. A remote without it refuses; the +// wrapper must never manufacture a successful object check. func (r *closeBoundRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error { c, end := r.bind(ctx) defer end() if checker, ok := r.ChunkRemote.(storage.ChunkCommitChecker); ok { return checker.CheckCommit(c, expected, next) } - return nil + return fmt.Errorf("%w: CheckCommit unavailable", errChunkRemoteCapabilities) } // BoundsHeadStep forwards whether the wrapped remote bounds its own HEAD diff --git a/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go b/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go index cc7c7374a4..318b77036b 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go @@ -64,6 +64,22 @@ func (g *gatedRemote) hold(ctx context.Context, what string, ch chan struct{}) e } func (g *gatedRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { + return g.getHead(ctx, false) +} +func (g *gatedRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) { + return g.getHead(ctx, true) +} +func (g *gatedRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error { + return g.ChunkRemote.(storage.ChunkCommitChecker).CheckCommit(ctx, expected, next) +} +func (g *gatedRemote) BoundsHeadStep() bool { + return g.ChunkRemote.(storage.ChunkHeadStepBounder).BoundsHeadStep() +} +func (g *gatedRemote) getHead(ctx context.Context, rootOnly bool) (storage.ChunkHead, error) { + read := g.ChunkRemote.GetHead + if rootOnly { + read = g.ChunkRemote.(storage.ChunkHeadRootReader).GetHeadRoot + } g.mu.Lock() fail := g.failGetHead > 0 if fail { @@ -75,14 +91,14 @@ func (g *gatedRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { return storage.ChunkHead{}, errors.New("injected GetHead failure") } if g.holdAfter { - h, err := g.ChunkRemote.GetHead(ctx) + h, err := read(ctx) _ = g.hold(ctx, "gethead", ch) return h, err } if err := g.hold(ctx, "gethead", ch); err != nil { return storage.ChunkHead{}, err } - return g.ChunkRemote.GetHead(ctx) + return read(ctx) } // B Start reads HEAD through StartStore before constructing its content diff --git a/seaweed-block/core/frontend/durable/provider_seal_progress_test.go b/seaweed-block/core/frontend/durable/provider_seal_progress_test.go index dee6577f1d..15c28f723b 100644 --- a/seaweed-block/core/frontend/durable/provider_seal_progress_test.go +++ b/seaweed-block/core/frontend/durable/provider_seal_progress_test.go @@ -28,6 +28,14 @@ type sealProgressRemote struct { calls int } +func (r *sealProgressRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error { + return r.layoutRemote.CheckCommit(ctx, expected, next) +} +func (r *sealProgressRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) { + return r.layoutRemote.GetHeadRoot(ctx) +} +func (r *sealProgressRemote) BoundsHeadStep() bool { return r.layoutRemote.BoundsHeadStep() } + func (r *sealProgressRemote) AbortOpenSession(ctx context.Context) (string, error) { return r.layoutRemote.AbortOpenSession(ctx) } diff --git a/seaweed-block/core/frontend/durable/remote_capabilities_test.go b/seaweed-block/core/frontend/durable/remote_capabilities_test.go index 1a91efa091..b387924d31 100644 --- a/seaweed-block/core/frontend/durable/remote_capabilities_test.go +++ b/seaweed-block/core/frontend/durable/remote_capabilities_test.go @@ -58,7 +58,7 @@ type missingRootRemote struct { } func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing.T) { - for _, missing := range []string{"CheckCommit", "BoundsHeadStep", "GetHeadRoot"} { + for _, missing := range []string{"CheckCommit", "BoundsHeadStep", "GetHeadRoot", "complete"} { t.Run(missing, func(t *testing.T) { fixture := newKZLayout(t) cfg := ProviderConfig{Impl: ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 256, BlockSize: 4096, ChunkBlocks: 16, @@ -73,8 +73,10 @@ func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing. return &missingCheckRemote{lr, lr, lr, lr}, nil case "BoundsHeadStep": return &missingBoundRemote{lr, lr, lr, lr}, nil - default: + case "GetHeadRoot": return &missingRootRemote{lr, lr, lr, lr}, nil + default: + return lr, nil } }, } @@ -86,12 +88,17 @@ func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing. if _, err := p.EnsureStorage("v1"); err != nil { t.Fatal(err) } - if _, err := p.RecoverVolume(context.Background(), "v1"); err == nil { - t.Fatalf("layout remote missing %s was accepted at startup", missing) + _, err = p.RecoverVolume(context.Background(), "v1") + if missing == "complete" { + if err != nil { + t.Fatalf("complete layout remote refused: %v", err) + } + } else if !errors.Is(err, errChunkRemoteCapabilities) { + t.Fatalf("missing %s: want capability refusal, got %v", missing, err) } for _, s := range p.DurableStatuses() { - if s.Operational { - t.Fatal("unsupported layout remote served") + if s.Operational != (missing == "complete") { + t.Fatalf("%s operational=%v", missing, s.Operational) } } }) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index ea7351d744..2294136f3b 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -66,7 +66,7 @@ stateDiagram-v2 | — | CreateRefused | a new volume needs the durable root's free space >= its size + WAL, checked before the store, its WAL or its fresh marker is created (the replica floor, written when the assignment arrives, precedes the check and stays); the refusal ends the process with status 1; an existing volume opens and warns when its remaining data growth + WAL exceed the free space | `core/frontend/durable/headroom.go`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-LOCAL-HEADROOM-001` | | — | CreateRefused | a chunk volume in create mode (no local store yet): before the provider is built, the geometry flags are compared with the volume record; they disagree, or the record is there but does not decode: exit 78; the filer failed the read: exit 75; nothing is created; an absent record keeps the create path; an existing store is never rechecked against the flags | `cmd/blockvolume/main.go` (create-mode check); `cmd/blockvolume/chunk_remote.go` `geometryFlagsRefusal` | `INV-VOL-GEOMETRY-FLAGS-RECORD-001` | | Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001`, `INV-RECOVERY-PROGRESS-WINDOW-001` | -| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason); a workspace primary claims HEAD, listens and reports ready only while its lease guard permits now (`WorkspaceLeaseGuard.Held`; without a grant: `NotReadyReason=lease_not_held`, exit 75 after the start-time wait); a primary of a replicated line serves only when its own `--replication-ack` is the profile its assignment names (otherwise not Healthy, `NotReadyReason` naming both profiles, ahead of the backend's own refusal) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection`; `core/host/volume/workspace_lease.go` `Held`; `core/host/volume/workspace_startup.go` `noteAckProfile` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001`, `INV-PRIMARY-ACK-PROFILE-001` | +| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason); a workspace primary claims HEAD, listens and reports ready only while its lease guard permits now (`WorkspaceLeaseGuard.Held`; without a grant: `NotReadyReason=lease_not_held`, exit 75 after the start-time wait); a primary of a replicated line serves only when its own `--replication-ack` is the profile its assignment names (otherwise not Healthy, `NotReadyReason` naming both profiles, ahead of the backend's own refusal) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection`; `core/host/volume/workspace_lease.go` `Held`; `core/host/volume/workspace_startup.go` `noteAckProfile` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001`, `INV-PRIMARY-ACK-PROFILE-001`, `INV-LAYOUT-REMOTE-CAPABILITIES-001` | | Recovering | RecoveryFailed | a WAL integrity failure or an I/O error; the backend stays not operational and the host blocks local readiness with `wal_corrupt` or `io_error` | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `INV-WAL-TYPED-FAILCLOSED-001`, `INV-WAL-OPGATE-001`, `INV-WAL-V3-W-RECOVERY-001` | | Serving | Serving | each `Read`, `Write`, `Sync` passes the operational, chunk-fence and lineage checks; write admission samples the active writer's native pressure before waiting; a write is durable only when a covering `Sync` returns | `core/frontend/durable/storage_adapter.go` `gate`; `core/storage/walstore.go` `WALStore.Sync` | `INV-FE-LINEAGE-GATE-001`, `INV-WAL-SYNC-FRONTIER-001`, `INV-FE-FUA-SYNC-001`, `INV-FE-FLUSH-SYNC-001`, `INV-WAL-V3-ADMISSION-001`, `INV-WAL-V3-W-001` | | Serving | Serving (checkpoint) | the flusher binds its snapshot/materialization to one recovery lifetime; extent and owned COW map are durable before the shared descriptor publisher advances checkpoint/tail; both slot tails pin reuse | `core/storage/flusher.go` `flushOnceInternal`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `INV-WAL-CHECKPOINT-SNAPSHOT-001`, `INV-WAL-REUSE-PERSISTED-TAIL-001`, `INV-WAL-CKPT-META-FAIL-001`, `INV-CUT-BITMAP-001`, `INV-WAL-FLUSH-SYNC-COVERS-WAL-001`, `INV-WAL-V3-RECLAIM-001`, `INV-WAL-V3-PUBLISH-NONCE-FLOOR-001`, `INV-WAL-V3-MAP-PRIOR-LIVE-001` | @@ -900,6 +900,7 @@ Notes: | `INV-CUT-QUIESCED-001` | HEAD is exactly the image at a quiesced cut H, and H is a synced LSN. | M5 Quiesce → Copy → CAS | `core/storage/chunk_layer.go` `captureLocked` | `TestChunkLayer_C1_HeadIsQuiescedCutImage`, `TestChunkLayer_C3_EveryHeadIsExactUnderConcurrentWrites` (`core/storage/chunk_layer_contract_test.go`) | `CutPipeline` `HeadImage`; `CutCapture` `HeadImage` | ACTIVE | | `INV-CUT-BIRTH-001` | Retired: B does not store per-chunk BirthLSN; `INV-SNAPK-COMMIT-REACH-001` protects the published object graph, and the surviving barrier-image test protects the cut image. | legacy M5 | — | — | — | ARCHIVED | | `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window. | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy` (`core/storage/chunk_cut_progress_test.go`); `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`); `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied` (`core/storage/chunk_layer_precopy_test.go`); `TestNativeReplacementRecoverInvalidatesStagedImage` (`core/storage/legacy_replacement_v3_test.go`); `TestChunkStageV3_MidUploadAbortReducesRetryBytes` (`core/storage/chunk_abort_upload_bytes_test.go`); `TestCutRevokedMidUploadKeepsItsUploads` (`core/storage/chunk_cut_revoke_reuse_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | +| `INV-LAYOUT-REMOTE-CAPABILITIES-001` | A provider attaches only a layout remote with commit checking, a bounded HEAD step and identity-only HEAD reads. Its wrapper refuses missing check/read capabilities and never substitutes a full manifest read or a successful check. | M1 attach; M5 object check and HEAD confirmation | `LayoutRemote` compile-time assertions; `DurableProvider.newChunkLayer`; `closeBoundRemote` | `TestCloseBoundRemoteRefusesMissingCapabilities`, `TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart`, `TestCloseBoundRemoteForwardsCapabilitiesAndClose` (`core/frontend/durable/remote_capabilities_test.go`) | existing adapter contract (no state or transition change) | ACTIVE | | `INV-CUT-RETRY-FAIRNESS-001` | New staging retries without backoff; zero progress backs off. Dirty-start cleaning waits for a completed store attempt or one maintenance interval. K=3 admitted stalled background attempts yield reusable staging, never a pending or active/newer cut. | M5 Stage, M6 Clean (CUT-BUDGET B1/B3) | `core/frontend/durable/provider_chunk.go`; `core/frontend/durable/chunk_snapshot_schedule.go`; `core/storage/chunk_periodic_cut.go` | `TestCutLoopProgressRetriesWithoutBackoff`, `TestScheduledSnapshotProgressRetriesWithoutBackoff`, `TestDirtyStartCleaningWaitsForFirstCutAttempt`, `TestDirtyStartCaptureRefusalsDoNotReleaseCleaning`, `TestStalledCutYieldsSessionToCleaning` (`core/frontend/durable/cut_progress_test.go`); `TestDiscardStagedRechecksCaptureState` (`core/storage/chunk_stalled_discard_test.go`); `TestLayoutStalledSessionYieldAllowsCleaning` (`core/frontend/chunkstore/layout_stalled_discard_test.go`) | `CommitReach` `CBegin` (existing session exclusion; scheduling only) | ACTIVE | | `INV-CUT-STAGED-COUNT-001` | `Stats.StagedChunks` counts each chunk staging finished (remembered for reuse) in every cut attempt, an interrupted round included, and only grows; a re-staged chunk counts again; it is in-process. A cut's `PayloadNs` includes its staging rounds whether or not they uploaded. | M5 Stage (before the barrier) | `core/storage/chunk_cut_payload.go` `rememberPayload`, `streamCutPayloads`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkStage_StagedChunksCountsFailedAttempts`, `TestChunkStage_StagedChunksCountsAnInterruptedRound`, `TestChunkStage_PayloadTimeCountsStagingWithoutUploads` (`core/storage/chunk_stage_accounting_test.go`) | — | ACTIVE | | `INV-CUT-BITMAP-001` | The owned map never under-reports: its checkpoint coverage is durable before WAL recycling; UNKNOWN is cleared only after definite HEAD publication (a cut, or a fresh store's claim: `INV-CUT-FRESH-KNOWN-ZERO-001`) and an unchanged capture token. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `core/storage/chunk_layer_map_v3.go` `persistCapturedMapV3` | `TestWALStoreV3_AutomaticMapCheckpoint` (`core/storage/walstore_map_checkpoint_v3_test.go`); `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN` (`core/storage/chunk_layer_map_v3_test.go`) | `CutCapture` `HeadImage` | ACTIVE | @@ -1300,4 +1301,4 @@ replay, reclaim indexing, attach. Counts are cumulative within each phase across same-process retries; a repeated or earlier frontier is not progress. Late progress cannot clear an already elapsed inactivity window. The existing same-epoch promotion-ready fact alone clears the timeout latch. C.L's start -rows remain STUB until recovery and attach controls are qualified together. \ No newline at end of file +rows remain STUB until recovery and attach controls are qualified together. From 8999b186b30f0b312ceb137d47d2132b1bb5fcd7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 10:12:23 -0800 Subject: [PATCH 06/19] test: remove retired full-head fallback from reader census --- seaweed-block/core/frontend/chunkstore/head_readers_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/seaweed-block/core/frontend/chunkstore/head_readers_test.go b/seaweed-block/core/frontend/chunkstore/head_readers_test.go index 60c07d8e22..2b3bdf2068 100644 --- a/seaweed-block/core/frontend/chunkstore/head_readers_test.go +++ b/seaweed-block/core/frontend/chunkstore/head_readers_test.go @@ -61,7 +61,6 @@ var headReaders = map[string]string{ "cmd/sw-block/chunk_b.go chunkShowContext -> ReadHead": "found=false: prints a null head, including via the chunkShow wrapper (probe TestOpsChunk_AbsentVolume)", "cmd/sw-block/chunk_b.go chunkSnapshots -> ReadHead": "refuses volume_not_found (probe TestOpsChunk_AbsentVolume)", "core/frontend/durable/provider_chunk.go GetHead -> GetHead": "ErrHeadAbsent from the layout remote (probe LayoutRemote)", - "core/frontend/durable/provider_chunk.go GetHeadRoot -> GetHead": "ErrHeadAbsent from the layout remote (probe LayoutRemote)", "core/frontend/durable/provider_chunk.go GetHeadRoot -> GetHeadRoot": "ErrHeadAbsent from the layout remote (probe LayoutRemote)", "core/storage/chunk_head_belt.go confirmChunkHead -> GetHead": "ErrHeadAbsent from the layout remote: not confirmed (probe LayoutRemote)", "core/storage/chunk_head_belt.go confirmChunkHead -> GetHeadRoot": "ErrHeadAbsent from the layout remote: not confirmed (probe LayoutRemote)", From 56286ab00451bf01352df650f626ec608dd208de Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 10:27:13 -0800 Subject: [PATCH 07/19] test: require verify options and stable HEAD observations --- .../cmd/sw-block/chunk_verify_test.go | 13 +++++++ .../frontend/chunkstore/layout_verify_test.go | 39 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/seaweed-block/cmd/sw-block/chunk_verify_test.go b/seaweed-block/cmd/sw-block/chunk_verify_test.go index 38cda8165b..82ca4c61e4 100644 --- a/seaweed-block/cmd/sw-block/chunk_verify_test.go +++ b/seaweed-block/cmd/sw-block/chunk_verify_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" +"fmt" "fmt" "path" "strings" @@ -227,3 +228,15 @@ func TestOpsChunk_VerifyStartCheckIsBoundedByTheTimeout(t *testing.T) { t.Errorf("verify: exit %d, out %q; want a retryable remote_unavailable refusal", code, out.String()) } } + +func TestOpsChunkVerifyRefusesUnsupportedFlagsBeforeDial(t *testing.T) { + old := dialChunkFiler + dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return nil, nil, fmt.Errorf("unsupported option reached dial") } + t.Cleanup(func(){ dialChunkFiler = old }) + for _, arg := range []string{"--snapshot=s1", "--all-snapshots", "--all-snapshots=false", "--concurrency=1", "--bytes-per-sec=0"} { + t.Run(arg, func(t *testing.T){ + code,out,_ := runChunk("verify", "--volume=v1", "--chunk-filer=f:1", arg) + if code != 2 || chunkErrorOut(t,out).Code != codeBadRequestCLI || !strings.Contains(out,"unsupported") { t.Fatalf("exit=%d out=%s",code,out) } + }) + } +} diff --git a/seaweed-block/core/frontend/chunkstore/layout_verify_test.go b/seaweed-block/core/frontend/chunkstore/layout_verify_test.go index 663f84386b..6a5e1927e7 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_verify_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout_verify_test.go @@ -152,3 +152,42 @@ func snapshotStore(fb filerBlobs) string { puts, _, stored := fb.fakeBlobs.counts() return fmt.Sprintf("puts=%d stored=%d %s", puts, stored, strings.Join(keys, ",")) } + +type verifyChangingHead struct { filerBlobs; reads int; mode string } +func (f *verifyChangingHead) LookupEntry(ctx context.Context, dir, name string) (*filerpb.Entry,error) { + e,err := f.filerBlobs.LookupEntry(ctx,dir,name) + if name != layout.HeadName || err != nil { return e,err } + f.reads++ + e=proto.Clone(e).(*filerpb.Entry) + if f.reads >= 2 { + switch f.mode { + case "advance": e.Extended[layoutGen]=[]byte("2") + case "absent": return nil,ErrNotFound + case "error": return nil,fmt.Errorf("injected confirmation failure") + case "unknown": delete(e.Extended,layoutGen) + } + } + return e,nil +} +func TestVerifyLayoutRequiresStableHeadForMissingAndOrphans(t *testing.T) { + for _,mode := range []string{"stable","advance","absent","error","unknown"} { + t.Run(mode,func(t *testing.T){ + fb,id:=verifyFixtureVolume(t) + hp:=path.Join("/blocks",layout.VolumeDir("v",id),layout.HeadName) + fb.fakeFiler.entries[hp].Extended=map[string][]byte{layoutKind:[]byte("head"),layoutVolume:[]byte(id.String()),layoutGen:[]byte("1")} + c:=layout.NameChunk(0,[]byte(strings.Repeat("a",64))) + delete(fb.fakeFiler.entries,path.Join("/blocks",layout.VolumeDir("v",id),c.Path())) + extra:=layout.NameChunk(9,[]byte("orphan")) + putFile(t,fb.fakeFiler,path.Join("/blocks",layout.VolumeDir("v",id),extra.Path()),[]byte("orphan")) + f:=&verifyChangingHead{filerBlobs:fb,mode:mode} + r,err:=VerifyLayout(context.Background(),f,"/blocks",layout.VolumeDir("v",id),layout.VerifyOptions{Orphans:true}) + if err != nil { t.Fatal(err) } + if mode=="stable" { + if !r.Complete || len(r.Findings)!=2 || f.reads!=2 { t.Fatalf("stable: %+v reads=%d",r,f.reads) } + } else { + for _,finding:=range r.Findings { if finding.Class==layout.FindMissing || finding.Class==layout.FindOrphan { t.Fatalf("unstable HEAD published finding: %+v reads=%d",r,f.reads) } } + if r.Complete || r.OrphansChecked || r.Incomplete=="" { t.Fatalf("unstable pass looks complete: %+v",r) } + } + }) + } +} From c0b8242b1f97874cec786d3b5311a24a30492ff2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 10:28:05 -0800 Subject: [PATCH 08/19] ci: the PR template asks the five questions, Weakens among them Co-Authored-By: Claude Opus 5.5 --- seaweed-block/.github/pull_request_template.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/seaweed-block/.github/pull_request_template.md b/seaweed-block/.github/pull_request_template.md index 6ea6d32104..7019263e14 100644 --- a/seaweed-block/.github/pull_request_template.md +++ b/seaweed-block/.github/pull_request_template.md @@ -4,6 +4,13 @@ Model: Simplest: +Five questions, answered in plain words before review: +Serves: +Decided by: +Layer use: +Deviation buys: +Weakens: +