From fbcf09fcb995fc6663048124d5cb6cb04cf197c7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 2 Dec 2026 02:52:44 -0800 Subject: [PATCH] master: a late grant on an unreported host is a warning naming the volume (r2.877) An idle unreported host stays info. A host holding a placed volume that has waited for its grant past the startup window (the freshness window, from when this master first saw it waiting) is a warning naming each such volume and its wait. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/host/master/format_gate.go | 33 +++++++++++++++ .../master/format_level_new_cluster_test.go | 40 +++++++++++++++++++ seaweed-block/core/host/master/host.go | 1 + .../core/host/master/observation_snapshot.go | 21 +++++++--- 4 files changed, 90 insertions(+), 5 deletions(-) diff --git a/seaweed-block/core/host/master/format_gate.go b/seaweed-block/core/host/master/format_gate.go index 432a4d2a50..a5cf4df884 100644 --- a/seaweed-block/core/host/master/format_gate.go +++ b/seaweed-block/core/host/master/format_gate.go @@ -10,6 +10,7 @@ import ( "sync/atomic" "time" + "github.com/seaweedfs/seaweed-block/core/lifecycle" control "github.com/seaweedfs/seaweed-block/core/rpc/control" "github.com/seaweedfs/seaweed-block/core/rpc/lifecycleclient" "google.golang.org/grpc/codes" @@ -170,6 +171,38 @@ func (h *Host) awaitingFirstReport(server string) bool { return !ok } +// grantStartupWindow is how long a placed volume may wait for its grant on a +// host that has not reported before the status calls it late: the master's +// freshness window (a started holder reports within it). +func (h *Host) grantStartupWindow() time.Duration { + return h.cfg.Freshness.EffectiveFreshnessWindow() +} + +// grantsWaitingPastStartup names the volumes placed on server that have no +// authority line yet and have waited past the startup window since this +// master first saw them waiting, each with its wait. A volume that has its +// line, or that no longer names server, leaves the record. +func (h *Host) grantsWaitingPastStartup(server string, placements []lifecycle.PlacementIntent, now time.Time) []string { + window := h.grantStartupWindow() + var late []string + for _, p := range placements { + onServer := false + for _, s := range p.Slots { + onServer = onServer || s.ServerID == server + } + if _, granted := h.Publisher().VolumeAuthorityLine(p.VolumeID); granted || !onServer { + h.grantWait.Delete(p.VolumeID) + continue + } + v, _ := h.grantWait.LoadOrStore(p.VolumeID, now) + if waited := now.Sub(v.(time.Time)); waited > window { + late = append(late, fmt.Sprintf("%s (waiting %s, window %s)", p.VolumeID, waited.Round(time.Second), window)) + } + } + sort.Strings(late) + return late +} + // placementTooOld names why server may not be chosen as a placement target // (create, move, restore target, a failover candidate), or "" when it may: // only a KNOWN-old report refuses (r2.875). An unknown server is placeable, diff --git a/seaweed-block/core/host/master/format_level_new_cluster_test.go b/seaweed-block/core/host/master/format_level_new_cluster_test.go index 3f5497ab1e..b12a9826d6 100644 --- a/seaweed-block/core/host/master/format_level_new_cluster_test.go +++ b/seaweed-block/core/host/master/format_level_new_cluster_test.go @@ -4,11 +4,13 @@ import ( "bytes" "os" "path/filepath" + "strings" "testing" "time" "github.com/seaweedfs/seaweed-block/core/authority" "github.com/seaweedfs/seaweed-block/core/lifecycle" + "github.com/seaweedfs/seaweed-block/core/ops" control "github.com/seaweedfs/seaweed-block/core/rpc/control" ) @@ -199,3 +201,41 @@ func TestTheGrantReadsTheHoldersOwnReportNotASiblings(t *testing.T) { t.Fatalf("v's grant after v's own report: err %v, published %v; want granted", err, published) } } + +// On a new cluster an idle unreported host is info: the cluster stays ok. A +// host that holds a placed volume waiting for its grant past the startup +// window is a warning: the nodes degrade the cluster and the condition names +// the volume and its wait (r2.877). Before the window it is still info. +func TestAnIdleUnreportedHostLeavesTheClusterOKALateGrantDegradesIt(t *testing.T) { + r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + if _, err := r.m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-b", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322"}); err != nil { + t.Fatal(err) + } + condition := func(now time.Time) (ops.ObservationCondition, []ops.NodeEvidence, string) { + snap := r.m.ObservationSnapshot(now) + for _, n := range snap.Nodes { + for _, c := range n.Conditions { + if n.NodeName == "node-b" && c.Reason == "awaiting_first_report" { + return c, snap.Nodes, snap.Status + } + } + } + t.Fatal("node-b has no awaiting_first_report condition") + return ops.ObservationCondition{}, nil, "" + } + c, _, status := condition(time.Now()) + if c.Severity != "info" || status != ops.ObservationStatusOK { + t.Fatalf("an idle unreported host: severity %q, cluster %q; want info and ok", c.Severity, status) + } + r.createVolume(t, "waiting") + r.place(t, "waiting", "node-b") + now := time.Now() + c, nodes, _ := condition(now) // first seen waiting now + if c.Severity != "info" || clusterStatus(nil, nodes) != ops.ObservationStatusOK { + t.Fatalf("a placed volume within its startup window: severity %q; want info", c.Severity) + } + c, nodes, _ = condition(now.Add(r.m.grantStartupWindow() + time.Second)) + if c.Severity != "warning" || clusterStatus(nil, nodes) != ops.ObservationStatusDegraded || !strings.Contains(c.Message, "waiting (waiting") { + t.Fatalf("a placed volume past its startup window: severity %q, nodes status %q, message %q; want a warning naming the volume", c.Severity, clusterStatus(nil, nodes), c.Message) + } +} diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 10028bd32a..eb20fe93ee 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -153,6 +153,7 @@ type Host struct { statusHTTP *http.Server journal *journalIsolation reads *readsLevels // each server's reported format read level (format_gate.go) + grantWait sync.Map // volume -> time.Time: first seen placed on an unreported host without its grant (format_gate.go) format formatLevelState // the cluster's format level (format_gate.go) finalizeMu sync.Mutex // serializes the format finalize and host retires (format_gate.go) // testPublicationAdmission, when a test sets it before Start, wraps each diff --git a/seaweed-block/core/host/master/observation_snapshot.go b/seaweed-block/core/host/master/observation_snapshot.go index b282fed674..d21d877748 100644 --- a/seaweed-block/core/host/master/observation_snapshot.go +++ b/seaweed-block/core/host/master/observation_snapshot.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "sort" + "strings" "time" "github.com/seaweedfs/seaweed-block/core/authority" @@ -28,12 +29,22 @@ func (h *Host) ObservationSnapshot(now time.Time) ops.ClusterEvidence { cluster.Nodes = observationNodes(snapshot.Nodes, snapshot.Placements) cluster.Volumes = h.observationVolumes(snapshot) for i := range cluster.Nodes { - if h.awaitingFirstReport(cluster.Nodes[i].NodeName) { - cluster.Nodes[i].Conditions = append(cluster.Nodes[i].Conditions, ops.ObservationCondition{ - Type: "FormatLevel", Status: "AwaitingReport", Reason: "awaiting_first_report", Severity: "info", // the grant gate keeps it from serving: nothing is degraded by a spare host - Message: fmt.Sprintf("awaiting report: no format read level reported since the master started; no new work until its first heartbeat (cluster format level %d)", h.formatLevel()), - }) + node := cluster.Nodes[i].NodeName + if !h.awaitingFirstReport(node) { + continue } + // An idle unreported host is info (the grant gate keeps it from + // serving: nothing is degraded); a host holding a placed volume that + // has waited for its grant past its startup window is a warning, + // naming each such volume and its wait (r2.877). + severity, message := "info", fmt.Sprintf("awaiting report: no format read level reported since the master started; no grant until its first heartbeat (cluster format level %d)", h.formatLevel()) + if late := h.grantsWaitingPastStartup(node, snapshot.Placements, now); len(late) > 0 { + severity = "warning" + message += "; placed volumes waiting for their grant past the startup window: " + strings.Join(late, ", ") + } + cluster.Nodes[i].Conditions = append(cluster.Nodes[i].Conditions, ops.ObservationCondition{ + Type: "FormatLevel", Status: "AwaitingReport", Reason: "awaiting_first_report", Severity: severity, Message: message, + }) } cluster.Events = h.events.list("") cluster.Status = clusterStatus(cluster.Volumes, cluster.Nodes)