test terminal hydration failures and queue status

This commit is contained in:
pingqiu committed 2026-11-19 16:03:15 -08:00
1 parent 5aea1eaf8b
commit 33b85df283
2 files changed
+46 -1

No files matched your search

@@ -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
@@ -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)