From ac3bcbb0f5af94587a5899c3a90a8f7b01066b9b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:39:18 -0800 Subject: [PATCH 1/9] test: a restore and a fork target on a durable root without room are refused, leave no file, and serve once space is freed Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go new file mode 100644 index 0000000000..c8f5217037 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -0,0 +1,124 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "syscall" + "testing" + "time" +) + +// Local headroom for a restore and a fork target. The durable root of each +// target is on a small file system (CHUNKSTORE_SMALL_ROOT, a directory on it) +// that a filler file (CHUNKSTORE_SMALL_FILLER, on the same file system) keeps +// below the volume size + WAL. The runner prepares both (a loop-mounted ext4 +// needs root); without them the test is skipped. + +const ( + headroomVolumeBytes = 65536 * 4096 // the harness's volume size + headroomWALBytes = 64 << 20 // the default WAL +) + +func freeBytes(t *testing.T, dir string) int64 { + t.Helper() + var st syscall.Statfs_t + if err := syscall.Statfs(dir, &st); err != nil { + t.Fatal(err) + } + return int64(st.Bavail) * int64(st.Bsize) +} + +// requireNoFiles fails if any regular file exists under dir: a refused +// create leaves nothing behind. +func requireNoFiles(t *testing.T, dir string) { + t.Helper() + _ = filepath.Walk(dir, func(p string, info os.FileInfo, err error) error { + if err == nil && !info.IsDir() { + t.Fatalf("a refused create left %s (%d bytes)", p, info.Size()) + } + return nil + }) +} + +// refusedForHeadroom starts the target's blockvolume and requires it to +// refuse the create: it exits on its own, its log names the free bytes and +// the need (size + WAL), and its durable root holds no file. +func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) { + t.Helper() + b := env.hosts["n-"+target] + d := env.h.start(t, name, env.h.volume, env.volArgsFor(b)...) + err := d.wait(60 * time.Second) + select { + case <-d.done: + default: + t.Fatalf("%s: blockvolume did not exit within 60 s of a create without room (%v)", name, err) + } + if err == nil { + t.Fatalf("%s: blockvolume created %s without room for it and exited cleanly", name, target) + } + want := fmt.Sprintf("volume %s needs %d (size %d + WAL %d)", target, headroomVolumeBytes+headroomWALBytes, headroomVolumeBytes, headroomWALBytes) + line := d.line(want) + if line == "" || !strings.Contains(line, "bytes free") { + t.Fatalf("%s: no refusal naming the free bytes and %q", name, want) + } + t.Logf("%s refused: %s", name, strings.TrimSpace(line)) + requireNoFiles(t, b.root) +} + +// TestHeadroomRefusesARestoreAndAForkTargetThenServesThem: a snapshot of v1 +// is restored into v2 and forked into v3, each target's durable root on a +// small file system with less free space than the volume size + WAL. Each +// target's blockvolume refuses the create, naming both numbers, and leaves no +// file; the source still serves its data and its snapshot is still listed. +// Once space is freed, the same targets start, serve, and read back the +// snapshot. +func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { + small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER") + if small == "" || filler == "" { + t.Skip("CHUNKSTORE_SMALL_ROOT and CHUNKSTORE_SMALL_FILLER name a small file system and its filler file") + } + need := int64(headroomVolumeBytes + headroomWALBytes) + if free := freeBytes(t, small); free >= need { + t.Fatalf("the small file system has %d bytes free, not less than the %d a volume needs: fix the runner", free, need) + } + + env := startLadderEnv(t, "v2", "v3") + for _, v := range []string{"v2", "v3"} { + b := env.hosts["n-"+v] + b.root = filepath.Join(small, t.Name(), "vol-n-"+v) + env.hosts["n-"+v] = b + if err := os.MkdirAll(b.root, 0o700); err != nil { + t.Fatal(err) + } + } + img := ladderImage("headroom", []uint64{0, 3}, 4) + env.writeImage(t, "s1", img) + env.snapshot(t, "s1", "v1", "base") + + env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v2", + "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) + env.h.command(t, "ops", "chunk", "fork", "--source", "v1", "--snapshot", "base", "--target", "v3", + "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) + env.refusedForHeadroom(t, "v2", "blockvolume-v2-no-room") + env.refusedForHeadroom(t, "v3", "blockvolume-v3-no-room") + + env.requireImage(t, "s1", img) // the source is intact + if l := env.snapshots(t, "v1", "base"); len(l) != 1 || l[0].State != "active" { + t.Fatalf("the source's snapshot after the refusals: %+v", l) + } + + if err := os.Remove(filler); err != nil { + t.Fatal(err) + } + if free := freeBytes(t, small); free < need { + t.Fatalf("after removing the filler the small file system has %d bytes free; the %d a volume needs does not fit: fix the runner", free, need) + } + for _, v := range []string{"v2", "v3"} { + env.startTarget(t, v, "blockvolume-"+v+"-with-room") + env.requireImage(t, "n-"+v, img) + } +} From 0a9ef172a8bac607d5d38508546741b8c9326938 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:43:44 -0800 Subject: [PATCH 2/9] test: headroom refusals record their exit line; the stranded target is deleted and the snapshot restored elsewhere; the check's per-volume limit is stated Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 62 ++++++++++++++----- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index c8f5217037..c0ee9e3b9c 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -3,6 +3,7 @@ package main_test import ( + "encoding/json" "fmt" "os" "path/filepath" @@ -17,6 +18,11 @@ import ( // that a filler file (CHUNKSTORE_SMALL_FILLER, on the same file system) keeps // below the volume size + WAL. The runner prepares both (a loop-mounted ext4 // needs root); without them the test is skipped. +// +// The check's limit: it compares one volume's size + WAL with the free space +// at that moment, not the sum over every volume on the file system. Two +// 256 MiB + 64 MiB targets both pass on the 512 MiB file system once the +// filler is gone, though together they could outgrow it. const ( headroomVolumeBytes = 65536 * 4096 // the harness's volume size @@ -45,9 +51,10 @@ func requireNoFiles(t *testing.T, dir string) { } // refusedForHeadroom starts the target's blockvolume and requires it to -// refuse the create: it exits on its own, its log names the free bytes and -// the need (size + WAL), and its durable root holds no file. -func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) { +// refuse the create: it exits on its own with its exit line (status and +// reason), its log names the free bytes and the need (size + WAL), and its +// durable root holds no file. It returns the exit line. +func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) string { t.Helper() b := env.hosts["n-"+target] d := env.h.start(t, name, env.h.volume, env.volArgsFor(b)...) @@ -65,17 +72,26 @@ func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) { if line == "" || !strings.Contains(line, "bytes free") { t.Fatalf("%s: no refusal naming the free bytes and %q", name, want) } - t.Logf("%s refused: %s", name, strings.TrimSpace(line)) + exit := d.line("blockvolume: exiting status=") + if exit == "" { + t.Fatalf("%s: no 'blockvolume: exiting status=N reason=...' line", name) + } + t.Logf("%s refused: %s; %s", name, strings.TrimSpace(line), strings.TrimSpace(exit)) requireNoFiles(t, b.root) + return strings.TrimSpace(exit) } // TestHeadroomRefusesARestoreAndAForkTargetThenServesThem: a snapshot of v1 -// is restored into v2 and forked into v3, each target's durable root on a -// small file system with less free space than the volume size + WAL. Each -// target's blockvolume refuses the create, naming both numbers, and leaves no -// file; the source still serves its data and its snapshot is still listed. -// Once space is freed, the same targets start, serve, and read back the -// snapshot. +// is restored into v2 and v4 and forked into v3, each target's durable root +// on a small file system with less free space than the volume size + WAL. +// Each target's blockvolume refuses the create, naming both numbers, exits +// with the same exit line, and leaves no file; the source still serves its +// data and its snapshot is still listed. The operator's two ways out: +// - give up the stranded target: volume-delete of v4 (which exists in the +// catalog but cannot start) completes, and the source's snapshot is +// then restored into another target, v5, which serves it; +// - free space: once the filler is removed, v2 and v3 start, serve, and +// read back the snapshot. func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER") if small == "" || filler == "" { @@ -86,8 +102,8 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { t.Fatalf("the small file system has %d bytes free, not less than the %d a volume needs: fix the runner", free, need) } - env := startLadderEnv(t, "v2", "v3") - for _, v := range []string{"v2", "v3"} { + env := startLadderEnv(t, "v2", "v3", "v4", "v5") + for _, v := range []string{"v2", "v3", "v4"} { b := env.hosts["n-"+v] b.root = filepath.Join(small, t.Name(), "vol-n-"+v) env.hosts["n-"+v] = b @@ -103,8 +119,26 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.h.command(t, "ops", "chunk", "fork", "--source", "v1", "--snapshot", "base", "--target", "v3", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - env.refusedForHeadroom(t, "v2", "blockvolume-v2-no-room") - env.refusedForHeadroom(t, "v3", "blockvolume-v3-no-room") + env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v4", + "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) + exits := map[string]string{} + for _, v := range []string{"v2", "v3", "v4"} { + line := env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") + exits[line[strings.Index(line, "status="):]] = v + } + if len(exits) != 1 { + t.Fatalf("the refusals exited differently: %v", exits) + } + + // The stranded target given up: deleted, and the snapshot restored elsewhere. + out, errOut, code := env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v4", "--chunk-filer", env.cluster.filerGRPC, + "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-v4") + var del struct{ Completed bool } + if code != 0 || json.Unmarshal([]byte(out), &del) != nil || !del.Completed { + t.Fatalf("volume-delete of the refused target v4: exit %d %s %s; want completed", code, out, errOut) + } + env.restoreInto(t, "v1", "base", "v5") + env.requireImage(t, "n-v5", img) env.requireImage(t, "s1", img) // the source is intact if l := env.snapshots(t, "v1", "base"); len(l) != 1 || l[0].State != "active" { From f03c0241d094145f0d2eadf88636a1f98fc12ed2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:09:12 -0800 Subject: [PATCH 3/9] test: headroom refusal pinned to its exit: status 1 from the durable storage open at startup Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index c0ee9e3b9c..e6c87d4334 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -51,9 +51,12 @@ func requireNoFiles(t *testing.T, dir string) { } // refusedForHeadroom starts the target's blockvolume and requires it to -// refuse the create: it exits on its own with its exit line (status and -// reason), its log names the free bytes and the need (size + WAL), and its -// durable root holds no file. It returns the exit line. +// refuse the create the way the durable store's open fails at startup: it +// exits on its own with status 1, its log says "blockvolume: durable storage +// open:" and names the free bytes and the need (size + WAL), and its durable +// root holds no file. Status 1 is not RestartPreventExitStatus=78 in the +// shipped unit, so systemd starts it again every 5 s, refusing each time, +// until space is freed. It returns the refusal line. func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) string { t.Helper() b := env.hosts["n-"+target] @@ -72,20 +75,19 @@ func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) str if line == "" || !strings.Contains(line, "bytes free") { t.Fatalf("%s: no refusal naming the free bytes and %q", name, want) } - exit := d.line("blockvolume: exiting status=") - if exit == "" { - t.Fatalf("%s: no 'blockvolume: exiting status=N reason=...' line", name) + if code := exitCode(err); code != 1 || !strings.Contains(line, "blockvolume: durable storage open:") { + t.Fatalf("%s: exit status %d, refusal %q; want status 1 from the durable storage open at startup", name, code, line) } - t.Logf("%s refused: %s; %s", name, strings.TrimSpace(line), strings.TrimSpace(exit)) + t.Logf("%s refused (exit status 1): %s", name, strings.TrimSpace(line)) requireNoFiles(t, b.root) - return strings.TrimSpace(exit) + return strings.TrimSpace(line) } // TestHeadroomRefusesARestoreAndAForkTargetThenServesThem: a snapshot of v1 // is restored into v2 and v4 and forked into v3, each target's durable root // on a small file system with less free space than the volume size + WAL. // Each target's blockvolume refuses the create, naming both numbers, exits -// with the same exit line, and leaves no file; the source still serves its +// with status 1, and leaves no file; the source still serves its // data and its snapshot is still listed. The operator's two ways out: // - give up the stranded target: volume-delete of v4 (which exists in the // catalog but cannot start) completes, and the source's snapshot is @@ -121,13 +123,8 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v4", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - exits := map[string]string{} for _, v := range []string{"v2", "v3", "v4"} { - line := env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") - exits[line[strings.Index(line, "status="):]] = v - } - if len(exits) != 1 { - t.Fatalf("the refusals exited differently: %v", exits) + env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") } // The stranded target given up: deleted, and the snapshot restored elsewhere. From 13a5a68d8b8d2a83705141dfbf52eceae51efbc3 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:13:39 -0800 Subject: [PATCH 4/9] test: headroom asserts today's behaviour (only the replica floor remains; the stranded target is not deletable) and the documented way out Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 75 +++++++++++++------ 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index e6c87d4334..a720abb1a2 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -38,12 +38,15 @@ func freeBytes(t *testing.T, dir string) int64 { return int64(st.Bavail) * int64(st.Bsize) } -// requireNoFiles fails if any regular file exists under dir: a refused -// create leaves nothing behind. -func requireNoFiles(t *testing.T, dir string) { +// requireOnlyReplicaFloor fails unless the only regular file under dir is +// the volume's replica floor: a refused create writes no store, WAL or +// marker. The floor is written when the assignment arrives, before the store +// is opened and refused (a known limit: the check precedes the store, not +// every sidecar). +func requireOnlyReplicaFloor(t *testing.T, dir, vol string) { t.Helper() _ = filepath.Walk(dir, func(p string, info os.FileInfo, err error) error { - if err == nil && !info.IsDir() { + if err == nil && !info.IsDir() && filepath.Base(p) != vol+".replica-floor" { t.Fatalf("a refused create left %s (%d bytes)", p, info.Size()) } return nil @@ -54,9 +57,10 @@ func requireNoFiles(t *testing.T, dir string) { // refuse the create the way the durable store's open fails at startup: it // exits on its own with status 1, its log says "blockvolume: durable storage // open:" and names the free bytes and the need (size + WAL), and its durable -// root holds no file. Status 1 is not RestartPreventExitStatus=78 in the -// shipped unit, so systemd starts it again every 5 s, refusing each time, -// until space is freed. It returns the refusal line. +// root holds no store (only its replica floor). Status 1 is not +// RestartPreventExitStatus=78 in the shipped unit, so systemd starts it +// again every 5 s, refusing each time, until space is freed or its start +// limit stops it. It returns the refusal line. func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) string { t.Helper() b := env.hosts["n-"+target] @@ -79,7 +83,7 @@ func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) str t.Fatalf("%s: exit status %d, refusal %q; want status 1 from the durable storage open at startup", name, code, line) } t.Logf("%s refused (exit status 1): %s", name, strings.TrimSpace(line)) - requireNoFiles(t, b.root) + requireOnlyReplicaFloor(t, b.root, target) return strings.TrimSpace(line) } @@ -87,13 +91,16 @@ func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) str // is restored into v2 and v4 and forked into v3, each target's durable root // on a small file system with less free space than the volume size + WAL. // Each target's blockvolume refuses the create, naming both numbers, exits -// with status 1, and leaves no file; the source still serves its -// data and its snapshot is still listed. The operator's two ways out: -// - give up the stranded target: volume-delete of v4 (which exists in the -// catalog but cannot start) completes, and the source's snapshot is -// then restored into another target, v5, which serves it; -// - free space: once the filler is removed, v2 and v3 start, serve, and -// read back the snapshot. +// with status 1, and writes no store; the source still serves its data and +// its snapshot is still listed, and restores into another target (v5) that +// serves it. +// +// A refused target exists in the catalog and holds the master's line, but +// cannot start: today it cannot be volume-deleted either (the delete wants a +// clean revocation ACK its holder cannot send), a known limit of 1.0. The +// documented way out is tested: once space is freed, v2 and v3 start and +// serve the snapshot, and v4 starts, is sealed, revoked and acknowledged, and +// then deleted. func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER") if small == "" || filler == "" { @@ -127,13 +134,16 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") } - // The stranded target given up: deleted, and the snapshot restored elsewhere. - out, errOut, code := env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v4", "--chunk-filer", env.cluster.filerGRPC, - "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-v4") - var del struct{ Completed bool } - if code != 0 || json.Unmarshal([]byte(out), &del) != nil || !del.Completed { - t.Fatalf("volume-delete of the refused target v4: exit %d %s %s; want completed", code, out, errOut) + // The stranded target: not deletable while its holder cannot start. + deleteV4 := func() (string, string, int) { + return env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v4", "--chunk-filer", env.cluster.filerGRPC, + "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-v4") } + out, errOut, code := deleteV4() + if code == 0 || !strings.Contains(out+errOut, "live authority requires clean revocation ACK") { + t.Fatalf("volume-delete of the refused target v4: exit %d %s %s; want refused for the missing ACK (a known limit)", code, out, errOut) + } + // The snapshot is still restorable into another target that has room. env.restoreInto(t, "v1", "base", "v5") env.requireImage(t, "n-v5", img) @@ -152,4 +162,27 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { env.startTarget(t, v, "blockvolume-"+v+"-with-room") env.requireImage(t, "n-"+v, img) } + + // The documented way out for the stranded target: with room it starts, + // and the usual delete steps (seal, revoke, ACK, delete) complete. + _, mustU := fatalOn(t) + d4 := env.startTarget(t, "v4", "blockvolume-v4-with-room") + e4 := mustU(adoptedEpoch(d4.line("blockvolume: volume v4 adopted as PRIMARY at r1@"))) + b4 := env.hosts["n-v4"] + out, errOut = env.h.command(t, "ops", "chunk", "detach", "--plain", "--volume", "v4", "--status-addr", b4.status, "--timeout", "120s") + g4 := mustU(sealedGen(out, errOut, e4)) + env.h.command(t, "ops", "workspace", "revoke", "--master", env.h.masterAddr, "--volume", "v4", "--replica", "r1", + "--epoch", fmt.Sprint(e4), "--sealed-gen", fmt.Sprint(g4)) + if err := d4.wait(30 * time.Second); err != nil { + t.Fatalf("v4 after the revocation: %v; want a clean exit by itself", err) + } + poll(t, 30*time.Second, "workspace show never reported v4's ACK", func() bool { + out, _ := env.h.command(t, "ops", "workspace", "show", "--master", env.h.masterAddr, "--volume", "v4") + return showsAck(out, e4, g4) + }) + out, errOut, code = deleteV4() + var del struct{ Completed bool } + if code != 0 || json.Unmarshal([]byte(out), &del) != nil || !del.Completed { + t.Fatalf("volume-delete of v4 after the way out: exit %d %s %s; want completed", code, out, errOut) + } } From 1d53ad9a4234cc9079aa53688c474c5e9e0b0a5a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:27:28 -0800 Subject: [PATCH 5/9] test: headroom runs both documented ways out for a refused target: free space and start it, or force-move it to a host with room Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 134 +++++++++++++----- 1 file changed, 102 insertions(+), 32 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index a720abb1a2..9ab8345a90 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -7,6 +7,8 @@ import ( "fmt" "os" "path/filepath" + "regexp" + "strconv" "strings" "syscall" "testing" @@ -60,8 +62,8 @@ func requireOnlyReplicaFloor(t *testing.T, dir, vol string) { // root holds no store (only its replica floor). Status 1 is not // RestartPreventExitStatus=78 in the shipped unit, so systemd starts it // again every 5 s, refusing each time, until space is freed or its start -// limit stops it. It returns the refusal line. -func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) string { +// limit stops it. It returns the refused process. +func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) *daemon { t.Helper() b := env.hosts["n-"+target] d := env.h.start(t, name, env.h.volume, env.volArgsFor(b)...) @@ -84,7 +86,48 @@ func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) str } t.Logf("%s refused (exit status 1): %s", name, strings.TrimSpace(line)) requireOnlyReplicaFloor(t, b.root, target) - return strings.TrimSpace(line) + return d +} + +// logUint reads the number re captures from the first line of d's log that +// it matches. +func logUint(t *testing.T, d *daemon, re *regexp.Regexp) uint64 { + t.Helper() + data, _ := os.ReadFile(d.log) + m := re.FindSubmatch(data) + if m == nil { + t.Fatalf("%s: no line matching %s", d.name, re) + } + n, err := strconv.ParseUint(string(m[1]), 10, 64) + if err != nil || n == 0 { + t.Fatalf("%s: %q: %v", d.name, m[0], err) + } + return n +} + +// deleteServingTarget runs the volume-lifecycle page's delete for a target +// that serves (d on host b at epoch e): seal, revoke and wait for its ACK +// and clean exit, then volume-delete, which must complete. +func (env *handoffEnv) deleteServingTarget(t *testing.T, vol string, b bvHost, d *daemon, e uint64) { + t.Helper() + _, mustU := fatalOn(t) + out, errOut := env.h.command(t, "ops", "chunk", "detach", "--plain", "--volume", vol, "--status-addr", b.status, "--timeout", "120s") + g := mustU(sealedGen(out, errOut, e)) + env.h.command(t, "ops", "workspace", "revoke", "--master", env.h.masterAddr, "--volume", vol, "--replica", "r1", + "--epoch", fmt.Sprint(e), "--sealed-gen", fmt.Sprint(g)) + if err := d.wait(30 * time.Second); err != nil { + t.Fatalf("%s after the revocation: %v; want a clean exit by itself", vol, err) + } + poll(t, 30*time.Second, fmt.Sprintf("workspace show never reported %s's ACK", vol), func() bool { + out, _ := env.h.command(t, "ops", "workspace", "show", "--master", env.h.masterAddr, "--volume", vol) + return showsAck(out, e, g) + }) + out, errOut, code := env.h.run(t, "ops", "chunk", "volume-delete", "--volume", vol, "--chunk-filer", env.cluster.filerGRPC, + "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-"+vol) + var del struct{ Completed bool } + if code != 0 || json.Unmarshal([]byte(out), &del) != nil || !del.Completed { + t.Fatalf("volume-delete of %s after the way out: exit %d %s %s; want completed", vol, code, out, errOut) + } } // TestHeadroomRefusesARestoreAndAForkTargetThenServesThem: a snapshot of v1 @@ -97,10 +140,12 @@ func (env *handoffEnv) refusedForHeadroom(t *testing.T, target, name string) str // // A refused target exists in the catalog and holds the master's line, but // cannot start: today it cannot be volume-deleted either (the delete wants a -// clean revocation ACK its holder cannot send), a known limit of 1.0. The -// documented way out is tested: once space is freed, v2 and v3 start and -// serve the snapshot, and v4 starts, is sealed, revoked and acknowledged, and -// then deleted. +// clean revocation ACK its holder cannot send), a known limit of 1.0. Both +// documented ways out are run: once space is freed, v2 and v3 start and serve +// the snapshot, and v4 starts, is sealed, revoked and acknowledged, and then +// deleted; and the refused restore target v6 is force-moved to another host +// with room (n-v7), where it starts, serves the snapshot and is deleted the +// same way. func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER") if small == "" || filler == "" { @@ -111,8 +156,8 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { t.Fatalf("the small file system has %d bytes free, not less than the %d a volume needs: fix the runner", free, need) } - env := startLadderEnv(t, "v2", "v3", "v4", "v5") - for _, v := range []string{"v2", "v3", "v4"} { + env := startLadderEnv(t, "v2", "v3", "v4", "v5", "v6", "v7") + for _, v := range []string{"v2", "v3", "v4", "v6"} { b := env.hosts["n-"+v] b.root = filepath.Join(small, t.Name(), "vol-n-"+v) env.hosts["n-"+v] = b @@ -128,10 +173,13 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.h.command(t, "ops", "chunk", "fork", "--source", "v1", "--snapshot", "base", "--target", "v3", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v4", - "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - for _, v := range []string{"v2", "v3", "v4"} { - env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") + for _, v := range []string{"v4", "v6"} { + env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", v, + "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) + } + refused := map[string]*daemon{} + for _, v := range []string{"v2", "v3", "v4", "v6"} { + refused[v] = env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") } // The stranded target: not deletable while its holder cannot start. @@ -163,26 +211,48 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { env.requireImage(t, "n-"+v, img) } - // The documented way out for the stranded target: with room it starts, - // and the usual delete steps (seal, revoke, ACK, delete) complete. - _, mustU := fatalOn(t) + // Way out 1 for a stranded target: with room it starts, and the usual + // delete steps (seal, revoke, ACK, delete) complete. + adopted := func(vol string) *regexp.Regexp { + return regexp.MustCompile(`blockvolume: volume ` + vol + ` adopted as PRIMARY at r1@(\d+) `) + } d4 := env.startTarget(t, "v4", "blockvolume-v4-with-room") - e4 := mustU(adoptedEpoch(d4.line("blockvolume: volume v4 adopted as PRIMARY at r1@"))) - b4 := env.hosts["n-v4"] - out, errOut = env.h.command(t, "ops", "chunk", "detach", "--plain", "--volume", "v4", "--status-addr", b4.status, "--timeout", "120s") - g4 := mustU(sealedGen(out, errOut, e4)) - env.h.command(t, "ops", "workspace", "revoke", "--master", env.h.masterAddr, "--volume", "v4", "--replica", "r1", - "--epoch", fmt.Sprint(e4), "--sealed-gen", fmt.Sprint(g4)) - if err := d4.wait(30 * time.Second); err != nil { - t.Fatalf("v4 after the revocation: %v; want a clean exit by itself", err) - } - poll(t, 30*time.Second, "workspace show never reported v4's ACK", func() bool { - out, _ := env.h.command(t, "ops", "workspace", "show", "--master", env.h.masterAddr, "--volume", "v4") - return showsAck(out, e4, g4) + env.deleteServingTarget(t, "v4", env.hosts["n-v4"], d4, logUint(t, d4, adopted("v4"))) + + // Way out 2: the refused target's line is force-moved to a host with room + // (n-v7, whose own volume is never created), where it starts, serves the + // snapshot, and is deleted the same way. + e6 := logUint(t, refused["v6"], regexp.MustCompile(`assignment stream delivery .*volume="v6" .*epoch=(\d+)`)) + b7 := env.hosts["n-v7"] + move := []string{"ops", "workspace", "force-move", "--master", env.h.masterAddr, "--volume", "v6", + "--target-host", b7.id, "--target-data", b7.data, "--target-ctrl", b7.ctrl, "--request-id", "force-v6", + "--confirm-forced", fmt.Sprintf("v6@%d", e6)} + var preview string + poll(t, 150*time.Second, "the forced move of the refused, never-started target v6 was never admitted", func() bool { + out, errOut, _ := env.h.run(t, append(append([]string{}, move...), "--dry-run")...) + preview = out + errOut + return previewAdmitted(out) }) - out, errOut, code = deleteV4() - var del struct{ Completed bool } - if code != 0 || json.Unmarshal([]byte(out), &del) != nil || !del.Completed { - t.Fatalf("volume-delete of v4 after the way out: exit %d %s %s; want completed", code, out, errOut) + t.Logf("forced move of v6 admitted: %s", strings.TrimSpace(preview)) + out, _ = env.h.command(t, move...) + issued := regexp.MustCompile(fmt.Sprintf(`(?m)^forced move issued: volume v6 request \S+: r1@%d on n-v6 -> r1@(\d+) on %s `, e6, regexp.QuoteMeta(b7.id))) + m := issued.FindStringSubmatch(out) + if m == nil { + t.Fatalf("forced move of v6: %q; want issued to %s", out, b7.id) } + b6 := b7 + b6.volume = "v6" + b6.root = filepath.Join(filepath.Dir(b7.root), "vol-n-v7-v6") + env.hosts["n-v7"] = b6 + d6 := env.h.start(t, "blockvolume-v6-on-n-v7", env.h.volume, env.volArgsFor(b6)...) + d6.waitLog(t, 60*time.Second, "blockvolume: volume v6 adopted as PRIMARY at r1@") + e62 := logUint(t, d6, adopted("v6")) + if fmt.Sprint(e62) != m[1] { + t.Fatalf("v6 adopted at epoch %d on n-v7; the forced move issued %s", e62, m[1]) + } + poll(t, 60*time.Second, "v6 never reported its frontend ready on n-v7", func() bool { + return volumeFrontendReady(b6.status, "v6") + }) + env.requireImage(t, "n-v7", img) + env.deleteServingTarget(t, "v6", b6, d6, e62) } From c692f894627d463ec4bcb340b8d0137f9db440b2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:29:41 -0800 Subject: [PATCH 6/9] test: headroom seals each target with a per-volume check of the detach answer Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index 9ab8345a90..cbec0cab08 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -110,9 +110,17 @@ func logUint(t *testing.T, d *daemon, re *regexp.Regexp) uint64 { // and clean exit, then volume-delete, which must complete. func (env *handoffEnv) deleteServingTarget(t *testing.T, vol string, b bvHost, d *daemon, e uint64) { t.Helper() - _, mustU := fatalOn(t) out, errOut := env.h.command(t, "ops", "chunk", "detach", "--plain", "--volume", vol, "--status-addr", b.status, "--timeout", "120s") - g := mustU(sealedGen(out, errOut, e)) + var a struct { + VolumeID string `json:"volumeID"` + HeadGen uint64 `json:"headGen"` + HeadEpoch uint64 `json:"headEpoch"` + } + if err := json.Unmarshal([]byte(out), &a); err != nil || a.VolumeID != vol || a.HeadGen == 0 || a.HeadEpoch != e || + strings.TrimSpace(errOut) != fmt.Sprintf("sealed HEAD generation: %d", a.HeadGen) { + t.Fatalf("plain detach of %s: %v %q %q; want %s sealed at epoch %d with its generation line", vol, err, out, errOut, vol, e) + } + g := a.HeadGen env.h.command(t, "ops", "workspace", "revoke", "--master", env.h.masterAddr, "--volume", vol, "--replica", "r1", "--epoch", fmt.Sprint(e), "--sealed-gen", fmt.Sprint(g)) if err := d.wait(30 * time.Second); err != nil { From 9c341c49ec0bd8239a4e58d16e47f12104a5d6a8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:32:56 -0800 Subject: [PATCH 7/9] test: headroom reports the forced move's last dry-run answer when it is never admitted Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index cbec0cab08..8dee6ea7b9 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -236,11 +236,16 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { "--target-host", b7.id, "--target-data", b7.data, "--target-ctrl", b7.ctrl, "--request-id", "force-v6", "--confirm-forced", fmt.Sprintf("v6@%d", e6)} var preview string - poll(t, 150*time.Second, "the forced move of the refused, never-started target v6 was never admitted", func() bool { + for end := time.Now().Add(150 * time.Second); ; time.Sleep(2 * time.Second) { out, errOut, _ := env.h.run(t, append(append([]string{}, move...), "--dry-run")...) - preview = out + errOut - return previewAdmitted(out) - }) + preview = strings.TrimSpace(out + errOut) + if previewAdmitted(out) { + break + } + if time.Now().After(end) { + t.Fatalf("the forced move of the refused, never-started target v6 was never admitted in 150 s; the last dry run answered: %s", preview) + } + } t.Logf("forced move of v6 admitted: %s", strings.TrimSpace(preview)) out, _ = env.h.command(t, move...) issued := regexp.MustCompile(fmt.Sprintf(`(?m)^forced move issued: volume v6 request \S+: r1@%d on n-v6 -> r1@(\d+) on %s `, e6, regexp.QuoteMeta(b7.id))) From 7365944675134b98cc2a62f31f0ecbc94b611c8e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:37:01 -0800 Subject: [PATCH 8/9] test: headroom pins the forced move refused for a never-started target; the one way out (free space) runs for v4 and v6 Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 60 ++++++------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index 8dee6ea7b9..9bc0bd1892 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -147,13 +147,12 @@ func (env *handoffEnv) deleteServingTarget(t *testing.T, vol string, b bvHost, d // serves it. // // A refused target exists in the catalog and holds the master's line, but -// cannot start: today it cannot be volume-deleted either (the delete wants a -// clean revocation ACK its holder cannot send), a known limit of 1.0. Both -// documented ways out are run: once space is freed, v2 and v3 start and serve -// the snapshot, and v4 starts, is sealed, revoked and acknowledged, and then -// deleted; and the refused restore target v6 is force-moved to another host -// with room (n-v7), where it starts, serves the snapshot and is deleted the -// same way. +// cannot start, and until it has started once it is stranded (a known limit +// of 1.0): a volume-delete wants a clean revocation ACK its holder cannot +// send, and a forced move to a host with room (n-v7) is refused because the +// master knows no holder of it. The one way out is run: once space is freed, +// v2 and v3 start and serve the snapshot, and v4 and v6 start, serve, and are +// sealed, revoked, acknowledged and deleted. func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER") if small == "" || filler == "" { @@ -227,45 +226,22 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { d4 := env.startTarget(t, "v4", "blockvolume-v4-with-room") env.deleteServingTarget(t, "v4", env.hosts["n-v4"], d4, logUint(t, d4, adopted("v4"))) - // Way out 2: the refused target's line is force-moved to a host with room - // (n-v7, whose own volume is never created), where it starts, serves the - // snapshot, and is deleted the same way. + // A forced move is no way out for a refused target: the master knows no + // holder of it (it never held a lease), so every dry run is refused and + // nothing is sent. Its one way out is the first: with room, it starts on + // its own host and is deleted the usual way. e6 := logUint(t, refused["v6"], regexp.MustCompile(`assignment stream delivery .*volume="v6" .*epoch=(\d+)`)) b7 := env.hosts["n-v7"] move := []string{"ops", "workspace", "force-move", "--master", env.h.masterAddr, "--volume", "v6", "--target-host", b7.id, "--target-data", b7.data, "--target-ctrl", b7.ctrl, "--request-id", "force-v6", - "--confirm-forced", fmt.Sprintf("v6@%d", e6)} - var preview string - for end := time.Now().Add(150 * time.Second); ; time.Sleep(2 * time.Second) { - out, errOut, _ := env.h.run(t, append(append([]string{}, move...), "--dry-run")...) - preview = strings.TrimSpace(out + errOut) - if previewAdmitted(out) { - break - } - if time.Now().After(end) { - t.Fatalf("the forced move of the refused, never-started target v6 was never admitted in 150 s; the last dry run answered: %s", preview) + "--confirm-forced", fmt.Sprintf("v6@%d", e6), "--dry-run"} + for end := time.Now().Add(30 * time.Second); time.Now().Before(end); time.Sleep(3 * time.Second) { + out, errOut, code := env.h.run(t, move...) + if code == 0 || previewAdmitted(out) || !strings.Contains(out+errOut, `the master knows no holder of volume "v6"`) || !strings.Contains(out+errOut, "nothing was sent") { + t.Fatalf("forced move of the refused, never-started v6: exit %d %s %s; want refused, the master knowing no holder, nothing sent", code, out, errOut) } } - t.Logf("forced move of v6 admitted: %s", strings.TrimSpace(preview)) - out, _ = env.h.command(t, move...) - issued := regexp.MustCompile(fmt.Sprintf(`(?m)^forced move issued: volume v6 request \S+: r1@%d on n-v6 -> r1@(\d+) on %s `, e6, regexp.QuoteMeta(b7.id))) - m := issued.FindStringSubmatch(out) - if m == nil { - t.Fatalf("forced move of v6: %q; want issued to %s", out, b7.id) - } - b6 := b7 - b6.volume = "v6" - b6.root = filepath.Join(filepath.Dir(b7.root), "vol-n-v7-v6") - env.hosts["n-v7"] = b6 - d6 := env.h.start(t, "blockvolume-v6-on-n-v7", env.h.volume, env.volArgsFor(b6)...) - d6.waitLog(t, 60*time.Second, "blockvolume: volume v6 adopted as PRIMARY at r1@") - e62 := logUint(t, d6, adopted("v6")) - if fmt.Sprint(e62) != m[1] { - t.Fatalf("v6 adopted at epoch %d on n-v7; the forced move issued %s", e62, m[1]) - } - poll(t, 60*time.Second, "v6 never reported its frontend ready on n-v7", func() bool { - return volumeFrontendReady(b6.status, "v6") - }) - env.requireImage(t, "n-v7", img) - env.deleteServingTarget(t, "v6", b6, d6, e62) + d6 := env.startTarget(t, "v6", "blockvolume-v6-with-room") + env.requireImage(t, "n-v6", img) + env.deleteServingTarget(t, "v6", env.hosts["n-v6"], d6, logUint(t, d6, adopted("v6"))) } From f9d30f8f5e2c0be9808e8d31d91e9ebaf0268021 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:47:24 -0800 Subject: [PATCH 9/9] test: headroom runner script in testdata, exact replica-floor check, pinned delete refusal, distinct request ids, the per-volume limit asserted Co-Authored-By: Claude Opus 5.5 --- .../headroom_restore_fork_integration_test.go | 58 ++++++++++++++----- .../blockvolume/testdata/headroom-small-fs.sh | 43 ++++++++++++++ 2 files changed, 87 insertions(+), 14 deletions(-) create mode 100755 seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index 9bc0bd1892..f94e200850 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -18,13 +18,15 @@ import ( // Local headroom for a restore and a fork target. The durable root of each // target is on a small file system (CHUNKSTORE_SMALL_ROOT, a directory on it) // that a filler file (CHUNKSTORE_SMALL_FILLER, on the same file system) keeps -// below the volume size + WAL. The runner prepares both (a loop-mounted ext4 -// needs root); without them the test is skipped. +// below the volume size + WAL. testdata/headroom-small-fs.sh prepares both on +// a fresh loop-mounted ext4 for each run and removes it afterwards (root +// only); without them the test is skipped, as in CI. // // The check's limit: it compares one volume's size + WAL with the free space -// at that moment, not the sum over every volume on the file system. Two -// 256 MiB + 64 MiB targets both pass on the 512 MiB file system once the -// filler is gone, though together they could outgrow it. +// at that moment, not the sum over every volume on the file system. Once the +// filler is gone, four 256 MiB + 64 MiB targets (1280 MiB together) all start +// on the 768 MiB file system; the test asserts that sum exceeds the file +// system's size. const ( headroomVolumeBytes = 65536 * 4096 // the harness's volume size @@ -40,19 +42,37 @@ func freeBytes(t *testing.T, dir string) int64 { return int64(st.Bavail) * int64(st.Bsize) } -// requireOnlyReplicaFloor fails unless the only regular file under dir is +func fsBytes(t *testing.T, dir string) int64 { + t.Helper() + var st syscall.Statfs_t + if err := syscall.Statfs(dir, &st); err != nil { + t.Fatal(err) + } + return int64(st.Blocks) * int64(st.Bsize) +} + +// requireOnlyReplicaFloor requires the regular files under dir to be exactly // the volume's replica floor: a refused create writes no store, WAL or // marker. The floor is written when the assignment arrives, before the store // is opened and refused (a known limit: the check precedes the store, not // every sidecar). func requireOnlyReplicaFloor(t *testing.T, dir, vol string) { t.Helper() - _ = filepath.Walk(dir, func(p string, info os.FileInfo, err error) error { - if err == nil && !info.IsDir() && filepath.Base(p) != vol+".replica-floor" { - t.Fatalf("a refused create left %s (%d bytes)", p, info.Size()) + var files []string + if err := filepath.Walk(dir, func(p string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() { + files = append(files, filepath.Base(p)) } return nil - }) + }); err != nil { + t.Fatalf("listing %s: %v", dir, err) + } + if len(files) != 1 || files[0] != vol+".replica-floor" { + t.Fatalf("a refused create left %v under %s; want exactly %s.replica-floor", files, dir, vol) + } } // refusedForHeadroom starts the target's blockvolume and requires it to @@ -139,8 +159,9 @@ func (env *handoffEnv) deleteServingTarget(t *testing.T, vol string, b bvHost, d } // TestHeadroomRefusesARestoreAndAForkTargetThenServesThem: a snapshot of v1 -// is restored into v2 and v4 and forked into v3, each target's durable root -// on a small file system with less free space than the volume size + WAL. +// is restored into v2, v4 and v6 and forked into v3, each target's durable +// root on a small file system with less free space than the volume size + +// WAL. // Each target's blockvolume refuses the create, naming both numbers, exits // with status 1, and writes no store; the source still serves its data and // its snapshot is still listed, and restores into another target (v5) that @@ -163,6 +184,7 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { t.Fatalf("the small file system has %d bytes free, not less than the %d a volume needs: fix the runner", free, need) } + t.Cleanup(func() { _ = os.RemoveAll(filepath.Join(small, t.Name())) }) env := startLadderEnv(t, "v2", "v3", "v4", "v5", "v6", "v7") for _, v := range []string{"v2", "v3", "v4", "v6"} { b := env.hosts["n-"+v] @@ -192,10 +214,10 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { // The stranded target: not deletable while its holder cannot start. deleteV4 := func() (string, string, int) { return env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v4", "--chunk-filer", env.cluster.filerGRPC, - "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-v4") + "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-v4-while-refused") } out, errOut, code := deleteV4() - if code == 0 || !strings.Contains(out+errOut, "live authority requires clean revocation ACK") { + if code != 1 || !strings.Contains(out+errOut, "live authority requires clean revocation ACK") { t.Fatalf("volume-delete of the refused target v4: exit %d %s %s; want refused for the missing ACK (a known limit)", code, out, errOut) } // The snapshot is still restorable into another target that has room. @@ -244,4 +266,12 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { d6 := env.startTarget(t, "v6", "blockvolume-v6-with-room") env.requireImage(t, "n-v6", img) env.deleteServingTarget(t, "v6", env.hosts["n-v6"], d6, logUint(t, d6, adopted("v6"))) + + // The check is per volume, not a sum: all four targets started on this + // file system, though together they need more than its whole size. + if total, size := 4*need, fsBytes(t, small); total <= size { + t.Fatalf("four targets need %d bytes, not more than the %d-byte file system: the run does not show the per-volume limit", total, size) + } else { + t.Logf("four targets needing %d bytes together all started on a %d-byte file system (the check is per volume)", total, size) + } } diff --git a/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh b/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh new file mode 100755 index 0000000000..96553abf9f --- /dev/null +++ b/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Small-file-system harness for TestHeadroomRefusesARestoreAndAForkTargetThenServesThem. +# Root only, on a disposable host; it formats only a loop device over a private +# sparse file under WORKDIR. +# +# headroom-small-fs.sh WORKDIR -- TEST_COMMAND... +# +# It makes a 768 MiB ext4 (no reserved blocks) on a loop device, mounts it at +# WORKDIR/mnt and fills 600 MiB of it with WORKDIR/mnt/filler, so less than a +# volume's size + WAL (256 MiB + 64 MiB) is free; the test removes the filler +# when it needs room. The test runs with CHUNKSTORE_SMALL_ROOT (a directory on +# that file system) and CHUNKSTORE_SMALL_FILLER (the filler). Each run gets a +# fresh file system. Exit status is the test's. Everything this script created +# is removed. +# +# Example (from the repository root, as root): +# mkdir /tmp/headroom && cmd/blockvolume/testdata/headroom-small-fs.sh /tmp/headroom -- \ +# env CHUNKSTORE_WEED=/path/to/weed go test -count=1 -tags 'subprocess chunkstore_integration' \ +# -run '^TestHeadroomRefusesARestoreAndAForkTargetThenServesThem$' -timeout 15m ./cmd/blockvolume/ +set -euo pipefail +[ "$(id -u)" = 0 ] || { echo "root required" >&2; exit 2; } +work=$(realpath "${1:?existing empty work dir}") +[ "${2:-}" = -- ] || { echo "usage: $0 WORKDIR -- TEST_COMMAND..." >&2; exit 2; } +shift 2 +for c in losetup mkfs.ext4 mount umount mountpoint truncate dd; do command -v "$c" >/dev/null; done +loop= +cleanup() { + if mountpoint -q "$work/mnt"; then umount "$work/mnt"; fi + if [ -n "$loop" ]; then losetup -d "$loop" || true; fi + rm -rf "$work/mnt" "$work/small.img" +} +trap cleanup EXIT +mkdir "$work/mnt" +truncate -s 768M "$work/small.img" +loop=$(losetup --find --show "$work/small.img") +mkfs.ext4 -q -F -m 0 "$loop" +mount "$loop" "$work/mnt" +dd if=/dev/zero of="$work/mnt/filler" bs=1M count=600 status=none +sync +mkdir "$work/mnt/roots" +status=0 +CHUNKSTORE_SMALL_ROOT="$work/mnt/roots" CHUNKSTORE_SMALL_FILLER="$work/mnt/filler" "$@" || status=$? +exit "$status"