pub struct MetadataImage { /* private fields */ }Implementations§
Source§impl MetadataImage
impl MetadataImage
pub fn new(cluster_id: Uuid) -> Self
pub fn cluster_id(&self) -> Uuid
pub fn topics(&self) -> impl Iterator<Item = &TopicRecord>
pub fn topic(&self, name: &str) -> Option<&TopicRecord>
Sourcepub fn topic_by_id(&self, id: &Uuid) -> Option<&TopicRecord>
pub fn topic_by_id(&self, id: &Uuid) -> Option<&TopicRecord>
KIP-516: resolve a topic by its UUID. O(1) via the topic_ids index.
Sourcepub fn topic_name_by_id(&self, id: &Uuid) -> Option<&str>
pub fn topic_name_by_id(&self, id: &Uuid) -> Option<&str>
KIP-516: resolve a topic name by its UUID.
pub fn partition(&self, topic: &str, idx: i32) -> Option<&PartitionRecord>
pub fn partitions_of( &self, topic: &str, ) -> impl Iterator<Item = &PartitionRecord>
Sourcepub fn topic_partition_count(&self, topic: &str) -> i32
pub fn topic_partition_count(&self, topic: &str) -> i32
The live partition count for topic, derived from the partitions
map rather than the stored TopicRecord.partitions field. This is
the authoritative count for the KIP-631 round-trip (the KIP-631
TopicRecord carries no partition count) and for the validate
partition-count-grew check. Returns 0 for an unknown topic or one
with no partition records yet applied.
Sourcepub fn all_partitions(
&self,
) -> impl Iterator<Item = (&(String, i32), &PartitionRecord)>
pub fn all_partitions( &self, ) -> impl Iterator<Item = (&(String, i32), &PartitionRecord)>
Single-pass iterator over every partition in the image, yielding
the flat (topic_name, partition_index) key alongside the record.
O(P) in total partition count — the cluster-wide maintenance loops
(failover, rebalance, reassignment, metrics) use this instead of
topics().flat_map(partitions_of), which is O(topics × P).
Sourcepub fn reassignments_in_flight(
&self,
) -> impl Iterator<Item = &PartitionRecord> + '_
pub fn reassignments_in_flight( &self, ) -> impl Iterator<Item = &PartitionRecord> + '_
All partitions where a reassignment is currently in flight
(adding_replicas or removing_replicas non-empty).
Sourcepub fn topic_config(&self, topic: &str) -> Option<&BTreeMap<String, String>>
pub fn topic_config(&self, topic: &str) -> Option<&BTreeMap<String, String>>
Currently-effective config overrides for topic, or None if no
V1TopicConfig record has been applied for this topic since the last
V1DeleteTopic (or since image creation).
Sourcepub fn broker_config(
&self,
node_id: NodeId,
) -> Option<&BTreeMap<String, String>>
pub fn broker_config( &self, node_id: NodeId, ) -> Option<&BTreeMap<String, String>>
Per-broker config overrides for node_id, or None if no
V1BrokerConfig record has been applied for this broker.
Sourcepub fn broker_throttle_rate(
&self,
node_id: NodeId,
kind: ThrottleKind,
) -> Option<u64>
pub fn broker_throttle_rate( &self, node_id: NodeId, kind: ThrottleKind, ) -> Option<u64>
Returns the throttle rate in bytes/sec for node_id and kind.
Returns None if the config key is absent, unparseable, or is -1
(Kafka convention for “disabled / unlimited”).
Sourcepub fn client_metrics_config(
&self,
name: &str,
) -> Option<&BTreeMap<String, String>>
pub fn client_metrics_config( &self, name: &str, ) -> Option<&BTreeMap<String, String>>
Override map for a single KIP-714 client-metrics subscription.
Sourcepub fn client_metrics_subscriptions(
&self,
) -> impl Iterator<Item = (&String, &BTreeMap<String, String>)>
pub fn client_metrics_subscriptions( &self, ) -> impl Iterator<Item = (&String, &BTreeMap<String, String>)>
All configured client-metrics subscriptions, (name, overrides).
pub fn client_quotas(&self) -> &HashMap<EntityKey, BTreeMap<String, f64>>
pub fn scram_credential( &self, user: &str, mechanism: SaslMechanism, ) -> Option<&ScramCredential>
Sourcepub fn scram_credentials_users(&self) -> Vec<String>
pub fn scram_credentials_users(&self) -> Vec<String>
All distinct users with at least one SCRAM credential. Order is unspecified.
Sourcepub fn scram_credentials_for_user(
&self,
user: &str,
) -> Vec<(SaslMechanism, u32)>
pub fn scram_credentials_for_user( &self, user: &str, ) -> Vec<(SaslMechanism, u32)>
All (mechanism, iterations) pairs for user. Empty if user has
no SCRAM credentials. Order is unspecified.
pub fn broker(&self, node_id: NodeId) -> Option<&BrokerRegistrationRecord>
Sourcepub fn broker_epoch(&self, node_id: NodeId) -> Option<i64>
pub fn broker_epoch(&self, node_id: NodeId) -> Option<i64>
KIP-903: the broker epoch (registration commit offset) for node_id,
or None if the broker is not registered in this image.
pub fn brokers(&self) -> impl Iterator<Item = &BrokerRegistrationRecord>
pub fn kraft_version(&self) -> u16
pub fn voters(&self) -> &VoterSet
Sourcepub fn matching_acls<'a>(
&'a self,
rt: ResourceType,
rn: &'a str,
) -> impl Iterator<Item = &'a AclEntry> + 'a
pub fn matching_acls<'a>( &'a self, rt: ResourceType, rn: &'a str, ) -> impl Iterator<Item = &'a AclEntry> + 'a
Iterate every ACL that could possibly match (rt, rn):
- all literal entries at
(rt, rn) - all literal entries at
(rt, "*")— theWILDCARD_RESOURCE, which matches every resource of that type (see Kafka’sAclAuthorizer/StandardAuthorizer; this is whatkafka-acls --topic '*'produces) - all prefixed entries whose
resource_nameis a prefix ofrn
Sourcepub fn all_acls(&self) -> impl Iterator<Item = &AclEntry>
pub fn all_acls(&self) -> impl Iterator<Item = &AclEntry>
All ACL entries (literal + prefixed across all resource types).
Used by DescribeAcls.
Sourcepub fn delegation_token_by_id(&self, token_id: &str) -> Option<&DelegationToken>
pub fn delegation_token_by_id(&self, token_id: &str) -> Option<&DelegationToken>
Look up a delegation token by its token_id (KIP-48).
Sourcepub fn delegation_tokens_by_owner(
&self,
owner: &KafkaPrincipal,
) -> Vec<&DelegationToken>
pub fn delegation_tokens_by_owner( &self, owner: &KafkaPrincipal, ) -> Vec<&DelegationToken>
All tokens owned by owner (KIP-48; exact match on
the owning KafkaPrincipal). Order is unspecified.
Sourcepub fn delegation_tokens_visible_to(
&self,
principal: &KafkaPrincipal,
) -> Vec<&DelegationToken>
pub fn delegation_tokens_visible_to( &self, principal: &KafkaPrincipal, ) -> Vec<&DelegationToken>
Tokens that principal is allowed to see via
DescribeDelegationToken without DescribeToken permission —
either as the owner or as a listed renewer (KIP-48). Order is
unspecified.
Sourcepub fn all_delegation_tokens(&self) -> impl Iterator<Item = &DelegationToken>
pub fn all_delegation_tokens(&self) -> impl Iterator<Item = &DelegationToken>
Every delegation token currently in the
image (KIP-48). Used by DescribeDelegationToken for callers with
DescribeToken permission on the cluster.
Sourcepub fn delegation_token_by_hmac(&self, hmac: &[u8]) -> Option<&DelegationToken>
pub fn delegation_token_by_hmac(&self, hmac: &[u8]) -> Option<&DelegationToken>
KIP-48: lookup a delegation token by its HMAC bytes.
RenewDelegationToken / ExpireDelegationToken identify a token
by HMAC on the wire (not by token_id), and the SCRAM
delegation-token fallback needs the same lookup at
the auth path. Implementation is a linear scan over the small
(per-broker, in-memory) token map — clarity over an explicit
HMAC→token_id index until cardinality justifies it.
Sourcepub fn finalized_features(&self) -> &BTreeMap<String, i16>
pub fn finalized_features(&self) -> &BTreeMap<String, i16>
KIP-584: finalized feature levels, keyed by feature name. Empty
until an UpdateFeatures call lands a V1FeatureLevel record.
Sourcepub fn finalized_features_epoch(&self) -> i64
pub fn finalized_features_epoch(&self) -> i64
KIP-584 finalized-features epoch. -1 (“unknown”) until the first
feature is finalized.
Sourcepub fn finalized_metadata_version(&self) -> Option<i16>
pub fn finalized_metadata_version(&self) -> Option<i16>
The finalized metadata.version level, or None if no
V1FeatureLevel for metadata.version has been applied
(a pre-bootstrap / legacy image — MetadataVersion.UNKNOWN).
Sourcepub fn finalized_feature(&self, name: &str) -> Option<i16>
pub fn finalized_feature(&self, name: &str) -> Option<i16>
KIP-584: the finalized level for an arbitrary feature, or None if it
has not been finalized. Generic counterpart to
Self::finalized_metadata_version.
Sourcepub fn min_required_metadata_version(&self) -> i16
pub fn min_required_metadata_version(&self) -> i16
The minimum metadata.version level the live image requires: the
floor a downgrade must not drop below. Rises with feature-gated
state present in the image (KRaft SCRAM creds, delegation tokens).
Baseline is METADATA_VERSION_MIN.
Sourcepub fn apply(&mut self, rec: &MetadataRecord)
pub fn apply(&mut self, rec: &MetadataRecord)
Apply one record. Returns the previous record (for V1Topic /
V1BrokerRegistration) so the caller can observe overwrite cases.
Infallible — pre-validation against the current image happens
in the controller before submitting to Raft. Apply must never
fail on a committed entry.
Sourcepub fn to_records(&self) -> Vec<MetadataRecord>
pub fn to_records(&self) -> Vec<MetadataRecord>
Serialize the image into the minimal sequence of MetadataRecords
whose in-order apply reproduces this image exactly.
This is the inverse of apply over a sequence of non-tombstone
records: each stored entry maps to the record that would create it.
Tombstone / removal records (V1DeleteTopic,
V1DeleteScramCredential, V1DeleteAccessControlEntry,
V1DeleteDelegationToken, V1UnregisterBroker) are intentionally
never emitted: a snapshot captures resulting state, not deletion
history. V1BrokerConfig deletes likewise vanish — only the
surviving key/value pairs are emitted as Some(value) sets.
Records are emitted in dependency order so that a fresh image
applying them never sees a dangling reference: brokers,
broker-configs, topics, partitions, topic-configs, SCRAM creds,
ACLs, client quotas, delegation tokens.
Sourcepub fn from_records(cluster_id: Uuid, records: &[MetadataRecord]) -> Self
pub fn from_records(cluster_id: Uuid, records: &[MetadataRecord]) -> Self
Reconstruct an image from a cluster_id and a record sequence
(typically Self::to_records output read back from a snapshot):
new an empty image and apply each record in order.
Sourcepub fn validate(&self, rec: &MetadataRecord) -> Result<(), MetadataError>
pub fn validate(&self, rec: &MetadataRecord) -> Result<(), MetadataError>
Synchronous pre-validation: returns Ok if the record would be a
no-conflict apply, otherwise the appropriate error. Used by
Controller::submit_change before forwarding to openraft.
Trait Implementations§
Source§impl Clone for MetadataImage
impl Clone for MetadataImage
Source§fn clone(&self) -> MetadataImage
fn clone(&self) -> MetadataImage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetadataImage
impl Debug for MetadataImage
Source§impl Default for MetadataImage
impl Default for MetadataImage
Source§fn default() -> MetadataImage
fn default() -> MetadataImage
Source§impl PartialEq for MetadataImage
impl PartialEq for MetadataImage
Source§fn eq(&self, other: &MetadataImage) -> bool
fn eq(&self, other: &MetadataImage) -> bool
self and other values to be equal, and is used by ==.