recovery: allow base pin above legacy frontier hint

This commit is contained in:
pingqiu committed 2026-05-02 01:23:13 -07:00
1 parent 93036aca62
commit 1c7cfa57b3
2 files changed
+11 -8

No files matched your search

@@ -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 {
@@ -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)