wzcheng99 3597bc40ca T4a-4: ReplicationVolume MVP (Option X LSN-order fan-out)
Introduces ReplicationVolume — the per-volume fan-out owner that
tracks the authoritative replica set and serializes Ship fan-out so
the V2 BlockVol.shipMu LSN-order invariant survives the V3 layer
split.

Architect-approved Option X (G-1 pre-code review,
v3-phase-15-t4a-4-g1-v2-read.md): v.mu.Lock() held across the
entire per-peer fan-out loop (Condition A), not just map snapshot
or "prepare then unlock then ship." The mutex is plain sync.Mutex
(no reader-only API worth preserving RWMutex for).

Contract wording (architect-revised, explicit):
  ReplicationVolume.OnLocalWrite serializes fan-out in LSN order
  for a given volume. Caller order is NOT trusted as the
  correctness mechanism.

System invariant: INV-REPL-LSN-ORDER-FANOUT-001. V2 BlockVol.shipMu
atomically composed "allocate LSN + append WAL + Ship" under one
mutex. V3 splits the three concerns across engine / LogicalStorage /
ReplicationVolume; the LSN-order property is preserved end-to-end
when (a) Backend.Write invokes LogicalStorage.Write + OnLocalWrite
under the caller's own atomicity (natural shape — same goroutine)
and (b) OnLocalWrite's mutex serializes fan-out. Test
TestReplicationVolume_OnLocalWrite_ConcurrentLSNs_OrderedAtReplica
is the adversarial pin: N concurrent callers, caller-side lock
mimics Backend.Write, LBAs interleaved with LSN ordering so any
reorder is byte-detectable at the replica.

Accepted T4a trade-off (mini-plan change log): correctness-first
serialized design. Per-volume fan-out holds v.mu during each
peer's ShipEntry, so a slow peer (lazy dial, 3s write deadline,
degraded state) stalls the writer path. Async queue (Option Z) is
deferred optimization, not forgotten design debt — revisit only
after INV-REPL-LSN-ORDER-FANOUT-001 is proven in production.

Surface (~200 LOC production + 430 LOC tests):
  - LocalWrite: {LBA, Data, LSN} — the layer-cross carrier
  - ReplicationVolume: peers map + borrowed store + serialization mu
  - NewReplicationVolume(volumeID, store): borrow store, never close
  - UpdateReplicaSet(targets): add/remove/recreate-on-lineage-bump
    under v.mu. Lineage bump = tear-down + recreate (T4a MVP; T4c
    may add in-place lineage update)
  - OnLocalWrite(ctx, w): LSN-order-serialized fan-out; per-peer
    error is best-effort (logged + peer already marked Degraded by
    ReplicaPeer.ShipEntry's forward-carry CARRY-1); does NOT fail
    the OnLocalWrite call
  - Close(): idempotent; releases all peers' sessions; does NOT
    close the borrowed store (BUG-005 discipline)
  - PeerCount() / newExec field: test seam for executor observation

BlockExecutor gains one test-grade accessor:
  - HasSession(id): diagnostic for Opt-3 executor-teardown fence.
    Used by TestReplicationVolume_UpdateReplicaSet_RemovePeer_
    ExecutorTornDown to assert session removal after peer.Close.
    Tri-line godoc contract; not intended for production flow.

Tests (8, all green):
  1. UpdateReplicaSet_AddPeer — empty → 1 peer
  2. UpdateReplicaSet_RemovePeer_ExecutorTornDown — Opt-3 three-
     assertion fence (Close-called, session-removed, re-add-works-
     and-ships-byte-exact)
  3. UpdateReplicaSet_LineageBump_RecreatesPeer — same ReplicaID
     new Epoch → new sessionID, new lineage
  4. OnLocalWrite_SinglePeer_BestEffort — 20 LBAs byte-exact,
     peer stays Healthy
  5. OnLocalWrite_PeerErrorDoesNotFailCaller — dead-addr peer,
     OnLocalWrite returns nil, peer Degraded
  6. OnLocalWrite_ConcurrentLSNs_OrderedAtReplica — INV-REPL-LSN-
     ORDER-FANOUT-001 adversarial pin (40 concurrent goroutines,
     LBA/LSN interleaved, replica state byte-detectable)
  7. Constructor_DoesNotOwnStore — BUG-005 regression fence; store
     usable post-ReplicationVolume.Close
  8. OnLocalWrite_Closed_Errors — post-Close call returns error,
     no panic

Full core/transport + core/replication + core/adapter suites green.
G-2 three-line godoc contracts on every public symbol (New, Update,
OnLocalWrite, Close, PeerCount) + HasSession on executor. G-3
preserved.
2026-04-23 15:31:51 -07:00
Languages
Go 84.6%
Rust 7.8%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%