pingqiu 44f87603fd T4b-5: ReplicationVolume.Sync + WriteObserver.Sync seam
Wires DurabilityCoordinator (T4b-4) into the per-volume Sync path.
Host-side FLUSH / SYNCHRONIZE_CACHE now drives the full local fsync
+ per-peer barrier closure in parallel with mode-dependent arithmetic.

Changes:

  core/frontend/durable/storage_adapter.go
    WriteObserver interface extended: Sync(ctx, targetLSN) joins the
    existing Observe(ctx, lba, lsn, data) method. Contract documented
    inline — observer.Sync OWNS the full sync job (both local
    fsync and peer barriers) when installed; StorageBackend delegates
    rather than calling storage.Sync locally.
    StorageBackend.Sync branches: observer==nil preserves the
    pre-T4b behavior (local storage.Sync only); observer!=nil reads
    walHead from LogicalStorage.Boundaries() and calls observer.Sync
    with that as targetLSN. The observer (ReplicationVolume) then
    invokes DurabilityCoordinator.SyncLocalAndReplicas which runs
    local + barriers in parallel inside its own goroutines.

  core/replication/volume.go
    ReplicationVolume gains:
      - coord field set to NewDurabilityCoordinator at construction
      - durabilityMode field, SetDurabilityMode setter +
        DurabilityMode accessor. Default BestEffort (zero value).
        Per mini-plan §5, T4b does not support per-Sync-call mode
        override — mode is a per-volume setting.
      - Sync(ctx, targetLSN) method — snapshots peers under v.mu,
        builds a localSync closure around v.store.Sync, delegates
        to coord.SyncLocalAndReplicas, returns error verbatim.

    Lock scope: v.mu held across the FULL Sync call. Matches the
    T4a-4 round-15 Condition A discipline — concurrent Sync +
    OnLocalWrite calls are serialized on v.mu, preserving the V2
    shipMu semantics extended from ship-only into ship+barrier.
    Accepted correctness-first trade-off: a slow peer barrier stalls
    other writers on the same volume; async-queue optimization
    (Option Z) is deferred post-T4.

Tests (2 required per mini-plan §2 T4b-5):

  - TestReplicationVolume_Sync_BestEffort_E2E — full end-to-end
    smoke: StorageBackend.Write 10 LBAs → Observe → ship → replica
    applies. StorageBackend.Sync → observer.Sync →
    DurabilityCoordinator → local fsync + peer barrier in parallel.
    Replica's R-boundary (durable frontier) must reach primary's
    H (walHead) after Sync returns. Peer stays Healthy throughout.

  - TestReplicationVolume_Sync_PreservesLSNOrderUnderConcurrency —
    forward-carry fence for INV-REPL-LSN-ORDER-FANOUT-001 under
    the new Sync code path. 40 goroutines, caller-side serialized
    LSN allocation + OnLocalWrite, periodic Sync calls interleaved
    every 4th iteration. LBA ordering is inverted from LSN order so
    any reorder is byte-detectable. All 40 LBAs must settle to the
    correct LSN marker at the replica.

Forward-carry verification: T4a-4's
TestReplicationVolume_OnLocalWrite_ConcurrentLSNs_OrderedAtReplica
continues to pass — the existing ordering invariant is not regressed
by the new Sync code path that shares v.mu.

Verification: full 21-package repo suite green including the
extended WriteObserver interface not breaking core/frontend/durable
tests. G-2 tri-line godoc on SetDurabilityMode, DurabilityMode
accessor, Sync method, extended WriteObserver.Sync contract. G-3
cumulative.

Fifth task in T4b batch. Next: T4b-6 L2 subprocess integration
matrix closes the batch.
2026-04-24 01:14:38 -07:00
Languages
Go 84.5%
Rust 7.9%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%