141 lines
10 KiB
Markdown
141 lines
10 KiB
Markdown
# Coordination subsystem plan — NEW deterministic Raft core
|
||
|
||
Status: NEW design, all tasks PLANNED. Baseline
|
||
`f1f9ba375b22abf1adcc7c550ec21ac20895c0a4`, inspected 2026-11-24.
|
||
Authority: [requirements](../REQUIREMENTS.md) R-005, R-011, R-012, R-014–R-016;
|
||
[architecture](../ARCHITECTURE.md) C-01–C-05, C-12, C-13.
|
||
|
||
## Baseline, algorithm and hard boundary
|
||
|
||
No current consensus module or tests exist; PROPOSED roots are `include/Void/Coordination`,
|
||
`src/Coordination`, `tests/standalone/Coordination`. Existing
|
||
[Resilience breaker](../../../include/Void/Resilience/CircuitBreaker.hpp) is a local
|
||
admission primitive, not leader election or fencing; source and matching graph metadata
|
||
were checked. Coordination is a native deterministic protocol with standard-library and
|
||
lower-foundation dependencies only. It imports no RPC, Discovery, Storage implementation,
|
||
Replication or Runtime. [Replication](Replication.md) owns concrete transport/persistence
|
||
adapters and application state machines. This direction is mandatory C-12.
|
||
|
||
Select fixed-membership Raft first, three or five voting nodes, majority commit, crash-stop/
|
||
recovery faults, authenticated non-Byzantine peers and stable storage. A single-node mode
|
||
is explicitly a development profile. Protocol design follows the
|
||
[extended Raft paper](https://raft.github.io/raft.pdf); timing affects liveness, while
|
||
persistence and quorum rules enforce safety. No lease-based linearizable reads, automatic
|
||
voter replacement, multi-leader writes or Byzantine tolerance are included initially.
|
||
|
||
## NEW event/action contract
|
||
|
||
```cpp
|
||
// NEW illustrative Void::Coordination shapes; no IO occurs inside Core.
|
||
struct PersistBatch { BarrierId id; DurableStateDelta delta; };
|
||
struct Persisted { BarrierId id; }; // confirms durable persistence, not merely write admission
|
||
struct Tick { SteadyInstant now; ElectionRandomSample election_sample; };
|
||
using Event = Variant<Tick, PeerMessage, Propose, ReadRequest,
|
||
Persisted, PersistenceFailed, Applied, SnapshotInstalled>;
|
||
using Action = Variant<PersistBatch, SendAfterPersist, ApplyCommitted,
|
||
ReadBarrier, RejectProposal, RoleChanged, Fatal>;
|
||
class Core {
|
||
static Result<Core> recover(FixedConfig, RecoveredProtocolState);
|
||
Result<ActionBatch> step(Event);
|
||
};
|
||
```
|
||
|
||
These are shape illustrations, not existing Variant/Result aliases. Binary owns wire
|
||
encoding primitives; Coordination owns versioned term/index/node/message types. Inputs
|
||
own message bytes; emitted actions own or pin their data until acknowledged. Each persist
|
||
action has an increasing barrier ID; only matching successful durable completion releases
|
||
dependent sends/votes/commit acknowledgements. One adapter event loop serializes `step`;
|
||
the core never calls user code or locks an external service. Time progression and election
|
||
random samples are explicit events, allowing byte-for-byte replay of histories.
|
||
|
||
Persisted state includes cluster/group identity, fixed voter list/hash, current term,
|
||
voted-for, indexed log records and snapshot's last-included index/term. Recovery validates
|
||
contiguity, snapshot boundary and monotonic terms before admitting a peer. Commit knowledge
|
||
can be recovered conservatively; applied index is supplied by the application's atomic
|
||
state and must never exceed known recoverable committed history. Contradictions fault the
|
||
group rather than trimming application state to make a test pass.
|
||
|
||
## Required state transitions and algorithms
|
||
|
||
1. Follower election timeout defaults to an injected uniform 300–600 ms; heartbeat 100 ms.
|
||
Deployments tune these from measured persistence/network delay, not from a safety claim.
|
||
Candidate increments term, votes for self and persists before requesting votes. Grant at
|
||
most one vote/term after log freshness check and durable term/vote update. Higher-term
|
||
messages cause step-down and persistence before any dependent reply.
|
||
2. AppendEntries checks previous index/term, rejects mismatch with a conflict hint and
|
||
truncates only an uncommitted conflicting suffix. Never overwrite an applied/committed
|
||
position. Persist suffix/term changes before success response. Duplicate or reordered
|
||
messages cannot regress match/commit indices. Ignore responses from old terms/rounds.
|
||
3. Leader tracks next/match per voter, sends bounded batches and advances commit only when
|
||
a majority match an entry from its current term; preceding entries then become committed.
|
||
New leader appends a no-op for its term. Proposals are not client successes until the
|
||
Replication adapter durably applies the committed command and result. Losing leadership
|
||
rejects uncommitted callers as unknown/not-leader without claiming their writes vanished.
|
||
4. For a consistent read, first commit the current-term entry. Start a fresh read context,
|
||
confirm leadership through current-term responses from a majority after that request,
|
||
record its safe read index and emit a barrier. Reply only when application applied index
|
||
reaches that index. Step-down invalidates pending read contexts. An isolated old leader
|
||
cannot serve linearizable reads from its local data. Explicit stale reads live above core.
|
||
5. Emit apply actions in contiguous committed order, bounded by adapter capacity; require
|
||
Applied(index) acknowledgement before discarding ownership. Core does not execute commands.
|
||
If apply fails, fault/pause the group; never skip an index and acknowledge later writes.
|
||
6. Snapshot messages identify cluster/config/format/index/term and bounded chunks. Core
|
||
validates boundary and requests installation; adapter atomically installs application,
|
||
dedup and applied position, durably records snapshot metadata, then acknowledges. Log
|
||
truncation waits for that durable installation; incomplete snapshots cannot displace active
|
||
state. Retain a suffix only when the included index/term matches.
|
||
|
||
The selected read and durability rules correspond to the paper's stable-state and client
|
||
interaction sections. Detailed defaults and action barriers here are NEW implementation
|
||
decisions, not an assertion that a paper alone verifies this implementation.
|
||
|
||
## Bounds and failure matrix
|
||
|
||
NEW defaults: 1 MiB command, AppendEntries ≤64 entries/2 MiB including envelope metadata,
|
||
4 in-flight batches/follower,
|
||
1,024 proposals and 64 MiB uncommitted payload budget, 256 read contexts, 4,096 queued events
|
||
and 64 MiB queued bytes. Log disk quota belongs to the adapter (initially 1 GiB/group).
|
||
When lag prevents reclamation, reject new proposals; do not remove required history without
|
||
a durable snapshot. Read/proposal deadlines use Async/Time contracts in adapters; expiry
|
||
removes caller interest, not protocol history. Core transitions are bounded by batch size;
|
||
long catch-up/snapshot work yields between chunks. Shutdown is adapter-driven: stop proposals,
|
||
finish persistence barriers and release action ownership only after completion/join.
|
||
|
||
| Fault | Protocol action / forbidden shortcut | Required evidence |
|
||
| --- | --- | --- |
|
||
| Minority partition / old leader | No new committed success or consistent local read | Partition histories with concurrent reads |
|
||
| Crash before vote/append persistence | No dependent success was sent | Crash every barrier boundary |
|
||
| Disk write/sync failure | Fatal/pause; never send a dependent affirmative reply | Inject short write and failed sync |
|
||
| Duplicate/reordered/delayed packets | Term/round/log checks; no state regression | Deterministic message permutations |
|
||
| Divergent uncommitted suffix | Conflict repair; committed prefix untouched | Election with conflicting histories |
|
||
| Snapshot interrupted/corrupt | Keep old state; reject/quarantine candidate | Chunk loss/restart/checksum mutation |
|
||
| Apply failure / state mismatch | Fault group and surface corruption | Applied-index invariant fixtures |
|
||
| Clock stall/jump / election storm | Liveness may stop; no relaxed quorum | Adversarial Tick schedules |
|
||
| Unknown peer/config/version | Reject before core mutation | Cross-cluster/spoofed node messages |
|
||
|
||
## Task DAG and evidence gates
|
||
|
||
| ID | Phase / dependencies | Scope and acceptance | Recommended role |
|
||
| --- | --- | --- | --- |
|
||
| S-COORDINATION-01 | P0; baseline | Write formal invariants, event model and deterministic test harness specification | astra_implementer |
|
||
| S-COORDINATION-02 | P1; S-COORDINATION-01, Binary/Time/Functional contracts | NEW pure types/codec/ports, replay harness; no network/storage/runtime dependency | astra_implementer |
|
||
| S-COORDINATION-03 | P4; S-COORDINATION-02 | Fixed voters, elections, append/commit and persistence barriers; model/simulation safety gate | astra_implementer |
|
||
| S-COORDINATION-04 | P4; S-COORDINATION-03 | Current-term no-op, read contexts and apply barriers; isolated-leader reads fail | astra_implementer |
|
||
| S-COORDINATION-05 | P4; S-COORDINATION-04, snapshot port defined in S-COORDINATION-02 | Snapshot boundary/recovery against a fake port; crash/suffix/corruption tests pass without a Replication dependency | astra_implementer |
|
||
| S-COORDINATION-06 | P4 later; S-COORDINATION-05, integrated fixed-group acceptance | Explicit joint-consensus membership protocol plus learners; separate proof/review and fault gate before any voter edits | astra_implementer |
|
||
|
||
CURRENT: no Coordination targets exist; no consensus execution evidence is claimed.
|
||
PROPOSED verification includes a reference state-machine model, exhaustive bounded schedules,
|
||
seeded randomized simulations, persistent replay artifacts, partitions and crash/recovery.
|
||
Check election safety, log matching, leader completeness, state-machine safety and read
|
||
linearizability on recorded histories. Separate adversarial review is required even when
|
||
tests pass; commands await target creation in [VALIDATION](../VALIDATION.md).
|
||
Measure step p50/p95/p99, actions/second, allocations, RSS/CPU, bytes retained and build
|
||
cost under [PERFORMANCE](../PERFORMANCE.md), not a universal consensus speed claim.
|
||
|
||
Migration versions protocol and persistent formats; mixed unsupported majors refuse peers.
|
||
Fixed membership is immutable after bootstrap. Rollback replays a compatible durable
|
||
format or restores an approved snapshot into a separately identified cluster; never reset
|
||
term/vote in place or reuse a node identity with an empty disk. See [MIGRATION](../MIGRATION.md),
|
||
[BUILD-AND-DISTRIBUTION](../BUILD-AND-DISTRIBUTION.md) and [Replication](Replication.md).
|