pub trait TieredStore: Send + Sync {
// Required methods
fn estimated_ram_bytes(&self) -> usize;
fn tier(&self) -> StorageTier;
fn persist(&self, path: &Path) -> Result<()>;
fn open_mmap(&self, path: &Path) -> Result<()>;
fn reload_to_ram(&self) -> Result<()>;
}Expand description
A storage subsystem that can transition between RAM and disk tiers.
Implementors manage their own data layout for both tiers. The
BufferManager triggers transitions via the
MemoryConsumer trait; this trait provides
the mechanics of persisting, mapping, and reloading data.
§Crate boundaries
This trait lives in grafeo-common so it can be referenced by both
grafeo-core (section serializers) and grafeo-engine (orchestration).
Implementations that need filesystem I/O (mmap, file creation) should
live in grafeo-engine, not grafeo-core.
Required Methods§
Sourcefn estimated_ram_bytes(&self) -> usize
fn estimated_ram_bytes(&self) -> usize
Estimated RAM footprint in bytes if built entirely in memory.
Returns 0 when the structure is on disk or uninitialized.
Sourcefn tier(&self) -> StorageTier
fn tier(&self) -> StorageTier
Current storage tier.
Sourcefn persist(&self, path: &Path) -> Result<()>
fn persist(&self, path: &Path) -> Result<()>
Serializes in-memory state to the given path.
After this call, open_mmap can serve reads
from the file. This does NOT free RAM: the caller should drop the
in-memory representation separately (typically via the
MemoryConsumer::spill path).
§Errors
Returns an error if serialization or I/O fails.
Sourcefn open_mmap(&self, path: &Path) -> Result<()>
fn open_mmap(&self, path: &Path) -> Result<()>
Switches to mmap-backed reads from a previously persisted file.
Drops the in-memory data and serves reads through the OS page cache.
The tier transitions to StorageTier::OnDisk.
§Errors
Returns an error if the file cannot be memory-mapped.
Sourcefn reload_to_ram(&self) -> Result<()>
fn reload_to_ram(&self) -> Result<()>
Reloads data from disk back into RAM.
The tier transitions to StorageTier::InMemory. Used when memory
becomes available and faster access is desired.
§Errors
Returns an error if deserialization fails.