Skip to main content

crabka_metadata/
lib.rs

1//! Versioned metadata records and the immutable image they apply to.
2//!
3//! `crabka-metadata` provides [`MetadataRecord`] (the versioned union
4//! of topic / partition / broker registrations / topic deletions) and
5//! [`MetadataImage`] (an immutable snapshot of the cluster's metadata).
6//!
7//! The image is mutated only by [`MetadataImage::apply`] called from
8//! the Raft state machine in `crabka-raft`. Everywhere else it's read
9//! via shared references and Arc clones.
10//!
11//! ## Applying controller records
12//!
13//! ```rust
14//! use crabka_metadata::{MetadataImage, MetadataRecord, TopicRecord};
15//! use uuid::Uuid;
16//!
17//! let mut image = MetadataImage::new(Uuid::new_v4());
18//! let topic_id = Uuid::new_v4();
19//!
20//! image.apply(&MetadataRecord::V1Topic(TopicRecord {
21//!     name: "orders".into(),
22//!     topic_id,
23//!     partitions: 0,
24//!     replication_factor: 3,
25//! }));
26//!
27//! let topic = image.topic("orders").expect("topic exists");
28//! assert_eq!(topic.topic_id, topic_id);
29//! ```
30//!
31//! ## Canonical quota entity keys
32//!
33//! ```rust
34//! use crabka_metadata::canonicalize_entity;
35//!
36//! let key = canonicalize_entity(vec![
37//!     ("user".to_string(), Some("alice".to_string())),
38//!     ("client-id".to_string(), Some("analytics".to_string())),
39//! ]);
40//!
41//! assert_eq!(key[0].0, "client-id");
42//! assert_eq!(key[1].0, "user");
43//! ```
44
45#![doc(html_root_url = "https://docs.rs/crabka-metadata/0.3.5")]
46
47pub mod acl;
48mod error;
49mod feature;
50pub mod group_version;
51mod image;
52pub mod kafka_record;
53pub mod kraft_translate;
54pub mod metadata_version;
55mod records;
56pub mod transaction_version;
57pub mod voters;
58
59pub use acl::{AclEntry, AclEntryFilter, AclOperation, PatternType, PermissionType, ResourceType};
60pub use error::MetadataError;
61pub use feature::{
62    Feature, bootstrap_feature_records, bootstrap_feature_records_with_overrides, feature,
63    feature_registry, is_supported_level, validate_feature_dependencies,
64};
65pub use image::{DelegationToken, EntityKey, MetadataImage, ThrottleKind, canonicalize_entity};
66pub use kafka_record::{KafkaRecordError, from_kafka_record, to_kafka_record};
67pub use kraft_translate::{
68    TranslateError, from_kraft, from_kraft_value, to_kraft, to_kraft_records, to_kraft_values,
69};
70pub use records::{
71    BrokerConfigRecord, BrokerEndpoint, BrokerRegistrationRecord, ClientMetricsConfigRecord,
72    ClientQuotaRecord, DelegationTokenRecord, DeleteDelegationTokenRecord,
73    DeleteScramCredentialRecord, DeleteTopicRecord, FeatureLevelRecord, FeaturesEpochRecord,
74    KRaftVersionRecord, MetadataRecord, NodeId, PartitionDirAssignmentRecord, PartitionRecord,
75    QuotaEntity, ScramCredentialRecord, TopicConfigRecord, TopicRecord, UnregisterBrokerRecord,
76    VotersRecord,
77};
78pub use voters::{KRaftVersionRange, Voter, VoterEndpoint, VoterSet};