diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index c04b210970..fe86039969 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -627,6 +627,10 @@ func promotionAllowedReplicas(result PromotionProbeResult, ok bool, peerCount in } frontierKnown := result.SyncAckKnown || result.SyncAckLSN > 0 if isQuorumAckProfile(result.AckProfile) && !frontierKnown { + // Survivors are counted only from result, the probe run for this + // tick, and freshPeers, read for this tick. Nothing from an + // earlier tick is kept: a survivor seen ready last tick and not + // seen now does not count. seen := map[string]bool{} for _, candidate := range result.Candidates { if candidate.ReplicaID != "" && candidate.Ready && freshPeers[candidate.ReplicaID] { diff --git a/seaweed-block/core/host/master/promotion_frontier_coverage_test.go b/seaweed-block/core/host/master/promotion_frontier_coverage_test.go index c134b7063e..41bf39f282 100644 --- a/seaweed-block/core/host/master/promotion_frontier_coverage_test.go +++ b/seaweed-block/core/host/master/promotion_frontier_coverage_test.go @@ -2,6 +2,7 @@ package master import ( "reflect" + "sync" "testing" "time" @@ -163,6 +164,81 @@ func TestFreshPromotionPeers_UsesObservationFreshness(t *testing.T) { } } +type swapPromotionProbe struct { + mu sync.Mutex + result PromotionProbeResult +} + +func (p *swapPromotionProbe) set(r PromotionProbeResult) { + p.mu.Lock() + defer p.mu.Unlock() + p.result = r +} + +func (p *swapPromotionProbe) ProbePromotionCandidates(string, authority.AuthorityBasis, []authority.ReplicaCandidate) (PromotionProbeResult, error) { + p.mu.Lock() + defer p.mu.Unlock() + return p.result, nil +} + +// Survivors count only from this tick's probe: r3 was probed ready on the +// previous tick, but this tick its probe is missing, so with an unknown +// frontier r2 alone cannot be promoted. +func TestProductLoop_UnknownFrontierSurvivorReadyLastTickMissingNowRefused(t *testing.T) { + h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 3}) + defer closeTestMaster(t, h) + probe := &swapPromotionProbe{} + h.SetPromotionEvidenceProvider(probe) + seedRF3Placement(t, h) + ingestRF3Observation(t, h, true, true, true) + if _, err := h.RunLifecycleProductTick(); err != nil { + t.Fatal(err) + } + if initial := waitAuthorityLine(t, h.Publisher(), "vol-rf3"); initial.ReplicaID != "r1" { + t.Fatalf("initial line=%+v want r1", initial) + } + + // Previous tick: both survivors probed ready, current primary ready. + probe.set(PromotionProbeResult{ + AckProfile: "sync-quorum", + CurrentKnown: true, + Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true, DurableLSN: 90}, + Candidates: []PromotionCandidateEvidence{ + {ReplicaID: "r2", Ready: true, DurableLSN: 90}, + {ReplicaID: "r3", Ready: true, DurableLSN: 90}, + }, + }) + ingestRF3Observation(t, h, true, true, true) + prev, err := h.RunLifecycleProductTick() + if err != nil { + t.Fatal(err) + } + if prev.PromotionProbes != 1 || prev.PromotionBlocked != 0 { + t.Fatalf("previous tick=%+v want one probe that admits both survivors", prev) + } + + // This tick: the primary is lost and r3's probe is missing. + probe.set(PromotionProbeResult{ + AckProfile: "sync-quorum", + Candidates: []PromotionCandidateEvidence{ + {ReplicaID: "r2", Ready: true, DurableLSN: 90}, + {ReplicaID: "r3", ProbeAddr: "missing"}, + }, + }) + ingestRF3Observation(t, h, false, true, true) + now, err := h.RunLifecycleProductTick() + if err != nil { + t.Fatal(err) + } + if now.PromotionProbes != 1 || now.PromotionBlocked != 1 { + t.Fatalf("this tick=%+v want the promotion blocked: r3 is not seen this tick", now) + } + time.Sleep(200 * time.Millisecond) + if line, _ := h.Publisher().VolumeAuthorityLine("vol-rf3"); line.ReplicaID != "r1" { + t.Fatalf("authority moved to %+v on a partial view", line) + } +} + // RF2 never consults the RF3 promotion gate: a probe that would refuse every // candidate (unknown frontier, no survivors) does not stop RF2 failover. func TestMountedFailover_ProductLoopRF2IgnoresRF3FrontierGate(t *testing.T) {