Skip to main content

Module state

Module state 

Source
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 scans
  • MmapStateStore: 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§

ArchivedStateSnapshot
An archived StateSnapshot
InMemoryStore
In-memory state store using BTreeMap for sorted key access.
MmapStateStore
Memory-mapped state store implementation.
StateSnapshot
A snapshot of state store contents for checkpointing.
StateSnapshotResolver
The resolver for an archived StateSnapshot

Enums§

StateError
Errors that can occur in state operations.

Traits§

StateStore
Trait for state store implementations.
StateStoreExt
Extension trait for StateStore providing typed access methods.