mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
transport: derive rebuild base pin from primary sync
This commit is contained in:
1 parent
91707b1e96
commit
508763c277
2 files changed
+69
-8
No files matched your search
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user