Expand description
§State Store Module
High-performance state storage for streaming operators.
§Design Goals
- < 500ns lookup latency for point queries
- Zero-copy access where possible
- Lock-free for single-threaded access
- Memory-mapped for large state
§State Backends
InMemoryStore: BTreeMap-based, fast lookups with O(log n + k) prefix/range scansMmapStateStore: Memory-mapped, supports larger-than-memory state with optional persistence
§Example
use bytes::Bytes;
use laminar_core::state::{StateStore, StateStoreExt, InMemoryStore};
let mut store = InMemoryStore::new();
// Basic key-value operations
store.put(b"user:1", Bytes::from_static(b"alice")).unwrap();
assert_eq!(store.get(b"user:1").unwrap().as_ref(), b"alice");
// Typed state access (requires StateStoreExt)
store.put_typed(b"count", &42u64).unwrap();
let count: u64 = store.get_typed(b"count").unwrap().unwrap();
assert_eq!(count, 42);
// Snapshots for checkpointing
let snapshot = store.snapshot();
store.delete(b"user:1").unwrap();
assert!(store.get(b"user:1").is_none());
// Restore from snapshot
store.restore(snapshot);
assert_eq!(store.get(b"user:1").unwrap().as_ref(), b"alice");§Memory-Mapped Store Example
use bytes::Bytes;
use laminar_core::state::{StateStore, MmapStateStore};
use std::path::Path;
// In-memory mode (fast, not persistent)
let mut store = MmapStateStore::in_memory(1024 * 1024);
store.put(b"key", Bytes::from_static(b"value")).unwrap();
// Persistent mode (survives restarts)
let mut persistent = MmapStateStore::persistent(
Path::new("/tmp/state.db"),
1024 * 1024
).unwrap();
persistent.put(b"key", Bytes::from_static(b"value")).unwrap();
persistent.flush().unwrap();Re-exports§
pub use self::StateError as Error;pub use ahash_store::AHashMapStore;pub use dict_encoder::DictionaryKeyEncoder;
Modules§
- ahash_
store - AHashMap-backed state store with O(1) lookups and zero-copy reads. AHashMap-backed state store with dual-structure design.
- dict_
encoder - Dictionary key encoder for low-cardinality GROUP BY keys. Dictionary key encoder for low-cardinality GROUP BY keys.
Structs§
- Archived
State Snapshot - An archived
StateSnapshot - InMemory
Store - In-memory state store using
BTreeMapfor sorted key access. - Mmap
State Store - Memory-mapped state store implementation.
- State
Snapshot - A snapshot of state store contents for checkpointing.
- State
Snapshot Resolver - The resolver for an archived
StateSnapshot
Enums§
- State
Error - Errors that can occur in state operations.
Traits§
- State
Store - Trait for state store implementations.
- State
Store Ext - Extension trait for
StateStoreproviding typed access methods.