Skip to main content

moloch_storage/
lib.rs

1//! Storage layer for Moloch.
2//!
3//! Provides persistent storage for:
4//! - Audit events
5//! - Blocks
6//! - MMR nodes
7//! - Indexes for efficient queries
8//!
9//! # Batch Operations
10//!
11//! For efficient bulk writes, use the batch API:
12//!
13//! ```ignore
14//! use moloch_storage::{RocksStorage, StorageBatch, BatchWriter};
15//!
16//! let storage = RocksStorage::open("./data")?;
17//! let mut batch = StorageBatch::new();
18//!
19//! batch.put_block(block1);
20//! batch.put_block(block2);
21//! batch.put_mmr_node(0, hash);
22//!
23//! storage.commit(batch)?; // Atomic write
24//! ```
25//!
26//! # Iterators
27//!
28//! For efficient traversal, use the iterator API:
29//!
30//! ```ignore
31//! use moloch_storage::{RocksStorage, BlockIterator, EventIterator};
32//!
33//! let storage = RocksStorage::open("./data")?;
34//!
35//! // Iterate over all blocks
36//! for block in BlockIterator::all(&storage)? {
37//!     println!("Block {}", block?.header.height);
38//! }
39//!
40//! // Iterate over events in specific block range
41//! for event in EventIterator::in_blocks(&storage, 0, 100) {
42//!     let (height, event) = event?;
43//!     println!("Event {} in block {}", event.id(), height);
44//! }
45//! ```
46
47mod batch;
48mod iter;
49mod mmap;
50mod rocks;
51pub mod snapshot;
52mod traits;
53
54pub use batch::{BatchOp, BatchWriter, BulkReader, StorageBatch};
55pub use iter::{BlockIterator, EventIterator, MmrNodeIterator};
56pub use mmap::{MmapConfig, MmapStats, MmapStorage};
57pub use rocks::RocksStorage;
58pub use snapshot::{
59    ImportPhase, ImportProgress, PruneConfig, PruneStats, Snapshot, SnapshotBuilder, SnapshotError,
60    SnapshotHeader, SnapshotReader, SNAPSHOT_MAGIC, SNAPSHOT_VERSION,
61};
62pub use traits::{BlockStore, ChainStore, EventStore};