From 33b85df283017e46c66bac319b253dbaa90e04fb Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 10:16:44 -0800 Subject: [PATCH] test terminal hydration failures and queue status --- .../frontend/durable/hydration_budget_test.go | 41 +++++++++++++++++++ .../chunk_hydration_concurrency_test.go | 6 ++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/frontend/durable/hydration_budget_test.go b/seaweed-block/core/frontend/durable/hydration_budget_test.go index cd3bae1973..178a4cf3de 100644 --- a/seaweed-block/core/frontend/durable/hydration_budget_test.go +++ b/seaweed-block/core/frontend/durable/hydration_budget_test.go @@ -10,9 +10,50 @@ import ( "time" "github.com/seaweedfs/seaweed-block/core/frontend" + "github.com/seaweedfs/seaweed-block/core/frontend/nvme" "github.com/seaweedfs/seaweed-block/core/storage" ) +type faultyHydrationRemote struct { + storage.ChunkRemote + fault error + corrupt bool +} + +func (r *faultyHydrationRemote) Get(ctx context.Context, key string) ([]byte, error) { + if r.fault != nil { + return nil, r.fault + } + b, err := r.ChunkRemote.Get(ctx, key) + if err == nil && r.corrupt && len(b) > 0 { + b = append([]byte(nil), b...) + b[0] ^= 0xff + } + return b, err +} + +func TestDurableHydration_NVMePreservesPhysicalAndHashErrors(t *testing.T) { + for _, corrupt := range []bool{false, true} { + t.Run(map[bool]string{false: "joined physical", true: "hash"}[corrupt], func(t *testing.T) { + r := &faultyHydrationRemote{ChunkRemote: seededRemote(t), corrupt: corrupt} + if !corrupt { + r.fault = errors.Join(context.DeadlineExceeded, errors.New("physical remote read failure")) + } + p := chunkProvider(t, t.TempDir(), r, v1View(), 0) + openRecovered(t, p) + b, err := p.Open(context.Background(), "v1") + if err != nil { + t.Fatal(err) + } + h := nvme.NewIOHandler(nvme.HandlerConfig{Backend: b, BlockSize: 4096, VolumeSize: pcBlocks * 4096}) + res := h.Handle(context.Background(), nvme.IOCommand{Opcode: 2, NSID: 1, SLBA: 33, NLB: 1}) + if res.SC != nvme.SCInternalError || len(res.Data) != 0 { + t.Fatalf("terminal hydration failure: %+v", res) + } + }) + } +} + type pacedHydrationRemote struct { storage.ChunkRemote gets atomic.Int64 diff --git a/seaweed-block/core/storage/chunk_hydration_concurrency_test.go b/seaweed-block/core/storage/chunk_hydration_concurrency_test.go index 220c4073b7..46f5742189 100644 --- a/seaweed-block/core/storage/chunk_hydration_concurrency_test.go +++ b/seaweed-block/core/storage/chunk_hydration_concurrency_test.go @@ -105,7 +105,7 @@ func TestChunkHydration_ConcurrentReadersShareOneGet(t *testing.T) { } func TestChunkHydration_QueueAndWorkerLimitsAreBounded(t *testing.T) { - s, _, remote, registered := hydrationFixture(t, 1, 2) + s, layer, remote, registered := hydrationFixture(t, 1, 2) entered, release := holdGets(t, remote) defer release() first := startHydrationRead(t, s, context.Background(), 8) @@ -125,6 +125,10 @@ func TestChunkHydration_QueueAndWorkerLimitsAreBounded(t *testing.T) { if got := remote.stats().gets; got != 1 { t.Fatalf("worker bound exceeded: Gets=%d", got) } + stats := layer.Stats().Hydration + if stats.WorkerLimit != 1 || stats.QueueDepth != 2 || stats.Active != 1 || stats.Queued != 1 || stats.WaitRefusals != 2 || stats.Fetches != 1 { + t.Fatalf("hydration status does not reflect bounded pressure: %+v", stats) + } release() if r := hydrationOutcome(t, first); r.err != nil { t.Fatal(r.err)