From 62e092de37b86df863733036fe47e58a6b59207f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 12:18:09 -0800 Subject: [PATCH 1/6] Store-down procedure: the store goes down inside the cut by construction The test polled for the cut's first filer entry and then checked HEAD had not moved; on a fast host the cut committed between the two (HEAD gen 4 -> 5, "not mid-cut"). It now runs on a filer front that holds the reply to the cut's first applied chunk-object create: the store is stopped while that reply is held, then the reply is released, so the cut cannot commit before the store is down. E1_TEST_SKIP_BOUNDARY=1 holds nothing and the test then fails as inconclusive. Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 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 8c864c6c48..90e450ddfc 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -8,10 +8,13 @@ import ( "errors" "fmt" "os" + "path" "path/filepath" "strings" "testing" "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" ) // The SeaweedFS side down during a cut, then back, @@ -21,6 +24,13 @@ 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. // +// The store goes down inside the cut by construction: a filer front holds +// the reply to the cut's first applied chunk-object create, the store is +// stopped while that reply is held, then the reply is released. The cut +// cannot commit while one of its uploads is unanswered. With +// E1_TEST_SKIP_BOUNDARY=1 the front holds nothing and the test fails as +// inconclusive (the control). +// // 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 @@ -48,7 +58,13 @@ func TestProcedureStoreDownDuringACut(t *testing.T) { } func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bool) { - env := startHandoffEnvWith(t, 1, []string{"v2"}) + if testListenHost() != "127.0.0.1" { + t.Fatal("the causal filer front requires loopback") + } + var boundary *snapshotFilerBoundary + cluster := startWorkspaceWeedWith(t, t.TempDir(), w4WeedOpts{VolumeSizeLimitMB: 256, VolumeMax: 32, + FilerBind: "127.0.0.2", FilerFront: func(c *w4WeedCluster) { boundary = newSnapshotFilerBoundary(t, c) }}) + env := startHandoffEnvOnCluster(t, 1, []string{"v2"}, procedureTLSConfig(), false, cluster) 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. @@ -65,6 +81,12 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } holder := env.start(t, "blockvolume-v1", "s1") env.adopt(t, holder, "s1") + id, err := layout.ParseVolumeID(env.layoutID("v1")) + if err != nil { + t.Fatal(err) + } + boundary.id = id + boundary.dir = path.Join(env.chunkPath, layout.VolumeDir("v1", id)) 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 { @@ -97,8 +119,10 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } } - // A cut starts; the store goes down once its uploads have begun. - gen, entries := headGen(), f1FilerEntries(t, env) + // A cut starts; the store goes down while the reply to its first applied + // chunk-object create is held, so before the cut can commit. + gen := headGen() + reached := boundary.arm("OBJECT", "") type cutAnswer struct { rc int out string @@ -118,16 +142,17 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } answered <- cutAnswer{rc, out + errOut, time.Since(cutStart)} }() - 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) - } + t.Cleanup(func() { boundary.unblock(); cutCancel(); <-cutDone }) + select { + case <-reached: + case <-time.After(30 * time.Second): + t.Fatalf("%s: inconclusive: the cut applied no chunk-object create within 30s, so 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) + t.Fatalf("%s: the cut committed (HEAD gen %d -> %d) while one of its uploads was unanswered", down, gen, g) } env.cluster.stopProc(t, down) + boundary.unblock() downAt := time.Now() t.Logf("%s killed %s after the cut started", down, downAt.Sub(cutStart).Round(time.Millisecond)) From 85d0ca75047f13ad60f4d2b74617734244a26e6b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 21:17:16 -0800 Subject: [PATCH 2/6] test: the store-down guard checks HEAD's committed image, not its generation A cut's session begin writes HEAD (a new generation) before its first upload, so a generation change does not mean the cut committed. On M01 (weed 4.53) the guard fired on the session begin in all four subtests. Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 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 90e450ddfc..80b9e6957d 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -97,6 +97,17 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } return hd.Gen } + // headImage is HEAD's committed image (its current root and position). + // A cut's session begin also writes HEAD (a new generation) before its + // first upload, so the generation alone does not tell a commit apart. + headImage := func() string { + out, _ := env.h.command(t, env.chunkShow()...) + hd, err := parseLayoutHead(out) + if err != nil { + t.Fatal(err) + } + return fmt.Sprintf("%s@%d", hd.Current, hd.Position) + } sideBytes := func() int64 { files, _ := filepath.Glob(filepath.Join(env.hosts["s1"].root, "*.cut-cow-*")) var n int64 @@ -121,7 +132,7 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo // A cut starts; the store goes down while the reply to its first applied // chunk-object create is held, so before the cut can commit. - gen := headGen() + image := headImage() reached := boundary.arm("OBJECT", "") type cutAnswer struct { rc int @@ -148,8 +159,8 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo case <-time.After(30 * time.Second): t.Fatalf("%s: inconclusive: the cut applied no chunk-object create within 30s, so the store would not go down mid-cut", down) } - if g := headGen(); g != gen { - t.Fatalf("%s: the cut committed (HEAD gen %d -> %d) while one of its uploads was unanswered", down, gen, g) + if got := headImage(); got != image { + t.Fatalf("%s: the cut committed (HEAD image %s -> %s) while one of its uploads was unanswered", down, image, got) } env.cluster.stopProc(t, down) boundary.unblock() @@ -282,7 +293,7 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo if stalled.rc == 0 { t.Fatalf("%s: the cut the outage hit reported success: %s", down, firstLine(stalled.out)) } - gen = headGen() + 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 c1fb2111295166b2d03d3a7e91d0264b591d30c4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 21:30:51 -0800 Subject: [PATCH 3/6] test: the store-down test waits for a readable HEAD after the restart; verify names the master The filer front accepts at once while the real filer behind it may still be starting, so the restart is complete when HEAD reads again. The chunk verify call names --master, which a bare chunk path now needs. Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 13 ++++++++++--- 1 file changed, 10 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 80b9e6957d..4b5bf1d310 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -88,7 +88,7 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo boundary.id = id boundary.dir = path.Join(env.chunkPath, layout.VolumeDir("v1", id)) 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"} + verify := []string{"ops", "chunk", "verify", "--master", env.h.masterAddr, "--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 := parseLayoutHead(out) @@ -275,8 +275,15 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo // The store comes back. env.cluster.restartProc(t, down) backAt := time.Now() - if down == "filer" { - w4WaitTCP(t, env.cluster.filerGRPC, 30*time.Second) + // The store is back when HEAD reads through it again: the filer front + // accepts at once, while the real filer behind it may still be starting. + for end := time.Now().Add(time.Minute); ; time.Sleep(time.Second) { + if _, _, rc := env.h.run(t, env.chunkShow()...); rc == 0 { + break + } + if time.Now().After(end) { + t.Fatalf("%s back: HEAD not readable within 1m of the restart", down) + } } stalled := cutWhileDown if stalled == nil { From 4426d07ba4e4188102c908eef00f0ba862964cb7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 21:44:33 -0800 Subject: [PATCH 4/6] test: the store-down test finds copy-on-write side files under the volume's directory A store now lives in its volume's own directory (-) and its side file is created next to it; the test globbed only the host root, so it measured 0 and its no-leftover checks looked nowhere. It walks the root. Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 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 4b5bf1d310..5f2e6297c9 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "io/fs" "os" "path" "path/filepath" @@ -108,14 +109,20 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo } return fmt.Sprintf("%s@%d", hd.Current, hd.Position) } + // sideBytes sums the copy-on-write side files anywhere under the host's + // root: a store lives in its volume's own directory (-), and + // its side file is created next to it. 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 { + _ = filepath.WalkDir(env.hosts["s1"].root, func(p string, d fs.DirEntry, err error) error { + if err != nil || d.IsDir() || !strings.Contains(d.Name(), ".cut-cow-") { + return nil + } + if st, err := os.Stat(p); err == nil { n += st.Size() } - } + return nil + }) return n } From 15381ee7eb8cc284da84f0191133537544cdda79 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 21:59:00 -0800 Subject: [PATCH 5/6] test: the store-down test proves the held upload was still waiting at the kill The filer front records when the held call leaves and why (the test's release, or its caller giving up); the test checks the hold is still waiting right after the store goes down, else the run is inconclusive. E1_TEST_DELAY_KILL delays the kill past the upload's timeout as the negative control. The post-restart HEAD reads carry the wait's absolute deadline, and the side-file census fails on any error but a file removed while it is walked. Co-Authored-By: Claude Opus 5.5 --- .../procedure_store_down_integration_test.go | 50 ++++++++++++++++--- ...napshot_filer_boundary_integration_test.go | 36 ++++++++++++- 2 files changed, 76 insertions(+), 10 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 5f2e6297c9..0f7a352eb5 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -112,17 +112,33 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo // sideBytes sums the copy-on-write side files anywhere under the host's // root: a store lives in its volume's own directory (-), and // its side file is created next to it. + // A census it cannot complete fails the test: only a file removed while + // it is walked (the window closing) is skipped. sideBytes := func() int64 { var n int64 - _ = filepath.WalkDir(env.hosts["s1"].root, func(p string, d fs.DirEntry, err error) error { - if err != nil || d.IsDir() || !strings.Contains(d.Name(), ".cut-cow-") { + err := filepath.WalkDir(env.hosts["s1"].root, func(p string, d fs.DirEntry, err error) error { + if err != nil { + if errors.Is(err, fs.ErrNotExist) { + return nil + } + return err + } + if d.IsDir() || !strings.Contains(d.Name(), ".cut-cow-") { return nil } - if st, err := os.Stat(p); err == nil { - n += st.Size() + st, err := os.Stat(p) + if errors.Is(err, fs.ErrNotExist) { + return nil } + if err != nil { + return err + } + n += st.Size() return nil }) + if err != nil { + t.Fatalf("copy-on-write side-file census: %v", err) + } return n } @@ -169,7 +185,22 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo if got := headImage(); got != image { t.Fatalf("%s: the cut committed (HEAD image %s -> %s) while one of its uploads was unanswered", down, image, got) } + if d := os.Getenv("E1_TEST_DELAY_KILL"); d != "" { + // Control: a kill delayed past the upload's own timeout, so the cut + // gives up while the store is healthy; the check below must call + // the run inconclusive. + if wait, err := time.ParseDuration(d); err == nil { + time.Sleep(wait) + } + } env.cluster.stopProc(t, down) + // The outage is inside the cut only if the held upload was still + // waiting when the store went down: a held call whose caller gave up + // (the upload's 30 s context) means the cut failed with the store + // healthy. + if held, why := boundary.stillHeld(); !held { + t.Fatalf("%s: inconclusive: the held upload was not waiting when the store went down (%s)", down, why) + } boundary.unblock() downAt := time.Now() t.Logf("%s killed %s after the cut started", down, downAt.Sub(cutStart).Round(time.Millisecond)) @@ -284,10 +315,13 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo backAt := time.Now() // The store is back when HEAD reads through it again: the filer front // accepts at once, while the real filer behind it may still be starting. - for end := time.Now().Add(time.Minute); ; time.Sleep(time.Second) { - if _, _, rc := env.h.run(t, env.chunkShow()...); rc == 0 { - break - } + readable := func(end time.Time) bool { // one read, bounded by the whole wait's deadline + ctx, cancel := context.WithDeadline(context.Background(), end) + defer cancel() + _, _, rc, err := runCLI(ctx, env.h, env.chunkShow()...) + return err == nil && rc == 0 + } + for end := time.Now().Add(time.Minute); !readable(end); time.Sleep(time.Second) { if time.Now().After(end) { t.Fatalf("%s back: HEAD not readable within 1m of the restart", down) } diff --git a/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go index d226c29279..62c421049b 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go @@ -37,7 +37,11 @@ type snapshotFilerBoundary struct { kind, name string reached chan struct{} release chan struct{} - hit bool + // left is closed when the held call returns, by the test's release or + // by its caller giving up (its context done; leftByCaller says which). + left chan struct{} + leftByCaller bool + hit bool } func newSnapshotFilerBoundary(t *testing.T, cluster *w4WeedCluster) *snapshotFilerBoundary { @@ -88,9 +92,31 @@ func (p *snapshotFilerBoundary) arm(kind, name string) <-chan struct{} { p.kind, p.name = kind, name p.reached = make(chan struct{}) p.release = make(chan struct{}) + p.left = make(chan struct{}) + p.leftByCaller = false p.hit = false return p.reached } + +// stillHeld reports whether the held call is still waiting (its caller has +// not given up), with why it left otherwise. +func (p *snapshotFilerBoundary) stillHeld() (bool, string) { + p.mu.Lock() + left, byCaller := p.left, p.leftByCaller + p.mu.Unlock() + if left == nil { + return false, "nothing was held" + } + select { + case <-left: + if byCaller { + return false, "its caller gave up (the upload's context ended)" + } + return false, "it was released" + default: + return true, "" + } +} func (p *snapshotFilerBoundary) unblock() { p.mu.Lock() defer p.mu.Unlock() @@ -119,12 +145,18 @@ func (p *snapshotFilerBoundary) after(ctx context.Context, dir string, entry *fi } p.hit = true close(p.reached) - release := p.release + release, left := p.release, p.left p.mu.Unlock() + byCaller := false select { case <-release: case <-ctx.Done(): + byCaller = true } + p.mu.Lock() + p.leftByCaller = byCaller + p.mu.Unlock() + close(left) } func (p *snapshotFilerBoundary) head(t *testing.T) layout.Head { t.Helper() From 5a9f2a66c2973477a58f0a5fb901cfe44dce4265 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 22:04:08 -0800 Subject: [PATCH 6/6] test: stillHeld reads the held call's own context A caller can give up before the front's handler is scheduled to notice, leaving the left channel open; the check reads the held request's context first. Co-Authored-By: Claude Opus 5.5 --- ...napshot_filer_boundary_integration_test.go | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go index 62c421049b..afa393b799 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go @@ -4,6 +4,7 @@ package main_test import ( "context" + "fmt" "io" "net" "net/http" @@ -41,7 +42,10 @@ type snapshotFilerBoundary struct { // by its caller giving up (its context done; leftByCaller says which). left chan struct{} leftByCaller bool - hit bool + // heldCtx is the held call's own context: its caller giving up is read + // from it directly, not from the handler having run since. + heldCtx context.Context + hit bool } func newSnapshotFilerBoundary(t *testing.T, cluster *w4WeedCluster) *snapshotFilerBoundary { @@ -94,6 +98,7 @@ func (p *snapshotFilerBoundary) arm(kind, name string) <-chan struct{} { p.release = make(chan struct{}) p.left = make(chan struct{}) p.leftByCaller = false + p.heldCtx = nil p.hit = false return p.reached } @@ -102,16 +107,18 @@ func (p *snapshotFilerBoundary) arm(kind, name string) <-chan struct{} { // not given up), with why it left otherwise. func (p *snapshotFilerBoundary) stillHeld() (bool, string) { p.mu.Lock() - left, byCaller := p.left, p.leftByCaller + left, ctx := p.left, p.heldCtx p.mu.Unlock() - if left == nil { + if left == nil || ctx == nil { return false, "nothing was held" } + // The call's own context first: its caller can give up before the + // handler is scheduled to notice, which would leave left open. + if err := ctx.Err(); err != nil { + return false, fmt.Sprintf("its caller gave up (%v)", err) + } select { case <-left: - if byCaller { - return false, "its caller gave up (the upload's context ended)" - } return false, "it was released" default: return true, "" @@ -144,6 +151,7 @@ func (p *snapshotFilerBoundary) after(ctx context.Context, dir string, entry *fi return } p.hit = true + p.heldCtx = ctx close(p.reached) release, left := p.release, p.left p.mu.Unlock()