mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
cb4a137ce622c43344e2d169ab7d15ff6a66b16f
Per architect 2026-04-29 review of g7-redo/wal-shipper-impl:
Q1a (INV-SUBSET fromLSN+1 anchoring):
TestWalShipper_DeliveredEqualsCursor — replaced "expected LSN 1..head"
with explicit `fromLSN+1, ..., head` derivation. fromLSN=0 still in
this case (so first emit IS LSN 1) but assertion is now general:
future variants with fromLSN > 0 work without rewriting test logic.
Q1b (CursorMonotonic seed/fromLSN alignment):
Earlier seed (LSN 1..5) + fromLSN=10 had `head < fromLSN` — an edge
that exposes R1 bugs but doesn't pin INV-MONOTONIC-CURSOR cleanly.
Changed seed to LSN 1..15 so head=15 ≥ fromLSN=10, giving DrainBacklog
a real range (10, 15] to ship. Assertions strengthened: post-drain
cursor==head, idempotent NotifyAppend with lsn<cursor doesn't regress.
Q1c (BacklogStaysBacklog_UnderLoad err loosening):
Spec §5.3 normative content is "R1 must not fake-Realtime under
saturation"; whether DrainBacklog returns nil or non-nil at ctx
deadline is impl choice. Removed strict `drainErr != nil` Fatal,
removed errors.Is check; primary contracts (mode != Realtime AND
cursor < head) stay as Errorf. drainErr now logged as observation.
Q3 (R1_DoubleCheckRejectsRace fixedHeadSource):
Replaced HeadSourceFromStorage + sleep-until-cursor≥8 heuristic
with explicit fixedHeadSource control. Substrate Write happens
BEFORE head bump (atomicity: any scan after the bump sees LSN 11
in substrate). NotifyAppend after bump covers race-lost-the-window
branch (R1 already flipped → realtime emit).
Q4 (R2 single-shot per session — already correct):
Test asserts `fired ≤ 1` per session. Architect ratified per-session
single-shot; cross-session re-fire works because StartSession
resets saturationFired flag. Spec §6 line for "default per-session
at most once; cross-session can re-fire" is architect's edit
(separate from this commit).
TEST BUG FOUND DURING `go test` (architect-prompted "fix-then-code"):
6 sites used `lsn, _, _ := primary.Boundaries()` which captures R
(syncedLSN, FIRST return value), not H. memorywal.Boundaries returns
`(R, S, H)`; only Sync() advances R, so concurrent NotifyAppend after
Write got stale lsn=preSyncedLSN, hit the idempotent-skip path
(`lsn <= cursor`), and live writes during session vanished.
Fixed by using primary.Write's RETURNED lsn directly:
- Old: _, _ = primary.Write(lba, data)
lsn, _, _ := primary.Boundaries()
- New: lsn, _ := primary.Write(lba, data)
6 fix sites: R1_NoGapAtTransition (line 396), NoDoubleLive (566),
R2_LagSignalFires (627), R2_NoSpuriousSignal (669),
BacklogToRealtime_Happy (717), BacklogStaysBacklog_UnderLoad (786).
Two tests went from RED → GREEN purely via this test bugfix:
- TestWalShipper_R1_NoGapAtTransition: was cursor=102 want 200;
now cursor=200 == finalHead, all 200 LSN in emit log.
- TestWalShipper_BacklogToRealtime_Happy: was emit count=10 want
11; now 11 emits (10 backlog + 1 realtime LSN 11).
Other tests passed coincidentally because their assertions don't
depend on the lsn parameter to NotifyAppend being correct (e.g.,
R2 tests count fired hooks, not exact LSN sequences).
IMPLEMENTATION (wal_shipper.go) is unchanged — no behavior bug
surfaced. Tests had the bug; spec-driven discipline still worked
(failing tests forced inspection that found the test bug, not a
silent green-on-bad-impl).
Test results:
go test ./core/transport/ -run "TestWalShipper_" -count=1 → all
PASS (10 PASS + 1 SKIP for RegistrySingleton P1 placeholder)
go test ... -run "R1_NoGap|R1_DoubleCheck|NoDoubleLive" -count=20
→ no flake under stress (architect Q3 alternate gate; -race not
enabled per Windows+CGO note in memory)
Wider sweep core/transport/ + core/recovery/ + core/storage/... +
core/replication/component/ all green.
Next: P1 (BlockExecutor.Ship delegate to walShipper) — TDD again,
write tests against INV-NO-DOUBLE-LIVE + INV-SINGLE (registry)
first.
Languages
Go
84.5%
Rust
7.9%
Shell
2.7%
templ
1.6%
Java
1%
Other
2%