From affc3a34f6ee4ef83096acfd3628abd487a3a78d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 12:51:25 -0800 Subject: [PATCH] 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 --- seaweed-block/cmd/blockmaster/main.go | 7 +++ seaweed-block/cmd/blockvolume/main.go | 1 + seaweed-block/core/host/master/probe_round.go | 30 ++++++++++- .../core/host/master/product_loop.go | 53 ++++++++++++++----- .../core/host/master/product_loop_test.go | 18 ++++--- seaweed-block/core/host/volume/probe_round.go | 2 +- 6 files changed, 91 insertions(+), 20 deletions(-) diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 98b86e56d9..cb51ba63ec 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -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 } diff --git a/seaweed-block/cmd/blockvolume/main.go b/seaweed-block/cmd/blockvolume/main.go index 5ce9c726ae..2c2a65c922 100644 --- a/seaweed-block/cmd/blockvolume/main.go +++ b/seaweed-block/cmd/blockvolume/main.go @@ -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, diff --git a/seaweed-block/core/host/master/probe_round.go b/seaweed-block/core/host/master/probe_round.go index 9e0057339c..cd7bd7d1b2 100644 --- a/seaweed-block/core/host/master/probe_round.go +++ b/seaweed-block/core/host/master/probe_round.go @@ -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, ",") +} diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index cc26616d24..9d7631000d 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -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)) diff --git a/seaweed-block/core/host/master/product_loop_test.go b/seaweed-block/core/host/master/product_loop_test.go index 7a4218ca18..3f0efbc0bc 100644 --- a/seaweed-block/core/host/master/product_loop_test.go +++ b/seaweed-block/core/host/master/product_loop_test.go @@ -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") } } diff --git a/seaweed-block/core/host/volume/probe_round.go b/seaweed-block/core/host/volume/probe_round.go index 559e45f455..d238934eb5 100644 --- a/seaweed-block/core/host/volume/probe_round.go +++ b/seaweed-block/core/host/volume/probe_round.go @@ -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