Commit Graph
1 Commits
Author SHA1 Message Date
pingqiu e79ec9e952 T4b-4: DurabilityCoordinator (muscle port, G-1 signed)
Ports V2 MakeDistributedSync (weed/storage/blockvol/dist_group_commit.go,
~45 LOC muscle) into V3 DurabilityCoordinator at core/replication/
durability.go. Gate G-1 pre-signed by QA at round 24 per revised
artifact sw-block/design/v3-phase-15-t4b-4-g1-v2-read.md.

Core surface:

  - DurabilityMode enum (BestEffort / SyncQuorum / SyncAll) with
    String() + zero-safe BestEffort default, mirroring V2
  - DurabilityResult struct with DurableNodes, Quorum, FailedPeers,
    Err fields for caller diagnostics
  - ErrDurabilityBarrierFailed / ErrDurabilityQuorumLost sentinels
    mirroring V2 blockerr.ErrDurability*
  - NewDurabilityCoordinator() stateless constructor
  - SyncLocalAndReplicas(ctx, mode, targetLSN, localSync, peers) —
    parallel fan-out + mode arithmetic
  - EvaluateBarrierAcks(mode, rf, localSyncSucceeded, perPeerErrors)
    — pure arithmetic helper exposed for unit testing

Hidden invariants pinned (from G-1 §4.2):

  #7  Local-fsync short-circuits mode arithmetic. If localSync
      errors, DurableNodes=0, mode arithmetic skipped. Pinned by
      TestDurabilityCoordinator_LocalSyncFails_AllModesError across
      all three modes.

  #8  Peer-state mutation on barrier failure. DurabilityCoordinator
      does NOT call peer.Invalidate — that translation lives inside
      peer.Barrier (T4b-3 wrapper) per §0-B locality. Coordinator
      sees only the error vector; failed peers are logged with
      peer ID + lsn + err at the coordinator layer for operator
      visibility. Pinned by TestDurabilityCoordinator_BestEffort_
      Silences_Failures + TestDurabilityCoordinator_StaleLineageAck_
      NotCounted (both assert peer.State() == ReplicaDegraded after
      coordinator returns).

  #9  Zero-peers fast-path. len(peers)==0 skips parallel machinery
      entirely — localSync runs in the caller's goroutine. Pinned
      by TestDurabilityCoordinator_ZeroPeers_StandaloneFastPath
      across all three modes via runtime.Stack() goroutine-ID
      check (sameGoroutine must be true).

  #10 Target LSN derivation responsibility shift. Caller owns
      targetLSN; coordinator passes it through to peer.Barrier.
      Documented in SyncLocalAndReplicas godoc.

  #11 Flat wg.Add(1 + len(peers)) layout (not V2's wg.Add(2) +
      nested BarrierAll). Semantically equivalent. Pinned by
      TestDurabilityCoordinator_ParallelExecution (elapsed ~100ms
      for localDelay=100ms + 2 peers; sequential would be 100ms+).

Uniform round-21 rule: peer.Barrier owns lineage validation at the
executor seam; stale-lineage acks surface as ErrBarrierLineageMismatch
→ coordinator sees it as a failed peer → NOT counted toward durability.
Pinned by TestDurabilityCoordinator_StaleLineageAck_NotCounted with
a custom replica sending valid-decode responses carrying the wrong
lineage.

Metrics (V2 concern #6) DEFERRED to T4-end observability pass per
G-1 §7 decision. core/replication has no metrics surface yet;
adding one is scope creep.

Tests (9 per mini-plan §2 T4b-4 + 2 sanity):

   1. _Quorum_RF3_AllHealthy — RF=3, 2 peers healthy → 3/3 durable
   2. _Quorum_RF3_OneReplicaFailed — 2/3 durable, quorum met
      (sync_quorum), sync_all fails
   3. _Quorum_RF3_BothReplicasFailed — 1/3 durable,
      ErrDurabilityQuorumLost
   4. _SyncAll_AnyFailure_Fails — no silent swallow
   5. _BestEffort_Silences_Failures — peers Degraded, Err=nil
   6. _StaleLineageAck_NotCounted — H5 LOCK pin via
      wrong-lineage replica
   7. _LocalSyncFails_AllModesError — V2 line 46-48 short-circuit
      across all modes
   8. _ParallelExecution — elapsed ≤ 150ms for 100ms localSync + 2
      peers
   9. _ZeroPeers_StandaloneFastPath — rf=1, same-goroutine,
      INV-REPL-ZERO-PEER-NO-SPAWN

Plus sanity: _Constructor and DurabilityMode_String.

Verification: full 21-package repo suite green. G-2 tri-line godoc
on every public symbol (DurabilityMode + stringer, DurabilityResult,
DurabilityCoordinator, NewDurabilityCoordinator, SyncLocalAndReplicas,
EvaluateBarrierAcks, error sentinels). G-3 cumulative.

Fourth task in T4b batch. Next: T4b-5 ReplicationVolume.Sync wires
DurabilityCoordinator into the volume Sync path + extends
WriteObserver interface.
2026-04-24 00:40:06 -07:00