diff --git a/seaweed-block/core/host/master/creating_primary_gate_test.go b/seaweed-block/core/host/master/creating_primary_gate_test.go index b3379fdf40..b6eebf8ea9 100644 --- a/seaweed-block/core/host/master/creating_primary_gate_test.go +++ b/seaweed-block/core/host/master/creating_primary_gate_test.go @@ -70,7 +70,9 @@ func TestMasterRestartInTheGapDoesNotReassign(t *testing.T) { } h2.Start() defer closeTestMaster(t, h2) - h2.SetPromotionEvidenceProvider(&switchProbe{awaitingEpoch: waitAuthorityLine(t, h2.Publisher(), "vol-rf3").Epoch}) + // The primary still awaits the stores: it served nothing, so no survivor + // holds a write (every end is zero). + h2.SetPromotionEvidenceProvider(&switchProbe{awaitingEpoch: waitAuthorityLine(t, h2.Publisher(), "vol-rf3").Epoch, empty: true}) if inCreationWait(h2) { t.Fatal("fixture: the restarted master still waits for stores") } diff --git a/seaweed-block/core/host/master/creation_phase_test.go b/seaweed-block/core/host/master/creation_phase_test.go index 94ac320dea..fed91b925b 100644 --- a/seaweed-block/core/host/master/creation_phase_test.go +++ b/seaweed-block/core/host/master/creation_phase_test.go @@ -115,7 +115,7 @@ func establishVolume(t *testing.T, h *Host, volumeID string) { 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 + if _, err := h.attest.noteFirstReady(volumeID); err != nil { // creation ended (the primary's first ready answer) t.Fatalf("establish %s: %v", volumeID, err) } if line, _ := h.Publisher().VolumeAuthorityLine(volumeID); h.inCreationPhase(volumeID, line, nil) != "" { @@ -160,7 +160,7 @@ func TestCreationPhaseSurvivesAMasterRestart(t *testing.T) { if established { attestAllStores(t, h) h.attest.awaited("vol-rf3", h.replicaSlotsFor("vol-rf3")) - if err := h.attest.noteFirstReady("vol-rf3"); err != nil { + if _, err := h.attest.noteFirstReady("vol-rf3"); err != nil { t.Fatal(err) } } @@ -195,13 +195,12 @@ 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) { +// Creation does not end at the last store attestation: a primary restarted +// after it, before it adopts the complete assignment (it answers not ready, +// and no longer says it awaits the stores), with no write on any survivor, +// is still creating: no fencing round, no reassign. Creation ends at a +// ready answer or a survivor's write (TestCreationEndsAtTheFirstReadyAnswerOrASurvivorsWrite). +func TestCreationOutlivesTheLastStoreAttestation(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 @@ -222,32 +221,17 @@ func TestCreationEndsAtThePrimarysFirstReadyAnswer(t *testing.T) { 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) + t.Fatal("creation ended with no write on any survivor") } } -// recordFirstReady records that the volume's primary answered ready at its -// first line (after its stores were attested): fixtures whose primary was -// healthy before the scenario's failure. +// recordFirstReady records the end of creation (after the stores were +// attested), as the primary's first ready answer does: fixtures whose +// primary was healthy before the scenario's failure. func recordFirstReady(t *testing.T, h *Host, volumeID string) { t.Helper() h.attest.awaited(volumeID, h.replicaSlotsFor(volumeID)) - if err := h.attest.noteFirstReady(volumeID); err != nil { + if _, err := h.attest.noteFirstReady(volumeID); err != nil { t.Fatal(err) } } diff --git a/seaweed-block/core/host/master/creation_survivor_test.go b/seaweed-block/core/host/master/creation_survivor_test.go new file mode 100644 index 0000000000..5b3c23e9df --- /dev/null +++ b/seaweed-block/core/host/master/creation_survivor_test.go @@ -0,0 +1,244 @@ +package master + +import ( + "os" + "path/filepath" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// restartCreatingMaster closes h and starts a master on the same stores, +// with a fresh switchProbe (r1 not ready, r2 ready holding DurableLSN 70). +func restartCreatingMaster(t *testing.T, h *Host, cfg Config) *Host { + t.Helper() + closeTestMaster(t, h) + cfg.Listen = "127.0.0.1:0" + cfg.ControllerConfig.ExpectedSlotsPerVolume = 3 + cfg.Freshness.FreshnessWindow = testFreshness + cfg.Freshness.PendingGrace = time.Millisecond + h2, err := New(cfg) + if err != nil { + t.Fatalf("master restart: %v", err) + } + h2.Start() + h2.SetPromotionEvidenceProvider(&switchProbe{}) + return h2 +} + +// operatorProbe is a switchProbe with the sync-quorum profile the +// operator's move reads from its gate. +type operatorProbe struct{ *switchProbe } + +func (operatorProbe) AckProfile() string { return "sync_quorum" } + +// withOperatorProbe installs p behind the operator's ack profile. +func withOperatorProbe(h *Host, p *switchProbe) { h.SetPromotionEvidenceProvider(operatorProbe{p}) } + +// The gap the creation phase must not open: every store is attested, the +// primary serves at once and a write is acknowledged by the quorum (r2 +// holds it: DurableLSN 70), and the primary dies before any gate tick could +// read a ready answer from it. The volume served, so it is not creating: +// the operator's failover moves it (decided on the fencing round). Without +// a write on any survivor (it served nothing), it is still creating and +// the failover is refused. +func TestAVolumeWhosePrimaryDiedAfterAQuorumWriteFailsOver(t *testing.T) { + for _, wrote := range []bool{true, false} { + t.Run(map[bool]string{true: "a survivor holds the write", false: "no write anywhere"}[wrote], func(t *testing.T) { + h := newBootGraceMasterCreating(t, Config{}) + defer closeTestMaster(t, h) + attestAllStores(t, h) // stage 2: the primary may serve now + p := probeOf(t, h) + p.mu.Lock() + p.currentUnknown = true // the primary is gone: it never answers + p.empty = !wrote + p.mu.Unlock() + withOperatorProbe(h, p) + ingestRF3Incarnations(t, h, silent, readySlot("r2-a"), readySlot("r3-a")) + _, err := h.plannedMoveEvidence("vol-rf3", "r2") + if wrote { + if err != nil { + t.Fatalf("the operator's failover after a quorum-acknowledged write: %v", err) + } + if h.attest.awaitingFirstReady("vol-rf3") { + t.Fatal("the survivor's write did not end creation durably") + } + return + } + if err != ErrMoveWhileCreating { + t.Fatalf("a volume no survivor holds a write of: err=%v; want ErrMoveWhileCreating", err) + } + }) + } +} + +// Creation ends at the first of the primary's ready answer and a +// survivor's answer that it holds a write of the current line; until then +// (stores attested, a not-ready primary, empty survivors) it is creating. +// Ending is one-way and durable. +func TestCreationEndsAtTheFirstReadyAnswerOrASurvivorsWrite(t *testing.T) { + for _, by := range []string{"the primary's ready answer", "a survivor's write"} { + t.Run(by, func(t *testing.T) { + cfg := Config{AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir()} + h := newBootGraceMasterCreating(t, cfg) + attestAllStores(t, h) + p := probeOf(t, h) + p.mu.Lock() + p.empty = true // a not-ready primary, nothing on any survivor + p.mu.Unlock() + line := waitAuthorityLine(t, h.Publisher(), "vol-rf3") + if h.inCreationPhase("vol-rf3", line, nil) == "" { + t.Fatal("creation ended with a not-ready primary and empty survivors") + } + // Neither a survivor's row at another epoch nor the primary's own + // DurableLSN ends it. + for _, c := range []PromotionCandidateEvidence{{ReplicaID: "r2", DurableLSN: 9, LastDataEpoch: line.Epoch + 1}, {ReplicaID: "r1", DurableLSN: 9}} { + if h.inCreationPhase("vol-rf3", line, &PromotionProbeResult{Candidates: []PromotionCandidateEvidence{c}}) == "" { + t.Fatalf("creation ended on %+v", c) + } + } + p.mu.Lock() + if by == "a survivor's write" { + p.empty = false // r2 answers DurableLSN 70; r1 still not ready + } else { + p.currentReady = true // a Healthy volume that never took a write + } + p.mu.Unlock() + if why := h.inCreationPhase("vol-rf3", line, nil); why != "" { + t.Fatalf("after %s: still creating (%s)", by, why) + } + p.mu.Lock() + p.empty, p.currentReady = true, false // later answers reopen nothing + p.mu.Unlock() + if why := h.inCreationPhase("vol-rf3", line, nil); why != "" { + t.Fatalf("creation reopened after it ended (%s)", why) + } + h2 := restartCreatingMaster(t, h, cfg) + defer closeTestMaster(t, h2) + pr := probeOf(t, h2) + pr.mu.Lock() + pr.empty = true + pr.mu.Unlock() + if why := h2.inCreationPhase("vol-rf3", waitAuthorityLine(t, h2.Publisher(), "vol-rf3"), nil); why != "" { + t.Fatalf("after a restart the ended creation is back (%s)", why) + } + }) + } +} + +// When the write that ends the store wait fails, the volume stays held (as +// waiting) and nothing replaces it: no probe, no fencing round, no move, +// also after a restart; once the write succeeds the normal stages follow. +func TestAFailedEndOfTheStoreWaitKeepsTheVolumeHeld(t *testing.T) { + cfg := Config{AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), + ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}} + h := newBootGraceMasterCreating(t, cfg) + line := waitAuthorityLine(t, h.Publisher(), "vol-rf3") + // Every store recorded, but the record's next write fails: a directory + // stands at its temp path. + 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) + } + block := filepath.Join(cfg.AuthorityStoreDir, storeAttestationFile+".tmp") + if err := os.Mkdir(block, 0o755); err != nil { + t.Fatal(err) + } + time.Sleep(250 * time.Millisecond) // past the boot grace + dead := restarting + dead.eligible = false + for i := 0; i < 2; i++ { + if why := h.inCreationPhase("vol-rf3", line, nil); why == "" { + t.Fatal("a failed write of the end of the store wait released the volume") + } + creatingTick(t, h, dead) + expectLineStaysR1(t, h, "the end of the store wait not recorded") + if _, err := h.plannedMoveEvidence("vol-rf3", "r2"); err != ErrMoveWhileCreating { + t.Fatalf("operator move: err=%v; want ErrMoveWhileCreating", err) + } + } + if h.attest.awaitingFirstReady("vol-rf3") { + t.Fatal("memory moved to stage 2 without the write") + } + h = restartCreatingMaster(t, h, cfg) + if why := h.inCreationPhase("vol-rf3", line, nil); why == "" { + t.Fatal("after a restart the unrecorded end released the volume") + } + if err := os.Remove(block); err != nil { + t.Fatal(err) + } + // The write succeeds: stage 2, ended at once by r2's write (DurableLSN 70). + if why := h.inCreationPhase("vol-rf3", line, nil); why != "" { + t.Fatalf("after the write succeeded: still creating (%s)", why) + } + closeTestMaster(t, h) +} + +// The primary's own answer alone holds a volume whose master record holds +// nothing (an established volume): its assignment at the current epoch +// still awaits the stores. The matching epoch holds on both gates and the +// operator's fenced path; a stale epoch holds nothing (the controls that +// the fixture would move). Removing the answer guard fails the holds. +func TestThePrimarysAwaitingAnswerAloneHoldsAnEstablishedVolume(t *testing.T) { + for _, matching := range []bool{true, false} { + name := map[bool]string{true: "matching epoch", false: "stale epoch"}[matching] + setup := func(t *testing.T) (*Host, *switchProbe) { + h := newBootGraceMaster(t, Config{ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}}) + if h.attest.awaitingFirstReady("vol-rf3") || inCreationWait(h) { + t.Fatal("fixture: the record still holds the volume") + } + p := probeOf(t, h) + epoch := waitAuthorityLine(t, h.Publisher(), "vol-rf3").Epoch + if !matching { + epoch++ + } + p.mu.Lock() + p.awaitingEpoch = epoch + p.mu.Unlock() + time.Sleep(250 * time.Millisecond) // past the boot grace + return h, p + } + t.Run("unsupported gate/"+name, func(t *testing.T) { + h, _ := setup(t) + defer closeTestMaster(t, h) + ineligible := restarting + ineligible.eligible = false + unsupportedTick(t, h, ineligible) + if matching { + expectLineStaysR1(t, h, "the primary's awaiting answer") + return + } + expectFailoverToR2(t, h, "a stale awaiting answer") + }) + t.Run("supported gate/"+name, func(t *testing.T) { + h, p := setup(t) + defer closeTestMaster(t, h) + supportedCreatingTick(t, h, rf3Slot{incarnation: "r1-a", reachable: true, eligible: true}) + p.mu.Lock() + fences := p.fenceCalls + p.mu.Unlock() + line, _ := h.Publisher().VolumeAuthorityLine("vol-rf3") + moved := fences > 0 || line.ReplicaID != "r1" + if matching && moved { + t.Fatalf("the primary's awaiting answer: fences=%d line=%+v", fences, line) + } + if !matching && !moved { + t.Fatal("control: a stale awaiting answer took no replacement decision") + } + }) + t.Run("operator's fenced path/"+name, func(t *testing.T) { + h, p := setup(t) + defer closeTestMaster(t, h) + withOperatorProbe(h, p) + ingestRF3Incarnations(t, h, silent, readySlot("r2-a"), readySlot("r3-a")) // the primary unreachable: the fenced path + _, err := h.plannedMoveEvidence("vol-rf3", "r2") + if matching && err != ErrMoveWhileCreating { + t.Fatalf("err=%v; want ErrMoveWhileCreating", err) + } + if !matching && err == ErrMoveWhileCreating { + t.Fatal("control: a stale awaiting answer refused the move as creating") + } + }) + } +} diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index 7699250c2e..f70b3deca6 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -1103,28 +1103,42 @@ func (h *Host) freshCurrentSlot(volumeID, replicaID string) (authority.ReplicaCa // inCreationPhase is the one decision of the creation phase, which every // 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: 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 -// can only hold a volume, never release one. +// volume is creating, or "" once creation ended. A replacement acts only on +// ended: one durable, one-way fact in the master's record, written by the +// first of +// - the line's primary answering ready (its first Healthy), or +// - a survivor answering DurableLSN > 0 at the current line (under the +// quorum ack every acknowledged write is on a survivor, so a volume +// that served and lost its primary before the master read a ready +// answer still ends creation and fails over), +// once every initial store is attested (stage 1 holds whatever is +// answered). Nothing clears it. Besides, the current +// primary's own answer, when one was read, holds the volume while its +// assignment at this line's epoch still awaits the stores (the master's +// wait may be over before the re-sent assignment arrives); an answer can +// only hold a volume, never release one. func (h *Host) inCreationPhase(volumeID string, current authority.AuthorityBasis, answer *PromotionProbeResult) string { if h.attest != nil { 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" + by := "" + if h.firstReadyNow(volumeID, current, answer) { + by = "primary " + current.ReplicaID + " answered ready" + } else if holder, ok := h.survivorHoldingAWrite(volumeID, current, answer); ok { + by = "survivor " + holder + " holds a write" + } else { + return "neither a ready answer of the primary nor a write on a survivor yet" } - if err := h.attest.noteFirstReady(volumeID); err != nil { - return "the first ready answer could not be recorded: " + err.Error() + ended, err := h.attest.noteFirstReady(volumeID) + if err != nil { + return "the end of creation 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 !ended { + return "creation may not end now" + } + h.log.Printf("blockmaster: volume=%s creation complete: %s at %s@%d", volumeID, by, current.ReplicaID, current.Epoch) } } if answer != nil && answer.CurrentKnown && current.Epoch != 0 && answer.Current.AwaitingReplicaStoresEpoch == current.Epoch { @@ -1157,6 +1171,56 @@ func (h *Host) firstReadyNow(volumeID string, current authority.AuthorityBasis, return res.CurrentKnown && res.Current.ReplicaID == current.ReplicaID && res.Current.Ready && res.Current.AwaitingReplicaStoresEpoch == 0 } +// survivorHoldingAWrite: a survivor (any replica but the line's own) answers, +// in a probe of the current line, DurableLSN > 0 with its epoch-table row at +// the current epoch (or no row). It reads the answer given, else a round of +// the survivors alone. It names the survivor. +func (h *Host) survivorHoldingAWrite(volumeID string, current authority.AuthorityBasis, answer *PromotionProbeResult) (string, 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, h.survivorCandidates(volumeID, current.ReplicaID)) + if err != nil { + return "", false + } + res = &r + } + for _, c := range res.Candidates { + if c.ReplicaID == "" || c.ReplicaID == current.ReplicaID { + continue + } + if c.DurableLSN > 0 && (c.LastDataEpoch == 0 || c.LastDataEpoch == current.Epoch) { + return c.ReplicaID, true + } + } + return "", false +} + +// survivorCandidates are the volume's replicas other than the line's own, +// each from its fresh heartbeat slot when it has one. +func (h *Host) survivorCandidates(volumeID, currentReplica string) []authority.ReplicaCandidate { + var out []authority.ReplicaCandidate + for _, id := range h.replicaSlotsFor(volumeID) { + if id == currentReplica { + continue + } + c, ok := h.freshCurrentSlot(volumeID, id) + if !ok { + c = authority.ReplicaCandidate{ReplicaID: id} + } + out = append(out, c) + } + return out +} + // answerOf is the probe's answer, or nil when the probe gave none. func answerOf(result PromotionProbeResult, ok bool) *PromotionProbeResult { if !ok { diff --git a/seaweed-block/core/host/master/store_attestation.go b/seaweed-block/core/host/master/store_attestation.go index 819b441f60..c69e7c1ec1 100644 --- a/seaweed-block/core/host/master/store_attestation.go +++ b/seaweed-block/core/host/master/store_attestation.go @@ -31,11 +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: every initial store is attested, but creation has + // not ended: neither has the primary answered ready nor a survivor + // answered that it holds a write of the current line. Set in the same + // write that clears Initial, cleared for good by the first of the two + // (creation ended). A record written before this field existed has none, + // so an established volume is never reopened. AwaitingFirstReady bool `json:"awaiting_first_ready,omitempty"` } @@ -166,17 +167,19 @@ func (s *storeAttestations) awaited(volumeID string, current []string) (waiting, 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 - // awaited); the next call retries the write. - return 0, len(current) + // Not recorded: the volume stays in its wait (reported as one store + // awaited) until the end of the wait is durable; the next call + // retries the write. Releasing it here would end creation with no + // durable record of its next stage. + return 1, len(current) } s.vols = vols s.notifyLocked(volumeID) return 0, len(current) } -// awaitingFirstReady: the volume's stores are all attested and its primary -// has not yet answered ready at its first line. +// awaitingFirstReady: the volume's stores are all attested and its creation +// has not ended. func (s *storeAttestations) awaitingFirstReady(volumeID string) bool { s.mu.Lock() defer s.mu.Unlock() @@ -184,14 +187,14 @@ func (s *storeAttestations) awaitingFirstReady(volumeID string) bool { 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 { +// noteFirstReady records, durably and for good, that the volume's creation +// ended. It reports whether creation has ended (false: it may not end now). +func (s *storeAttestations) noteFirstReady(volumeID string) (bool, error) { s.mu.Lock() defer s.mu.Unlock() v, had := s.vols[volumeID] if !had || !v.AwaitingFirstReady { - return nil + return true, nil } vols := make(map[string]attestedStores, len(s.vols)) for k, x := range s.vols { @@ -200,11 +203,11 @@ func (s *storeAttestations) noteFirstReady(volumeID string) error { v.AwaitingFirstReady = false vols[volumeID] = v if err := s.persist(vols); err != nil { - return err + return false, err } s.vols = vols s.notifyLocked(volumeID) - return nil + return true, nil } // record merges att into the volume's record, in one write: each replica it diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 37fcfd0ad1..44d23bc377 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -958,7 +958,7 @@ Notes: | `INV-AUTH-ONE-PRIMARY-001` | A volume's authority line names one replica at its highest epoch, a reassignment supersedes the previous primary, and observed dual primaries make the volume `invalid`. A genesis `Bind` is refused once any slot of the volume holds a line. | M2 Unbound → Bound, Bound → Reassigned; K8s readiness | `core/authority/authority.go` `applyWithWorkspaceMove` (`IntentBind`, `boundReplicaForVolume`); `core/authority/policy.go` `VolumeAuthorityLine`; `core/authority/controller.go` `decideVolume`; `core/ops/managed_volume_model.go` `classifyManagedVolume` | `TestG8_0_Publisher_ReassignAdvancesPerVolumeEpochAcrossReplicaSlots` (`core/authority/g8_0_authority_failover_test.go`); `TestPublisher_RunRejectsSecondSlotGenesisBind` (`core/authority/bind_volume_regression_test.go`); `TestPublisher_BindSecondSlotOfBoundVolumeRejected`, `TestPublisher_BindOtherVolumeUnaffected`, `TestPublisher_ReassignToOtherSlotStillAllowedThenBindRejected`, `TestPublisher_BindAfterRestartRejectedForAnySlot` (`core/authority/bind_volume_genesis_test.go`); `TestManagedVolumeProjection_InvalidDualPrimaryBeatsReady` (`core/ops/managed_volume_model_test.go`) | — | ACTIVE | | `INV-FENCE-STALE-PRIMARY-001` | Once a primary has observed a newer line for another replica, its backend refuses `Read`, `Write` and `Sync`, and replicas refuse its frames below their epoch floor. | M3 Primary → Supporting \| Excluded | `core/host/volume/projection_bridge.go` `projectionWithSupersede`; `core/frontend/durable/storage_adapter.go` `lineageCheck`; `core/transport/replica.go` `admitMutation` | `TestG8A_SupersedeFact_FencesOldPrimaryDurableBackend` (`core/host/volume/g8a_stale_fence_test.go`); `TestG2_PromotedHostRefusesShipFromDeposedPrimary` (`core/host/volume/g2_self_fence_test.go`) | `ReplicationFailover` `NoStaleAck` | ACTIVE | | `INV-PROMOTE-FRONTIER-001` | With a known required acknowledgement frontier under `sync_quorum` or `sync_all`, the RF=3 promotion gate allows only probed-ready candidates whose durable LSN is at least the required LSN. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas`, `applyPromotionEvidenceGate`; `core/host/master/probe_round.go` (`SyncAckKnown`); `core/engine/promotion_ready.go` `BuildPromotionReadyFact` | `TestMountedFailover_ProductLoopRF3PromotesCandidateCoveringSyncAckProbe` (`core/host/master/product_loop_test.go`); `TestPromotionAllowedReplicas_RequiredFrontierCoverage`, `TestWorkloadPlanProvider_RequiredFrontierKnownness` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE | -| `INV-PROMOTE-CREATION-WAIT-001` | Creation is its own phase, ending at the line's primary's first ready answer (recorded durably, for good): before it, or while the primary answers that it awaits replica stores, no replacement decision is made (reassign, fencing round, heal, operator move, rebalance); checked first. | CreatePromo model (VolumeCreate x Promotion) | `core/host/master/product_loop.go` `inCreationPhase`, `holdCreating`, `applyPromotionEvidenceGate`, `applyUnsupportedPromotionEvidenceGate`; `core/host/master/planned_move.go` `plannedMoveEvidence`; `core/host/master/store_attestation.go` `awaited`; `core/host/volume/probe_round.go` `probeAnswer` | `TestCreatingVolumeRunsNoFencingRoundOnTheSupportedGate`, `TestCreatingVolumeIsNotReplacedWhenItsPrimaryIsSilent`, `TestCreationEndsAtThePrimarysFirstReadyAnswer`, `TestCreatingVolumeRefusesTheOperatorsMove`, `TestCreationPhaseSurvivesAMasterRestart` (`core/host/master/creation_phase_test.go`); `TestPrimaryAwaitingReplicaStoresIsNotReplacedForNotReady`, `TestMasterRestartInTheGapDoesNotReassign`, `TestCreatingPrimaryNotReadyForAnotherReasonIsNotReplaced`, `TestCreatingVolumeWithAStaleAwaitingAnswerIsNotReplaced`, `TestCreatingPrimaryWithAnUnacceptableSlotIsNotReplaced` (`core/host/master/creating_primary_gate_test.go`); `TestProbeRound_CarriesThePrimarysAwaitingStoresEpoch` (`core/host/master/probe_round_test.go`); `TestProbeAnswerReadsTheWaitBeforeReadiness`, `TestProbeAnswerAfterTheWaitNamesNothing` (`core/host/volume/replica_stores_wait_test.go`) | — | ACTIVE | +| `INV-PROMOTE-CREATION-WAIT-001` | Creation is its own phase, ended durably and for good by the first of: the line's primary's ready answer, or a survivor answering DurableLSN > 0 at the line. Until then, or while the primary answers it awaits replica stores, no replacement decision is made; checked first. | CreateEvid2 model (VolumeCreate x Promotion, survivor evidence) | `core/host/master/product_loop.go` `inCreationPhase`, `firstReadyNow`, `survivorHoldingAWrite`, `holdCreating`, `applyPromotionEvidenceGate`, `applyUnsupportedPromotionEvidenceGate`; `core/host/master/planned_move.go` `plannedMoveEvidence`; `core/host/master/store_attestation.go` `awaited`; `core/host/volume/probe_round.go` `probeAnswer` | `TestCreatingVolumeRunsNoFencingRoundOnTheSupportedGate`, `TestCreatingVolumeIsNotReplacedWhenItsPrimaryIsSilent`, `TestCreationOutlivesTheLastStoreAttestation`, `TestCreatingVolumeRefusesTheOperatorsMove`, `TestCreationPhaseSurvivesAMasterRestart` (`core/host/master/creation_phase_test.go`); `TestPrimaryAwaitingReplicaStoresIsNotReplacedForNotReady`, `TestMasterRestartInTheGapDoesNotReassign`, `TestCreatingPrimaryNotReadyForAnotherReasonIsNotReplaced`, `TestCreatingVolumeWithAStaleAwaitingAnswerIsNotReplaced`, `TestCreatingPrimaryWithAnUnacceptableSlotIsNotReplaced` (`core/host/master/creating_primary_gate_test.go`); `TestAVolumeWhosePrimaryDiedAfterAQuorumWriteFailsOver`, `TestCreationEndsAtTheFirstReadyAnswerOrASurvivorsWrite`, `TestAFailedEndOfTheStoreWaitKeepsTheVolumeHeld`, `TestThePrimarysAwaitingAnswerAloneHoldsAnEstablishedVolume` (`core/host/master/creation_survivor_test.go`); `TestAVolumeThatServedBeforeItsFirstGateTickFailsOver` (`cmd/blockvolume/creation_gap_integration_test.go`, tagged); `TestProbeRound_CarriesThePrimarysAwaitingStoresEpoch` (`core/host/master/probe_round_test.go`); `TestProbeAnswerReadsTheWaitBeforeReadiness`, `TestProbeAnswerAfterTheWaitNamesNothing` (`core/host/volume/replica_stores_wait_test.go`) | — | ACTIVE | | `INV-PROMOTE-FRONTIER-PROBE-001` | For a replicated volume (two or more slots), the gate allows no candidate unless this tick's promotion probe succeeded with a known ack profile. | M3 Supporting → promotion candidate (the gate, RF=2 and up) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate`, `promotionAllowedReplicas` | `TestMountedFailover_ProductLoopRF3BlocksFailoverWithoutFreshPromotionProbe` (`core/host/master/product_loop_test.go`); `TestMountedFailover_ProductLoopRF2DecidesOnThePromotionGate` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE | | `INV-PROMOTE-UNKNOWN-CURRENT-001` | A current primary whose status cannot be read (probe refused, timed out, pod gone) is unknown, never failed: no promotion path reassigns on it; a direct reassign needs the primary's own not-ready report. | M3 Primary → promotion candidate (both promotion paths) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate` (supported path), `applyUnsupportedPromotionEvidenceGate` (unsupported path) | `TestUnsupportedPathNeverReassignsOnAnUnansweredPrimary` (`core/host/master/primary_boot_grace_gate_test.go`); `TestMountedFailover_ProductLoopRF3DoesNotReassignWhenCurrentSlotMissing` (`core/host/master/product_loop_test.go`). Limits: Kubernetes alpha failover on node or pod loss is a manual admin action in this release; the admin's failover runs the fencing round and publishes only on its decision (basis Fenced) when the primary is unreachable (no fresh, reachable heartbeat; any replica count); a reachable RF3 `sync_quorum` primary's move stays refused (it needs a seal) and `best_effort` stays refused (`core/host/master/planned_move.go` `fencedMoveEvidence`; `TestManualFailoverRF3SyncQuorumDecidesOnTheFencingRound`, `TestManualFailoverRF2UnreachablePrimaryDecidesOnTheFencingRound`, `TestManualFailoverRF2BestEffortIsNeverFenced`, `TestManualFailoverRF3ReachablePrimaryIsRefused`, `TestManualFailoverAndThePromotionLoopPublishOneLine`) | — | ACTIVE | | `INV-PROMOTE-FRONTIER-UNKNOWN-001` | With an unknown frontier under `sync_quorum` or `sync_all`, the gate allows the highest-durable ready candidate only if at least N_peers-K+1 of the N_peers peers are probed ready this tick and have a fresh heartbeat (K as in `waitForSyncAcks`); else none. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas`, `unknownFrontierSurvivorsNeeded`, `freshPromotionPeers`; `core/replication/async_ack.go` `waitForSyncAcks` | `TestMountedFailover_ProductLoopRF3UnknownRequiredLSNFallsBackToHighestDurableLSN` (`core/host/master/product_loop_test.go`); `TestProductLoop_MissingRequiredFrontierRefusesRF3Promotion` (`core/host/master/promotion_missing_frontier_regression_test.go`); `TestUnknownFrontierSurvivorsNeeded`, `TestFreshPromotionPeers_UsesObservationFreshness`, `TestProductLoop_UnknownFrontierSurvivorReadyLastTickMissingNowRefused` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |