pub struct PayloadStore { /* private fields */ }Expand description
Payload storage engine
Architecture:
- Append-only payload file (payload.data)
- In-memory index: edge_id -> (offset, length, compression)
- Memory-mapped reads for zero-copy access
- Write-ahead log for crash recovery
Thread Safety:
- Reads: Lock-free via memory map (multiple concurrent readers)
- Writes: Serialized via RwLock (single writer)
- Index: Protected by RwLock
SCALABILITY:
- HashMap backend (default): Fast but uses ~50MB RAM per 1M payloads (32 bytes per entry + overhead). Suitable for < 10M traces.
- DiskHash backend: Disk-backed hash table scales to billions with minimal RAM. Recommended for 10M+ traces.
Usage:
use sochdb_storage::payload::{PayloadStore, IndexBackend};
// Default: in-memory HashMap
let store = PayloadStore::open("./data").unwrap();
// For 10M+ scale: disk-backed hash table
let store = PayloadStore::open_with_backend("./data", IndexBackend::DiskHash).unwrap();Implementations§
Source§impl PayloadStore
impl PayloadStore
Sourcepub fn open<P: AsRef<Path>>(data_dir: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(data_dir: P) -> Result<Self>
Open or create a payload store with default HashMap index
Sourcepub fn open_with_backend<P: AsRef<Path>>(
data_dir: P,
backend: IndexBackend,
) -> Result<Self>
pub fn open_with_backend<P: AsRef<Path>>( data_dir: P, backend: IndexBackend, ) -> Result<Self>
Open or create a payload store with specified index backend
Sourcepub fn append(
&self,
edge_id: u128,
data: &[u8],
compression: Option<CompressionType>,
) -> Result<(u64, u32, u8)>
pub fn append( &self, edge_id: u128, data: &[u8], compression: Option<CompressionType>, ) -> Result<(u64, u32, u8)>
Append a payload and return (offset, length, compression_type)
Compression Strategy:
- Small payloads (<1KB): No compression (overhead > benefit)
- Medium payloads (1KB-100KB): LZ4 (fast compression/decompression)
- Large payloads (>100KB): ZSTD (higher compression ratio)
This can be overridden by specifying compression_type explicitly.
DESKTOP APP FIX: Monitors memory growth and logs warnings at thresholds to prevent silent OOM in long-running sessions.
Sourcepub fn get_at_offset(
&self,
offset: u64,
length: u32,
compression: CompressionType,
) -> Result<Vec<u8>>
pub fn get_at_offset( &self, offset: u64, length: u32, compression: CompressionType, ) -> Result<Vec<u8>>
Get a payload at a specific offset
This is used when reading edges from SSTables that have embedded (offset, length, compression) tuples.
Sourcepub fn has_payload(&self, edge_id: u128) -> bool
pub fn has_payload(&self, edge_id: u128) -> bool
Check if a payload exists for an edge
Sourcepub fn save_index(&self) -> Result<()>
pub fn save_index(&self) -> Result<()>
Save index to disk for fast recovery (delegates to backend)
Sourcepub fn stats(&self) -> PayloadStats
pub fn stats(&self) -> PayloadStats
Get statistics
Trait Implementations§
Source§impl Drop for PayloadStore
impl Drop for PayloadStore
Auto Trait Implementations§
impl !RefUnwindSafe for PayloadStore
impl !UnwindSafe for PayloadStore
impl Freeze for PayloadStore
impl Send for PayloadStore
impl Sync for PayloadStore
impl Unpin for PayloadStore
impl UnsafeUnpin for PayloadStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more