log/lib.rs
1//! OpenData Log - A key-oriented log system built on SlateDB.
2//!
3//! OpenData Log provides a simple log abstraction where each key represents an
4//! independent log stream. Unlike traditional messaging systems with partitions,
5//! users write directly to keys and can create new keys as access patterns evolve.
6//!
7//! # Architecture
8//!
9//! The log is built on SlateDB's LSM tree. Writes append entries to the WAL and
10//! memtable, then flush to sorted string tables (SSTs). LSM compaction naturally
11//! organizes data for log locality, grouping entries by key prefix over time.
12//!
13//! # Key Concepts
14//!
15//! - **LogDb**: The main entry point providing both read and write operations.
16//! - **LogDbReader**: A read-only view of the log, useful for consumers that should
17//! not have write access.
18//! - **Sequence Numbers**: Each entry is assigned a global sequence number at
19//! append time. Sequence numbers are monotonically increasing within a key's
20//! log but not contiguous (other keys' appends are interleaved).
21//!
22//! # Example
23//!
24//! ```
25//! # use log::{LogDb, LogRead, Config, Record};
26//! # use bytes::Bytes;
27//! # use common::StorageConfig;
28//! # #[tokio::main]
29//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
30//! let config = Config { storage: StorageConfig::InMemory, ..Default::default() };
31//! let log = LogDb::open(config).await?;
32//!
33//! // Append records
34//! let records = vec![
35//! Record { key: Bytes::from("orders"), value: Bytes::from("order-123") },
36//! ];
37//! log.try_append(records).await?;
38//! log.flush().await?;
39//!
40//! // Scan a key's log
41//! let mut iter = log.scan(Bytes::from("orders"), ..).await?;
42//! while let Some(entry) = iter.next().await? {
43//! println!("seq={}, value={:?}", entry.sequence, entry.value);
44//! }
45//! # Ok(())
46//! # }
47//! ```
48
49mod config;
50mod error;
51mod listing;
52mod log;
53mod model;
54mod range;
55mod reader;
56mod segment;
57mod serde;
58#[cfg(feature = "http-server")]
59pub mod server;
60mod storage;
61mod writer;
62
63pub use config::{Config, CountOptions, ReaderConfig, ScanOptions, SegmentConfig};
64pub use error::{AppendError, AppendResult, Error, Result};
65pub use listing::{LogKey, LogKeyIterator};
66pub use log::{LogDb, LogDbBuilder};
67pub use model::{AppendOutput, LogEntry, Record, Segment, SegmentId, Sequence};
68
69pub use reader::{LogDbReader, LogIterator, LogRead};
70
71// Re-export proto types for use by clients
72#[cfg(feature = "http-server")]
73pub mod proto {
74 pub use crate::server::proto::*;
75}