From c86586a124db88b03a254d60d02cc5f6962e3cd8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 05:32:14 -0800 Subject: [PATCH 1/3] Holder snapshot delete retries only a lost HEAD update A snapshot delete is one conditional update of HEAD, and the holder's cleaning kicked by the previous delete also updates HEAD; D4's second delete lost that race once (status 500, "HEAD generation moved"). The helper retries exactly that answer, within 30 s, as the CLI reports it retryable; every other answer is returned unchanged. Co-Authored-By: Claude Opus 5.5 --- .../snapshot_ladder_d_integration_test.go | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go index 9b6ed5acd0..b27db46d68 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go @@ -40,17 +40,28 @@ func (env *handoffEnv) deleteSnapshot(t *testing.T, vol, name string) { // control route (POST /chunk/snapshot/delete on hostID's status listener), // which runs the holder's cleaning pass right after the delete. It returns // the HTTP status and body. +// +// A snapshot delete is one conditional update of HEAD. The holder's +// cleaning (kicked by the previous delete) also updates HEAD, so a delete +// that read HEAD just before can lose its update ("HEAD generation moved") +// and change nothing; ops chunk snapshot-delete reports that as a retryable +// conflict. Only that answer is retried, within 30 s; any other is returned. func (env *handoffEnv) holderDeleteSnapshot(t *testing.T, hostID, vol, name string) (int, string) { t.Helper() body, _ := json.Marshal(map[string]string{"volumeID": vol, "name": name}) c := &http.Client{Timeout: 2 * time.Minute} - resp, err := c.Post("http://"+env.hosts[hostID].status+"/chunk/snapshot/delete", "application/json", strings.NewReader(string(body))) - if err != nil { - t.Fatal(err) + for end := time.Now().Add(30 * time.Second); ; time.Sleep(200 * time.Millisecond) { + resp, err := c.Post("http://"+env.hosts[hostID].status+"/chunk/snapshot/delete", "application/json", strings.NewReader(string(body))) + if err != nil { + t.Fatal(err) + } + out, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) + resp.Body.Close() + if resp.StatusCode == http.StatusOK || !strings.Contains(string(out), "HEAD generation moved") || time.Now().After(end) { + return resp.StatusCode, string(out) + } + t.Logf("holder delete of %s lost its HEAD update to a concurrent change; retrying: %s", name, out) } - defer resp.Body.Close() - out, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) - return resp.StatusCode, string(out) } // poolObjects counts the chunk objects in vol's pool (every shard From cb51f2ebe9b6325ccfff3515b1cc3dde8949fbaf Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 06:17:13 -0800 Subject: [PATCH 2/3] test(blockvolume): weed port pairs avoid the host's ephemeral port range w4FreePortPair checked a pair free and weed bound it later; a pair inside ip_local_port_range could be taken in between by any outgoing connection's source port (seen: a filer's gRPC port 43775 inside a host's 43255-47350, "bind: address already in use", with extra volumes adding connections). handoffAddress already stays below that range for the same reason. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit a54fcdde5ea81b1d23396c45ace385038288553a) --- .../workspace_weed_integration_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go index a1a5f4f82d..b8c25f4a8c 100644 --- a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go +++ b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go @@ -37,13 +37,32 @@ func testListenHost() string { return "127.0.0.1" } +// ephemeralPorts is the host's range for outgoing connections' source ports +// (Linux ip_local_port_range; the Linux default when unreadable). A port in it +// can be taken by any outgoing connection between the free check and weed's +// bind, so a port pair never uses it. +func ephemeralPorts() (int, int) { + lo, hi := 32768, 60999 + if b, err := os.ReadFile("/proc/sys/net/ipv4/ip_local_port_range"); err == nil { + var a, z int + if n, _ := fmt.Sscan(string(b), &a, &z); n == 2 && a > 0 && z >= a { + lo, hi = a, z + } + } + return lo, hi +} + func w4FreePortPair(t *testing.T, used map[int]bool) int { t.Helper() + lo, hi := ephemeralPorts() for i := 0; i < 200; i++ { p := 20000 + rand.Intn(20000) if used[p] || used[p+10000] { continue } + if (p >= lo && p <= hi) || (p+10000 >= lo && p+10000 <= hi) { + continue + } ok := true for _, q := range []int{p, p + 10000} { l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", testListenHost(), q)) From de1ca8c23517c4e89855c115054feb52f3026b90 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 06:06:28 -0800 Subject: [PATCH 3/3] test(blockvolume): control: weed port pairs never use the ephemeral range Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 496b933f482ce955a863d7aa579e6d1ea45b3d15) --- .../weed_ports_integration_test.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 seaweed-block/cmd/blockvolume/weed_ports_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/weed_ports_integration_test.go b/seaweed-block/cmd/blockvolume/weed_ports_integration_test.go new file mode 100644 index 0000000000..a5e662abc7 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/weed_ports_integration_test.go @@ -0,0 +1,22 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import "testing" + +// TestWeedPortPairsAvoidTheEphemeralRange: no port of a weed port pair lies in +// the host's range for outgoing connections' source ports, where any +// connection could take it between w4FreePortPair's free check and weed's bind +// (a filer's gRPC port inside a host's 43255-47350 failed to bind that way). +func TestWeedPortPairsAvoidTheEphemeralRange(t *testing.T) { + lo, hi := ephemeralPorts() + used := map[int]bool{} + for i := 0; i < 100; i++ { + p := w4FreePortPair(t, used) + for _, q := range []int{p, p + 10000} { + if q >= lo && q <= hi { + t.Fatalf("pair %d/%d: port %d is in the ephemeral range %d-%d", p, p+10000, q, lo, hi) + } + } + } +}