yggr/lib.rs
1//! Jotun — a Raft node runtime built on
2//! [`yggr_core`].
3//!
4//! Users implement [`StateMachine`] (your application's apply/restore logic) and call
5//! [`Node::start`]; the runtime owns the engine, the network
6//! transport, the on-disk persistence, the tick driver, and the
7//! action dispatcher. Incoming snapshots are installed and restored
8//! automatically. By default the runtime also reacts to snapshot hints
9//! from the engine by calling [`StateMachine::snapshot`] and feeding
10//! the resulting bytes back into Raft; the serializer runs on a
11//! separate task so a slow [`StateMachine::snapshot`] does not stall
12//! ticks, heartbeats, or [`Node::status`]. `snapshot` is fallible
13//! ([`SnapshotError`]); returning `Err` just skips this hint and the
14//! engine retries on the next one. Set
15//! [`Config::snapshot_hint_threshold_entries`] to `0` (and
16//! [`Config::max_log_entries`]) if you want to disable host-initiated
17//! compaction entirely.
18//!
19//! Observability is pull-model: [`Node::metrics`] returns a snapshot
20//! of counters and gauges covering elections, replication, commits,
21//! applies, reads, and snapshots.
22//!
23//! For users who want different transport, storage, or concurrency,
24//! [`Storage`] and [`Transport`] are traits — the defaults are
25//! TCP + a hand-rolled segmented log on disk, but anything that
26//! satisfies the trait works.
27//!
28//! Internals (the engine state machine, log entries, message types)
29//! live in [`yggr_core`] and are re-exported here for convenience.
30
31#![cfg_attr(
32 test,
33 allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing,)
34)]
35
36pub mod node;
37pub mod state_machine;
38pub mod storage;
39pub mod transport;
40
41pub use node::{
42 Bootstrap, Config, ConfigError, Node, NodeStartError, NodeStatus, ProposeError, ReadError,
43 Role, TransferLeadershipError,
44};
45pub use state_machine::{DecodeError, SnapshotError, StateMachine};
46pub use storage::{DiskStorage, DiskStorageError, Storage, StoredHardState, StoredSnapshot};
47pub use transport::{TcpTransport, TcpTransportError, Transport};
48
49// Convenience re-exports from yggr-core. Saves users from having to
50// `use yggr_core::...` for the basics; the engine itself stays
51// addressable via that crate for power-user integrations.
52pub use yggr_core::{ConfigChange, LogIndex, NodeId, Term};