From 2c50e8cdc8f030e20fd72a514628219de39155da Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 2 May 2026 09:59:08 -0700 Subject: [PATCH] recovery: name sender band as frontier hint --- seaweed-block/core/recovery/e2e_test.go | 6 ++--- .../core/recovery/integration_stub.go | 20 ++++++++-------- .../core/recovery/peer_ship_coordinator.go | 4 ++-- seaweed-block/core/recovery/sender.go | 24 +++++++++---------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/seaweed-block/core/recovery/e2e_test.go b/seaweed-block/core/recovery/e2e_test.go index 1d14c03372..9f8e197aec 100644 --- a/seaweed-block/core/recovery/e2e_test.go +++ b/seaweed-block/core/recovery/e2e_test.go @@ -31,7 +31,7 @@ func formulaPayload(lba uint32, epoch byte, blockSize int) []byte { // TestE2E_RebuildHappyPath drives a full session end-to-end: // - Primary writes 100 LBAs (LSN 1..100), syncs. // - Replica is empty (separate substrate). -// - Session opens with fromLSN=0, targetLSN=100. +// - Session opens with fromLSN=0, frontierHint=100. // - Sender ships base lane + backlog (no live writes yet). // - Barrier round-trip closes the session. // - Verify: every LBA on the replica matches primary. @@ -114,11 +114,11 @@ func TestE2E_RebuildHappyPath(t *testing.T) { // TestE2E_RebuildWithLiveWritesDuringSession is the case the user // asked about: primary keeps writing during the session, sender -// routes those post-target entries onto the session lane (because +// routes those session-live entries onto the session lane (because // we are still DrainingHistorical) and ships them ahead of barrier. // // Sequence: -// 1. Primary writes 30 LBAs, sync. Snapshot fromLSN=0, targetLSN=30. +// 1. Primary writes 30 LBAs, sync. Snapshot fromLSN=0, frontierHint=30. // 2. Open session. // 3. While session is active, primary writes 5 more (LSN 31..35). // The sender's caller (this test simulating the WAL shipper) diff --git a/seaweed-block/core/recovery/integration_stub.go b/seaweed-block/core/recovery/integration_stub.go index d62f5c8578..3079b0ce15 100644 --- a/seaweed-block/core/recovery/integration_stub.go +++ b/seaweed-block/core/recovery/integration_stub.go @@ -96,8 +96,8 @@ func NewPrimaryBridge(store storage.LogicalStorage, coord *PeerShipCoordinator, // Wire detail (POC): caller provides the dialed `conn`. Production // integration would dial through the existing connection pool / // listener registry. -func (b *PrimaryBridge) StartRebuildSession(ctx context.Context, conn net.Conn, replicaID ReplicaID, sessionID, fromLSN, targetLSN uint64) error { - return b.startRebuildSessionLocked(ctx, conn, replicaID, sessionID, fromLSN, targetLSN, nil) +func (b *PrimaryBridge) StartRebuildSession(ctx context.Context, conn net.Conn, replicaID ReplicaID, sessionID, fromLSN, frontierHint uint64) error { + return b.startRebuildSessionLocked(ctx, conn, replicaID, sessionID, fromLSN, frontierHint, nil) } // StartRebuildSessionWithSink is the variant that accepts an external @@ -114,18 +114,18 @@ func (b *PrimaryBridge) StartRebuildSession(ctx context.Context, conn net.Conn, // // `sink` MUST be non-nil; nil reverts to the bridging path (use // `StartRebuildSession` for that explicitly). -func (b *PrimaryBridge) StartRebuildSessionWithSink(ctx context.Context, conn net.Conn, replicaID ReplicaID, sessionID, fromLSN, targetLSN uint64, sink WalShipperSink) error { +func (b *PrimaryBridge) StartRebuildSessionWithSink(ctx context.Context, conn net.Conn, replicaID ReplicaID, sessionID, fromLSN, frontierHint uint64, sink WalShipperSink) error { if sink == nil { return fmt.Errorf("recovery bridge: StartRebuildSessionWithSink: sink is required (use StartRebuildSession for the bridging path)") } - return b.startRebuildSessionLocked(ctx, conn, replicaID, sessionID, fromLSN, targetLSN, sink) + return b.startRebuildSessionLocked(ctx, conn, replicaID, sessionID, fromLSN, frontierHint, sink) } // startRebuildSessionLocked is the shared implementation. When `sink` // is nil, it constructs a bridging `senderBacklogSink` via // NewSenderWithBacklogRelay (legacy compatible). When non-nil, the // caller-provided sink is installed via NewSenderWithSink. -func (b *PrimaryBridge) startRebuildSessionLocked(ctx context.Context, conn net.Conn, replicaID ReplicaID, sessionID, fromLSN, targetLSN uint64, sink WalShipperSink) error { +func (b *PrimaryBridge) startRebuildSessionLocked(ctx context.Context, conn net.Conn, replicaID ReplicaID, sessionID, fromLSN, frontierHint uint64, sink WalShipperSink) error { // Single-flight check at the bridge level (before coordinator), // so a second call observes our internal sender map first and // reports the racing-bridge-call case distinctly from the @@ -142,9 +142,9 @@ func (b *PrimaryBridge) startRebuildSessionLocked(ctx context.Context, conn net. // install the sender or fire OnStart. var err error if sink == nil { - err = b.coord.StartSessionLegacyBand(replicaID, sessionID, fromLSN, targetLSN) + err = b.coord.StartSessionLegacyBand(replicaID, sessionID, fromLSN, frontierHint) } else { - err = b.coord.StartSession(replicaID, sessionID, fromLSN, targetLSN) + err = b.coord.StartSession(replicaID, sessionID, fromLSN, frontierHint) } if err != nil { b.mu.Unlock() @@ -164,11 +164,11 @@ func (b *PrimaryBridge) startRebuildSessionLocked(ctx context.Context, conn net. b.onStart(replicaID, sessionID) } - log.Printf("g7-debug: bridge.startRebuildSessionLocked spawning sender goroutine replica=%s sessionID=%d fromLSN=%d targetLSN=%d sinkType=%T", - replicaID, sessionID, fromLSN, targetLSN, sink) + log.Printf("g7-debug: bridge.startRebuildSessionLocked spawning sender goroutine replica=%s sessionID=%d fromLSN=%d frontierHint=%d sinkType=%T", + replicaID, sessionID, fromLSN, frontierHint, sink) go func() { log.Printf("g7-debug: sender goroutine entry replica=%s sessionID=%d", replicaID, sessionID) - achieved, err := sender.Run(ctx, sessionID, fromLSN, targetLSN) + achieved, err := sender.Run(ctx, sessionID, fromLSN, frontierHint) log.Printf("g7-debug: sender goroutine exit replica=%s sessionID=%d achieved=%d err=%v", replicaID, sessionID, achieved, err) b.mu.Lock() delete(b.senders, replicaID) diff --git a/seaweed-block/core/recovery/peer_ship_coordinator.go b/seaweed-block/core/recovery/peer_ship_coordinator.go index c2e80dc30b..8f2230a5c0 100644 --- a/seaweed-block/core/recovery/peer_ship_coordinator.go +++ b/seaweed-block/core/recovery/peer_ship_coordinator.go @@ -58,7 +58,7 @@ func (p PeerShipPhase) String() string { // LocalWriteRouting tells the WAL shipper which lane a freshly produced // local write must travel on for a given peer, given that peer's current // ship phase. Spec §3.2 #3: "one ordered outbound queue per peer mixing -// recover-tagged and post-target traffic with explicit LSN order". +// recover-tagged and session-live traffic with explicit LSN order". // // §IV.0 T3 (v3-recovery-algorithm-consensus.md): RouteSessionLane means // all WAL for this peer MUST ship on the recover dual-lane session path — @@ -358,7 +358,7 @@ func (c *PeerShipCoordinator) RecordBarrierWalLegOk(id ReplicaID, walLegOk bool) // // In the dual-lane path, the PrimaryWalLegOk witness is the completion // authority and achievedLSN is returned as an observation, not compared -// to the frozen target band. The no-witness branch fail-closes unless +// to the frontier hint. The no-witness branch fail-closes unless // the session was explicitly started with StartSessionLegacyBand. // // Per §IV.2.1, this primary-side coordinator IS the terminal authority diff --git a/seaweed-block/core/recovery/sender.go b/seaweed-block/core/recovery/sender.go index 10921433ad..2cb13d1838 100644 --- a/seaweed-block/core/recovery/sender.go +++ b/seaweed-block/core/recovery/sender.go @@ -79,12 +79,12 @@ type Sender struct { replicaID ReplicaID // Session contract — set at Run() entry, immutable thereafter. - // targetLSN is the legacy name for the fourth wire slot. In + // frontierHint is the recovery session's legacy fourth wire slot. In // production dual-lane it is only a frontier hint; the real WAL // feeder owns catch-up/live-tail convergence. - sessionID uint64 - fromLSN uint64 - targetLSN uint64 + sessionID uint64 + fromLSN uint64 + frontierHint uint64 writerMu sync.Mutex // own mutex; serializes conn writes (frames are atomic) sharedWriter *sync.Mutex // optional; non-nil if sink exposes WriteMu() (C1 §6.8 #1) @@ -223,7 +223,7 @@ type walItem struct { // // Lifecycle (P2c-slice B-2): // - StartSession is a no-op: session bounds live on Sender (fromLSN / -// targetLSN set at Run entry); rewind semantics belong on the real +// frontierHint set at Run entry); rewind semantics belong on the real // WalShipper sink in transport. // - NotifyAppend buffers live writes under sinkMu — the bridging // path's "production discipline" (architect rule 2). streamBacklog @@ -389,7 +389,7 @@ func (s *Sender) LiveReady() bool { // success; returns an error on any wire / session failure. // // PRECONDITION: caller already invoked -// `coordinator.StartSession(replicaID, sessionID, fromLSN, targetLSN)` +// `coordinator.StartSession(replicaID, sessionID, fromLSN, frontierHint)` // synchronously before spawning the goroutine that calls Run. This // keeps "session is registered" observable from the call site that // scheduled Run, so concurrent code reading `coord.RouteLocalWrite` @@ -414,13 +414,13 @@ func (s *Sender) LiveReady() bool { // Lifecycle / cancellation: pass a Context whose cancellation signals // "abort this session". DrainBacklog observes ctx and returns ctx.Err() // on cancellation; sink.EndSession defer fires regardless. -func (s *Sender) Run(ctx context.Context, sessionID, fromLSN, targetLSN uint64) (achievedLSN uint64, err error) { +func (s *Sender) Run(ctx context.Context, sessionID, fromLSN, frontierHint uint64) (achievedLSN uint64, err error) { s.sessionID = sessionID s.fromLSN = fromLSN - s.targetLSN = targetLSN + s.frontierHint = frontierHint - log.Printf("g7-debug: Sender.Run entry replica=%s sessionID=%d fromLSN=%d targetLSN=%d sinkType=%T", - s.replicaID, sessionID, fromLSN, targetLSN, s.sink) + log.Printf("g7-debug: Sender.Run entry replica=%s sessionID=%d fromLSN=%d frontierHint=%d sinkType=%T", + s.replicaID, sessionID, fromLSN, frontierHint, s.sink) // Defer cleanup runs on every exit path. EndSession on the sink // is the seal-defense — guarantees post-Run NotifyAppend (e.g., @@ -449,7 +449,7 @@ func (s *Sender) Run(ctx context.Context, sessionID, fromLSN, targetLSN uint64) numBlocks := s.primaryStore.NumBlocks() log.Printf("g7-debug: Sender.Run writing frameSessionStart replica=%s numBlocks=%d", s.replicaID, numBlocks) if err := s.writeFrame(frameSessionStart, encodeSessionStart(sessionStartPayload{ - SessionID: sessionID, FromLSN: fromLSN, TargetLSN: targetLSN, NumBlocks: numBlocks, + SessionID: sessionID, FromLSN: fromLSN, TargetLSN: frontierHint, NumBlocks: numBlocks, })); err != nil { return 0, newFailure(FailureWire, PhaseSendStart, err) } @@ -639,7 +639,7 @@ func (s *Sender) Run(ctx context.Context, sessionID, fromLSN, targetLSN uint64) // legacy target-band oracle for compatibility. if !s.coordinator.CanEmitSessionComplete(s.replicaID, achieved) { return achieved, newFailure(FailureContract, PhaseBarrierResp, - fmt.Errorf("session close predicate refused achieved=%d frontier_hint=%d", achieved, targetLSN)) + fmt.Errorf("session close predicate refused achieved=%d frontier_hint=%d", achieved, frontierHint)) } return achieved, nil }