From e1edfe04da6671e2d324fc8ac616466560184a8d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 06:19:34 -0800 Subject: [PATCH] fix: apply zero-lineage retry rule to observed and adopted facts --- .../process_exit_authority_test.go | 2 +- .../startup_systemd_integration_test.go | 30 +++++++++---------- seaweed-block/core/host/volume/host.go | 16 ++++------ .../core/host/volume/workspace_startup.go | 2 +- .../host/volume/workspace_startup_test.go | 10 ++++--- seaweed-block/docs/design/invariants.md | 2 +- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/process_exit_authority_test.go b/seaweed-block/cmd/blockvolume/process_exit_authority_test.go index e86edd7c0c..44cbe8bece 100644 --- a/seaweed-block/cmd/blockvolume/process_exit_authority_test.go +++ b/seaweed-block/cmd/blockvolume/process_exit_authority_test.go @@ -126,7 +126,7 @@ func TestWorkspaceRetryUsesNewestOwnAssignment(t *testing.T) { {"never assigned", []struct { replica string epoch uint64 - }{{"other", 6}}, 78}, + }{{"other", 6}}, 75}, {"empty replica newer epoch", []struct { replica string epoch uint64 diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go index fa869e29b3..ce34dde5d6 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go @@ -191,7 +191,7 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) { t.Fatalf("systemd rate limit hit: %+v", s) } gap1PlannedStopDoesNotRestart(t, ws, unit, statusAddr, volume, after.Epoch, "r1", s["NRestarts"], s["InvocationID"]) - gap1SupersededDoesNotRestart(t, fixture, stem, filepath.Join(bin, "blockvolume"), args, root, volume) + gap1NeverAssignedRetries(t, fixture, stem, filepath.Join(bin, "blockvolume"), args, root, volume) } // Roots are deliberately independent of testing.TempDir: unknown unit cleanup @@ -499,11 +499,11 @@ func gap1PlannedStopDoesNotRestart(t *testing.T, ws control.WorkspaceServiceClie }) } -// The master keeps the real r1 authority line. This process has never had an -// assignment and names r-old, so only the observed different-replica fact may -// permit 78. Run after the live holder has ACKed and exited, avoiding a node -// registration change while that holder is serving. -func gap1SupersededDoesNotRestart(t *testing.T, fixture *gap1Fixture, stem, exe string, args []string, root, volume string) { +// The master keeps the real r1 authority line. A fresh r-old process has +// zero observed-own lineage, so a foreign fact selects retry75, never78. +// Run after the live holder has ACKed and exited, avoiding a node registration +// change while that holder is serving. This is not a superseded-holder witness. +func gap1NeverAssignedRetries(t *testing.T, fixture *gap1Fixture, stem, exe string, args []string, root, volume string) { t.Helper() changed := append([]string(nil), args...) addr := leaseBinaryAddress(t) @@ -538,7 +538,7 @@ func gap1SupersededDoesNotRestart(t *testing.T, fixture *gap1Fixture, stem, exe } // A never-assigned replica remains ModeIdle, so /status intentionally // reports unknown even after recording the other-replica fact. Prove - // receipt in this process before checking its terminal78 decision. + // receipt in this process before checking its retry75 decision. ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() journal, err := exec.CommandContext(ctx, "journalctl", "--unit="+unit, "--no-pager", "--output=cat").CombinedOutput() @@ -552,18 +552,16 @@ func gap1SupersededDoesNotRestart(t *testing.T, fixture *gap1Fixture, stem, exe } return false }) - waitGAP1(t, "positive supersede did not exit78 without restart", 45*time.Second, func() bool { + waitGAP1(t, "never-assigned foreign identity did not exit75 and restart", 45*time.Second, func() bool { s := gap1Unit(t, unit) - if s["NRestarts"] != "0" { - t.Fatalf("superseded unit restarted: %+v", s) + n, err := strconv.Atoi(s["NRestarts"]) + if err != nil { + t.Fatalf("invalid restart count: %+v", s) } - if s["MainPID"] != "0" { - return false + if s["ExecMainStatus"] == "78" { + t.Fatalf("zero-lineage process chose no-retry: %+v", s) } - if s["ExecMainStatus"] != "78" || s["ActiveState"] != "failed" || s["SubState"] != "failed" { - t.Fatalf("supersede not a terminal no-retry exit: %+v", s) - } - return true + return n >= 1 && s["MainPID"] != "0" && s["ExecMainStatus"] == "75" }) } diff --git a/seaweed-block/core/host/volume/host.go b/seaweed-block/core/host/volume/host.go index 43e68fba2e..78b5613748 100644 --- a/seaweed-block/core/host/volume/host.go +++ b/seaweed-block/core/host/volume/host.go @@ -523,21 +523,15 @@ func (h *Host) getReplication() replicaSetUpdater { return h.replication } -// IsSuperseded compares an adopted lineage. Before adoption there is no -// serving incarnation to fence (INV-AUTH-HOLDER-IDENTITY-001). +// IsSuperseded is the one foreign-holder comparison. Callers supply the +// named lineage: adopted engine state for fencing, observed own assignment +// for exit classification. Zero lineage selects neither fencing nor exit78 +// (INV-AUTH-HOLDER-IDENTITY-001; INV-WS-STARTUP-RETRY-001). func (h *Host) IsSuperseded(selfReplicaID string, selfEpoch, selfEV uint64) bool { - return selfEpoch != 0 && h.isSupersededLineage(selfReplicaID, selfEpoch, selfEV) -} - -// isSupersededLineage is the one foreign-holder comparison. Callers name -// their evidence: adopted engine lineage for fencing, observed own assignment -// for process exit (INV-WS-STARTUP-RETRY-001). Zero observed lineage means this -// process never received its own assignment, not that a foreign line is ours. -func (h *Host) isSupersededLineage(selfReplicaID string, selfEpoch, selfEV uint64) bool { h.otherMu.Lock() defer h.otherMu.Unlock() other := h.lastOther - if other == nil || other.ReplicaId == "" || other.VolumeId != h.cfg.VolumeID { + if selfEpoch == 0 || other == nil || other.ReplicaId == "" || other.VolumeId != h.cfg.VolumeID { return false } if other.ReplicaId == selfReplicaID && h.assignmentNamesSelf(other) { diff --git a/seaweed-block/core/host/volume/workspace_startup.go b/seaweed-block/core/host/volume/workspace_startup.go index 1a270eb801..22a743f114 100644 --- a/seaweed-block/core/host/volume/workspace_startup.go +++ b/seaweed-block/core/host/volume/workspace_startup.go @@ -22,5 +22,5 @@ func (h *Host) recordSelfAssignment(f *control.AssignmentFact) { func (h *Host) IsCurrentReplicaSuperseded() bool { h.ownAssignmentMu.RLock() defer h.ownAssignmentMu.RUnlock() - return h.isSupersededLineage(h.cfg.ReplicaID, h.ownAssignmentEpoch, h.ownAssignmentEV) + return h.IsSuperseded(h.cfg.ReplicaID, h.ownAssignmentEpoch, h.ownAssignmentEV) } diff --git a/seaweed-block/core/host/volume/workspace_startup_test.go b/seaweed-block/core/host/volume/workspace_startup_test.go index 319e1a7b28..cec944cd7f 100644 --- a/seaweed-block/core/host/volume/workspace_startup_test.go +++ b/seaweed-block/core/host/volume/workspace_startup_test.go @@ -9,8 +9,10 @@ import ( func TestWorkspaceExitLineageIncludesBlockedOwnAssignment(t *testing.T) { h, _, _ := newStubbedHost(t, "v", "r", &orderingRecorder{}) h.applyFixtureFact(&control.AssignmentFact{VolumeId: "v", ReplicaId: "other", Epoch: 6, EndpointVersion: 1}) - if !h.IsCurrentReplicaSuperseded() { - t.Fatal("never-assigned newer other line did not supersede") + // Zero observed-own lineage inherits the fencing predicate's zero rule: + // a never-assigned process retries75; it has no own incarnation to supersede. + if h.IsCurrentReplicaSuperseded() { + t.Fatal("never-assigned process must retry75 despite a foreign line") } h.BlockLocalReadiness("local recovery pending") h.applyFixtureFact(&control.AssignmentFact{VolumeId: "v", ReplicaId: "r", Epoch: 7, EndpointVersion: 1}) @@ -56,8 +58,8 @@ func TestWorkspaceExitAndFenceUseNamedLineages(t *testing.T) { foreign := holderAssignment(t, "other") foreign.Epoch = 6 h.applyFact(foreign) - if !h.IsCurrentReplicaSuperseded() || h.IsSuperseded("r1", 0, 0) || fencer.calls.Load() != 0 { - t.Fatal("foreign same-replica server must select exit78 without fencing an unadopted incarnation") + if h.IsCurrentReplicaSuperseded() || h.IsSuperseded("r1", 0, 0) || fencer.calls.Load() != 0 { + t.Fatal("foreign same-replica server must select retry75 and no fence before any own assignment") } own := holderAssignment(t, "self") own.Epoch = 7 diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 7611fc2df8..54a0d8c31a 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -717,7 +717,7 @@ Notes: | `INV-WS-STARTUP-RETRY-001` | A workspace primary exits 75 on assignment timeout or lease expiry, with bounded cleanup; a newer other-replica master fact or an exact foreign HEAD at or above the assigned epoch permits 78. ACKed revocation and signal retain normal exit. Lease and claim gates never relax. | M2 restart | `cmd/blockvolume/process_exit.go` `superviseProcess`, `workspaceRetryOutcome`; `core/frontend/durable/provider_chunk.go` `claimHeadSupersedes`; `core/frontend/durable/provider_startup.go` `endChunkStartup` | `TestChunkAssignmentTimeoutExposesCurrentRecoveryOutcome` (`core/frontend/durable/provider_startup_outcome_test.go`); `TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake` (`core/frontend/durable/provider_startup_internal_test.go`); `TestWorkspaceDisplacedClaimUsesAssignedEpoch`, `TestWorkspaceRetryUsesNewestOwnAssignment`, `TestWorkspaceForeignHeadClaimChoosesNoRetry`, `TestWorkspaceOldLocalHolderForeignHeadChoosesNoRetry` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceExitFirstOutcomeIsLatched`, `TestWorkspaceExitDoesNotWaitForBlockedFrontendClose`, `TestWorkspacePlannedStopKeepsSuccess` (`cmd/blockvolume/process_exit_test.go`) | Existing WorkspaceRegrant restart transition; no new grant rule | ACTIVE | - `INV-WS-STARTUP-RETRY-001`: exit 78 is permitted by a NEWER observed master fact for this volume naming another replica (compared with the latest own assignment, zero before any), or by the exact refused HEAD claim image proving another holder at or above the assigned epoch. The provider binds the latter proof to its recovery generation. Both existing-root checks and claim CAS readback use the same epoch-qualified supersede classifier. A lower-epoch foreign HEAD on an existing root retains the move-back diagnostic; a displaced lower-epoch claim on a fresh root retries 75 without serving. A same-holder higher-epoch HEAD fence retries 75. Unknown/no line, same replica at a higher epoch, and status codes alone mean retry 75. A wrong retry costs a bounded restart loop; a wrong 78 causes an outage until an explicit operator start. Sealed same-epoch recovery remains up for read-only replay after assignment; stale local roots, corrupt WAL and I/O faults retain diagnostic wait. The first chosen outcome wins. Process cleanup reuses `WorkspaceDrainTimeout` (5 s), including a blocked Close; only main exits the process. -- Part T lineage evidence: `recordSelfAssignment` records the newest identity-validated observed-own assignment before local-readiness admission; `EngineProjection` is the adopted-own lineage. Exit compares the former (zero means never assigned); fencing requires a nonzero latter. Both use `isSupersededLineage` through their named entry points; neither fact grants I/O. `TestWorkspaceExitAndFenceUseNamedLineages` and `TestWorkspaceExitLineageIncludesBlockedOwnAssignment` (`core/host/volume/workspace_startup_test.go`) keep the distinction causal. +- Part T lineage evidence: `recordSelfAssignment` records the newest identity-validated observed-own assignment before local-readiness admission; `EngineProjection` is the adopted-own lineage. Exit compares the former; fencing compares the latter. Both use `IsSuperseded` with explicit lineage; zero lineage selects retry75 and no fence; neither fact grants I/O. `TestWorkspaceExitAndFenceUseNamedLineages` and `TestWorkspaceExitLineageIncludesBlockedOwnAssignment` (`core/host/volume/workspace_startup_test.go`) keep the distinction causal. - Part T evidence scope: `workspaceRetryOutcome` is the one retry/no-retry decision. Startup `chooseChunkStartupExit` supplies the recovery-generation-bound refused-claim HEAD proof; runtime lease-end supplies none. Both combine that input with the newer other-replica master line; absent proof means retry 75. - Part T fence ownership: `Host.FenceWorkspaceLease` uses `WorkspaceLeaseGuard.fenceLocked`, including before runtime publication; the zero-validity terminal guard preserves the first cause through installation and can grant no I/O. No second host fence latch exists. `TestWorkspaceHostFencePublishesOneTerminalCause`, `TestWorkspaceInstalledHostFenceRecordsCause`, `TestWorkspaceFenceBeforeHeldInstallIsTerminal` (`core/host/volume/workspace_terminal_test.go`). - Startup arbitration: sealed-replay/stale-local-root dispositions suppress the same wait's deadline defer (`TestChunkStartupRetainedDispositionWinsExpiredAttachContext`, `core/frontend/durable/provider_startup_outcome_test.go`). A stop request retires startup monitoring and its atomic-choice callback before resource cleanup; success is chosen only after the guard's ACK (`TestWorkspacePlannedDrainOwnsStartupExpiryUntilAck`, `cmd/blockvolume/process_exit_authority_test.go`). Provider-validated startup selection briefly takes the process startup mutex; cancellation takes only that mutex. No reverse provider-lock acquisition or remote call occurs.