diff --git a/seaweed-block/cmd/blockvolume/durable_startup_budget_test.go b/seaweed-block/cmd/blockvolume/durable_startup_budget_test.go new file mode 100644 index 0000000000..b5f9886f15 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/durable_startup_budget_test.go @@ -0,0 +1,47 @@ +package main + +import ( + "context" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// This counting provider represents local map replay without disk throughput or +// wall-clock sleeps. It probes the production startup boundary, not a widened +// deadline: a per-volume walk must not inherit the attach operation's timer. +type countingLocalRecovery struct { + entries int + visited int + underDeadline int +} + +func (p *countingLocalRecovery) EnsureStorage(string) (storage.LogicalStorage, error) { + return nil, nil +} +func (p *countingLocalRecovery) RecoverVolume(ctx context.Context, id string) (durable.RecoveryReport, error) { + for i := 0; i < p.entries; i++ { + p.visited++ + if _, timed := ctx.Deadline(); timed { + p.underDeadline++ + } + } + return durable.RecoveryReport{VolumeID: id, Evidence: "local replay completed"}, nil +} + +func TestDurableStartup_LocalRecoveryWorkIsOutsideFixedDeadline(t *testing.T) { + for _, entries := range []int{1, 262144} { + t.Run(map[int]string{1: "one", 262144: "one_tib_chunk_count"}[entries], func(t *testing.T) { + p := &countingLocalRecovery{entries: entries} + outcome, _, err := openAndRecoverDurable(p, &spyHost{}, "v1", 10*time.Second) + if err != nil || outcome != durableStartupReady || p.visited != entries { + t.Fatalf("startup=%v err=%v visited=%d want=%d", outcome, err, p.visited, entries) + } + if p.underDeadline != 0 { + t.Fatalf("volume-sized local recovery visited %d/%d entries under a fixed deadline; growing replay must precede the bounded attach operation", p.underDeadline, entries) + } + }) + } +}