mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
fix(master): creation ends at the primary's first ready answer at its first line
Not at the last store attestation: a primary restarted after the last attestation, before it adopts the complete assignment, was no longer creating by the record and could be replaced. The record now sets awaiting_first_ready in the same write that clears its initial set, and clears it, durably and for good, at the line's primary's first ready answer; until then the volume is creating. A record written before the field existed carries none, so an established volume is never reopened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b1c5c89a1
commit
2eb5fbfcab
3 files changed
+134
-5
No files matched your search
@@ -113,6 +113,10 @@ func establishVolume(t *testing.T, h *Host, volumeID string) {
|
||||
if err := h.ingestStoreAttestation(server, attestation(volumeID, line.ReplicaID, line.Epoch, stores)); err != nil {
|
||||
t.Fatalf("establish %s: %v", volumeID, err)
|
||||
}
|
||||
h.attest.awaited(volumeID, h.replicaSlotsFor(volumeID)) // the wait closes
|
||||
if err := h.attest.noteFirstReady(volumeID); err != nil { // the primary's first ready answer
|
||||
t.Fatalf("establish %s: %v", volumeID, err)
|
||||
}
|
||||
if line, _ := h.Publisher().VolumeAuthorityLine(volumeID); h.inCreationPhase(volumeID, line, nil) != "" {
|
||||
t.Fatalf("establish %s: still creating after the attestation (line %+v, server %q)", volumeID, line, server)
|
||||
}
|
||||
@@ -154,6 +158,10 @@ func TestCreationPhaseSurvivesAMasterRestart(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, cfg)
|
||||
if established {
|
||||
attestAllStores(t, h)
|
||||
h.attest.awaited("vol-rf3", h.replicaSlotsFor("vol-rf3"))
|
||||
if err := h.attest.noteFirstReady("vol-rf3"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
closeTestMaster(t, h)
|
||||
|
||||
@@ -169,7 +177,7 @@ func TestCreationPhaseSurvivesAMasterRestart(t *testing.T) {
|
||||
defer closeTestMaster(t, h2)
|
||||
p := &switchProbe{} // r1 not ready (not awaiting), r2 ready with evidence
|
||||
h2.SetPromotionEvidenceProvider(p)
|
||||
if got := inCreationWait(h2); got == established {
|
||||
if got := h2.inCreationPhase("vol-rf3", waitAuthorityLine(t, h2.Publisher(), "vol-rf3"), nil) != ""; got == established {
|
||||
t.Fatalf("after the restart creating=%t; want %t", got, !established)
|
||||
}
|
||||
time.Sleep(250 * time.Millisecond) // past the boot grace
|
||||
@@ -185,3 +193,49 @@ func TestCreationPhaseSurvivesAMasterRestart(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Creation ends at the primary's first ready answer at its first line, not
|
||||
// at the last store attestation: a primary restarted after the last
|
||||
// attestation, before it adopts the complete assignment (it answers not
|
||||
// ready, and no longer says it awaits the stores), is still creating: no
|
||||
// fencing round, no reassign. Its first ready answer ends creation, durably,
|
||||
// and from then on the normal rules apply.
|
||||
func TestCreationEndsAtThePrimarysFirstReadyAnswer(t *testing.T) {
|
||||
h := newBootGraceMasterCreating(t, Config{ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}})
|
||||
defer closeTestMaster(t, h)
|
||||
attestAllStores(t, h) // every store recorded: the master's wait is over
|
||||
p := probeOf(t, h)
|
||||
p.mu.Lock()
|
||||
p.empty = true // r1 answers not ready (restarted), awaiting nothing
|
||||
p.mu.Unlock()
|
||||
time.Sleep(250 * time.Millisecond) // past the boot grace
|
||||
restarted := rf3Slot{incarnation: "r1-b", reachable: true, eligible: true}
|
||||
supportedCreatingTick(t, h, restarted)
|
||||
supportedCreatingTick(t, h, restarted)
|
||||
p.mu.Lock()
|
||||
fences := p.fenceCalls
|
||||
p.mu.Unlock()
|
||||
if fences != 0 {
|
||||
t.Fatalf("%d fencing rounds before the primary's first ready answer", fences)
|
||||
}
|
||||
expectLineStaysR1(t, h, "a restarted primary before its first ready answer")
|
||||
line := waitAuthorityLine(t, h.Publisher(), "vol-rf3")
|
||||
if h.inCreationPhase("vol-rf3", line, nil) == "" {
|
||||
t.Fatal("creation ended before the primary's first ready answer")
|
||||
}
|
||||
p.mu.Lock()
|
||||
p.currentReady = true // the first ready answer
|
||||
p.mu.Unlock()
|
||||
if why := h.inCreationPhase("vol-rf3", line, nil); why != "" {
|
||||
t.Fatalf("after the first ready answer: still creating (%s)", why)
|
||||
}
|
||||
if h.attest.awaitingFirstReady("vol-rf3") {
|
||||
t.Fatal("the first ready answer was not recorded")
|
||||
}
|
||||
p.mu.Lock()
|
||||
p.currentReady = false // a later not-ready answer reopens nothing
|
||||
p.mu.Unlock()
|
||||
if why := h.inCreationPhase("vol-rf3", line, nil); why != "" {
|
||||
t.Fatalf("creation reopened after it ended (%s)", why)
|
||||
}
|
||||
}
|
||||
@@ -1104,8 +1104,10 @@ func (h *Host) freshCurrentSlot(volumeID, replicaID string) (authority.ReplicaCa
|
||||
// replacement entry (both promotion gates, the operator's move and planned
|
||||
// move, the rebalance through the gate) calls first: it returns why the
|
||||
// volume is creating, or "" once it is not. Two sources, in order:
|
||||
// - the master's own durable record still awaits a replica store (every
|
||||
// initial store attested clears it, durably; no other state);
|
||||
// - the master's own durable record: it still awaits a replica store, or
|
||||
// every store is attested but the primary has not yet answered ready at
|
||||
// its first line (its first ready answer ends creation, recorded durably
|
||||
// and for good; no other state);
|
||||
// - the current primary's own answer, when one was read, says its
|
||||
// assignment at this line's epoch still awaits the stores (the master's
|
||||
// wait may be over before the re-sent assignment arrives). The answer
|
||||
@@ -1115,6 +1117,15 @@ func (h *Host) inCreationPhase(volumeID string, current authority.AuthorityBasis
|
||||
if waiting, _ := h.attest.awaited(volumeID, h.replicaSlotsFor(volumeID)); waiting > 0 {
|
||||
return "the master's record awaits replica stores"
|
||||
}
|
||||
if h.attest.awaitingFirstReady(volumeID) {
|
||||
if !h.firstReadyNow(volumeID, current, answer) {
|
||||
return "the primary has not yet answered ready at its first line"
|
||||
}
|
||||
if err := h.attest.noteFirstReady(volumeID); err != nil {
|
||||
return "the first ready answer could not be recorded: " + err.Error()
|
||||
}
|
||||
h.log.Printf("blockmaster: volume=%s creation complete: primary %s answered ready at epoch %d", volumeID, current.ReplicaID, current.Epoch)
|
||||
}
|
||||
}
|
||||
if answer != nil && answer.CurrentKnown && current.Epoch != 0 && answer.Current.AwaitingReplicaStoresEpoch == current.Epoch {
|
||||
return "the primary's answer awaits replica stores"
|
||||
@@ -1122,6 +1133,30 @@ func (h *Host) inCreationPhase(volumeID string, current authority.AuthorityBasis
|
||||
return ""
|
||||
}
|
||||
|
||||
// firstReadyNow: the line's own primary answers ready now (from the answer
|
||||
// given, or a round of the primary alone). A primary that awaits the stores,
|
||||
// or one that does not answer, is not ready.
|
||||
func (h *Host) firstReadyNow(volumeID string, current authority.AuthorityBasis, answer *PromotionProbeResult) bool {
|
||||
if !current.Assigned || current.ReplicaID == "" {
|
||||
return false
|
||||
}
|
||||
res := answer
|
||||
if res == nil {
|
||||
h.promotionMu.RLock()
|
||||
prober := h.promotionProber
|
||||
h.promotionMu.RUnlock()
|
||||
if prober == nil {
|
||||
return false
|
||||
}
|
||||
r, err := prober.ProbePromotionCandidates(volumeID, current, nil)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
res = &r
|
||||
}
|
||||
return res.CurrentKnown && res.Current.ReplicaID == current.ReplicaID && res.Current.Ready && res.Current.AwaitingReplicaStoresEpoch == 0
|
||||
}
|
||||
|
||||
// answerOf is the probe's answer, or nil when the probe gave none.
|
||||
func answerOf(result PromotionProbeResult, ok bool) *PromotionProbeResult {
|
||||
if !ok {
|
||||
|
||||
@@ -31,6 +31,12 @@ type attestedStores struct {
|
||||
// meanwhile is not waited for); it is cleared, for good, the first time
|
||||
// every current replica has a recorded store.
|
||||
Initial []string `json:"initial,omitempty"`
|
||||
// AwaitingFirstReady: every initial store is attested, but the volume's
|
||||
// primary has not yet answered ready at its first line (first Healthy).
|
||||
// Set in the same write that clears Initial, cleared for good by the
|
||||
// first ready answer: creation ends there. A record written before this
|
||||
// field existed has none, so an established volume is never reopened.
|
||||
AwaitingFirstReady bool `json:"awaiting_first_ready,omitempty"`
|
||||
}
|
||||
|
||||
// storeAttestations is the master's record of which store each replica
|
||||
@@ -157,6 +163,7 @@ func (s *storeAttestations) awaited(volumeID string, current []string) (waiting,
|
||||
vols[k] = x
|
||||
}
|
||||
v.Initial = nil
|
||||
v.AwaitingFirstReady = true // creation ends at the primary's first ready answer
|
||||
vols[volumeID] = v
|
||||
if err := s.persist(vols); err != nil {
|
||||
// Not cleared: the volume keeps answering from its stores (nothing
|
||||
@@ -168,6 +175,38 @@ func (s *storeAttestations) awaited(volumeID string, current []string) (waiting,
|
||||
return 0, len(current)
|
||||
}
|
||||
|
||||
// awaitingFirstReady: the volume's stores are all attested and its primary
|
||||
// has not yet answered ready at its first line.
|
||||
func (s *storeAttestations) awaitingFirstReady(volumeID string) bool {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
v, had := s.vols[volumeID]
|
||||
return had && v.AwaitingFirstReady
|
||||
}
|
||||
|
||||
// noteFirstReady records, durably and for good, that the volume's primary
|
||||
// answered ready at its first line: its creation is complete.
|
||||
func (s *storeAttestations) noteFirstReady(volumeID string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
v, had := s.vols[volumeID]
|
||||
if !had || !v.AwaitingFirstReady {
|
||||
return nil
|
||||
}
|
||||
vols := make(map[string]attestedStores, len(s.vols))
|
||||
for k, x := range s.vols {
|
||||
vols[k] = x
|
||||
}
|
||||
v.AwaitingFirstReady = false
|
||||
vols[volumeID] = v
|
||||
if err := s.persist(vols); err != nil {
|
||||
return err
|
||||
}
|
||||
s.vols = vols
|
||||
s.notifyLocked(volumeID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// record merges att into the volume's record, in one write: each replica it
|
||||
// names gets that store as its reference; a replica it does not name keeps
|
||||
// its last one. An attestation from a lower epoch than the recorded one is
|
||||
@@ -200,7 +239,8 @@ func (s *storeAttestations) record(att *control.StoreAttestation) error {
|
||||
next.Stores[id] = sid
|
||||
}
|
||||
}
|
||||
next.Initial = cur.Initial // cleared only by awaited
|
||||
next.Initial = cur.Initial // cleared only by awaited
|
||||
next.AwaitingFirstReady = cur.AwaitingFirstReady // cleared only by noteFirstReady
|
||||
if had && sameAttestation(cur, next) {
|
||||
return nil
|
||||
}
|
||||
@@ -218,7 +258,7 @@ func (s *storeAttestations) record(att *control.StoreAttestation) error {
|
||||
}
|
||||
|
||||
func sameAttestation(a, b attestedStores) bool {
|
||||
if a.Primary != b.Primary || a.Epoch != b.Epoch || len(a.Stores) != len(b.Stores) || len(a.Initial) != len(b.Initial) {
|
||||
if a.Primary != b.Primary || a.Epoch != b.Epoch || len(a.Stores) != len(b.Stores) || len(a.Initial) != len(b.Initial) || a.AwaitingFirstReady != b.AwaitingFirstReady {
|
||||
return false
|
||||
}
|
||||
for k, v := range a.Stores {
|
||||
|
||||
Reference in new issue
Block a user