From bb36a601b8f938c1e9c3ac103e1c904d3bec05e2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 30 Apr 2026 00:03:03 -0700 Subject: [PATCH] =?UTF-8?q?transport:=20RecoverySink=20=E2=80=94=20review-?= =?UTF-8?q?feedback=20doc=20tightening?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three doc-only follow-ups from architect code review of 845c810 (non-blocking; no logic changes): 1. NewRecoverySink — explicit caller obligations: - Defer EndSession at the StartSession call site so a StartSession error path still restores steady context (recovery.Sender.Run already does this; production callers using NewRecoverySink directly must too). - nil sessionConn = programmer error (Realtime emits would have nowhere to go). nil steadyConn = honest only when no steady ship was in flight; next steady emit fails closed at EmitFunc. 2. installRecordingShipper (test helper) — TEST-ONLY / single-goroutine note. The entry.shipper assignment bypasses walShipperMu deliberately; production paths take that mutex. Don't lift the pattern into production or concurrent tests without re-introducing the lock. Test suite unchanged; go test ./core/transport/ -run TestRecoverySink still PASS (6/6). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../core/transport/recovery_sink_adapter.go | 14 ++++++++++++++ .../core/transport/recovery_sink_adapter_test.go | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/seaweed-block/core/transport/recovery_sink_adapter.go b/seaweed-block/core/transport/recovery_sink_adapter.go index 06da25a4ab..26be2d6d95 100644 --- a/seaweed-block/core/transport/recovery_sink_adapter.go +++ b/seaweed-block/core/transport/recovery_sink_adapter.go @@ -61,6 +61,20 @@ type RecoverySink struct { // NewRecoverySink ensures the WalShipperEntry exists (via // WalShipperFor) so the emit-context update in StartSession has // somewhere to land. +// +// Caller obligations: +// +// - Defer EndSession at the call site that calls StartSession. +// If StartSession returns an error, the emit context has already +// been swapped to session — only the deferred EndSession restores +// steady. (recovery.Sender.Run defers sink.EndSession; production +// callers using NewRecoverySink directly must do the same.) +// - The caller is responsible for snapshotting the steady context +// correctly. Passing nil sessionConn is a programmer error +// (Realtime emits during the session would have nowhere to go); +// passing nil steadyConn is honest only when no steady ship was +// in flight before this session — the next steady emit will see +// "no conn" and fail closed at the EmitFunc level. func NewRecoverySink( e *BlockExecutor, replicaID string, diff --git a/seaweed-block/core/transport/recovery_sink_adapter_test.go b/seaweed-block/core/transport/recovery_sink_adapter_test.go index bd9b305361..d248f357d4 100644 --- a/seaweed-block/core/transport/recovery_sink_adapter_test.go +++ b/seaweed-block/core/transport/recovery_sink_adapter_test.go @@ -49,6 +49,13 @@ type recordedEmit struct { // // Returns a pointer to a slice the test consumes; callers must // hold the test's mutex while reading. +// +// TEST-ONLY / single-goroutine: the entry.shipper assignment below +// does NOT acquire walShipperMu. Production paths (WalShipperFor, +// updateWalShipperEmitContext) take that mutex; this helper bypasses +// it deliberately because tests run before any concurrent access. +// Do not lift this pattern into production code or concurrent test +// scenarios without re-introducing the lock. func installRecordingShipper(t *testing.T, e *BlockExecutor, replicaID string) (*[]recordedEmit, *sync.Mutex) { t.Helper()