crabka_raft/lib.rs
1//! Metadata Raft quorum for Crabka.
2//!
3//! `crabka-raft` runs a hand-rolled KIP-595 `KRaft` consensus engine (the
4//! [`kraft::KraftController`]) over Crabka's storage ([`crabka_log`]) and
5//! transport ([`crabka_client_core`]). The public entry point is
6//! [`Controller::start`], which spawns the engine, opens a TCP listener serving
7//! the real KIP-595 RPCs (Fetch=1, Vote=52, BeginQuorumEpoch=53,
8//! EndQuorumEpoch=54) plus the Crabka-private observer/forward RPCs, and returns
9//! a [`ControllerHandle`] for submitting metadata changes and reading the
10//! current [`crabka_metadata::MetadataImage`].
11//!
12//! ## Quick start
13//!
14//! ```no_run
15//! use crabka_metadata::{MetadataRecord, TopicRecord};
16//! use crabka_raft::{Controller, ControllerConfig};
17//! use std::time::Duration;
18//! use uuid::Uuid;
19//!
20//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
21//! let dir = tempfile::tempdir()?;
22//! let cfg = ControllerConfig::for_tests(1, dir.path().to_path_buf());
23//! let controller = Controller::start(cfg).await?;
24//!
25//! controller
26//! .submit_change(vec![MetadataRecord::V1Topic(TopicRecord {
27//! name: "my-topic".into(),
28//! topic_id: Uuid::new_v4(),
29//! partitions: 3,
30//! replication_factor: 1,
31//! })])
32//! .await?;
33//!
34//! assert!(controller.current_image().topic("my-topic").is_some());
35//! controller.shutdown().await;
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! ## Capabilities and boundaries
41//!
42//! The controller persists and recovers `KRaft` metadata records, serves and
43//! installs KIP-630 snapshots through `FetchSnapshot`, publishes the current
44//! metadata image to broker tasks, and exposes Crabka-private submit/fetch RPCs
45//! for broker and observer integration. KIP-853-style observer bootstrap and
46//! auto-join are wired through the broker/controller configuration; the older
47//! handle-level `add_learner` / `change_membership` compatibility methods still
48//! return [`RaftError::Unsupported`]. Mixed JVM+Crabka controller quorums are
49//! outside this crate's compatibility target.
50
51#![doc(html_root_url = "https://docs.rs/crabka-raft/0.3.5")]
52
53mod config;
54mod controller;
55mod error;
56pub mod handshake;
57pub mod kraft;
58mod network;
59pub mod reconfig;
60mod server;
61mod snapshot;
62mod types;
63mod wire;
64
65pub use config::{BootstrapMode, ControllerConfig};
66pub use controller::{Controller, ControllerHandle, QuorumState, SnapshotRange, SnapshotSlice};
67pub use error::RaftError;
68pub use handshake::{DuplexStream, RaftHandshakeError, RaftListenerHandshake};
69pub use kraft::MetadataFetchSlice;
70pub use network::{OutboundDialer, PlaintextDialer};
71pub use reconfig::{AddVoter, ReconfigOutcome, RemoveVoter, UpdateVoter};
72pub use types::{AppData, AppDataResponse, Node, NodeId};
73pub use wire::{
74 API_KEY_METADATA_FETCH, API_KEY_SUBMIT_CHANGE, CrabkaMetadataFetchRequest,
75 CrabkaMetadataFetchResponse, CrabkaSubmitChangeRequest, CrabkaSubmitChangeResponse,
76};