From 85d83237f491464fd7fdcf30056f18eed86b0d8f Mon Sep 17 00:00:00 2001 From: pingqiu-cpu Date: Thu, 3 Dec 2026 05:06:39 -0800 Subject: [PATCH] fix(snapshot): omit the uncomputed chunk count from answers (#983) Merge note (pull_request_target spec-trace workflow has a startup_failure on every branch since 2026-12-02 22:45Z, so its checks run locally): - Test run 47108982354 succeeded (go test (linux), process-level tests (real binaries)) on head d120a2c3 against main 20d58908, the current main head. - spec-trace-check.sh and public-text-check.sh, run with the main branch's scripts against this head and body: both exit 0. - Code review ACCEPT on 18f26292, no findings: the create/list answers drop the uncomputed chunk count without traversing manifests or rewriting receipts. --- seaweed-block/core/frontend/chunkstore/api.go | 3 +- .../core/frontend/chunkstore/control_types.go | 1 - .../core/host/volume/chunk_control.go | 3 +- .../core/host/volume/chunk_control_test.go | 4 +- .../host/volume/snapshot_chunk_count_test.go | 78 +++++++++++++++++++ seaweed-block/docs/design/invariants.md | 1 + seaweed-block/docs/releases/README.md | 1 + seaweed-block/docs/releases/v1.1.1.md | 10 +++ seaweed-block/docs/status-schema.md | 14 ++++ seaweed-block/docs/time-bounds.tsv | 12 +-- seaweed-block/docs/volume-lifecycle.md | 12 +++ 11 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 seaweed-block/core/host/volume/snapshot_chunk_count_test.go create mode 100644 seaweed-block/docs/releases/v1.1.1.md diff --git a/seaweed-block/core/frontend/chunkstore/api.go b/seaweed-block/core/frontend/chunkstore/api.go index 605b8437ce..23f511d3c4 100644 --- a/seaweed-block/core/frontend/chunkstore/api.go +++ b/seaweed-block/core/frontend/chunkstore/api.go @@ -17,7 +17,6 @@ type SnapshotListItem struct { CutLSN uint64 `json:"cutLSN"` CreatedNs int64 `json:"createdNs"` State string `json:"state"` - ChunkCount int `json:"chunkCount"` Labels map[string]string `json:"labels"` Consistency string `json:"consistency"` Parent *Parent `json:"parent"` @@ -36,7 +35,7 @@ func NewSnapshotListBody(vol string, list []SnapshotInfo, next string) SnapshotL body := SnapshotListBody{VolumeID: vol, Snapshots: make([]SnapshotListItem, 0, len(list)), Next: next} for _, s := range list { body.Snapshots = append(body.Snapshots, SnapshotListItem{Name: s.Name, Root: s.Root, Dependents: s.Dependents, Class: s.Class, ExpiresAtNs: s.ExpiresAtNs, HeadGen: s.HeadGen, HeadEpoch: s.HeadEpoch, - CutLSN: s.CutLSN, CreatedNs: s.CreatedNs, State: s.State, ChunkCount: s.ChunkCount, Labels: s.Labels, + CutLSN: s.CutLSN, CreatedNs: s.CreatedNs, State: s.State, Labels: s.Labels, Consistency: s.Consistency, Parent: s.Parent}) } return body diff --git a/seaweed-block/core/frontend/chunkstore/control_types.go b/seaweed-block/core/frontend/chunkstore/control_types.go index ca2e3fdcb8..6c0c15ca29 100644 --- a/seaweed-block/core/frontend/chunkstore/control_types.go +++ b/seaweed-block/core/frontend/chunkstore/control_types.go @@ -122,7 +122,6 @@ type SnapshotInfo struct { CutLSN uint64 `json:"cutLSN"` CreatedNs int64 `json:"createdNs"` State string `json:"state"` - ChunkCount int `json:"chunkCount"` // ManifestBytes is the snapshot's manifest size (its root and every // segment), written once by the commit that named it; null when unknown // (a snapshot named before v1.1 recorded it), never 0. diff --git a/seaweed-block/core/host/volume/chunk_control.go b/seaweed-block/core/host/volume/chunk_control.go index 557b15e8ce..a3292a422e 100644 --- a/seaweed-block/core/host/volume/chunk_control.go +++ b/seaweed-block/core/host/volume/chunk_control.go @@ -205,7 +205,6 @@ type snapshotBody struct { HeadEpoch uint64 `json:"headEpoch"` CutLSN uint64 `json:"cutLSN"` CreatedNs int64 `json:"createdNs"` - ChunkCount int `json:"chunkCount"` ManifestBytes *uint64 `json:"manifestBytes"` // null: unknown Consistency string `json:"consistency"` Labels map[string]string `json:"labels"` @@ -677,7 +676,7 @@ func (s *StatusServer) handleChunkSnapshot(w http.ResponseWriter, r *http.Reques return } writeChunkJSON(w, http.StatusOK, snapshotBody{VolumeID: info.VolumeID, Name: info.Name, HeadGen: info.HeadGen, - HeadEpoch: info.HeadEpoch, CutLSN: info.CutLSN, CreatedNs: info.CreatedNs, ChunkCount: info.ChunkCount, + HeadEpoch: info.HeadEpoch, CutLSN: info.CutLSN, CreatedNs: info.CreatedNs, ManifestBytes: info.ManifestBytes, Consistency: info.Consistency, Labels: info.Labels, Replayed: info.Replayed}) } diff --git a/seaweed-block/core/host/volume/chunk_control_test.go b/seaweed-block/core/host/volume/chunk_control_test.go index 149faf028d..2fc456edb9 100644 --- a/seaweed-block/core/host/volume/chunk_control_test.go +++ b/seaweed-block/core/host/volume/chunk_control_test.go @@ -186,7 +186,7 @@ func TestStatusServer_ChunkSuccessBodiesUseSpecFields(t *testing.T) { if w.Code != 200 || ctl.lastSnap.Name != "s1" || ctl.lastSnap.RequestID != "r" || ctl.lastSnap.Consistency != "app" || ctl.lastSnap.Labels["agent.step"] != "x" || ctl.lastSnap.ExpiresAtNs != 9 { t.Fatalf("snapshot: %d %s %+v", w.Code, w.Body, ctl.lastSnap) } - wantKeys(t, "snapshot", jsonKeys(t, w.Body.Bytes()), "volumeID", "name", "headGen", "headEpoch", "cutLSN", "createdNs", "chunkCount", + wantKeys(t, "snapshot", jsonKeys(t, w.Body.Bytes()), "volumeID", "name", "headGen", "headEpoch", "cutLSN", "createdNs", "manifestBytes", "consistency", "labels", "replayed") w = serve(t, s, http.MethodGet, "/chunk/snapshots?volume=v1&prefix=a&startAfter=b&limit=7&includeDeleting=true", "", "") @@ -201,7 +201,7 @@ func TestStatusServer_ChunkSuccessBodiesUseSpecFields(t *testing.T) { t.Fatalf("snapshots body: %v %s", err, w.Body) } wantKeys(t, "snapshots[0]", jsonKeys(t, list.Snapshots[0]), "name", "headGen", "headEpoch", "cutLSN", "createdNs", "state", - "chunkCount", "labels", "consistency", "parent") + "labels", "consistency", "parent") w = serve(t, s, http.MethodPost, "/chunk/snapshot/delete", `{"volumeID":"v1","name":"s1"}`, "") if w.Code != 200 { diff --git a/seaweed-block/core/host/volume/snapshot_chunk_count_test.go b/seaweed-block/core/host/volume/snapshot_chunk_count_test.go new file mode 100644 index 0000000000..956a779120 --- /dev/null +++ b/seaweed-block/core/host/volume/snapshot_chunk_count_test.go @@ -0,0 +1,78 @@ +package volume + +import ( + "bytes" + "context" + "encoding/json" + "net/http" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/frontend/durable/testutil" +) + +// A snapshot after 200 MiB of writes must not advertise the uncomputed zero +// chunk count. The public answer omits it rather than walking the manifest. +func TestSnapshotAfter200MiBWritesOmitsUncomputedChunkCount(t *testing.T) { + ctx := context.Background() + const blocks = 200 * 1024 * 1024 / 4096 + const chunkBlocks = 1024 + f := testutil.NewLayoutFixture(t, "v1", blocks, chunkBlocks) + cfg := durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: blocks, ChunkBlocks: chunkBlocks} + f.Configure(&cfg) + dp, err := durable.NewDurableProvider(cfg, healthyView{}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = dp.Close() }) + s, err := dp.EnsureStorage("v1") + if err != nil { + t.Fatal(err) + } + if _, err := dp.RecoverVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + block := bytes.Repeat([]byte{'X'}, 4096) + for lba := uint32(0); lba < blocks; lba++ { + if _, err := s.Write(lba, block); err != nil { + t.Fatalf("write %d: %v", lba, err) + } + } + server := chunkServer(t, NewChunkControl(dp, f.Catalog, f.Ref), true) + for _, label := range []string{"create", "replay"} { + w := serve(t, server, http.MethodPost, "/chunk/snapshot", `{"volumeID":"v1","name":"daily","requestID":"count-regression"}`, "") + if w.Code != http.StatusOK { + t.Fatalf("%s: %d %s", label, w.Code, w.Body) + } + var answer struct { + Name string `json:"name"` + CutLSN uint64 `json:"cutLSN"` + } + if err := json.Unmarshal(w.Body.Bytes(), &answer); err != nil || answer.Name != "daily" || answer.CutLSN != blocks { + t.Fatalf("%s did not snapshot all 200 MiB of writes: %v %s", label, err, w.Body) + } + assertNoSnapshotChunkCount(t, w.Body.Bytes()) + } + w := serve(t, server, http.MethodGet, "/chunk/snapshots?volume=v1", "", "") + if w.Code != http.StatusOK { + t.Fatalf("list: %d %s", w.Code, w.Body) + } + var list struct { + Snapshots []json.RawMessage `json:"snapshots"` + } + if err := json.Unmarshal(w.Body.Bytes(), &list); err != nil || len(list.Snapshots) != 1 { + t.Fatalf("list: %v %s", err, w.Body) + } + assertNoSnapshotChunkCount(t, list.Snapshots[0]) +} + +func assertNoSnapshotChunkCount(t *testing.T, b []byte) { + t.Helper() + var answer map[string]json.RawMessage + if err := json.Unmarshal(b, &answer); err != nil { + t.Fatal(err) + } + if count, ok := answer["chunkCount"]; ok { + t.Fatalf("snapshot advertises an uncomputed chunkCount=%s: %s", count, b) + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 63ca2c663c..91bfa78bce 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1186,6 +1186,7 @@ Notes: | `INV-CUT-TIMER-RESTART-001` | A successful cut of any kind restarts the periodic timer, which runs on in-process monotonic time (a restart starts a fresh schedule; wall-clock steps move nothing). | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestWALStoreChunk_ExplicitCutRestartsTheTimer`, `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`); `TestCutPolicy_TimerRunsOnObservationTime`, `TestCutPolicy_StaggerPreservesExplicitTimerReset` (`core/frontend/durable/cut_policy_test.go`) | — | ACTIVE | | `INV-CUT-TIMER-SKIP-001` | A periodic cut decided from an older last cut is skipped under the capture lock: no automatic cut follows another within the interval. | M5 periodic trigger (before Admit) | `core/storage/chunk_periodic_cut.go` `CutUnlessCutSince`; `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestChunkPeriodicCut_SkipsAfterANewerCut`, `TestChunkPeriodicCut_SkipsANewerCutWithAnOlderStamp` (`core/storage/chunk_periodic_cut_test.go`); `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`) | — | ACTIVE | | `INV-CUT-TIMER-SLOT-WAIT-001` | A periodic cut refused for held host slots, pending urgent work or an earlier ticket is a wait, not a failure: no backoff or minimum spacing; it retries at the next poll in ticket order, and status reports the wait until any later cut succeeds. Other errors keep the backoff. | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `cutPolicy.after`, `chunkLoop`; `core/hostlimit/limiter.go` `ErrSlotsHeld` | `TestCutPolicy_HostSlotBusyIsAWaitNotAFailure`, `TestCutPolicy_SuccessDuringSlotWaitEndsTheWait`, `TestCutWaitSlot_StatusEndsTheWaitAfterALaterCut`, `TestCutPolicy_TicketOrderWaitBound` (`core/frontend/durable/cut_policy_test.go`); `TestTimerCutRunsSoonAfterHostSlotFrees`, `TestSlotWaitEndsWithASuccessfulDetachSeal` (`core/frontend/durable/host_slot_wait_test.go`); `TestAdmitClosedDuringPoolAcquisitionIsRevoked` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | +| `INV-SNAPSHOT-ANSWER-COUNT-001` | Newly produced snapshot creation and listing answers omit the uncomputed chunk count; no manifest scan is added to answer a snapshot. | M9 snapshot answer projection (no transition change) | `core/frontend/chunkstore/control_types.go`, `api.go`; `core/host/volume/chunk_control.go` | `TestSnapshotAfter200MiBWritesOmitsUncomputedChunkCount` (`core/host/volume/snapshot_chunk_count_test.go`) | NONE (pure projection of the published snapshot; no authority or persisted format change) | STUB | | `INV-CLI-CATALOG-ERROR-001` | The chunk CLI reports filer/master transport failures as retryable remote_unavailable (exit 1), including census, dial, resolve and read failures; configuration refusals stay distinct. An absent v1.1 delete reports snapshot_not_found; its not_found receipt stays unchanged. | M9 client error projection; M4 census refusal, no transition change | `cmd/sw-block/chunk_transport.go` `chunkTransportFailure`; `cmd/sw-block/chunk.go` `chunkResult`; `cmd/sw-block/catalog_snapshot_operation.go` `catalogSnapshotDeleteRefusal`; `core/frontend/chunkstore/single_filer.go` `CheckSingleFiler`; `core/frontend/chunkstore/layout/delete.go` `RunMarkDeleting` | `TestOpsChunkTransportFailureMatrix`, `TestOpsChunkVerifyUnreachableCensusPreservesTransport`, `TestCheckSingleFilerKeepsTransportCause`; `TestOpsChunkCatalogUnavailableIsTyped`, `TestCatalogTransportClassificationKeepsDefiniteAnswers`, `TestSnapshotDeleteAbsentCLIUsesContractCodeAndKeepsReceipt` | SnapOps.Poll; r2.972 | STUB | | `INV-CLI-CHUNK-LOOP-001` | Above the per-request bound, sw-block ops chunk snapshot\|detach repeats the SAME request (same name and request id) only after a retryable or outcome_unknown answer. Manual cut uses the separate one-POST/read-only-poll contract. | client (no state machine): the CLI side of M5 requests | `cmd/sw-block/chunk_loop.go` `chunkPostLoop`; `cmd/sw-block/chunk.go` `chunkPostUntil` | `TestChunkSnapshotRepeatsTimedOutRequestsWithTheSameBody`, `TestChunkSnapshotLoopReusesTheGeneratedRequestID`, `TestChunkLoopRepeatsAnOutcomeUnknownNotMarkedRetryable` (`cmd/sw-block`) | — | ACTIVE | | `INV-CLI-CHUNK-LOOP-002` | Above the per-request bound, sw-block ops chunk snapshot\|detach stops at the first definite answer (success or non-retryable refusal). | client (no state machine): the CLI side of M5 cut requests | `cmd/sw-block/chunk_loop.go` `chunkPostLoop` | `TestChunkLoopStopsOnANonRetryableRefusal`, `TestChunkDetachOutcomeUnknownSettles` (`cmd/sw-block`) | — | ACTIVE | diff --git a/seaweed-block/docs/releases/README.md b/seaweed-block/docs/releases/README.md index 97cd9221cc..e4139ebffc 100644 --- a/seaweed-block/docs/releases/README.md +++ b/seaweed-block/docs/releases/README.md @@ -4,6 +4,7 @@ Seaweed Block release notes use narrow product claims. Each alpha version names what a user or reviewer can actually run, what QA evidence backs it, and what is still outside the supported boundary. +- [v1.1.1 (unreleased)](v1.1.1.md) - [v1.1 (unreleased)](v1.1.md) - [v1.0.1](v1.0.1.md) - [v1.0.0](v1.0.0.md) diff --git a/seaweed-block/docs/releases/v1.1.1.md b/seaweed-block/docs/releases/v1.1.1.md new file mode 100644 index 0000000000..a5499acbaf --- /dev/null +++ b/seaweed-block/docs/releases/v1.1.1.md @@ -0,0 +1,10 @@ +# v1.1.1 (unreleased) + +## Corrections + +- Snapshot creation and listing answers omit `chunkCount`, which was never + computed and incorrectly reported `0` after data was written. This avoids + adding a full manifest scan to these responses. Consumers must tolerate the + absent field. Older retained operation results keep their original bytes; + a historical `chunkCount: 0` means unknown, not an empty snapshot. See the + [snapshot response schema](../status-schema.md#snapshot-control-responses). diff --git a/seaweed-block/docs/status-schema.md b/seaweed-block/docs/status-schema.md index 442c3488c8..f616bda962 100644 --- a/seaweed-block/docs/status-schema.md +++ b/seaweed-block/docs/status-schema.md @@ -553,3 +553,17 @@ The frontends this host can serve. Go type `volume.FrontendCapabilitiesStatus`. | `frontendTransports[].preflight[].detail` | string | extra detail, such as the path probed (omitted when empty) | + +## Snapshot control responses + +The optional chunk-control routes are separate from the generated `GET /status/*` +tables above. In v1.1.1, `POST /chunk/snapshot` success bodies, newly recorded +snapshot-create operation results, and entries from `GET /chunk/snapshots` omit +`chunkCount`. The field previously always contained an uncomputed `0`, even +after data was written; omission does not mean the snapshot is empty. + +An older retained snapshot operation result is replayed without rewriting its +bytes and may still contain `chunkCount: 0`; treat that value as unknown. +No full manifest scan is added to creation or listing responses. The `verify` +report counts references across all distinct roots named by HEAD, not the +distinct chunks of one snapshot. diff --git a/seaweed-block/docs/time-bounds.tsv b/seaweed-block/docs/time-bounds.tsv index 7ccccccad8..da336fd872 100644 --- a/seaweed-block/docs/time-bounds.tsv +++ b/seaweed-block/docs/time-bounds.tsv @@ -196,12 +196,12 @@ core/host/master/services.go services.deleteHolderEvidence context.WithTimeout 1 core/host/master/workspace_service.go services.AckWorkspaceRevoked context.WithTimeout 1 236 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request core/host/master/workspace_service.go services.MoveWorkspace context.WithTimeout 1 355 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request core/host/master/workspace_service.go services.PreviewWorkspaceMove context.WithTimeout 1 623 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request -core/host/volume/chunk_control.go chunkContext context.WithTimeout 1 571 pending-fix SnapOps.Start HTTP chunk handlers' default 5 min total (manual cut, snapshot, backup); fix #964 and its waiter follow-up -core/host/volume/chunk_control.go StatusServer.handleChunkCut time.NewTimer 1 626 per-call CutTime.InProgress one POST observation answers by W or earlier on a sequence rise or terminal result; worker owns the independent cut window -core/host/volume/chunk_control.go StatusServer.handleChunkDetach context.WithTimeout 1 798 pending-fix SnapOps.Start a cut waiter's fixed total; fix follows the cut window of #964 (one waiter PR for snapshot, backup, plain detach and stop) -core/host/volume/chunk_control.go chunkControl.snapshotOperationAttempt context.WithTimeout 1 1032 per-call SnapOps.Start one RPC or request -core/host/volume/chunk_control.go chunkControl.deleteSnapshotOperation time.Now().Add 1 1166 pending-fix SnapOps.Start unmeasured: the holder's snapshot-delete resume loop (30 s) around intent preparation; a measurement at the cap or a window is owed -core/host/volume/chunk_control.go chunkControl.deleteSnapshotOperation time.After 1 1189 control-timer SnapOps.Start resume loop poll +core/host/volume/chunk_control.go chunkContext context.WithTimeout 1 570 pending-fix SnapOps.Start HTTP chunk handlers' default 5 min total (manual cut, snapshot, backup); fix #964 and its waiter follow-up +core/host/volume/chunk_control.go StatusServer.handleChunkCut time.NewTimer 1 625 per-call CutTime.InProgress one POST observation answers by W or earlier on a sequence rise or terminal result; worker owns the independent cut window +core/host/volume/chunk_control.go StatusServer.handleChunkDetach context.WithTimeout 1 797 pending-fix SnapOps.Start a cut waiter's fixed total; fix follows the cut window of #964 (one waiter PR for snapshot, backup, plain detach and stop) +core/host/volume/chunk_control.go chunkControl.snapshotOperationAttempt context.WithTimeout 1 1031 per-call SnapOps.Start one RPC or request +core/host/volume/chunk_control.go chunkControl.deleteSnapshotOperation time.Now().Add 1 1165 pending-fix SnapOps.Start unmeasured: the holder's snapshot-delete resume loop (30 s) around intent preparation; a measurement at the cap or a window is owed +core/host/volume/chunk_control.go chunkControl.deleteSnapshotOperation time.After 1 1188 control-timer SnapOps.Start resume loop poll core/host/volume/host.go Host.runRoleRetry time.After 1 550 control-timer FormatGate.Downgrade; FormatGate.Upgrade role retry delay core/host/volume/host.go Host.runHeartbeat context.WithTimeout 1 792 per-call FormatGate.Downgrade; FormatGate.Upgrade one RPC or request core/host/volume/host.go Host.runSubscribe time.After 1 962 control-timer FormatGate.Downgrade; FormatGate.Upgrade subscribe retry backoff diff --git a/seaweed-block/docs/volume-lifecycle.md b/seaweed-block/docs/volume-lifecycle.md index c51c487f32..c7d1353558 100644 --- a/seaweed-block/docs/volume-lifecycle.md +++ b/seaweed-block/docs/volume-lifecycle.md @@ -650,3 +650,15 @@ admission. Permanent and lineage errors are not converted to retryable errors. - Never run SeaweedFS `volume.fsck` with its delete flags on a cluster holding walstore-chunk volumes: see [SeaweedFS maintenance commands that destroy chunk volumes](standalone-deployment.md#seaweedfs-maintenance-commands-that-destroy-chunk-volumes). + +### Snapshot chunk-count reporting + +Snapshot creation and listing answers omit `chunkCount`: it was never populated +and reported a misleading zero even after data was written. A snapshot root names +segments without a cached chunk count; an exact count would require reading all +of those segments. These responses do not perform that extra manifest scan. +Older retained operation results may still replay their original `chunkCount: 0`; +that value is unknown, not an empty snapshot. `verify` reports chunk references +across all distinct roots named by HEAD (the current image and snapshots), +counting a shared reference again in each distinct root, rather than a single +snapshot count or a count of unique physical objects.