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.
This commit is contained in:
pingqiu-cpu authored and GitHub committed 2026-12-03 05:06:39 -08:00
1 parent 687cc31e32
commit 85d83237f4
11 files changed
+126 -13

No files matched your search

@@ -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
@@ -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.
@@ -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})
}
@@ -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 {
@@ -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)
}
}
+1
View File
@@ -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 |
+1
View File
@@ -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)
+10
View File
@@ -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).
+14
View File
@@ -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) |
<!-- END GENERATED -->
## 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.
+6 -6
View File
@@ -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
Can't render this file because it contains an unexpected character in line 47 and column 127.
+12
View File
@@ -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.