Expand description
Versioned metadata records and the immutable image they apply to.
crabka-metadata provides MetadataRecord (the versioned union
of topic / partition / broker registrations / topic deletions) and
MetadataImage (an immutable snapshot of the cluster’s metadata).
The image is mutated only by MetadataImage::apply called from
the Raft state machine in crabka-raft. Everywhere else it’s read
via shared references and Arc clones.
§Applying controller records
use crabka_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 crabka_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 kafka_record::KafkaRecordError;pub use kafka_record::from_kafka_record;pub use kafka_record::to_kafka_record;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 voters::KRaftVersionRange;pub use voters::Voter;pub use voters::VoterEndpoint;pub use voters::VoterSet;
Modules§
- acl
- Wire-stable ACL types replicated through the raft quorum
via
MetadataRecord::V1AccessControlEntry/V1DeleteAccessControlEntry. Mirrors the shape Kafka exposes on theCreateAcls/DeleteAcls/DescribeAclswire messages, but stays pure data — the authorizer incrabka-brokerevaluates these. - group_
version - KIP-848
group.versionfeature-level constants. A plain integer feature (noX.Y-IVnstring table): level 0 = classic consumer groups only, level 1 = next-gen (KIP-848) protocol GA. Range + the metadata.version bootstrap-default threshold are pinned against the cp-kafka 4.0GroupVersionenum (verified empirically 2026-05-30). - kafka_
record - Bridge between
MetadataRecordand the KafkaRecordwire type. - kraft_
translate - Translate Crabka’s internal
MetadataRecordcurrency to/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 Crabka advertises ([METADATA_VERSION_MIN, METADATA_VERSION_MAX]). JVM clients callMetadataVersion.fromFeatureLevel(N)and throw on any level their enum doesn’t know, so the levels andX.Y-IVnnames here MUST match upstream exactly. Verify against the cp-kafka 4.0 enum before editing. - transaction_
version - KIP-890
transaction.versionfeature-level constants. Plain integer feature: 0 = classic (KIP-98) non-flexible txn-state records; 1 = flexible (tagged) txn-state records; 2 = epoch-bump-on-completion + server-sideAddPartitionsToTxnverification. Range + the metadata.version bootstrap threshold are pinned against the cp-kafka 4.0TransactionVersionenum (verified empirically 2026-05-30; bothTV_1andTV_2bootstrap at 4.0-IV2). - voters
- KIP-853 voter set value types: a voter is (id, directory-id, endpoints, kraft.version range).
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. Stored as a
list on
BrokerRegistrationRecord::endpointsso KRaft-style metadata can advertise per-listenerhost:port/protocol triples to clients onMetadatav9+. Legacy single-listener brokers leave the list empty and rely on the top-levelhost+portfields. - 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). Empty map = delete the subscription. Merging happens at theIncrementalAlterConfigshandler before the record is submitted (same pattern asTopicConfigRecord). - Client
Quota Record - Delegation
Token - In-memory image type for a single delegation
token (KIP-48). Mirrors
DelegationTokenRecordminus any tombstone concerns — tombstones are handled as removals on the apply path. - Delegation
Token Record - A single delegation token’s authoritative state (KIP-48).
Replacement semantics — appending a new record with the same
token_idoverwrites the prior one in the image (used by both Create and Renew). Removal goes throughDeleteDelegationTokenRecord.hmacis the 32-byte HMAC-SHA-256 overtoken_idkeyed by the broker’s master secret key; clients authenticate via SCRAM-SHA-256 using the hex-encoded HMAC as the password. - Delete
Delegation Token Record - Tombstone record removing a delegation token (KIP-48)
from the image. Emitted by
ExpireDelegationTokenhandlers and the background expiry sweep. - 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 rather than storing 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.
- KRaft
Version Record - KIP-853: finalizes the cluster-wide kraft.version feature level.
- Metadata
Image - Partition
DirAssignment Record - KIP-858 directory-assignment delta. A broker reports which log-dir UUID
hosts its replica of
(topic, partition). Applied as a DELTA: sets ONLY the reporting replica’s slot inPartitionRecord.directories, never touching leader/isr/replicas/adding/removing — so it cannot clobber a concurrent reassignment or ISR change. On theKRaftlog it rides a Crabka-private carrier (viato_kraft) so it decodes back to this same delta and applies as a one-slot merge — never a full-record replace. - Partition
Record - Quota
Entity - Scram
Credential Record - Topic
Config Record - Mutable topic configuration overrides. Authoritative target state:
each
V1TopicConfigrecord fully replaces the previous override map fortopic. Empty map = clear all overrides. Merging happens at theAlterConfigshandler before the record is submitted. - Topic
Record - Unregister
Broker Record - KIP-185 /
UnregisterBroker(api_key64). Marks a broker as permanently unregistered: the admin operator confirms the broker is gone for good and asks the cluster to drop its registration entry from the metadata image. SubsequentMetadataresponses no longer advertise the broker’s endpoints; clients stop routing to it. - Voters
Record - KIP-853: full snapshot of the controller voter set.
Enums§
- Metadata
Error - Metadata
Record - Throttle
Kind - Selects which KIP-73 throttle rate config key to read.
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). Used by bothcrabka formatand the broker’s standalone self-bootstrap so a fresh cluster finalizes every feature’s release default. - bootstrap_
feature_ records_ with_ overrides - KIP-1022
crabka 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). - validate_
feature_ dependencies - KIP-1022 dependency validation for a fully-resolved feature→level map (as
seeded by
crabka format). For every finalized feature, each of itsdependencies(level)must be present inresolvedat>=the required level. ReturnsErrnaming the first unmet dependency. A no-op for today’s registry (no feature declares dependencies) but enforces the rule at format time, mirroring theUpdateFeatureshandler.