From 55bf4a846173562c0ed87e08724ce1489d5d36c1 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 15:00:52 -0800 Subject: [PATCH 1/3] authority: test: a replica's slot takes a fact only from its expected server Red on main: assembleVolumeTopology keys fresh facts by replica id from whichever server reported them first, so another server's fact for r1 supplies r1's addresses and health. Co-Authored-By: Claude Opus 5.5 --- .../authority/snapshot_slot_server_test.go | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 seaweed-block/core/authority/snapshot_slot_server_test.go diff --git a/seaweed-block/core/authority/snapshot_slot_server_test.go b/seaweed-block/core/authority/snapshot_slot_server_test.go new file mode 100644 index 0000000000..d535ab909d --- /dev/null +++ b/seaweed-block/core/authority/snapshot_slot_server_test.go @@ -0,0 +1,39 @@ +package authority + +import "testing" + +// INV-OBS-SLOT-FROM-EXPECTED-SERVER-001: a replica's slot in the assembled +// topology takes its addresses and health only from a fresh fact reported +// by the server its expected slot names. Another server's fact for the +// same replica (whatever it claims, and whichever comes first) is never +// used: with no fact from the expected server the slot is a placeholder. +func TestAssembleVolumeTopology_SlotFactOnlyFromTheExpectedServer(t *testing.T) { + expected := VolumeExpected{VolumeID: "v1", Slots: []ExpectedSlot{{ReplicaID: "r1", ServerID: "node-a"}, {ReplicaID: "r2", ServerID: "node-b"}}} + foreign := slotWithServer{serverID: "node-x", slot: SlotFact{VolumeID: "v1", ReplicaID: "r1", DataAddr: "10.9.9.9:1", CtrlAddr: "10.9.9.9:2", Reachable: true, ReadyForPrimary: true, Eligible: true, EvidenceScore: 99}} + own := slotWithServer{serverID: "node-a", slot: SlotFact{VolumeID: "v1", ReplicaID: "r1", DataAddr: "10.0.0.1:1", CtrlAddr: "10.0.0.1:2", Reachable: true, Eligible: true}} + r2 := slotWithServer{serverID: "node-b", slot: SlotFact{VolumeID: "v1", ReplicaID: "r2", DataAddr: "10.0.0.2:1", CtrlAddr: "10.0.0.2:2", Reachable: true, Eligible: true}} + + slot := func(topo VolumeTopologySnapshot, replica string) ReplicaCandidate { + t.Helper() + for _, s := range topo.Slots { + if s.ReplicaID == replica { + return s + } + } + t.Fatalf("no slot %s in %+v", replica, topo.Slots) + return ReplicaCandidate{} + } + + // The foreign fact comes first: the expected server's fact still wins. + got := slot(assembleVolumeTopology("v1", expected, []slotWithServer{foreign, own, r2}, AuthorityBasis{}, false), "r1") + if got.DataAddr != own.slot.DataAddr || got.CtrlAddr != own.slot.CtrlAddr || got.ServerID != "node-a" || got.EvidenceScore != 0 { + t.Fatalf("r1 = %+v, want node-a's fact (addresses %s/%s, score 0)", got, own.slot.DataAddr, own.slot.CtrlAddr) + } + + // Only the foreign server reported r1: the slot is a placeholder, never + // the foreign addresses or health. + got = slot(assembleVolumeTopology("v1", expected, []slotWithServer{foreign, r2}, AuthorityBasis{}, false), "r1") + if got.DataAddr != "" || got.CtrlAddr != "" || got.Reachable || got.Eligible || got.ReadyForPrimary { + t.Fatalf("r1 = %+v, want a placeholder (no foreign addresses or health)", got) + } +} From ab633d203262e056946306c79b3ee9dc56416779 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 15:01:12 -0800 Subject: [PATCH 2/3] authority: a replica's slot takes a fact only from the server its expected slot names assembleVolumeTopology now ignores a fresh fact for a replica reported by any server other than the one the expected slot names, so another host cannot put its addresses or health into the assignment line of a replica it does not host (its doc comment already said so). With no fact from the expected server the slot stays a placeholder, as for a missing fact. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/snapshot_builder.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/seaweed-block/core/authority/snapshot_builder.go b/seaweed-block/core/authority/snapshot_builder.go index f54d6ef540..16585e17b0 100644 --- a/seaweed-block/core/authority/snapshot_builder.go +++ b/seaweed-block/core/authority/snapshot_builder.go @@ -416,8 +416,19 @@ func assembleVolumeTopology( ) VolumeTopologySnapshot { slots := make([]ReplicaCandidate, 0, len(expected.Slots)) + // A replica's fact counts only from the server its expected slot names: + // another server reporting the same replica id (rule §9's foreign claim + // does not cover a known replica id) must not supply its addresses or + // health to the line. + expectedServer := make(map[string]string, len(expected.Slots)) + for _, e := range expected.Slots { + expectedServer[e.ReplicaID] = e.ServerID + } byReplicaID := map[string]slotWithServer{} for _, f := range freshSlots { + if f.serverID != expectedServer[f.slot.ReplicaID] { + continue + } if _, ok := byReplicaID[f.slot.ReplicaID]; !ok { byReplicaID[f.slot.ReplicaID] = f } From c546662f51460c75669de37b54d2436970b97601 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 15:35:54 -0800 Subject: [PATCH 3/3] invariants: INV-OBS-SLOT-FROM-EXPECTED-SERVER-001 (approved; lands after Train 11) Co-Authored-By: Claude Opus 5.5 --- seaweed-block/docs/design/invariants.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 7847a9c0a8..e8f2101ff6 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -403,7 +403,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -185 rows: 163 ACTIVE, 19 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 170 new. +186 rows: 164 ACTIVE, 19 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 171 new. The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger. @@ -697,6 +697,7 @@ Notes: | `INV-CSI-CONSUMES-AUTHORITY-001` | CSI never imports authority code or builds assignment facts; it takes the publish target from blockmaster and refreshes it before a stage, and blockmaster mints the IDs of the events CSI reports. | M2 (read side) | `core/csi/master_backend.go` `LookupPublishTarget`; `core/csi/node.go` `refreshPublishContext`; `core/host/master/observation_service.go` `ReportClusterEvent` | `TestG15a_CSI_DoesNotImportAuthorityOrConstructAssignmentFacts` (`core/csi/boundary_guard_test.go`); `TestG15e_CSIReattachUsesFreshPublishTargetAfterUnstage` (`core/csi/node_test.go`); `TestObservationService_ReportClusterEventAppearsInVolumeTimeline` (`core/host/master/observation_service_test.go`) | — | ACTIVE | | `INV-K8S-NONLOOPBACK-001` | Generated multi-node Helm values enable external iSCSI, external status and loopback rejection; with rejection enabled CSI never publishes a loopback target and fails closed when only loopback targets exist. | M2 (read side) | `cmd/sw-block/main.go` `runOpsGenerateHelmValues`; `core/csi/master_backend.go` `rejectFrontendAddr` | `TestOpsGenerateHelmValuesMultiNodeExternalISCSI` (`cmd/sw-block/main_test.go`); `TestNodeLoss_ControlStatusLookup_RejectsLoopbackPublishTargetsWhenEnabled`, `TestNodeLoss_ControlStatusLookup_FailClosedWhenOnlyLoopbackTargets` (`core/csi/master_backend_test.go`) | — | ACTIVE | | `INV-OBS-PRODUCT-EVENTS-001` | blockmaster records placement-verified, promotion-candidate-evaluation and authority-published events, and the CSI node reports `csi_reattach_observed` after a successful stage. | M3 promotion decision (observation) | `core/host/master/product_loop.go` `recordPlacementVerifiedEvents`, `recordPromotionEvaluationEvents`, `recordAuthorityPublishedEvent` | `TestMasterTimeline_RecordsPlacementVerified`, `TestMasterTimeline_RecordsPromotionCandidateEvaluation`, `TestMasterTimeline_RecordsAuthorityPublishedAfterMint` (`core/host/master/event_ring_test.go`); `TestNodeStage_ReportsCSIReattachObservedAfterSuccessfulStage` (`core/csi/node_test.go`) | — | ACTIVE | +| `INV-OBS-SLOT-FROM-EXPECTED-SERVER-001` | A replica's slot in the assembled topology takes addresses and health only from a fresh fact reported by the server its expected slot names; another server's fact for the same replica is never used, so with none from that server the slot is a placeholder. | AUTHORITY/ORDER: observation to assignment line | `core/authority/snapshot_builder.go` `assembleVolumeTopology` | `TestAssembleVolumeTopology_SlotFactOnlyFromTheExpectedServer` (`core/authority/snapshot_slot_server_test.go`) | — (pure assembly; the unit test is the proof form) | ACTIVE | | `INV-HELM-RF-NODECOUNT-001` | Generated Helm values fail closed when the requested replication factor exceeds the selected Ready schedulable node count. | M3 (configuration) | `cmd/sw-block/main.go` `runOpsGenerateHelmValues`, `selectHelmValuesNodes` | `TestOpsGenerateHelmValuesRejectsRFAboveSelectedNodes` (`cmd/sw-block/main_test.go`) | — | ACTIVE | | `INV-HOSTPATH-TRANSPARENT-001` | The read model reports transparent host-path recovery only with a multipathed, Active/Optimized, stale-fenced path, writer and reader checks, and the same pod UID. | K8s readiness model | `core/ops/managed_volume_model.go` `classifyManagedVolume`, `deriveManagedVolumeStates` | `TestManagedVolumeProjection_TransparentISCSIALUARecovered`, `TestManagedVolumeProjection_MissingMultipathBlocksTransparentClaim` (`core/ops/managed_volume_model_test.go`) | — | ACTIVE | | `INV-K8S-REATTACH-001` | A CSI re-stage after failover uses the fresh publish target, and the read model reports recovery by reattach only with CSI reattach observed and a verified reader. | K8s readiness model | `core/csi/node.go` `refreshPublishContext`; `core/ops/managed_volume_model.go` `classifyManagedVolume` | `TestG15e_CSIReattachUsesFreshPublishTargetAfterUnstage` (`core/csi/node_test.go`); `TestManagedVolumeProjection_NodeLossReattachRecovered` (`core/ops/managed_volume_model_test.go`) | — | ACTIVE |