From fcb170c8d8d614ba75a09ca4842637968038032c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 21:00:46 -0800 Subject: [PATCH 1/5] test(chunkstore): measure unchanged manifest group scaling --- .../chunkstore/manifest_scaling_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 seaweed-block/core/frontend/chunkstore/manifest_scaling_test.go diff --git a/seaweed-block/core/frontend/chunkstore/manifest_scaling_test.go b/seaweed-block/core/frontend/chunkstore/manifest_scaling_test.go new file mode 100644 index 0000000000..dd093d6c84 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/manifest_scaling_test.go @@ -0,0 +1,36 @@ +package chunkstore + +import ( + "context" + "fmt" + "testing" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// Metadata-only scaling probe: one chunk per 1-GiB segment, all unchanged. +// No volume data allocation or remote I/O is included. Report ns/op and allocs; +// the old per-group scan visits groups*groups base references. +func BenchmarkPrepareManifestUnchangedGroups(b *testing.B) { + for _, n := range []int{256, 1024, 4096} { + b.Run(fmt.Sprint(n), func(b *testing.B) { + r, err := NewChunkRemote(newFakeFiler(), newFakeBlobs(), "/chunks/v1") + if err != nil { + b.Fatal(err) + } + base := storage.ChunkHead{Chunks: map[uint64]storage.ChunkRef{}, Segments: map[uint64]storage.ChunkSegment{}, ChunkBytes: 1 << 30, ManifestChunkCount: n} + for i := 0; i < n; i++ { + base.Chunks[uint64(i)] = storage.ChunkRef{Key: fmt.Sprintf("@v1/chunk/%d", i)} + base.Segments[uint64(i)] = storage.ChunkSegment{Key: fmt.Sprintf("@v1/seg/%d", i), Owner: "v1", Count: 1} + } + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + next, ids, err := r.PrepareManifest(context.Background(), base, base, 1<<30) + if err != nil || len(ids) != 0 || len(next.Segments) != n { + b.Fatalf("unchanged segment reuse: %v, intents=%v", err, ids) + } + } + }) + } +} From 1f36db305f173bc9cca00f096f07b7bdb8ea5564 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 21:06:23 -0800 Subject: [PATCH 2/5] fix(chunkstore): partition base manifest chunks once per preparation --- .../core/frontend/chunkstore/manifest.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/manifest.go b/seaweed-block/core/frontend/chunkstore/manifest.go index 01781b4b06..9a4708655d 100644 --- a/seaweed-block/core/frontend/chunkstore/manifest.go +++ b/seaweed-block/core/frontend/chunkstore/manifest.go @@ -90,14 +90,19 @@ func (r *ChunkRemote) PrepareManifest(ctx context.Context, base, next storage.Ch data []byte } var uploads []upload - for group, chunks := range groups { - old := map[uint64]storage.ChunkRef{} - for idx, ref := range base.Chunks { - if idx/per == group { - ref.Key = qualifyManifestKey(owner, ref.Key) - old[idx] = ref - } + // Partition the base once, rather than scanning every base chunk for each + // segment group. Keep the same qualified-key comparison for segment reuse. + baseGroups := map[uint64]map[uint64]storage.ChunkRef{} + for idx, ref := range base.Chunks { + group := idx / per + if baseGroups[group] == nil { + baseGroups[group] = map[uint64]storage.ChunkRef{} } + ref.Key = qualifyManifestKey(owner, ref.Key) + baseGroups[group][idx] = ref + } + for group, chunks := range groups { + old := baseGroups[group] if previous, ok := base.Segments[group]; ok && base.ChunkBytes == chunkBytes && reflect.DeepEqual(chunks, old) { next.Segments[group] = previous continue From 766596ffd76249487c513c4e17223e844ce1444a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 21:07:15 -0800 Subject: [PATCH 3/5] docs: record manifest base partition cost invariant --- seaweed-block/docs/design/invariants.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index b032a37af0..d2e60e38ba 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -469,6 +469,12 @@ Notes: |---|---|---|---|---|---|---| | `INV-NVME-H2C-RANGE-001` | An H2CData range exceeding the expected transfer size is refused before slicing, including a uint32 offset-plus-length overflow; an exact-bound payload is preserved. | Frontend H2C receive validation; no storage state transition | `core/frontend/nvme/session.go` `recvH2CData` | `TestRecvH2CDataRangeBounds` (`core/frontend/nvme/h2c_bounds_test.go`) | — | ACTIVE | +### Manifest preparation scan cost + +| ID | Invariant | Transition | Enforced in | Regression/qualification | Model | Status | +|---|---|---|---|---|---|---| +| `INV-CUT-MANIFEST-SCAN-001` | PrepareManifest partitions base references once; each segment compares only its own base group. Unchanged segment identities remain reusable. | M5 Manifest | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `BenchmarkPrepareManifestUnchangedGroups`; `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` | Algorithmic cost; no state/transition change to `CutPipeline` | ACTIVE | + ## Part C. Change rules How a fix or a feature is calibrated against this model: From ebe1b0bd13e318c70cec62d4fcd94444c87dd5e2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 21:50:16 -0800 Subject: [PATCH 4/5] test: include reproducible manifest scaling qualification checker --- .../scripts/check-manifest-scaling.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 seaweed-block/scripts/check-manifest-scaling.py diff --git a/seaweed-block/scripts/check-manifest-scaling.py b/seaweed-block/scripts/check-manifest-scaling.py new file mode 100644 index 0000000000..1ad129ccb7 --- /dev/null +++ b/seaweed-block/scripts/check-manifest-scaling.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Check three-sample manifest benchmark scaling; no device or host access. + +Run go test with -bench BenchmarkPrepareManifestUnchangedGroups -benchtime=20x +-count=3, save stdout, then pass that file to this checker. A 16x metadata +scale must grow less than 64x on the same serial runner. This is an explicit +qualification benchmark, not a wall-clock CI unit test. +""" +import re +import statistics +import sys +from pathlib import Path + +if len(sys.argv) != 2: + raise SystemExit("usage: check-manifest-scaling.py BENCHMARK_LOG") +samples = {256: [], 1024: [], 4096: []} +for count, ns in re.findall( + r"BenchmarkPrepareManifestUnchangedGroups/(256|1024|4096)-\d+\s+\d+\s+(\d+) ns/op", + Path(sys.argv[1]).read_text(encoding="utf-8-sig"), +): + samples[int(count)].append(int(ns)) +if any(len(values) != 3 for values in samples.values()): + raise SystemExit("need exactly three samples per group count") +medians = {count: statistics.median(values) for count, values in samples.items()} +if min(medians.values()) <= 0: + raise SystemExit("benchmark durations must be positive") +growth = medians[4096] / medians[256] +print("median_ns", medians, "growth_4096_over_256", growth, "limit", 64) +raise SystemExit(0 if growth < 64 else 1) From 6de4d89a98cd3953bcd05510ba967f8e56cfeda4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 22:57:06 -0800 Subject: [PATCH 5/5] chore: keep public PR changes to implementation and tests --- seaweed-block/docs/design/invariants.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index d2e60e38ba..b032a37af0 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -469,12 +469,6 @@ Notes: |---|---|---|---|---|---|---| | `INV-NVME-H2C-RANGE-001` | An H2CData range exceeding the expected transfer size is refused before slicing, including a uint32 offset-plus-length overflow; an exact-bound payload is preserved. | Frontend H2C receive validation; no storage state transition | `core/frontend/nvme/session.go` `recvH2CData` | `TestRecvH2CDataRangeBounds` (`core/frontend/nvme/h2c_bounds_test.go`) | — | ACTIVE | -### Manifest preparation scan cost - -| ID | Invariant | Transition | Enforced in | Regression/qualification | Model | Status | -|---|---|---|---|---|---|---| -| `INV-CUT-MANIFEST-SCAN-001` | PrepareManifest partitions base references once; each segment compares only its own base group. Unchanged segment identities remain reusable. | M5 Manifest | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `BenchmarkPrepareManifestUnchangedGroups`; `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` | Algorithmic cost; no state/transition change to `CutPipeline` | ACTIVE | - ## Part C. Change rules How a fix or a feature is calibrated against this model: