From 80ba50dfd2ca71fa18e0e4de95da8e4461776962 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 07:19:22 -0800 Subject: [PATCH] test(replication): pin WAL across both two-replica catch-up sessions --- .../replication/component/cluster_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/seaweed-block/core/replication/component/cluster_test.go b/seaweed-block/core/replication/component/cluster_test.go index 5e01b108a8..3d49ea5369 100644 --- a/seaweed-block/core/replication/component/cluster_test.go +++ b/seaweed-block/core/replication/component/cluster_test.go @@ -110,14 +110,43 @@ func TestComponent_ProbeHappy(t *testing.T) { }) } +// Pin the genesis replay window across both sessions. Unlike a logical +// retention setting, this prevents the old impl1 checkpoint releasing it. +type twoReplicaWALPin struct{} + +func (twoReplicaWALPin) MinPinAcrossActiveSessions() (uint64, bool) { return 0, true } + // TestComponent_TwoReplicas_BothConverge — multi-replica scenario. // Demonstrates WithReplicas(N) + per-replica catch-up. func TestComponent_TwoReplicas_BothConverge(t *testing.T) { component.RunMatrix(t, func(t *testing.T, c *component.Cluster) { c.WithReplicas(2).Start() + var ws *storage.WALStore + var priorFlushes uint64 + if s, ok := c.Primary().Store.(*storage.WALStore); ok { + ws, priorFlushes = s, s.FlushCount() + s.SetRecycleFloorSource(twoReplicaWALPin{}) + defer s.SetRecycleFloorSource(nil) + } + c.PrimaryWriteN(10) c.PrimarySync() + // Let the real flusher complete work before catch-up, so the pin + // (rather than winning a race with the timer) keeps WAL available. + if ws != nil { + deadline := time.Now().Add(10 * time.Second) + for ws.FlushCount() == priorFlushes && time.Now().Before(deadline) { + time.Sleep(time.Millisecond) + } + if ws.FlushCount() == priorFlushes { + t.Fatal("primary did not complete a flush") + } + if cp := ws.CheckpointLSN(); cp != 0 { + t.Fatalf("active replay pin allowed checkpoint%d, want0", cp) + } + } + for i := 0; i < c.ReplicaCount(); i++ { r := c.CatchUpReplica(i) if !r.Success {