diff --git a/seaweed-block/core/transport/dual_lane_p2d_profile_test.go b/seaweed-block/core/transport/dual_lane_p2d_profile_test.go index 08124629b4..8e7950493e 100644 --- a/seaweed-block/core/transport/dual_lane_p2d_profile_test.go +++ b/seaweed-block/core/transport/dual_lane_p2d_profile_test.go @@ -73,7 +73,11 @@ func TestP2d_EmitDispatch_SteadyMsgShipProfile(t *testing.T) { resCh <- readUntilEOF(readerConn) }() - if err := shipper.NotifyAppend(7, 50, []byte{0xDE, 0xAD, 0xBE, 0xEF}); err != nil { + // §6.3 migration: lsn=cursor+1=1 so fast-path tail-emit fires. + // (Pre-§6.3 this used lsn=50 for distinctness; under §6.3 + // fail-closed default, that would CursorGap. The wire-format + // claim — SWRP preamble vs frameWALEntry — is unchanged.) + if err := shipper.NotifyAppend(7, 1, []byte{0xDE, 0xAD, 0xBE, 0xEF}); err != nil { t.Fatalf("NotifyAppend: %v", err) } _ = writerConn.Close() @@ -121,7 +125,9 @@ func TestP2d_EmitDispatch_DualLaneWALFrameProfile_LiveKind(t *testing.T) { resCh <- readUntilEOF(readerConn) }() - if err := shipper.NotifyAppend(11, 200, []byte{0xCA, 0xFE}); err != nil { + // §6.3 migration: lsn=1 so fast-path fires. Wire-format claim + // (frameWALEntry + WALKindSessionLive tag) is independent of LSN. + if err := shipper.NotifyAppend(11, 1, []byte{0xCA, 0xFE}); err != nil { t.Fatalf("NotifyAppend: %v", err) } _ = writerConn.Close() diff --git a/seaweed-block/core/transport/recovery_sink_adapter_test.go b/seaweed-block/core/transport/recovery_sink_adapter_test.go index 8a6930c3cd..326ffc9217 100644 --- a/seaweed-block/core/transport/recovery_sink_adapter_test.go +++ b/seaweed-block/core/transport/recovery_sink_adapter_test.go @@ -349,7 +349,12 @@ func TestRecoverySink_NotifyAppendAfterEndSession_UsesSteadyContext(t *testing.T // the underlying WalShipper directly so the recording EmitFunc // captures the post-EndSession context state. shipper := e.WalShipperFor(replicaID) - if err := shipper.NotifyAppend(7, 100, []byte{0xCC}); err != nil { + // §6.3 migration: lsn = cursor+1 so fast-path tail-emit fires. + // Post-EndSession cursor is wherever DrainBacklog left it (0 for + // empty substrate). Test's claim is rule-2 context restore, not + // LSN-sequence semantics — distinct LSN value not required. + postLSN := shipper.Cursor() + 1 + if err := shipper.NotifyAppend(7, postLSN, []byte{0xCC}); err != nil { t.Fatalf("WalShipper.NotifyAppend post-EndSession: %v", err) } @@ -360,8 +365,8 @@ func TestRecoverySink_NotifyAppendAfterEndSession_UsesSteadyContext(t *testing.T t.Fatal("no emits recorded") } last := (*recorded)[len(*recorded)-1] - if last.lba != 7 || last.lsn != 100 { - t.Fatalf("last emit unexpected: lba=%d lsn=%d (want lba=7 lsn=100)", last.lba, last.lsn) + if last.lba != 7 || last.lsn != postLSN { + t.Fatalf("last emit unexpected: lba=%d lsn=%d (want lba=7 lsn=%d)", last.lba, last.lsn, postLSN) } if last.conn != steadyConn { t.Errorf("post-EndSession emit: conn=%p want steadyConn=%p (rule 2 violated)", @@ -435,7 +440,9 @@ func TestRecoverySink_FullLifecycle(t *testing.T) { // call the underlying WalShipper directly to verify the post- // EndSession emit context is the restored steady context. shipper := e.WalShipperFor(replicaID) - if err := shipper.NotifyAppend(15, 9999, []byte{0xFF}); err != nil { + // §6.3 migration: lsn = cursor+1 so fast-path fires. + postLSN := shipper.Cursor() + 1 + if err := shipper.NotifyAppend(15, postLSN, []byte{0xFF}); err != nil { t.Fatalf("WalShipper.NotifyAppend post-EndSession: %v", err) } diff --git a/seaweed-block/core/transport/ship_sender_test.go b/seaweed-block/core/transport/ship_sender_test.go index 442ecf2802..fb83132e96 100644 --- a/seaweed-block/core/transport/ship_sender_test.go +++ b/seaweed-block/core/transport/ship_sender_test.go @@ -363,9 +363,11 @@ func TestExecutor_Ship_StaleEpoch_SilentDrop(t *testing.T) { } // Sanity: a matching-epoch Ship on the same session still works. + // §6.3 migration: lsn=cursor+1=1 (cursor=0; the stale-epoch Ship + // above was silent-dropped before reaching the shipper). fresh := make([]byte, 4096) fresh[0], fresh[1] = 0xAA, 0xBB - if err := exec.Ship("r1", lineage, 6, 2, fresh); err != nil { + if err := exec.Ship("r1", lineage, 6, 1, fresh); err != nil { t.Fatalf("fresh-epoch Ship: %v", err) } deadline := time.Now().Add(2 * time.Second) diff --git a/seaweed-block/core/transport/wal_shipper.go b/seaweed-block/core/transport/wal_shipper.go index 55252e909b..60ee5f7932 100644 --- a/seaweed-block/core/transport/wal_shipper.go +++ b/seaweed-block/core/transport/wal_shipper.go @@ -207,20 +207,21 @@ type WalShipperConfig struct { // DefaultWalShipperConfig returns production defaults. // -// MIGRATION NOTE (slice 1 of §6.3 collapse): LegacyOutOfOrderEmit -// defaults to TRUE here as a transitional bridge — preserves -// pre-§6.3 "log + emit on tail gap" semantics so existing tests + -// production callers don't observe a behavior flip in this commit. -// Slice 2 will flip the default to false (§6.3 normative fail-closed -// on tail gap), once production callers have been audited / -// migrated. Tests that explicitly want §6.3 strict behavior must -// set LegacyOutOfOrderEmit=false in their config. +// SLICE-2 (architect ruling 2026-04-30): LegacyOutOfOrderEmit +// defaults to FALSE — §6.3 normative tail-gap fail-closed. The +// shipper does NOT silently emit input bytes for a missing-LSN +// case; the engine MUST escalate to rebuild on tail gap. +// +// Tests / call sites that still need pre-§6.3 log+emit behavior +// MUST opt in explicitly with LegacyOutOfOrderEmit=true AND +// document a deprecation owner + removal date. New code MUST NOT +// rely on log+drop-gap. func DefaultWalShipperConfig() WalShipperConfig { return WalShipperConfig{ - IdleSleep: 5 * time.Millisecond, - SaturationThreshold: 100_000, - OnSaturation: nil, - LegacyOutOfOrderEmit: true, // slice-1 transitional; flip in slice-2 + IdleSleep: 5 * time.Millisecond, + SaturationThreshold: 100_000, + OnSaturation: nil, + // LegacyOutOfOrderEmit: false (zero value) — §6.3 normative. } } diff --git a/seaweed-block/core/transport/wal_shipper_executor_test.go b/seaweed-block/core/transport/wal_shipper_executor_test.go index c768122bfa..92cfd04ade 100644 --- a/seaweed-block/core/transport/wal_shipper_executor_test.go +++ b/seaweed-block/core/transport/wal_shipper_executor_test.go @@ -137,32 +137,34 @@ func TestBlockExecutor_Ship_AdvancesWalShipperCursor(t *testing.T) { const replicaID = "r1" - // Ship LSN=10 → walShipper cursor must reach 10. - if err := exec.Ship(replicaID, lineage, 0, 10, []byte{0xAA, 0xBB}); err != nil { - t.Fatalf("Ship lsn=10: %v", err) + // §6.3 migration: sequential LSN starting at cursor+1=1; no gaps. + // Test claim is "Ship advances WalShipper cursor" — sequential LSN + // is the production-mirror pattern (cursor advances by 1 per Ship). + // Ship LSN=1 → cursor must reach 1. + if err := exec.Ship(replicaID, lineage, 0, 1, []byte{0xAA, 0xBB}); err != nil { + t.Fatalf("Ship lsn=1: %v", err) } s := exec.WalShipperFor(replicaID) - if got := s.Cursor(); got != 10 { - t.Errorf("after Ship lsn=10: walShipper.Cursor()=%d want 10 (Ship must delegate to WalShipper)", got) + if got := s.Cursor(); got != 1 { + t.Errorf("after Ship lsn=1: walShipper.Cursor()=%d want 1 (Ship must delegate to WalShipper)", got) } - // Ship LSN=20 → walShipper cursor advances. - if err := exec.Ship(replicaID, lineage, 1, 20, []byte{0xCC}); err != nil { - t.Fatalf("Ship lsn=20: %v", err) + // Ship LSN=2 → cursor advances. + if err := exec.Ship(replicaID, lineage, 1, 2, []byte{0xCC}); err != nil { + t.Fatalf("Ship lsn=2: %v", err) } - if got := s.Cursor(); got != 20 { - t.Errorf("after Ship lsn=20: walShipper.Cursor()=%d want 20", got) + if got := s.Cursor(); got != 2 { + t.Errorf("after Ship lsn=2: walShipper.Cursor()=%d want 2", got) } - // Idempotent Ship with lsn=15 (less than current cursor=20) — - // walShipper's NotifyAppend in Realtime drops it; cursor unchanged. - // Ship should still return nil (caller can't tell idempotent skip - // from successful emit at this layer). - if err := exec.Ship(replicaID, lineage, 2, 15, []byte{0xDD}); err != nil { - t.Fatalf("Ship lsn=15 (idempotent): %v", err) + // Idempotent Ship with lsn=1 (less than cursor=2) — walShipper's + // drive() drops it (in.lsn <= cursor); cursor unchanged. Ship + // returns nil regardless. + if err := exec.Ship(replicaID, lineage, 2, 1, []byte{0xDD}); err != nil { + t.Fatalf("Ship lsn=1 (idempotent): %v", err) } - if got := s.Cursor(); got != 20 { - t.Errorf("after idempotent Ship lsn=15: walShipper.Cursor()=%d want 20 (no regress)", got) + if got := s.Cursor(); got != 2 { + t.Errorf("after idempotent Ship lsn=1: walShipper.Cursor()=%d want 2 (no regress)", got) } } @@ -224,44 +226,56 @@ func TestBlockExecutor_WalShipperRegistry_StableUnderConcurrent_Ship(t *testing. // First, capture the walShipper instance from main goroutine. expected := exec.WalShipperFor(replicaID) - // Drive concurrent Ship() — each writer ships distinct LSNs. + // §6.3 migration (architect Path B ruling): concurrent Ship with + // out-of-order LSN is no longer a survivable pattern — under the + // fail-closed tail-gap default, out-of-order LSN returns an error + // per §6.3 / §6.9 NEGATIVE-EQUITY. The test's own header + // acknowledges concurrent Ship is "NOT production" — production + // serializes via volume.mu. The registry-stability claim + // (INV-SINGLE: WalShipperFor returns the same instance) is + // independent of concurrency and holds under sequential Ship. + // + // Drive sequential Ship from a single goroutine but call + // WalShipperFor from N concurrent goroutines to still exercise the + // registry-stability concurrency claim — the part of the test + // whose intent survives the §6.3 collapse. var wg sync.WaitGroup - for w := 0; w < writers; w++ { + const lookups = 8 + for r := 0; r < lookups; r++ { wg.Add(1) - go func(workerID int) { + go func() { defer wg.Done() - for i := 0; i < perWriter; i++ { - // LSNs: 1..200, distinct per (worker, i). - lsn := uint64(workerID*perWriter + i + 1) - if err := exec.Ship(replicaID, lineage, uint32(i), lsn, []byte{byte(workerID)}); err != nil { - t.Errorf("Ship: %v", err) + for j := 0; j < perWriter; j++ { + if got := exec.WalShipperFor(replicaID); got != expected { + t.Errorf("WalShipperFor concurrent lookup returned different instance (registry race)") return } } - }(w) + }() + } + // Sequential Ship with cursor+1 LSN — production-mirror. + for i := 0; i < writers*perWriter; i++ { + lsn := uint64(i + 1) + if err := exec.Ship(replicaID, lineage, uint32(i%64), lsn, []byte{byte(i & 0xFF)}); err != nil { + t.Fatalf("Ship lsn=%d: %v", lsn, err) + } } wg.Wait() - // After concurrent Ships, the WalShipper for r1 must STILL be - // the same instance — registry must have linearized. + // After Ships + concurrent lookups, the WalShipper for r1 must + // still be the same instance — registry stability claim survives + // concurrent WalShipperFor lookups. got := exec.WalShipperFor(replicaID) if got != expected { - t.Errorf("concurrent Ship: WalShipperFor(r1) returned different instance after load (registry race)") + t.Errorf("WalShipperFor returned different instance after load (registry race)") } - // Cursor advanced from 0. We deliberately do NOT assert - // cursor == maxLSN here: out-of-order concurrent Ship - // (non-production scenario; production serializes via volume.mu) - // can have lower-LSN goroutines silently idempotent-skip when a - // higher LSN already advanced cursor. cursor ≤ maxLSN is the - // only honest bound. Lossless-emit pinning belongs to P2 e2e - // with serialized Ship. + // Sequential Ship: cursor MUST equal maxLSN (lossless under §6.3 + // when LSN sequence is dense and serialized — the production-mirror + // pattern). const maxLSN = uint64(writers * perWriter) cursor := expected.Cursor() - if cursor == 0 { - t.Errorf("after %d concurrent Ships: cursor=0 (no Ship landed at all)", writers*perWriter) - } - if cursor > maxLSN { - t.Errorf("cursor=%d > maxLSN=%d (impossible — bug)", cursor, maxLSN) + if cursor != maxLSN { + t.Errorf("after sequential Ships: cursor=%d want %d (lossless under §6.3 + serialized)", cursor, maxLSN) } } diff --git a/seaweed-block/core/transport/walshipper_resident_test.go b/seaweed-block/core/transport/walshipper_resident_test.go index 4b51b5a8aa..95d369460d 100644 --- a/seaweed-block/core/transport/walshipper_resident_test.go +++ b/seaweed-block/core/transport/walshipper_resident_test.go @@ -163,8 +163,9 @@ func TestWalShipper_Resident_SteadyShipBetweenSessions(t *testing.T) { } e.updateWalShipperEmitContext(replicaID, steadyConn, steadyLineage, EmitProfileSteadyMsgShip) - // Phase 1: steady NotifyAppend (Realtime). - if err := shipper.NotifyAppend(0, 1, []byte{0x01}); err != nil { + // Phase 1: steady NotifyAppend (Realtime). lsn = cursor+1 = 1. + p1LSN := shipper.Cursor() + 1 + if err := shipper.NotifyAppend(0, p1LSN, []byte{0x01}); err != nil { t.Fatalf("phase1 NotifyAppend: %v", err) } @@ -185,7 +186,11 @@ func TestWalShipper_Resident_SteadyShipBetweenSessions(t *testing.T) { sink1.EndSession() // Phase 3: steady NotifyAppend between sessions (Realtime, steady context). - if err := shipper.NotifyAppend(1, 2, []byte{0x02}); err != nil { + // §6.3 migration: cursor was reset to fromLSN=0 by session1's StartSession; + // DrainBacklog with empty substrate didn't advance it. Use cursor+1 so + // fast-path fires. + p3LSN := shipper.Cursor() + 1 + if err := shipper.NotifyAppend(1, p3LSN, []byte{0x02}); err != nil { t.Fatalf("phase3 NotifyAppend: %v", err) } @@ -205,8 +210,9 @@ func TestWalShipper_Resident_SteadyShipBetweenSessions(t *testing.T) { } sink2.EndSession() - // Phase 5: steady NotifyAppend post-session-2. - if err := shipper.NotifyAppend(2, 3, []byte{0x03}); err != nil { + // Phase 5: steady NotifyAppend post-session-2. §6.3: cursor+1. + p5LSN := shipper.Cursor() + 1 + if err := shipper.NotifyAppend(2, p5LSN, []byte{0x03}); err != nil { t.Fatalf("phase5 NotifyAppend: %v", err) } @@ -292,8 +298,9 @@ func TestWalShipper_Resident_NotifyAppendDuringSession_BacklogMode(t *testing.T) } sink.EndSession() - // Post-EndSession Realtime emit MUST land. - if err := shipper.NotifyAppend(99, 9999, []byte{0xFF}); err != nil { + // Post-EndSession Realtime emit MUST land. §6.3: lsn=cursor+1. + postLSN := shipper.Cursor() + 1 + if err := shipper.NotifyAppend(99, postLSN, []byte{0xFF}); err != nil { t.Fatalf("post-session NotifyAppend: %v", err) } @@ -306,8 +313,8 @@ func TestWalShipper_Resident_NotifyAppendDuringSession_BacklogMode(t *testing.T) } last := (*recorded)[len(*recorded)-1] - if last.lba != 99 || last.lsn != 9999 { - t.Errorf("last emit unexpected: lba=%d lsn=%d (want 99/9999)", last.lba, last.lsn) + if last.lba != 99 || last.lsn != postLSN { + t.Errorf("last emit unexpected: lba=%d lsn=%d (want 99/%d)", last.lba, last.lsn, postLSN) } if last.lineage != steadyLineage { t.Errorf("post-session emit lineage=%+v want steady=%+v (rule 2 violated)",