diff --git a/seaweed-block/core/host/master/format_gate.go b/seaweed-block/core/host/master/format_gate.go index 6c981be5d4..7b0c64d418 100644 --- a/seaweed-block/core/host/master/format_gate.go +++ b/seaweed-block/core/host/master/format_gate.go @@ -83,6 +83,17 @@ func (r *readsLevels) entry(server, volume string, served map[string]bool) (uint return e.level, ok } +// report is entry plus whether the report is fresh (within the window). A +// kept entry of a served volume whose process has been silent past the +// window is live for the grant and placement checks but stale: the finalize +// lists it rather than blocking on it. +func (r *readsLevels) report(server, volume string, served map[string]bool) (level uint32, ok, fresh bool) { + r.mu.Lock() + defer r.mu.Unlock() + e, ok := r.liveLocked(server, served)[volume] + return e.level, ok, ok && !e.seen.Before(r.now().Add(-r.window)) +} + // of is the lowest level of server's live entries, and whether it has any. func (r *readsLevels) of(server string, served map[string]bool) (uint32, bool) { r.mu.Lock() @@ -341,11 +352,12 @@ func (h *Host) formatTooOldReason(server string) string { } // finalizeCheck judges the finalize at level. Only a process that holds work -// and reports a lower level blocks it (blocking: "volume v reads level 0"). -// Every host it cannot confirm is listed, not blocking (unconfirmed): a held -// volume with no live report, a host with no live report at all, an old -// process that holds no volume. Safety stays with the grant gate, which -// refuses an old binary at grant. Both lists are sorted by server. +// and freshly reports a lower level blocks it (blocking: "volume v reads +// level 0"). Every host it cannot confirm is listed, not blocking +// (unconfirmed): a held volume with no report or only a stale one, a host +// with no live report at all, an old process that holds no volume. Safety +// stays with the grant gate, which refuses an old binary at grant and still +// reads a stale kept entry. Both lists are sorted by server. func (h *Host) finalizeCheck(level uint32) (blocking, unconfirmed []hostBelow) { candidates := map[string]bool{} for _, s := range h.reads.servers() { @@ -384,9 +396,11 @@ func (h *Host) finalizeCheck(level uint32) (blocking, unconfirmed []hostBelow) { } var block, note []string for _, v := range vols { - switch reads, ok := h.reads.entry(s, v, served); { + switch reads, ok, fresh := h.reads.report(s, v, served); { case !ok: note = append(note, fmt.Sprintf("volume %s: no report", v)) + case !fresh: + note = append(note, fmt.Sprintf("volume %s: stale report (reads level %d)", v, reads)) case reads < level: block = append(block, fmt.Sprintf("volume %s reads level %d", v, reads)) } diff --git a/seaweed-block/core/host/master/format_gate_test.go b/seaweed-block/core/host/master/format_gate_test.go index b90e2a599f..d0111f8b3d 100644 --- a/seaweed-block/core/host/master/format_gate_test.go +++ b/seaweed-block/core/host/master/format_gate_test.go @@ -259,6 +259,16 @@ func TestFinalizeFormatBlocksOnAnOldHolderAndIsDurable(t *testing.T) { } } +// listedAs says whether resp lists server with a detail containing want. +func listedAs(resp *control.FinalizeFormatResponse, server, want string) bool { + for _, u := range resp.GetUnconfirmed() { + if u.GetServerId() == server && strings.Contains(u.GetDetail(), want) { + return true + } + } + return false +} + // A host the finalize cannot confirm is listed, not blocking: a held volume // with no report, a registered host with no report, an old process that // holds no volume. The list comes with a refusal (typed metadata) and with @@ -460,8 +470,9 @@ func TestAServerKeepsASilentProcessThatStillHoldsItsVolume(t *testing.T) { // An old process holds a placed volume, a new sibling // keeps reporting, the old one falls silent past the freshness window. The -// finalize stays refused naming the old process, and at level 1 a placement -// onto the server stays refused by the format check. +// finalize lists the stale report and does not block on it; at level 1 a +// placement onto the server stays refused by the format check, which still +// reads the kept entry. func TestASilentOldHolderKeepsTheFinalizeAndNewWorkRefused(t *testing.T) { r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) now := time.Now() @@ -481,11 +492,10 @@ func TestASilentOldHolderKeepsTheFinalizeAndNewWorkRefused(t *testing.T) { if err := r.fgProcessHeartbeat("node-b", "new-proc", "vb", 1); err != nil { t.Fatal(err) } - _, err := r.lc.FinalizeFormat(r.ctx, &control.FinalizeFormatRequest{Level: 1}) - if reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "volume va reads level 0") { - t.Fatalf("finalize with a silent old holder of va: %v", err) + resp, err := r.lc.FinalizeFormat(r.ctx, &control.FinalizeFormatRequest{Level: 1}) + if err != nil || !listedAs(resp, "node-b", "volume va: stale report (reads level 0)") { + t.Fatalf("finalize with a silent old holder of va: %+v %v, want finalized listing node-b's stale report", resp, err) } - r.m.format.v.Store(1) if why := r.m.formatTooOld("node-b"); why == "" { t.Fatal("level 1: node-b takes new work while its silent old process still holds va") } @@ -541,7 +551,7 @@ func TestThePublicationBoundaryRefusesAnAskForAnOldServer(t *testing.T) { // A heartbeat that reports several volumes records the level for each: an // old process reporting [va, vb] is kept for vb, still placed on its // server, after va stops being served and the report ages past the -// window. +// window: the grant for vb is refused; the finalize lists the stale report. func TestEveryVolumeOfAHeartbeatKeepsItsLevel(t *testing.T) { r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) now := time.Now() @@ -565,9 +575,14 @@ func TestEveryVolumeOfAHeartbeatKeepsItsLevel(t *testing.T) { if err := r.fgProcessHeartbeat("node-b", "new-proc", "vc", 1); err != nil { t.Fatal(err) } - _, err := r.lc.FinalizeFormat(r.ctx, &control.FinalizeFormatRequest{Level: 1}) - if reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "volume vb reads level 0") { - t.Fatalf("finalize with the old process still holding vb (its second slot): %v", err) + r.m.format.v.Store(1) + if why := r.m.grantTooOld("node-b", "vb"); !strings.Contains(why, "binary_too_old") { + t.Fatalf("level 1: the grant for vb, held by the silent old process: %q, want binary_too_old", why) + } + r.m.format.v.Store(0) + resp, err := r.lc.FinalizeFormat(r.ctx, &control.FinalizeFormatRequest{Level: 1}) + if err != nil || !listedAs(resp, "node-b", "volume vb: stale report (reads level 0)") { + t.Fatalf("finalize with the old process's stale report for vb: %+v %v, want finalized listing it", resp, err) } } @@ -577,8 +592,10 @@ func TestEveryVolumeOfAHeartbeatKeepsItsLevel(t *testing.T) { // mid-lease, on an old binary, serves nothing until the line is re-issued for // its new incarnation, and that re-issue is refused at the publication // boundary (binary_too_old) on the new process's own report: the line keeps -// naming the dead process. The control restarts on a binary that reads the -// level and gets the line re-issued for it. +// naming the dead process, though a sibling process on the same server keeps +// reporting level 1 (the grant reads p2's own report, never p1's or a +// sibling's). The control restarts on a binary that reads the level and gets +// the line re-issued for it. func TestAHolderRestartedOnAnOldBinaryIsNotReissuedItsLine(t *testing.T) { for _, old := range []bool{true, false} { t.Run(map[bool]string{true: "old-binary", false: "control"}[old], func(t *testing.T) { @@ -625,6 +642,10 @@ func TestAHolderRestartedOnAnOldBinaryIsNotReissuedItsLine(t *testing.T) { Slots: []*control.HeartbeatSlot{{VolumeId: "v", ReplicaId: "r1", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302", Incarnation: inc, Reachable: true, Eligible: true}}}); err != nil { t.Fatal(err) } + // A sibling process on node-b, serving another volume, reads level 1. + if err := r.fgProcessHeartbeat("node-b", "sibling", "w", 1); err != nil { + t.Fatal(err) + } } // waitFor ticks the product loop and heartbeats inc until cond holds. waitFor := func(what, inc string, reads uint32, cond func() bool) { diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index 143b6dc618..5c9312b8e8 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -151,8 +151,8 @@ type FinalizeFormatResponse struct { FormatLevel uint32 `protobuf:"varint,1,opt,name=format_level,json=formatLevel,proto3" json:"format_level,omitempty"` Already bool `protobuf:"varint,2,opt,name=already,proto3" json:"already,omitempty"` // the cluster was already at this level: nothing written // Hosts the finalize could not confirm and did not block on: a held - // volume with no live report, a host with no report, an old process that - // holds no volume. The grant gate refuses an old binary at grant. + // volume with no report or a stale one, a host with no report, an old + // process that holds no volume. The grant gate refuses an old binary at grant. Unconfirmed []*FormatHostNote `protobuf:"bytes,3,rep,name=unconfirmed,proto3" json:"unconfirmed,omitempty"` } diff --git a/seaweed-block/core/rpc/proto/control.proto b/seaweed-block/core/rpc/proto/control.proto index cf198e4234..21ff5b90f2 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -122,7 +122,7 @@ service LifecycleService { // FinalizeFormat raises the cluster's format level to 1 (the v1.1 // format), durably and one-way: a v1.0.x master refuses the store from // then on, and holders may upgrade. Refused (FAILED_PRECONDITION, reason - // FORMAT_HOSTS_TOO_OLD) only while a live report of a process that holds + // FORMAT_HOSTS_TOO_OLD) only while a fresh report of a process that holds // a volume reads below level 1; the refusal names each one. Hosts it // cannot confirm are answered in unconfirmed and do not block. // At level 1 it succeeds without writing. @@ -148,8 +148,8 @@ message FinalizeFormatResponse { uint32 format_level = 1; bool already = 2; // the cluster was already at this level: nothing written // Hosts the finalize could not confirm and did not block on: a held - // volume with no live report, a host with no report, an old process that - // holds no volume. The grant gate refuses an old binary at grant. + // volume with no report or a stale one, a host with no report, an old + // process that holds no volume. The grant gate refuses an old binary at grant. repeated FormatHostNote unconfirmed = 3; } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index b27ae25b5e..b02f22d4e1 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -856,7 +856,7 @@ Notes: | `INV-WS-RESTART-GRACE-001` | At format level 1, a renewal writes nothing durable. A forced move, an expired re-grant and a no-live-lease proof wait for this process's deadline plus skew: its latest grant, or after a restart the restart floor (restart + TTL); no lease value an earlier process wrote is read. | M2 Granted → Granted; Expired → Moved (forced); Expired → Granted; any → DeleteReserved | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `regrantWorkspaceLease`, `newWorkspaceLease`; `core/authority/workspace.go` `forcedMoveBarrierLocked`, `AckWorkspaceRevocation`; `core/authority/authority.go` `reloadFromStore` (the restart floor) | `TestRenewalWritesNothingDurable`, `TestForcedAdmissionIgnoresAPersistedHorizon` (`core/authority/workspace_restart_grace_test.go`); `TestWorkspaceLeaseGuardServesThroughAStalledStore` (`core/host/master/workspace_lease_horizon_test.go`); `TestAfterARestartADifferentHolderIsRefusedUntilTheRestartFloor`, `TestAfterARestartTheSameLiveHolderRenewsAtOnce` (`core/authority/workspace_restart_barrier_test.go`) | `LeaseRestart` `OneServer` (grace design) | ACTIVE | | `INV-WS-AUTH-RECORD-V2-001` | The format finalize writes the store's attestation file as format 2 (`INV-FMT-LEVEL-001`), on which a v1.0.x master refuses its whole start; from then on its authority records are envelope version 2 (a v1.0.x master would skip them); before it, both are v1.0's. It reads both forms of each. | M2 every workspace write; master start | `core/host/master/store_attestation.go` `ensureEnvelope`, `decodeStoreAttestations`; `core/host/master/host.go` `New`; `core/authority/authority_store.go` `storeEnvelopeVersion`, `encodeEnvelope`, `decodeEnvelope` | `TestAV100MasterRefusesTheAttestationEnvelope`, `TestAttestationsWriteTheV100FileUntilTheFinalize`, `TestAttestationsReadTheV100File` (`core/host/master/golden_v100_test.go`); `TestARecordWrittenNowFailsTheV100Decoder` (`core/authority/workspace_restart_grace_test.go`); `TestAuthorityStoreWritesTheV100Files`, `TestAuthorityStoreReadsTheV100Files` (`core/authority/golden_v100_test.go`) | — | ACTIVE | | `INV-FMT-LEVEL-001` | The cluster's format level is the attestation file's form: v1.0.x's bare map is level 0, the envelope (format 2, format_level 1) level 1. It only rises: the finalize is its only writer, and an envelope below level 1 is refused at start. | FormatGate Finalize (level 0 → 1) | `core/host/master/store_attestation.go` `decodeStoreAttestations`, `finalize`, `persist`, `level`; `core/host/master/host.go` `New` | `TestFinalizeFormatBlocksOnAnOldHolderAndIsDurable`, `TestAnAttestationEnvelopeBelowLevel1IsRefused` (`core/host/master/format_gate_test.go`); `TestAttestationsWriteTheV100FileUntilTheFinalize`, `TestAV100MasterRefusesTheAttestationEnvelope` (`core/host/master/golden_v100_test.go`) | `FormatGate` `OneWay` (mutation `level_lowered`) | ACTIVE | -| `INV-FMT-FINALIZE-001` | The finalize is refused, naming them, only while a live report of a process holding a volume reads below 1; hosts it cannot confirm are listed, not blocking. Else it writes the envelope durably, then switches the publisher under both its locks, then answers; a failed write leaves level 0. | FormatGate Finalize | `core/host/master/format_gate.go` `FinalizeFormat`, `finalizeCheck`; `core/authority/workspace_lease_v100.go` `FinalizeFormatLevel` | `TestFinalizeFormatBlocksOnAnOldHolderAndIsDurable`, `TestFinalizeFormatListsTheHostsItCannotConfirm`, `TestAFailedFinalizeWriteLeavesLevel0`, `TestAHolderRestartedOnAnOldBinaryIsNotReissuedItsLine` (`core/host/master/format_gate_test.go`); `TestHost_ApplyFact_LineIssuedForAnotherProcessIsNotAdopted` (`core/host/volume/line_incarnation_test.go`); `TestClusterFinalizeFormat` (`cmd/sw-block/cluster_format_test.go`); `TestClusterFinalizeFormatTypedAnswer` (`cmd/sw-block/cluster_format_json_test.go`) | `FormatGate` `FinalizeKeepsHosts` (mutation `finalize_ignores_reports`); `FormatGateMaster` (mutations `old_starts_after_finalize`, `finalize_not_atomic`) | ACTIVE | +| `INV-FMT-FINALIZE-001` | The finalize is refused, naming them, only while a fresh report of a process holding a volume reads below 1; hosts with no or a stale report are listed, not blocking. Else it writes the envelope durably, then switches the publisher under both its locks, then answers; a failed write leaves level 0. | FormatGate Finalize | `core/host/master/format_gate.go` `FinalizeFormat`, `finalizeCheck`; `core/authority/workspace_lease_v100.go` `FinalizeFormatLevel` | `TestFinalizeFormatBlocksOnAnOldHolderAndIsDurable`, `TestFinalizeFormatListsTheHostsItCannotConfirm`, `TestAFailedFinalizeWriteLeavesLevel0`, `TestAHolderRestartedOnAnOldBinaryIsNotReissuedItsLine` (`core/host/master/format_gate_test.go`); `TestHost_ApplyFact_LineIssuedForAnotherProcessIsNotAdopted` (`core/host/volume/line_incarnation_test.go`); `TestClusterFinalizeFormat` (`cmd/sw-block/cluster_format_test.go`); `TestClusterFinalizeFormatTypedAnswer` (`cmd/sw-block/cluster_format_json_test.go`) | `FormatGate` `FinalizeKeepsHosts` (mutation `finalize_ignores_reports`); `FormatGateMaster` (mutations `old_starts_after_finalize`, `finalize_not_atomic`) | ACTIVE | | `INV-FMT-ELIGIBLE-001` | At level L no new work goes to a server known to read below L: no placement or move target (binary_too_old). An unreported server is placeable; no line is granted to a holder process before its own report. Heartbeats are recorded, never refused. Placed work stays. Every assignment carries L. | FormatGate Assign (placement, move, failover) | `core/host/master/format_gate.go` `formatEligible`, `formatTooOld`, `placementTooOld`, `grantTooOld`; `core/host/master/journal_isolation.go` `newWorkRefused`, `reconcilePlacements`; `core/host/master/workspace_binding.go` `PlaceWorkspace`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/host/master/services.go` `ReportHeartbeat`, `assignmentFact` | `TestFormatGateRecordsAnOldBinarysHeartbeatAtLevel1`, `TestFormatGateRefusesPlacementAndMoveOntoAnOldHost`, `TestFormatGateProductLoopPlacesOnlyOnHostsThatReadTheLevel`, `TestAssignmentFactCarriesTheFormatLevel` (`core/host/master/format_gate_test.go`) | `FormatGate` `NoStrand` (mutation `place_ignores_reads_level`) | ACTIVE | | `INV-FMT-LEVEL0-V100-001` | At format level 0 the master writes as v1.0: grants clamp to the persisted horizon, an extender keeps it current, forced moves and re-grants wait for the later of horizon and deadline plus skew, records are version 1. Every grant raises the deadline at both levels. | M2 Granted → Granted; Expired → Moved (forced); Expired → Granted (level 0) | `core/authority/workspace_lease_v100.go` `renewV100Locked`, `extendWorkspaceLease`, `forcedMoveBarrierV100Locked`, `ackValidityLocked`, `envelopeVersionLocked`; `core/authority/workspace_lease_view.go` `RenewWorkspaceLease` | `TestALevel0RenewalKeepsTheHorizonCurrent`, `TestALevel0GrantIsClampedToTheHorizon`, `TestTheForcedBarrierFollowsTheFormatLevel`, `TestRecordEnvelopeVersionFollowsTheFormatLevel` (`core/authority/workspace_format_level_test.go`) | `FormatGateMaster` `OneServer`, `GraceOnlyFinal` (mutations `level0_no_horizon`, `old_starts_after_finalize`) | ACTIVE | | `INV-FMT-RETIRE-001` | A host retire, the node registry's only writer after start, is refused, naming the volumes, while the host holds a placement or a live line, and unless confirm repeats the id. A retired id is unregistered; if the host returns it registers again at its reported level. | FormatGate Retire | `core/host/master/format_gate.go` `RetireHost`; `core/host/master/journal_isolation.go` `volumesServedBy` | `TestRetireHostRefusesAHostThatHoldsWork` (`core/host/master/format_gate_test.go`); `TestClusterRetireHost` (`cmd/sw-block/cluster_format_test.go`); `TestNodeRegistryIsWrittenOnlyAtStartup` (`cmd/blockmaster/node_registry_guard_test.go`) | `FormatGate` r2 `OneServer` (mutation `retire_holding_host`) | ACTIVE | diff --git a/seaweed-block/docs/releases/v1.1.md b/seaweed-block/docs/releases/v1.1.md index 9294293f66..113a7718ae 100644 --- a/seaweed-block/docs/releases/v1.1.md +++ b/seaweed-block/docs/releases/v1.1.md @@ -46,7 +46,7 @@ These notes collect v1.1's changes as they land; v1.1 is not released. format, and blockmaster keeps v1.0's lease semantics, until `sw-block cluster finalize-format --master `. Each host reports the format its binary reads; the finalize refuses only while a process that holds a volume reports that it reads an older format, and names each one: upgrade it, or move its volumes. Every host it cannot confirm (a - held volume with no report yet, a host with no report, an old process that holds no volume) is listed in the answer + held volume with no report or a stale one, a host with no report, an old process that holds no volume) is listed in the answer and in `--json` (`listed`), and does not block. Such a host, if it runs an old binary, is refused (`binary_too_old`) when it asks for a grant. A host that holds nothing can be retired (`sw-block cluster retire-host --server --confirm --master `, refused while the host still holds a volume).