mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
authority, master: decide boot grace from the newest fact; record unsupported ready ticks; cap at the effective window
Review of #130 r2 (three P2s): - The unsupported-volume gate records the current primary's own fresh slot fact on every pass (RecordPrimaryBootFact), not only when a promotion is considered, so a ready report ends the grace and ready restarts count toward flap history. - The grace decision is ordered like the history: a superseded fact (older than the newest recorded one, or equal-time with another incarnation) is not a decision input. The decision follows the newest recorded fact (its incarnation, placeability and grace clock), and a superseded fact's endpoint is never used for a refresh. A fresh fact still needs to be placeable and not ready. - The cap uses the observation store's effective freshness window (FreshnessConfig.EffectiveFreshnessWindow), so an omitted window caps at its 10s default; an unset or nonpositive grace takes the window. Lock order unchanged: state under TopologyController.mu; the gate reads the store snapshot (its own lock, released) before calling the controller; no new locks. Refs #128 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c30c14950
commit
4c84545c84
5 files changed
+78
-23
No files matched your search
@@ -230,7 +230,7 @@ func (c *TopologyController) processSupportedVolumeLocked(
|
||||
// S4 behavior; stuck evidence has its own lifecycle and is
|
||||
// NOT cleared here — §10 clearing rule 4.)
|
||||
delete(c.unsupported, vol.VolumeID)
|
||||
c.observeIncarnationsLocked(vol)
|
||||
c.observeIncarnationsLocked(vol, serverIndex)
|
||||
|
||||
c.confirmDesiredLocked(vol, currentLine, hasLine)
|
||||
|
||||
@@ -497,8 +497,8 @@ func (c *TopologyController) decideVolume(
|
||||
// A restarted current primary that is placeable but not ready yet
|
||||
// keeps its authority through its boot grace; only its endpoint
|
||||
// may be refreshed.
|
||||
if candidatePlaceable(current, serverIndex) && c.inPrimaryBootGraceLocked(vol.VolumeID, current) {
|
||||
if current.DataAddr != currentLine.DataAddr || current.CtrlAddr != currentLine.CtrlAddr {
|
||||
if hold, superseded := c.primaryBootGraceLocked(vol.VolumeID, current, candidatePlaceable(current, serverIndex)); hold {
|
||||
if !superseded && (current.DataAddr != currentLine.DataAddr || current.CtrlAddr != currentLine.CtrlAddr) {
|
||||
return AssignmentAsk{
|
||||
VolumeID: vol.VolumeID,
|
||||
ReplicaID: current.ReplicaID,
|
||||
|
||||
@@ -125,6 +125,12 @@ type FreshnessConfig struct {
|
||||
PendingGrace time.Duration
|
||||
}
|
||||
|
||||
// EffectiveFreshnessWindow is the window the observation store actually
|
||||
// uses: the configured one, or its default when omitted or nonpositive.
|
||||
func (c FreshnessConfig) EffectiveFreshnessWindow() time.Duration {
|
||||
return c.withDefaults().FreshnessWindow
|
||||
}
|
||||
|
||||
func (c FreshnessConfig) withDefaults() FreshnessConfig {
|
||||
out := c
|
||||
if out.FreshnessWindow <= 0 {
|
||||
|
||||
@@ -26,13 +26,16 @@ import "time"
|
||||
// Ordering: a fact changes the history only if its ObservedAt is
|
||||
// strictly newer than the last fact recorded for that replica, so a
|
||||
// delayed or superseded snapshot can never count a restart, reset a
|
||||
// grace, or end one. A slot without an incarnation (an older volume
|
||||
// grace, or end one. A superseded fact (older, or equal-time with a
|
||||
// different incarnation) is not a decision input either: the decision
|
||||
// follows the newest recorded fact, and its endpoint is never used. A slot without an incarnation (an older volume
|
||||
// binary) or without an observation time gets no grace. All state is
|
||||
// guarded by TopologyController.mu.
|
||||
|
||||
type primaryBootGrace struct {
|
||||
incarnation string
|
||||
lastObservedAt time.Time // newest fact recorded for this replica
|
||||
lastPlaceable bool // whether that newest fact was placeable
|
||||
graceStart time.Time // controller clock when the incarnation was first recorded
|
||||
ended bool // reported ready, expired, or never granted
|
||||
starts []time.Time // incarnation starts within the flap window
|
||||
@@ -41,14 +44,14 @@ type primaryBootGrace struct {
|
||||
func bootGraceKey(volumeID, replicaID string) string { return volumeID + "/" + replicaID }
|
||||
|
||||
// observeIncarnationsLocked records each slot's boot fact.
|
||||
func (c *TopologyController) observeIncarnationsLocked(vol VolumeTopologySnapshot) {
|
||||
func (c *TopologyController) observeIncarnationsLocked(vol VolumeTopologySnapshot, servers map[string]ServerObservation) {
|
||||
for _, slot := range vol.Slots {
|
||||
c.recordBootFactLocked(vol.VolumeID, slot)
|
||||
c.recordBootFactLocked(vol.VolumeID, slot, candidatePlaceable(slot, servers))
|
||||
}
|
||||
}
|
||||
|
||||
// recordBootFactLocked is the only writer of bootGrace.
|
||||
func (c *TopologyController) recordBootFactLocked(volumeID string, slot ReplicaCandidate) {
|
||||
func (c *TopologyController) recordBootFactLocked(volumeID string, slot ReplicaCandidate, placeable bool) {
|
||||
if slot.Incarnation == "" || slot.ObservedAt.IsZero() {
|
||||
return
|
||||
}
|
||||
@@ -65,6 +68,7 @@ func (c *TopologyController) recordBootFactLocked(volumeID string, slot ReplicaC
|
||||
c.bootGrace[key] = g
|
||||
}
|
||||
g.lastObservedAt = slot.ObservedAt
|
||||
g.lastPlaceable = placeable
|
||||
if slot.ReadyForPrimary {
|
||||
g.ended = true
|
||||
}
|
||||
@@ -92,14 +96,34 @@ func (c *TopologyController) startIncarnation(prev *primaryBootGrace, incarnatio
|
||||
}
|
||||
}
|
||||
|
||||
// inPrimaryBootGraceLocked reports whether the current primary's slot
|
||||
// is inside its boot grace now. Expiry ends the grace for good.
|
||||
func (c *TopologyController) inPrimaryBootGraceLocked(volumeID string, current ReplicaCandidate) bool {
|
||||
if current.Incarnation == "" || current.ReadyForPrimary {
|
||||
return false
|
||||
// primaryBootGraceLocked decides whether the current primary, described
|
||||
// by fact, holds its authority through a boot grace. hold is true when
|
||||
// it does; superseded reports that fact is older than the newest
|
||||
// recorded one (or equal-time with another incarnation), in which case
|
||||
// the decision follows the recorded fact and the caller must not use
|
||||
// fact's endpoint.
|
||||
func (c *TopologyController) primaryBootGraceLocked(volumeID string, fact ReplicaCandidate, placeable bool) (hold, superseded bool) {
|
||||
if fact.Incarnation == "" {
|
||||
return false, false
|
||||
}
|
||||
g := c.bootGrace[bootGraceKey(volumeID, current.ReplicaID)]
|
||||
if g == nil || g.incarnation != current.Incarnation || g.ended {
|
||||
g := c.bootGrace[bootGraceKey(volumeID, fact.ReplicaID)]
|
||||
if g == nil {
|
||||
return false, false
|
||||
}
|
||||
if !fact.ObservedAt.IsZero() && (fact.ObservedAt.Before(g.lastObservedAt) ||
|
||||
(fact.ObservedAt.Equal(g.lastObservedAt) && fact.Incarnation != g.incarnation)) {
|
||||
return g.lastPlaceable && c.graceActiveLocked(g), true
|
||||
}
|
||||
if !placeable || fact.ReadyForPrimary || g.incarnation != fact.Incarnation {
|
||||
return false, false
|
||||
}
|
||||
return c.graceActiveLocked(g), false
|
||||
}
|
||||
|
||||
// graceActiveLocked reports whether g's grace is running. Expiry ends
|
||||
// it for good.
|
||||
func (c *TopologyController) graceActiveLocked(g *primaryBootGrace) bool {
|
||||
if g.ended {
|
||||
return false
|
||||
}
|
||||
if c.now().Sub(g.graceStart) >= c.config.PrimaryBootGrace {
|
||||
@@ -119,11 +143,26 @@ func (c *TopologyController) inPrimaryBootGraceLocked(volumeID string, current R
|
||||
func (c *TopologyController) PrimaryBootGraceHolds(volumeID string, current ReplicaCandidate) bool {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if !current.Reachable || !current.Eligible || current.Withdrawn {
|
||||
return false
|
||||
}
|
||||
c.recordBootFactLocked(volumeID, current)
|
||||
return c.inPrimaryBootGraceLocked(volumeID, current)
|
||||
placeable := ownPlaceable(current)
|
||||
c.recordBootFactLocked(volumeID, current, placeable)
|
||||
hold, _ := c.primaryBootGraceLocked(volumeID, current, placeable)
|
||||
return hold
|
||||
}
|
||||
|
||||
// RecordPrimaryBootFact records the current primary's fresh slot fact
|
||||
// (ordered, as above) whether or not a promotion is being considered,
|
||||
// so a ready report ends the grace and every start counts toward flap
|
||||
// history. Same caller contract as PrimaryBootGraceHolds.
|
||||
func (c *TopologyController) RecordPrimaryBootFact(volumeID string, current ReplicaCandidate) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.recordBootFactLocked(volumeID, current, ownPlaceable(current))
|
||||
}
|
||||
|
||||
// ownPlaceable reports placeability from a slot that already carries
|
||||
// its server's reachability and eligibility.
|
||||
func ownPlaceable(slot ReplicaCandidate) bool {
|
||||
return slot.Reachable && slot.Eligible && !slot.Withdrawn
|
||||
}
|
||||
|
||||
// PrimaryBootGrace returns the effective boot-grace bound.
|
||||
|
||||
@@ -179,10 +179,12 @@ func New(cfg Config) (*Host, error) {
|
||||
|
||||
holder := &publisherHolder{}
|
||||
ctrlCfg := cfg.ControllerConfig
|
||||
if w := cfg.Freshness.FreshnessWindow; w > 0 && (ctrlCfg.PrimaryBootGrace == 0 || ctrlCfg.PrimaryBootGrace > w) {
|
||||
if w := cfg.Freshness.EffectiveFreshnessWindow(); ctrlCfg.PrimaryBootGrace <= 0 || ctrlCfg.PrimaryBootGrace > w {
|
||||
// A restarted primary may stay not-ready for at most the
|
||||
// window in which its observations are trusted (#128); a
|
||||
// larger configured grace is capped, never widened.
|
||||
// window in which its observations are trusted (#128): the
|
||||
// store's effective window, also when the config omits it. A
|
||||
// larger configured grace is capped, never widened; an unset
|
||||
// or nonpositive one takes the window.
|
||||
if ctrlCfg.PrimaryBootGrace > w {
|
||||
lg.Printf("blockmaster: primary boot grace %s capped at freshness window %s", ctrlCfg.PrimaryBootGrace, w)
|
||||
}
|
||||
|
||||
@@ -226,6 +226,14 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
|
||||
if !ok || !current.Assigned {
|
||||
continue
|
||||
}
|
||||
// Record the current primary's own fresh slot fact on every
|
||||
// pass, not only when a promotion is considered, so a ready
|
||||
// report ends its boot grace and every start counts toward
|
||||
// flap history (#128).
|
||||
cur, curFresh := h.freshCurrentSlot(placement.VolumeID, current.ReplicaID)
|
||||
if curFresh && h.ctrl != nil {
|
||||
h.ctrl.RecordPrimaryBootFact(placement.VolumeID, cur)
|
||||
}
|
||||
vol, ok := topologyFromUnsupportedPlacement(placement, current)
|
||||
if !ok {
|
||||
continue
|
||||
@@ -262,7 +270,7 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
|
||||
// Unsupported does not mean the current primary is unhealthy:
|
||||
// a different slot may be stale. Judge the current primary
|
||||
// from its own fresh heartbeat slot, never from placement.
|
||||
if cur, ok := h.freshCurrentSlot(vol.VolumeID, current.ReplicaID); ok && h.primaryBootGraceHolds(vol.VolumeID, cur) {
|
||||
if curFresh && h.primaryBootGraceHolds(vol.VolumeID, cur) {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user