From 508763c2770f0e50c4e9ec1e9d04e95038d161b9 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 2 May 2026 01:09:56 -0700 Subject: [PATCH] transport: derive rebuild base pin from primary sync --- .../core/transport/dual_lane_test.go | 59 +++++++++++++++++++ .../core/transport/rebuild_sender.go | 18 +++--- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/seaweed-block/core/transport/dual_lane_test.go b/seaweed-block/core/transport/dual_lane_test.go index d3d63d89ea..5a5c3233c3 100644 --- a/seaweed-block/core/transport/dual_lane_test.go +++ b/seaweed-block/core/transport/dual_lane_test.go @@ -189,6 +189,65 @@ func TestDualLane_StartRebuildPinned_SeparatesBasePinFromFrontierHint(t *testing } } +func TestDualLane_StartRebuild_DerivesBasePinFromPrimarySync(t *testing.T) { + primary := storage.NewBlockStore(16, 4096) + for lba := uint32(0); lba < 4; lba++ { + data := bytes.Repeat([]byte{byte(lba + 1)}, 4096) + if _, err := primary.Write(lba, data); err != nil { + t.Fatalf("Write: %v", err) + } + } + _, _, preH := primary.Boundaries() + if preH == 0 { + t.Fatal("test premise: primary head must be non-zero") + } + coord := recovery.NewPeerShipCoordinator() + + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("listen: %v", err) + } + defer ln.Close() + accepted := make(chan net.Conn, 1) + go func() { + conn, _ := ln.Accept() + accepted <- conn + }() + + exec := NewBlockExecutorWithDualLane( + primary, + "127.0.0.1:0", + ln.Addr().String(), + coord, + recovery.ReplicaID("r1"), + ) + + const frontierHint = uint64(99) + if err := exec.StartRebuild("r1", 18, 1, 1, frontierHint); err != nil { + t.Fatalf("StartRebuild: %v", err) + } + + st, ok := coord.Status("r1") + if !ok { + t.Fatal("coordinator has no active session") + } + if st.FromLSN != preH { + t.Fatalf("coordinator FromLSN=%d want synced primary H/base pin %d", st.FromLSN, preH) + } + if st.TargetLSN != frontierHint { + t.Fatalf("coordinator TargetLSN=%d want frontier hint %d", st.TargetLSN, frontierHint) + } + + select { + case conn := <-accepted: + if conn != nil { + _ = conn.Close() + } + case <-time.After(2 * time.Second): + t.Fatal("dual-lane listener did not accept connection") + } +} + // TestDualLane_LegacyConstructorIsNotDualLane verifies the // existing NewBlockExecutor path is unchanged: e.dualLane is nil, // StartRebuild falls through to the legacy single-lane code (no diff --git a/seaweed-block/core/transport/rebuild_sender.go b/seaweed-block/core/transport/rebuild_sender.go index 0278b465cc..49df85af81 100644 --- a/seaweed-block/core/transport/rebuild_sender.go +++ b/seaweed-block/core/transport/rebuild_sender.go @@ -20,11 +20,16 @@ import ( // MsgRebuildBlock per LBA, then a terminal MsgRebuildDone whose // BarrierResponse carries the replica's actually achieved frontier. func (e *BlockExecutor) StartRebuild(replicaID string, sessionID, epoch, endpointVersion, targetLSN uint64) error { - // Legacy wrapper: older adapter/engine surfaces only provide one - // number. Treat it as both the base snapshot pin and the frontier - // hint. New transport code that has a distinct base pin should call - // StartRebuildPinned. - return e.StartRebuildPinned(replicaID, sessionID, epoch, endpointVersion, targetLSN, targetLSN) + // Legacy wrapper: older adapter/engine surfaces only provide the + // frontier hint. The transport owns the base snapshot cut, so take a + // local durable sync here and use that as BasePinLSN. This keeps the + // base feeder's WAL rewind point tied to primary storage reality, not + // to a probe/compat band value. + basePinLSN, err := e.primaryStore.Sync() + if err != nil { + return fmt.Errorf("rebuild base pin sync: %w", err) + } + return e.StartRebuildPinned(replicaID, sessionID, epoch, endpointVersion, basePinLSN, targetLSN) } // StartRebuildPinned is the explicit rebuild entry point: basePinLSN is @@ -36,9 +41,6 @@ func (e *BlockExecutor) StartRebuildPinned(replicaID string, sessionID, epoch, e if e.dualLane != nil { return e.startRebuildDualLane(replicaID, sessionID, epoch, endpointVersion, basePinLSN, frontierHint) } - if basePinLSN != frontierHint { - return fmt.Errorf("legacy rebuild path requires basePinLSN == frontierHint (basePinLSN=%d frontierHint=%d)", basePinLSN, frontierHint) - } lineage := RecoveryLineage{ SessionID: sessionID, Epoch: epoch,