From f7c329672b21c28b7a51983bdd75e7448c6c7995 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:16:37 -0800 Subject: [PATCH 1/7] test: kill -9 with guest I/O in flight, restart, read back every acked block Single-volume coverage gap 1, cell A2.4 (V1-SPEC r2.55): a qd1 NVMe/TCP writer streams distinct blocks with a Flush every 8 writes; the holder is SIGKILLed mid-stream and restarted inside the lease at the same epoch; every Flush-acknowledged write must read back, and what survives past the last acknowledged Flush must be a prefix of the stream, untorn. Co-Authored-By: Claude Opus 5.5 --- .../procedure_crash_io_integration_test.go | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go new file mode 100644 index 0000000000..3314be24f8 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -0,0 +1,144 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "bytes" + "fmt" + "sync" + "testing" + "time" +) + +// Single-volume coverage, gap 1 (cell A2.4, V1-SPEC r2.55): kill -9 of the +// holder WITH guest I/O in flight, then a restart inside the lease. Every +// write a Flush acknowledged must read back after the restart +// (INV-WAL-SYNCED-RECOVERED-001); writes not yet acknowledged by a Flush may +// vanish, but what is left of them must be a prefix of the stream in LBA +// order with nothing torn or invented (the writer writes LBAs in order). +// +// The writer is the guest: qd1 NVMe/TCP writes of distinct blocks, a Flush +// every crashIOFlushEvery writes; it records the last LBA a successful +// Flush covered. The holder is killed while the writer is mid-stream. + +const ( + crashIOBase = 2048 // first LBA the writer uses (chunk 2) + crashIOSpan = 40000 + crashIOFlushEvery = 8 +) + +func crashIOBlock(lba uint64) []byte { + s := fmt.Sprintf("crash-io lba %08d|", lba) + b := make([]byte, 4096) + for i := range b { + b[i] = s[i%len(s)] + } + return b +} + +// crashIOWriter writes LBAs crashIOBase.. in order until stopped or an I/O +// fails, and reports how far the Flush acknowledgements reached. +type crashIOWriter struct { + mu sync.Mutex + written int // writes completed (acknowledged by the write itself) + flushed int // writes covered by an acknowledged Flush + err error + done chan struct{} +} + +func startCrashIOWriter(t *testing.T, env *handoffEnv, id string) *crashIOWriter { + t.Helper() + w := &crashIOWriter{done: make(chan struct{})} + c := dialNVMe(t, env.hosts[id].nvme, plannedHandoffNQN) + go func() { + defer close(w.done) + defer c.close() + for n := 0; n < crashIOSpan; n++ { + lba := crashIOBase + uint64(n) + err := c.tryWrite(lba, crashIOBlock(lba)) + if err == nil && n%crashIOFlushEvery == crashIOFlushEvery-1 { + err = c.tryFlush() + if err == nil { + w.mu.Lock() + w.flushed = n + 1 + w.mu.Unlock() + } + } + w.mu.Lock() + if err != nil { + w.err = err + } else { + w.written = n + 1 + } + w.mu.Unlock() + if err != nil { + return + } + } + }() + return w +} + +func (w *crashIOWriter) counts() (written, flushed int, err error) { + w.mu.Lock() + defer w.mu.Unlock() + return w.written, w.flushed, w.err +} + +func TestProcedureCrashWithIOInFlight(t *testing.T) { + env := startHandoffEnv(t, 1) + first := env.start(t, "blockvolume-s1", "s1") + e := env.adopt(t, first, "s1") + + w := startCrashIOWriter(t, env, "s1") + // Let the stream run until a good number of Flushes acknowledged, so the + // kill lands mid-stream with writes in flight. + poll(t, 60*time.Second, "the writer never got 2000 flushed writes", func() bool { + _, flushed, err := w.counts() + return flushed >= 2000 || err != nil + }) + if _, _, err := w.counts(); err != nil { + t.Fatalf("a write failed before the kill: %v", err) + } + first.kill(t) // SIGKILL while the writer is still writing + select { + case <-w.done: + case <-time.After(70 * time.Second): + t.Fatal("the writer did not stop after the holder was killed") + } + written, flushed, werr := w.counts() + if werr == nil { + t.Fatalf("the writer finished all %d writes before the kill: no I/O was in flight", crashIOSpan) + } + t.Logf("at the kill: %d writes completed, %d covered by an acknowledged Flush; the writer's error: %v", written, flushed, werr) + + again := env.start(t, "blockvolume-s1-again", "s1") + if got := env.adopt(t, again, "s1"); got != e { + t.Fatalf("the restarted holder adopted epoch %d; want %d", got, e) + } + + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + defer c.close() + zero := make([]byte, 4096) + for n := 0; n < flushed; n++ { + lba := crashIOBase + uint64(n) + if got := c.read(t, lba, 4096); !bytes.Equal(got, crashIOBlock(lba)) { + t.Fatalf("flush-acknowledged write %d (LBA %d) is lost or wrong after kill -9 and restart", n, lba) + } + } + // Past the Flush acknowledgements: a prefix of the stream, then zeros. + kept, ended := flushed, false + for n := flushed; n < written+crashIOFlushEvery && n < crashIOSpan; n++ { + lba := crashIOBase + uint64(n) + got := c.read(t, lba, 4096) + switch { + case !ended && bytes.Equal(got, crashIOBlock(lba)): + kept++ + case bytes.Equal(got, zero): + ended = true + default: + t.Fatalf("LBA %d after the last acknowledged Flush holds data out of the stream's order or torn (kept %d)", lba, kept) + } + } + t.Logf("after the restart: all %d flush-acknowledged writes read back; %d of the %d unflushed completed writes survived as a prefix", flushed, kept-flushed, written-flushed) +} From 013a9ac19c9d0def7954e177572cf3036bf163ae Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:17:50 -0800 Subject: [PATCH 2/7] test: kill -9 on a fresh root with fills in flight, restart, read back Single-volume coverage gap 1, cell A3.5 (V1-SPEC r2.55): after a clean move to s2 (fresh root, lazy hydration), a reader walks 60 chunks that only HEAD holds while a writer streams Flush-acknowledged writes into other chunks; s2 is SIGKILLed mid-walk and restarted at the same epoch; every source chunk must read back (fills redone) and every acknowledged write survive. Co-Authored-By: Claude Opus 5.5 --- .../procedure_crash_io_integration_test.go | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go index 3314be24f8..390fbaa8d1 100644 --- a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -8,6 +8,8 @@ import ( "sync" "testing" "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/nvme" ) // Single-volume coverage, gap 1 (cell A2.4, V1-SPEC r2.55): kill -9 of the @@ -142,3 +144,182 @@ func TestProcedureCrashWithIOInFlight(t *testing.T) { } t.Logf("after the restart: all %d flush-acknowledged writes read back; %d of the %d unflushed completed writes survived as a prefix", flushed, kept-flushed, written-flushed) } + +// Gap 1, cell A3.5: kill -9 of a holder serving on a FRESH root (after a +// clean move) while chunk fills from HEAD are in flight. s1 writes one block +// in each of the first fillChunks chunks; after the hand-over, s2 starts +// with no local copy. A reader walks those chunks (each read misses and +// fills) while a writer streams Flush-acknowledged writes into chunks s1 +// never wrote; s2 is SIGKILLed mid-walk and restarted. Every s1 block must +// read back (the fills are redone from HEAD) and every acknowledged s2 write +// must survive. +const ( + fillChunks = 60 + fillWriterBase = 60 * ladderChunkBlocks + fillWriterSpan = 4 * ladderChunkBlocks + fillFlushEvery = 8 +) + +func fillSourceBlock(c int) []byte { + s := fmt.Sprintf("fill-src chunk %03d|", c) + b := make([]byte, 4096) + for i := range b { + b[i] = s[i%len(s)] + } + return b +} + +func TestProcedureCrashOnAFreshRootWithFillsInFlight(t *testing.T) { + env := startHandoffEnv(t, 2) + must, mustU := fatalOn(t) + h := env.h + + old := env.start(t, "blockvolume-s1", "s1") + e := env.adopt(t, old, "s1") + for c := 0; c < fillChunks; c++ { + env.writeBlock(t, "s1", uint64(c*ladderChunkBlocks), fillSourceBlock(c)) + } + g := env.seal(t, "s1", e) + l := env.sealedLSN(t, e, g) + env.revoke(t, e, g) + if err := old.wait(30 * time.Second); err != nil { + t.Fatalf("s1 after the revocation: %v", err) + } + env.waitAck(t, e, g) + moved, _ := h.command(t, env.moveClean(e, "s2", "move-fill-1")...) + e2 := mustU(movedEpochTo(moved, e, g, l, "s2")) + nw := env.start(t, "blockvolume-s2", "s2") + must(checkClaimDoneBy(nw.waitLog(t, 60*time.Second, "durable: HEAD claim for volume=v1 done in"), e2, "s2")) + if got := env.adopt(t, nw, "s2"); got != e2 { + t.Fatalf("s2 adopted at epoch %d; want %d", got, e2) + } + + // The reader: read misses fill each source chunk from HEAD. + var rmu sync.Mutex + reads, readErr := 0, error(nil) + readerDone := make(chan struct{}) + rc := dialNVMe(t, env.hosts["s2"].nvme, plannedHandoffNQN) + go func() { + defer close(readerDone) + defer rc.close() + for c := 0; c < fillChunks; c++ { + _, err := rc.tryRead(uint64(c*ladderChunkBlocks), 4096) + rmu.Lock() + if err != nil { + readErr = err + rmu.Unlock() + return + } + reads = c + 1 + rmu.Unlock() + } + }() + // The writer: acknowledged local writes into chunks s1 never wrote. + var wmu sync.Mutex + written, flushed := 0, 0 + writerDone := make(chan struct{}) + wc := dialNVMe(t, env.hosts["s2"].nvme, plannedHandoffNQN) + go func() { + defer close(writerDone) + defer wc.close() + for n := 0; n < fillWriterSpan; n++ { + lba := uint64(fillWriterBase + n) + err := wc.tryWrite(lba, crashIOBlock(lba)) + if err == nil && n%fillFlushEvery == fillFlushEvery-1 { + if err = wc.tryFlush(); err == nil { + wmu.Lock() + flushed = n + 1 + wmu.Unlock() + } + } + if err != nil { + return + } + wmu.Lock() + written = n + 1 + wmu.Unlock() + } + }() + poll(t, 60*time.Second, "s2 never got its first fills and acknowledged writes", func() bool { + rmu.Lock() + r := reads + rmu.Unlock() + wmu.Lock() + f := flushed + wmu.Unlock() + return r >= 3 && f >= 64 + }) + nw.kill(t) // SIGKILL with fills and writes in flight + <-readerDone + <-writerDone + rmu.Lock() + readsAtKill, rerr := reads, readErr + rmu.Unlock() + wmu.Lock() + writtenAtKill, flushedAtKill := written, flushed + wmu.Unlock() + if readsAtKill >= fillChunks { + t.Fatalf("the reader finished all %d fills before the kill: no fill was in flight", fillChunks) + } + t.Logf("at the kill: %d of %d source chunks read (filled), reader error %v; %d writes completed, %d covered by a Flush", readsAtKill, fillChunks, rerr, writtenAtKill, flushedAtKill) + + again := env.start(t, "blockvolume-s2-again", "s2") + if got := env.adopt(t, again, "s2"); got != e2 { + t.Fatalf("the restarted s2 adopted epoch %d; want %d", got, e2) + } + c := dialNVMe(t, env.hosts["s2"].nvme, plannedHandoffNQN) + defer c.close() + for k := 0; k < fillChunks; k++ { + if got := c.read(t, uint64(k*ladderChunkBlocks), 4096); !bytes.Equal(got, fillSourceBlock(k)) { + t.Fatalf("source chunk %d (filled before the kill: %t) does not read back after the restart", k, k < readsAtKill) + } + } + for n := 0; n < flushedAtKill; n++ { + lba := uint64(fillWriterBase + n) + if got := c.read(t, lba, 4096); !bytes.Equal(got, crashIOBlock(lba)) { + t.Fatalf("flush-acknowledged write %d (LBA %d) on the fresh root is lost after kill -9 and restart", n, lba) + } + } + t.Logf("after the restart: all %d source chunks and all %d flush-acknowledged writes read back", fillChunks, flushedAtKill) +} + +// tryRead is read returning the error (for readers off the test goroutine). +func (c *nvmeInitiator) tryRead(lba uint64, n int) ([]byte, error) { + cmd := c.ioCmd(0x02, lba, n/4096) + if err := c.w.SendHeaderOnly(0x4, &cmd, 64); err != nil { + return nil, fmt.Errorf("nvme Read: %w", err) + } + var data []byte + for { + ch, err := c.r.Dequeue() + if err != nil { + return nil, fmt.Errorf("nvme Read: %w", err) + } + if ch.Type == 0x5 { + var resp nvme.CapsuleResponse + if err := c.r.Receive(&resp); err != nil { + return nil, fmt.Errorf("nvme Read response: %w", err) + } + if resp.Status != 0 { + return nil, fmt.Errorf("nvme Read status 0x%04x", resp.Status) + } + break + } + if ch.Type != 0x7 { + return nil, fmt.Errorf("nvme Read: unexpected PDU type 0x%x", ch.Type) + } + var dh nvme.C2HDataHeader + if err := c.r.Receive(&dh); err != nil { + return nil, fmt.Errorf("nvme C2HData: %w", err) + } + part := make([]byte, c.r.Length()) + if err := c.r.ReceiveData(part); err != nil { + return nil, fmt.Errorf("nvme C2HData payload: %w", err) + } + data = append(data, part...) + } + if len(data) != n { + return nil, fmt.Errorf("nvme Read returned %d bytes; want %d", len(data), n) + } + return data, nil +} From 78517f7b34f2424089cc90ea7b3ac8f5b000ec78 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:24:37 -0800 Subject: [PATCH 3/7] test: kill -9 mid-cut at each stage, restart, next cut publishes the volume Single-volume coverage gap 2, unit part (cells P5.4, P6.4, P8.7, P9.4, P10.4, P11.3; V1-SPEC r2.55): a cut dies after admission, at the barrier, during the upload, before the HEAD CAS and after the CAS applied (before its reply). The process death closes the store without cleanup and loses every later remote call. After the restart HEAD is whole (old before the CAS, new after it), every synced local write reads back, and the next cut publishes the volume as it is. Co-Authored-By: Claude Opus 5.5 --- .../core/storage/chunk_cut_crash_test.go | 240 ++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 seaweed-block/core/storage/chunk_cut_crash_test.go diff --git a/seaweed-block/core/storage/chunk_cut_crash_test.go b/seaweed-block/core/storage/chunk_cut_crash_test.go new file mode 100644 index 0000000000..3567df0a07 --- /dev/null +++ b/seaweed-block/core/storage/chunk_cut_crash_test.go @@ -0,0 +1,240 @@ +package storage + +import ( + "bytes" + "context" + "errors" + "sync" + "testing" +) + +// Single-volume coverage gap 2 (cells P5.4, P6.4, P8.7, P9.4, P10.4, P11.3; +// V1-SPEC r2.55): the holder dies (kill -9) in the middle of a cut, at each +// stage, and restarts. Expected: HEAD is the old image (or, once the CAS +// applied, the new one), never a mix; every synced local write reads back +// after the restart; the next cut succeeds and publishes the volume as it +// is. The crash is modelled as a process death: the store's file is closed +// without any cleanup and every later remote mutation from the dead +// process is lost (crashRemote), so the remote keeps exactly what the dead +// cut had sent. + +var errProcessDead = errors.New("injected: the process is dead") + +// crashRemote forwards to the fake until killed; after that every remote +// call of the dead process fails without reaching the fake: a dead process +// neither writes nor reads. +type crashRemote struct { + *fakeChunkRemote + mu sync.Mutex + dead bool + puts int + onPut func(n int) // after the n-th successful Put + onCAS func(applied bool) + casSeen bool + beforeCAS bool // kill before the CAS is sent +} + +func (r *crashRemote) isDead() bool { r.mu.Lock(); defer r.mu.Unlock(); return r.dead } + +func (r *crashRemote) kill() { r.mu.Lock(); r.dead = true; r.mu.Unlock() } + +func (r *crashRemote) Put(ctx context.Context, key string, data []byte) error { + if r.isDead() { + return errProcessDead + } + if err := r.fakeChunkRemote.Put(ctx, key, data); err != nil { + return err + } + r.mu.Lock() + r.puts++ + n, hook := r.puts, r.onPut + r.mu.Unlock() + if hook != nil { + hook(n) + } + return nil +} + +func (r *crashRemote) CASHead(ctx context.Context, expected chunkHeadVersion, next chunkHead) (uint64, error) { + if r.isDead() { + return 0, errProcessDead + } + r.mu.Lock() + before, hook := r.beforeCAS, r.onCAS + r.mu.Unlock() + if before && hook != nil { + hook(false) + return 0, errProcessDead + } + gen, err := r.fakeChunkRemote.CASHead(ctx, expected, next) + if err == nil && hook != nil { + hook(true) + return 0, errProcessDead // the reply never reaches the dead process + } + return gen, err +} + +func (r *crashRemote) Delete(ctx context.Context, key string) error { + if r.isDead() { + return errProcessDead + } + return r.fakeChunkRemote.Delete(ctx, key) +} + +func (r *crashRemote) PutIntent(ctx context.Context, in chunkIntent) (string, error) { + if r.isDead() { + return "", errProcessDead + } + return r.fakeChunkRemote.PutIntent(ctx, in) +} + +func (r *crashRemote) Get(ctx context.Context, key string) ([]byte, error) { + if r.isDead() { + return nil, errProcessDead + } + return r.fakeChunkRemote.Get(ctx, key) +} + +func (r *crashRemote) GetHead(ctx context.Context) (chunkHead, error) { + if r.isDead() { + return chunkHead{}, errProcessDead + } + return r.fakeChunkRemote.GetHead(ctx) +} + +func (r *crashRemote) ListIntents(ctx context.Context) ([]chunkIntent, error) { + if r.isDead() { + return nil, errProcessDead + } + return r.fakeChunkRemote.ListIntents(ctx) +} + +func (r *crashRemote) DeleteIntent(ctx context.Context, id string) error { + if r.isDead() { + return errProcessDead + } + return r.fakeChunkRemote.DeleteIntent(ctx, id) +} + +// cutCrashImage is the volume's content as a byte image. +func cutCrashImage(t *testing.T, s *WALStore) []byte { + t.Helper() + img := make([]byte, 0, ctNumBlocks*ctBlockSize) + for lba := uint32(0); lba < ctNumBlocks; lba++ { + b, err := s.Read(lba) + if err != nil { + t.Fatalf("read LBA %d: %v", lba, err) + } + img = append(img, b...) + } + return img +} + +func TestChunkCutCrashAtEachStage(t *testing.T) { + stages := []struct { + name string + // arm installs the kill at the stage; applied says whether the + // stage is past the HEAD CAS. + arm func(l *chunkLayerImpl, r *crashRemote, die func()) + applied bool + }{ + {"after admission", func(l *chunkLayerImpl, r *crashRemote, die func()) { l.testAfterAdmitHook = die }, false}, + {"at the barrier, after Sync fixed H", func(l *chunkLayerImpl, r *crashRemote, die func()) { + l.testAfterBarrierSyncHook = func(uint64) { die() } + }, false}, + {"during the upload, after the first chunk", func(l *chunkLayerImpl, r *crashRemote, die func()) { + r.onPut = func(n int) { + if n == 1 { + die() + } + } + }, false}, + {"before the HEAD CAS is sent", func(l *chunkLayerImpl, r *crashRemote, die func()) { + r.beforeCAS = true + r.onCAS = func(bool) { die() } + }, false}, + {"after the HEAD CAS applied, before its reply", func(l *chunkLayerImpl, r *crashRemote, die func()) { + r.onCAS = func(applied bool) { + if applied { + die() + } + } + }, true}, + } + for _, st := range stages { + t.Run(st.name, func(t *testing.T) { + ctx := ctTimeout(t) + s, path, crashStore := crashableStore(t) + f := newFakeChunkRemote() + r := &crashRemote{fakeChunkRemote: f} + cfg := ctConfig(1) + l := mustAttach(t, s, r, cfg).(*chunkLayerImpl) + for lba := uint32(0); lba < ctNumBlocks; lba++ { + if _, err := s.Write(lba, makeBlock(ctBlockSize, byte(0x10+lba))); err != nil { + t.Fatal(err) + } + } + mustSyncFlush(t, s) + if _, err := l.Capture(ctx); err != nil { + t.Fatal(err) + } + old, _ := f.GetHead(ctx) + oldImage := f.imageOf(t, old) + + // New writes, then the cut that dies. + for lba := uint32(4); lba < 12; lba++ { // chunks 1 and 2 + if _, err := s.Write(lba, makeBlock(ctBlockSize, byte(0xC0+lba))); err != nil { + t.Fatal(err) + } + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + want := cutCrashImage(t, s) + die := func() { + r.kill() + crashStore() + } + r.mu.Lock() + r.puts = 0 // count this cut's uploads only + r.mu.Unlock() + st.arm(l, r, die) + _, cutErr := l.Capture(ctx) + if !r.isDead() { + t.Fatalf("the stage %q was never reached (puts %d, cut error %v)", st.name, r.puts, cutErr) + } + if cutErr == nil { + t.Fatal("the cut succeeded although the process died during it") + } + if s.v3 != nil && s.v3.ownedMap != nil { // the dead process's map file + _ = s.v3.ownedMap.Close() + s.v3.ownedMap = nil + } + + // Restart: the store recovers its WAL; HEAD is old or new, whole. + s2, _ := reopen(t, path) + head, _ := f.GetHead(ctx) + got := f.imageOf(t, head) + switch { + case st.applied && !bytes.Equal(got, want): + t.Fatalf("the CAS applied but HEAD (gen %d) is not the new image", head.Gen) + case !st.applied && (head.Gen != old.Gen || !bytes.Equal(got, oldImage)): + t.Fatalf("a cut that died before its CAS changed HEAD: gen %d -> %d", old.Gen, head.Gen) + } + if local := cutCrashImage(t, s2); !bytes.Equal(local, want) { + t.Fatal("a synced local write is lost after the crash and restart") + } + l2 := mustAttach(t, s2, f, cfg) + if _, err := l2.Capture(ctx); err != nil { + t.Fatalf("the first cut after the restart: %v", err) + } + final, _ := f.GetHead(ctx) + if !bytes.Equal(f.imageOf(t, final), want) { + t.Fatalf("the cut after the restart (gen %d) does not publish the volume as it is", final.Gen) + } + if intents, err := f.ListIntents(ctx); err == nil { + t.Logf("stage %q: HEAD gen %d -> crash -> %d -> %d after the next cut; %d intent(s) left", st.name, old.Gen, head.Gen, final.Gen, len(intents)) + } + }) + } +} From 41332710a7861997c8eeea4f1df00e0245e8417a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:25:36 -0800 Subject: [PATCH 4/7] test: kill -9 during a cut's upload with real binaries, restart, read back Single-volume coverage gap 2, procedure part (cells P8.7, P9.4, P11.3; V1-SPEC r2.55): image A is cut, every block rewritten (image B), and the holder SIGKILLed half-way through the second cut. After the restart HEAD verifies whole at depth data, the volume reads B, and the next cut, restored into a new volume through a snapshot, is B. Co-Authored-By: Claude Opus 5.5 --- .../procedure_crash_io_integration_test.go | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go index 390fbaa8d1..ec37361533 100644 --- a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -323,3 +323,94 @@ func (c *nvmeInitiator) tryRead(lba uint64, n int) ([]byte, error) { } return data, nil } + +// Gap 2, procedure part (cells P8.7, P9.4, P11.3): kill -9 of the holder +// during a cut's upload, with real binaries. Image A is cut; every block is +// rewritten (image B, flushed); a second cut starts and the holder is +// SIGKILLed at half the first cut's duration. After the restart: HEAD +// verifies whole at depth data (old or new image, nothing missing), every +// block reads B locally, and the next cut, read back through a snapshot +// restored into a new volume, is B. +const ( + cutCrashChunks = 48 + cutCrashPer = 64 // blocks written per chunk +) + +func cutCrashBlock(img byte, lba uint64) []byte { + s := fmt.Sprintf("cut-crash %c lba %08d|", img, lba) + b := make([]byte, 4096) + for i := range b { + b[i] = s[i%len(s)] + } + return b +} + +func (env *handoffEnv) writeCutCrashImage(t *testing.T, img byte) { + t.Helper() + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + defer c.close() + for ch := 0; ch < cutCrashChunks; ch++ { + for i := 0; i < cutCrashPer; i++ { + lba := uint64(ch*ladderChunkBlocks + i) + c.write(t, lba, cutCrashBlock(img, lba)) + } + } + c.flush(t) +} + +func (env *handoffEnv) requireCutCrashImage(t *testing.T, hostID string, img byte) { + t.Helper() + c := dialNVMe(t, env.hosts[hostID].nvme, plannedHandoffNQN) + defer c.close() + for ch := 0; ch < cutCrashChunks; ch++ { + for i := 0; i < cutCrashPer; i++ { + lba := uint64(ch*ladderChunkBlocks + i) + if got := c.read(t, lba, 4096); !bytes.Equal(got, cutCrashBlock(img, lba)) { + t.Fatalf("%s: LBA %d is not image %c", hostID, lba, img) + } + } + } +} + +func TestProcedureCrashDuringACut(t *testing.T) { + env := startHandoffEnvWith(t, 1, []string{"v2"}) + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + first := env.start(t, "blockvolume-v1", "s1") + e := env.adopt(t, first, "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"} + + env.writeCutCrashImage(t, 'A') + cutStart := time.Now() + env.h.command(t, cut...) + full := time.Since(cutStart) + env.writeCutCrashImage(t, 'B') + + done := make(chan int, 1) + go func() { + _, _, code := env.h.run(t, cut...) + done <- code + }() + time.Sleep(full / 2) + select { + case code := <-done: + t.Fatalf("the second cut finished (exit %d) before the kill at %s: no upload was in flight", code, full/2) + default: + } + first.kill(t) + code := <-done + t.Logf("the first cut took %s; the holder was killed at %s into the second (its CLI exit %d)", full, full/2, code) + + if out, errOut, rc := env.h.run(t, verify...); rc != 0 { + t.Fatalf("HEAD is not whole after the kill (verify exit %d):\n%s\n%s", rc, out, errOut) + } + again := env.start(t, "blockvolume-v1-again", "s1") + if got := env.adopt(t, again, "s1"); got != e { + t.Fatalf("the restarted holder adopted epoch %d; want %d", got, e) + } + env.requireCutCrashImage(t, "s1", 'B') + env.h.command(t, cut...) + env.snapshot(t, "s1", "v1", "after-crash") + env.restoreInto(t, "v1", "after-crash", "v2") + env.requireCutCrashImage(t, "n-v2", 'B') +} From e4ee17cdfca2c2da8e911285038528f37958d840 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:32:49 -0800 Subject: [PATCH 5/7] test: fresh-root crash test uses the move request id the harness checks; clearer survivor log Co-Authored-By: Claude Opus 5.5 --- .../cmd/blockvolume/procedure_crash_io_integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go index ec37361533..3a4963f44f 100644 --- a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -142,7 +142,7 @@ func TestProcedureCrashWithIOInFlight(t *testing.T) { t.Fatalf("LBA %d after the last acknowledged Flush holds data out of the stream's order or torn (kept %d)", lba, kept) } } - t.Logf("after the restart: all %d flush-acknowledged writes read back; %d of the %d unflushed completed writes survived as a prefix", flushed, kept-flushed, written-flushed) + t.Logf("after the restart: all %d flush-acknowledged writes read back; %d writes past the last acknowledged Flush survived as a prefix (%d had completed; one in flight may persist without its reply)", flushed, kept-flushed, written-flushed) } // Gap 1, cell A3.5: kill -9 of a holder serving on a FRESH root (after a @@ -186,7 +186,7 @@ func TestProcedureCrashOnAFreshRootWithFillsInFlight(t *testing.T) { t.Fatalf("s1 after the revocation: %v", err) } env.waitAck(t, e, g) - moved, _ := h.command(t, env.moveClean(e, "s2", "move-fill-1")...) + moved, _ := h.command(t, env.moveClean(e, "s2", "move-v1-1")...) e2 := mustU(movedEpochTo(moved, e, g, l, "s2")) nw := env.start(t, "blockvolume-s2", "s2") must(checkClaimDoneBy(nw.waitLog(t, 60*time.Second, "durable: HEAD claim for volume=v1 done in"), e2, "s2")) From e3c6505797e78f1fd45b8944cc343b8233852493 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:43:07 -0800 Subject: [PATCH 6/7] test: cut crash tests: the dying cut has its own deadline; the procedure kill adapts until it lands mid-upload The unit ladder's dying cut retried its failing uploads until a context it shared with the restarted process expired; it now has its own short context. The procedure test proves the kill landed mid-upload (new chunk objects on the filer, HEAD unchanged) and otherwise adapts the delay and repeats with a new image. The fresh-root test kills once 8 writes are flushed, so the reader is still filling. Co-Authored-By: Claude Opus 5.5 --- .../procedure_crash_io_integration_test.go | 92 ++++++++++++------- .../core/storage/chunk_cut_crash_test.go | 10 +- 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go index 3a4963f44f..0f59881dc5 100644 --- a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -247,7 +247,7 @@ func TestProcedureCrashOnAFreshRootWithFillsInFlight(t *testing.T) { wmu.Lock() f := flushed wmu.Unlock() - return r >= 3 && f >= 64 + return r >= 3 && f >= 8 }) nw.kill(t) // SIGKILL with fills and writes in flight <-readerDone @@ -326,11 +326,16 @@ func (c *nvmeInitiator) tryRead(lba uint64, n int) ([]byte, error) { // Gap 2, procedure part (cells P8.7, P9.4, P11.3): kill -9 of the holder // during a cut's upload, with real binaries. Image A is cut; every block is -// rewritten (image B, flushed); a second cut starts and the holder is -// SIGKILLed at half the first cut's duration. After the restart: HEAD -// verifies whole at depth data (old or new image, nothing missing), every -// block reads B locally, and the next cut, read back through a snapshot -// restored into a new volume, is B. +// rewritten and a second cut starts; the holder is SIGKILLed after a delay. +// The kill counts as mid-upload only if chunk objects of the second cut +// reached the filer while HEAD stayed at the first cut's generation; else the +// delay is adapted (shorter if the cut had committed, longer if nothing was +// uploaded) and the step repeats with a new image, up to cutCrashAttempts +// times. After the mid-upload kill and a restart: HEAD verifies whole at +// depth data, every block reads the last image locally, and the next cut, +// read back through a snapshot restored into a new volume, is that image. +const cutCrashAttempts = 6 + const ( cutCrashChunks = 48 cutCrashPer = 64 // blocks written per chunk @@ -375,42 +380,63 @@ func (env *handoffEnv) requireCutCrashImage(t *testing.T, hostID string, img byt func TestProcedureCrashDuringACut(t *testing.T) { env := startHandoffEnvWith(t, 1, []string{"v2"}) env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} - first := env.start(t, "blockvolume-v1", "s1") - e := env.adopt(t, first, "s1") + holder := env.start(t, "blockvolume-v1", "s1") + e := 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"} + headGen := func() uint64 { + out, _ := env.h.command(t, env.chunkShow()...) + h, err := parseHead(out) + if err != nil { + t.Fatal(err) + } + return h.Gen + } env.writeCutCrashImage(t, 'A') cutStart := time.Now() env.h.command(t, cut...) - full := time.Since(cutStart) - env.writeCutCrashImage(t, 'B') - - done := make(chan int, 1) - go func() { - _, _, code := env.h.run(t, cut...) - done <- code - }() - time.Sleep(full / 2) - select { - case code := <-done: - t.Fatalf("the second cut finished (exit %d) before the kill at %s: no upload was in flight", code, full/2) - default: + delay := time.Since(cutStart) / 2 + img, landed := byte('A'), false + for attempt := 1; attempt <= cutCrashAttempts && !landed; attempt++ { + img++ + env.writeCutCrashImage(t, img) + gen, entries := headGen(), f1FilerEntries(t, env) + done := make(chan int, 1) + go func() { + _, _, code := env.h.run(t, cut...) + done <- code + }() + time.Sleep(delay) + holder.kill(t) + code := <-done + uploaded := f1FilerEntries(t, env) - entries + after := headGen() + switch { + case after != gen: + t.Logf("attempt %d: the cut committed before the kill at %s (HEAD gen %d -> %d, CLI exit %d); shorter", attempt, delay, gen, after, code) + delay /= 2 + case uploaded <= 0: + t.Logf("attempt %d: nothing was uploaded before the kill at %s; longer", attempt, delay) + delay *= 2 + default: + landed = true + t.Logf("attempt %d: killed at %s mid-upload: %d new filer entries, HEAD still gen %d (CLI exit %d)", attempt, delay, uploaded, gen, code) + } + if out, errOut, rc := env.h.run(t, verify...); rc != 0 { + t.Fatalf("attempt %d: HEAD is not whole after the kill (verify exit %d):\n%s\n%s", attempt, rc, out, errOut) + } + holder = env.start(t, fmt.Sprintf("blockvolume-v1-%d", attempt), "s1") + if got := env.adopt(t, holder, "s1"); got != e { + t.Fatalf("attempt %d: the restarted holder adopted epoch %d; want %d", attempt, got, e) + } + env.requireCutCrashImage(t, "s1", img) } - first.kill(t) - code := <-done - t.Logf("the first cut took %s; the holder was killed at %s into the second (its CLI exit %d)", full, full/2, code) - - if out, errOut, rc := env.h.run(t, verify...); rc != 0 { - t.Fatalf("HEAD is not whole after the kill (verify exit %d):\n%s\n%s", rc, out, errOut) + if !landed { + t.Fatalf("no kill landed mid-upload in %d attempts", cutCrashAttempts) } - again := env.start(t, "blockvolume-v1-again", "s1") - if got := env.adopt(t, again, "s1"); got != e { - t.Fatalf("the restarted holder adopted epoch %d; want %d", got, e) - } - env.requireCutCrashImage(t, "s1", 'B') env.h.command(t, cut...) env.snapshot(t, "s1", "v1", "after-crash") env.restoreInto(t, "v1", "after-crash", "v2") - env.requireCutCrashImage(t, "n-v2", 'B') + env.requireCutCrashImage(t, "n-v2", img) } diff --git a/seaweed-block/core/storage/chunk_cut_crash_test.go b/seaweed-block/core/storage/chunk_cut_crash_test.go index 3567df0a07..4abd8439dd 100644 --- a/seaweed-block/core/storage/chunk_cut_crash_test.go +++ b/seaweed-block/core/storage/chunk_cut_crash_test.go @@ -6,6 +6,7 @@ import ( "errors" "sync" "testing" + "time" ) // Single-volume coverage gap 2 (cells P5.4, P6.4, P8.7, P9.4, P10.4, P11.3; @@ -199,7 +200,13 @@ func TestChunkCutCrashAtEachStage(t *testing.T) { r.puts = 0 // count this cut's uploads only r.mu.Unlock() st.arm(l, r, die) - _, cutErr := l.Capture(ctx) + // The dying cut gets its own short context: after the death its + // remote calls fail and it may retry them until its deadline (a + // real dead process does not); the restarted process below runs + // on fresh contexts. + dyingCtx, cancelDying := context.WithTimeout(context.Background(), 5*time.Second) + _, cutErr := l.Capture(dyingCtx) + cancelDying() if !r.isDead() { t.Fatalf("the stage %q was never reached (puts %d, cut error %v)", st.name, r.puts, cutErr) } @@ -212,6 +219,7 @@ func TestChunkCutCrashAtEachStage(t *testing.T) { } // Restart: the store recovers its WAL; HEAD is old or new, whole. + ctx = ctTimeout(t) s2, _ := reopen(t, path) head, _ := f.GetHead(ctx) got := f.imageOf(t, head) From 523b0f03c5a20fddeca3555beafc8f5f1208cd5d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 18:48:37 -0800 Subject: [PATCH 7/7] test: chunk verify at depth data needs its explicit --timeout Co-Authored-By: Claude Opus 5.5 --- .../cmd/blockvolume/procedure_crash_io_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go index 0f59881dc5..4bb7226ae6 100644 --- a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -383,7 +383,7 @@ func TestProcedureCrashDuringACut(t *testing.T) { holder := env.start(t, "blockvolume-v1", "s1") e := 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"} + 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()...) h, err := parseHead(out)