From 520fd27de02369d43d498bdc68d895efa4774f45 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 05:43:01 -0800 Subject: [PATCH] wip red: an unfenced promotion and the unsupported path's failover Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/adapter/normalize.go | 4 +++ .../authority/bind_volume_genesis_test.go | 25 +++++++++++++++++ seaweed-block/core/authority/directive.go | 4 +++ .../core/host/master/fence_fakes_test.go | 6 ++++ .../master/primary_boot_grace_gate_test.go | 28 +++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/seaweed-block/core/adapter/normalize.go b/seaweed-block/core/adapter/normalize.go index b9c1cecec5..7111f0bb10 100644 --- a/seaweed-block/core/adapter/normalize.go +++ b/seaweed-block/core/adapter/normalize.go @@ -62,6 +62,10 @@ type PrimaryEvidence struct { // answering (a fencing round); the line is minted only at this epoch. // 0: no fencing round (a planned move). FencedEpoch uint64 + // Planned: a guarded planned move (the target in every acknowledgement + // set while the current primary is alive), the one promotion minted + // without a fencing round. + Planned bool } // ProbeResult is the outcome of a transport probe. diff --git a/seaweed-block/core/authority/bind_volume_genesis_test.go b/seaweed-block/core/authority/bind_volume_genesis_test.go index b00da638dd..ed62acdfc1 100644 --- a/seaweed-block/core/authority/bind_volume_genesis_test.go +++ b/seaweed-block/core/authority/bind_volume_genesis_test.go @@ -3,6 +3,8 @@ package authority import ( "errors" "testing" + + "github.com/seaweedfs/seaweed-block/core/adapter" ) // #183: Bind is genesis for the volume. These cover the branches around @@ -145,3 +147,26 @@ func TestPublisher_AFencedDecisionIsMintedOnlyAtItsFencedEpoch(t *testing.T) { t.Fatalf("a decision fenced at the next epoch: %v", err) } } + +// A promotion is minted only on a fencing round's decision or as a guarded +// planned move: one with neither (a decision read from a plain round) is +// refused, so no path can skip the fence. +func TestPublisher_AnUnfencedPromotionIsRefused(t *testing.T) { + pub := NewPublisher(NewStaticDirective(nil)) + if err := pub.apply(bindAsk("v1", "r1")); err != nil { + t.Fatal(err) + } + ask := bindAsk("v1", "r2") + ask.Intent = IntentReassign + ask.Evidence = adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: 9} + if err := pub.apply(ask); !errors.Is(err, ErrPromotionUnfenced) { + t.Fatalf("an unfenced, unplanned promotion: %v; want ErrPromotionUnfenced", err) + } + if line, _ := pub.VolumeAuthorityLine("v1"); line.ReplicaID != "r1" || line.Epoch != 1 { + t.Fatalf("the line moved: %+v", line) + } + ask.Evidence.Planned = true + if err := pub.apply(ask); err != nil { + t.Fatalf("a guarded planned move: %v", err) + } +} diff --git a/seaweed-block/core/authority/directive.go b/seaweed-block/core/authority/directive.go index 05d7eb3953..edeac8183e 100644 --- a/seaweed-block/core/authority/directive.go +++ b/seaweed-block/core/authority/directive.go @@ -83,6 +83,10 @@ var ErrReassignWithoutKind = errors.New("authority: a reassign needs a primary k // e+1 arrived after the volume's line left e; the publisher mints nothing. var ErrFenceSuperseded = errors.New("authority: the fencing round's epoch is no longer the next epoch of the line") +// ErrPromotionUnfenced: a promotion carried neither a fencing round's epoch +// nor the planned-move mark; the publisher mints nothing. +var ErrPromotionUnfenced = errors.New("authority: a promotion needs a fencing round's decision or a guarded planned move") + // Directive is the input side of the authority route. A Directive // emits one AssignmentAsk at a time. The publisher's Run loop calls // Next repeatedly until ctx cancellation. diff --git a/seaweed-block/core/host/master/fence_fakes_test.go b/seaweed-block/core/host/master/fence_fakes_test.go index 6b701cd81b..454540862f 100644 --- a/seaweed-block/core/host/master/fence_fakes_test.go +++ b/seaweed-block/core/host/master/fence_fakes_test.go @@ -22,6 +22,12 @@ func (s staticPromotionProbe) FencePromotionCandidates(_ string, current authori } func (p *switchProbe) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) { + p.mu.Lock() + silent := p.fenceSilent + p.mu.Unlock() + if silent { + return PromotionProbeResult{FencedEpoch: current.Epoch + 1}, nil + } return fenceObeyed(current, survivors) } diff --git a/seaweed-block/core/host/master/primary_boot_grace_gate_test.go b/seaweed-block/core/host/master/primary_boot_grace_gate_test.go index 8e47b0b894..6f34395ebd 100644 --- a/seaweed-block/core/host/master/primary_boot_grace_gate_test.go +++ b/seaweed-block/core/host/master/primary_boot_grace_gate_test.go @@ -65,6 +65,7 @@ func ingestRF3Incarnations(t *testing.T, h *Host, r1, r2, r3 rf3Slot) { type switchProbe struct { mu sync.Mutex r3End uint64 + fenceSilent bool // no survivor answers the fencing round currentReady bool // currentUnknown: the current primary did not answer (status GET // refused or timed out), so CurrentKnown is false. @@ -243,6 +244,33 @@ func TestUnsupportedPathNeverReassignsOnAnUnansweredPrimary(t *testing.T) { expectLineStaysR1(t, h, "still unanswered on the next tick") } +// The unsupported path decides a failover on a fencing round too: with the +// round unanswered nothing is published, however ready the survivor looked +// in the plain round; answered, the line carries the fenced epoch. +func TestUnsupportedPathFailsOverOnlyOnAFencingRound(t *testing.T) { + ineligible := restarting + ineligible.eligible = false + t.Run("fencing round unanswered", func(t *testing.T) { + h := newBootGraceMaster(t, Config{}) + defer closeTestMaster(t, h) + p := probeOf(t, h) + p.mu.Lock() + p.fenceSilent = true + p.mu.Unlock() + unsupportedTick(t, h, ineligible) + expectLineStaysR1(t, h, "the survivors did not answer the fencing round") + }) + t.Run("fencing round answered", func(t *testing.T) { + h := newBootGraceMaster(t, Config{}) + defer closeTestMaster(t, h) + unsupportedTick(t, h, ineligible) + expectFailoverToR2(t, h, "fenced survivors") + if info, _ := h.Publisher().LastPublished("vol-rf3", "r2"); info.Primary.FencedEpoch != 2 { + t.Fatalf("failover line evidence %+v; want fenced at 2", info.Primary) + } + }) +} + // An explicit unhealthy current primary gets no grace on this path. func TestBootGrace_UnsupportedPathUnhealthyCurrentFailsOverAtOnce(t *testing.T) { h := newBootGraceMaster(t, Config{})