From 733c505d42d0ba329f207b18204474ad02604c3d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:19:13 -0800 Subject: [PATCH 1/5] test: filer or volume server down during a cut, then back (real binaries) Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 206 ++++++++++++++++++ .../workspace_weed_integration_test.go | 84 +++++-- 2 files changed, 272 insertions(+), 18 deletions(-) create mode 100644 seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go new file mode 100644 index 0000000000..2f4eec3d81 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -0,0 +1,206 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "bytes" + "errors" + "fmt" + "os" + "path/filepath" + "testing" + "time" +) + +// The SeaweedFS side down during a cut, then back (V1-SPEC r2.61 addendum, +// round 2), with real binaries: image B is written and a cut starts; once +// its uploads have begun, the filer (or the volume server) is killed. For a +// minute the guest keeps writing and flushing over NVMe/TCP while the test +// records how the cut answers and how much copy-on-write side data the +// stalled cut keeps on the local root. Then the store comes back. +// +// Asserted: every guest command answers within storeDownBound and a guest +// write that was flushed is never lost; the cut answers (an error is +// allowed) once the store is back at the latest; the next cut moves HEAD and +// verifies at depth data; no COW side file is left; a snapshot restored into +// a new volume is the last flushed image. Recorded for the operator guide: +// guest errors and the slowest answer while the store is down, when and how +// the cut answered, the peak COW side bytes. +const storeDownBound = 20 * time.Second + +func TestProcedureStoreDownDuringACut(t *testing.T) { + for _, down := range []string{"filer", "volume"} { + t.Run(down, func(t *testing.T) { storeDownDuringACut(t, down) }) + } +} + +func storeDownDuringACut(t *testing.T, down string) { + env := startHandoffEnvWith(t, 1, []string{"v2"}) + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + holder := env.start(t, "blockvolume-v1", "s1") + env.adopt(t, holder, "s1") + cut := []string{"ops", "chunk", "cut", "--volume", "v1", "--status-addr", env.hosts["s1"].status} + verify := []string{"ops", "chunk", "verify", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--depth", "data", "--timeout", "5m"} + headGen := func() uint64 { + out, _ := env.h.command(t, env.chunkShow()...) + hd, err := parseHead(out) + if err != nil { + t.Fatal(err) + } + return hd.Gen + } + sideBytes := func() int64 { + files, _ := filepath.Glob(filepath.Join(env.hosts["s1"].root, "*.cut-cow-*")) + var n int64 + for _, f := range files { + if st, err := os.Stat(f); err == nil { + n += st.Size() + } + } + return n + } + + env.writeCutCrashImage(t, 'A') + env.h.command(t, cut...) + env.writeCutCrashImage(t, 'B') + want := map[uint64][]byte{} + for ch := 0; ch < cutCrashChunks; ch++ { + for i := 0; i < cutCrashPer; i++ { + lba := uint64(ch*ladderChunkBlocks + i) + want[lba] = cutCrashBlock('B', lba) + } + } + + // A cut starts; the store goes down once its uploads have begun. + gen, entries := headGen(), f1FilerEntries(t, env) + type cutAnswer struct { + rc int + out string + at time.Duration + } + answered := make(chan cutAnswer, 1) + cutStart := time.Now() + go func() { + out, errOut, rc := env.h.run(t, cut...) + answered <- cutAnswer{rc, out + errOut, time.Since(cutStart)} + }() + for end := time.Now().Add(10 * time.Second); f1FilerEntries(t, env) <= entries && time.Now().Before(end); time.Sleep(20 * time.Millisecond) { + } + env.cluster.stopProc(t, down) + downAt := time.Now() + t.Logf("%s killed %s after the cut started", down, downAt.Sub(cutStart).Round(time.Millisecond)) + + // A minute of guest writes and flushes while the store is down. + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + var pending []uint64 + var errs int + var slowest time.Duration + var cutWhileDown *cutAnswer + peakSide := sideBytes() + op := func(f func() error) error { + start := time.Now() + _ = c.io.SetDeadline(start.Add(storeDownBound)) + err := f() + if d := time.Since(start); d > slowest { + slowest = d + } + var ne interface{ Timeout() bool } + if errors.As(err, &ne) && ne.Timeout() { + t.Fatalf("%s down: a guest command did not answer within %s: %v", down, storeDownBound, err) + } + return err + } + written := 0 + for n := 0; time.Since(downAt) < time.Minute; n++ { + ch, i := (n/cutCrashPer)%cutCrashChunks, n%cutCrashPer + lba := uint64(ch*ladderChunkBlocks + i) + b := cutCrashBlock('C', lba) + if err := op(func() error { return c.tryWrite(lba, b) }); err != nil { + errs++ + continue + } + written++ + pending = append(pending, lba) + if len(pending) == 8 { + if err := op(c.tryFlush); err != nil { + errs++ + } else { + for _, l := range pending { + want[l] = cutCrashBlock('C', l) + } + } + pending = pending[:0] + } + if s := sideBytes(); s > peakSide { + peakSide = s + } + if cutWhileDown == nil { + select { + case a := <-answered: + cutWhileDown = &a + default: + } + } + time.Sleep(10 * time.Millisecond) + } + c.close() + t.Logf("%s down 60s: guest writes %d, errors %d, slowest answer %s, frontend ready %v, peak COW side bytes %d", + down, written, errs, slowest.Round(time.Millisecond), env.frontendReadyAt("s1"), peakSide) + if cutWhileDown != nil { + t.Logf("%s down: the cut answered while it was down, after %s, exit %d: %s", down, cutWhileDown.at.Round(time.Millisecond), cutWhileDown.rc, firstLine(cutWhileDown.out)) + } else { + t.Logf("%s down: the cut had not answered after %s", down, time.Since(cutStart).Round(time.Second)) + } + + // The store comes back. + env.cluster.restartProc(t, down) + backAt := time.Now() + if down == "filer" { + w4WaitTCP(t, env.cluster.filerGRPC, 30*time.Second) + } + if cutWhileDown == nil { + select { + case a := <-answered: + t.Logf("%s back: the stalled cut answered %s after the restart, exit %d: %s", down, time.Since(backAt).Round(time.Millisecond), a.rc, firstLine(a.out)) + case <-time.After(5 * time.Minute): + t.Fatalf("%s back: the cut started before the outage never answered", down) + } + } + var g uint64 + for end := time.Now().Add(2 * time.Minute); ; time.Sleep(2 * time.Second) { + _, _, rc := env.h.run(t, cut...) + if g = headGen(); rc == 0 && g > gen { + break + } + if time.Now().After(end) { + t.Fatalf("%s back: no cut committed within 2m (HEAD gen %d, was %d)", down, g, gen) + } + } + t.Logf("%s back: a cut committed %s after the restart (HEAD gen %d -> %d)", down, time.Since(backAt).Round(time.Millisecond), gen, g) + if out, errOut, rc := env.h.run(t, verify...); rc != 0 { + t.Fatalf("%s back: HEAD does not verify (exit %d):\n%s\n%s", down, rc, out, errOut) + } + if s := sideBytes(); s != 0 { + t.Fatalf("%s back: %d COW side bytes left on the local root after a committed cut", down, s) + } + env.snapshot(t, "s1", "v1", "after-"+down+"-down") + env.restoreInto(t, "v1", "after-"+down+"-down", "v2") + for _, host := range []string{"s1", "n-v2"} { + c := dialNVMe(t, env.hosts[host].nvme, plannedHandoffNQN) + for lba, w := range want { + if got := c.read(t, lba, 4096); !bytes.Equal(got, w) { + c.close() + t.Fatalf("%s back: %s LBA %d is not the last flushed write", down, host, lba) + } + } + c.close() + } + fmt.Printf("STORE_DOWN_OK %s\n", down) +} + +func firstLine(s string) string { + if i := bytes.IndexByte([]byte(s), '\n'); i >= 0 { + return s[:i] + } + return s +} diff --git a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go index 5ca1cbde54..d0bdb10205 100644 --- a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go +++ b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go @@ -21,6 +21,7 @@ type w4WeedCluster struct { master, filerHTTP, filerGRPC string dir string weed string + procs map[string]*w4WeedProc } func w4FreePortPair(t *testing.T, used map[int]bool) int { @@ -86,29 +87,17 @@ func startWorkspaceWeedAt(t *testing.T, dir string) *w4WeedCluster { dir: dir, weed: weed, } + c.procs = map[string]*w4WeedProc{} run := func(name string, args ...string) { - logf, err := os.Create(filepath.Join(dir, name+".log")) - if err != nil { - t.Fatal(err) - } - cmd := exec.Command(weed, args...) - cmd.Stdout, cmd.Stderr = logf, logf - cmd.Dir = dir - if err := cmd.Start(); err != nil { - t.Fatalf("start %s: %v", name, err) - } + c.startProc(t, name, args...) t.Cleanup(func() { - _ = cmd.Process.Kill() - done := make(chan error, 1) - go func() { done <- cmd.Wait() }() - select { - case <-done: - case <-time.After(5 * time.Second): + p := c.procs[name] + if !c.stopProcWithin(name, 5*time.Second) { t.Errorf("weed %s did not exit after kill", name) } - logf.Close() + p.log.Close() if t.Failed() { - b, _ := os.ReadFile(logf.Name()) + b, _ := os.ReadFile(p.log.Name()) if len(b) > 4000 { b = b[len(b)-4000:] } @@ -145,6 +134,65 @@ func startWorkspaceWeedAt(t *testing.T, dir string) *w4WeedCluster { return c } +// w4WeedProc is one weed process; a restart replaces it under the same name, +// arguments and log, so the cluster's cleanup always ends the current one. +type w4WeedProc struct { + args []string + log *os.File + cmd *exec.Cmd + done chan struct{} +} + +func (c *w4WeedCluster) startProc(t *testing.T, name string, args ...string) { + t.Helper() + p := c.procs[name] + if p == nil { + logf, err := os.Create(filepath.Join(c.dir, name+".log")) + if err != nil { + t.Fatal(err) + } + p = &w4WeedProc{args: args, log: logf} + c.procs[name] = p + } + cmd := exec.Command(c.weed, p.args...) + cmd.Stdout, cmd.Stderr = p.log, p.log + cmd.Dir = c.dir + if err := cmd.Start(); err != nil { + t.Fatalf("start %s: %v", name, err) + } + p.cmd, p.done = cmd, make(chan struct{}) + go func(done chan struct{}) { _ = cmd.Wait(); close(done) }(p.done) +} + +// stopProcWithin kills name's current process and reports whether it exited. +func (c *w4WeedCluster) stopProcWithin(name string, d time.Duration) bool { + p := c.procs[name] + if p == nil || p.cmd == nil { + return true + } + _ = p.cmd.Process.Kill() + select { + case <-p.done: + return true + case <-time.After(d): + return false + } +} + +// stopProc and restartProc take one weed process (master, volume, filer) down +// and bring it back with the same ports and data directory. +func (c *w4WeedCluster) stopProc(t *testing.T, name string) { + t.Helper() + if !c.stopProcWithin(name, 10*time.Second) { + t.Fatalf("weed %s did not exit after kill", name) + } +} + +func (c *w4WeedCluster) restartProc(t *testing.T, name string) { + t.Helper() + c.startProc(t, name) +} + func (c *w4WeedCluster) client(t *testing.T, assignPath string) *chunkstore.SWFS { t.Helper() cl, err := chunkstore.DialSWFS(chunkstore.SWFSConfig{FilerGRPC: c.filerGRPC, Collection: "swblock", AssignPath: assignPath}) From a76288e82f7f345e65f6ad6aae3ae481a329d8c4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:26:29 -0800 Subject: [PATCH 2/5] test: store down during a cut: a variant past the cut's copy-on-write reserve, outcome recorded Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go index 2f4eec3d81..7c92465d9e 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -30,13 +30,30 @@ const storeDownBound = 20 * time.Second func TestProcedureStoreDownDuringACut(t *testing.T) { for _, down := range []string{"filer", "volume"} { - t.Run(down, func(t *testing.T) { storeDownDuringACut(t, down) }) + t.Run(down, func(t *testing.T) { storeDownDuringACut(t, down, 0) }) } + // The limit (claude06's variant): the stalled cut's copy-on-write reserve + // (--host-limit-cow-bytes) is 4 MiB, less than the 12 MiB of its capture + // that the guest overwrites during the outage. The outcome is recorded. + t.Run("volume-cow-reserve-exceeded", func(t *testing.T) { storeDownDuringACut(t, "volume", 4<<20) }) } -func storeDownDuringACut(t *testing.T, down string) { +func storeDownDuringACut(t *testing.T, down string, cowBytes int64) { env := startHandoffEnvWith(t, 1, []string{"v2"}) env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + if cowBytes > 0 { + // Not under a temporary directory: the host-limit launch check refuses one. + home, err := os.UserHomeDir() + if err != nil { + t.Fatal(err) + } + dir, err := os.MkdirTemp(home, ".swblock-test-host-limit-") + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = os.RemoveAll(dir) }) + env.volExtra = append(env.volExtra, "--host-limit-dir", dir, "--host-limit-cow-bytes", fmt.Sprint(cowBytes)) + } holder := env.start(t, "blockvolume-v1", "s1") env.adopt(t, holder, "s1") cut := []string{"ops", "chunk", "cut", "--volume", "v1", "--status-addr", env.hosts["s1"].status} @@ -93,7 +110,7 @@ func storeDownDuringACut(t *testing.T, down string) { // A minute of guest writes and flushes while the store is down. c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) var pending []uint64 - var errs int + var errs, timeouts int var slowest time.Duration var cutWhileDown *cutAnswer peakSide := sideBytes() @@ -106,7 +123,13 @@ func storeDownDuringACut(t *testing.T, down string) { } var ne interface{ Timeout() bool } if errors.As(err, &ne) && ne.Timeout() { - t.Fatalf("%s down: a guest command did not answer within %s: %v", down, storeDownBound, err) + if cowBytes == 0 { + t.Fatalf("%s down: a guest command did not answer within %s: %v", down, storeDownBound, err) + } + timeouts++ + // The queue is mid-command after a timeout: a new connection. + c.close() + c = dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) } return err } @@ -144,8 +167,8 @@ func storeDownDuringACut(t *testing.T, down string) { time.Sleep(10 * time.Millisecond) } c.close() - t.Logf("%s down 60s: guest writes %d, errors %d, slowest answer %s, frontend ready %v, peak COW side bytes %d", - down, written, errs, slowest.Round(time.Millisecond), env.frontendReadyAt("s1"), peakSide) + t.Logf("%s down 60s (COW reserve %d): guest writes %d, errors %d (of them over %s: %d), slowest answer %s, frontend ready %v, peak COW side bytes %d", + down, cowBytes, written, errs, storeDownBound, timeouts, slowest.Round(time.Millisecond), env.frontendReadyAt("s1"), peakSide) if cutWhileDown != nil { t.Logf("%s down: the cut answered while it was down, after %s, exit %d: %s", down, cutWhileDown.at.Round(time.Millisecond), cutWhileDown.rc, firstLine(cutWhileDown.out)) } else { From 2d6d11fd8ad80b96071eee5ffd7872665346287a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:06:41 -0800 Subject: [PATCH 3/5] test: store down during a cut: a 400 MiB copy-on-write window, asserted within half the reserve and closed on the failure Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go index 7c92465d9e..0a045034dc 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" "time" ) @@ -30,15 +31,19 @@ const storeDownBound = 20 * time.Second func TestProcedureStoreDownDuringACut(t *testing.T) { for _, down := range []string{"filer", "volume"} { - t.Run(down, func(t *testing.T) { storeDownDuringACut(t, down, 0) }) + t.Run(down, func(t *testing.T) { storeDownDuringACut(t, down, 0, false) }) } // The limit (claude06's variant): the stalled cut's copy-on-write reserve // (--host-limit-cow-bytes) is 4 MiB, less than the 12 MiB of its capture // that the guest overwrites during the outage. The outcome is recorded. - t.Run("volume-cow-reserve-exceeded", func(t *testing.T) { storeDownDuringACut(t, "volume", 4<<20) }) + t.Run("volume-cow-reserve-exceeded", func(t *testing.T) { storeDownDuringACut(t, "volume", 4<<20, false) }) + // 400 MiB: the 48 captured 4 MiB chunks fit in half of it, so the cut + // opens its copy-on-write window; asserted to stay within reserve/2 and + // to close when the cut fails. + t.Run("volume-cow-window-400MiB", func(t *testing.T) { storeDownDuringACut(t, "volume", 400<<20, true) }) } -func storeDownDuringACut(t *testing.T, down string, cowBytes int64) { +func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bool) { env := startHandoffEnvWith(t, 1, []string{"v2"}) env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} if cowBytes > 0 { @@ -174,6 +179,21 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64) { } else { t.Logf("%s down: the cut had not answered after %s", down, time.Since(cutStart).Round(time.Second)) } + if cowWindow { + // The reserve bounds the copy-on-write window: stage() opens it only + // when the captured chunks fit in half the reserve. + switch { + case cutWhileDown == nil || !strings.Contains(cutWhileDown.out, "capture copy"): + t.Fatalf("%s down: the cut did not fail inside a copy-on-write window (no 'capture copy'): %+v", down, cutWhileDown) + case peakSide == 0 || peakSide > cowBytes/2: + t.Fatalf("%s down: peak COW side bytes %d, want > 0 and <= half the %d reserve", down, peakSide, cowBytes) + case sideBytes() != 0: + t.Fatalf("%s down: %d COW side bytes left after the cut failed: the window did not close", down, sideBytes()) + case written == 0: + t.Fatalf("%s down: the guest wrote nothing while the window was open", down) + } + t.Logf("%s down: COW window measured: peak %d <= reserve/2 %d, closed on the failure", down, peakSide, cowBytes/2) + } // The store comes back. env.cluster.restartProc(t, down) From a105008b9cf0d762e1efc4797df20752f9c55b87 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:18:40 -0800 Subject: [PATCH 4/5] test: store down during a cut, lead review: guest errors/stalls fail in every variant, the kill is proven mid-cut and the stalled cut must fail, HEAD re-read after it answers, each pass writes new bytes, the cut CLI runs off the test goroutine and is drained in cleanup Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 80 +++++++++++++------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go index 0a045034dc..00e80237df 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -4,6 +4,7 @@ package main_test import ( "bytes" + "context" "errors" "fmt" "os" @@ -20,22 +21,25 @@ import ( // records how the cut answers and how much copy-on-write side data the // stalled cut keeps on the local root. Then the store comes back. // -// Asserted: every guest command answers within storeDownBound and a guest -// write that was flushed is never lost; the cut answers (an error is -// allowed) once the store is back at the latest; the next cut moves HEAD and -// verifies at depth data; no COW side file is left; a snapshot restored into -// a new volume is the last flushed image. Recorded for the operator guide: -// guest errors and the slowest answer while the store is down, when and how -// the cut answered, the peak COW side bytes. +// Asserted, in every variant: the store goes down mid-cut (uploads begun, +// HEAD unmoved); the guest keeps writing with no error and every command +// answers within storeDownBound; the cut the outage hit fails; after the +// store returns a later cut moves HEAD and verifies at depth data; no COW +// side file is left; a snapshot restored into a new volume is the last +// flushed image (each pass writes new bytes). Recorded for the operator +// guide: the slowest answer, when and how the stalled cut answered, the peak +// COW side bytes. +// +// Runs 4 variants of about 2-3 minutes: go test -timeout 30m. const storeDownBound = 20 * time.Second func TestProcedureStoreDownDuringACut(t *testing.T) { for _, down := range []string{"filer", "volume"} { t.Run(down, func(t *testing.T) { storeDownDuringACut(t, down, 0, false) }) } - // The limit (claude06's variant): the stalled cut's copy-on-write reserve - // (--host-limit-cow-bytes) is 4 MiB, less than the 12 MiB of its capture - // that the guest overwrites during the outage. The outcome is recorded. + // 4 MiB: the reserve's half holds no 4 MiB chunk, so stage() uploads the + // whole dirty set before the cut point and opens no copy-on-write window; + // with the store down that upload fails. No local space, guest undisturbed. t.Run("volume-cow-reserve-exceeded", func(t *testing.T) { storeDownDuringACut(t, "volume", 4<<20, false) }) // 400 MiB: the 48 captured 4 MiB chunks fit in half of it, so the cut // opens its copy-on-write window; asserted to stay within reserve/2 and @@ -102,11 +106,26 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } answered := make(chan cutAnswer, 1) cutStart := time.Now() + cutCtx, cutCancel := context.WithTimeout(context.Background(), 8*time.Minute) + cutDone := make(chan struct{}) + // Off the test goroutine: runCLI never fails the test, and cleanup waits + // for it so nothing outlives the test. go func() { - out, errOut, rc := env.h.run(t, cut...) + defer close(cutDone) + out, errOut, rc, err := runCLI(cutCtx, env.h, cut...) + if err != nil { + rc, errOut = -1, errOut+err.Error() + } answered <- cutAnswer{rc, out + errOut, time.Since(cutStart)} }() - for end := time.Now().Add(10 * time.Second); f1FilerEntries(t, env) <= entries && time.Now().Before(end); time.Sleep(20 * time.Millisecond) { + t.Cleanup(func() { cutCancel(); <-cutDone }) + for end := time.Now().Add(10 * time.Second); f1FilerEntries(t, env) <= entries; time.Sleep(20 * time.Millisecond) { + if time.Now().After(end) { + t.Fatalf("%s: the cut uploaded nothing within 10s: the store would not go down mid-cut", down) + } + } + if g := headGen(); g != gen { + t.Fatalf("%s: the cut committed (HEAD gen %d -> %d) before the store went down: not mid-cut", down, gen, g) } env.cluster.stopProc(t, down) downAt := time.Now() @@ -115,7 +134,7 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo // A minute of guest writes and flushes while the store is down. c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) var pending []uint64 - var errs, timeouts int + var errs int var slowest time.Duration var cutWhileDown *cutAnswer peakSide := sideBytes() @@ -128,36 +147,35 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } var ne interface{ Timeout() bool } if errors.As(err, &ne) && ne.Timeout() { - if cowBytes == 0 { - t.Fatalf("%s down: a guest command did not answer within %s: %v", down, storeDownBound, err) - } - timeouts++ - // The queue is mid-command after a timeout: a new connection. - c.close() - c = dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + t.Fatalf("%s down: a guest command did not answer within %s: %v", down, storeDownBound, err) } return err } written := 0 + pendingBytes := map[uint64][]byte{} for n := 0; time.Since(downAt) < time.Minute; n++ { ch, i := (n/cutCrashPer)%cutCrashChunks, n%cutCrashPer lba := uint64(ch*ladderChunkBlocks + i) - b := cutCrashBlock('C', lba) + // Each pass over the image writes new bytes ('C', 'D', ...), so a lost + // tail of rewrites is visible at the read-back. + b := cutCrashBlock(byte('C'+n/(cutCrashChunks*cutCrashPer)), lba) if err := op(func() error { return c.tryWrite(lba, b) }); err != nil { errs++ continue } written++ pending = append(pending, lba) + pendingBytes[lba] = b if len(pending) == 8 { if err := op(c.tryFlush); err != nil { errs++ } else { for _, l := range pending { - want[l] = cutCrashBlock('C', l) + want[l] = pendingBytes[l] } } pending = pending[:0] + clear(pendingBytes) } if s := sideBytes(); s > peakSide { peakSide = s @@ -172,8 +190,12 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo time.Sleep(10 * time.Millisecond) } c.close() - t.Logf("%s down 60s (COW reserve %d): guest writes %d, errors %d (of them over %s: %d), slowest answer %s, frontend ready %v, peak COW side bytes %d", - down, cowBytes, written, errs, storeDownBound, timeouts, slowest.Round(time.Millisecond), env.frontendReadyAt("s1"), peakSide) + t.Logf("%s down 60s (COW reserve %d): guest writes %d, errors %d, slowest answer %s, frontend ready %v, peak COW side bytes %d", + down, cowBytes, written, errs, slowest.Round(time.Millisecond), env.frontendReadyAt("s1"), peakSide) + // Guest I/O is not delayed by the outage, in every variant. + if written == 0 || errs != 0 || slowest >= storeDownBound { + t.Fatalf("%s down: the guest was disturbed: %d writes, %d errors, slowest answer %s", down, written, errs, slowest) + } if cutWhileDown != nil { t.Logf("%s down: the cut answered while it was down, after %s, exit %d: %s", down, cutWhileDown.at.Round(time.Millisecond), cutWhileDown.rc, firstLine(cutWhileDown.out)) } else { @@ -201,14 +223,22 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo if down == "filer" { w4WaitTCP(t, env.cluster.filerGRPC, 30*time.Second) } - if cutWhileDown == nil { + stalled := cutWhileDown + if stalled == nil { select { case a := <-answered: + stalled = &a t.Logf("%s back: the stalled cut answered %s after the restart, exit %d: %s", down, time.Since(backAt).Round(time.Millisecond), a.rc, firstLine(a.out)) case <-time.After(5 * time.Minute): t.Fatalf("%s back: the cut started before the outage never answered", down) } } + // The cut the outage hit must have failed; HEAD is read again after its + // answer, so only a later cut can satisfy the check below. + if stalled.rc == 0 { + t.Fatalf("%s: the cut the outage hit reported success: %s", down, firstLine(stalled.out)) + } + gen = headGen() var g uint64 for end := time.Now().Add(2 * time.Minute); ; time.Sleep(2 * time.Second) { _, _, rc := env.h.run(t, cut...) From 8255863cc79c6bdfb13b797563c608b5644a84bd Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 07:26:26 -0800 Subject: [PATCH 5/5] test: store down during a cut: flush the last partial batch so the read-back names every block Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go index 00e80237df..e35739bf54 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -189,6 +189,17 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } time.Sleep(10 * time.Millisecond) } + // The last partial batch is flushed too, so every write is acknowledged + // and the read-back can name each block's bytes. + if len(pending) > 0 { + if err := op(c.tryFlush); err != nil { + errs++ + } else { + for _, l := range pending { + want[l] = pendingBytes[l] + } + } + } c.close() t.Logf("%s down 60s (COW reserve %d): guest writes %d, errors %d, slowest answer %s, frontend ready %v, peak COW side bytes %d", down, cowBytes, written, errs, slowest.Round(time.Millisecond), env.frontendReadyAt("s1"), peakSide)