From b03e43d26f4dd1f726aa1e833911e52bb19818d2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:16:53 -0800 Subject: [PATCH 1/9] test: interleave independent heartbeat slots on one server --- .../observation_store_slot_order_test.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 seaweed-block/core/authority/observation_store_slot_order_test.go diff --git a/seaweed-block/core/authority/observation_store_slot_order_test.go b/seaweed-block/core/authority/observation_store_slot_order_test.go new file mode 100644 index 0000000000..e41191a2fd --- /dev/null +++ b/seaweed-block/core/authority/observation_store_slot_order_test.go @@ -0,0 +1,42 @@ +package authority + +import ( + "fmt" + "testing" + "time" +) + +// V1-SPEC r2.53: independent processes on one server order only their +// own (volume, replica) reports; another slot's later timestamp is irrelevant. +func TestObservationStore_InterleavedSendersOrderPerSlot(t *testing.T) { + for _, n := range []int{10, 100} { + t.Run(fmt.Sprintf("%d slots", n), func(t *testing.T) { + base := time.Unix(1000, 0) + now := base.Add(3 * time.Second) + s := NewObservationStore(FreshnessConfig{FreshnessWindow: 10 * time.Second}, func() time.Time { return now }) + for round := 0; round < 2; round++ { + for i := n - 1; i >= 0; i-- { + slot := healthySlot(fmt.Sprintf("v%d", i/2), fmt.Sprintf("r%d", i%2+1)) + slot.DataAddr = fmt.Sprintf("round-%d-slot-%d", round, i) + at := base.Add(time.Duration(round)*time.Second + time.Duration(i)*time.Millisecond) + obs, err := HeartbeatToObservation(serverObs("one-host", at, slot)) + if err != nil { + t.Fatal(err) + } + if err := s.Ingest(obs); err != nil { + t.Fatal(err) + } + } + } + for i := 0; i < n; i++ { + got, ok := s.SlotFactOnServer("one-host", fmt.Sprintf("v%d", i/2), fmt.Sprintf("r%d", i%2+1)) + if !ok || got.DataAddr != fmt.Sprintf("round-1-slot-%d", i) { + t.Errorf("slot %d lost an independent sender's heartbeat: fact=%+v present=%v", i, got, ok) + } + } + if got := s.SupersededCount(); got != 0 { + t.Fatalf("other senders superseded %d slot reports", got) + } + }) + } +} From f305ecd6cf28372774abcf53c89efb6803041751 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:17:25 -0800 Subject: [PATCH 2/9] fix: order heartbeat reports within each replica slot --- .../core/authority/observation_store.go | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index fbf1bb65f2..343d584df8 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -35,18 +35,18 @@ type ObservationStore struct { revision uint64 onMutation func() - // supersededCount counts heartbeat ingests that were dropped - // because a newer ObservedAt was already stored for the same - // ServerID. Diagnostic only — PCDD-DELAYED-HB-001 evidence + // supersededCount counts slot reports that were dropped because a + // newer ObservedAt was stored for that server/volume/replica slot. + // Diagnostic only — PCDD-DELAYED-HB-001 evidence // surface. Not an authority input; publisher / controller / // evidence minting paths MUST NOT read it. Exposed via // SupersededCount(). supersededCount uint64 } -// SupersededCount returns the total number of ingests that were -// dropped because a newer observation from the same server was -// already stored. Diagnostic surface for PCDD-DELAYED-HB-001. +// SupersededCount returns the total number of slot reports dropped +// because a newer report of that same server/volume/replica was stored. +// Diagnostic surface for PCDD-DELAYED-HB-001. // NOT authority input. Monotonic across the lifetime of the store. func (s *ObservationStore) SupersededCount() uint64 { s.mu.Lock() @@ -292,42 +292,45 @@ func (s *ObservationStore) ingest(obs Observation) ([]SlotHealthTransition, erro var transitions []SlotHealthTransition s.mu.Lock() prev, hadPrev := s.observations[obs.ServerID] - if hadPrev { - if prev.ObservedAt.After(obs.ObservedAt) { - // Out-of-order ingest: keep the newer one already - // stored. No mutation fired. - // - // Diagnostic counter for PCDD-DELAYED-HB-001. Not an - // authority input. Must never be read by publisher / - // controller / evidence minting path — it exists so - // tests and operators can see that a superseded - // heartbeat was observed and recorded-as-superseded, - // distinct from "silently dropped". - s.supersededCount++ - s.mu.Unlock() - return nil, nil - } - } // Health transitions, from this accepted report against the same - // server's previously stored fact for each slot it carries. + // slot's stored fact. V1-SPEC r2.53: timestamps order one sender's + // slot only; a later report from another slot cannot supersede it. + accepted := make([]SlotFact, 0, len(obs.Slots)) for _, slot := range obs.Slots { old := "" + superseded := false if hadPrev { for _, p := range prev.Slots { if slotKey(p) == slotKey(slot) { old = p.UnhealthyReason + superseded = slotObservedAt(p, prev).After(slot.ObservedAt) break } } } + if superseded { + s.supersededCount++ + continue + } + accepted = append(accepted, slot) if old != slot.UnhealthyReason { transitions = append(transitions, SlotHealthTransition{ VolumeID: slot.VolumeID, ReplicaID: slot.ReplicaID, Old: old, New: slot.UnhealthyReason, }) } } + if len(obs.Slots) > 0 && len(accepted) == 0 { + s.mu.Unlock() + return nil, nil + } + obs.Slots = accepted if hadPrev { obs.Slots = mergeServerSlots(prev.Slots, obs.Slots) + if prev.ObservedAt.After(obs.ObservedAt) { + // Preserve the newest server metadata without lending its + // timestamp or freshness to another process's slot. + obs.ObservedAt, obs.ExpiresAt, obs.Server = prev.ObservedAt, prev.ExpiresAt, prev.Server + } } s.observations[obs.ServerID] = obs s.revision++ From d06879b76c57dd4b98e61b930b3fa232c73ece97 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:18:19 -0800 Subject: [PATCH 3/9] test: pin mixed-slot supersession and independent expiry --- .../core/authority/observation_store.go | 11 ++--- .../observation_store_slot_order_test.go | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 343d584df8..74e0ec43b8 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -10,7 +10,7 @@ import ( // ============================================================ // P14 S4 — Observation Store // -// Push-ingested latest-wins observation store per ServerID. The +// Push-ingested latest-wins observation store per replica slot. The // store computes derived freshness on read, based on wall-clock // time vs ObservedAt + FreshnessWindow. Expired observations stay // visible; they are just semantically ineligible for supported @@ -231,11 +231,10 @@ var ErrInvalidObservation = errors.New("observation_store: invalid observation") // ExpiresAt, and fires the registered mutation callback if // anything changed. // -// Latest-wins per ServerID. If an incoming observation has an -// ObservedAt strictly older than the currently-stored one from -// the same server, the store keeps the newer one (ignores the -// stale ingest). No error is returned for that case; it's a -// routine ordering event, not a bug. +// Latest-wins per (ServerID, volume, replica). A slot report strictly +// older than that slot's stored fact is ignored; other slots in the +// observation are accepted independently. No error is returned for +// superseded reports. func (s *ObservationStore) Ingest(obs Observation) error { _, err := s.ingest(obs) return err diff --git a/seaweed-block/core/authority/observation_store_slot_order_test.go b/seaweed-block/core/authority/observation_store_slot_order_test.go index e41191a2fd..33f191ce2e 100644 --- a/seaweed-block/core/authority/observation_store_slot_order_test.go +++ b/seaweed-block/core/authority/observation_store_slot_order_test.go @@ -40,3 +40,51 @@ func TestObservationStore_InterleavedSendersOrderPerSlot(t *testing.T) { }) } } + +func TestObservationStore_MixedSlotReportKeepsOnlyNewerFacts(t *testing.T) { + base := time.Unix(1000, 0) + now := base.Add(4 * time.Second) + s := NewObservationStore(FreshnessConfig{FreshnessWindow: 10 * time.Second}, func() time.Time { return now }) + report := func(at time.Duration, slots ...SlotFact) []SlotHealthTransition { + t.Helper() + tr, err := s.IngestWithHealthTransitions(Observation{ServerID: "one-host", ObservedAt: base.Add(at), Slots: slots}) + if err != nil { + t.Fatal(err) + } + return tr + } + a, b, c := healthySlot("a", "r1"), healthySlot("b", "r1"), healthySlot("c", "r1") + report(3*time.Second, a) + report(time.Second, b) + a.UnhealthyReason, b.UnhealthyReason, c.UnhealthyReason = "stale", "new-b", "new-c" + mutations := 0 + s.SetOnMutation(func() { mutations++ }) + tr := report(2*time.Second, a, b, c) + if len(tr) != 2 || tr[0].VolumeID != "b" || tr[0].New != "new-b" || tr[1].VolumeID != "c" || tr[1].New != "new-c" { + t.Fatalf("mixed report transitions=%+v; want only b and c", tr) + } + if got, ok := s.SlotFactOnServer("one-host", "a", "r1"); !ok || got.UnhealthyReason != "" { + t.Fatalf("stale a replaced its newer fact: %+v, %v", got, ok) + } + if s.SupersededCount() != 1 || mutations != 1 { + t.Fatalf("mixed report: superseded=%d mutations=%d; want 1/1", s.SupersededCount(), mutations) + } + rev := s.Snapshot().revision + if tr := report(time.Second, a, b, c); len(tr) != 0 { + t.Fatalf("all-stale report emitted transitions: %+v", tr) + } + if s.SupersededCount() != 4 || mutations != 1 || s.Snapshot().revision != rev { + t.Fatalf("all-stale report: superseded=%d mutations=%d revision=%d; want 4/1/%d", s.SupersededCount(), mutations, s.Snapshot().revision, rev) + } + // The server's timestamp stays at its newest report; each accepted slot + // keeps its own expiry, including after a delayed mixed report. + now = base.Add(12500 * time.Millisecond) + if _, ok := s.SlotFactOnServer("one-host", "a", "r1"); !ok { + t.Fatal("a lost its later expiry to another slot's older report") + } + for _, volume := range []string{"b", "c"} { + if _, ok := s.SlotFactOnServer("one-host", volume, "r1"); ok { + t.Fatalf("%s inherited a's later freshness", volume) + } + } +} From 69e5951dc615fbe532c423a06602644b5267169f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:20:13 -0800 Subject: [PATCH 4/9] docs: state the heartbeat slot clock limit --- seaweed-block/docs/operator-guide.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index c611d56232..cbff179009 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -54,6 +54,11 @@ one live blockvolume per volume ([one process per volume](releases/one-process-p - **SeaweedFS space:** every cut and snapshot stores the chunks that changed since the previous one. Space comes back only by GC and then a SeaweedFS vacuum (below). +Each volume process reports its own heartbeat slot (server, volume and replica). +The master orders each slot against that slot's previous report. In version 1.0, +a backward host-clock step longer than the freshness window (10 seconds by +default) can expire the host's slots; keep host clocks synchronized. + ## Recovery point and sync policy - **A stopped volume** keeps everything it acknowledged, on its host. From 41e70e6a6a88e7f68dbf99fa16121f072c7c7b1e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:21:17 -0800 Subject: [PATCH 5/9] test: require unlocked per-slot superseded heartbeat diagnostics --- .../observation_store_slot_order_test.go | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/seaweed-block/core/authority/observation_store_slot_order_test.go b/seaweed-block/core/authority/observation_store_slot_order_test.go index 33f191ce2e..71e25c106e 100644 --- a/seaweed-block/core/authority/observation_store_slot_order_test.go +++ b/seaweed-block/core/authority/observation_store_slot_order_test.go @@ -1,11 +1,68 @@ package authority import ( + "bytes" "fmt" + "log" + "strings" "testing" "time" ) +type unlockedHeartbeatLog struct { + bytes.Buffer + store *ObservationStore + locked bool +} + +func (w *unlockedHeartbeatLog) Write(p []byte) (int, error) { + if w.store.mu.TryLock() { + w.store.mu.Unlock() + } else { + w.locked = true + } + return w.Buffer.Write(p) +} + +func TestObservationStore_SupersededSlotLogsAfterUnlock(t *testing.T) { + base := time.Unix(1000, 0) + s := NewObservationStore(FreshnessConfig{}, func() time.Time { return base }) + w := &unlockedHeartbeatLog{store: s} + old := log.Writer() + log.SetOutput(w) + t.Cleanup(func() { log.SetOutput(old) }) + for _, server := range []string{"one-host", "other-host"} { + for _, volume := range []string{"a", "b"} { + slot := healthySlot(volume, "r1") + if err := s.Ingest(Observation{ServerID: server, ObservedAt: base, Slots: []SlotFact{slot}}); err != nil { + t.Fatal(err) + } + } + } + for _, tc := range []struct{ server, volume string }{{"one-host", "a"}, {"one-host", "a"}, {"one-host", "b"}, {"other-host", "a"}} { + if err := s.Ingest(Observation{ServerID: tc.server, ObservedAt: base.Add(-time.Second), Slots: []SlotFact{healthySlot(tc.volume, "r1")}}); err != nil { + t.Fatal(err) + } + } + if w.locked { + t.Fatal("superseded diagnostic was emitted while the store lock was held") + } + lines := strings.Split(strings.TrimSpace(w.String()), "\n") + if len(lines) != 4 { + t.Fatalf("diagnostics=%q; want one line per dropped slot", w.String()) + } + for i, want := range []string{ + "server=one-host volume=a replica=r1 sent_at=1970-01-01T00:16:39Z newest=1970-01-01T00:16:40Z total=1", + "server=one-host volume=a replica=r1 sent_at=1970-01-01T00:16:39Z newest=1970-01-01T00:16:40Z total=2", + "server=one-host volume=b replica=r1 sent_at=1970-01-01T00:16:39Z newest=1970-01-01T00:16:40Z total=1", + "server=other-host volume=a replica=r1 sent_at=1970-01-01T00:16:39Z newest=1970-01-01T00:16:40Z total=1", + } { + if !strings.Contains(lines[i], "heartbeat superseded "+want) { + t.Errorf("diagnostic %d=%q; want %q", i, lines[i], want) + } + } +} + // V1-SPEC r2.53: independent processes on one server order only their // own (volume, replica) reports; another slot's later timestamp is irrelevant. func TestObservationStore_InterleavedSendersOrderPerSlot(t *testing.T) { From 6d7435313e2c0944e68cb8b819011c3d1b4d67a1 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:21:41 -0800 Subject: [PATCH 6/9] feat: report superseded heartbeat counts per slot after unlock --- .../core/authority/observation_store.go | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 74e0ec43b8..5bd3b4f8a7 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -2,6 +2,7 @@ package authority import ( "errors" + "log" "sort" "sync" "time" @@ -42,6 +43,7 @@ type ObservationStore struct { // evidence minting paths MUST NOT read it. Exposed via // SupersededCount(). supersededCount uint64 + supersededSlots map[[3]string]uint64 } // SupersededCount returns the total number of slot reports dropped @@ -54,6 +56,14 @@ func (s *ObservationStore) SupersededCount() uint64 { return s.supersededCount } +// SupersededSlotCount is the diagnostic count for one reporting slot. +// Like SupersededCount, it is not an authority input. +func (s *ObservationStore) SupersededSlotCount(serverID, volumeID, replicaID string) uint64 { + s.mu.Lock() + defer s.mu.Unlock() + return s.supersededSlots[[3]string{serverID, volumeID, replicaID}] +} + // SlotFact returns the most-recently-observed SlotFact for a // (volumeID, replicaID) pair across all reporting servers, or // (zero, false) if no server has reported that slot. @@ -201,10 +211,11 @@ func NewObservationStore(config FreshnessConfig, now func() time.Time) *Observat } cfg := config.withDefaults() return &ObservationStore{ - config: cfg, - now: now, - startedAt: now(), - observations: map[string]Observation{}, + config: cfg, + now: now, + startedAt: now(), + observations: map[string]Observation{}, + supersededSlots: make(map[[3]string]uint64), } } @@ -289,6 +300,19 @@ func (s *ObservationStore) ingest(obs Observation) ([]SlotHealthTransition, erro var fn func() var transitions []SlotHealthTransition + var dropped []struct { + volume, replica string + sentAt, newest time.Time + total uint64 + } + // Both the all-superseded and mixed-report paths release mu before + // returning. Logging never runs under the store lock. + defer func() { + for _, d := range dropped { + log.Printf("heartbeat superseded server=%s volume=%s replica=%s sent_at=%s newest=%s total=%d", + obs.ServerID, d.volume, d.replica, d.sentAt.UTC().Format(time.RFC3339Nano), d.newest.UTC().Format(time.RFC3339Nano), d.total) + } + }() s.mu.Lock() prev, hadPrev := s.observations[obs.ServerID] // Health transitions, from this accepted report against the same @@ -297,18 +321,25 @@ func (s *ObservationStore) ingest(obs Observation) ([]SlotHealthTransition, erro accepted := make([]SlotFact, 0, len(obs.Slots)) for _, slot := range obs.Slots { old := "" - superseded := false + var newest time.Time if hadPrev { for _, p := range prev.Slots { if slotKey(p) == slotKey(slot) { old = p.UnhealthyReason - superseded = slotObservedAt(p, prev).After(slot.ObservedAt) + newest = slotObservedAt(p, prev) break } } } - if superseded { + if newest.After(slot.ObservedAt) { s.supersededCount++ + key := [3]string{obs.ServerID, slot.VolumeID, slot.ReplicaID} + s.supersededSlots[key]++ + dropped = append(dropped, struct { + volume, replica string + sentAt, newest time.Time + total uint64 + }{slot.VolumeID, slot.ReplicaID, slot.ObservedAt, newest, s.supersededSlots[key]}) continue } accepted = append(accepted, slot) From 7e0648a1a6b25cf53fdf9a77cc64bf5bff9eaecb Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:22:11 -0800 Subject: [PATCH 7/9] test: check readable per-slot superseded totals --- seaweed-block/core/authority/observation_store.go | 9 +++------ .../core/authority/observation_store_slot_order_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 5bd3b4f8a7..424c89da21 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -300,11 +300,12 @@ func (s *ObservationStore) ingest(obs Observation) ([]SlotHealthTransition, erro var fn func() var transitions []SlotHealthTransition - var dropped []struct { + type supersededReport struct { volume, replica string sentAt, newest time.Time total uint64 } + var dropped []supersededReport // Both the all-superseded and mixed-report paths release mu before // returning. Logging never runs under the store lock. defer func() { @@ -335,11 +336,7 @@ func (s *ObservationStore) ingest(obs Observation) ([]SlotHealthTransition, erro s.supersededCount++ key := [3]string{obs.ServerID, slot.VolumeID, slot.ReplicaID} s.supersededSlots[key]++ - dropped = append(dropped, struct { - volume, replica string - sentAt, newest time.Time - total uint64 - }{slot.VolumeID, slot.ReplicaID, slot.ObservedAt, newest, s.supersededSlots[key]}) + dropped = append(dropped, supersededReport{slot.VolumeID, slot.ReplicaID, slot.ObservedAt, newest, s.supersededSlots[key]}) continue } accepted = append(accepted, slot) diff --git a/seaweed-block/core/authority/observation_store_slot_order_test.go b/seaweed-block/core/authority/observation_store_slot_order_test.go index 71e25c106e..cbcc535ef4 100644 --- a/seaweed-block/core/authority/observation_store_slot_order_test.go +++ b/seaweed-block/core/authority/observation_store_slot_order_test.go @@ -61,6 +61,12 @@ func TestObservationStore_SupersededSlotLogsAfterUnlock(t *testing.T) { t.Errorf("diagnostic %d=%q; want %q", i, lines[i], want) } } + if s.SupersededSlotCount("one-host", "a", "r1") != 2 || + s.SupersededSlotCount("one-host", "b", "r1") != 1 || + s.SupersededSlotCount("other-host", "a", "r1") != 1 || + s.SupersededSlotCount("other-host", "b", "r1") != 0 || s.SupersededCount() != 4 { + t.Fatal("per-slot diagnostics disagree with emitted totals or aggregate count") + } } // V1-SPEC r2.53: independent processes on one server order only their From d59c640128a92f6ba6e8db80158f112c9df77eab Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 17:26:07 -0800 Subject: [PATCH 8/9] docs: trace heartbeat slot ordering to its invariant --- seaweed-block/core/authority/observation_store.go | 3 ++- .../core/authority/observation_store_slot_order_test.go | 2 +- seaweed-block/docs/design/invariants.md | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 424c89da21..dbf1229678 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -317,7 +317,8 @@ func (s *ObservationStore) ingest(obs Observation) ([]SlotHealthTransition, erro s.mu.Lock() prev, hadPrev := s.observations[obs.ServerID] // Health transitions, from this accepted report against the same - // slot's stored fact. V1-SPEC r2.53: timestamps order one sender's + // slot's stored fact. INV-OBS-SLOT-ORDER-001 / V1-SPEC r2.53: + // timestamps order one sender's // slot only; a later report from another slot cannot supersede it. accepted := make([]SlotFact, 0, len(obs.Slots)) for _, slot := range obs.Slots { diff --git a/seaweed-block/core/authority/observation_store_slot_order_test.go b/seaweed-block/core/authority/observation_store_slot_order_test.go index cbcc535ef4..e13d0ca8d5 100644 --- a/seaweed-block/core/authority/observation_store_slot_order_test.go +++ b/seaweed-block/core/authority/observation_store_slot_order_test.go @@ -69,7 +69,7 @@ func TestObservationStore_SupersededSlotLogsAfterUnlock(t *testing.T) { } } -// V1-SPEC r2.53: independent processes on one server order only their +// INV-OBS-SLOT-ORDER-001 / V1-SPEC r2.53: processes on one server order only their // own (volume, replica) reports; another slot's later timestamp is irrelevant. func TestObservationStore_InterleavedSendersOrderPerSlot(t *testing.T) { for _, n := range []int{10, 100} { diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 7831af1871..ac65b7368d 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -467,7 +467,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -315 rows: 244 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 300 new. +316 rows: 245 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 301 new. The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger. @@ -930,6 +930,7 @@ Notes: | `INV-CSI-CONSUMES-AUTHORITY-001` | CSI never imports authority code or builds assignment facts; it takes the publish target from blockmaster and refreshes it before a stage, and blockmaster mints the IDs of the events CSI reports. | M2 (read side) | `core/csi/master_backend.go` `LookupPublishTarget`; `core/csi/node.go` `refreshPublishContext`; `core/host/master/observation_service.go` `ReportClusterEvent` | `TestG15a_CSI_DoesNotImportAuthorityOrConstructAssignmentFacts` (`core/csi/boundary_guard_test.go`); `TestG15e_CSIReattachUsesFreshPublishTargetAfterUnstage` (`core/csi/node_test.go`); `TestObservationService_ReportClusterEventAppearsInVolumeTimeline` (`core/host/master/observation_service_test.go`) | — | ACTIVE | | `INV-K8S-NONLOOPBACK-001` | Generated multi-node Helm values enable external iSCSI, external status and loopback rejection; with rejection enabled CSI never publishes a loopback target and fails closed when only loopback targets exist. | M2 (read side) | `cmd/sw-block/main.go` `runOpsGenerateHelmValues`; `core/csi/master_backend.go` `rejectFrontendAddr` | `TestOpsGenerateHelmValuesMultiNodeExternalISCSI` (`cmd/sw-block/main_test.go`); `TestNodeLoss_ControlStatusLookup_RejectsLoopbackPublishTargetsWhenEnabled`, `TestNodeLoss_ControlStatusLookup_FailClosedWhenOnlyLoopbackTargets` (`core/csi/master_backend_test.go`) | — | ACTIVE | | `INV-OBS-PRODUCT-EVENTS-001` | blockmaster records placement-verified, promotion-candidate-evaluation and authority-published events, and the CSI node reports `csi_reattach_observed` after a successful stage. | M3 promotion decision (observation) | `core/host/master/product_loop.go` `recordPlacementVerifiedEvents`, `recordPromotionEvaluationEvents`, `recordAuthorityPublishedEvent` | `TestMasterTimeline_RecordsPlacementVerified`, `TestMasterTimeline_RecordsPromotionCandidateEvaluation`, `TestMasterTimeline_RecordsAuthorityPublishedAfterMint` (`core/host/master/event_ring_test.go`); `TestNodeStage_ReportsCSIReattachObservedAfterSuccessfulStage` (`core/csi/node_test.go`) | — | ACTIVE | +| `INV-OBS-SLOT-ORDER-001` | A heartbeat slot (server, volume, replica) is ordered only against that slot's own previous heartbeat: a later-stamped heartbeat of another slot of the same server never supersedes it. | AUTHORITY/ORDER: per-slot heartbeat ingest (V1-SPEC r2.53) | `core/authority/observation_store.go` `ingest` (per-slot comparison), `slotObservedAt`; `SupersededSlotCount` (diagnostic only) | `TestObservationStore_InterleavedSendersOrderPerSlot`, `TestObservationStore_MixedSlotReportKeepsOnlyNewerFacts`, `TestObservationStore_SupersededSlotLogsAfterUnlock` (`core/authority/observation_store_slot_order_test.go`) | 1.0 limit: a backward wall-clock step longer than the freshness window expires that host's slots; 1.0.1: per-process sequence. | ACTIVE | | `INV-OBS-SLOT-FROM-EXPECTED-SERVER-001` | A replica's slot in the assembled topology takes addresses and health only from a fresh fact reported by the server its expected slot names; another server's fact for the same replica is never used, so with none from that server the slot is a placeholder. | AUTHORITY/ORDER: observation to assignment line | `core/authority/snapshot_builder.go` `assembleVolumeTopology` | `TestAssembleVolumeTopology_SlotFactOnlyFromTheExpectedServer` (`core/authority/snapshot_slot_server_test.go`) | — (pure assembly; the unit test is the proof form) | ACTIVE | | `INV-HELM-RF-NODECOUNT-001` | Generated Helm values fail closed when the requested replication factor exceeds the selected Ready schedulable node count. | M3 (configuration) | `cmd/sw-block/main.go` `runOpsGenerateHelmValues`, `selectHelmValuesNodes` | `TestOpsGenerateHelmValuesRejectsRFAboveSelectedNodes` (`cmd/sw-block/main_test.go`) | — | ACTIVE | | `INV-HOSTPATH-TRANSPARENT-001` | The read model reports transparent host-path recovery only with a multipathed, Active/Optimized, stale-fenced path, writer and reader checks, and the same pod UID. | K8s readiness model | `core/ops/managed_volume_model.go` `classifyManagedVolume`, `deriveManagedVolumeStates` | `TestManagedVolumeProjection_TransparentISCSIALUARecovered`, `TestManagedVolumeProjection_MissingMultipathBlocksTransparentClaim` (`core/ops/managed_volume_model_test.go`) | — | ACTIVE | From 814fb36a92de0c6c8f4a159c42b0f4e5dcc0ec84 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 20:44:09 -0800 Subject: [PATCH 9/9] docs: trace per-slot heartbeat ingest guards and freshness default --- seaweed-block/docs/design/invariants.md | 28 ++++++++++++++++++++++++- seaweed-block/docs/operator-guide.md | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index ac65b7368d..a2818d5a82 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -81,6 +81,32 @@ Recovery warnings such as `wal_hole_suspected` are recorded in Serving without c blockmaster's publisher is the only component that mints epochs. Diagrams: the assignment lifecycle in [core §1.5](block-design.md#15-authority-blockmaster-assignments-epochs-leases), and the workspace lease and move in [agent workspace §7](agent-workspace-design.md#7-lease-takeover-and-host-moves). +**Heartbeat observations, per server/volume/replica slot.** + +`ObservationStore.ingest` compares each reported slot only with that slot's +stored timestamp (`slotObservedAt`). An older slot is dropped and counted; +an equal or newer slot is accepted. A mixed report merges accepted slots and +retains every other stored slot. An all-superseded nonempty report changes no +observation or health transition. Accepted slots keep their own freshness; +server metadata keeps its newest timestamp without lending it to another slot. + +```mermaid +flowchart LR + Report[Receive heartbeat report] --> Compare{Each slot: stored timestamp newer?} + Compare -->|yes| Drop[Drop and count only that slot] + Compare -->|no| Accept[Accept that slot and its health transition] + Drop --> Mixed{Any accepted slots or an empty report?} + Accept --> Mixed + Mixed -->|yes| Merge[Merge accepted slots; retain other slots and newest server metadata] + Mixed -->|no| Keep[Keep stored observations unchanged] +``` + +| From | To | Event and guard | Enforced in | Protects | +|---|---|---|---|---| +| Stored observations | Stored observations (slot refused) | stored timestamp for this server/volume/replica is strictly newer than the report; drop and count only this slot | `core/authority/observation_store.go` `ingest`, `slotObservedAt` | `INV-OBS-SLOT-ORDER-001` | +| Stored observations | Stored observations (mixed report merged) | accept equal/newer slots against their own stored timestamp; merge only accepted slots, preserving other slots and independent freshness | `core/authority/observation_store.go` `ingest`, `mergeServerSlots` | `INV-OBS-SLOT-ORDER-001` | +| Stored observations | Stored observations (no mutation) | a nonempty report has no accepted slot; publish no observation mutation or health transition | `core/authority/observation_store.go` `ingest` | `INV-OBS-SLOT-ORDER-001` | + **Assignment line, per volume.** | From | To | Event and guard | Enforced in | Protects | @@ -930,7 +956,7 @@ Notes: | `INV-CSI-CONSUMES-AUTHORITY-001` | CSI never imports authority code or builds assignment facts; it takes the publish target from blockmaster and refreshes it before a stage, and blockmaster mints the IDs of the events CSI reports. | M2 (read side) | `core/csi/master_backend.go` `LookupPublishTarget`; `core/csi/node.go` `refreshPublishContext`; `core/host/master/observation_service.go` `ReportClusterEvent` | `TestG15a_CSI_DoesNotImportAuthorityOrConstructAssignmentFacts` (`core/csi/boundary_guard_test.go`); `TestG15e_CSIReattachUsesFreshPublishTargetAfterUnstage` (`core/csi/node_test.go`); `TestObservationService_ReportClusterEventAppearsInVolumeTimeline` (`core/host/master/observation_service_test.go`) | — | ACTIVE | | `INV-K8S-NONLOOPBACK-001` | Generated multi-node Helm values enable external iSCSI, external status and loopback rejection; with rejection enabled CSI never publishes a loopback target and fails closed when only loopback targets exist. | M2 (read side) | `cmd/sw-block/main.go` `runOpsGenerateHelmValues`; `core/csi/master_backend.go` `rejectFrontendAddr` | `TestOpsGenerateHelmValuesMultiNodeExternalISCSI` (`cmd/sw-block/main_test.go`); `TestNodeLoss_ControlStatusLookup_RejectsLoopbackPublishTargetsWhenEnabled`, `TestNodeLoss_ControlStatusLookup_FailClosedWhenOnlyLoopbackTargets` (`core/csi/master_backend_test.go`) | — | ACTIVE | | `INV-OBS-PRODUCT-EVENTS-001` | blockmaster records placement-verified, promotion-candidate-evaluation and authority-published events, and the CSI node reports `csi_reattach_observed` after a successful stage. | M3 promotion decision (observation) | `core/host/master/product_loop.go` `recordPlacementVerifiedEvents`, `recordPromotionEvaluationEvents`, `recordAuthorityPublishedEvent` | `TestMasterTimeline_RecordsPlacementVerified`, `TestMasterTimeline_RecordsPromotionCandidateEvaluation`, `TestMasterTimeline_RecordsAuthorityPublishedAfterMint` (`core/host/master/event_ring_test.go`); `TestNodeStage_ReportsCSIReattachObservedAfterSuccessfulStage` (`core/csi/node_test.go`) | — | ACTIVE | -| `INV-OBS-SLOT-ORDER-001` | A heartbeat slot (server, volume, replica) is ordered only against that slot's own previous heartbeat: a later-stamped heartbeat of another slot of the same server never supersedes it. | AUTHORITY/ORDER: per-slot heartbeat ingest (V1-SPEC r2.53) | `core/authority/observation_store.go` `ingest` (per-slot comparison), `slotObservedAt`; `SupersededSlotCount` (diagnostic only) | `TestObservationStore_InterleavedSendersOrderPerSlot`, `TestObservationStore_MixedSlotReportKeepsOnlyNewerFacts`, `TestObservationStore_SupersededSlotLogsAfterUnlock` (`core/authority/observation_store_slot_order_test.go`) | 1.0 limit: a backward wall-clock step longer than the freshness window expires that host's slots; 1.0.1: per-process sequence. | ACTIVE | +| `INV-OBS-SLOT-ORDER-001` | A heartbeat slot (server, volume, replica) is ordered only against that slot's own previous heartbeat: a later-stamped heartbeat of another slot of the same server never supersedes it. | M2 heartbeat observations: per-slot refusal / mixed merge / all-superseded no mutation (V1-SPEC r2.53) | `core/authority/observation_store.go` `ingest` (per-slot comparison), `slotObservedAt`; `SupersededSlotCount` (diagnostic only) | `TestObservationStore_InterleavedSendersOrderPerSlot`, `TestObservationStore_MixedSlotReportKeepsOnlyNewerFacts`, `TestObservationStore_SupersededSlotLogsAfterUnlock` (`core/authority/observation_store_slot_order_test.go`) | 1.0 limit: a backward wall-clock step longer than the freshness window expires that host's slots; 1.0.1: per-process sequence. | ACTIVE | | `INV-OBS-SLOT-FROM-EXPECTED-SERVER-001` | A replica's slot in the assembled topology takes addresses and health only from a fresh fact reported by the server its expected slot names; another server's fact for the same replica is never used, so with none from that server the slot is a placeholder. | AUTHORITY/ORDER: observation to assignment line | `core/authority/snapshot_builder.go` `assembleVolumeTopology` | `TestAssembleVolumeTopology_SlotFactOnlyFromTheExpectedServer` (`core/authority/snapshot_slot_server_test.go`) | — (pure assembly; the unit test is the proof form) | ACTIVE | | `INV-HELM-RF-NODECOUNT-001` | Generated Helm values fail closed when the requested replication factor exceeds the selected Ready schedulable node count. | M3 (configuration) | `cmd/sw-block/main.go` `runOpsGenerateHelmValues`, `selectHelmValuesNodes` | `TestOpsGenerateHelmValuesRejectsRFAboveSelectedNodes` (`cmd/sw-block/main_test.go`) | — | ACTIVE | | `INV-HOSTPATH-TRANSPARENT-001` | The read model reports transparent host-path recovery only with a multipathed, Active/Optimized, stale-fenced path, writer and reader checks, and the same pod UID. | K8s readiness model | `core/ops/managed_volume_model.go` `classifyManagedVolume`, `deriveManagedVolumeStates` | `TestManagedVolumeProjection_TransparentISCSIALUARecovered`, `TestManagedVolumeProjection_MissingMultipathBlocksTransparentClaim` (`core/ops/managed_volume_model_test.go`) | — | ACTIVE | diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index cbff179009..a3e6d5b7c3 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -56,7 +56,7 @@ one live blockvolume per volume ([one process per volume](releases/one-process-p Each volume process reports its own heartbeat slot (server, volume and replica). The master orders each slot against that slot's previous report. In version 1.0, -a backward host-clock step longer than the freshness window (10 seconds by +a backward host-clock step longer than the freshness window (30 seconds by default) can expire the host's slots; keep host clocks synchronized. ## Recovery point and sync policy