mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
wip: one decision function on every failover path; a promotion states its basis; no fence in boot grace
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
520fd27de0
commit
b2cb5d4879
9 files changed
+102
-12
No files matched your search
@@ -62,12 +62,28 @@ 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
|
||||
// Basis is why a promotion may be minted; a promotion without one is
|
||||
// refused.
|
||||
Basis PromotionBasis
|
||||
}
|
||||
|
||||
// PromotionBasis is the one reason a promotion is minted.
|
||||
type PromotionBasis uint8
|
||||
|
||||
const (
|
||||
BasisNone PromotionBasis = iota
|
||||
// BasisFenced: decided on a fencing round's answers; FencedEpoch is the
|
||||
// epoch minted.
|
||||
BasisFenced
|
||||
// BasisPlanned: a planned move after its guard (the target in every
|
||||
// acknowledgement set while the current primary is alive); no fencing
|
||||
// round, FencedEpoch 0.
|
||||
BasisPlanned
|
||||
// BasisHeal: the line's own primary continued at FencedEpoch after a
|
||||
// fencing round that published nothing.
|
||||
BasisHeal
|
||||
)
|
||||
|
||||
// ProbeResult is the outcome of a transport probe.
|
||||
type ProbeResult struct {
|
||||
ReplicaID string
|
||||
|
||||
@@ -595,6 +595,15 @@ func (p *Publisher) applyWithWorkspaceMove(ask AssignmentAsk, grant *workspaceGr
|
||||
p.mu.Unlock()
|
||||
return fmt.Errorf("%w: volume %s fenced at %d, the next epoch is %d", ErrFenceSuperseded, ask.VolumeID, ask.Evidence.FencedEpoch, next.Epoch)
|
||||
}
|
||||
// A promotion states its basis, exactly one: fenced (at this epoch),
|
||||
// planned (after the planned-move guard, no fence), or heal (the
|
||||
// line's own primary, at this epoch). No path mints one without.
|
||||
if ask.Evidence.Kind == adapter.PrimaryKindPromotion {
|
||||
if err := promotionBasisHolds(ask, next.Epoch, p.state, maxEpoch); err != nil {
|
||||
p.mu.Unlock()
|
||||
return fmt.Errorf("%w: volume %s replica %s: %v", ErrPromotionUnfenced, ask.VolumeID, ask.ReplicaID, err)
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
p.mu.Unlock()
|
||||
|
||||
@@ -165,7 +165,16 @@ func TestPublisher_AnUnfencedPromotionIsRefused(t *testing.T) {
|
||||
if line, _ := pub.VolumeAuthorityLine("v1"); line.ReplicaID != "r1" || line.Epoch != 1 {
|
||||
t.Fatalf("the line moved: %+v", line)
|
||||
}
|
||||
ask.Evidence.Planned = true
|
||||
ask.Evidence.Basis = adapter.BasisFenced // but fenced at another epoch
|
||||
ask.Evidence.FencedEpoch = 3
|
||||
if err := pub.apply(ask); err == nil {
|
||||
t.Fatal("a fenced basis at another epoch was minted")
|
||||
}
|
||||
ask.Evidence.Basis, ask.Evidence.FencedEpoch = adapter.BasisHeal, 2 // r2 is not the line's primary
|
||||
if err := pub.apply(ask); !errors.Is(err, ErrPromotionUnfenced) {
|
||||
t.Fatalf("a heal of another replica: %v; want ErrPromotionUnfenced", err)
|
||||
}
|
||||
ask.Evidence.Basis, ask.Evidence.FencedEpoch = adapter.BasisPlanned, 0
|
||||
if err := pub.apply(ask); err != nil {
|
||||
t.Fatalf("a guarded planned move: %v", err)
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ func (c *TopologyController) decideVolume(
|
||||
DataAddr: target.DataAddr,
|
||||
CtrlAddr: target.CtrlAddr,
|
||||
Intent: IntentReassign,
|
||||
Evidence: target.PromotionEvidence,
|
||||
Evidence: plannedEvidence(target.PromotionEvidence),
|
||||
}, "rebalance", true
|
||||
}
|
||||
return AssignmentAsk{}, "", false
|
||||
@@ -744,3 +744,10 @@ func sameAsk(a, b AssignmentAsk) bool {
|
||||
a.CtrlAddr == b.CtrlAddr &&
|
||||
a.Intent == b.Intent
|
||||
}
|
||||
|
||||
// plannedEvidence is a rebalance's evidence: the gate's probe of the target,
|
||||
// a planned move after the planned-move guard (PlannedMoveAllowed).
|
||||
func plannedEvidence(ev adapter.PrimaryEvidence) adapter.PrimaryEvidence {
|
||||
ev.FencedEpoch, ev.Basis = 0, adapter.BasisPlanned
|
||||
return ev
|
||||
}
|
||||
@@ -14,6 +14,7 @@ package authority
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -87,6 +88,32 @@ var ErrFenceSuperseded = errors.New("authority: the fencing round's epoch is no
|
||||
// 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")
|
||||
|
||||
// promotionBasisHolds checks a promotion's basis against the epoch it is
|
||||
// minted at; for a heal, the target must be the replica the line names now.
|
||||
func promotionBasisHolds(ask AssignmentAsk, epoch uint64, state map[subKey]assignmentState, lineEpoch uint64) error {
|
||||
ev := ask.Evidence
|
||||
switch ev.Basis {
|
||||
case adapter.BasisFenced:
|
||||
if ev.FencedEpoch != epoch {
|
||||
return fmt.Errorf("fenced at %d, minted at %d", ev.FencedEpoch, epoch)
|
||||
}
|
||||
case adapter.BasisPlanned:
|
||||
if ev.FencedEpoch != 0 {
|
||||
return fmt.Errorf("a planned move carries no fenced epoch (%d)", ev.FencedEpoch)
|
||||
}
|
||||
case adapter.BasisHeal:
|
||||
if ev.FencedEpoch != epoch {
|
||||
return fmt.Errorf("heal fenced at %d, minted at %d", ev.FencedEpoch, epoch)
|
||||
}
|
||||
if cur, ok := state[subKey{volumeID: ask.VolumeID, replicaID: ask.ReplicaID}]; !ok || !cur.present || cur.info.Epoch != lineEpoch {
|
||||
return fmt.Errorf("a heal continues the line's own primary; %s is not it", ask.ReplicaID)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("no basis")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -4,7 +4,8 @@ import "github.com/seaweedfs/seaweed-block/core/adapter"
|
||||
|
||||
// testPromotion is a reassign's kind in tests of the publisher's epoch
|
||||
// mechanics: a promotion decided by the gate.
|
||||
var testPromotion = adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion}
|
||||
// testPromotion: the tests here stand in for the master as a planned move.
|
||||
var testPromotion = adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, Basis: adapter.BasisPlanned}
|
||||
|
||||
// gatedSink stands in, in these tests, for the master's promotion gate: it
|
||||
// gives every slot the gate would allow (ready, reachable, eligible, not
|
||||
|
||||
@@ -272,7 +272,7 @@ func (p *Publisher) MoveWorkspace(ctx context.Context, req WorkspaceMoveRequest,
|
||||
if replay {
|
||||
return r, nil
|
||||
}
|
||||
kind := adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion} // a clean move: the source detached at its sealed image
|
||||
kind := adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, Basis: adapter.BasisPlanned} // a clean move: the source detached at its sealed image
|
||||
if req.Kind == "forced" {
|
||||
kind = adapter.PrimaryEvidence{Kind: adapter.PrimaryKindForced}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@ func (h *Host) plannedMoveEvidence(volumeID, target string) (adapter.PrimaryEvid
|
||||
}
|
||||
for _, c := range result.Candidates {
|
||||
if c.ReplicaID == target && c.Ready {
|
||||
return promotionEvidenceFor(result, target), nil
|
||||
ev := promotionEvidenceFor(result, target)
|
||||
ev.FencedEpoch, ev.Basis = 0, adapter.BasisPlanned
|
||||
return ev, nil
|
||||
}
|
||||
}
|
||||
return adapter.PrimaryEvidence{}, fmt.Errorf("planned move: replica %s did not answer the probe round ready (caught up, epoch table valid)", target)
|
||||
|
||||
@@ -273,7 +273,10 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int,
|
||||
// ready): the decision is read from a fencing round, never from the
|
||||
// plain answers, so no write the old primary gets acknowledged after
|
||||
// a survivor answered can be missing from the target.
|
||||
replacing := !currentAcceptable || (result.CurrentKnown && !result.Current.Ready)
|
||||
// A primary in its boot grace is not replaced, so no fencing round
|
||||
// cuts it off from its replicas while it starts.
|
||||
replacing := (!currentAcceptable || (result.CurrentKnown && !result.Current.Ready)) &&
|
||||
!h.primaryBootGraceHoldsNow(vol.VolumeID, vol.Authority.ReplicaID)
|
||||
// A survivor answering above the line was fenced by a round that
|
||||
// published nothing (e.g. before a master restart): heal.
|
||||
if ok && !replacing && floorAboveLine(result, vol.Authority.Epoch) {
|
||||
@@ -493,7 +496,7 @@ func (h *Host) healAfterFailedFence(volumeID string, current authority.Authority
|
||||
CtrlAddr: current.CtrlAddr,
|
||||
Intent: authority.IntentReassign,
|
||||
Evidence: adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: c.DurableLSN, DataEpoch: c.LastDataEpoch, DataFirstLSN: c.LastDataFirstLSN,
|
||||
StoreID: c.StoreID, FencedEpoch: current.Epoch + 1},
|
||||
StoreID: c.StoreID, FencedEpoch: current.Epoch + 1, Basis: adapter.BasisHeal},
|
||||
}, true
|
||||
}
|
||||
|
||||
@@ -573,6 +576,18 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
|
||||
h.log.Printf("blockmaster: promotion gate unsupported volume=%s current=%s not ready but in boot grace; no direct reassign", vol.VolumeID, current.ReplicaID)
|
||||
continue
|
||||
}
|
||||
// One decision function: the failover is read from a fencing
|
||||
// round here too, never from the plain answers.
|
||||
result, allowed = h.fencedDecision(vol.VolumeID, current, result, len(candidates))
|
||||
if len(allowed) == 0 {
|
||||
h.noteFencePending(vol.VolumeID, current.Epoch+1)
|
||||
if heal, healed := h.healAfterFailedFence(vol.VolumeID, current); healed {
|
||||
directAsks = append(directAsks, heal)
|
||||
} else {
|
||||
h.recordVolumeBlockedEvent(vol.VolumeID, ops.ReasonFenceRoundIncomplete)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if target, ok := chooseAllowedPromotionTarget(vol, result, allowed); ok {
|
||||
h.log.Printf("blockmaster: promotion gate unsupported volume=%s direct_reassign=%s current=%s", vol.VolumeID, target.ReplicaID, current.ReplicaID)
|
||||
directAsks = append(directAsks, authority.AssignmentAsk{
|
||||
@@ -894,7 +909,11 @@ func promotionAllowedReplicas(result PromotionProbeResult, ok bool, peerCount in
|
||||
func promotionEvidenceFor(result PromotionProbeResult, replicaID string) adapter.PrimaryEvidence {
|
||||
for _, c := range result.Candidates {
|
||||
if c.ReplicaID == replicaID {
|
||||
return adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: c.DurableLSN, DataEpoch: c.LastDataEpoch, DataFirstLSN: c.LastDataFirstLSN, StoreID: c.StoreID, FencedEpoch: result.FencedEpoch}
|
||||
ev := adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: c.DurableLSN, DataEpoch: c.LastDataEpoch, DataFirstLSN: c.LastDataFirstLSN, StoreID: c.StoreID, FencedEpoch: result.FencedEpoch}
|
||||
if result.FencedEpoch != 0 {
|
||||
ev.Basis = adapter.BasisFenced
|
||||
}
|
||||
return ev
|
||||
}
|
||||
}
|
||||
return adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion}
|
||||
|
||||
Reference in new issue
Block a user