Skip to main content

Module controller

Module controller 

Source
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::FetchTimeout and starts an election, as Kafka’s pollFollowerAsVoter does; an observer’s RE-POLLS (SendFetch), and only the configured consecutive misses send it back to leader discovery;
  • the leader re-broadcasts BeginQuorumEpoch to voters each heartbeat tick.

Modules§

checkpoint
The KIP-630 .checkpoint artifacts 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.
KraftConfig
Configuration to build a KraftController.
KraftController
Cheap, cloneable handle to the running engine: holds the command sender and the watch receivers the broker/handle read.

Functions§

control_batch_image_records
The image records one committed control batch carries, in log order: each KIP-853 KRaftVersionRecord as a V1KRaftVersion and each VotersRecord as a V1Voters.
decode_committed_value
Decodes the committed metadata value at offset against image.
is_kip835_noop
Whether value is an empty KIP-835 NoOpRecord: a record that changes nothing, which every replay skips. A NoOpRecord that carries a private tagged field is a krabka record carrier, and it is not one.