Commit Graph
2 Commits
Author SHA1 Message Date
pingqiu d38b95d1aa G5-5C #1.1: address QA review of batch 1 — close result/backoff seam, reject MaxConcurrent>1, add Stop-cancels-inflight test
QA review of seaweed_block@<batch 1> flagged three legitimate issues:

1. Probe result/backoff seam not closed.
   Fix: add ResultFn(peer, err) seam, called once per probe attempt
   with the outcome (success / error / surfaced panic). NewProbeLoop
   requires a non-nil resultFn. dispatchProbe wraps probeFn in a
   defer/recover that converts panics into a non-nil error and
   forwards every outcome to resultFn (also panic-safe via second
   recover wrapper). This gives ReplicaPeer's cooldown progression
   (batch 2) a single canonical hook into success/failure.

2. MaxConcurrent > 1 silently accepted.
   Fix: NewProbeLoop now rejects MaxConcurrent > 1 with an explicit
   error message citing the v0.5 architect binding. <= 0 still
   normalizes to 1 (silent default for the typical empty config
   path); =1 is the only accepted explicit value.

3. Missing Stop-cancels-inflight test.
   Fix: TestProbeLoop_StopCancelsInflightProbe — probeFn blocks on
   <-ctx.Done(); Stop() must return within 2s; verifies the
   ctx-cancel goroutine in dispatchProbe wires stopCh → ctx
   correctly.

Additional tests:
- TestProbeLoop_MaxConcurrentGreaterThanOne_Rejected (covers the
  rejection path + the =0 normalization path + the =1 acceptance
  path).
- TestProbeLoop_NilResultFn_Rejected (constructor seam check).
- TestProbeLoop_ResultFn_ReceivesProbeOutcome (success + error +
  panic each surface to resultFn with the right shape).
- TestProbeLoop_ResultFn_PanicIsolated (panic in resultFn does not
  crash loop — CP4B-2 lesson 3 extended to result callback).

Test results: 13/13 PASS. Full replication suite no regression.

Note on gopls diagnostics ("undefined: ReplicaPeer"): seaweedfs
workspace doesn't include the seaweed_block module — gopls can't
resolve cross-module identifiers. go build / go test inside
seaweed_block compiles cleanly. A go.work entry would silence the
gopls warnings; out of scope for this batch.

Next batch (G5-5C #2): peer.go::ProbeIfDegraded() + cooldown
state-machine + in-flight guard tests.
2026-04-27 15:42:38 -07:00
pingqiu 4a38e5cbce G5-5C #1: probe loop skeleton + lifecycle tests
First production batch for the G5-5C primary-side degraded-peer probe
loop, per the architect-bound mini-plan v0.5 §1.A binding (Option B,
core/replication/ ownership) and §1.H audit-PASS verdict at
seaweedfs@9245446b5.

Files:
- core/replication/probe_loop.go (new): ProbeLoop struct with config
  + start/stop lifecycle (sync.Once on both); per-iteration tick that
  snapshots peers via PeerSourceFn, gates each via CooldownFn,
  dispatches via ProbeFn; CP4B-2 lessons applied (zero-interval
  rejected at construction; stop-before-start no deadlock; callback
  panic isolated via recover).
- core/replication/probe_loop_test.go (new): seven lifecycle tests
  covering Start/Stop happy path, stop-before-start, idempotent
  concurrent stop, zero-interval rejection, callback panic isolation,
  cooldownFn gating, empty peer set, and probeFn-error-doesn't-stop.

Design:
- ProbeLoop is runtime/wiring only. No engine FSM, no transport.
- Seams (PeerSourceFn / ProbeFn / CooldownFn) injected by host so
  the loop knows nothing about adapter, executor, or engine.
- Default config: Interval 5s, MaxConcurrent 1, CooldownBase 5s,
  CooldownCap 60s — architect-bound G5-5C v0.5 §1.A shape.
- Authority-bound (§1.E): peersFn snapshots ReplicationVolume.peers
  under lock; loop never enumerates network-discoverable addresses.
- All G5-5C INVs map cleanly to existing engine/replication state per
  the §1.H audit; this skeleton adds NO recovery substrate.

Tests verified:
- go test ./core/replication/ -run TestProbeLoop -count=1: PASS (7/7)
- go test ./core/replication/ -count=1: PASS (no regression on
  existing T4a-5/T4b/T4c suites)

Next batch (G5-5C #2): peer.go::ProbeIfDegraded() + cooldown
state-machine + in-flight guard tests.
2026-04-27 15:37:06 -07:00