wip red: an unfenced promotion and the unsupported path's failover

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-25 05:43:01 -08:00
1 parent ccb0683605
commit 520fd27de0
5 files changed
+67

No files matched your search

+4
View File
@@ -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.
@@ -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)
}
}
@@ -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.
@@ -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)
}
@@ -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{})