# Conflicts:
#	docs/design/invariants.md
This commit is contained in:
pingqiu committed 2026-11-21 16:11:43 -08:00
commit 50d4b0357f
3 files changed
+52 -1

No files matched your search

@@ -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
}
@@ -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)
}
}
+2 -1
View File
@@ -409,7 +409,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO
## Part B. Invariant ledger
188 rows: 166 ACTIVE, 19 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 173 new.
189 rows: 167 ACTIVE, 19 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 174 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.
@@ -706,6 +706,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 |