From 3819309942b5c3f8b3508b69bc8a1c481b2b63c0 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 22:54:21 -0800 Subject: [PATCH] test: the status's hydration counters follow first reads A row and a test for the two per-volume counters the status already reports: the HEAD-named chunks still to hydrate (AbsentChunks) and the chunks hydrated so far (Hydration.Completed, cumulative). On a restore target whose HEAD names two chunks they start at 2 and 0; a read of an un-hydrated chunk moves both by one and a repeat read moves neither, so a caller can prove a read happened before its chunk was hydrated. Co-Authored-By: Claude Opus 5.5 --- .../durable/hydration_progress_test.go | 79 +++++++++++++++++++ seaweed-block/docs/design/invariants.md | 3 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 seaweed-block/core/frontend/durable/hydration_progress_test.go diff --git a/seaweed-block/core/frontend/durable/hydration_progress_test.go b/seaweed-block/core/frontend/durable/hydration_progress_test.go new file mode 100644 index 0000000000..3841d2b410 --- /dev/null +++ b/seaweed-block/core/frontend/durable/hydration_progress_test.go @@ -0,0 +1,79 @@ +package durable + +import ( + "bytes" + "context" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +func hydrationProgress(t *testing.T, p *DurableProvider) (absent int, hydrated uint64) { + t.Helper() + for _, st := range p.DurableStatuses() { + if st.VolumeID == "v1" && st.Chunk != nil && st.Chunk.Attached { + return st.Chunk.Stats.AbsentChunks, st.Chunk.Stats.Hydration.Completed + } + } + t.Fatal("v1 has no attached chunk layer") + return 0, 0 +} + +// INV-CUT-HYDRATION-PROGRESS-001: the status reports, per volume, the +// chunks still to hydrate (AbsentChunks: HEAD-named, not yet local) and the +// chunks hydrated so far (Hydration.Completed, cumulative). A read of an +// un-hydrated chunk moves both by one; a second read of it moves neither. A +// caller can therefore prove that a read happened before its chunk was +// hydrated by reading the two before and after it. +func TestHydrationProgressCountersFollowFirstReads(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + mem := storage.NewMemChunkRemote() + src := kzProvider(t, t.TempDir(), mem) + if _, err := src.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + if _, err := src.RecoverVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + data := map[int64][]byte{3: bytes.Repeat([]byte{0x33}, 4096), 7: bytes.Repeat([]byte{0x77}, 4096)} + for chunk, b := range data { + if _, err := src.Backend("v1").Write(ctx, chunk*16*4096, b); err != nil { + t.Fatal(err) + } + } + if err := src.Backend("v1").Sync(ctx); err != nil { + t.Fatal(err) + } + if _, err := src.CaptureVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + if err := src.Close(); err != nil { + t.Fatal(err) + } + + p := kzProvider(t, t.TempDir(), mem) + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + if _, err := p.RecoverVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + want := []struct { + read int64 // chunk read before the check (-1: none) + absent int + hydrated uint64 + }{{-1, 2, 0}, {3, 1, 1}, {3, 1, 1}, {7, 0, 2}} + got := make([]byte, 4096) + for _, w := range want { + if w.read >= 0 { + if n, err := p.Backend("v1").Read(ctx, w.read*16*4096, got); err != nil || n != len(got) || !bytes.Equal(got, data[w.read]) { + t.Fatalf("read of chunk %d: %d %v, data equal %v", w.read, n, err, bytes.Equal(got, data[w.read])) + } + } + if absent, hydrated := hydrationProgress(t, p); absent != w.absent || hydrated != w.hydrated { + t.Fatalf("after reading chunk %d: %d still to hydrate, %d hydrated; want %d, %d", w.read, absent, hydrated, w.absent, w.hydrated) + } + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index f5e1ae5477..ace443cffe 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -497,7 +497,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -323 rows: 253 ACTIVE, 67 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 308 new. +324 rows: 254 ACTIVE, 67 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 309 new. The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger. @@ -858,6 +858,7 @@ Notes: | `INV-CUT-INTENT-CLOSE-001` | Close deletes the intents of reusable uploads and leftover intents, but never an intent of a proposal whose CAS outcome is still unresolved. | M5 Close | `core/storage/chunk_layer.go` `Close`, `captureLocked`, `dropIntents` | `TestChunkCloseDropsReusableButKeepsUnknownCASRoots` (`core/storage/chunk_review271_test.go`); `TestHeadBeltOldCASUnconfirmedKeepsIntentsAndFrontier`, `TestHeadBeltLowerEpochConflictFencesWithoutCleanup`, `TestHeadBeltEmptyBaseForeignPublicationFences` (`core/storage/chunk_head_belt_test.go`) | — | ACTIVE | | `INV-CUT-SEGMENT-REUSE-001` | A cut rewrites only manifest segments whose chunk references changed, and an uploaded but unpublished segment leaves the published root unchanged. | M5 Manifest | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` (`core/frontend/chunkstore/manifest_test.go`) | `CutPipeline` `SegConsistent` | ACTIVE | | `INV-CUT-HYDRATION-WAIT-001` | A read command shares its arrival deadline across chunks. A timed-out waiter returns typed pending without cancelling a shared fill. Per-layer worker and distinct-flight limits bound remote work; Close wakes waiters and joins issued fills before storage release. Physical/hash errors remain terminal. | M4 Holder (hydration wait) | `core/storage/chunk_hydration.go`; `core/storage/walstore.go` `ReadContext`; `core/frontend/durable/storage_adapter.go` `readStorageBlock`; `core/frontend/nvme/session.go` `handleRead` | `TestDurableHydration_MultipleChunksShareOneDeadline`, `TestDurableHydration_NVMePreservesPhysicalAndHashErrors`, `TestSessionReadBudgetIncludesQueueResidence`, `TestChunkHydration_QueueAndWorkerLimitsAreBounded`, `TestChunkHydration_CloseWakesCallerAndJoinsUninterruptibleGet`, `TestChunkHydration_ContextlessReadAllowsSlowFill`, `TestChunkHydration_NewGenerationDoesNotJoinStaleGet`, `TestChunkHydration_StaleCompletionKeepsReplacement`, `TestDurableHydration_RMWFenceWinsCallerExpiry` | — | ACTIVE | +| `INV-CUT-HYDRATION-PROGRESS-001` | The status reports per volume the HEAD-named chunks still to hydrate (`AbsentChunks`) and the chunks hydrated so far (`Hydration.Completed`, cumulative); a read of an un-hydrated chunk moves both by one, a repeat read neither. Observation only. | M5 hydration (reader; no transition) | `core/storage/chunk_layer.go` `Stats` (`absentHydratable`); `core/storage/chunk_hydration.go` `hydrationWorker` | `TestHydrationProgressCountersFollowFirstReads` (`core/frontend/durable/hydration_progress_test.go`) | — | ACTIVE | | `INV-CUT-READMISS-001` | A block fetched from HEAD after a move is installed only if it does not overwrite a newer local extent version; a newer WAL-only write still wins on reads, and HEAD's value may be installed beneath it as the backing value, which is correct if a crash loses that unsynced write. | M4 Holder (lazy restore) | `core/storage/chunk_layer.go` `OnReadMiss`, `installFetchedBlock`; `core/storage/walstore.go` `readFromExtent` | `TestChunkLayer_WALOnlyOverlapReadNeverReturnsUntouchedZero` (`core/storage/chunk_layer_races_test.go`); `TestWALStore_PostReadMissRechecksWALFormat` (`core/storage/walstore_read_miss_v3_test.go`; real-store v2/v3 dispatch) | — | ACTIVE | | `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 |