crabka-metadata 0.3.0

Versioned metadata record types + immutable image for Crabka
Documentation

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");