Merge pull request #551 from seaweedfs/fix/no-reassign-on-unknown-primary

fix(master): never reassign on a current primary that did not answer
This commit is contained in:
Ping Qiu authored and GitHub committed 2026-11-24 12:52:28 -08:00
commit c52efbb5ee
6 files changed
+42 -21

No files matched your search

@@ -64,6 +64,9 @@ func ingestRF3Incarnations(t *testing.T, h *Host, r1, r2, r3 rf3Slot) {
type switchProbe struct {
mu sync.Mutex
currentReady bool
// currentUnknown: the current primary did not answer (status GET
// refused or timed out), so CurrentKnown is false.
currentUnknown bool
// When hold is set, a probe signals entered and then blocks until
// release is closed.
hold bool
@@ -99,7 +102,7 @@ func (p *switchProbe) ProbePromotionCandidates(volumeID string, current authorit
// Only r2 is seen, so its promotion needs a known frontier
// it covers (#181); r3 is silent in these tests.
SyncAckLSN: 70,
CurrentKnown: true,
CurrentKnown: !p.currentUnknown,
Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: p.currentReady, DurableLSN: 70},
Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 70}},
}, nil
@@ -213,6 +216,24 @@ func TestBootGrace_UnsupportedPathHonorsGraceThenFailsOver(t *testing.T) {
expectFailoverToR2(t, h, "unready past its boot grace")
}
// A current primary that did not answer its status probe is UNKNOWN, not
// failed: the unsupported path never reassigns on it, however ready the
// survivor (an unknown fact is never read as failed). Only a positive
// not-ready report from the primary itself moves the line.
func TestUnsupportedPathNeverReassignsOnAnUnansweredPrimary(t *testing.T) {
h := newBootGraceMaster(t, Config{})
defer closeTestMaster(t, h)
p := probeOf(t, h)
p.mu.Lock()
p.currentUnknown = true
p.mu.Unlock()
unsupportedTick(t, h, readySlot("r1-a"))
expectLineStaysR1(t, h, "status probe of the current primary timed out")
unsupportedTick(t, h, readySlot("r1-a"))
expectLineStaysR1(t, h, "still unanswered on the next tick")
}
// An explicit unhealthy current primary gets no grace on this path.
func TestBootGrace_UnsupportedPathUnhealthyCurrentFailsOverAtOnce(t *testing.T) {
h := newBootGraceMaster(t, Config{})
@@ -336,7 +336,9 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
break
}
}
if enabledCandidate && (!result.CurrentKnown || !result.Current.Ready) {
// Only a positive not-ready report from the current primary moves the
// line. A primary that did not answer is unknown, never failed.
if enabledCandidate && result.CurrentKnown && !result.Current.Ready {
// Unsupported does not mean the current primary is unhealthy:
// a different slot may be stale. Judge the current primary
// from its own fresh heartbeat slot, never from placement.
@@ -544,7 +544,7 @@ func TestMountedFailover_ProductLoopRF3ProbeCanAuthorizeStaleHeartbeatReadiness(
}
}
func TestMountedFailover_ProductLoopRF3PromotesWhenCurrentSlotMissingButSurvivorProbeReady(t *testing.T) {
func TestMountedFailover_ProductLoopRF3DoesNotReassignWhenCurrentSlotMissing(t *testing.T) {
h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{
ExpectedSlotsPerVolume: 3,
})
@@ -570,28 +570,22 @@ func TestMountedFailover_ProductLoopRF3PromotesWhenCurrentSlotMissingButSurvivor
}
// K8s can keep the server/node fresh while the generated primary
// blockvolume pod is gone. That produces PartialInventory and excludes
// the volume from the normal supported snapshot; the product loop must
// still use placement + probe evidence to promote an eligible survivor.
// blockvolume pod is gone: PartialInventory, and the current primary's
// status cannot be read (CurrentKnown false). That is UNKNOWN, not
// failed: on a partition the primary may still be serving, so no
// automatic reassign happens, however ready the survivors. Failover is
// an admin forced move with its barrier.
ingestRF3PartialInventoryMissingCurrent(t, h, "vol-rf3", "node-a", "node-b", "node-c")
placements := h.Lifecycle().Placements.ListPlacements()
report := authority.SupportabilityReport{Unsupported: map[string]authority.VolumeUnsupportedEvidence{
"vol-rf3": {VolumeID: "vol-rf3", Reasons: []string{authority.ReasonPartialInventory}},
}}
probes, blocked, asks := h.applyUnsupportedPromotionEvidenceGate(placements, report, nil)
if probes != 1 || blocked != 0 || len(asks) != 1 {
line, _ := h.Publisher().VolumeAuthorityLine("vol-rf3")
t.Fatalf("probes=%d blocked=%d asks=%+v placements=%+v line=%+v want one direct unsupported promotion ask", probes, blocked, asks, placements, line)
probes, _, asks := h.applyUnsupportedPromotionEvidenceGate(placements, report, nil)
if probes != 1 || len(asks) != 0 {
t.Fatalf("probes=%d asks=%+v; want one probe and no reassign for an unanswered current primary", probes, asks)
}
if asks[0].ReplicaID != "r3" || asks[0].Intent != authority.IntentReassign {
t.Fatalf("ask=%+v want highest durable survivor r3 reassign", asks[0])
}
if err := h.ctrl.SubmitAssignmentAsk(asks[0]); err != nil {
t.Fatalf("submit unsupported promotion ask: %v", err)
}
failover := waitAuthorityReplica(t, h.Publisher(), "vol-rf3", "r3")
if failover.Epoch != 2 || failover.EndpointVersion != 1 {
t.Fatalf("failover line=%+v want highest durable survivor r3@2/1", failover)
if line, _ := h.Publisher().VolumeAuthorityLine("vol-rf3"); line.ReplicaID != "r1" || line.Epoch != initial.Epoch {
t.Fatalf("line=%+v; want r1@%d unchanged", line, initial.Epoch)
}
}
+1
View File
@@ -205,6 +205,7 @@ This alpha MVP does not yet claim:
- production-ready durability
- multi-node Kubernetes operation
- failover while a pod remains mounted
- automatic failover when the primary node or pod is lost: blockmaster does not reassign on a primary it cannot read; failover is a manual admin action (a `SwBlockReplicaFailback` with the expected current line, applied for the failback executor, which calls blockmaster's admin `ExecuteFailback`)
- real operator reconciliation
- backend data shredding on delete
- snapshots, clone, resize, block mode, topology spread, or NVMe-oF
+2 -1
View File
@@ -516,7 +516,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO
## Part B. Invariant ledger
326 rows: 255 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 311 new.
327 rows: 256 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 312 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.
@@ -986,6 +986,7 @@ Notes:
| `INV-FENCE-STALE-PRIMARY-001` | Once a primary has observed a newer line for another replica, its backend refuses `Read`, `Write` and `Sync`, and replicas refuse its frames below their epoch floor. | M3 Primary → Supporting \| Excluded | `core/host/volume/projection_bridge.go` `projectionWithSupersede`; `core/frontend/durable/storage_adapter.go` `lineageCheck`; `core/transport/replica.go` `admitMutation` | `TestG8A_SupersedeFact_FencesOldPrimaryDurableBackend` (`core/host/volume/g8a_stale_fence_test.go`); `TestG2_PromotedHostRefusesShipFromDeposedPrimary` (`core/host/volume/g2_self_fence_test.go`) | `ReplicationFailover` `NoStaleAck` | ACTIVE |
| `INV-PROMOTE-FRONTIER-001` | With a known required acknowledgement frontier under `sync_quorum` or `sync_all`, the RF=3 promotion gate allows only probed-ready candidates whose durable LSN is at least the required LSN. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas`, `applyPromotionEvidenceGate`; `core/host/master/promotion_probe.go` (`SyncAckKnown`); `core/engine/promotion_ready.go` `BuildPromotionReadyFact` | `TestMountedFailover_ProductLoopRF3PromotesCandidateCoveringSyncAckProbe` (`core/host/master/product_loop_test.go`); `TestPromotionAllowedReplicas_RequiredFrontierCoverage`, `TestWorkloadPlanProvider_RequiredFrontierKnownness` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-PROMOTE-FRONTIER-PROBE-001` | For a volume with three or more slots, the gate allows no candidate unless this tick's promotion probe succeeded with a known ack profile. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate`, `promotionAllowedReplicas` | `TestMountedFailover_ProductLoopRF3BlocksFailoverWithoutFreshPromotionProbe` (`core/host/master/product_loop_test.go`); `TestMountedFailover_ProductLoopRF2IgnoresRF3FrontierGate` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-PROMOTE-UNKNOWN-CURRENT-001` | A current primary whose status cannot be read (probe refused, timed out, pod gone) is unknown, never failed: no promotion path reassigns on it; a direct reassign needs the primary's own not-ready report. | M3 Primary → promotion candidate (both promotion paths) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate` (supported path), `applyUnsupportedPromotionEvidenceGate` (unsupported path) | `TestUnsupportedPathNeverReassignsOnAnUnansweredPrimary` (`core/host/master/primary_boot_grace_gate_test.go`); `TestMountedFailover_ProductLoopRF3DoesNotReassignWhenCurrentSlotMissing` (`core/host/master/product_loop_test.go`). Limits: Kubernetes alpha failover on node or pod loss is a manual admin action in this release | — | ACTIVE |
| `INV-PROMOTE-FRONTIER-UNKNOWN-001` | With an unknown frontier under `sync_quorum` or `sync_all`, the gate allows the highest-durable ready candidate only if at least N_peers-K+1 of the N_peers peers are probed ready this tick and have a fresh heartbeat (K as in `waitForSyncAcks`); else none. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas`, `unknownFrontierSurvivorsNeeded`, `freshPromotionPeers`; `core/replication/async_ack.go` `waitForSyncAcks` | `TestMountedFailover_ProductLoopRF3UnknownRequiredLSNFallsBackToHighestDurableLSN` (`core/host/master/product_loop_test.go`); `TestProductLoop_MissingRequiredFrontierRefusesRF3Promotion` (`core/host/master/promotion_missing_frontier_regression_test.go`); `TestUnknownFrontierSurvivorsNeeded`, `TestFreshPromotionPeers_UsesObservationFreshness`, `TestProductLoop_UnknownFrontierSurvivorReadyLastTickMissingNowRefused` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-PROMOTE-FRONTIER-BEST-EFFORT-001` | Under `best_effort`, the gate allows no candidate when a nonzero required frontier is given, and otherwise allows the highest-durable ready candidate. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas` | `TestMountedFailover_ProductLoopRF3BestEffortUnknownRequiredLSNCanSelectHighestDurableLSN`, `TestMountedFailover_ProductLoopRF3RejectsBestEffortProbeForHA` (`core/host/master/product_loop_test.go`); `TestPromotionAllowedReplicas_RequiredFrontierCoverage` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `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 |
@@ -210,7 +210,9 @@ The volume computes whether it may become primary; blockmaster decides; only the
**RF=3 gate** (`core/host/master/promotion_probe.go`, `promotionAllowedReplicas`, `chooseAllowedPromotionTarget`): no promotion when the probe failed or is not installed, or the ack profile is unknown; a candidate is skipped when it is not `replica_ready` with a known frontier, or its durable LSN is below the required frontier. The decision is recorded as an ops event (`candidate_covers_required_frontier`, `candidate_frontier_behind`, `no_promotion_ready_candidate`). The required frontier per volume (`RequiredLSNByVolume`) is not set by `cmd/blockmaster` today, so the frontier is unknown and coverage is proven from the survivors instead: with `sync_quorum` or `sync_all`, the ready candidate with the highest durable LSN is promoted only when at least P-K+1 of the P peers are probed ready (known durable LSN) and have a fresh heartbeat, where K is the number of peer acks a write needs (`waitForSyncAcks`: P for `sync_all`, (P+1)/2 for `sync_quorum`). Any P-K+1 peers include one that holds every acknowledged write that their sampled frontiers represent. The probes of one tick are snapshots, not a fence: a primary that is still running can acknowledge after a sample was taken (for example, r3 reports 70 in a held probe response, the old primary then acknowledges 71, and r2 at 70 is still selected). That is the missing primary lease below (§12, #195). For RF=3 that is both peers under `sync_quorum` and one under `sync_all`; with fewer, nothing is promoted. An unknown frontier is never read as zero. `best_effort` is unchanged (§12).
**What blocks a promotion:** any engine reason above; `unhealthy_reason` set or withdrawn; an unreachable or ineligible server; boot grace still holding; a current primary whose probe is ready; a snapshot rejected for slot count; slots that changed while the probe ran.
**A current primary that does not answer is unknown, not failed.** When its status cannot be read (a pod gone, a partition), blockmaster does not reassign on either path, however ready the survivors: on a partition the primary may still be serving. Only the primary's own not-ready report moves the line automatically; otherwise failover is a manual admin action in this release.
**What blocks a promotion:** any engine reason above; a current primary whose status cannot be read; `unhealthy_reason` set or withdrawn; an unreachable or ineligible server; boot grace still holding; a current primary whose probe is ready; a snapshot rejected for slot count; slots that changed while the probe ran.
```mermaid
stateDiagram-v2