Expand description
Versioned metadata records and the immutable image they apply to.
krabka-metadata provides MetadataRecord, the versioned union
of topic, partition, broker-registration, and topic-deletion records, and
MetadataImage, an immutable snapshot of the cluster’s metadata.
Only MetadataImage::apply mutates the image, and the Raft state
machine in krabka-raft calls that method. Everywhere else reads it
through shared references and Arc clones.
§Applying controller records
use krabka_metadata::{MetadataImage, MetadataRecord, TopicRecord};
use uuid::Uuid;
let mut image = MetadataImage::new(Uuid::new_v4());
let topic_id = Uuid::new_v4();
image.apply(&MetadataRecord::V1Topic(TopicRecord {
name: "orders".into(),
topic_id,
partitions: 0,
replication_factor: 3,
}));
let topic = image.topic("orders").expect("topic exists");
assert_eq!(topic.topic_id, topic_id);§Canonical quota entity keys
use krabka_metadata::canonicalize_entity;
let key = canonicalize_entity(vec![
("user".to_string(), Some("alice".to_string())),
("client-id".to_string(), Some("analytics".to_string())),
]);
assert_eq!(key[0].0, "client-id");
assert_eq!(key[1].0, "user");Re-exports§
pub use acl::AclEntry;pub use acl::AclEntryFilter;pub use acl::AclOperation;pub use acl::PatternType;pub use acl::PermissionType;pub use acl::ResourceType;pub use break_glass::BreakGlassAction;pub use break_glass::BreakGlassApproval;pub use break_glass::BreakGlassProposalRecord;pub use kafka_record::KafkaRecordError;pub use kafka_record::from_kafka_record;pub use kafka_record::to_kafka_record;pub use krabka_version::KrabkaVersion;pub use krabka_version::PrivateRpc;pub use krabka_version::private_rpc_version;pub use kraft_translate::PRIVATE_RECORD_VERSION;pub use kraft_translate::TranslateError;pub use kraft_translate::from_kraft;pub use kraft_translate::from_kraft_value;pub use kraft_translate::to_kraft;pub use kraft_translate::to_kraft_records;pub use kraft_translate::to_kraft_values;pub use write_freeze::TopicFreezeRecord;pub use krabka_voters as voters;
Modules§
- acl
- Wire-stable ACL types replicated through the raft quorum
with
MetadataRecord::V1AccessControlEntryandV1DeleteAccessControlEntry. They mirror the shape that Kafka exposes on theCreateAcls,DeleteAcls, andDescribeAclswire messages, but they stay pure data. The authorizer inkrabka-brokerevaluates them. - break_
glass - Break-glass proposal records, replicated through the raft quorum with
MetadataRecord::V1BreakGlassProposalandV1DeleteBreakGlassProposal. - directory_
id - KIP-858 reserved log-directory ids, transcribed from Kafka’s
org.apache.kafka.common.DirectoryId. - group_
version - KIP-848
group.versionfeature-level constants. It is a plain integer feature with noX.Y-IVnstring table: level 0 means classic consumer groups only, and level 1 means next-gen (KIP-848) protocol GA. The range and the metadata.version bootstrap-default threshold are pinned against the cp-kafka 4.0GroupVersionenum, verified empirically 2026-05-30. - kafka_
record - Bridge between
MetadataRecordand a KafkaRecordwhose value is the wincode encoding of the record. - krabka_
version - The krabka-owned
krabka.versionfeature (KIP-584). - kraft_
translate - Translate Krabka’s internal
MetadataRecordcurrency to and from the KIP-631KraftMetadataRecordwire shape, so the controller log and snapshots are genuinely KIP-631-framed. - metadata_
version - KIP-778
metadata.versionfeature-level model. The canonical string<->integer-level table, mirrored byte-for-byte from upstream Kafka’sMetadataVersionenum over the range Krabka advertises ([METADATA_VERSION_MIN, METADATA_VERSION_MAX]). JVM clients callMetadataVersion.fromFeatureLevel(N)and throw on any level their enum does not know, so the levels andX.Y-IVnnames here MUST match upstream exactly. Verify againstMetadataVersion.javain Kafka’sserver-commonmodule on trunk before editing: levels are never reused, so the table must carry every level up toMETADATA_VERSION_MAX, reserved ones included. - transaction_
version - KIP-890
transaction.versionfeature-level constants, matching Kafka’sTransactionVersion, which definesTV_0toTV_2only. 0 means classic (KIP-98) non-flexible txn-state records, 1 means flexible (tagged) txn-state records, and 2 means an epoch bump on completion plus server-sideAddPartitionsToTxnverification. BothTV_1andTV_2bootstrap at 4.0-IV2. - write_
freeze - Topic write-freeze registry entries, replicated through the raft quorum
with
MetadataRecord::V1TopicFreeze.
Structs§
- Broker
Config Record - Per-broker configuration key/value pair.
Some(value)= set;None= delete. - Broker
Endpoint - A single named listener endpoint advertised by a broker. It is stored as a
list on
BrokerRegistrationRecord::endpoints, so KRaft-style metadata can advertise per-listenerhost:portand protocol triples to clients onMetadatav9+. A legacy single-listener broker leaves the list empty and relies on the top-levelhostandportfields. - Broker
Registration Change Record - Kafka’s
BrokerRegistrationChangeRecord(metadata apiKey 17): a delta on the registration of one broker. - Broker
Registration Record - Client
Metrics Config Record - KIP-714 client-metrics subscription config. Authoritative target
state: each
V1ClientMetricsConfigfully replaces the previous override map forname, the subscription name. An empty map deletes the subscription. TheIncrementalAlterConfigshandler merges before it submits the record, in the same pattern asTopicConfigRecord. - Client
Quota Record - Controller
Registration Record - KIP-919 controller registration persisted in the metadata log.
- Delegation
Token - In-memory image type for a single delegation
token (KIP-48). Mirrors
DelegationTokenRecordwithout any tombstone concerns. The apply path handles tombstones as removals. - Delegation
Token Record - A single delegation token’s authoritative state (KIP-48).
The record has replacement semantics: a new record with the same
token_idoverwrites the prior one in the image. Both Create and Renew use that. Removal goes throughDeleteDelegationTokenRecord. - Delete
Delegation Token Record - Tombstone record that removes a delegation token (KIP-48)
from the image. The
ExpireDelegationTokenhandlers and the background expiry sweep emit it. - Delete
Scram Credential Record - Delete
Topic Record - Feature
Level Record - KIP-584 finalized feature level.
levelis the finalizedmax_version_levelforname.level == 0is the KIP-584 sentinel for “delete this finalized feature”:MetadataImage::applyremoves the entry and does not store a zero. Replacement semantics: a later record with the samenameoverwrites the previous level. - Features
Epoch Record - Snapshot-only carrier for the KIP-584 finalized-features epoch.
- Group
Config Record - KIP-1071 dynamic configuration for one group resource. Each record is the
authoritative override map for
group_id; an empty map clears the resource. - KRaft
Version Range - Supported kraft.version range for a voter. The range is inclusive.
- KRaft
Version Record - KIP-853: finalizes the cluster-wide kraft.version feature level.
- Leader
Epoch - A partition leader epoch. KIP-320 wire type:
int32. - Metadata
Image - NodeId
- A broker or controller node id: the canonical
krabka_ids::NodeIdnewtype, which is au64internally and Kafka’sint32on the wire. - Partition
DirAssignment Record - KIP-858 directory-assignment delta. A broker reports which log-dir UUID
hosts its replica of
(topic, partition). Apply treats it as a DELTA: it sets ONLY the slot of the reporting replica inPartitionRecord.directoriesand never touches leader, isr, replicas, adding, or removing. It therefore cannot clobber a concurrent reassignment or ISR change. On theKRaftlog it is encoded as Kafka’s standardPartitionChangeRecordwith only the directories field set. - Partition
ElrRecord - KIP-966 eligible-leader state for one partition. Empty vectors clear it.
- Partition
Offset Advance Record - Diskless offset-sequencer delta: advance a partition’s committed
next-offset by
count. - Partition
Record - Partition
Recovery Record - Partition
Update Record - A Kafka
PartitionChangeRecordcan carry assignment, ELR, and recovery changes together. This record preserves that atomic update on replay. - Producer
IdsRecord - Durable controller state for cluster-wide producer-ID block allocation.
next_producer_idis the first ID not covered by any committed block. - Quota
Entity - Scram
Credential Record - Topic
Config Record - Mutable topic configuration overrides. Authoritative target state:
each
V1TopicConfigrecord fully replaces the previous override map fortopic. An empty map clears all overrides. TheAlterConfigshandler merges before it submits the record. - Topic
Record - Unregister
Broker Record - KIP-919 /
UnregisterBroker(api_key64), Kafka’sUnregisterBrokerRecord(metadata apiKey 1). Marks a broker as permanently unregistered: the admin operator confirms that the broker is gone for good and asks the cluster to drop its registration entry from the metadata image. LaterMetadataresponses no longer advertise the endpoints of the broker, and clients stop routing to it. - Unregister
Controller Record - KIP-1312
UnregisterController(api_key94), Kafka trunk’sUnregisterControllerRecord(metadata apiKey 29). Removes the registration of one controller. An apply against an unknownnode_iddoes nothing. - Voter
- One voter’s full identity.
- Voter
Endpoint - A single listener endpoint advertised by a voter.
- Voter
Set - The authoritative voter set, ordered by node id.
- Voters
Record - KIP-853: full snapshot of the controller voter set.
Enums§
- Fencing
Change - A change to the fencing state of a broker registration, as Kafka’s
BrokerRegistrationFencingChangeencodes it inBrokerRegistrationChangeRecord.Fenced. - Leader
Recovery State - KIP-704 state of an uncleanly elected leader.
- Metadata
Error - Metadata
Record - Throttle
Kind - Selects which broker byte-rate config key to read.
Constants§
- DEFAULT_
BROKER_ CONFIG_ NODE_ ID - Internal identity for Kafka’s cluster-wide default broker-config resource. Broker IDs are non-negative signed 32-bit integers on the Kafka wire, so this value cannot collide with a real broker.
Traits§
- Feature
- One versioned cluster feature (KIP-584).
Functions§
- bootstrap_
feature_ records - KIP-584/1022 bootstrap: one
V1FeatureLevelrecord per registered feature at its per-release default, derived frombootstrap_mv, the bootstrap metadata.version level. Bothkrabka formatand the broker’s standalone self-bootstrap use this, so a fresh cluster finalizes the release default of every feature. - bootstrap_
feature_ records_ with_ overrides - KIP-1022
krabka formatseeding: oneV1FeatureLevelrecord per registered feature, each at its explicit--feature NAME=LEVELoverride if present inoverrides, else its per-release default forbootstrap_mv. - canonicalize_
entity - feature
- Look up a registered feature by name.
- feature_
registry - All features this broker supports finalizing. Single source of truth.
- is_
supported_ level - True if
levelis within the registered feature’s supported range.falsefor an unknown feature (nothing supports that level). - supported_
feature_ ranges - Supported feature ranges advertised by a Krabka broker or controller when
it registers with the
KRaftcontroller. - validate_
feature_ dependencies - KIP-1022 dependency validation for a fully-resolved feature→level map, as
seeded by
krabka format. For every finalized feature, each of itsdependencies(level)must be present inresolvedat>=the required level. ReturnsErrwith the name of the first unmet dependency, enforcing the rule at format time in the same way as theUpdateFeatureshandler.