Expand description
Metadata Raft quorum for Krabka.
krabka-raft runs a hand-rolled KIP-595 KRaft consensus engine, the
kraft::KraftController, over Krabka’s storage (krabka_log) and
transport ([krabka_client_core]). The public entry point is
Controller::start. It spawns the engine and opens a TCP listener. That
listener serves the real KIP-595 RPCs (Fetch=1, Vote=52,
BeginQuorumEpoch=53, EndQuorumEpoch=54) and the Krabka-private observer and
forward RPCs. Controller::start returns a ControllerHandle, which
submits metadata changes and reads the current
krabka_metadata::MetadataImage.
§Quick start
use {
krabka_metadata::{MetadataRecord, TopicRecord},
krabka_raft::{Controller, ControllerConfig, NodeId},
std::time::Duration,
uuid::Uuid,
};
let dir = tempfile::tempdir()?;
let cfg = ControllerConfig::for_tests(NodeId(1), dir.path().to_path_buf());
let controller = Controller::start(cfg).await?;
controller
.submit_change(vec![MetadataRecord::V1Topic(TopicRecord {
name: "my-topic".into(),
topic_id: Uuid::new_v4(),
partitions: 3,
replication_factor: 1,
})])
.await?;
assert2::assert!(controller.current_image().topic("my-topic").is_some());
controller.shutdown().await;§Capabilities and boundaries
The controller persists and recovers KRaft metadata records, and it serves
and installs KIP-630 snapshots through FetchSnapshot. It also publishes
the current metadata image to broker tasks and exposes Krabka-private submit
and fetch RPCs for broker and observer integration.
KIP-853-style observer bootstrap and auto-join are wired through the broker
and controller configuration. ControllerHandle::add_learner stages a
node identity; ControllerHandle::change_membership reconciles a
one-voter delta into add_voter or remove_voter.
Mixed JVM and Krabka controller quorums are outside this crate’s
compatibility target.
Re-exports§
pub use event_queue::EventQueueRecorder;pub use event_queue::NoEventQueueRecorder;pub use handshake::AllowAllGrants;pub use handshake::ClusterGrants;pub use handshake::ClusterOperation;pub use handshake::ControllerApiVersions;pub use handshake::HandshakeStream;pub use handshake::RaftConnection;pub use handshake::RaftHandshakeError;pub use handshake::RaftListenerHandshake;pub use kraft::MetadataFetchSlice;pub use kraft::controller::control_batch_image_records;pub use kraft::controller::decode_committed_value;pub use kraft::controller::is_kip835_noop;pub use reconfig::AddVoter;pub use reconfig::ReconfigOutcome;pub use reconfig::RemoveVoter;pub use reconfig::UpdateVoter;
Modules§
- event_
queue - The controller’s event-queue measurements.
- handshake
- Pluggable inbound handshake for the controller listener.
- kraft
- Hand-rolled
KRaftconsensus engine (KIP-595 and KIP-996). - reconfig
- KIP-853 requests submitted to the single-owner Raft engine.
- voter_
requests - The KIP-853 request checks that
AddRaftVoter,RemoveRaftVoterandUpdateRaftVotershare on the controller listener and on the broker listener, with Kafka’s codes, order and messages.
Structs§
- Accepting
Listener - The listener an accept arrived on.
- AppData
- What the controller asks Raft to replicate.
- AppData
Response - Connection
Guard - RAII release for one accepted connection.
- Connection
Limiter - Live-connection accounting for one node’s listeners. A clone shares the
same counters, so every accept loop and every
ConnectionGuardaccount against one set of totals. - Connection
Limits - The two caps a node is started with.
usize::MAXmeans unlimited. - Connection
Quota Settings - The quotas in force for one listener, before the hosts of
max.connections.per.ip.overridesare resolved. - Connection
Quotas - The quotas one accept is checked against: the settings in force and the resolved override addresses.
- Controller
- Zero-sized factory for
ControllerHandles. - Controller
Admin Request - Authenticated request handed from the controller listener to the broker’s existing Admin handler registry.
- Controller
Admin Response - Encoded Kafka response body plus its response-header shape.
- Controller
ApiVersion - One Kafka API version range served by a controller-listener Admin router.
- Controller
Config - Controller
Fetch Miss Limit - The number of consecutive fetch misses a controller tolerates.
- Controller
Handle - Handle returned by
Controller::start. - Krabka
Metadata Fetch Request - Krabka
Metadata Fetch Response - Krabka
Submit Change Request - Forward-to-leader payload.
- Krabka
Submit Change Response - Listener
Limits - The limits Kafka’s
SocketServerputs on every listener, including the controller’s. - Metadata
LogConfig - How the metadata log rolls its segments and when it gives up the prefix that a snapshot covers. The defaults are Kafka’s.
- Metadata
Raft Command Queue Capacity - The capacity of the metadata Raft command queue.
- Metadata
Raft Fetch Max - The most bytes one metadata Raft fetch carries, a whole byte count that
fits the protocol’s
int32field. - Node
- KIP-853 voter node identity used by controller membership.
- NodeId
- A broker, node, replica, or controller identifier.
- Observed
Stream - A stream that reads and writes through
innerand showsobserverevery poll. - Offset
Reservation - Plaintext
Dialer - Default no-op dialer: it opens a raw
TcpStreamwithConnection::connect. - Quorum
State - Krabka-native view of the controller’s current quorum state.
- Quorum
State Snapshot - A structured, node-local snapshot of consensus state for the handle, which
serves the broker’s
DescribeQuorumadmin view. - Released
Api - One Kafka 4.3.1 request schema: its api key and the versions the release accepts by default.
- Snapshot
Slice - A contiguous byte window of the latest metadata
.checkpoint, returned byControllerHandle::read_snapshot_range. - Submit
Change Result
Enums§
- Bootstrap
Mode - Bootstrap orchestration for a freshly-formatted controller node.
- Connection
Limit - The connection ceiling that refused an inbound connection.
- Delegation
Token Mutation - A token mutation bound to the exact committed record observed by its caller.
- Metadata
Replay Error - A committed metadata log record that a controller cannot replay.
- Persisted
Format Error - What is wrong with a node-local file whose layout carries a version
marker.
RaftError::PersistedFormatnames the file. - Raft
Error - Snapshot
Range - Outcome of
ControllerHandle::read_snapshot_range. - Unstable
ApiVersions - Whether a listener advertises and accepts what Kafka trunk serves beyond the latest Kafka release.
- Unstable
Feature Versions - Whether a node supports feature levels past the latest production ones.
Constants§
- API_
KEY_ DELEGATION_ TOKEN_ MUTATION - Generation-bound delegation-token mutation forwarded to the leader.
- API_
KEY_ METADATA_ FETCH - Observer metadata fetch.
- API_
KEY_ SUBMIT_ CHANGE - Forwards a
Controller::submit_changefrom a follower to the leader. - DEFAULT_
METADATA_ LOG_ SEGMENT_ ROLL_ INTERVAL metadata.log.segment.msdefault: seven days.- DEFAULT_
METADATA_ LOG_ SEGMENT_ SIZE metadata.log.segment.bytesdefault: 1 GiB.- DEFAULT_
METADATA_ MAX_ IDLE_ INTERVAL metadata.max.idle.interval.msdefault: 500 ms.- DEFAULT_
METADATA_ MAX_ RETENTION metadata.max.retention.msdefault: seven days.- DEFAULT_
METADATA_ MAX_ RETENTION_ SIZE metadata.max.retention.bytesdefault: 100 MiB.- KAFKA_
4_ 3_ 1_ APIS - Every api key Kafka 4.3.1 has a valid version of, in key order.
- LATEST_
PRODUCTION_ METADATA_ VERSION - Kafka 4.3’s
MetadataVersion.LATEST_PRODUCTION,4.3-IV0. - MAX_
CONNECTIONS - Kafka’s
SocketServerConfigs.MAX_CONNECTIONS_CONFIG. - MAX_
CONNECTIONS_ PER_ IP - Kafka’s
SocketServerConfigs.MAX_CONNECTIONS_PER_IP_CONFIG. - MAX_
CONNECTIONS_ PER_ IP_ OVERRIDES - Kafka’s
SocketServerConfigs.MAX_CONNECTIONS_PER_IP_OVERRIDES_CONFIG. - MAX_
CONNECTION_ CREATION_ RATE - Kafka’s
SocketServerConfigs.MAX_CONNECTION_CREATION_RATE_CONFIG. - METADATA_
PARTITION_ DIR - The name of the metadata partition’s directory under the metadata log
directory: Kafka’s
UnifiedLog.logDirNameof__cluster_metadata-0. - MIN_
METADATA_ LOG_ SEGMENT_ SIZE - The least
metadata.log.segment.bytesKafka accepts: 8 MiB. Kafka’sConfigDefrefuses a smaller value, and only its internalinternal.metadata.log.segment.bytesgoes below it, for tests. - PRIVATE_
BASELINE_ VERSION - The version of every krabka-private API that a sender uses when it has no
metadata image to read
krabka.versionfrom: v0, the krabka-broker 1.0.0 formats, which every 1.x receiver serves. - PRIVATE_
CLUSTER_ AUTHORIZATION_ FAILED - The
error_codeof a krabka-private response when the connection principal lacksClusterActionon the cluster. It is Kafka’sCLUSTER_AUTHORIZATION_FAILED. - PRIVATE_
UNSUPPORTED_ VERSION - The
error_codeof a krabka-private response to a request at a version the receiver does not implement. It is Kafka’sUNSUPPORTED_VERSION. - SUBMIT_
CHANGE_ UNCOMMITTED_ TAIL KrabkaSubmitChangeResponse::error_code: the leader refused a compare-and-set until its uncommitted tail commits. The forwarding node turns it back intocrate::RaftError::UncommittedTail.
Traits§
- Controller
Admin Router - Optional KIP-919 Admin RPC surface attached by the broker crate.
- Outbound
Dialer - Outbound dialer the controller hands to the peer sender.
- Raft
Shard Router - Classifies and serves shard-addressed KIP-595 requests before metadata dispatch.
- Registration
Admission - What the broker crate does to a batch that registers a broker anew, before the leader appends it.
- Stream
Observer - What an
ObservedStreamreports to.
Functions§
- api_
versions_ max_ version - Highest
ApiVersionsversion a listener serves underunstable. - describe_
quorum - Answers a decoded
DescribeQuorumrequest fromquorum, this node’s consensus snapshot. - deserialize_
metadata_ snapshot - Decode the KIP-630 metadata records from a Kafka metadata snapshot.
- deserialize_
metadata_ snapshot_ image - Decode the whole image a Kafka metadata snapshot holds: its KIP-853 quorum
controls, as a
V1KRaftVersionand aV1Votersrecord, ahead of its KIP-630 metadata records. - fetch_
error_ response - Kafka’s
FetchRequest.getErrorResponse:error_codeand the session id ofrequestat the top level. - finalized_
feature_ keys - The finalized-feature rows of
image, in name order: every finalized level above 0,metadata.versionat Kafka’s minimum before the first feature delta, andkraft.versionwhen its level is above 0. - is_
valid_ api_ versions_ request - Kafka’s
ApiVersionsRequest.isValid. - is_
valid_ client_ info - KIP-511 client-information validity check. Matches the JVM
ApiVersionsRequest.isValidregex[a-zA-Z0-9](?:[a-zA-Z0-9\-.]*[a-zA-Z0-9])?: - kafka_
4_ 3_ 1_ api - The Kafka 4.3.1 row for
api_key, orNonewhen that release has no such api key. - kafka_
4_ 3_ 1_ max - The highest version of
api_keyKafka 4.3.1 accepts by default, orNonewhen that release has no such api key. - metadata_
log_ nonempty - True when the metadata partition directory
diralready holds durable raft state, which a node that ran before leaves. A quorum-state file or a log segment that holds bytes is such state. - metadata_
partition_ dir - The metadata partition directory under
metadata_log_dir, Kafka’smetadata.log.dir. It holds the metadata log segments, the KIP-630<end_offset>-<epoch>.checkpointsnapshots and thequorum-statefile. - metadata_
snapshot_ last_ contained_ log_ timestamp - Read the append timestamp of the last record batch contained in a KIP-630 metadata snapshot.
- private_
api_ highest_ version - The highest version of the krabka-private
api_keythis build serves, orNonewhenapi_keyis not one of them. - private_
request_ version - The version of
rpca sender puts in the request header, negotiated fromimage, the sender’s current metadata image. - serialize_
bootstrap_ snapshot - Serialize the bootstrap checkpoint of a dynamic format, as Kafka’s
Formatter.writeBoostrapSnapshotwrites it: the KIP-853kraft.versionand voter set, then the bootstrap records in their own order. - serialize_
metadata_ snapshot - Serialize a Kafka metadata snapshot, including KIP-853 control state.
- supported_
feature_ key - The supported-feature row for one feature at
api_version, orNonewhen Kafka leaves the feature out of the response. - supported_
feature_ keys - Every supported-feature row of the
krabka_metadatafeature registry atapi_version, each feature capped asunstablecaps it (crate::supported_feature_range). - supported_
feature_ range - The supported range of
featureunderunstable. - supported_
feature_ ranges - The feature ranges a node registers with the controller under
unstable. - unsupported_
version_ response - Kafka’s
ApiVersionsRequest.getErrorResponseforUNSUPPORTED_VERSION(KIP-511).
Type Aliases§
- Controller
Admin Route Future - IpOverrides
- The cap of each override address.
- Registration
Admission Future - The batch
RegistrationAdmission::admitanswers with. - Shard
Route Future - Optional router for KIP-595 traffic addressed to non-metadata quorum shards.