mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
master: the finalize judges per process and keeps every host that ever reported
Review fixes. A host that reported counts even after its reports leave the freshness window (then, with no live report and no work, it is unknown and refuses). Each volume a counted host serves needs its own live report at the level, so one unreported process refuses, naming its volume; work held only as an issued line counts the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fe9ba2478
commit
fe0f02b68e
3 files changed
+152
-34
No files matched your search
@@ -32,6 +32,9 @@ type readsLevels struct {
|
||||
window time.Duration
|
||||
now func() time.Time
|
||||
procs map[string]map[string]procLevel // server -> volume -> report
|
||||
// ever: servers that reported since this master started, kept when their
|
||||
// entries leave the freshness window (a retire forgets them).
|
||||
ever map[string]bool
|
||||
}
|
||||
|
||||
type procLevel struct {
|
||||
@@ -41,7 +44,7 @@ type procLevel struct {
|
||||
}
|
||||
|
||||
func newReadsLevels(window time.Duration) *readsLevels {
|
||||
return &readsLevels{window: window, now: time.Now, procs: map[string]map[string]procLevel{}}
|
||||
return &readsLevels{window: window, now: time.Now, procs: map[string]map[string]procLevel{}, ever: map[string]bool{}}
|
||||
}
|
||||
|
||||
// note records the level the process holding volume (on server) reported.
|
||||
@@ -52,25 +55,49 @@ func (r *readsLevels) note(server, volume, process string, level uint32) {
|
||||
r.procs[server] = map[string]procLevel{}
|
||||
}
|
||||
r.procs[server][volume] = procLevel{level: level, process: process, seen: r.now()}
|
||||
r.ever[server] = true
|
||||
}
|
||||
|
||||
// servers lists every server with a recorded report, sorted.
|
||||
// servers lists every server that reported since this master started,
|
||||
// whether or not its reports are still fresh, sorted.
|
||||
func (r *readsLevels) servers() []string {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
out := make([]string, 0, len(r.procs))
|
||||
for s := range r.procs {
|
||||
out := make([]string, 0, len(r.ever))
|
||||
for s := range r.ever {
|
||||
out = append(out, s)
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// everReported says server reported since this master started (fresh or not).
|
||||
func (r *readsLevels) everReported(server string) bool {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.ever[server]
|
||||
}
|
||||
|
||||
// belowExcept is below for the volumes not in except.
|
||||
func (r *readsLevels) belowExcept(server string, level uint32, served, except map[string]bool) []string {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
var out []string
|
||||
for v, e := range r.liveLocked(server, served) {
|
||||
if !except[v] && e.level < level {
|
||||
out = append(out, fmt.Sprintf("process %s of %s (reads level %d)", e.process, v, e.level))
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// forget drops every entry of server (a retired host).
|
||||
func (r *readsLevels) forget(server string) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
delete(r.procs, server)
|
||||
delete(r.ever, server)
|
||||
}
|
||||
|
||||
// liveLocked returns server's entries that still count: every entry of a
|
||||
@@ -109,21 +136,6 @@ func (r *readsLevels) of(server string, served map[string]bool) (uint32, bool) {
|
||||
return low, found
|
||||
}
|
||||
|
||||
// below names server's live entries below level, sorted, each as
|
||||
// "process of volume (reads level N)".
|
||||
func (r *readsLevels) below(server string, level uint32, served map[string]bool) []string {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
var out []string
|
||||
for v, e := range r.liveLocked(server, served) {
|
||||
if e.level < level {
|
||||
out = append(out, fmt.Sprintf("%s of %s (reads level %d)", e.process, v, e.level))
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// noteHeartbeat records reads for every volume a heartbeat reports (each
|
||||
// slot), naming the reporting process by the slot's incarnation (new on
|
||||
// every process start), else its data address. A heartbeat with no slot
|
||||
@@ -340,18 +352,35 @@ func (h *Host) formatTooOldReason(server string) string {
|
||||
return lifecycleclient.ReasonBinaryTooOld
|
||||
}
|
||||
|
||||
// belowLevel lists the given servers whose reported read level is below
|
||||
// level, or that have not reported, sorted, each with what it reported.
|
||||
func (h *Host) belowLevel(servers []string, level uint32) []hostBelow {
|
||||
// finalizeBelow judges the finalize per process: for each counted server,
|
||||
// every volume it serves needs that volume's own live report at level or
|
||||
// above ("volume v: no report", "volume v reads level 0"); a process it
|
||||
// reports for any other volume must read the level too; and a server whose
|
||||
// reports all left the freshness window, holding nothing, is unknown ("no
|
||||
// report"). It returns each server that fails, with what failed, sorted.
|
||||
func (h *Host) finalizeBelow(servers []string, level uint32) []hostBelow {
|
||||
var out []hostBelow
|
||||
for _, s := range servers {
|
||||
served := h.servedBy(s)
|
||||
reads, ok := h.reads.of(s, served)
|
||||
switch {
|
||||
case !ok:
|
||||
out = append(out, hostBelow{s, "no report"})
|
||||
case reads < level:
|
||||
out = append(out, hostBelow{s, "process " + strings.Join(h.reads.below(s, level, served), ", ")})
|
||||
vols := h.volumesServedBy(s)
|
||||
served := make(map[string]bool, len(vols))
|
||||
for _, v := range vols {
|
||||
served[v] = true
|
||||
}
|
||||
var failed []string
|
||||
for _, v := range vols {
|
||||
switch reads, ok := h.reads.entry(s, v, served); {
|
||||
case !ok:
|
||||
failed = append(failed, fmt.Sprintf("volume %s: no report", v))
|
||||
case reads < level:
|
||||
failed = append(failed, fmt.Sprintf("volume %s reads level %d", v, reads))
|
||||
}
|
||||
}
|
||||
failed = append(failed, h.reads.belowExcept(s, level, served, served)...)
|
||||
if _, live := h.reads.of(s, served); len(vols) == 0 && !live {
|
||||
failed = append(failed, "no report")
|
||||
}
|
||||
if len(failed) > 0 {
|
||||
out = append(out, hostBelow{s, strings.Join(failed, "; ")})
|
||||
}
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].server < out[j].server })
|
||||
@@ -406,7 +435,7 @@ func (h *Host) FinalizeFormat(level uint32) (already bool, err error) {
|
||||
return true, nil
|
||||
}
|
||||
counted := h.finalizeHosts()
|
||||
if below := h.belowLevel(counted, 1); len(below) > 0 {
|
||||
if below := h.finalizeBelow(counted, 1); len(below) > 0 {
|
||||
return false, errFormatHostsTooOld{hosts: below}
|
||||
}
|
||||
if _, err := h.attest.finalize(); err != nil {
|
||||
@@ -450,7 +479,7 @@ func (h *Host) finalizeHosts() []string {
|
||||
}
|
||||
var out []string
|
||||
for s := range candidates {
|
||||
if _, reported := h.reads.of(s, h.servedBy(s)); reported || len(h.volumesServedBy(s)) > 0 {
|
||||
if h.reads.everReported(s) || len(h.volumesServedBy(s)) > 0 {
|
||||
out = append(out, s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func TestFinalizeFormatNeedsEveryHostWithWorkOrAReportAndIsDurable(t *testing.T)
|
||||
reads *uint32
|
||||
want string
|
||||
md string
|
||||
}{{nil, "node-b (no report)", "no report"}, {ptr(uint32(0)), "node-b (process 127.0.0.1:19311 of hb-node-b (reads level 0))", "process 127.0.0.1:19311 of hb-node-b (reads level 0)"}} {
|
||||
}{{nil, "node-b (volume held: no report)", "volume held: no report"}, {ptr(uint32(0)), "volume held: no report; process 127.0.0.1:19311 of hb-node-b (reads level 0)", "volume held: no report; process 127.0.0.1:19311 of hb-node-b (reads level 0)"}} {
|
||||
if step.reads != nil {
|
||||
if err := r.fgHeartbeat("node-b", *step.reads); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -235,6 +235,9 @@ func TestFinalizeFormatNeedsEveryHostWithWorkOrAReportAndIsDurable(t *testing.T)
|
||||
if err := r.fgHeartbeat("node-b", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.fgProcessHeartbeat("node-b", "proc-held", "held", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := finalize()
|
||||
if err != nil || resp.GetFormatLevel() != 1 || resp.GetAlready() {
|
||||
t.Fatalf("finalize with every host at level 1: %+v %v", resp, err)
|
||||
@@ -697,7 +700,93 @@ func TestFinalizeFormatIgnoresAnIdleUnreportedHost(t *testing.T) {
|
||||
}
|
||||
placed.createVolume(t, "held")
|
||||
placed.place(t, "held", "node-b")
|
||||
if err := finalize(placed); reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "node-b (no report)") {
|
||||
if err := finalize(placed); reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "node-b (volume held: no report)") {
|
||||
t.Fatalf("finalize with node-b placed and unreported: %v", err)
|
||||
}
|
||||
|
||||
// node-b reported level 0, holds nothing, and its report then left the
|
||||
// freshness window: it reported once, so it still counts, and with no
|
||||
// live report it is unknown, which refuses.
|
||||
expired := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir())
|
||||
if err := expired.fgHeartbeat("node-a", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := expired.fgHeartbeat("node-b", 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now()
|
||||
expired.m.reads.mu.Lock()
|
||||
expired.m.reads.now = func() time.Time { return now.Add(time.Hour) }
|
||||
expired.m.reads.mu.Unlock()
|
||||
if err := expired.fgHeartbeat("node-a", 1); err != nil { // node-a stays fresh
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := finalize(expired); reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "node-b (no report)") {
|
||||
t.Fatalf("finalize with node-b's old report expired: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// The finalize judges per process: every volume a counted server serves
|
||||
// needs its own live report at level 1. One server, two placed volumes, one
|
||||
// of them reported at level 1 and the other not: refused, naming the
|
||||
// unreported volume only. Work held only as an issued line (a lease or an
|
||||
// assignment, its placement gone) counts the same way.
|
||||
func TestFinalizeFormatJudgesEveryServedVolume(t *testing.T) {
|
||||
finalize := func(r *isolationRig) error {
|
||||
_, err := r.lc.FinalizeFormat(r.ctx, &control.FinalizeFormatRequest{Level: 1})
|
||||
return err
|
||||
}
|
||||
r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir())
|
||||
if err := r.fgHeartbeat("node-a", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, v := range []string{"v1", "v2"} {
|
||||
r.createVolume(t, v)
|
||||
r.place(t, v, "node-b")
|
||||
}
|
||||
if err := r.fgProcessHeartbeat("node-b", "proc-v1", "v1", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := finalize(r)
|
||||
msg := status.Convert(err).Message()
|
||||
if reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(msg, "node-b (volume v2: no report)") || strings.Contains(msg, "volume v1") {
|
||||
t.Fatalf("finalize with v2 on node-b unreported: %v", err)
|
||||
}
|
||||
if _, md := lifecycleclient.ReasonDetail(err); md[lifecycleclient.HostMetadataPrefix+"node-b"] != "volume v2: no report" {
|
||||
t.Fatalf("typed detail %v, want node-b = volume v2: no report", md)
|
||||
}
|
||||
if err := r.fgProcessHeartbeat("node-b", "proc-v2", "v2", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := finalize(r); err != nil {
|
||||
t.Fatalf("finalize with both of node-b's volumes at level 1: %v", err)
|
||||
}
|
||||
|
||||
// Work held only as an issued line: vol is granted to node-a, then its
|
||||
// placement is deleted. node-a reports level 1 only for another volume,
|
||||
// so the line's volume has no report of its own: refused.
|
||||
lease := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir())
|
||||
lease.createVolume(t, "leased")
|
||||
lease.place(t, "leased", "node-a")
|
||||
if err := ingestV11(lease.m, authority.Observation{ServerID: "node-a", ObservedAt: time.Now().UTC(),
|
||||
Slots: []authority.SlotFact{{VolumeID: "leased", ReplicaID: "r1", DataAddr: "127.0.0.1:19131", CtrlAddr: "127.0.0.1:19132"}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := lease.m.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waitAuthorityLine(t, lease.m.Publisher(), "leased")
|
||||
if line := lease.m.Publisher().PublishedAuthorityLines()["leased"]; line.IssuedHost != "node-a" {
|
||||
t.Fatalf("fixture line: %+v, want issued to node-a", line)
|
||||
}
|
||||
if err := lease.m.Lifecycle().Placements.DeletePlacement("leased"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lease.m.reads.forget("node-a")
|
||||
if err := lease.fgProcessHeartbeat("node-a", "proc-other", "other", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := finalize(lease); reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "node-a (volume leased: no report)") {
|
||||
t.Fatalf("finalize with node-a holding only the leased line, unreported for it: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -838,7 +838,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` | `TestFinalizeFormatNeedsEveryHostWithWorkOrAReportAndIsDurable`, `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` | Finalize is refused, naming them, while a host with a placement, lease or assignment, or a report, does not read level 1 (an idle unreported host does not block). 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`, `finalizeHosts`, `belowLevel`; `core/authority/workspace_lease_v100.go` `FinalizeFormatLevel` | `TestFinalizeFormatNeedsEveryHostWithWorkOrAReportAndIsDurable`, `TestFinalizeFormatIgnoresAnIdleUnreportedHost`, `TestAFailedFinalizeWriteLeavesLevel0` (`core/host/master/format_gate_test.go`); `TestClusterFinalizeFormat` (`cmd/sw-block/cluster_format_test.go`) | `FormatGate` `FinalizeKeepsHosts` (mutation `finalize_ignores_reports`); `FormatGateMaster` (mutations `old_starts_after_finalize`, `finalize_not_atomic`) | ACTIVE |
|
||||
| `INV-FMT-FINALIZE-001` | Finalize is refused, naming them, while a host with work or a report lacks a live level-1 report for a volume it serves, or reports an older process (an idle unreported host does not block). Else: envelope write, then publisher switch under both locks, then answer; a failed write leaves level 0. | FormatGate Finalize | `core/host/master/format_gate.go` `FinalizeFormat`, `finalizeHosts`, `finalizeBelow`; `core/authority/workspace_lease_v100.go` `FinalizeFormatLevel` | `TestFinalizeFormatNeedsEveryHostWithWorkOrAReportAndIsDurable`, `TestFinalizeFormatIgnoresAnIdleUnreportedHost`, `TestFinalizeFormatJudgesEveryServedVolume`, `TestAFailedFinalizeWriteLeavesLevel0` (`core/host/master/format_gate_test.go`); `TestClusterFinalizeFormat` (`cmd/sw-block/cluster_format_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 |
|
||||
|
||||
Reference in new issue
Block a user