mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
fix(master): hold the automatic path on an ack profile mismatch
The volume answers each promotion probe with its own --replication-ack; the probe round names every answer whose profile is missing or differs from blockmaster's (or an unknown master profile), and both gates hold such a volume before any fencing round (ack_profile_mismatch), as they hold a best_effort one. One helper (automaticFailoverHold) decides both, called before the unsupported gate reads its candidates, so a held volume always shows why. blockmaster refuses an unknown --launcher-replication-ack. The best_effort product-loop test now expects the hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2da008f236
commit
affc3a34f6
6 files changed
+91
-20
No files matched your search
@@ -171,6 +171,13 @@ func parseFlags(args []string) (flags, error) {
|
||||
if f.authorityStore == "" {
|
||||
return flags{}, fmt.Errorf("--authority-store is required")
|
||||
}
|
||||
// The promotion gate reads every frontier rule from this profile: an
|
||||
// unknown one is refused here, as blockvolume refuses its own.
|
||||
switch f.launcherReplicationAck {
|
||||
case "best-effort", "sync-quorum", "sync-all":
|
||||
default:
|
||||
return flags{}, fmt.Errorf("--launcher-replication-ack=%q invalid; want best-effort, sync-quorum, or sync-all", f.launcherReplicationAck)
|
||||
}
|
||||
if err := master.ValidateStatusListen(f.statusListen); err != nil {
|
||||
return flags{}, err
|
||||
}
|
||||
|
||||
@@ -1686,6 +1686,7 @@ func hostConfig(f flags, readyCh chan<- adapter.AssignmentInfo) volume.Config {
|
||||
}
|
||||
return volume.Config{
|
||||
MasterAddr: f.masterAddr,
|
||||
AckProfile: strings.ReplaceAll(f.replicationAck, "-", "_"),
|
||||
LinesNameTheirProcess: true,
|
||||
ServerID: f.serverID,
|
||||
VolumeID: f.volumeID,
|
||||
|
||||
@@ -3,6 +3,9 @@ package master
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -229,7 +232,7 @@ done:
|
||||
// ready as a serving primary, on a valid table.
|
||||
result.Current = PromotionCandidateEvidence{ReplicaID: current.ReplicaID, Ready: a.GetPrimaryReady(), AwaitingReplicaStoresEpoch: a.GetAwaitingReplicaStoresEpoch(), DurableLSN: a.GetDurableEnd(),
|
||||
LastDataEpoch: a.GetLastDataEpoch(), LastDataFirstLSN: a.GetLastDataFirstLsn(), TableInvalid: a.GetTablePresent() && !a.GetTableValid(), TableValid: a.GetTablePresent() && a.GetTableValid(),
|
||||
StoreID: store, Floor: a.GetFloor()}
|
||||
StoreID: store, Floor: a.GetFloor(), AckProfile: a.GetAckProfile()}
|
||||
} else {
|
||||
result.Current = PromotionCandidateEvidence{ReplicaID: current.ReplicaID, ProbeAddr: "no answer"}
|
||||
}
|
||||
@@ -259,11 +262,36 @@ done:
|
||||
TableValid: a.GetTablePresent() && a.GetTableValid(),
|
||||
StoreID: store,
|
||||
Floor: a.GetFloor(),
|
||||
AckProfile: a.GetAckProfile(),
|
||||
// A promotion target answers as a ready replica, from a store
|
||||
// whose epoch table is present and valid, and whose id is the
|
||||
// store its primary attested (counted toward its write ACKs).
|
||||
Ready: a.GetReplicaReady() && a.GetTablePresent() && a.GetTableValid() && attested,
|
||||
})
|
||||
}
|
||||
result.ProfileMismatch = profileMismatch(p.ackProfile, got)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// profileMismatch names the answers whose ack profile is missing or is not
|
||||
// the master's (or says the master's own is unknown); "" when all agree.
|
||||
func profileMismatch(master string, answers map[string]*control.ProbeAnswer) string {
|
||||
if !isKnownAckProfile(master) {
|
||||
return fmt.Sprintf("master ack profile %q unknown", master)
|
||||
}
|
||||
want := canonicalAckProfile(master)
|
||||
var bad []string
|
||||
for id, a := range answers {
|
||||
if got := canonicalAckProfile(a.GetAckProfile()); got != want {
|
||||
if got == "" {
|
||||
got = "none"
|
||||
}
|
||||
bad = append(bad, id+"="+got)
|
||||
}
|
||||
}
|
||||
if len(bad) == 0 {
|
||||
return ""
|
||||
}
|
||||
sort.Strings(bad)
|
||||
return "master " + want + ", answers " + strings.Join(bad, ",")
|
||||
}
|
||||
@@ -314,13 +314,14 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int,
|
||||
directAsks = append(directAsks, heal)
|
||||
}
|
||||
}
|
||||
if replacing && ok && isBestEffortProfile(result.AckProfile) {
|
||||
// The same refusal as the operator's move (plannedMoveAllowed):
|
||||
// a best_effort write may exist on the primary alone, so no
|
||||
// replica takes its place automatically.
|
||||
holdReason, holdWhy := "", ""
|
||||
if replacing && ok {
|
||||
holdReason, holdWhy = automaticFailoverHold(result)
|
||||
}
|
||||
if holdReason != "" {
|
||||
allowed = map[string]bool{}
|
||||
h.log.Printf("blockmaster: promotion gate volume=%s current=%s ack_profile=best_effort: no automatic failover", vol.VolumeID, vol.Authority.ReplicaID)
|
||||
h.recordVolumeBlockedEvent(vol.VolumeID, ops.ReasonBestEffortNoAutomaticFailover)
|
||||
h.log.Printf("blockmaster: promotion gate volume=%s current=%s %s: no automatic failover", vol.VolumeID, vol.Authority.ReplicaID, holdWhy)
|
||||
h.recordVolumeBlockedEvent(vol.VolumeID, holdReason)
|
||||
} else if (len(allowed) > 0 || emptyVolumeSurvivors(result, ok)) && replacing {
|
||||
result, allowed = h.fencedDecision(vol.VolumeID, vol.Authority, result, len(candidates))
|
||||
if len(allowed) == 0 {
|
||||
@@ -453,10 +454,33 @@ func (h *Host) fencedDecision(volumeID string, current authority.AuthorityBasis,
|
||||
return fenced, allowed
|
||||
}
|
||||
|
||||
// automaticFailoverHold is the profile rule that holds a lost primary's
|
||||
// volume before any fencing round, as a blocked-event reason and a log
|
||||
// phrase ("" when none holds): the round's answers disagree with the
|
||||
// master's profile or do not name one, the master's profile is unknown, or
|
||||
// it is best_effort (a write may be on the primary alone, the same reason
|
||||
// the operator's move refuses it, plannedMoveAllowed).
|
||||
func automaticFailoverHold(result PromotionProbeResult) (reason, why string) {
|
||||
switch {
|
||||
case result.ProfileMismatch != "":
|
||||
return ops.ReasonAckProfileMismatch, "ack profile mismatch (" + result.ProfileMismatch + ")"
|
||||
case !isKnownAckProfile(result.AckProfile):
|
||||
return ops.ReasonAckProfileMismatch, fmt.Sprintf("ack_profile=%q unknown", result.AckProfile)
|
||||
case isBestEffortProfile(result.AckProfile):
|
||||
return ops.ReasonBestEffortNoAutomaticFailover, "ack_profile=best_effort"
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// isBestEffortProfile: the ack profile acknowledges a write without any
|
||||
// replica (planned_move.go's ErrPlannedMoveBestEffort).
|
||||
func isBestEffortProfile(profile string) bool {
|
||||
return strings.ToLower(strings.ReplaceAll(profile, "-", "_")) == "best_effort"
|
||||
return canonicalAckProfile(profile) == "best_effort"
|
||||
}
|
||||
|
||||
// canonicalAckProfile: best-effort and best_effort are the same profile.
|
||||
func canonicalAckProfile(profile string) string {
|
||||
return strings.ToLower(strings.ReplaceAll(profile, "-", "_"))
|
||||
}
|
||||
|
||||
// emptyVolumeSurvivors: the plain round saw a ready replica and every answer
|
||||
@@ -616,6 +640,16 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
|
||||
h.log.Printf("blockmaster: promotion gate unsupported volume=%s current=%s probe_unavailable reasons=%v", vol.VolumeID, current.ReplicaID, evidence.Reasons)
|
||||
h.recordPromotionProbeUnavailableEvent(vol.VolumeID, current.ReplicaID)
|
||||
}
|
||||
// A lost primary is held before its candidates are read when the
|
||||
// profile rules forbid an automatic failover (best_effort, a profile
|
||||
// mismatch or an unknown profile), so the volume shows why.
|
||||
if probeOK && result.CurrentKnown && !result.Current.Ready {
|
||||
if reason, why := automaticFailoverHold(result); reason != "" {
|
||||
h.log.Printf("blockmaster: promotion gate unsupported volume=%s current=%s %s: no automatic failover", vol.VolumeID, current.ReplicaID, why)
|
||||
h.recordVolumeBlockedEvent(vol.VolumeID, reason)
|
||||
continue
|
||||
}
|
||||
}
|
||||
enabledCandidate := false
|
||||
for _, slot := range vol.Slots {
|
||||
if slot.ReplicaID != current.ReplicaID && allowed[slot.ReplicaID] {
|
||||
@@ -640,11 +674,6 @@ 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
|
||||
}
|
||||
if isBestEffortProfile(result.AckProfile) {
|
||||
h.log.Printf("blockmaster: promotion gate unsupported volume=%s current=%s ack_profile=best_effort: no automatic failover", vol.VolumeID, current.ReplicaID)
|
||||
h.recordVolumeBlockedEvent(vol.VolumeID, ops.ReasonBestEffortNoAutomaticFailover)
|
||||
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))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/seaweedfs/seaweed-block/core/adapter"
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
||||
"github.com/seaweedfs/seaweed-block/core/ops"
|
||||
)
|
||||
|
||||
func TestG9G_ProductLoopPublishesVerifiedExistingReplica(t *testing.T) {
|
||||
@@ -392,7 +393,10 @@ func TestMountedFailover_ProductLoopRF3UnknownRequiredLSNFallsBackToHighestDurab
|
||||
}
|
||||
}
|
||||
|
||||
func TestMountedFailover_ProductLoopRF3BestEffortUnknownRequiredLSNCanSelectHighestDurableLSN(t *testing.T) {
|
||||
// A best_effort volume is not failed over automatically even when a ready
|
||||
// survivor holds the highest durable end: a best_effort write may be on the
|
||||
// lost primary alone (the same reason the operator's move refuses it).
|
||||
func TestMountedFailover_ProductLoopRF3BestEffortIsHeldDespiteAHighestDurableSurvivor(t *testing.T) {
|
||||
h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{
|
||||
ExpectedSlotsPerVolume: 3,
|
||||
})
|
||||
@@ -423,12 +427,14 @@ func TestMountedFailover_ProductLoopRF3BestEffortUnknownRequiredLSNCanSelectHigh
|
||||
if err != nil {
|
||||
t.Fatalf("failover product tick: %v", err)
|
||||
}
|
||||
if result.PromotionProbes != 1 || result.PromotionBlocked != 0 {
|
||||
t.Fatalf("result=%+v want best-effort unknown required LSN to select highest durable survivor", result)
|
||||
if result.PromotionProbes != 1 || result.PromotionBlocked != 1 {
|
||||
t.Fatalf("result=%+v want the best-effort volume's promotion blocked", result)
|
||||
}
|
||||
failover := waitAuthorityReplica(t, h.Publisher(), "vol-rf3", "r3")
|
||||
if failover.Epoch != 2 || failover.EndpointVersion != 1 {
|
||||
t.Fatalf("failover line=%+v want r3@2/1", failover)
|
||||
if line, ok := h.Publisher().VolumeAuthorityLine("vol-rf3"); !ok || line.ReplicaID != "r1" || line.Epoch != initial.Epoch {
|
||||
t.Fatalf("line=%+v ok=%t; want it to stay %s@%d", line, ok, initial.ReplicaID, initial.Epoch)
|
||||
}
|
||||
if !blockedFor(h, "vol-rf3", ops.ReasonBestEffortNoAutomaticFailover) {
|
||||
t.Fatal("the volume does not show why it is not failed over")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ func (h *Host) roundNamesThisStore(round *control.ProbeRound) bool {
|
||||
|
||||
// probeAnswer is this replica's evidence now, for round.
|
||||
func (h *Host) probeAnswer(round uint64) *control.ProbeAnswer {
|
||||
a := &control.ProbeAnswer{ServerId: h.cfg.ServerID, VolumeId: h.cfg.VolumeID, ReplicaId: h.cfg.ReplicaID, RoundId: round}
|
||||
a := &control.ProbeAnswer{ServerId: h.cfg.ServerID, VolumeId: h.cfg.VolumeID, ReplicaId: h.cfg.ReplicaID, RoundId: round, AckProfile: h.cfg.AckProfile}
|
||||
if src, ok := h.getReplication().(primaryEvidenceSource); ok && src != nil {
|
||||
if st, end, err := src.LocalPrimaryEvidence(); err == nil {
|
||||
a.DurableEnd = end
|
||||
|
||||
Reference in new issue
Block a user