diff --git a/seaweed-block/core/transport/executor.go b/seaweed-block/core/transport/executor.go index 588acc758c..96900bd686 100644 --- a/seaweed-block/core/transport/executor.go +++ b/seaweed-block/core/transport/executor.go @@ -121,6 +121,21 @@ type walShipperEntry struct { // mutex is uncontended. In dual-lane sessions, recovery.Sender // duck-types `WriteMu() *sync.Mutex` on the sink and uses this // mutex for its own writeFrame calls. + // + // Lock hierarchy (architect §6.8 mechanical SINGLE-SERIALIZER): + // + // walShipper.shipMu ───> walShipperEntry.writeMu + // + // - WalShipper holds shipMu around mode/cursor mutations and + // calls EmitFunc under it (NotifyAppend Realtime, DrainBacklog + // scan callback, drainOpportunity scan callback). EmitFunc + // then acquires writeMu for the wire write — shipMu is + // OUTERMOST. + // - recovery.Sender.writeFrame acquires only writeMu (Sender + // does not hold shipMu). + // + // Therefore: any code path that holds shipMu may acquire writeMu, + // but NEVER the reverse. Reversing this order risks deadlock. writeMu sync.Mutex } diff --git a/seaweed-block/core/transport/wal_shipper.go b/seaweed-block/core/transport/wal_shipper.go index 88ee3958b3..28f375a2aa 100644 --- a/seaweed-block/core/transport/wal_shipper.go +++ b/seaweed-block/core/transport/wal_shipper.go @@ -148,10 +148,25 @@ type WalShipperConfig struct { OnSaturation func(replicaID string, lag uint64) // DisableTimerDrain, if true, suppresses the C2 §6.8 #4 self- - // driving Backlog drain goroutine. Tests that need manual control - // over DrainBacklog timing (e.g., R2 saturation tests that drive - // lag without letting drain catch up) set this. Production - // callers leave it false (default). + // driving Backlog drain goroutine. + // + // PRODUCTION CALLERS MUST LEAVE THIS false. §6.8 #4 is a MUST: + // "primary-idle starvation forbidden" — backlog cannot depend + // solely on new appends. Setting DisableTimerDrain=true in + // production violates the architect contract. + // + // Test-only invariant when set true: + // "the WalShipper MUST NOT linger in cursor < head without + // an alternative drain source" — i.e., the test itself drives + // DrainBacklog explicitly, OR the test asserts on a + // transient-debt state and tears the shipper down before + // the assertion would observe starvation. + // + // Today's only callers are core/transport's R2 saturation tests + // (TestWalShipper_R2_LagSignalFires / NoSpuriousSignal): they + // build lag by writing without a manual DrainBacklog call, + // observe OnSaturation fires, then tear down. Within the test + // scope, debt is intentional and bounded. DisableTimerDrain bool }