Skip to main content

laminar_core/
lib.rs

1//! # `LaminarDB` Core
2//!
3//! The core streaming engine for `LaminarDB`, implementing the Ring 0 (hot path) components.
4//!
5//! This crate provides:
6//! - **Reactor**: Single-threaded event loop with zero allocations
7//! - **Operators**: Streaming operators (map, filter, window, join)
8//! - **State Store**: Lock-free state management with sub-microsecond lookup
9//! - **Time**: Event time processing, watermarks, and timers
10//!
11//! ## Design Principles
12//!
13//! 1. **Zero allocations on hot path** - Uses arena allocators
14//! 2. **No locks on hot path** - SPSC queues, lock-free structures
15//! 3. **Predictable latency** - < 1μs event processing
16//! 4. **CPU cache friendly** - Data structures optimized for cache locality
17//!
18//! ## Example
19//!
20//! ```rust,ignore
21//! use laminar_core::{Reactor, Config};
22//!
23//! let config = Config::default();
24//! let mut reactor = Reactor::new(config)?;
25//!
26//! // Run the event loop
27//! reactor.run()?;
28//! ```
29
30#![deny(missing_docs)]
31#![warn(clippy::all, clippy::pedantic)]
32#![allow(clippy::module_name_repetitions)]
33#![allow(clippy::disallowed_types)]
34// Allow unsafe in alloc module for zero-copy optimizations
35#![allow(unsafe_code)]
36
37/// Cross-partition aggregation.
38pub mod aggregation;
39pub mod alloc;
40pub mod budget;
41/// Distributed checkpoint barrier protocol.
42pub mod checkpoint;
43pub mod compiler;
44pub mod dag;
45pub mod detect;
46/// Structured error code registry (`LDB-NNNN`) and Ring 0 hot path error type.
47pub mod error_codes;
48/// Secondary index support using redb.
49pub mod index;
50pub mod io_uring;
51/// Lookup table types and predicate pushdown.
52pub mod lookup;
53pub mod mv;
54pub mod numa;
55pub mod operator;
56pub mod reactor;
57pub mod sink;
58pub mod state;
59pub mod streaming;
60pub mod subscription;
61pub mod time;
62pub mod tpc;
63pub mod xdp;
64
65/// Distributed delta mode (multi-node coordination).
66#[cfg(feature = "delta")]
67pub mod delta;
68
69// Re-export key types
70pub use reactor::{Reactor, ReactorConfig};
71
72/// Result type for laminar-core operations
73pub type Result<T> = std::result::Result<T, Error>;
74
75/// Error types for laminar-core
76#[derive(Debug, thiserror::Error)]
77pub enum Error {
78    /// Reactor-related errors
79    #[error("Reactor error: {0}")]
80    Reactor(#[from] reactor::ReactorError),
81
82    /// State store errors
83    #[error("State error: {0}")]
84    State(#[from] state::StateError),
85
86    /// Operator errors
87    #[error("Operator error: {0}")]
88    Operator(#[from] operator::OperatorError),
89
90    /// Time-related errors
91    #[error("Time error: {0}")]
92    Time(#[from] time::TimeError),
93
94    /// Thread-per-core runtime errors
95    #[error("TPC error: {0}")]
96    Tpc(#[from] tpc::TpcError),
97
98    /// `io_uring` errors
99    #[error("io_uring error: {0}")]
100    IoUring(#[from] io_uring::IoUringError),
101
102    /// NUMA errors
103    #[error("NUMA error: {0}")]
104    Numa(#[from] numa::NumaError),
105
106    /// Sink errors
107    #[error("Sink error: {0}")]
108    Sink(#[from] sink::SinkError),
109
110    /// Materialized view errors
111    #[error("MV error: {0}")]
112    Mv(#[from] mv::MvError),
113
114    /// XDP/eBPF errors
115    #[error("XDP error: {0}")]
116    Xdp(#[from] xdp::XdpError),
117
118    /// DAG topology errors
119    #[error("DAG error: {0}")]
120    Dag(#[from] dag::DagError),
121}