Expand description
crafty-core — the pure Raft consensus state machine (no I/O).
RaftNode drives leader election and log replication deterministically:
it consumes events and returns Output effects for an outer runtime to
execute (architecture-style). Because it performs no I/O and derives all randomness
from a seed, an entire cluster can be simulated reproducibly (testing-strategy).
Joint-consensus membership (membership-early), ReadIndex (read-consistency), and snapshots
build on this foundation in later increments.
Re-exports§
pub use crafty_proto as proto;
Structs§
- AckWindow
Liveness - Per-peer latched reachability with ack-window + hysteresis.
- Catalog
Expansion Plan - Plan for appending contiguous Raft groups to the catalog (Tier 2).
- Committed
- A committed application command ready to apply to the state machine.
- Compaction
Policy - When the runtime should automatically compact the Raft log.
- Compaction
Stats - Observed log retention relative to the last snapshot.
- Config
- Timing and determinism configuration, in logical ticks.
- Group
Membership Change - Per-group membership delta between a committed and desired voter set.
- Group
Rebalance Plan - Local rebalance actions for one physical node (multi-Raft control plane).
- Group
Replication Target - Desired voters + learners for one group.
- NotLeader
- Returned by
RaftNode::propose/RaftNode::read_indexwhen the node is not the leader. - Persist
- A batch of durable state changes an outer runtime must fsync before
acting on any network effect drained from the same step (Raft §5.1–§5.3):
a follower persists appended entries before ack’ing them, and a node
persists its term/vote before replying to a vote. Produced by
RaftNode::take_persist; it is the delta since the previous call. - PhiAccrual
Detector - Phi-accrual failure detector for one peer (Haystack-style, tick time base).
- PhiAccrual
Liveness - Per-peer phi detectors for all voters.
- Raft
Group Id - Identifies one of the cluster’s independent Raft groups (multi-Raft).
- Raft
Node - A single Raft participant: a deterministic, I/O-free state machine.
- Reachability
Config - Tunable reachability parameters (logical ticks).
- ReadId
- Client-supplied token identifying a linearizable read request (read-consistency).
- Shard
Count Expansion Plan - Plan for expanding the active shard keyspace (Tier 1).
- ShardId
- A partition of the keyspace. Fixed count per cluster; each shard is owned by exactly one Raft group at a time.
- Shard
Router - Maps application keys onto a fixed number of shards with a stable hash.
- Shard
Routing Switch Plan - Operator plan for switching keyed routing from modulus to stable virtual.
- Snapshot
State - A read-only view of this node’s most recent snapshot (Raft §7): its
boundary
(term, index), the configuration in effect there, and the opaque application bytes. Returned byRaftNode::stored_snapshotso a runtime can persist the snapshot durably and purge the compacted log prefix (backlog A6), and fed back toRaftNode::restore_with_snapshoton restart. - Stable
Shard Activation Plan - Plan for activating more virtual shards without remapping existing keys.
- Stable
Shard Router - Router over a fixed virtual space with a tunable active prefix (Tier 2).
- TwoPhase
Plan - Client-coordinated cross-shard 2PC plan.
- TwoPhase
Step - One keyed prepare step in a cross-shard 2PC plan.
Enums§
- Catalog
Error - Invalid multi-Raft group catalog.
- Catalog
Propose Error - Why a catalog metadata change could not be started.
- Failure
Detector Kind - Which algorithm derives per-peer reachability on the leader.
- Membership
Error - Why a membership change could not be started.
- Output
- An effect produced by the core for the runtime to execute.
- Role
- The role a node currently plays in its term.
- Shard
Expansion Error - Why a shard-count expansion request was rejected.
- Shard
Routing Kind - How keyed traffic maps into the virtual shard space (Tier 1 vs Tier 2).
- Shard
Routing Switch Error - Why a Tier 1 → Tier 2 routing switch was rejected.
- Stable
Shard Activation Error - Why stable shard activation was rejected.
- TwoPhase
Plan Error - Why a
TwoPhasePlanfails validation.
Constants§
- DEFAULT_
COMPACT_ BYTES - Default retained applied log bytes before auto-compaction (~4 MiB).
- DEFAULT_
COMPACT_ ENTRIES - Default retained applied entries before auto-compaction (Tier 1 ops).
- DEFAULT_
GROUP_ LEARNER_ FACTOR - Default non-voting learner replicas per group beyond voters (Tier 1).
0disables. - DEFAULT_
GROUP_ REPLICATION_ FACTOR - Default replication factor for per-group voter sets (per-group-raft-membership).
- MAX_
VIRTUAL_ SHARDS - Upper bound for
ShardRouteractive shard counts (Tier 1 expansion). - META_
RAFT_ GROUP_ ID - Reserved Raft group id for the cluster coordinator (Meta-Raft).
- TWO_
PHASE_ DEFAULT_ PREPARE_ TIMEOUT_ MS - Default prepare staging timeout (5 minutes) for durable 2PC garbage collection.
- TWO_
PHASE_ MAX_ GROUPS - Maximum distinct Raft groups in one 2PC transaction.
- TWO_
PHASE_ MAX_ PAYLOAD - Maximum encoded command payload per step.
- TWO_
PHASE_ MAX_ STEPS - Maximum steps in one 2PC transaction.
Traits§
- Command
- A replicated command applied to the
StateMachine. - Query
- A read-only query served by the
StateMachine. - State
Machine - The user-defined, deterministic application state machine (state-machine).
Functions§
- compaction_
stats - Collect compaction stats from a live node view.
- effective_
replication_ factor - Clamp
replication_factorto[1, live_count]. Returns0whenlive_count == 0. - entry_
estimated_ bytes - Rough on-disk size of one log entry for byte-threshold policy.
- group_
host_ assignment - Full assignment of each Raft group to a host node over
nodes. - group_
learners - Desired learner set for one Raft group: live nodes ranked after the voter
set, up to
learner_factornodes (Tier 1 per-group-raft-membership). - group_
membership_ assignment - Full desired voter assignment for every group in
groups(per-group-raft-membership). - group_
voters - Desired voter set for one Raft group: the top
effective_replication_factorlive nodes by rendezvous weight forgroup, sorted byNodeId(per-group-raft-membership). - groups_
joining_ node_ affects - Groups whose desired voter set gains
nodewhen the live set grows fromlive_nodes_beforetolive_nodes_after(cluster join). - groups_
leaving_ node_ affects - Groups whose desired voter set loses
nodewhen it departs the live set (cluster leave). - is_
meta_ raft_ group - Whether
groupis the Meta-Raft coordinator group. - node_
should_ host_ group - Whether
node_idshould run a local replica forgroup(voter or learner). - place_
shard - The Raft group that owns
shard, chosen by rendezvous (highest-random-weight) hashing: the group maximizingmix64(shard, group). ReturnsNoneonly whengroupsis empty. Deterministic given the same group set, and stable under group churn — removing the winning group promotes the next-highest weight, leaving all other shards’ owners unchanged. - plan_
catalog_ expansion - Plan appending
add_groupscontiguous ids after the current catalog tail. - plan_
group_ membership_ change - Diff
current_votersagainstdesired_voters(sorted inputs not required). - plan_
group_ membership_ sync - Groups whose desired voter/learner sets differ from
current(per-group-raft-membership). Skips the Meta-Raft coordinator — its membership is managed by/cluster/joinand/cluster/leave. - plan_
node_ group_ rebalance - Diff the groups
node_idcurrently hosts against groups where it belongs in the desired voter or learner set (per-group-raft-membership). - plan_
shard_ count_ expansion - Plan a shard-count increase. Shrinking is rejected — pick a larger
MAX_VIRTUAL_SHARDSup front or migrate data explicitly. - plan_
stable_ shard_ activation - Plan increasing the active virtual shard prefix (Tier 2 stable expansion).
- plan_
switch_ to_ stable_ routing - Validate switching from Tier 1 modulus to Tier 2 stable virtual routing.
- shard_
is_ active - Whether
shardis routable givenactive_countactive virtual shards. - should_
compact - Whether
policysays the runtime should runRaftNode::compactnow. - stable_
router_ preserves_ routable_ keys - After growing the active prefix, keys that were already routable keep the same virtual shard id.
- validate_
catalog - Validate a multi-Raft user group catalog (contiguous ids
0..=max). - validate_
two_ phase_ plan - Validate a cross-shard 2PC plan before issuing prepare calls.
- virtual_
shard_ for - Map
keyto a fixed virtual shard in[0, [``MAX_VIRTUAL_SHARDS``]). UnlikeShardRouter::shard_for, this id never changes when the active prefix grows ([tier2-multi-raft-architecture]).