mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
master: a primary in the creation wait is not replaced for answering not ready
A new volume's primary hides its frontend until the master has recorded every replica's store, so it answers the promotion probe "not primary-ready" by design. Past its boot grace, the promotion gate took that for a failed primary and fenced it, reassigning the volume. While the master still awaits the volume's stores (read before the probe), and only while the primary's own fresh slot is acceptable, the not-ready answer is judged as the wait; an unreachable, ineligible or withdrawn primary is still replaced. Fixtures that fail over an established volume now attest its stores. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f24312e39f
commit
71682c1e03
4 files changed
+215
No files matched your search
@@ -0,0 +1,153 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// A new volume's primary hides its frontend until its replicas' stores are
|
||||
// recorded (the creation wait), so it answers the promotion probe "not
|
||||
// primary-ready" by design. The master must not take that for a failed
|
||||
// primary: past its boot grace, with a ready survivor, the line stays.
|
||||
// (Real-path symptom: r1 adopted at epoch 1, the master moved the primary
|
||||
// to r2 at epoch 2 while r1 was still learning its replicas' stores.)
|
||||
func TestPrimaryInTheCreationWaitIsNotReplacedForNotReady(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}})
|
||||
defer closeTestMaster(t, h)
|
||||
if waiting, _ := h.attest.awaited("vol-rf3", h.replicaSlotsFor("vol-rf3")); waiting == 0 {
|
||||
t.Fatal("fixture: the new volume is not in its creation wait")
|
||||
}
|
||||
time.Sleep(250 * time.Millisecond) // past the boot grace
|
||||
unsupportedTick(t, h, readySlot("r1-a"))
|
||||
expectLineStaysR1(t, h, "a primary in the creation wait answered not ready")
|
||||
unsupportedTick(t, h, readySlot("r1-a"))
|
||||
expectLineStaysR1(t, h, "still in the creation wait on the next tick")
|
||||
}
|
||||
|
||||
// The creation wait never shelters a failed primary: one whose own fresh
|
||||
// slot is not acceptable (an unhealthy heartbeat makes it ineligible) is
|
||||
// replaced through the fencing round, as for an established volume.
|
||||
func TestPrimaryInTheCreationWaitIsReplacedWhenItsSlotIsNotAcceptable(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{})
|
||||
defer closeTestMaster(t, h)
|
||||
if !h.inCreationWait("vol-rf3") {
|
||||
t.Fatal("fixture: the new volume is not in its creation wait")
|
||||
}
|
||||
ineligible := restarting
|
||||
ineligible.eligible = false
|
||||
unsupportedTick(t, h, ineligible)
|
||||
expectFailoverToR2(t, h, "an ineligible primary inside the creation wait")
|
||||
}
|
||||
|
||||
// The wait clears while the probe is held (the master records the last
|
||||
// store meanwhile): the primary's not-ready answer was given inside the
|
||||
// wait and is judged as the wait, so this round does not fence it.
|
||||
func TestCreationWaitClearingDuringTheProbeDoesNotFence(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}})
|
||||
defer closeTestMaster(t, h)
|
||||
p := probeOf(t, h)
|
||||
time.Sleep(250 * time.Millisecond) // past the boot grace
|
||||
heldTick(t, h, readySlot("r1-a"), func() {
|
||||
attestAllStores(t, h)
|
||||
// r1 keeps heartbeating while the probe runs: its slot stays
|
||||
// acceptable, so only the wait reading decides this round.
|
||||
ingestRF3Incarnations(t, h, readySlot("r1-a"), readySlot("r2-a"), silent)
|
||||
})
|
||||
if n := func() int { p.mu.Lock(); defer p.mu.Unlock(); return p.fenceCalls }(); n != 0 {
|
||||
t.Fatalf("%d fencing rounds on a not-ready answer given inside the creation wait", n)
|
||||
}
|
||||
expectLineStaysR1(t, h, "the wait cleared during the probe")
|
||||
}
|
||||
|
||||
// attestSomeStores records r1 and r2 but not r3: the volume is still in its
|
||||
// creation wait.
|
||||
func attestSomeStores(t *testing.T, h *Host) {
|
||||
t.Helper()
|
||||
line := waitAuthorityLine(t, h.Publisher(), "vol-rf3")
|
||||
if err := h.ingestStoreAttestation("node-a", attestation("vol-rf3", "r1", line.Epoch, map[string]storage.StoreID{"r1": testStoreID, "r2": testStoreID})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !h.inCreationWait("vol-rf3") {
|
||||
t.Fatal("fixture: a partial attestation ended the creation wait")
|
||||
}
|
||||
}
|
||||
|
||||
// Partial attestation (still creating): a primary whose own slot is not
|
||||
// acceptable is replaced; one that does not answer the probe is unknown and
|
||||
// never replaced.
|
||||
func TestCreationWaitPartialAttestationControls(t *testing.T) {
|
||||
t.Run("unhealthy primary (ineligible) is replaced", func(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{})
|
||||
defer closeTestMaster(t, h)
|
||||
attestSomeStores(t, h)
|
||||
ineligible := restarting
|
||||
ineligible.eligible = false
|
||||
unsupportedTick(t, h, ineligible)
|
||||
expectFailoverToR2(t, h, "an unhealthy primary inside the creation wait")
|
||||
})
|
||||
t.Run("expired primary (no fresh slot) is replaced", func(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{})
|
||||
defer closeTestMaster(t, h)
|
||||
attestSomeStores(t, h)
|
||||
unsupportedTick(t, h, silent)
|
||||
expectFailoverToR2(t, h, "an expired primary inside the creation wait")
|
||||
})
|
||||
t.Run("unanswered primary is never replaced", func(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{})
|
||||
defer closeTestMaster(t, h)
|
||||
attestSomeStores(t, h)
|
||||
p := probeOf(t, h)
|
||||
p.mu.Lock()
|
||||
p.currentUnknown = true
|
||||
p.mu.Unlock()
|
||||
unsupportedTick(t, h, readySlot("r1-a"))
|
||||
expectLineStaysR1(t, h, "an unanswered primary inside the creation wait")
|
||||
})
|
||||
}
|
||||
|
||||
// The realistic new volume: never written, so every end is zero and no
|
||||
// frontier is known, with only r1 and r2 attested (still creating). What the
|
||||
// code does, for each primary:
|
||||
// - unhealthy (ineligible) or expired: NOT promoted. With the required
|
||||
// frontier unknown, the RF3 quorum rule needs two fenced survivors and
|
||||
// only r2 is ready (r3 answers end 0, not ready), so nothing is
|
||||
// published: the line stays and the volume stays in its visible creation
|
||||
// wait (status: creating: waiting for replica attestations). The
|
||||
// operator recreates it (it has served nothing).
|
||||
// - unanswered: unknown, never failed: the line stays, in the same wait.
|
||||
func TestCreationWaitEmptyVolumeOutcomes(t *testing.T) {
|
||||
ineligible := restarting
|
||||
ineligible.eligible = false
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
r1 rf3Slot
|
||||
unknown bool
|
||||
promoted bool
|
||||
}{
|
||||
{"unhealthy primary: stays in the visible wait", ineligible, false, false},
|
||||
{"expired primary: stays in the visible wait", silent, false, false},
|
||||
{"unanswered primary: stays in the visible wait", readySlot("r1-a"), true, false},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{})
|
||||
defer closeTestMaster(t, h)
|
||||
attestSomeStores(t, h)
|
||||
p := probeOf(t, h)
|
||||
p.mu.Lock()
|
||||
p.empty, p.currentUnknown = true, c.unknown
|
||||
p.mu.Unlock()
|
||||
unsupportedTick(t, h, c.r1)
|
||||
if c.promoted {
|
||||
expectFailoverToR2(t, h, c.name)
|
||||
return
|
||||
}
|
||||
expectLineStaysR1(t, h, c.name)
|
||||
if !h.inCreationWait("vol-rf3") {
|
||||
t.Fatal("the volume left its creation wait without the missing store")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// #128 boot grace through the full lifecycle product tick, on the
|
||||
@@ -71,6 +72,9 @@ type switchProbe struct {
|
||||
// currentUnknown: the current primary did not answer (status GET
|
||||
// refused or timed out), so CurrentKnown is false.
|
||||
currentUnknown bool
|
||||
// empty: a new volume, never written: every end is zero and no frontier
|
||||
// is required.
|
||||
empty bool
|
||||
// When hold is set, a probe signals entered and then blocks until
|
||||
// release is closed.
|
||||
hold bool
|
||||
@@ -101,6 +105,14 @@ func (p *switchProbe) ProbePromotionCandidates(volumeID string, current authorit
|
||||
p.mu.Lock()
|
||||
}
|
||||
defer p.mu.Unlock()
|
||||
if p.empty {
|
||||
return PromotionProbeResult{
|
||||
AckProfile: "sync-quorum",
|
||||
CurrentKnown: !p.currentUnknown,
|
||||
Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: p.currentReady},
|
||||
Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true}, {ReplicaID: "r3"}},
|
||||
}, nil
|
||||
}
|
||||
return PromotionProbeResult{
|
||||
AckProfile: "sync-quorum",
|
||||
// Only r2 is ready, so its promotion needs a known frontier it
|
||||
@@ -146,7 +158,18 @@ const testFreshness = time.Second
|
||||
// promotion probe says the current primary r1 is not ready and r2 is a
|
||||
// ready survivor, and publishes r1 from an all-ready first observation.
|
||||
// It then lets node-c's facts age out, so the volume is unsupported.
|
||||
// The volume has left its creation wait (its stores are attested): an
|
||||
// established volume, whose not-ready primary is a failover candidate.
|
||||
func newBootGraceMaster(t *testing.T, cfg Config) *Host {
|
||||
t.Helper()
|
||||
h := newBootGraceMasterCreating(t, cfg)
|
||||
attestAllStores(t, h)
|
||||
return h
|
||||
}
|
||||
|
||||
// newBootGraceMasterCreating is newBootGraceMaster for a volume still in its
|
||||
// creation wait (no store attested).
|
||||
func newBootGraceMasterCreating(t *testing.T, cfg Config) *Host {
|
||||
t.Helper()
|
||||
cfg.AuthorityStoreDir = t.TempDir()
|
||||
cfg.LifecycleStoreDir = t.TempDir()
|
||||
@@ -174,6 +197,19 @@ func newBootGraceMaster(t *testing.T, cfg Config) *Host {
|
||||
return h
|
||||
}
|
||||
|
||||
// attestAllStores records r1's attestation of every replica's store, so the
|
||||
// volume has left its creation wait (an established volume).
|
||||
func attestAllStores(t *testing.T, h *Host) {
|
||||
t.Helper()
|
||||
line := waitAuthorityLine(t, h.Publisher(), "vol-rf3")
|
||||
if err := h.ingestStoreAttestation("node-a", attestation("vol-rf3", "r1", line.Epoch, map[string]storage.StoreID{"r1": testStoreID, "r2": testStoreID, "r3": testStoreID})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if h.inCreationWait("vol-rf3") {
|
||||
t.Fatal("fixture: still in the creation wait after the attestation")
|
||||
}
|
||||
}
|
||||
|
||||
// unsupportedTick ingests fresh r1/r2 facts (node-c stays silent) and
|
||||
// runs one product tick, requiring that the unsupported-volume gate
|
||||
// probed.
|
||||
|
||||
@@ -799,11 +799,26 @@ func (h *Host) probePromotionCandidates(volumeID string, current authority.Autho
|
||||
// legitimate failover.
|
||||
func (h *Host) probePromotionCandidatesCurrent(volumeID string, current authority.AuthorityBasis, candidates []authority.ReplicaCandidate) (PromotionProbeResult, bool) {
|
||||
before, beforeOK := h.freshCurrentSlot(volumeID, current.ReplicaID)
|
||||
// Read before the probe: the state the primary's answer is given in. If
|
||||
// the wait clears while the probe runs, the not-ready answer still
|
||||
// belongs to the wait; the next round judges the established volume.
|
||||
creating := h.inCreationWait(volumeID)
|
||||
result, ok := h.probePromotionCandidates(volumeID, current, candidates)
|
||||
if !ok || (result.CurrentKnown && result.Current.Ready) {
|
||||
return result, ok
|
||||
}
|
||||
after, afterOK := h.freshCurrentSlot(volumeID, current.ReplicaID)
|
||||
// A new volume's primary hides its frontend until the master has
|
||||
// recorded every replica's store (the creation wait), so it answers "not
|
||||
// primary-ready" by design. That answer is the wait, not a failure: the
|
||||
// primary is judged ready for this decision, but only while its own fresh
|
||||
// slot is acceptable. One that is unreachable, ineligible (an unhealthy
|
||||
// heartbeat) or withdrawn is replaced as for an established volume.
|
||||
if result.CurrentKnown && afterOK && after.Reachable && after.Eligible && !after.Withdrawn && creating {
|
||||
h.log.Printf("blockmaster: promotion gate volume=%s current=%s not frontend-ready inside the creation wait; judged ready", volumeID, current.ReplicaID)
|
||||
result.Current.Ready = true
|
||||
return result, ok
|
||||
}
|
||||
if !afterOK || !after.ReadyForPrimary || !after.Reachable || !after.Eligible || after.Withdrawn {
|
||||
return result, ok
|
||||
}
|
||||
@@ -1012,6 +1027,16 @@ func (h *Host) assignmentAskAlreadyCurrent(volumeID, replicaID, dataAddr, ctrlAd
|
||||
// fresh heartbeat slot read now: placeable by that report and inside its
|
||||
// boot grace (#128). No fresh slot, or an explicit unhealthy report
|
||||
// (unreachable, ineligible, withdrawn), never holds.
|
||||
// inCreationWait reports whether the master still awaits the stores of a
|
||||
// new volume's replicas (its primary serves nothing until then).
|
||||
func (h *Host) inCreationWait(volumeID string) bool {
|
||||
if h.attest == nil {
|
||||
return false
|
||||
}
|
||||
waiting, _ := h.attest.awaited(volumeID, h.replicaSlotsFor(volumeID))
|
||||
return waiting > 0
|
||||
}
|
||||
|
||||
func (h *Host) primaryBootGraceHoldsNow(volumeID, replicaID string) bool {
|
||||
if h.ctrl == nil {
|
||||
return false
|
||||
|
||||
@@ -451,6 +451,7 @@ func TestMountedFailover_ProductLoopRF3PromotesWhenCurrentProbeIsDownDespiteStal
|
||||
if initial.ReplicaID != "r1" {
|
||||
t.Fatalf("initial line=%+v want r1", initial)
|
||||
}
|
||||
attestAllStores(t, h) // an established volume, out of its creation wait
|
||||
|
||||
// Heartbeat state still says r1 is acceptable. The on-demand
|
||||
// current-primary probe is the fresher failure signal and must
|
||||
|
||||
Reference in new issue
Block a user