From 1d4e29a07a6b4d25e9e47eb95a00a2f90a99cc5d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 03:39:13 -0800 Subject: [PATCH] fix: fence foreign facts only after adopted lineage is superseded --- .../core/host/volume/assignment_holder.go | 20 +++++++++++++++++++ seaweed-block/core/host/volume/host.go | 13 ++++-------- seaweed-block/docs/design/invariants.md | 4 ++-- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/seaweed-block/core/host/volume/assignment_holder.go b/seaweed-block/core/host/volume/assignment_holder.go index c2f6928268..ddac223cec 100644 --- a/seaweed-block/core/host/volume/assignment_holder.go +++ b/seaweed-block/core/host/volume/assignment_holder.go @@ -10,3 +10,23 @@ func (h *Host) assignmentNamesSelf(f *control.AssignmentFact) bool { (f.GetDataAddr() == "" || f.GetDataAddr() == h.cfg.DataAddr) && (f.GetCtrlAddr() == "" || f.GetCtrlAddr() == h.cfg.CtrlAddr) } + +// observeForeignHolder implements M3 / INV-AUTH-HOLDER-IDENTITY-001. +// Delivery before a move is not supersession: record every refused fact, +// and use the one supersession decision against the adopted engine lineage. +func (h *Host) observeForeignHolder(f *control.AssignmentFact) { + h.recordOtherLine(f) + if h.view == nil { + return + } + own := h.view.EngineProjection() + if !h.IsSuperseded(h.cfg.ReplicaID, own.Epoch, own.EndpointVersion) { + h.log.Printf("blockvolume: volume %s foreign assignment server=%q replica=%q recorded, not adopted; waiting for own current line", h.cfg.VolumeID, f.ServerId, f.ReplicaId) + return + } + h.wd.notPrimary() + if err := h.fenceSelfWithPeers(selfRolePrimary, f.Epoch, false); err != nil { + h.log.Printf("blockvolume: foreign holder ingress fence: %v", err) + } + h.log.Printf("blockvolume: volume %s superseded by assignment server=%q replica=%q; fenced, not serving", h.cfg.VolumeID, f.ServerId, f.ReplicaId) +} diff --git a/seaweed-block/core/host/volume/host.go b/seaweed-block/core/host/volume/host.go index 042c731eba..5704165606 100644 --- a/seaweed-block/core/host/volume/host.go +++ b/seaweed-block/core/host/volume/host.go @@ -520,12 +520,12 @@ func (h *Host) getReplication() replicaSetUpdater { } // IsSuperseded gates a newer foreign replica line, or a same-replica foreign -// server/endpoint identity at or above the local lineage. An explicitly +// server/endpoint identity strictly newer than an adopted local lineage. An explicitly // matching self identity remains an ordinary adapter update. func (h *Host) IsSuperseded(selfReplicaID string, selfEpoch, selfEV uint64) bool { h.otherMu.Lock() defer h.otherMu.Unlock() - if h.lastOther == nil { + if h.lastOther == nil || selfEpoch == 0 { return false } other := h.lastOther @@ -533,7 +533,7 @@ func (h *Host) IsSuperseded(selfReplicaID string, selfEpoch, selfEV uint64) bool if h.assignmentNamesSelf(other) { return false } - return other.Epoch > selfEpoch || other.Epoch == selfEpoch && other.EndpointVersion >= selfEV + return other.Epoch > selfEpoch || other.Epoch == selfEpoch && other.EndpointVersion > selfEV } if other.Epoch > selfEpoch { return true @@ -810,12 +810,7 @@ func (h *Host) streamOnce(ctx context.Context) error { func (h *Host) applyFact(fact *control.AssignmentFact) { // INV-AUTH-HOLDER-IDENTITY-001: matching r1 and loopback endpoints do not identify a host. if fact.ReplicaId == h.cfg.ReplicaID && !h.assignmentNamesSelf(fact) { - h.wd.notPrimary() - h.recordOtherLine(fact) - if err := h.fenceSelfWithPeers(selfRolePrimary, fact.Epoch, false); err != nil { - h.log.Printf("blockvolume: foreign holder ingress fence: %v", err) - } - h.log.Printf("blockvolume: volume %s assignment server=%q replica=%q is not this process server=%q; fenced, not serving; never adopted", h.cfg.VolumeID, fact.ServerId, fact.ReplicaId, h.cfg.ServerID) + h.observeForeignHolder(fact) return } if fact.ReplicaId != h.cfg.ReplicaID { diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index cd3380a110..c7543d8665 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -132,7 +132,7 @@ RF2 qualification limitation until ordered-live certification is wired (#297). S |---|---|---|---|---| | any | (no change) | local readiness blocked (recovery pending or failed): the fact is stored and replayed when readiness clears | `core/host/volume/host.go` `applyFact`, `replayLocalReadinessFactIfReady` | `INV-ROLE-READINESS-BLOCK-001` | | any | (no change) | a role call below the current desired epoch is refused and does not clear a newer admission failure | `core/host/volume/host.go` `fenceSelfWithPeers`, `latchRoleAdmission` | `INV-ROLE-STALE-REPLAY-001` | -| Unassigned, Supporting | Primary at e | the primary fact names this process server and replica via assignmentNamesSelf, with matching data/control endpoints when carried; missing/foreign server is refused; the replica set is installed; the listener is fenced as primary and its floor e is persisted before the adapter is told | `core/host/volume/host.go` `applyFact`, `fenceSelfWithPeers`; `core/transport/replica.go` `FenceAsPrimary`, `raiseFloor` | `INV-FENCE-SELF-ON-PROMOTE-001`, `INV-FENCE-FLOOR-DURABLE-001`, `INV-AUTH-HOLDER-IDENTITY-001` | +| Unassigned, Supporting | Primary at e | the primary fact names this process server and replica via assignmentNamesSelf, with matching data/control endpoints when carried; missing/foreign server is refused; refused foreign facts are recorded but fence only an adopted own lineage that IsSuperseded finds strictly older (unassigned and older replay keep waiting); the replica set is installed; the listener is fenced as primary and its floor e is persisted before the adapter is told | `core/host/volume/host.go` `applyFact`, `fenceSelfWithPeers`; `core/transport/replica.go` `FenceAsPrimary`, `raiseFloor` | `INV-FENCE-SELF-ON-PROMOTE-001`, `INV-FENCE-FLOOR-DURABLE-001`, `INV-AUTH-HOLDER-IDENTITY-001` | | Unassigned, Primary | Supporting at e | the fact names another primary and lists this replica as a peer; the floor e is persisted first; the frontend stays gated | `core/host/volume/host.go` `applyFact`; `core/transport/replica.go` `AdmitAsReplica` | `INV-FENCE-FLOOR-DURABLE-001` | | Primary, Supporting | Excluded | the fact names another primary and does not list this replica, or names this replica on a missing/foreign server or mismatched carried endpoints; a same-replica foreign line at or above local epoch/endpoint-version gates the projection; ingress is closed, the other line is recorded and the frontend is unhealthy | `core/host/volume/host.go` `applyFact`, `recordOtherLine`; `core/host/volume/projection_bridge.go` `projectionWithSupersede` | `INV-ROLE-SUPERSEDED-001`, `INV-FENCE-STALE-PRIMARY-001`, `INV-AUTH-HOLDER-IDENTITY-001` | | Excluded | Excluded (no change) | an older recorded foreign fact cannot replace the newer epoch/endpoint-version fence; a stale replay cannot re-enable the frontend | `core/host/volume/host.go` `recordOtherLine`, `IsSuperseded` | `INV-AUTH-HOLDER-IDENTITY-001` | @@ -575,7 +575,7 @@ Notes: | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| -| `INV-AUTH-HOLDER-IDENTITY-001` | A primary holder is the pair (server id, replica id): every site that decides holdership (adopting a fact, lease first grant, renew, re-grant, HEAD claim, superseded exit) compares both; a missing server id is refused, never guessed. | AUTHORITY: PRIMARY holdership (supporting replicas are not holders) | `core/host/volume/host.go` `applyFact`, `IsSuperseded`, `recordOtherLine`; `assignment_holder.go` `assignmentNamesSelf`; `core/host/master/services.go` `SubscribeAssignments`; `workspace_service.go` `holderMatches`, `RenewWorkspaceLease`, `AckWorkspaceRevoked`; `cmd/blockvolume/chunk_remote.go` `chunkHolder`; `core/storage/chunk_restore.go` `ClaimChunkHead`; superseded exit covered by #409 | `TestAssignmentHolderIdentityRestartedOldProcess`, `TestAssignmentHolderIdentityMatchingServerStillAdopts`, `TestAssignmentHolderIdentityFencesPreviouslyHealthySameReplica`, `TestAssignmentHolderIdentityRefusesCarriedEndpointMismatch` (`core/host/volume/assignment_holder_test.go`); `TestWorkspaceLeaseGuardCarriesHolderServerIdentity` (`core/host/volume/workspace_holder_identity_test.go`); `TestWorkspaceLeaseRequiresHolderServerForGrantRenewAndRegrant`, `TestWorkspaceRevocationACKRequiresHolderServer` (`core/host/master/workspace_holder_identity_test.go`); `TestWorkspaceRPCCleanMovePreservesReplicaIdentity` (`core/host/master/workspace_service_test.go`); HEAD claim: `TestChunkHolderIsServerAndReplica` (`cmd/blockvolume/chunk_remote_test.go`), `TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced` (`core/frontend/durable/provider_chunk_holder_test.go`); superseded exit: covered by #409 (server-id/replica-id pair, never replica alone); supporting replicas are not holders; descriptor identity not in this row | - (unit and RPC identity boundary) | ACTIVE, `INV-AUTH-HOLDER-IDENTITY-001` | +| `INV-AUTH-HOLDER-IDENTITY-001` | A primary holder is the pair (server id, replica id): every site that decides holdership (adopting a fact, lease first grant, renew, re-grant, HEAD claim, superseded exit) compares both; a missing server id is refused, never guessed. | AUTHORITY: PRIMARY holdership (supporting replicas are not holders) | `core/host/volume/host.go` `applyFact`, `IsSuperseded`, `recordOtherLine`; `assignment_holder.go` `assignmentNamesSelf`, `observeForeignHolder`; `host.go` `IsSuperseded`; `core/host/master/services.go` `SubscribeAssignments`; `workspace_service.go` `holderMatches`, `RenewWorkspaceLease`, `AckWorkspaceRevoked`; `cmd/blockvolume/chunk_remote.go` `chunkHolder`; `core/storage/chunk_restore.go` `ClaimChunkHead`; superseded exit covered by #409 | `TestAssignmentHolderIdentityRestartedOldProcess`, `TestAssignmentHolderIdentityMatchingServerStillAdopts`, `TestAssignmentHolderIdentityFencesPreviouslyHealthySameReplica`, `TestAssignmentHolderIdentityRefusesCarriedEndpointMismatch`, `TestAssignmentHolderIdentityForeignStreamOrdering` (`core/host/volume/assignment_holder_test.go`); `TestWorkspaceLeaseGuardCarriesHolderServerIdentity` (`core/host/volume/workspace_holder_identity_test.go`); `TestWorkspaceLeaseRequiresHolderServerForGrantRenewAndRegrant`, `TestWorkspaceRevocationACKRequiresHolderServer` (`core/host/master/workspace_holder_identity_test.go`); `TestWorkspaceRPCCleanMovePreservesReplicaIdentity` (`core/host/master/workspace_service_test.go`); HEAD claim: `TestChunkHolderIsServerAndReplica` (`cmd/blockvolume/chunk_remote_test.go`), `TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced` (`core/frontend/durable/provider_chunk_holder_test.go`); superseded exit: covered by #409 (server-id/replica-id pair, never replica alone); supporting replicas are not holders; descriptor identity not in this row | - (unit and RPC identity boundary) | ACTIVE, `INV-AUTH-HOLDER-IDENTITY-001` | | `INV-AUTH-EPOCH-MINT-001` | Only the publisher mints epochs; a reassignment takes the per-volume maximum epoch plus one, also after a restart. | M2 Bound → Reassigned | `core/authority/authority.go` `applyWithWorkspaceMove`, `maxPublishedEpochForVolume` | `TestG8_0_Publisher_ReassignAdvancesPerVolumeEpochAcrossReplicaSlots` (`core/authority/g8_0_authority_failover_test.go`); `TestDurableAuthority_PublisherAdvancesFromReloaded` (`core/authority/authority_restart_test.go`); `TestG9F2_AssignmentRequestShapeHasNoEpochOrEndpointVersion` (`core/host/master/authority_request_bridge_test.go`) | `ControlPlane` `UniqueEpoch` | ACTIVE | | `INV-AUTH-PERSIST-BEFORE-PUBLISH-001` | With an authority store configured, an assignment is written to the store before memory or any subscriber sees it, and a failed write does not publish it: see M2 any → (store write first). | M2 any → (store write first) | `core/authority/authority.go` `applyWithWorkspaceMove` | `TestDurableAuthority_PutFailureRollsBackInMemoryState` (`core/authority/authority_restart_test.go`) | `ControlPlane` `UniqueEpoch` | ACTIVE | | `INV-AUTH-MOVE-JOURNAL-001` | A workspace move's epoch is issued only after its journal record is durable, and one move request id gets exactly one epoch, also across restarts. | M2 MoveReserved → MoveIssued | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `MoveWorkspace`, `sameWorkspaceRequest` | `TestWorkspaceMoveCannotIssueEpochWithoutJournal`, `TestWorkspaceCrashAfterJournalBeforeEpochResumesSameGrant` (`core/authority/workspace_test.go`); `TestWorkspaceReplayedIssueStartsGranteeLease` (`core/authority/workspace_unclaimed_grant_test.go`) | `ControlPlane` `Idempotent`, `JournalComplete` | ACTIVE |