From 82fb2a8a34eceba2b7c124c54517543cb7f1eabc Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 2 May 2026 12:12:02 -0700 Subject: [PATCH] adapter: pin retention breach does not retry lineage --- seaweed-block/core/adapter/adapter_test.go | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/seaweed-block/core/adapter/adapter_test.go b/seaweed-block/core/adapter/adapter_test.go index 5fb0e09c46..23f43d083d 100644 --- a/seaweed-block/core/adapter/adapter_test.go +++ b/seaweed-block/core/adapter/adapter_test.go @@ -431,6 +431,52 @@ func TestAdapter_DurableAckBelowRetention_StartsRebuild(t *testing.T) { } } +func TestAdapter_PinUnderRetentionClose_DoesNotRetrySameLineage(t *testing.T) { + exec := newMockExecutor() + exec.autoClose = false + exec.probeResults["r1"] = ProbeResult{ + ReplicaID: "r1", + Success: true, + EndpointVersion: 1, + TransportEpoch: 1, + ReplicaFlushedLSN: 10, + PrimaryTailLSN: 5, + PrimaryHeadLSN: 30, + } + a := NewVolumeReplicaAdapter(exec) + a.OnAssignment(AssignmentInfo{ + VolumeID: "v1", + ReplicaID: "r1", + Epoch: 1, + EndpointVersion: 1, + DataAddr: "data", + CtrlAddr: "ctrl", + }) + + sessionID := waitForLatestSessionID(t, exec, "StartCatchUp") + beforeStarts := countStarts(exec, "StartCatchUp") + countStarts(exec, "StartRebuild") + + exec.fireClose(SessionCloseResult{ + ReplicaID: "r1", + SessionID: sessionID, + Success: false, + FailureKind: engine.RecoveryFailurePinUnderRetention, + FailReason: "pin under retention: durable ack below primary S", + }) + + afterStarts := countStarts(exec, "StartCatchUp") + countStarts(exec, "StartRebuild") + if afterStarts != beforeStarts { + t.Fatalf("PinUnderRetention retried same lineage: starts before=%d after=%d log=%v", + beforeStarts, afterStarts, exec.getCommands()) + } + if !hasAdapterCommand(a, "PublishDegraded") { + t.Fatalf("PinUnderRetention must publish degraded; commands=%v", a.CommandLog()) + } + if got := a.Projection().Mode; got == engine.ModeHealthy { + t.Fatalf("PinUnderRetention must not leave replica healthy") + } +} + func TestAdapter_StartCatchUp_UsesFrontierHintOverLegacyTarget(t *testing.T) { exec := newMockExecutor() exec.autoStart = false @@ -528,6 +574,31 @@ func latestStartRecord(t *testing.T, exec *mockExecutor, kind string) startRecor return startRecord{} } +func waitForLatestSessionID(t *testing.T, exec *mockExecutor, kind string) uint64 { + t.Helper() + deadline := time.Now().Add(2 * time.Second) + for time.Now().Before(deadline) { + if sid := exec.latestSessionID(kind); sid != 0 { + return sid + } + time.Sleep(10 * time.Millisecond) + } + t.Fatalf("no %s session started; commands=%v", kind, exec.getCommands()) + return 0 +} + +func countStarts(exec *mockExecutor, kind string) int { + exec.mu.Lock() + defer exec.mu.Unlock() + n := 0 + for _, start := range exec.starts { + if start.kind == kind { + n++ + } + } + return n +} + func hasAdapterCommand(a *VolumeReplicaAdapter, kind string) bool { for _, got := range a.CommandLog() { if got == kind {