mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
04b0bb2fc479954d3fa6ae8a2267cfb7e33620de
Per v3-recovery-wal-shipper-mini-plan.md §3 P2 — "Drain API wired
from recovery.Sender; delete/disable recovery/sender duplicate
pump". P2a is the smallest green-on-merge step: introduce the
sink, make Sender accept it as OPTIONAL, branch Run() based on
presence. P2b/c migrate existing tests + delete legacy pump.
Architect 2026-04-29 P1 review ratification: "Proceed with P2 TDD
as you outlined, and keep these two integration rules explicit
in tests:
1. updateWalShipperEmitContext(replicaID, sessionConn,
sessionLineage) before StartSession.
2. After EndSession, restore whatever lineage conn Ship will
use, or the next steady emit will use stale recovery
lineage on the wire."
Rules 1 + 2 are caller obligations and live in transport (P2d).
P2a establishes the SINK interface contract that those rules
plug into.
WalShipperSink interface (core/recovery/sender.go):
type WalShipperSink interface {
StartSession(fromLSN uint64) error
DrainBacklog(ctx context.Context) error
EndSession()
}
Lives in core/recovery to avoid import cycle (transport
imports recovery for ReplicaID etc.). transport.WalShipper
satisfies it via duck typing.
Boundary docstring spells out architect rules 1+2 as caller
obligations; Sender does not enforce them.
Sender constructor:
NewSender(...) — legacy path (sink == nil; Run uses
streamBacklog/closeCh/drainAndSeal).
P2c removes this path.
NewSenderWithSink(..., sink) — sink-mode path (Run delegates).
Defensive: nil sink promotes to
NewSender so behavior is predictable.
Run() branching:
if s.sink != nil:
defer s.sink.EndSession() // always-cleanup defer FIRST so
// it fires on every exit path
// (success, StartSession err,
// DrainBacklog err, barrier err).
s.sink.StartSession(fromLSN)
s.sink.DrainBacklog(ctx)
// skip TryAdvanceToSteadyLive (kickoff Q3 collapse:
// {Idle, Active}; barrier-ack is the only completion signal)
else:
// LEGACY: streamBacklog → closeCh wait → drainAndSeal →
// TryAdvanceToSteadyLive (P2c removes)
Failure mapping for sink errors:
sink.StartSession err → FailureContract @ PhaseBacklog
sink.DrainBacklog err (ctx) → FailureCancelled @ PhaseBacklog
sink.DrainBacklog err (other) → FailureSubstrate @ PhaseBacklog
Test (TDD, sender_walshipper_sink_test.go):
TestSender_WithSink_DelegationOrder
- recordingSink mock captures call order
- Run sender (with deliberately non-converging setup so test
doesn't depend on barrier success)
- Assert: sink.callOrder = [StartSession, DrainBacklog, EndSession]
- Assert: startCalls/drainCalls/endCalls all 1 (always-cleanup)
- Assert: fromLSN argument forwarded to sink.StartSession
Other sink-test scaffolds (NoSink_FallsBackToLegacy,
WithSink_DelegatesStartSession, WithSink_EndSessionAlwaysCalled,
WithSink_StartSessionFailureAborts, WithSink_NoStreamBacklog
Reachable) marked t.Skip — they will be filled in as P2b/c
delete the legacy path and provide the e2e harness for sink-
driven WAL pump.
Test infrastructure:
recordingSink — mock with mutex-guarded call log; also has
shipDuringDrain hook + drainBlocksUntil channel
for P2b's e2e tests where the sink does pump
WAL via the test wire.
Test deadlock fix (caught during impl):
receiver returning error didn't close replicaConn → sender's
readerLoop blocks forever reading. Fixed by closing replicaConn
immediately after receiver.Run returns in the test goroutine.
Documented in test comments.
Test sweep:
go test ./core/recovery/ -run "TestSender_WithSink_DelegationOrder"
→ PASS (0.00s).
go test ./core/recovery/ ./core/transport/ -count=1
→ all PASS (no regression on legacy path, including existing
e2e tests that still use NewSender / sender.Close /
PushLiveWrite — those keep working in P2a).
Next:
P2b — migrate existing e2e tests (TestE2E_RebuildHappyPath etc.)
to NewSenderWithSink + a real walShipper / passthrough
sink. Required before P2c.
P2c — make sink required; delete streamBacklog, drainAndSeal,
PushLiveWrite, liveQueue, sealed, closeCh, queueMu,
walItem, Close.
P2d — transport-layer integration tests for architect rules
1 (updateContext before StartSession) and 2 (restore
after EndSession). Wire BlockExecutor.startRebuildDualLane
to call updateWalShipperEmitContext + walShipper.StartSession.
Languages
Go
84.5%
Rust
7.9%
Shell
2.7%
templ
1.6%
Java
1%
Other
2%