Expand description
The async KraftController consensus engine.
A single owning tokio task holds all consensus state (the QuorumStateMachine core, the
KraftLog, and the published MetadataImage) and turns inbound
commands/RPCs into core Events whose Actions it executes.
Ownership model: one task owns the Engine; everything else talks to it
over an mpsc of Command. The public KraftController handle is a
cheap clone holding the command sender plus the watch receivers. This is
a single-owner actor pattern; the engine is entirely ours.
§Concurrency / no-inline-await invariant
The loop is single-threaded over all consensus state, so it never blocks on
a peer RPC. Each Send* Action is dispatched fire-and-forget: a
[tokio::spawn]ed task calls PeerSender::send, decodes the response
body into the matching Receive*Response Event, and posts it back to
the loop via a clone of the command sender. This is critical for the
in-process multi-node sim, where engines RPC each other reciprocally — a
loop that awaited a send inline would deadlock.
§Timers & liveness
The loop drives a real monotonic clock and select!s over the mpsc plus an
election timer, a fetch timer, and a leader heartbeat interval:
- on a role transition the now-irrelevant timer is cancelled (a follower has no election timer; a leader has no fetch timer and runs the heartbeat);
- a voter’s fetch-timer expiry feeds
Event::FetchTimeoutand starts an election, as Kafka’spollFollowerAsVoterdoes; an observer’s RE-POLLS (SendFetch), and only the configured consecutive misses send it back to leader discovery; - the leader re-broadcasts
BeginQuorumEpochto voters each heartbeat tick.
Modules§
- checkpoint
- The KIP-630
.checkpointartifacts under a node’s metadata directory.
Structs§
- Activation
- What a new leader of an empty metadata log writes: the inputs of Kafka’s
ActivationRecordsGenerator.recordsForEmptyLog. - Kraft
Config - Configuration to build a
KraftController. - Kraft
Controller - Cheap, cloneable handle to the running engine: holds the command sender and
the
watchreceivers the broker/handle read.
Functions§
- control_
batch_ image_ records - The image records one committed control batch carries, in log order: each
KIP-853
KRaftVersionRecordas aV1KRaftVersionand eachVotersRecordas aV1Voters. - decode_
committed_ value - Decodes the committed metadata value at
offsetagainstimage. - is_
kip835_ noop - Whether
valueis an empty KIP-835NoOpRecord: a record that changes nothing, which every replay skips. ANoOpRecordthat carries a private tagged field is a krabka record carrier, and it is not one.