From 1c7cfa57b35ae15685f4d81d29efce84b3af063e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 2 May 2026 01:23:13 -0700 Subject: [PATCH] recovery: allow base pin above legacy frontier hint --- seaweed-block/core/recovery/peer_ship_coordinator.go | 10 ++++------ .../core/recovery/peer_ship_coordinator_test.go | 9 +++++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/seaweed-block/core/recovery/peer_ship_coordinator.go b/seaweed-block/core/recovery/peer_ship_coordinator.go index 99e577fcc7..4bf064947d 100644 --- a/seaweed-block/core/recovery/peer_ship_coordinator.go +++ b/seaweed-block/core/recovery/peer_ship_coordinator.go @@ -160,9 +160,10 @@ func NewPeerShipCoordinator() *PeerShipCoordinator { // to avoid; the coordinator only enforces the invariant. // // fromLSN is the session contract's lower LSN bound — typically -// `Recovery.R + 1` for a catch-up or the engine's pin choice for a -// rebuild. targetLSN is frozen at session start and does not move -// during the session (§2 "session target is fixed at start"). +// `Recovery.R + 1` for a catch-up or the engine's BasePinLSN choice +// for a rebuild. targetLSN is the legacy compat/frontier-hint band; it +// is no longer required to be >= fromLSN and is not a close predicate +// unless StartSessionLegacyBand explicitly opts into old behavior. func (c *PeerShipCoordinator) StartSession(id ReplicaID, sessionID, fromLSN, targetLSN uint64) error { return c.startSession(id, sessionID, fromLSN, targetLSN, false) } @@ -179,9 +180,6 @@ func (c *PeerShipCoordinator) startSession(id ReplicaID, sessionID, fromLSN, tar if sessionID == 0 { return errors.New("recovery: sessionID must be non-zero") } - if targetLSN < fromLSN { - return fmt.Errorf("recovery: targetLSN=%d < fromLSN=%d", targetLSN, fromLSN) - } c.mu.Lock() defer c.mu.Unlock() if existing, ok := c.states[id]; ok && existing.phase != PhaseIdle { diff --git a/seaweed-block/core/recovery/peer_ship_coordinator_test.go b/seaweed-block/core/recovery/peer_ship_coordinator_test.go index 3177506667..cfe53260a0 100644 --- a/seaweed-block/core/recovery/peer_ship_coordinator_test.go +++ b/seaweed-block/core/recovery/peer_ship_coordinator_test.go @@ -353,9 +353,14 @@ func TestCoordinator_StartSession_ArgValidation(t *testing.T) { if err := c.StartSession(r1, 0, 100, 200); err == nil { t.Error("sessionID=0 should error") } - if err := c.StartSession(r1, 1, 200, 100); err == nil { - t.Error("targetLSN < fromLSN should error") + // BasePinLSN/fromLSN and the legacy frontier-hint band are + // independent. A primary sync taken at rebuild start may produce a + // base pin higher than an older compatibility hint; that must not + // fail session registration. + if err := c.StartSession(r1, 1, 200, 100); err != nil { + t.Errorf("targetLSN/frontier hint below fromLSN/base pin should be legal: %v", err) } + c.EndSession(r1) // Equal targets are legal (zero-LSN-progress sessions). if err := c.StartSession(r1, 1, 100, 100); err != nil { t.Errorf("targetLSN == fromLSN: %v", err)