Files
seaweedfs/seaweed-block/internal/docs/protocol
Ping QiuandClaude Opus 5.5 cb353bccea fix(G2): a new primary fences its own replica listener (#82)
* test(G2): red - a promoted host applies the deposed primary's ship

fencing-gaps-todo.md G2, red test first. A real ReplicaListener and the
real Host.applyFact primary path: ship at epoch 1 to listener B, master
promotes B to primary at epoch 2 (a self AssignmentFact), the old primary
ships at epoch 1 again. Today the ship is applied.

Adds the seam the fix uses: Host.SetSelfFence / fenceSelf call the
host's own listener on the primary path (after UpdateReplicaSet, before
OnAssignment) and on the supporting-replica path, and replay an already
adopted role when the listener is installed later (cmd/blockvolume wires
it before Serve). The listener's FenceAsPrimary / AdmitAsReplica are
no-ops in this commit, so the test is red on behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(G2): a new primary fences its own replica listener

fencing-gaps-todo.md G2. The replica listener gets an epoch floor and a
primary flag. FenceAsPrimary(e), called by the host on the primary path
before OnAssignment, sets the floor to at least e and refuses every
replication mutation; AdmitAsReplica(e), on the supporting-replica path,
re-admits replication but keeps the floor. acceptMutationLineage, the
single gate for ship, recovery lane start and rebuild block/done,
applies both. Probes are unchanged.

Green: TestG2_PromotedHostRefusesShipFromDeposedPrimary (real
Host.applyFact primary path + real listener) passes 3/3; new listener
tests: a primary refuses ship / recovery lane start / rebuild but answers
probes; the floor stays after AdmitAsReplica and never goes down.
Ledger: INV-FENCE-SELF-ON-PROMOTE-001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style(G2): gofmt replica.go field alignment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(G2): the fence drains replication mutations already past the gate

Review of cc884db (claude03 P2-1, codex01 P1): acceptMutationLineage
released r.mu before the store write, and FenceAsPrimary only flipped
flags, so a deposed-epoch ship or rebuild admitted just before promotion
was applied after the fence returned, while the host served as primary.

Each mutating frame (ship, recovery lane start, rebuild block, rebuild
done, barrier) is now counted under r.mu from before its gate check until
its storage effect is done; its ack is written after it is uncounted, so
the fence never waits on the network. FenceAsPrimary sets primary and the
floor (no new admissions), then waits for the count to reach zero, bounded
(10 s); on timeout it returns an error and the host fails closed: no
OnAssignment, as for an UpdateReplicaSet failure; master redelivers.

Lock order: Host.selfFenceMu -> ReplicaListener.mu, never the reverse;
r.mu is held only for gate state and the counter (Cond.Wait releases it),
never across storage or network calls.

Red (fence without the wait) / green: in-flight controls for ship (direct
and ApplyHook paths) and a rebuild base write fail, then pass 3/3; a
mutation stuck past the bound makes the fence report an error; the host
does not adopt primary when the fence fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 00:49:38 -08:00
..

Protocol Design And Hardening

This directory is the working protocol-design entry point for Seaweed Block.

The goal is not to create a large abstract architecture library. The goal is to keep product behavior explainable and testable as the Kubernetes, CSI, host path, failover, repair, and dashboard surfaces grow.

Source Lineage

This directory distills the V3 design references under:

  • C:\work\seaweedfs\sw-block\design\v3-architecture.md
  • C:\work\seaweedfs\sw-block\design\v3-runtime-state-machines-overview.md
  • C:\work\seaweedfs\sw-block\design\v3-invariant-ledger.md
  • C:\work\seaweedfs\sw-block\design\protocol-anti-patterns.md
  • C:\work\seaweedfs\sw-block\design\v3-recovery-algorithm-consensus.md

Those documents remain the deeper historical source. The files here are the current-product operating copy for v0.3+ planning.

Design Thesis

Seaweed Block should use:

one product read model centered on ManagedVolume
+ many local projection controllers / small automata
+ invariant ledger
+ anti-pattern guardrails
+ cross-controller model tests

Do not build one giant state machine. Do not scatter unrelated local state machines. The product needs a shared volume-centered fact model and small engines that project from it.

Documents

  • control-model-principles.md defines the truth-domain model and the rules for large context plus small automata.
  • managed-volume-operations-model.md defines the Phase 22 center of gravity: a PVC-backed ManagedVolume read model that composes K8s, CSI, authority, replica, host-path, workload, and evidence facts.
  • engine-design-guidelines.md defines the reusable engine/control-plane method: facts, context, multi-state projections, invariant checks, action contracts, executor boundaries, and evidence.
  • invariant-ledger.md starts the current-project invariant ledger. Any new protocol claim should add or update a row here.
  • protocol-anti-patterns.md copies the important anti-patterns into the current project vocabulary.
  • phase22-control-context-plan.md proposes the next hardening phase: ManagedVolume Operations Model.
  • operations-state-dependency-review.md defines the Phase 22 scope decision: operations v1 over a real product read model, not a pure dashboard pass or narrow protocol refactor.
  • control-structure-effectiveness-review.md reviews which parts of the control/model work have become real product capability, which remain too semantic, and what proof is required before approving more model work.
  • fencing-gaps-todo.md tracks open epoch / fencing gaps G1-G5 with the failure scenario, proposed fix, and red test for each.

Review Rule

Any behavior change that affects authority, recovery, CSI attach, host path, Kubernetes node behavior, or support evidence should answer:

  1. Which truth domain owns the new fact?
  2. Which invariant proves the behavior?
  3. Which anti-pattern did we check against?
  4. Is this a projection, or does it create authority?
  5. Does a cross-controller model test cover the composed state?
  6. Does the behavior update the ManagedVolume story for PVC, replica, frontend, CSI, host path, recovery, or evidence?

If the answers are unclear, update the protocol docs before shipping the behavior.