From 184f4eacd451c2032b3d04b5e8f4ad18c00dd6f3 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 05:12:13 -0800 Subject: [PATCH] test: preserve the advertised filer identity at crash boundaries (cherry picked from commit ff6490991ae0dbad1dd285ebac35ea6a49282e0a) --- .../planned_handoff_integration_test.go | 14 ++++++- ...napshot_filer_boundary_integration_test.go | 37 +++++++++++++++---- .../snapshot_ladder_e_integration_test.go | 17 +++++++-- .../workspace_weed_integration_test.go | 15 +++++++- 4 files changed, 69 insertions(+), 14 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index f9ffca0bab..af521559ca 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -244,9 +244,19 @@ func startHandoffEnvTLS(t *testing.T, n int, targets []string, tlsNotAfter map[s // VolumeRecord. The restore-create test uses that form so the master creates // the target's identity and restored image in one request. func startHandoffEnvConfigured(t *testing.T, n int, targets []string, tlsNotAfter map[string]time.Time, precreateTargets bool, masterArgs ...string) *handoffEnv { + t.Helper() + return startHandoffEnvOnCluster(t, n, targets, tlsNotAfter, precreateTargets, nil, masterArgs...) +} + +// startHandoffEnvOnCluster also admits a caller-owned stock filer behind a +// fault-injection front; ordinary callers keep the default cluster unchanged. +func startHandoffEnvOnCluster(t *testing.T, n int, targets []string, tlsNotAfter map[string]time.Time, precreateTargets bool, cluster *w4WeedCluster, masterArgs ...string) *handoffEnv { t.Helper() h := newPlannedHandoffHarness(t) - env := &handoffEnv{h: h, cluster: startWorkspaceWeed(t), chunkPath: fmt.Sprintf("/handoff-%d", time.Now().UnixNano()), hosts: map[string]bvHost{}} + if cluster == nil { + cluster = startWorkspaceWeed(t) + } + env := &handoffEnv{h: h, cluster: cluster, chunkPath: fmt.Sprintf("/handoff-%d", time.Now().UnixNano()), hosts: map[string]bvHost{}} must, _ := fatalOn(t) env.hosts["s1"] = bvHost{id: "s1", data: h.dataAddr, ctrl: h.ctrlAddr, status: h.statusAddr, nvme: h.nvmeAddr, root: filepath.Join(h.dir, "vol")} for i := 2; i <= n; i++ { @@ -257,7 +267,7 @@ func startHandoffEnvConfigured(t *testing.T, n int, targets []string, tlsNotAfte id := "n-" + v env.hosts[id] = bvHost{id: id, data: handoffAddress(t), ctrl: handoffAddress(t), status: handoffAddress(t), nvme: handoffAddress(t), root: filepath.Join(h.dir, "vol-"+id), volume: v} } - cluster, chunkPath := env.cluster, env.chunkPath + chunkPath := env.chunkPath if tlsNotAfter != nil { servers := make([]string, 0, len(env.hosts)) for _, b := range env.hosts { 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 c9a0e51f95..717854e19e 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_filer_boundary_integration_test.go @@ -6,6 +6,9 @@ import ( "context" "io" "net" + "net/http" + "net/http/httputil" + "net/url" "os" "path" "sync" @@ -37,28 +40,46 @@ type snapshotFilerBoundary struct { hit bool } -func newSnapshotFilerBoundary(t *testing.T, env *handoffEnv) (*snapshotFilerBoundary, string) { +func newSnapshotFilerBoundary(t *testing.T, cluster *w4WeedCluster) *snapshotFilerBoundary { t.Helper() - id, err := layout.ParseVolumeID(env.layoutID("v1")) + conn, err := grpc.NewClient(cluster.filerGRPC, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { t.Fatal(err) } - conn, err := grpc.NewClient(env.cluster.filerGRPC, grpc.WithTransportCredentials(insecure.NewCredentials())) + p := &snapshotFilerBoundary{backend: filerpb.NewSeaweedFilerClient(conn)} + _, gp, _ := net.SplitHostPort(cluster.filerGRPC) + listener, err := net.Listen("tcp", net.JoinHostPort(testListenHost(), gp)) if err != nil { t.Fatal(err) } - p := &snapshotFilerBoundary{backend: filerpb.NewSeaweedFilerClient(conn), id: id, - dir: path.Join(env.chunkPath, layout.VolumeDir("v1", id))} - listener, err := net.Listen("tcp", "127.0.0.1:0") + backendURL, err := url.Parse("http://" + cluster.filerHTTP) if err != nil { t.Fatal(err) } + _, hp, _ := net.SplitHostPort(cluster.filerHTTP) + httpListener, err := net.Listen("tcp", net.JoinHostPort(testListenHost(), hp)) + if err != nil { + t.Fatal(err) + } + httpServer := &http.Server{Handler: httputil.NewSingleHostReverseProxy(backendURL), ReadHeaderTimeout: 10 * time.Second} + httpDone := make(chan struct{}) + go func() { defer close(httpDone); _ = httpServer.Serve(httpListener) }() server := grpc.NewServer() filerpb.RegisterSeaweedFilerServer(server, p) done := make(chan struct{}) go func() { defer close(done); _ = server.Serve(listener) }() - t.Cleanup(func() { p.unblock(); server.Stop(); _ = listener.Close(); <-done; _ = conn.Close() }) - return p, listener.Addr().String() + t.Cleanup(func() { + p.unblock() + server.Stop() + _ = listener.Close() + <-done + _ = httpServer.Close() + <-httpDone + _ = conn.Close() + }) + cluster.filerGRPC = listener.Addr().String() + cluster.filerHTTP = httpListener.Addr().String() + return p } func (p *snapshotFilerBoundary) arm(kind, name string) <-chan struct{} { diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_e_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_e_integration_test.go index 998eaf2eb4..fb67c66d5d 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_e_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_e_integration_test.go @@ -71,9 +71,20 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) { for i := 0; i <= len(boundaries); i++ { targets = append(targets, fmt.Sprintf("v%d", i+2)) } - env := startHandoffEnvWith(t, 1, targets) - boundary, filerAddr := newSnapshotFilerBoundary(t, env) - env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off", "--chunk-filer", filerAddr} + if testListenHost() != "127.0.0.1" { + t.Fatal("causal filer fixture 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, targets, procedureTLSConfig(), false, cluster) + 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)) + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} holder := env.start(t, "blockvolume-v1", "s1") e := env.adopt(t, holder, "s1") marker := pattern("ladder-e1-marker") diff --git a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go index f3236fbc38..a1a5f4f82d 100644 --- a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go +++ b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go @@ -91,6 +91,10 @@ func startWorkspaceWeedAt(t *testing.T, dir string) *w4WeedCluster { // VolumeSizeLimitMB each (the default holds about 8 GiB of chunks). type w4WeedOpts struct { VolumeSizeLimitMB, VolumeMax int + // A fault-injection front keeps the advertised filer endpoint unchanged. + // The one real filer binds a private loopback address; no second filer is registered. + FilerBind string + FilerFront func(*w4WeedCluster) } func startWorkspaceWeedWith(t *testing.T, dir string, o w4WeedOpts) *w4WeedCluster { @@ -137,8 +141,17 @@ func startWorkspaceWeedWith(t *testing.T, dir string, o w4WeedOpts) *w4WeedClust run("master", "master", "-ip="+testListenHost(), fmt.Sprintf("-port=%d", mp), "-mdir="+filepath.Join(dir, "m"), fmt.Sprintf("-volumeSizeLimitMB=%d", o.VolumeSizeLimitMB), "-defaultReplication=000") w4WaitTCP(t, c.master, 20*time.Second) run("volume", "volume", "-ip="+testListenHost(), fmt.Sprintf("-port=%d", vp), "-dir="+filepath.Join(dir, "v"), "-master="+c.master, fmt.Sprintf("-max=%d", o.VolumeMax)) - run("filer", "filer", "-ip="+testListenHost(), fmt.Sprintf("-port=%d", fp), "-master="+c.master, "-defaultStoreDir="+filepath.Join(dir, "f")) + filerArgs := []string{"filer", "-ip=" + testListenHost(), fmt.Sprintf("-port=%d", fp), "-master=" + c.master, "-defaultStoreDir=" + filepath.Join(dir, "f")} + if o.FilerBind != "" { + filerArgs = append(filerArgs, "-ip.bind="+o.FilerBind) + c.filerHTTP = net.JoinHostPort(o.FilerBind, fmt.Sprint(fp)) + c.filerGRPC = net.JoinHostPort(o.FilerBind, fmt.Sprint(fp+10000)) + } + run("filer", filerArgs...) w4WaitTCP(t, c.filerGRPC, 30*time.Second) + if o.FilerFront != nil { + o.FilerFront(c) + } // Wait until an assign succeeds (volume registered, volumes growable). cl := c.client(t, "/swblock/vols/probe")