mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
docs: §6.8 review-derived invariants — DisableTimerDrain + lock order
Architect review of C1+C2+C3 (offline against §6.8 / §IV / §V) flagged two doc gaps that should be inline in the code, not just PR descriptions: 1. DisableTimerDrain (wal_shipper.go WalShipperConfig): - PRODUCTION MUST leave false. §6.8 #4 is MUST: "primary-idle starvation forbidden". Setting true in production violates architect contract. - Test-only invariant: shipper MUST NOT linger in cursor < head without alternative drain source. Today's only users are R2 saturation tests (scope-bounded). 2. Lock hierarchy (executor.go walShipperEntry.writeMu): - shipMu → writeMu (always; reversal risks deadlock). - WalShipper holds shipMu; calls EmitFunc under it; EmitFunc acquires writeMu. - recovery.Sender.writeFrame acquires only writeMu (does not hold shipMu). Order is consistent: shipMu outermost when both in play. No code logic change; documentation tightening so future readers can verify §6.8 mechanical SINGLE-SERIALIZER without re-deriving from grep. go test all four packages — PASS.
This commit is contained in:
1 parent
dd370a5367
commit
14a0d32d40
2 files changed
+34
-4
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user