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) through 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>
Sourcepub fn partitions_of(
&self,
topic: &str,
) -> impl Iterator<Item = &PartitionRecord>
pub fn partitions_of( &self, topic: &str, ) -> impl Iterator<Item = &PartitionRecord>
All partitions of topic, in ascending partition-index order.
The by-topic index gives an O(1) topic lookup and an
O(own partitions) iteration. The method never scans the partitions of
other topics, so a per-topic caller stays proportional to the topic it
asks about, even in images with tens of thousands of topics.
Sourcepub fn partition_next_offset(&self, topic: &str, partition: i32) -> Option<i64>
pub fn partition_next_offset(&self, topic: &str, partition: i32) -> Option<i64>
The committed next-offset for a diskless partition, if any advance has been applied.
pub fn partition_elr( &self, topic: &str, partition: i32, ) -> (&[NodeId], &[NodeId])
pub fn leader_recovery_state( &self, topic: &str, partition: i32, ) -> LeaderRecoveryState
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 and not from the stored TopicRecord.partitions field. This is
the authoritative count for the KIP-631 round-trip, because the
KIP-631 TopicRecord carries no partition count. It is also the
authoritative count for the validate partition-count-grew check.
Returns 0 for an unknown topic, or for a topic with no applied
partition records. O(1).
Sourcepub fn all_partitions(&self) -> impl Iterator<Item = &PartitionRecord>
pub fn all_partitions(&self) -> impl Iterator<Item = &PartitionRecord>
Single-pass iterator over every partition in the image. Each record
carries its own topic and partition fields. Topic order is
unspecified. Within a topic the order is ascending partition index.
The iterator is O(P) in total partition count. The cluster-wide
maintenance loops for failover, rebalance, reassignment, and metrics
use this instead of a per-topic loop.
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, that is,
where adding_replicas or removing_replicas is 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 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 default_broker_config(&self) -> Option<&BTreeMap<String, String>>
pub fn default_broker_config(&self) -> Option<&BTreeMap<String, String>>
Cluster-wide dynamic broker-config defaults, or None when no default
broker config has been applied.
Sourcepub fn broker_throttle_rate(
&self,
node_id: NodeId,
kind: ThrottleKind,
) -> Option<ByteRate>
pub fn broker_throttle_rate( &self, node_id: NodeId, kind: ThrottleKind, ) -> Option<ByteRate>
Returns the KIP-73 throttle rate for node_id and kind.
Returns None if the config key is absent, unparseable, or negative.
-1 is Kafka’s convention for “disabled” or “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).
Sourcepub fn group_config(&self, group_id: &str) -> Option<&BTreeMap<String, String>>
pub fn group_config(&self, group_id: &str) -> Option<&BTreeMap<String, String>>
Dynamic KIP-1071 overrides for one GROUP config resource.
Sourcepub fn group_configs(
&self,
) -> impl Iterator<Item = (&String, &BTreeMap<String, String>)>
pub fn group_configs( &self, ) -> impl Iterator<Item = (&String, &BTreeMap<String, String>)>
All configured GROUP resources.
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>
pub fn controller( &self, node_id: NodeId, ) -> Option<&ControllerRegistrationRecord>
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.
Sourcepub fn next_producer_id(&self) -> i64
pub fn next_producer_id(&self) -> i64
First producer ID not covered by any committed allocation block.
pub fn brokers(&self) -> impl Iterator<Item = &BrokerRegistrationRecord>
pub fn controllers(&self) -> impl Iterator<Item = &ControllerRegistrationRecord>
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’sAclAuthorizerandStandardAuthorizer. 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, both literal and prefixed, across all resource types.
DescribeAcls uses this.
Sourcepub fn topic_freeze(&self, topic: &str) -> Option<&TopicFreezeRecord>
pub fn topic_freeze(&self, topic: &str) -> Option<&TopicFreezeRecord>
The write-freeze entry that covers topic, or None when the topic
accepts writes (KFC-9).
A cluster with no freeze costs two is_empty tests, because the
produce path calls this once per topic per request. A literal entry
beats every prefix entry, and the longest matching prefix wins among
the prefix entries.
An internal topic is never frozen. The __ name convention is the
test, so a prefix scope of "" or "_" cannot take
__consumer_offsets down with the rest of the cluster.
Sourcepub fn topic_freezes(&self) -> impl Iterator<Item = &TopicFreezeRecord>
pub fn topic_freezes(&self) -> impl Iterator<Item = &TopicFreezeRecord>
Every live write-freeze entry, literal and prefixed (KFC-9). A thawed
entry is removed on apply, so every entry here has frozen: true.
Order is unspecified.
Sourcepub fn break_glass_proposal(
&self,
id: Uuid,
) -> Option<&BreakGlassProposalRecord>
pub fn break_glass_proposal( &self, id: Uuid, ) -> Option<&BreakGlassProposalRecord>
Look up a break-glass proposal by its id (KFC-9).
Sourcepub fn break_glass_proposals(
&self,
) -> impl Iterator<Item = &BreakGlassProposalRecord>
pub fn break_glass_proposals( &self, ) -> impl Iterator<Item = &BreakGlassProposalRecord>
Every break-glass proposal still in the image (KFC-9), including the consumed and withdrawn ones that the expiry sweep has not yet removed. Order is unspecified.
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). The match on the owning
KafkaPrincipal is exact. 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 may see through DescribeDelegationToken
without DescribeToken permission: those it owns, created or may
renew (DelegationToken::owner_or_renewer). 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). DescribeDelegationToken uses this for callers with
DescribeToken permission on the cluster.
Sourcepub fn delegation_token_by_hmac(
&self,
secret_key: &[u8],
hmac: &[u8],
) -> Option<&DelegationToken>
pub fn delegation_token_by_hmac( &self, secret_key: &[u8], hmac: &[u8], ) -> Option<&DelegationToken>
KIP-48: the delegation token whose HMAC under secret_key is hmac.
RenewDelegationToken and ExpireDelegationToken identify a token by
HMAC on the wire and not by token_id. The image keeps no HMAC, as
Kafka’s metadata does not, so each token’s HMAC is recomputed with
krabka_security::compute_token_hmac. The scan is linear over the
small in-memory token map.
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 applied. That is a
pre-bootstrap or legacy image, which is 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 that the live image needs: the
floor that a downgrade must not drop below. It rises with feature-gated
state present in the image: KRaft SCRAM creds, delegation tokens, and
KIP-1276 CIDR ACL hosts. The baseline is METADATA_VERSION_MIN.
Sourcepub fn metadata_version_downgrade_records(
&self,
target: i16,
) -> Vec<MetadataRecord>
pub fn metadata_version_downgrade_records( &self, target: i16, ) -> Vec<MetadataRecord>
Metadata removals needed to materialize this image at target.
An empty result means the downgrade is lossless. The controller emits
these records before the trailing metadata.version feature record only
for an explicitly unsafe downgrade.
Sourcepub fn apply(&mut self, rec: &MetadataRecord)
pub fn apply(&mut self, rec: &MetadataRecord)
Apply one record. Returns the previous record, for V1Topic and
V1BrokerRegistration, so the caller can observe overwrite cases.
The method is infallible. The controller pre-validates against the
current image before it submits 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.
The method deliberately never emits tombstone or removal records:
V1DeleteTopic, V1DeleteScramCredential,
V1DeleteAccessControlEntry, V1DeleteDelegationToken, and
V1UnregisterBroker. A snapshot captures resulting state, not
deletion history. V1BrokerConfig deletes vanish in the same way. The
method emits only the surviving key and value pairs, as Some(value)
sets.
The method emits records in dependency order, so a fresh image that
applys 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 the output of Self::to_records read back from a snapshot.
The method news an empty image and applys 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.
Controller::submit_change uses this before it forwards to openraft.
§Errors
Returns the conflict that would prevent the record from being applied.
Trait Implementations§
Source§impl Clone for MetadataImage
impl Clone for MetadataImage
Source§impl Debug for MetadataImage
impl Debug for MetadataImage
Source§impl Default for MetadataImage
impl Default for MetadataImage
Source§impl PartialEq for MetadataImage
impl PartialEq for MetadataImage
impl StructuralPartialEq for MetadataImage
Auto Trait Implementations§
impl Freeze for MetadataImage
impl RefUnwindSafe for MetadataImage
impl Send for MetadataImage
impl Sync for MetadataImage
impl Unpin for MetadataImage
impl UnsafeUnpin for MetadataImage
impl UnwindSafe for MetadataImage
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);