From 5046436c8bc3ef15d5efe14b191cb3eb0b1c7f9a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 18:35:38 -0800 Subject: [PATCH 1/4] test: the systemd startup gate asserts serve-after-barrier in process (no fence exit) and a moved source's exit 78 Fixes #572. Co-Authored-By: Claude Opus 5.5 --- .../startup_systemd_integration_test.go | 90 +++++++++++++++---- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go index 95263837fa..7263493f5f 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go @@ -161,31 +161,41 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) { if firstPID == "0" { t.Fatal("returning unit did not start a real process") } - // Existing assignment wait is30s. This is an outer failed-run guard, not - // an injected success delay or a replacement product deadline. - waitGAP1(t, "GAP-1: first startup never exited75; stayed alive non-serving", 45*time.Second, func() bool { - s := gap1Unit(t, unit) + // The returning process waits in process for the master's barrier and + // serves after it, with no fence exit and no restart (the startup wait, + // #535): first it reports the barrier as its MasterWait, never serving. + var barrierMs int64 + waitGAP1(t, "returning unit never reported the master's barrier", 30*time.Second, func() bool { if gap1Operational(t, statusAddr, volume) { - t.Fatal("fixture returned before the expired-grant barrier: cannot count this as a startup-timeout red") + t.Fatal("the returning unit served before reporting a barrier wait: an expired lease was re-granted without the barrier") } - if s["ExecMainStatus"] == "75" { + if s := gap1Unit(t, unit); s["MainPID"] != firstPID { + t.Fatalf("the returning unit exited while waiting for the barrier: %+v", s) + } + if w := gap1MasterWait(t, statusAddr, volume); w.Reason == "barrier" && w.UntilMs > 0 { + barrierMs = w.UntilMs + t.Logf("captured master wait: reason=%s until=%d", w.Reason, w.UntilMs) return true } - if s["MainPID"] != "0" && s["MainPID"] != firstPID { - t.Fatalf("restart without captured75: %+v", s) - } return false }) - waitGAP1(t, "systemd did not restart/regrant/attach", 100*time.Second, func() bool { + // Then the same process serves: not before the barrier, and within the + // startup wait's bound (barrier + 30 s; the outer guard adds slack). + waitGAP1(t, "the returning unit never served after the barrier", 75*time.Second, func() bool { s := gap1Unit(t, unit) - n, e := strconv.Atoi(s["NRestarts"]) - if e != nil { - t.Fatalf("invalid captured NRestarts: %+v", s) + if s["MainPID"] != firstPID || s["NRestarts"] != "0" { + t.Fatalf("the returning unit restarted (a fence exit) instead of serving in process: %+v", s) } - if n > 2 { - t.Fatalf("barrier retry exceeded three total launches: %+v", s) + if !gap1Operational(t, statusAddr, volume) { + return false } - return n >= 1 && s["MainPID"] != "0" && s["MainPID"] != firstPID && gap1Operational(t, statusAddr, volume) + if now := time.Now().UnixMilli(); now < barrierMs { + t.Fatalf("served at %d, before the master's barrier %d", now, barrierMs) + } + if late := time.Now().UnixMilli() - barrierMs; late > 30_000 { + t.Fatalf("served %d ms after the barrier: past the startup wait's 30 s bound", late) + } + return true }) after, err := gap1ReadHead(t, remote) if err != nil || after.Gen <= before.Gen || after.Holder != before.Holder || after.Epoch != before.Epoch { @@ -215,6 +225,54 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) { } gap1PlannedStopDoesNotRestart(t, ws, unit, statusAddr, volume, after.Epoch, "r1", s["NRestarts"], s["InvocationID"]) gap1PrestartedTargetServesAfterMove(t, fixture, ws, remote, target, stem, filepath.Join(bin, "blockvolume"), args, root, volume, want) + gap1MovedSourceExits78(t, fixture, filepath.Join(bin, "blockvolume"), args, stem, statusAddr, volume) +} + +// gap1MovedSourceExits78 is the negative case of the in-process wait: after +// the volume moved to another host, the old source started again learns the +// move and exits 78 (final), which the unit's RestartPreventExitStatus keeps +// from restarting; it never serves. +func gap1MovedSourceExits78(t *testing.T, fixture *gap1Fixture, exe string, args []string, stem, statusAddr, volume string) { + t.Helper() + unit := stem + "-moved-source" + fixture.start(t, unit, true, exe, args...) + waitGAP1(t, "the moved-away source never exited 78", 90*time.Second, func() bool { + if gap1Operational(t, statusAddr, volume) { + t.Fatal("the moved-away source served") + } + s := gap1Unit(t, unit) + if s["ExecMainStatus"] == "75" { + t.Fatalf("the moved-away source exited 75 (retry) instead of 78 (moved): %+v", s) + } + return s["ExecMainStatus"] == "78" && s["MainPID"] == "0" + }) + time.Sleep(7 * time.Second) // past RestartSec: a restart would have happened + if s := gap1Unit(t, unit); s["NRestarts"] != "0" || s["MainPID"] != "0" { + t.Fatalf("systemd restarted the moved-away source after its exit 78: %+v", s) + } +} + +// gap1MasterWait reads the volume's /status MasterWait (the startup wait's +// reason and the master's barrier time), zero when absent. +func gap1MasterWait(t *testing.T, addr, volume string) struct { + Reason string + UntilMs int64 +} { + t.Helper() + var out struct { + MasterWait *struct { + Reason string + UntilMs int64 + } + } + code, body, err := gap1StatusAt(addr, volume, "/status") + if err != nil || code != http.StatusOK || json.Unmarshal(body, &out) != nil || out.MasterWait == nil { + return struct { + Reason string + UntilMs int64 + }{} + } + return *out.MasterWait } // Roots are deliberately independent of testing.TempDir: unknown unit cleanup From 0666f6ad185f1a47eb7ecce9bdbbfd31cd6abd74 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 18:41:39 -0800 Subject: [PATCH 2/4] test: the moved-source case stops the new holder first (the simulated hosts share one volume lock directory) Co-Authored-By: Claude Opus 5.5 --- .../blockvolume/startup_systemd_integration_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go index 7263493f5f..c42db24829 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go @@ -229,11 +229,17 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) { } // gap1MovedSourceExits78 is the negative case of the in-process wait: after -// the volume moved to another host, the old source started again learns the -// move and exits 78 (final), which the unit's RestartPreventExitStatus keeps -// from restarting; it never serves. +// the volume moved to another host (and the new holder stopped), the old +// source started again learns the move and exits 78 (final), which the unit's +// RestartPreventExitStatus keeps from restarting; it never serves. func gap1MovedSourceExits78(t *testing.T, fixture *gap1Fixture, exe string, args []string, stem, statusAddr, volume string) { t.Helper() + // The simulated hosts share this kernel's per-host volume lock directory: + // stop the new holder (the prestarted target) so the old source can open + // its root at all; on real separate hosts the two never share a lock. + target := stem + "-prestarted-target" + gap1Systemctl(t, "stop", target) + waitGAP1(t, "the new holder did not stop", 30*time.Second, func() bool { return gap1Unit(t, target)["MainPID"] == "0" }) unit := stem + "-moved-source" fixture.start(t, unit, true, exe, args...) waitGAP1(t, "the moved-away source never exited 78", 90*time.Second, func() bool { From 06641576457767c964f9a4e9128b5e5b41f0991e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 18:45:01 -0800 Subject: [PATCH 3/4] test: the moved-away source never serves and exits only 75 (no lineage of its own) Co-Authored-By: Claude Opus 5.5 --- .../startup_systemd_integration_test.go | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go index c42db24829..d968c5289e 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go @@ -225,14 +225,17 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) { } gap1PlannedStopDoesNotRestart(t, ws, unit, statusAddr, volume, after.Epoch, "r1", s["NRestarts"], s["InvocationID"]) gap1PrestartedTargetServesAfterMove(t, fixture, ws, remote, target, stem, filepath.Join(bin, "blockvolume"), args, root, volume, want) - gap1MovedSourceExits78(t, fixture, filepath.Join(bin, "blockvolume"), args, stem, statusAddr, volume) + gap1MovedSourceNeverServes(t, fixture, filepath.Join(bin, "blockvolume"), args, stem, statusAddr, volume) } -// gap1MovedSourceExits78 is the negative case of the in-process wait: after -// the volume moved to another host (and the new holder stopped), the old -// source started again learns the move and exits 78 (final), which the unit's -// RestartPreventExitStatus keeps from restarting; it never serves. -func gap1MovedSourceExits78(t *testing.T, fixture *gap1Fixture, exe string, args []string, stem, statusAddr, volume string) { +// gap1MovedSourceNeverServes is the negative case of the in-process wait: +// after the volume moved to another host (and the new holder stopped), the +// old source started again never serves and never adopts the line naming the +// other host. It has no lineage of its own from the master, so it exits 75 +// (retry: zero observed-own lineage selects retry, never a fence) rather than +// 78; the exit-78 refusal of a running holder that is moved is covered by +// the master-wait integration tests. +func gap1MovedSourceNeverServes(t *testing.T, fixture *gap1Fixture, exe string, args []string, stem, statusAddr, volume string) { t.Helper() // The simulated hosts share this kernel's per-host volume lock directory: // stop the new holder (the prestarted target) so the old source can open @@ -242,20 +245,24 @@ func gap1MovedSourceExits78(t *testing.T, fixture *gap1Fixture, exe string, args waitGAP1(t, "the new holder did not stop", 30*time.Second, func() bool { return gap1Unit(t, target)["MainPID"] == "0" }) unit := stem + "-moved-source" fixture.start(t, unit, true, exe, args...) - waitGAP1(t, "the moved-away source never exited 78", 90*time.Second, func() bool { + waitGAP1(t, "the moved-away source never exited", 75*time.Second, func() bool { if gap1Operational(t, statusAddr, volume) { t.Fatal("the moved-away source served") } s := gap1Unit(t, unit) - if s["ExecMainStatus"] == "75" { - t.Fatalf("the moved-away source exited 75 (retry) instead of 78 (moved): %+v", s) + switch s["ExecMainStatus"] { + case "", "0": + return false + case "75": + return true } - return s["ExecMainStatus"] == "78" && s["MainPID"] == "0" + t.Fatalf("the moved-away source exited %s; want 75 (retry, no lineage of its own): %+v", s["ExecMainStatus"], s) + return false }) - time.Sleep(7 * time.Second) // past RestartSec: a restart would have happened - if s := gap1Unit(t, unit); s["NRestarts"] != "0" || s["MainPID"] != "0" { - t.Fatalf("systemd restarted the moved-away source after its exit 78: %+v", s) + if gap1Operational(t, statusAddr, volume) { + t.Fatal("the moved-away source served after its exit") } + gap1Systemctl(t, "stop", unit) } // gap1MasterWait reads the volume's /status MasterWait (the startup wait's From e502ad4b9235a8182313bb6fd6818e67a53f624d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 19:05:39 -0800 Subject: [PATCH 4/4] test: the moved-away source's journal shows the refused foreign line and no adoption Co-Authored-By: Claude Opus 5.5 --- .../startup_systemd_integration_test.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go index d968c5289e..808e5e2f58 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go @@ -262,6 +262,27 @@ func gap1MovedSourceNeverServes(t *testing.T, fixture *gap1Fixture, exe string, if gap1Operational(t, statusAddr, volume) { t.Fatal("the moved-away source served after its exit") } + // The exit must come from the move, not from an unassigned or + // disconnected timeout: the journal shows the source received the line + // naming the other host, refused it as another server's, and never adopted + // a lineage of its own. + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + journal, err := exec.CommandContext(ctx, "journalctl", "--unit="+unit, "--no-pager", "--output=cat").CombinedOutput() + cancel() + if err != nil { + t.Fatalf("moved-away source journal: %v %s", err, journal) + } + for _, want := range []string{ + fmt.Sprintf("assignment identity refusal volume=%q replica=%q server=%q", volume, "r1", "s2"), + fmt.Sprintf("foreign assignment server=%q replica=%q recorded, not adopted", "s2", "r1"), + } { + if !strings.Contains(string(journal), want) { + t.Fatalf("the moved-away source's journal lacks %q: its exit is not proven to come from the move\n%s", want, journal) + } + } + if strings.Contains(string(journal), "adopted as PRIMARY") { + t.Fatalf("the moved-away source adopted a lineage:\n%s", journal) + } gap1Systemctl(t, "stop", unit) }