mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
recovery: WAL recycle gate consumes MinPin (priority 2.5) (#14)
Closes architect priority 2.5 per docs/recovery-wiring-plan.md §6.
Pinned by INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN. Depends on wiring
(stack-on-wiring per architect Option A 2026-04-29).
Substrate gate (`core/storage`):
+ RecycleFloorSource interface — externally-supplied
`MinPinAcrossActiveSessions() (uint64, bool)`. Substrate stays
orthogonal to engine: structural typing means
`core/recovery.PeerShipCoordinator` satisfies it without import.
+ RecycleFloorGate optional interface — substrate impl that
accepts a source via `SetRecycleFloorSource`. Cmd / wiring
type-asserts on it; smartwal can opt in later.
walstore (`core/storage/walstore.go`):
+ recycleFloorSrc field, mu-guarded.
+ persistCheckpoint clamps proposed `highestLSN` to floor when
source reports active session. Existing no-regress guard
(`if highestLSN <= s.checkpointLSN`) handles transient
floor-below-checkpoint races.
+ SetRecycleFloorSource setter.
memorywal (`core/storage/memorywal/store.go`):
+ recycleFloorSrc field, mu-guarded.
+ AdvanceWALTail clamps proposed `newTail` to floor when source
reports active session. Same shape as walstore.
+ SetRecycleFloorSource setter.
Coordinator assertion (`core/recovery/peer_ship_coordinator.go`):
+ `var _ storage.RecycleFloorSource = (*PeerShipCoordinator)(nil)`
— compile-time pin so future signature drift breaks the build,
not the runtime gate.
Daemon wiring (`cmd/blockvolume/main.go`):
+ In dual-lane mode, install gate via `RecycleFloorGate` type
assertion. Skipped silently when substrate doesn't support it
(BlockStore today). Diagnostic stderr line for operators.
Component fixture (`core/replication/component/cluster.go`):
+ Cluster.Start installs the gate when dualLane is set, so
component-level dual-lane tests exercise the recycle path
against the same coordinator they install on executors.
Tests (12 new):
+ walstore_recycle_pin_test.go (6) — nil source / inactive /
active clamp / floor-above-proposed (no clamp) / no-regress
when floor < current checkpoint / disable via Set(nil).
+ memorywal/store_recycle_pin_test.go (6) — nil source / inactive
/ active clamp + scan-gate inequality / floor-above-proposed /
disable / RecycleFloorGate interface satisfaction.
Verified: `go test ./core/... ./cmd/... -count=1` all green
(transport, host, recovery, storage{,/memorywal,/smartwal},
replication{,/component}, blockvolume).
inv-test-map.md updated: row flips from "logic only; recycle
integration is next milestone" to "coord + walstore + memorywal
substrate integration" with the 12 new tests cited.
This commit is contained in:
1 parent
d8b30f5956
commit
5b64dfd3c5
9 files changed
+485
-2
No files matched your search
@@ -497,6 +497,18 @@ func run(f flags) int {
|
||||
}
|
||||
return transport.NewBlockExecutorWithDualLane(s, replicaAddr, peerDualLane, recoveryCoord, recovery.ReplicaID(replicaID))
|
||||
})
|
||||
// G7-redo 2.5: install the recycle-floor gate on the
|
||||
// substrate so the WAL recycle path consults the
|
||||
// per-volume coordinator's MinPinAcrossActiveSessions.
|
||||
// Skipped silently when substrate doesn't implement
|
||||
// RecycleFloorGate (BlockStore today, smartwal until it
|
||||
// opts in). walstore + memorywal both satisfy.
|
||||
if gate, ok := store.(storage.RecycleFloorGate); ok {
|
||||
gate.SetRecycleFloorSource(recoveryCoord)
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: G7-redo 2.5 recycle gate installed (substrate honors min(pin_floor))")
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: G7-redo 2.5 substrate does not implement RecycleFloorGate; pin_floor advances unenforced at recycle")
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: G7-redo recovery-mode=dual-lane (PrimaryBridge per-peer; coord per-volume)")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,17 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// Compile-time assertion: PeerShipCoordinator's
|
||||
// MinPinAcrossActiveSessions signature satisfies the substrate's
|
||||
// RecycleFloorSource interface (G7-redo priority 2.5). If this break
|
||||
// it means the coordinator's pin-floor query method changed and the
|
||||
// substrate gate needs to track.
|
||||
var _ storage.RecycleFloorSource = (*PeerShipCoordinator)(nil)
|
||||
|
||||
// ReplicaID is the per-volume peer identifier the coordinator keys on.
|
||||
// Defined locally so this package stays independent of engine/adapter
|
||||
// types; integration code adapts to the project-wide peer identifier.
|
||||
|
||||
@@ -446,9 +446,15 @@ func (c *Cluster) Start() *Cluster {
|
||||
|
||||
// G7-redo: when dual-lane is enabled, instantiate the per-volume
|
||||
// coordinator BEFORE building executors so each executor
|
||||
// captures the same instance.
|
||||
// captures the same instance. G7-redo 2.5: also install the
|
||||
// recycle-floor gate on the primary substrate (walstore /
|
||||
// memorywal both implement RecycleFloorGate) so checkpoint
|
||||
// advancement clamps at min(pin_floor) during active sessions.
|
||||
if c.dualLane {
|
||||
c.coord = recovery.NewPeerShipCoordinator()
|
||||
if gate, ok := pStore.(storage.RecycleFloorGate); ok {
|
||||
gate.SetRecycleFloorSource(c.coord)
|
||||
}
|
||||
}
|
||||
executors := make([]*transport.BlockExecutor, c.replicaN)
|
||||
for i, r := range c.replicas {
|
||||
|
||||
@@ -65,6 +65,12 @@ type Store struct {
|
||||
// installed an entry at high LSN) gets the available records
|
||||
// rather than a spurious WALRecycled error.
|
||||
recycleFloor uint64
|
||||
|
||||
// recycleFloorSrc gates AdvanceWALTail when non-nil: the
|
||||
// proposed newTail cannot exceed `MinPinAcrossActiveSessions`.
|
||||
// Same semantic as walstore.WALStore — see
|
||||
// docs/recovery-wiring-plan.md §6.
|
||||
recycleFloorSrc storage.RecycleFloorSource
|
||||
}
|
||||
|
||||
type walRecord struct {
|
||||
@@ -178,9 +184,20 @@ func (s *Store) AdvanceFrontier(lsn uint64) {
|
||||
// recycling. After this, ScanLBAs(fromLSN < newTail) returns
|
||||
// storage.RecoveryFailure(Kind=WALRecycled). Sets recycleFloor as
|
||||
// the explicit "you asked for LSNs we've recycled" gate.
|
||||
//
|
||||
// G7-redo 2.5: when a RecycleFloorSource is installed and reports
|
||||
// any active session, the proposed newTail is clamped to
|
||||
// MinPinAcrossActiveSessions. INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN.
|
||||
func (s *Store) AdvanceWALTail(newTail uint64) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.recycleFloorSrc != nil {
|
||||
if floor, anyActive := s.recycleFloorSrc.MinPinAcrossActiveSessions(); anyActive {
|
||||
if newTail > floor {
|
||||
newTail = floor
|
||||
}
|
||||
}
|
||||
}
|
||||
if newTail <= s.recycleFloor {
|
||||
return
|
||||
}
|
||||
@@ -314,6 +331,17 @@ func (s *Store) AppliedLSNs() (map[uint32]uint64, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SetRecycleFloorSource installs the gate consulted in AdvanceWALTail
|
||||
// to clamp WAL recycle against active recover-session pin floors.
|
||||
// Pass nil to disable.
|
||||
//
|
||||
// Implements storage.RecycleFloorGate.
|
||||
func (s *Store) SetRecycleFloorSource(src storage.RecycleFloorSource) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.recycleFloorSrc = src
|
||||
}
|
||||
|
||||
func (s *Store) Close() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package memorywal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// G7-redo priority 2.5 — memorywal AdvanceWALTail consumes
|
||||
// `MinPinAcrossActiveSessions()` from an external coordinator so the
|
||||
// in-memory substrate honors the same retention inequality the on-disk
|
||||
// walstore does. Without this, component-level dual-lane tests
|
||||
// (`core/replication/component`) would be free to recycle past pinned
|
||||
// LSNs and the gate's correctness wouldn't be exercised end-to-end in
|
||||
// the in-memory test path.
|
||||
//
|
||||
// Pinned by: INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN.
|
||||
|
||||
// fakeRecycleFloorSource — substrate-level test stub. Same shape as
|
||||
// the walstore test; duplicated to keep the memorywal test package
|
||||
// self-contained (no `internal/testfakes` exists yet, and the stub
|
||||
// is trivial).
|
||||
type fakeRecycleFloorSource struct {
|
||||
floor uint64
|
||||
anyActive bool
|
||||
}
|
||||
|
||||
func (f *fakeRecycleFloorSource) MinPinAcrossActiveSessions() (uint64, bool) {
|
||||
return f.floor, f.anyActive
|
||||
}
|
||||
|
||||
// seedRecords appends `n` writes so AdvanceWALTail has something to
|
||||
// trim. Returns the highest LSN observed so the caller can target a
|
||||
// recycle position above it.
|
||||
func seedRecords(t *testing.T, s *Store, n int) uint64 {
|
||||
t.Helper()
|
||||
var lastLSN uint64
|
||||
for i := 0; i < n; i++ {
|
||||
lsn, err := s.Write(uint32(i), mkBlock(byte(i+1)))
|
||||
if err != nil {
|
||||
t.Fatalf("Write i=%d: %v", i, err)
|
||||
}
|
||||
lastLSN = lsn
|
||||
}
|
||||
return lastLSN
|
||||
}
|
||||
|
||||
// retainStartOf is a test-only accessor that uses Boundaries() — S is
|
||||
// memorywal's exposed retainStart.
|
||||
func retainStartOf(s *Store) uint64 {
|
||||
_, sboundary, _ := s.Boundaries()
|
||||
return sboundary
|
||||
}
|
||||
|
||||
// TestStore_RecycleGate_NilSource_LegacyBehavior pins fallback: when
|
||||
// no source is installed AdvanceWALTail trims as before. This is the
|
||||
// pre-priority-2.5 baseline; the gate must not change it.
|
||||
func TestStore_RecycleGate_NilSource_LegacyBehavior(t *testing.T) {
|
||||
s := NewStore(numBlocks, blockSize)
|
||||
_ = seedRecords(t, s, 5) // LSNs 1..5
|
||||
|
||||
// No source set; trim to 4 → only LSN 5 remains.
|
||||
s.AdvanceWALTail(4)
|
||||
|
||||
if got := retainStartOf(s); got != 4 {
|
||||
t.Errorf("retainStart after AdvanceWALTail(4) = %d, want 4 (nil source = no clamp)", got)
|
||||
}
|
||||
|
||||
// memorywal's gate fires when fromLSN+1 < recycleFloor. With
|
||||
// recycleFloor=4, fromLSN=0 (0+1 < 4) MUST be recycled — pins
|
||||
// that the trim actually reached the substrate (not silently
|
||||
// no-op'd by some unintended clamp from the gate code path).
|
||||
err := s.ScanLBAs(0, func(storage.RecoveryEntry) error { return nil })
|
||||
if err == nil {
|
||||
t.Fatal("ScanLBAs(0) after recycle to 4: want WALRecycled error")
|
||||
}
|
||||
}
|
||||
|
||||
// TestStore_RecycleGate_SourceInactive_LegacyBehavior pins the
|
||||
// `(_, false)` branch: source reports no active session → trim
|
||||
// proceeds unmodified.
|
||||
func TestStore_RecycleGate_SourceInactive_LegacyBehavior(t *testing.T) {
|
||||
s := NewStore(numBlocks, blockSize)
|
||||
_ = seedRecords(t, s, 5)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 2, anyActive: false}
|
||||
s.SetRecycleFloorSource(src)
|
||||
|
||||
// anyActive=false → src ignored; trim to 4.
|
||||
s.AdvanceWALTail(4)
|
||||
if got := retainStartOf(s); got != 4 {
|
||||
t.Errorf("retainStart = %d, want 4 (anyActive=false bypasses gate)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStore_RecycleGate_SourceActive_ClampsAtFloor pins the headline
|
||||
// behavior: source reports floor=2; flusher proposes trim to 4. The
|
||||
// gate clamps the effective newTail to 2 so records 2..3 are
|
||||
// retained.
|
||||
func TestStore_RecycleGate_SourceActive_ClampsAtFloor(t *testing.T) {
|
||||
s := NewStore(numBlocks, blockSize)
|
||||
_ = seedRecords(t, s, 5)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 2, anyActive: true}
|
||||
s.SetRecycleFloorSource(src)
|
||||
|
||||
// Proposed newTail=4 → clamped to 2. retainStart should land at 2.
|
||||
s.AdvanceWALTail(4)
|
||||
if got := retainStartOf(s); got != 2 {
|
||||
t.Errorf("retainStart = %d, want 2 (clamped to active pin floor)", got)
|
||||
}
|
||||
|
||||
// ScanLBAs(1) is below the new floor (recycleFloor=2).
|
||||
// memorywal's gate fires when fromLSN+1 < recycleFloor. With
|
||||
// recycleFloor=2, fromLSN=0 (0+1 < 2) returns recycled;
|
||||
// fromLSN=1 (1+1 == 2) does NOT — it's the first "still-retained"
|
||||
// position. This pins the inequality we ship.
|
||||
err := s.ScanLBAs(0, func(storage.RecoveryEntry) error { return nil })
|
||||
if err == nil {
|
||||
t.Error("ScanLBAs(0) after clamp to 2: want WALRecycled (0+1 < 2)")
|
||||
}
|
||||
calls := 0
|
||||
err = s.ScanLBAs(1, func(storage.RecoveryEntry) error {
|
||||
calls++
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("ScanLBAs(1) after clamp to 2: want success, got %v", err)
|
||||
}
|
||||
if calls == 0 {
|
||||
t.Error("ScanLBAs(1): want at least one entry emitted (LSNs 2..5 retained)")
|
||||
}
|
||||
}
|
||||
|
||||
// TestStore_RecycleGate_FloorAboveProposed_NoClamp pins the
|
||||
// "floor doesn't pull recycle forward" rule. If source reports
|
||||
// floor=10 but the proposed newTail is 4, the effective newTail
|
||||
// stays at 4 — the gate is an upper bound, not a target.
|
||||
func TestStore_RecycleGate_FloorAboveProposed_NoClamp(t *testing.T) {
|
||||
s := NewStore(numBlocks, blockSize)
|
||||
_ = seedRecords(t, s, 5)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 10, anyActive: true}
|
||||
s.SetRecycleFloorSource(src)
|
||||
|
||||
s.AdvanceWALTail(4) // proposed 4 < floor 10 → no clamp; trim to 4.
|
||||
if got := retainStartOf(s); got != 4 {
|
||||
t.Errorf("retainStart = %d, want 4 (floor >= proposed → no clamp)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStore_RecycleGate_SetRecycleFloorSourceNil_Disables pins the
|
||||
// disable path: after SetRecycleFloorSource(nil) AdvanceWALTail
|
||||
// behaves as if no source were ever installed.
|
||||
func TestStore_RecycleGate_SetRecycleFloorSourceNil_Disables(t *testing.T) {
|
||||
s := NewStore(numBlocks, blockSize)
|
||||
_ = seedRecords(t, s, 5)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 2, anyActive: true}
|
||||
s.SetRecycleFloorSource(src)
|
||||
|
||||
// First call clamps to 2.
|
||||
s.AdvanceWALTail(4)
|
||||
if got := retainStartOf(s); got != 2 {
|
||||
t.Fatalf("retainStart = %d, want 2 (gated)", got)
|
||||
}
|
||||
|
||||
// Seed more records so a second AdvanceWALTail has room to move.
|
||||
_, _ = s.Write(0, mkBlock(0xEE))
|
||||
_, _ = s.Write(1, mkBlock(0xFF))
|
||||
|
||||
// Disable the gate. Now AdvanceWALTail can move past the old floor.
|
||||
s.SetRecycleFloorSource(nil)
|
||||
s.AdvanceWALTail(6)
|
||||
if got := retainStartOf(s); got != 6 {
|
||||
t.Errorf("retainStart = %d, want 6 (gate disabled)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStore_RecycleGate_SatisfiesGateInterface pins the compile-time
|
||||
// assertion that *Store implements storage.RecycleFloorGate. The
|
||||
// daemon wiring relies on this type assertion succeeding.
|
||||
func TestStore_RecycleGate_SatisfiesGateInterface(t *testing.T) {
|
||||
s := NewStore(numBlocks, blockSize)
|
||||
var gate storage.RecycleFloorGate = s
|
||||
gate.SetRecycleFloorSource(nil) // smoke
|
||||
}
|
||||
@@ -180,6 +180,42 @@ func NewSubstrateIOFailure(cause error, detail string) *RecoveryFailure {
|
||||
|
||||
// --- T4d-1 Option C hybrid: per-LBA applied-LSN exposure ---
|
||||
|
||||
// --- G7-redo priority 2.5: WAL recycle gate via pin floor ---
|
||||
|
||||
// RecycleFloorSource is implemented by external coordinators that
|
||||
// gate WAL recycle advancement based on per-replica commitments.
|
||||
// Substrates consult this on every checkpoint advance / WAL tail
|
||||
// move to ensure entries below the floor are retained for replicas
|
||||
// with active recover sessions.
|
||||
//
|
||||
// Today this is `core/recovery.PeerShipCoordinator`'s
|
||||
// `MinPinAcrossActiveSessions() (uint64, bool)` — Go structural
|
||||
// typing satisfies this interface automatically; no import cycle.
|
||||
//
|
||||
// Per docs/recovery-wiring-plan.md §6 + design doc
|
||||
// docs/recovery-pin-floor-wire.md §5 retention inequality.
|
||||
type RecycleFloorSource interface {
|
||||
// MinPinAcrossActiveSessions returns the LSN below which any
|
||||
// recycle is safe (across all active recover sessions) and a
|
||||
// flag that says whether any session is active.
|
||||
//
|
||||
// `(0, false)` means no active session — the substrate may
|
||||
// recycle freely per its retention policy.
|
||||
// `(floor, true)` means at least one session is active and the
|
||||
// substrate MUST NOT advance its recycle past `floor`.
|
||||
MinPinAcrossActiveSessions() (uint64, bool)
|
||||
}
|
||||
|
||||
// RecycleFloorGate is an optional interface a LogicalStorage impl
|
||||
// satisfies if it supports the pin-floor gate. Cmd / wiring code
|
||||
// type-asserts on this and skips the wiring if the substrate does
|
||||
// not implement it (BlockStore today; smartwal can opt in later).
|
||||
//
|
||||
// `walstore.WALStore` and `memorywal.Store` implement this.
|
||||
type RecycleFloorGate interface {
|
||||
SetRecycleFloorSource(src RecycleFloorSource)
|
||||
}
|
||||
|
||||
// ErrAppliedLSNsNotTracked is returned by `LogicalStorage.AppliedLSNs`
|
||||
// when the substrate does not maintain per-LBA applied-LSN metadata
|
||||
// (e.g., in-memory BlockStore). The replica recovery apply gate
|
||||
|
||||
@@ -85,6 +85,16 @@ type WALStore struct {
|
||||
// Pinned by: INV-G6-RETENTION-POLICY-OPERATOR-VISIBLE.
|
||||
recoveryRetentionLSNs uint64
|
||||
|
||||
// recycleFloorSrc gates `persistCheckpoint` advancement when
|
||||
// non-nil: the proposed checkpoint cannot exceed the source's
|
||||
// reported `MinPinAcrossActiveSessions`. Set via
|
||||
// SetRecycleFloorSource at daemon wiring time when
|
||||
// --recovery-mode=dual-lane.
|
||||
//
|
||||
// nil = no gate (legacy behavior). Per docs/recovery-wiring-plan.md
|
||||
// §6 + INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN.
|
||||
recycleFloorSrc RecycleFloorSource
|
||||
|
||||
syncs atomic.Uint64 // total fsync operations performed (test/diagnostic)
|
||||
}
|
||||
|
||||
@@ -255,6 +265,20 @@ func (s *WALStore) writeExtent(lba uint32, data []byte) error {
|
||||
// over-writes the extent with identical bytes. Wasteful but correct.
|
||||
func (s *WALStore) persistCheckpoint(highestLSN uint64) error {
|
||||
s.mu.Lock()
|
||||
// G7-redo 2.5: clamp the proposed checkpoint to the recycle
|
||||
// floor reported by an external coordinator (e.g., the
|
||||
// recovery package's PeerShipCoordinator). When a replica is
|
||||
// in an active rebuild session and pin_floor < highestLSN, we
|
||||
// hold the checkpoint at pin_floor so WAL entries the replica
|
||||
// still depends on are retained. INV-RECYCLE-GATED-BY-MIN-
|
||||
// ACTIVE-PIN.
|
||||
if s.recycleFloorSrc != nil {
|
||||
if floor, anyActive := s.recycleFloorSrc.MinPinAcrossActiveSessions(); anyActive {
|
||||
if highestLSN > floor {
|
||||
highestLSN = floor
|
||||
}
|
||||
}
|
||||
}
|
||||
if highestLSN <= s.checkpointLSN {
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
@@ -507,6 +531,20 @@ func (s *WALStore) BlockSize() int { return int(s.sb.BlockSize) }
|
||||
// Called by: DurableProvider construction path after walstore is
|
||||
// opened, with the operator-supplied value from cmd/blockvolume.
|
||||
// Owns: recoveryRetentionLSNs field under s.mu.
|
||||
// SetRecycleFloorSource installs the gate consulted in
|
||||
// persistCheckpoint to clamp checkpoint advancement against active
|
||||
// recover-session pin floors. Pass nil to disable.
|
||||
//
|
||||
// Idempotent. Safe to call at any time — the gate is read under
|
||||
// s.mu so concurrent persistCheckpoint sees a consistent value.
|
||||
//
|
||||
// Implements storage.RecycleFloorGate.
|
||||
func (s *WALStore) SetRecycleFloorSource(src RecycleFloorSource) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.recycleFloorSrc = src
|
||||
}
|
||||
|
||||
func (s *WALStore) SetRecoveryRetentionLSNs(n uint64) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// G7-redo priority 2.5 — WAL recycle path consumes
|
||||
// `MinPinAcrossActiveSessions()` from an external coordinator (today
|
||||
// `core/recovery.PeerShipCoordinator`). These tests pin the substrate
|
||||
// gate directly: with no source set the legacy recycle proceeds; with
|
||||
// a source reporting an active session the checkpoint cannot advance
|
||||
// past the reported floor.
|
||||
//
|
||||
// Pinned by: INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN.
|
||||
//
|
||||
// Per docs/recovery-wiring-plan.md §6: "a new
|
||||
// walstore_recycle_pin_test.go confirms recycle floor is gated by min
|
||||
// pin when source is set; falls back to existing logic when nil."
|
||||
|
||||
// fakeRecycleFloorSource is a hand-written stub for
|
||||
// storage.RecycleFloorSource. The substrate-level test uses this
|
||||
// rather than depending on `core/recovery` (substrate stays orthogonal
|
||||
// to engine — same import discipline as `core/storage` itself).
|
||||
type fakeRecycleFloorSource struct {
|
||||
floor uint64
|
||||
anyActive bool
|
||||
}
|
||||
|
||||
func (f *fakeRecycleFloorSource) MinPinAcrossActiveSessions() (uint64, bool) {
|
||||
return f.floor, f.anyActive
|
||||
}
|
||||
|
||||
// TestWALStore_RecycleGate_NilSource_LegacyBehavior pins fallback:
|
||||
// when no source is installed (the daemon is in legacy mode, or
|
||||
// dual-lane wiring opted out for this volume), persistCheckpoint
|
||||
// advances exactly as it did before priority 2.5 landed.
|
||||
func TestWALStore_RecycleGate_NilSource_LegacyBehavior(t *testing.T) {
|
||||
ws := freshWALStore(t)
|
||||
advanceCheckpointForTest(t, ws, 50) // start at checkpoint=50
|
||||
|
||||
// No source set → checkpoint advances to 100 unmodified.
|
||||
if err := ws.persistCheckpoint(100); err != nil {
|
||||
t.Fatalf("persistCheckpoint(100): %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 100 {
|
||||
t.Errorf("CheckpointLSN = %d, want 100 (nil source = no clamp)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWALStore_RecycleGate_SourceInactive_LegacyBehavior pins the
|
||||
// `(_, false)` branch: a source that reports "no active session"
|
||||
// MUST NOT clamp. This is the steady-state (no rebuild in flight)
|
||||
// path; legacy behavior is preserved.
|
||||
func TestWALStore_RecycleGate_SourceInactive_LegacyBehavior(t *testing.T) {
|
||||
ws := freshWALStore(t)
|
||||
advanceCheckpointForTest(t, ws, 50)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 60, anyActive: false}
|
||||
ws.SetRecycleFloorSource(src)
|
||||
|
||||
// Even though src.floor=60 (< 100), anyActive=false → no clamp.
|
||||
if err := ws.persistCheckpoint(100); err != nil {
|
||||
t.Fatalf("persistCheckpoint(100): %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 100 {
|
||||
t.Errorf("CheckpointLSN = %d, want 100 (anyActive=false bypasses gate)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWALStore_RecycleGate_SourceActive_ClampsAtFloor pins the
|
||||
// headline behavior: an active session with floor=70 forces the
|
||||
// effective checkpoint to 70 even though the flusher proposed 100.
|
||||
// This is what holds the WAL retained for a replica that has
|
||||
// committed pin_floor=70 in its rebuild session.
|
||||
func TestWALStore_RecycleGate_SourceActive_ClampsAtFloor(t *testing.T) {
|
||||
ws := freshWALStore(t)
|
||||
advanceCheckpointForTest(t, ws, 50)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 70, anyActive: true}
|
||||
ws.SetRecycleFloorSource(src)
|
||||
|
||||
// Flusher proposes 100; gate clamps to 70.
|
||||
if err := ws.persistCheckpoint(100); err != nil {
|
||||
t.Fatalf("persistCheckpoint(100): %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 70 {
|
||||
t.Errorf("CheckpointLSN = %d, want 70 (clamped to active pin floor)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWALStore_RecycleGate_FloorAboveProposed_NoClamp pins the
|
||||
// "floor doesn't pull checkpoint forward" rule: when the source
|
||||
// reports floor=200 but the flusher only has 100 ready, the
|
||||
// effective checkpoint is the proposed 100 — the floor is an
|
||||
// upper-bound gate, not a target.
|
||||
func TestWALStore_RecycleGate_FloorAboveProposed_NoClamp(t *testing.T) {
|
||||
ws := freshWALStore(t)
|
||||
advanceCheckpointForTest(t, ws, 50)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 200, anyActive: true}
|
||||
ws.SetRecycleFloorSource(src)
|
||||
|
||||
// floor=200 >= proposed=100 → no clamp; checkpoint advances to 100.
|
||||
if err := ws.persistCheckpoint(100); err != nil {
|
||||
t.Fatalf("persistCheckpoint(100): %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 100 {
|
||||
t.Errorf("CheckpointLSN = %d, want 100 (floor >= proposed → no clamp)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWALStore_RecycleGate_FloorBelowCurrentCheckpoint_NoRegress pins
|
||||
// the monotonic invariant: even if the source reports a floor BELOW
|
||||
// the current checkpoint (e.g., transient race during session
|
||||
// install), persistCheckpoint must not regress checkpointLSN. The
|
||||
// `if highestLSN <= s.checkpointLSN { return nil }` guard handles
|
||||
// this — the post-clamp value just becomes a no-op rather than a
|
||||
// rollback.
|
||||
func TestWALStore_RecycleGate_FloorBelowCurrentCheckpoint_NoRegress(t *testing.T) {
|
||||
ws := freshWALStore(t)
|
||||
advanceCheckpointForTest(t, ws, 80) // current checkpoint = 80
|
||||
|
||||
// Active session reports floor=30 (below current). The clamp
|
||||
// would set highestLSN=30, but the no-regress guard returns
|
||||
// without changing checkpointLSN.
|
||||
src := &fakeRecycleFloorSource{floor: 30, anyActive: true}
|
||||
ws.SetRecycleFloorSource(src)
|
||||
|
||||
if err := ws.persistCheckpoint(100); err != nil {
|
||||
t.Fatalf("persistCheckpoint(100): %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 80 {
|
||||
t.Errorf("CheckpointLSN = %d, want 80 (must not regress under floor)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWALStore_RecycleGate_SetRecycleFloorSourceNil_Disables pins the
|
||||
// disable path: passing nil to SetRecycleFloorSource removes the gate
|
||||
// (used when the daemon transitions back to legacy mode, or when a
|
||||
// volume is closing down a coordinator). After Set(nil), behavior
|
||||
// matches the nil-source default.
|
||||
func TestWALStore_RecycleGate_SetRecycleFloorSourceNil_Disables(t *testing.T) {
|
||||
ws := freshWALStore(t)
|
||||
advanceCheckpointForTest(t, ws, 50)
|
||||
|
||||
src := &fakeRecycleFloorSource{floor: 70, anyActive: true}
|
||||
ws.SetRecycleFloorSource(src)
|
||||
|
||||
// First call clamps to 70.
|
||||
if err := ws.persistCheckpoint(100); err != nil {
|
||||
t.Fatalf("persistCheckpoint(100) [gated]: %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 70 {
|
||||
t.Fatalf("CheckpointLSN = %d, want 70 (gated)", got)
|
||||
}
|
||||
|
||||
// Disable the gate.
|
||||
ws.SetRecycleFloorSource(nil)
|
||||
|
||||
// Second call advances unmodified.
|
||||
if err := ws.persistCheckpoint(150); err != nil {
|
||||
t.Fatalf("persistCheckpoint(150) [ungated]: %v", err)
|
||||
}
|
||||
if got := ws.CheckpointLSN(); got != 150 {
|
||||
t.Errorf("CheckpointLSN = %d, want 150 (gate disabled)", got)
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ Status legend:
|
||||
| `INV-PIN-STABLE-WITHIN-SESSION` | Same session: `pin_floor` is monotonically non-decreasing. To pick a different anchor, invalidate session and start new lineage. | `TestCoordinator_SetPinFloor_Monotonic` (`core/recovery/peer_ship_coordinator_test.go:200`) — regression attempts ignored | ✅ pinned |
|
||||
| `INV-PIN-ADVANCES-ONLY-ON-REPLICA-ACK` | `pin_floor` advances iff replica has emitted `BaseBatchAcked` for an LBA range whose base data is now installed. Primary cannot advance pin on its own. | `TestE2E_PinFloorAdvancesIncrementally` (`core/recovery/e2e_test.go:466`) — K=8 cadence drives multiple acks across 50-LBA backlog; pin advances through coord.SetPinFloor. Wire impl in `g7-redo/pin-floor` branch (`6cb89ee`). | ✅ pinned |
|
||||
| `INV-PIN-COMPATIBLE-WITH-RETENTION` | `pin_floor ≥ retained(S)` always holds. A session demanding a pin below S MUST fail-loud → invalidate → new lineage. | `TestCoordinator_SetPinFloor_RejectsBelowRetention` (`core/recovery/peer_ship_coordinator_test.go:225`) — typed `*Failure(PinUnderRetention)` on `floor < primaryS`; `TestCoordinator_SetPinFloor_ZeroBoundaryDisablesCheck` (`core/recovery/peer_ship_coordinator_test.go:262`) — `S=0` legacy path. | ✅ pinned |
|
||||
| `INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN` | Primary's WAL recycle floor = `min(pin_floor)` over active sessions; no sessions ⇒ pure retention. | `TestCoordinator_MinPinAcrossActiveSessions` (`core/recovery/peer_ship_coordinator_test.go:159`) — 2-replica scenario, min tracks lowest as one advances; releases on `EndSession` | ✅ pinned (logic only; recycle integration is next milestone) |
|
||||
| `INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN` | Primary's WAL recycle floor = `min(pin_floor)` over active sessions; no sessions ⇒ pure retention. | `TestCoordinator_MinPinAcrossActiveSessions` (`core/recovery/peer_ship_coordinator_test.go:159`) — coord-level min/release.<br>`TestWALStore_RecycleGate_*` (`core/storage/walstore_recycle_pin_test.go`) — 6 cases: nil source / inactive source / active clamp / floor-above-proposed / no-regress / disable. Substrate `persistCheckpoint` honors gate.<br>`TestStore_RecycleGate_*` (`core/storage/memorywal/store_recycle_pin_test.go`) — 6 cases mirroring walstore on the in-memory substrate; pins gate interface + AdvanceWALTail clamp. | ✅ pinned (coord + walstore + memorywal substrate integration) |
|
||||
| `INV-SESSION-COMPLETE-CLOSURE` | System-level done = layer-1 `TryComplete` ∧ barrier-ack(`achieved == targetLSN`). Both halves required before declaring InSync. | `TestCoordinator_CanEmitSessionComplete` (`core/recovery/peer_ship_coordinator_test.go:79`)<br>`TestE2E_RebuildHappyPath` (`core/recovery/e2e_test.go:33`) — full round-trip<br>`TestE2E_RebuildWithLiveWritesDuringSession` (`core/recovery/e2e_test.go:127`) — closure with live | ✅ pinned (closure predicate + e2e round-trip) |
|
||||
| `INV-LIVE-CAUGHT-UP-IFF-FRONTIER-AT-BARRIER` | "Live caught up" is provable only via probe/barrier comparing `R_repr` against `H` at frozen time, not via shipper liveness. | `TestE2E_RebuildHappyPath` and `TestE2E_RebuildWithLiveWritesDuringSession` — both require barrier achieved ≥ target before passing | ✅ pinned indirectly (no test passes without barrier) |
|
||||
| `INV-SESSION-TEARDOWN-IS-EXPLICIT` | Convergence → InSync → teardown session → drop `pin_floor` → recycle resumes. All transitions are explicit events. | `TestCoordinator_EndSession_Idempotent` (`core/recovery/peer_ship_coordinator_test.go:218`)<br>e2e tests check `coord.Phase == Idle` post-Run | ✅ pinned |
|
||||
|
||||
Reference in new issue
Block a user