From d27ddb677720f46eee9383496164a0904c276f23 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:24:38 -0800 Subject: [PATCH 1/7] test: snapshot ladder C3 with kills: target killed mid-hydrate and mid-batch, writes while owning Co-Authored-By: Claude Opus 5.5 --- ...snapshot_ladder_c3kill_integration_test.go | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go new file mode 100644 index 0000000000..b97305a71d --- /dev/null +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -0,0 +1,119 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "context" + "encoding/json" + "fmt" + "testing" + "time" +) + +// restoreProgress is the restore driver's status of a target. +type restoreProgress struct { + Phase string `json:"phase"` + Running bool `json:"running"` + Filled int `json:"filled"` + Owned int `json:"owned"` + Foreign int `json:"foreign"` + Batches int `json:"batches"` +} + +// awaitRestorePhase polls target's restore status every 50 ms until ok +// holds and returns that status; it fails the test if the restore failed, +// became independent first (the moment was missed), or bound passed. +func (env *handoffEnv) awaitRestorePhase(t *testing.T, target, what string, bound time.Duration, ok func(restoreProgress) bool) restoreProgress { + t.Helper() + end := time.Now().Add(bound) + ctx, cancel := context.WithDeadline(context.Background(), end) + defer cancel() + for time.Now().Before(end) { + out, _, code, err := runCLI(ctx, env.h, "ops", "chunk", "restore", "--volume", target, "--status-addr", env.hosts["n-"+target].status, "--status") + var st restoreProgress + if err == nil && code == 0 && json.Unmarshal([]byte(out), &st) == nil { + switch { + case ok(st): + return st + case st.Phase == "failed": + t.Fatalf("restore of %s failed waiting for %s: %s", target, what, out) + case st.Phase == "independent": + t.Fatalf("restore of %s became independent before %s was seen (the restore is too small to catch it): %s", target, what, out) + } + } + time.Sleep(50 * time.Millisecond) + } + t.Fatalf("restore of %s: %s not seen within %v", target, what, bound) + return restoreProgress{} +} + +// startTarget starts target's blockvolume and waits until it serves. +func (env *handoffEnv) startTarget(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)...) + d.waitLog(t, 60*time.Second, fmt.Sprintf("blockvolume: volume %s adopted as PRIMARY at r1@", target)) + poll(t, 60*time.Second, fmt.Sprintf("%s never reported its frontend ready", target), func() bool { + return volumeFrontendReady(b.status, target) + }) + return d +} + +// TestSnapshotLadderC3KilledMidHydrateAndMidBatch: a restore of a snapshot +// of 48 written chunks into v2 (about 192 MiB to make local and re-upload). +// Its blockvolume is killed (SIGKILL) while the driver is hydrating, started +// again and the driver started again. While the driver then owns chunks, the +// guest writes to v2 (acknowledged), and the blockvolume is killed again in +// the middle of the batch, restarted, and the driver started again; the +// guest writes once more. The driver resumes from the target's remote facts +// to independence (per its status). Then v2 holds the snapshot with every +// acknowledged write over it, and the source's snapshot, restored again +// into v3, is unchanged (none of v2's writes in it). +func TestSnapshotLadderC3KilledMidHydrateAndMidBatch(t *testing.T) { + env := startLadderEnv(t, "v2", "v3") + var chunks []uint64 + for c := uint64(0); c < 48; c++ { + chunks = append(chunks, c) + } + src := ladderImage("c3ksrc", chunks, 2) + env.writeImage(t, "s1", src) + 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) + target := env.startTarget(t, "v2", "blockvolume-v2") + drive := func() { + t.Helper() + env.h.command(t, "ops", "chunk", "restore", "--volume", "v2", "--status-addr", env.hosts["n-v2"].status) + } + drive() + + // Killed while hydrating: some chunks local, not all. + st := env.awaitRestorePhase(t, "v2", "hydrating with part of the chunks local", 120*time.Second, func(s restoreProgress) bool { + return s.Phase == "hydrating" && s.Filled > 0 && s.Filled < len(chunks) + }) + target.kill(t) + t.Logf("killed while hydrating: %+v", st) + target = env.startTarget(t, "v2", "blockvolume-v2-after-hydrate-kill") + env.requireImage(t, "n-v2", src) // serves the snapshot at once after the restart + drive() + + // Written while owning, then killed in the middle of the batch. + env.awaitRestorePhase(t, "v2", "owning", 180*time.Second, func(s restoreProgress) bool { return s.Phase == "owning" }) + w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) + env.writeImage(t, "n-v2", w1) + st = env.awaitRestorePhase(t, "v2", "owning with chunks still foreign", 180*time.Second, func(s restoreProgress) bool { + return s.Phase == "owning" && s.Foreign > 0 + }) + target.kill(t) + t.Logf("killed while owning: %+v", st) + target = env.startTarget(t, "v2", "blockvolume-v2-after-batch-kill") + env.requireImage(t, "n-v2", mergeImages(src, w1)) // every acknowledged write survived the kill + drive() + w2 := ladderImage("c3kw2", []uint64{17, 40, 60}, 2) + env.writeImage(t, "n-v2", w2) + + env.waitIndependent(t, "v2") + env.requireImage(t, "n-v2", mergeImages(src, w1, w2)) + env.restoreChecked(t, "base", "v3", src, w1, w2) +} From 4be8d84b84e0ff4991f3aafe06122ea784523497 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 20:59:15 -0800 Subject: [PATCH 2/7] test: restore kill test uses 32 full chunks of incompressible data so its phases can be caught Co-Authored-By: Claude Opus 5.5 --- ...snapshot_ladder_c3kill_integration_test.go | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index b97305a71d..5e6afea3e9 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "fmt" + "math/rand" "testing" "time" ) @@ -47,6 +48,26 @@ func (env *handoffEnv) awaitRestorePhase(t *testing.T, target, what string, boun return restoreProgress{} } +// denseImage fills every block of the given chunks with incompressible +// bytes (seeded by tag and LBA), so that their chunks are full size in the +// store and a restore of them takes measurable time at the driver's rate. +func denseImage(tag string, chunks []uint64) map[uint64][]byte { + img := map[uint64][]byte{} + var seed int64 + for _, c := range tag { + seed = seed*31 + int64(c) + } + for _, c := range chunks { + for i := uint64(0); i < ladderChunkBlocks; i++ { + lba := c*ladderChunkBlocks + i + b := make([]byte, 4096) + rand.New(rand.NewSource(seed ^ int64(lba))).Read(b) + img[lba] = b + } + } + return img +} + // startTarget starts target's blockvolume and waits until it serves. func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { t.Helper() @@ -60,7 +81,8 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { } // TestSnapshotLadderC3KilledMidHydrateAndMidBatch: a restore of a snapshot -// of 48 written chunks into v2 (about 192 MiB to make local and re-upload). +// of 32 full chunks of incompressible data into v2 (128 MiB to make local +// and re-upload at the driver's 64 MiB/s). // Its blockvolume is killed (SIGKILL) while the driver is hydrating, started // again and the driver started again. While the driver then owns chunks, the // guest writes to v2 (acknowledged), and the blockvolume is killed again in @@ -72,10 +94,10 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { func TestSnapshotLadderC3KilledMidHydrateAndMidBatch(t *testing.T) { env := startLadderEnv(t, "v2", "v3") var chunks []uint64 - for c := uint64(0); c < 48; c++ { + for c := uint64(0); c < 32; c++ { chunks = append(chunks, c) } - src := ladderImage("c3ksrc", chunks, 2) + src := denseImage("c3ksrc", chunks) env.writeImage(t, "s1", src) env.snapshot(t, "s1", "v1", "base") From 0291522081ee9f7bc1ca3c53bf1a74ecab1df242 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 21:29:39 -0800 Subject: [PATCH 3/7] test: restore kill test triggers on the phase and its time, polls the status endpoint, keeps chunk 40 untouched Co-Authored-By: Claude Opus 5.5 --- ...snapshot_ladder_c3kill_integration_test.go | 104 ++++++++++++------ 1 file changed, 71 insertions(+), 33 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index 5e6afea3e9..29d262bb5d 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -3,10 +3,11 @@ package main_test import ( - "context" "encoding/json" "fmt" + "io" "math/rand" + "net/http" "testing" "time" ) @@ -21,33 +22,67 @@ type restoreProgress struct { Batches int `json:"batches"` } -// awaitRestorePhase polls target's restore status every 50 ms until ok -// holds and returns that status; it fails the test if the restore failed, -// became independent first (the moment was missed), or bound passed. +// restoreStatus reads target's restore status straight from its status +// server (a GET answers the status without starting a run). +func (env *handoffEnv) restoreStatus(c *http.Client, target string) (restoreProgress, string, bool) { + resp, err := c.Get("http://" + env.hosts["n-"+target].status + "/chunk/restore?volume=" + target) + if err != nil { + return restoreProgress{}, "", false + } + b, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) + resp.Body.Close() + var st restoreProgress + if resp.StatusCode != http.StatusOK || json.Unmarshal(b, &st) != nil { + return restoreProgress{}, string(b), false + } + return st, string(b), true +} + +// awaitRestorePhase polls target's restore status every 10 ms until ok +// holds and returns that status, logging each change with when it was seen +// (the record of where a kill landed). It fails the test if the restore +// failed, became independent first (the moment was missed), or bound passed. +// The driver's counters (filled, owned, foreign) are written when a step +// ends, not while it runs: a moment inside a step is chosen by the phase and +// the time spent in it, not by a counter. func (env *handoffEnv) awaitRestorePhase(t *testing.T, target, what string, bound time.Duration, ok func(restoreProgress) bool) restoreProgress { t.Helper() - end := time.Now().Add(bound) - ctx, cancel := context.WithDeadline(context.Background(), end) - defer cancel() - for time.Now().Before(end) { - out, _, code, err := runCLI(ctx, env.h, "ops", "chunk", "restore", "--volume", target, "--status-addr", env.hosts["n-"+target].status, "--status") - var st restoreProgress - if err == nil && code == 0 && json.Unmarshal([]byte(out), &st) == nil { + c := &http.Client{Timeout: 2 * time.Second} + began := time.Now() + last := restoreProgress{Phase: "-"} + for time.Since(began) < bound { + if st, raw, good := env.restoreStatus(c, target); good { + if st != last { + t.Logf("restore of %s at +%v (waiting for %s): %+v", target, time.Since(began).Round(time.Millisecond), what, st) + last = st + } switch { case ok(st): return st case st.Phase == "failed": - t.Fatalf("restore of %s failed waiting for %s: %s", target, what, out) + t.Fatalf("restore of %s failed waiting for %s: %s", target, what, raw) case st.Phase == "independent": - t.Fatalf("restore of %s became independent before %s was seen (the restore is too small to catch it): %s", target, what, out) + t.Fatalf("restore of %s became independent before %s was seen (the restore is too small to catch it): %s", target, what, raw) } } - time.Sleep(50 * time.Millisecond) + time.Sleep(10 * time.Millisecond) } t.Fatalf("restore of %s: %s not seen within %v", target, what, bound) return restoreProgress{} } +// requireRestoreState reads target's restore status once and fails the test +// unless the run is still going and ok holds: the check, right before a +// kill, that the kill lands where the test says. +func (env *handoffEnv) requireRestoreState(t *testing.T, target, what string, ok func(restoreProgress) bool) restoreProgress { + t.Helper() + st, raw, good := env.restoreStatus(&http.Client{Timeout: 2 * time.Second}, target) + if !good || !st.Running || !ok(st) { + t.Fatalf("restore of %s is no longer %s before the kill: %s", target, what, raw) + } + return st +} + // denseImage fills every block of the given chunks with incompressible // bytes (seeded by tag and LBA), so that their chunks are full size in the // store and a restore of them takes measurable time at the driver's rate. @@ -81,13 +116,17 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { } // TestSnapshotLadderC3KilledMidHydrateAndMidBatch: a restore of a snapshot -// of 32 full chunks of incompressible data into v2 (128 MiB to make local -// and re-upload at the driver's 64 MiB/s). -// Its blockvolume is killed (SIGKILL) while the driver is hydrating, started -// again and the driver started again. While the driver then owns chunks, the -// guest writes to v2 (acknowledged), and the blockvolume is killed again in -// the middle of the batch, restarted, and the driver started again; the -// guest writes once more. The driver resumes from the target's remote facts +// of 32 full chunks of incompressible data into v2 (128 MiB to make local at +// the driver's 64 MiB/s: about 2 s of hydrating). Its blockvolume is killed +// (SIGKILL) one second into hydrating (about half the chunks local, by the +// pace), started again and the driver started again; nothing is read in +// between, so the restart finds the chunks the walker had not reached still +// remote. When the walker has made every chunk local and the first batch cut +// (Hydrating>Owning, one batch for 32 chunks) is running, which the status +// shows as running with every chunk filled and no batch done, the guest +// writes to v2 (acknowledged) and, the batch still running, the blockvolume +// is killed again, restarted, and the driver started again; the guest writes +// once more. The driver resumes from the target's remote facts // to independence (per its status). Then v2 holds the snapshot with every // acknowledged write over it, and the source's snapshot, restored again // into v3, is unchanged (none of v2's writes in it). @@ -110,29 +149,28 @@ func TestSnapshotLadderC3KilledMidHydrateAndMidBatch(t *testing.T) { } drive() - // Killed while hydrating: some chunks local, not all. - st := env.awaitRestorePhase(t, "v2", "hydrating with part of the chunks local", 120*time.Second, func(s restoreProgress) bool { - return s.Phase == "hydrating" && s.Filled > 0 && s.Filled < len(chunks) - }) + // Killed one second into hydrating: by the pace, about half the chunks + // are local. + env.awaitRestorePhase(t, "v2", "hydrating", 120*time.Second, func(s restoreProgress) bool { return s.Phase == "hydrating" }) + time.Sleep(time.Second) + st := env.requireRestoreState(t, "v2", "hydrating", func(s restoreProgress) bool { return s.Phase == "hydrating" }) target.kill(t) - t.Logf("killed while hydrating: %+v", st) + t.Logf("killed 1 s into hydrating: %+v", st) target = env.startTarget(t, "v2", "blockvolume-v2-after-hydrate-kill") - env.requireImage(t, "n-v2", src) // serves the snapshot at once after the restart drive() // Written while owning, then killed in the middle of the batch. - env.awaitRestorePhase(t, "v2", "owning", 180*time.Second, func(s restoreProgress) bool { return s.Phase == "owning" }) + inBatch := func(s restoreProgress) bool { return s.Filled == len(chunks) && s.Batches == 0 && s.Phase != "independent" } + env.awaitRestorePhase(t, "v2", "the first batch cut running", 180*time.Second, func(s restoreProgress) bool { return s.Running && inBatch(s) }) w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) env.writeImage(t, "n-v2", w1) - st = env.awaitRestorePhase(t, "v2", "owning with chunks still foreign", 180*time.Second, func(s restoreProgress) bool { - return s.Phase == "owning" && s.Foreign > 0 - }) + st = env.requireRestoreState(t, "v2", "in its first batch cut", inBatch) target.kill(t) - t.Logf("killed while owning: %+v", st) + t.Logf("killed in the first batch cut, after the write: %+v", st) target = env.startTarget(t, "v2", "blockvolume-v2-after-batch-kill") env.requireImage(t, "n-v2", mergeImages(src, w1)) // every acknowledged write survived the kill drive() - w2 := ladderImage("c3kw2", []uint64{17, 40, 60}, 2) + w2 := ladderImage("c3kw2", []uint64{17, 44, 60}, 2) // not chunk 40: requireEdges keeps it untouched env.writeImage(t, "n-v2", w2) env.waitIndependent(t, "v2") From f58a1e261f224b7b2457343da4952bd8e30de3b9 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 21:29:49 -0800 Subject: [PATCH 4/7] test: gofmt Co-Authored-By: Claude Opus 5.5 --- .../blockvolume/snapshot_ladder_c3kill_integration_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index 29d262bb5d..4370316a68 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -160,7 +160,9 @@ func TestSnapshotLadderC3KilledMidHydrateAndMidBatch(t *testing.T) { drive() // Written while owning, then killed in the middle of the batch. - inBatch := func(s restoreProgress) bool { return s.Filled == len(chunks) && s.Batches == 0 && s.Phase != "independent" } + inBatch := func(s restoreProgress) bool { + return s.Filled == len(chunks) && s.Batches == 0 && s.Phase != "independent" + } env.awaitRestorePhase(t, "v2", "the first batch cut running", 180*time.Second, func(s restoreProgress) bool { return s.Running && inBatch(s) }) w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) env.writeImage(t, "n-v2", w1) From e536e100db9cdd570891aede980201ab6e35b1c0 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 21:34:56 -0800 Subject: [PATCH 5/7] test: restore kill test claims what its kills show: hydrating, and after hydration before independence; read back after the first restart Co-Authored-By: Claude Opus 5.5 --- ...snapshot_ladder_c3kill_integration_test.go | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index 4370316a68..6345de3af7 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -115,22 +115,26 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { return d } -// TestSnapshotLadderC3KilledMidHydrateAndMidBatch: a restore of a snapshot -// of 32 full chunks of incompressible data into v2 (128 MiB to make local at -// the driver's 64 MiB/s: about 2 s of hydrating). Its blockvolume is killed -// (SIGKILL) one second into hydrating (about half the chunks local, by the -// pace), started again and the driver started again; nothing is read in -// between, so the restart finds the chunks the walker had not reached still -// remote. When the walker has made every chunk local and the first batch cut -// (Hydrating>Owning, one batch for 32 chunks) is running, which the status -// shows as running with every chunk filled and no batch done, the guest -// writes to v2 (acknowledged) and, the batch still running, the blockvolume -// is killed again, restarted, and the driver started again; the guest writes -// once more. The driver resumes from the target's remote facts -// to independence (per its status). Then v2 holds the snapshot with every -// acknowledged write over it, and the source's snapshot, restored again -// into v3, is unchanged (none of v2's writes in it). -func TestSnapshotLadderC3KilledMidHydrateAndMidBatch(t *testing.T) { +// TestSnapshotLadderC3KilledHydratingAndBeforeIndependence: a restore of a +// snapshot of 32 full chunks of incompressible data into v2 (128 MiB to make +// local at the driver's 64 MiB/s: about 2 s of hydrating). Its blockvolume +// is killed (SIGKILL) one second into hydrating, started again, and read +// back in full (a partly filled chunk must never be served), and the driver +// is started again. When the status then shows every chunk filled and no +// batch done, still running and not independent (after hydration completed, +// before independence), the guest writes to v2 (acknowledged) and the +// blockvolume is killed again, restarted (every acknowledged write reads +// back), and the driver started again; the guest writes once more. The +// driver resumes from the target's remote facts to independence (per its +// status). Then v2 holds the snapshot with every acknowledged write over it, +// and the source's snapshot, restored again into v3, is unchanged (none of +// v2's writes in it). +// +// Not covered: guest writes while the driver reports Owning. With one batch +// (32 chunks, under the 64-chunk batch) the status goes from hydrating to +// independent without ever showing owning, so the second kill is only known +// to land after hydration completed and before independence. +func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { env := startLadderEnv(t, "v2", "v3") var chunks []uint64 for c := uint64(0); c < 32; c++ { @@ -149,26 +153,26 @@ func TestSnapshotLadderC3KilledMidHydrateAndMidBatch(t *testing.T) { } drive() - // Killed one second into hydrating: by the pace, about half the chunks - // are local. + // Killed one second into hydrating. env.awaitRestorePhase(t, "v2", "hydrating", 120*time.Second, func(s restoreProgress) bool { return s.Phase == "hydrating" }) time.Sleep(time.Second) st := env.requireRestoreState(t, "v2", "hydrating", func(s restoreProgress) bool { return s.Phase == "hydrating" }) target.kill(t) t.Logf("killed 1 s into hydrating: %+v", st) target = env.startTarget(t, "v2", "blockvolume-v2-after-hydrate-kill") + env.requireImage(t, "n-v2", src) // serves the snapshot, no partly filled chunk drive() - // Written while owning, then killed in the middle of the batch. - inBatch := func(s restoreProgress) bool { + // Written after hydration completed and before independence, then killed. + afterFill := func(s restoreProgress) bool { return s.Filled == len(chunks) && s.Batches == 0 && s.Phase != "independent" } - env.awaitRestorePhase(t, "v2", "the first batch cut running", 180*time.Second, func(s restoreProgress) bool { return s.Running && inBatch(s) }) + env.awaitRestorePhase(t, "v2", "hydration completed, not independent", 180*time.Second, func(s restoreProgress) bool { return s.Running && afterFill(s) }) w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) env.writeImage(t, "n-v2", w1) - st = env.requireRestoreState(t, "v2", "in its first batch cut", inBatch) + st = env.requireRestoreState(t, "v2", "after hydration and before independence", afterFill) target.kill(t) - t.Logf("killed in the first batch cut, after the write: %+v", st) + t.Logf("killed after hydration completed and before independence, after the write: %+v", st) target = env.startTarget(t, "v2", "blockvolume-v2-after-batch-kill") env.requireImage(t, "n-v2", mergeImages(src, w1)) // every acknowledged write survived the kill drive() From d393d93c4c0eba85502c14c198ebcfde2ecb39f1 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 21:40:39 -0800 Subject: [PATCH 6/7] test: restore kill test kills inside the resumed run, every chunk local, before independence Co-Authored-By: Claude Opus 5.5 --- ...snapshot_ladder_c3kill_integration_test.go | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index 6345de3af7..bb7dbbccd6 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -120,20 +120,22 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { // local at the driver's 64 MiB/s: about 2 s of hydrating). Its blockvolume // is killed (SIGKILL) one second into hydrating, started again, and read // back in full (a partly filled chunk must never be served), and the driver -// is started again. When the status then shows every chunk filled and no -// batch done, still running and not independent (after hydration completed, -// before independence), the guest writes to v2 (acknowledged) and the -// blockvolume is killed again, restarted (every acknowledged write reads +// is started again: the read-back has made every chunk local, so the +// resumed run has nothing left to fill (its status then reports filled 0) +// and spends its time re-uploading the chunks under v2's own keys. 150 ms +// into that run, still running and not independent, the guest writes to v2 +// (acknowledged) and, the run checked still running and not independent, +// the blockvolume is killed again, restarted (every acknowledged write reads // back), and the driver started again; the guest writes once more. The // driver resumes from the target's remote facts to independence (per its // status). Then v2 holds the snapshot with every acknowledged write over it, // and the source's snapshot, restored again into v3, is unchanged (none of // v2's writes in it). // -// Not covered: guest writes while the driver reports Owning. With one batch -// (32 chunks, under the 64-chunk batch) the status goes from hydrating to -// independent without ever showing owning, so the second kill is only known -// to land after hydration completed and before independence. +// Not covered: guest writes while the driver reports Owning. The status +// shows owning only once the single batch (32 chunks, under the 64-chunk +// batch) has ended, a few ms before independent, so the second kill is only +// known to land in the resumed run, every chunk local, before independence. func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { env := startLadderEnv(t, "v2", "v3") var chunks []uint64 @@ -163,16 +165,18 @@ func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { env.requireImage(t, "n-v2", src) // serves the snapshot, no partly filled chunk drive() - // Written after hydration completed and before independence, then killed. - afterFill := func(s restoreProgress) bool { - return s.Filled == len(chunks) && s.Batches == 0 && s.Phase != "independent" - } - env.awaitRestorePhase(t, "v2", "hydration completed, not independent", 180*time.Second, func(s restoreProgress) bool { return s.Running && afterFill(s) }) + // In the resumed run, every chunk local, before independence: written, + // then killed. + notDone := func(s restoreProgress) bool { return s.Phase != "independent" } + resumed := time.Now() + env.awaitRestorePhase(t, "v2", "the resumed run", 30*time.Second, func(s restoreProgress) bool { return s.Running && notDone(s) }) + time.Sleep(time.Until(resumed.Add(150 * time.Millisecond))) + env.requireRestoreState(t, "v2", "running and not independent", notDone) w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) env.writeImage(t, "n-v2", w1) - st = env.requireRestoreState(t, "v2", "after hydration and before independence", afterFill) + st = env.requireRestoreState(t, "v2", "running and not independent", notDone) target.kill(t) - t.Logf("killed after hydration completed and before independence, after the write: %+v", st) + t.Logf("killed %v into the resumed run, after the write: %+v", time.Since(resumed).Round(time.Millisecond), st) target = env.startTarget(t, "v2", "blockvolume-v2-after-batch-kill") env.requireImage(t, "n-v2", mergeImages(src, w1)) // every acknowledged write survived the kill drive() From 2e4d4d112bb0f7467140846c077bdf901cb4c863 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 22:01:09 -0800 Subject: [PATCH 7/7] test: restore kill test resumes from a partly local volume (subset read-back, 0 < filled < 32), checks the marker before and after Co-Authored-By: Claude Opus 5.5 --- ...snapshot_ladder_c3kill_integration_test.go | 117 ++++++++++++++---- 1 file changed, 92 insertions(+), 25 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index bb7dbbccd6..113bdad1a3 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -8,6 +8,7 @@ import ( "io" "math/rand" "net/http" + "path" "testing" "time" ) @@ -83,6 +84,19 @@ func (env *handoffEnv) requireRestoreState(t *testing.T, target, what string, ok return st } +// requireBlocksOf reads every block of img on the host and requires each to +// equal img (whole 4 KiB blocks compared byte for byte). +func (env *handoffEnv) requireBlocksOf(t *testing.T, hostID string, img map[uint64][]byte) { + t.Helper() + c := dialNVMe(t, env.hosts[hostID].nvme, plannedHandoffNQN) + defer c.close() + for lba, want := range img { + if got := c.read(t, lba, 4096); string(got) != string(want) { + t.Fatalf("%s: block %d differs from what was written", hostID, lba) + } + } +} + // denseImage fills every block of the given chunks with incompressible // bytes (seeded by tag and LBA), so that their chunks are full size in the // store and a restore of them takes measurable time at the driver's rate. @@ -103,6 +117,44 @@ func denseImage(tag string, chunks []uint64) map[uint64][]byte { return img } +// independent reports whether target's independence marker exists, read +// from the filer (not through the product's status, which reports only a +// run of this process). +func (env *handoffEnv) independent(t *testing.T, target string) bool { + t.Helper() + c := &http.Client{Timeout: 10 * time.Second} + p := path.Join(env.chunkPath, target, "RESTORE-INDEPENDENT") + resp, err := c.Get("http://" + env.cluster.filerHTTP + p + "?metadata=true") + if err != nil { + t.Fatal(err) + } + io.Copy(io.Discard, resp.Body) + resp.Body.Close() + switch resp.StatusCode { + case http.StatusOK: + return true + case http.StatusNotFound: + return false + } + t.Fatalf("filer lookup of %s: status %d", p, resp.StatusCode) + return false +} + +// subsetOf returns the blocks of img in the given chunks. +func subsetOf(img map[uint64][]byte, chunks []uint64) map[uint64][]byte { + in := map[uint64]bool{} + for _, c := range chunks { + in[c] = true + } + out := map[uint64][]byte{} + for lba, b := range img { + if in[lba/ladderChunkBlocks] { + out[lba] = b + } + } + return out +} + // startTarget starts target's blockvolume and waits until it serves. func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { t.Helper() @@ -117,25 +169,28 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { // TestSnapshotLadderC3KilledHydratingAndBeforeIndependence: a restore of a // snapshot of 32 full chunks of incompressible data into v2 (128 MiB to make -// local at the driver's 64 MiB/s: about 2 s of hydrating). Its blockvolume -// is killed (SIGKILL) one second into hydrating, started again, and read -// back in full (a partly filled chunk must never be served), and the driver -// is started again: the read-back has made every chunk local, so the -// resumed run has nothing left to fill (its status then reports filled 0) -// and spends its time re-uploading the chunks under v2's own keys. 150 ms -// into that run, still running and not independent, the guest writes to v2 -// (acknowledged) and, the run checked still running and not independent, -// the blockvolume is killed again, restarted (every acknowledged write reads -// back), and the driver started again; the guest writes once more. The -// driver resumes from the target's remote facts to independence (per its -// status). Then v2 holds the snapshot with every acknowledged write over it, -// and the source's snapshot, restored again into v3, is unchanged (none of -// v2's writes in it). +// local at the driver's 64 MiB/s: about 2 s of hydrating). +// +// 1. Its blockvolume is killed (SIGKILL) one second into hydrating and +// started again. Every other chunk is read back (a partly filled chunk +// must never be served), which makes those chunks local and leaves the +// rest to the driver, and the driver is started again. +// 2. The resumed run must report, when its hydrating step ends, that it +// filled some chunks and not all (0 < filled < 32: it resumed from a +// partly local volume). Then, the run still going and not independent, +// the guest writes to v2 (acknowledged); checked still running and not +// independent, the blockvolume is killed again and restarted. Before the +// driver is started again the independence marker must be absent (the +// kill landed before independence); every acknowledged write reads back. +// 3. The driver is started again, the guest writes once more, and the run +// reaches independence (per its status and the marker). Then v2 holds +// the snapshot with every acknowledged write over it, read back in full, +// and the source's snapshot, restored again into v3, is unchanged (none +// of v2's writes in it). // // Not covered: guest writes while the driver reports Owning. The status // shows owning only once the single batch (32 chunks, under the 64-chunk -// batch) has ended, a few ms before independent, so the second kill is only -// known to land in the resumed run, every chunk local, before independence. +// batch) has ended, a few ms before independent. func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { env := startLadderEnv(t, "v2", "v3") var chunks []uint64 @@ -162,28 +217,40 @@ func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { target.kill(t) t.Logf("killed 1 s into hydrating: %+v", st) target = env.startTarget(t, "v2", "blockvolume-v2-after-hydrate-kill") - env.requireImage(t, "n-v2", src) // serves the snapshot, no partly filled chunk + var even []uint64 + for c := uint64(0); c < 32; c += 2 { + even = append(even, c) + } + env.requireBlocksOf(t, "n-v2", subsetOf(src, even)) // no partly filled chunk is served drive() - // In the resumed run, every chunk local, before independence: written, - // then killed. + // The resumed run: it fills what is not local yet; then, before + // independence, written and killed. notDone := func(s restoreProgress) bool { return s.Phase != "independent" } - resumed := time.Now() - env.awaitRestorePhase(t, "v2", "the resumed run", 30*time.Second, func(s restoreProgress) bool { return s.Running && notDone(s) }) - time.Sleep(time.Until(resumed.Add(150 * time.Millisecond))) - env.requireRestoreState(t, "v2", "running and not independent", notDone) + st = env.awaitRestorePhase(t, "v2", "the resumed run's hydrating step ended", 60*time.Second, func(s restoreProgress) bool { + return s.Running && s.Filled > 0 && notDone(s) + }) + if st.Filled >= len(chunks) { + t.Fatalf("the resumed run filled %d chunks: it did not resume from a partly local volume (%d read back before it)", st.Filled, len(even)) + } w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) env.writeImage(t, "n-v2", w1) st = env.requireRestoreState(t, "v2", "running and not independent", notDone) target.kill(t) - t.Logf("killed %v into the resumed run, after the write: %+v", time.Since(resumed).Round(time.Millisecond), st) + t.Logf("killed in the resumed run after it filled %d of %d chunks, after the write: %+v", st.Filled, len(chunks), st) target = env.startTarget(t, "v2", "blockvolume-v2-after-batch-kill") - env.requireImage(t, "n-v2", mergeImages(src, w1)) // every acknowledged write survived the kill + if env.independent(t, "v2") { + t.Fatal("the independence marker exists after the second kill: the kill did not land before independence") + } + env.requireBlocksOf(t, "n-v2", w1) // every acknowledged write survived the kill drive() w2 := ladderImage("c3kw2", []uint64{17, 44, 60}, 2) // not chunk 40: requireEdges keeps it untouched env.writeImage(t, "n-v2", w2) env.waitIndependent(t, "v2") + if !env.independent(t, "v2") { + t.Fatal("the restore status says independent but the marker is absent") + } env.requireImage(t, "n-v2", mergeImages(src, w1, w2)) env.restoreChecked(t, "base", "v3", src, w1, w2) }