mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
authority, master: a rebalance passes the planned-move guard
A rebalance moves the primary while it is alive, so it is a planned move, yet it needed only the gate's promotion evidence. Under RF3 sync_quorum the old primary can be acknowledged by the other replica alone while the target adopts. The gate now marks a slot PlannedMoveAllowed from the same plannedMoveAllowed(profile, replicas) a failback uses, and the controller publishes a rebalance only to such a slot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0129f0397
commit
d92cfe3748
5 files changed
+130
-5
No files matched your search
@@ -496,8 +496,10 @@ func (c *TopologyController) decideVolume(
|
||||
}
|
||||
if target, ok := chooseRebalanceCandidate(vol, current, serverIndex, currentLoad, projectedLoad, c.config.RebalanceSkew); ok {
|
||||
// A primary change goes out only with the promotion gate's
|
||||
// evidence for its target (one decider): none, no rebalance.
|
||||
if target.PromotionEvidence.Kind != adapter.PrimaryKindPromotion {
|
||||
// evidence for its target (one decider): none, no rebalance. The
|
||||
// current primary is alive, so it is a planned move: the same
|
||||
// guard as a failback (the target in every acknowledgement set).
|
||||
if target.PromotionEvidence.Kind != adapter.PrimaryKindPromotion || !target.PlannedMoveAllowed {
|
||||
return AssignmentAsk{}, "", false
|
||||
}
|
||||
return AssignmentAsk{
|
||||
|
||||
@@ -31,6 +31,9 @@ func candidate(replicaID, serverID, dataAddr, ctrlAddr string, evidence uint64)
|
||||
Eligible: true,
|
||||
EvidenceScore: evidence,
|
||||
PromotionEvidence: adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: evidence},
|
||||
// The gate's planned-move guard held (the profile puts the target in
|
||||
// every acknowledgement set).
|
||||
PlannedMoveAllowed: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,3 +521,41 @@ func TestTopologyController_NoPrimaryChangeWithoutTheGatesEvidence(t *testing.T)
|
||||
t.Fatalf("a primary change without the gate's evidence: %+v", ask)
|
||||
}
|
||||
}
|
||||
|
||||
// A rebalance moves the primary while it is alive: a planned move. With the
|
||||
// gate's evidence but not its planned-move guard (RF3 sync_quorum, or
|
||||
// best_effort), the controller publishes no rebalance.
|
||||
func TestTopologyController_RebalanceNeedsThePlannedMoveGuard(t *testing.T) {
|
||||
for _, guard := range []bool{true, false} {
|
||||
t.Run(map[bool]string{true: "guard held", false: "guard refused"}[guard], func(t *testing.T) {
|
||||
planned := func(c ReplicaCandidate) ReplicaCandidate { c.PlannedMoveAllowed = guard; return c }
|
||||
reader := newFakeBasisReader()
|
||||
reader.Set("v1", "v1r1", AuthorityBasis{Assigned: true, ReplicaID: "v1r1", Epoch: 1, EndpointVersion: 1, DataAddr: "d11", CtrlAddr: "c11"})
|
||||
reader.Set("v2", "v2r1", AuthorityBasis{Assigned: true, ReplicaID: "v2r1", Epoch: 1, EndpointVersion: 1, DataAddr: "d21", CtrlAddr: "c21"})
|
||||
reader.Set("v3", "v3r2", AuthorityBasis{Assigned: true, ReplicaID: "v3r2", Epoch: 1, EndpointVersion: 1, DataAddr: "d32", CtrlAddr: "c32"})
|
||||
ctrl := NewTopologyController(TopologyControllerConfig{RebalanceSkew: 1}, reader)
|
||||
snap := ClusterSnapshot{
|
||||
CollectedRevision: 3,
|
||||
Servers: []ServerObservation{{ServerID: "s1", Reachable: true, Eligible: true}, {ServerID: "s2", Reachable: true, Eligible: true}, {ServerID: "s3", Reachable: true, Eligible: true}},
|
||||
Volumes: []VolumeTopologySnapshot{
|
||||
clusterVolume("v1", AuthorityBasis{Assigned: true, ReplicaID: "v1r1", Epoch: 1, EndpointVersion: 1, DataAddr: "d11", CtrlAddr: "c11"},
|
||||
candidate("v1r1", "s1", "d11", "c11", 10), planned(candidate("v1r2", "s2", "d12", "c12", 10)), planned(candidate("v1r3", "s3", "d13", "c13", 30))),
|
||||
clusterVolume("v2", AuthorityBasis{Assigned: true, ReplicaID: "v2r1", Epoch: 1, EndpointVersion: 1, DataAddr: "d21", CtrlAddr: "c21"},
|
||||
candidate("v2r1", "s1", "d21", "c21", 10), planned(candidate("v2r2", "s2", "d22", "c22", 10)), planned(candidate("v2r3", "s3", "d23", "c23", 10))),
|
||||
clusterVolume("v3", AuthorityBasis{Assigned: true, ReplicaID: "v3r2", Epoch: 1, EndpointVersion: 1, DataAddr: "d32", CtrlAddr: "c32"},
|
||||
planned(candidate("v3r1", "s1", "d31", "c31", 10)), candidate("v3r2", "s2", "d32", "c32", 10), planned(candidate("v3r3", "s3", "d33", "c33", 10))),
|
||||
},
|
||||
}
|
||||
if err := ctrl.SubmitClusterSnapshot(snap); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
||||
defer cancel()
|
||||
ask, err := ctrl.Next(ctx)
|
||||
moved := err == nil && ask.Intent == IntentReassign
|
||||
if moved != guard {
|
||||
t.Fatalf("guard=%t: ask=%+v err=%v", guard, ask, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,13 @@ type ReplicaCandidate struct {
|
||||
// when it allowed it (kind PROMOTION); a reassign to it carries this to
|
||||
// the target. A replica without it is never promoted.
|
||||
PromotionEvidence adapter.PrimaryEvidence
|
||||
Eligible bool
|
||||
Withdrawn bool
|
||||
EvidenceScore uint64
|
||||
// PlannedMoveAllowed: the gate also allows a move to this replica while
|
||||
// the current primary is alive (the planned-move guard of the volume's
|
||||
// ack profile and replica count held). A rebalance needs it.
|
||||
PlannedMoveAllowed bool
|
||||
Eligible bool
|
||||
Withdrawn bool
|
||||
EvidenceScore uint64
|
||||
// Incarnation identifies the reporting volume process; it changes
|
||||
// on every process start. Empty from older volume binaries.
|
||||
Incarnation string
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
)
|
||||
|
||||
// Every primary change with a live current primary is a planned move and
|
||||
// passes one guard: a failback (plannedMoveEvidence) and a rebalance (the
|
||||
// gate's PlannedMoveAllowed on the slot, which the controller requires) are
|
||||
// allowed exactly when plannedMoveAllowed holds for the volume's ack profile
|
||||
// and replica count. One row per profile x RF; each row checks both paths.
|
||||
func TestPlannedMoveOneGuardForFailbackAndRebalance(t *testing.T) {
|
||||
for _, profile := range []string{"sync_all", "sync_quorum", "best_effort"} {
|
||||
for _, rf := range []int{2, 3} {
|
||||
t.Run(fmt.Sprintf("%s/RF%d", profile, rf), func(t *testing.T) {
|
||||
want := plannedMoveAllowed(profile, rf) == nil
|
||||
h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: rf})
|
||||
defer closeTestMaster(t, h)
|
||||
vol := "vol-rf2"
|
||||
if rf == 3 {
|
||||
vol = "vol-rf3"
|
||||
seedRF3Placement(t, h)
|
||||
} else {
|
||||
seedRF2Placement(t, h)
|
||||
}
|
||||
candidates := []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 1}}
|
||||
if rf == 3 {
|
||||
candidates = append(candidates, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 1})
|
||||
}
|
||||
// The current primary is alive and ready: a move now is planned.
|
||||
h.SetPromotionEvidenceProvider(staticPromotionProbe{result: PromotionProbeResult{
|
||||
AckProfile: profile,
|
||||
SyncAckKnown: true,
|
||||
CurrentKnown: true,
|
||||
Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true, DurableLSN: 1},
|
||||
Candidates: candidates,
|
||||
}})
|
||||
|
||||
// Failback.
|
||||
_, err := h.plannedMoveEvidence(vol, "r2")
|
||||
if (err == nil) != want {
|
||||
t.Fatalf("failback to r2: err=%v; want allowed=%t", err, want)
|
||||
}
|
||||
|
||||
// Rebalance: the gate's annotation of the snapshot the
|
||||
// controller reads.
|
||||
slot := func(r, s string) authority.ReplicaCandidate {
|
||||
return authority.ReplicaCandidate{ReplicaID: r, ServerID: s, DataAddr: "d-" + r, CtrlAddr: "c-" + r, Reachable: true, ReadyForPrimary: true, Eligible: true}
|
||||
}
|
||||
snap := authority.ClusterSnapshot{
|
||||
Servers: []authority.ServerObservation{{ServerID: "s1", Reachable: true, Eligible: true}, {ServerID: "s2", Reachable: true, Eligible: true}, {ServerID: "s3", Reachable: true, Eligible: true}},
|
||||
Volumes: []authority.VolumeTopologySnapshot{{
|
||||
VolumeID: vol,
|
||||
Authority: authority.AuthorityBasis{Assigned: true, ReplicaID: "r1", Epoch: 1, EndpointVersion: 1, DataAddr: "d-r1", CtrlAddr: "c-r1"},
|
||||
Slots: []authority.ReplicaCandidate{slot("r1", "s1"), slot("r2", "s2")},
|
||||
}},
|
||||
}
|
||||
if rf == 3 {
|
||||
snap.Volumes[0].Slots = append(snap.Volumes[0].Slots, slot("r3", "s3"))
|
||||
}
|
||||
h.applyPromotionEvidenceGate(&snap)
|
||||
for _, s := range snap.Volumes[0].Slots[1:] {
|
||||
if !s.ReadyForPrimary {
|
||||
t.Fatalf("%s: the gate did not allow a ready candidate: %+v", s.ReplicaID, s)
|
||||
}
|
||||
if s.PlannedMoveAllowed != want {
|
||||
t.Fatalf("rebalance to %s: PlannedMoveAllowed=%t; want %t", s.ReplicaID, s.PlannedMoveAllowed, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,10 +262,12 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int,
|
||||
if allowed[slot.ReplicaID] {
|
||||
slot.ReadyForPrimary = true
|
||||
slot.PromotionEvidence = promotionEvidenceFor(result, slot.ReplicaID)
|
||||
slot.PlannedMoveAllowed = plannedMoveAllowed(result.AckProfile, len(vol.Slots)) == nil
|
||||
enabledCandidate = true
|
||||
} else {
|
||||
slot.ReadyForPrimary = false
|
||||
slot.PromotionEvidence = adapter.PrimaryEvidence{}
|
||||
slot.PlannedMoveAllowed = false
|
||||
}
|
||||
}
|
||||
// After the (blocking) probe, judge the current primary from its
|
||||
|
||||
Reference in new issue
Block a user