Skip to main content

inferadb_ledger_raft/
lib.rs

1//! Raft consensus infrastructure for InferaDB Ledger.
2//!
3//! Provides:
4//! - OpenRaft integration with inferadb-ledger-store log storage
5//! - Combined RaftStorage implementation (log + state machine)
6//! - Inter-node Raft network transport
7//! - Transaction batching, rate limiting, and background jobs
8//!
9//! # Public API
10//!
11//! The stable public API surface consists of:
12//! - [`trace_context`] — distributed tracing propagation helpers
13//! - [`metrics`] — Prometheus metric constants and recording helpers
14//! - [`LedgerTypeConfig`] — OpenRaft type configuration
15//!
16//! All other modules and re-exports are server-internal infrastructure
17//! hidden from documentation. They may change without notice.
18//!
19//! ## Architecture Note
20//!
21//! OpenRaft 0.9 has sealed traits for `RaftLogStorage` and `RaftStateMachine` (v2 API).
22//! We use the deprecated but non-sealed `RaftStorage` trait which combines both
23//! log storage and state machine functionality into a single implementation.
24//!
25//! ## Security Model
26//!
27//! Ledger runs behind WireGuard VPN. Authentication and authorization are handled
28//! by Engine/Control services upstream. Ledger trusts all incoming requests.
29
30#![deny(unsafe_code)]
31#![warn(missing_docs)]
32// gRPC services return tonic::Status (176 bytes) - this is standard practice for gRPC error
33// handling
34#![allow(clippy::result_large_err)]
35
36// ---------------------------------------------------------------------------
37// Public modules — stable API surface for SDK and external consumers
38// ---------------------------------------------------------------------------
39
40pub mod metrics;
41pub mod trace_context;
42
43// ---------------------------------------------------------------------------
44// Server-internal modules — implementation details hidden from `cargo doc`.
45// These are `pub` so the server/services crates can access them, but
46// `#[doc(hidden)]` keeps the documentation focused on SDK-facing types.
47// ---------------------------------------------------------------------------
48
49#[doc(hidden)]
50pub mod backup;
51#[doc(hidden)]
52pub mod batching;
53#[doc(hidden)]
54pub mod deadline;
55#[doc(hidden)]
56pub mod dek_rewrap;
57#[doc(hidden)]
58pub mod dependency_health;
59#[doc(hidden)]
60pub mod entry_crypto;
61#[doc(hidden)]
62pub mod error;
63#[doc(hidden)]
64pub mod event_writer;
65#[doc(hidden)]
66pub mod graceful_shutdown;
67#[doc(hidden)]
68pub mod hot_key_detector;
69#[doc(hidden)]
70pub mod idempotency;
71#[doc(hidden)]
72pub mod integrity_scrubber;
73#[doc(hidden)]
74pub mod invite_maintenance;
75#[doc(hidden)]
76pub mod leader_transfer;
77#[doc(hidden)]
78pub mod log_storage;
79#[doc(hidden)]
80pub mod logging;
81#[doc(hidden)]
82pub mod otel;
83#[doc(hidden)]
84pub mod pagination;
85#[doc(hidden)]
86pub mod peer_tracker;
87#[doc(hidden)]
88pub mod proof;
89#[doc(hidden)]
90pub mod raft_manager;
91#[doc(hidden)]
92pub mod resource_metrics;
93#[doc(hidden)]
94pub mod runtime_config;
95
96#[doc(hidden)]
97pub mod auto_recovery;
98#[doc(hidden)]
99pub mod block_compaction;
100#[doc(hidden)]
101pub mod btree_compaction;
102#[doc(hidden)]
103pub mod events_gc;
104#[doc(hidden)]
105pub mod file_lock;
106#[doc(hidden)]
107pub mod learner_refresh;
108#[doc(hidden)]
109pub mod organization_purge;
110#[doc(hidden)]
111pub mod orphan_cleanup;
112#[doc(hidden)]
113pub mod post_erasure_compaction;
114#[doc(hidden)]
115pub mod raft_network;
116#[doc(hidden)]
117pub mod rate_limit;
118#[doc(hidden)]
119pub mod region_router;
120#[doc(hidden)]
121pub mod region_storage;
122#[doc(hidden)]
123pub mod saga_orchestrator;
124#[doc(hidden)]
125pub mod snapshot;
126#[doc(hidden)]
127pub mod state_root_verifier;
128#[doc(hidden)]
129pub mod token_maintenance;
130#[doc(hidden)]
131pub mod ttl_gc;
132#[doc(hidden)]
133pub mod types;
134#[doc(hidden)]
135pub mod user_retention;
136
137// ---------------------------------------------------------------------------
138// Server infrastructure re-exports — consumed by the server crate for
139// bootstrapping, configuration, and background job management.
140//
141// These are `#[doc(hidden)]` to keep `cargo doc` focused on SDK types.
142// Server code should prefer direct module paths (e.g.
143// `inferadb_ledger_raft::graceful_shutdown::HealthState`) over these
144// convenience re-exports.
145// ---------------------------------------------------------------------------
146#[doc(hidden)]
147pub use auto_recovery::AutoRecoveryJob;
148#[doc(hidden)]
149pub use backup::{BackupJob, BackupManager};
150#[doc(hidden)]
151pub use block_compaction::BlockCompactor;
152#[doc(hidden)]
153pub use events_gc::EventsGarbageCollector;
154#[doc(hidden)]
155pub use graceful_shutdown::{BackgroundJobWatchdog, GracefulShutdown, HealthState};
156#[doc(hidden)]
157pub use hot_key_detector::HotKeyDetector;
158#[doc(hidden)]
159pub use integrity_scrubber::IntegrityScrubberJob;
160#[doc(hidden)]
161pub use invite_maintenance::InviteMaintenanceJob;
162#[doc(hidden)]
163pub use learner_refresh::LearnerRefreshJob;
164#[doc(hidden)]
165pub use log_storage::RaftLogStore;
166#[doc(hidden)]
167pub use organization_purge::OrganizationPurgeJob;
168#[doc(hidden)]
169pub use orphan_cleanup::OrphanCleanupJob;
170#[doc(hidden)]
171pub use post_erasure_compaction::PostErasureCompactionJob;
172#[doc(hidden)]
173pub use raft_manager::{RaftManager, RaftManagerConfig, RegionConfig, RegionGroup};
174#[doc(hidden)]
175pub use raft_network::GrpcRaftNetworkFactory;
176#[doc(hidden)]
177pub use rate_limit::RateLimiter;
178#[doc(hidden)]
179pub use region_storage::{RegionStorage, RegionStorageManager};
180#[doc(hidden)]
181pub use resource_metrics::ResourceMetricsCollector;
182#[doc(hidden)]
183pub use runtime_config::RuntimeConfigHandle;
184#[doc(hidden)]
185pub use saga_orchestrator::{
186    OnboardingPii, OrgPii, SagaOrchestrator, SagaOrchestratorHandle, SagaOutput, SagaSubmission,
187};
188#[doc(hidden)]
189pub use token_maintenance::TokenMaintenanceJob;
190#[doc(hidden)]
191pub use ttl_gc::TtlGarbageCollector;
192#[doc(hidden)]
193pub use types::LedgerNodeId;
194/// OpenRaft type configuration for the ledger's Raft consensus layer.
195pub use types::LedgerTypeConfig;
196#[doc(hidden)]
197pub use user_retention::UserRetentionReaper;