pub struct StorageEngine { /* private fields */ }Expand description
The unified storage engine for MenteDB.
Coordinates page allocation, caching, and write-ahead logging to provide crash-safe, page-oriented storage for memory nodes.
All internal state is protected by fine-grained locks so every public method
takes &self, enabling concurrent reads from multiple threads.
Implementations§
Source§impl StorageEngine
impl StorageEngine
Sourcepub fn open(path: &Path) -> MenteResult<Self>
pub fn open(path: &Path) -> MenteResult<Self>
Open (or create) a storage engine rooted at path.
path must be a directory; it will be created if it does not exist.
After opening, any uncommitted WAL entries are replayed for crash recovery.
Sourcepub fn recover(&self) -> MenteResult<usize>
pub fn recover(&self) -> MenteResult<usize>
Replay WAL entries to recover writes that were not checkpointed.
For each PageWrite entry the serialized data is written back to its page.
After replay the WAL is truncated. Returns the number of entries replayed.
Sourcepub fn close(&self) -> MenteResult<()>
pub fn close(&self) -> MenteResult<()>
Gracefully shut down: flush dirty pages, sync files.
Sourcepub fn allocate_page(&self) -> MenteResult<PageId>
pub fn allocate_page(&self) -> MenteResult<PageId>
Allocate a fresh page.
Sourcepub fn read_page(&self, page_id: PageId) -> MenteResult<Box<Page>>
pub fn read_page(&self, page_id: PageId) -> MenteResult<Box<Page>>
Read a page through the buffer pool.
Sourcepub fn write_page(&self, page_id: PageId, data: &[u8]) -> MenteResult<()>
pub fn write_page(&self, page_id: PageId, data: &[u8]) -> MenteResult<()>
Write data into a page with WAL protection.
Sourcepub fn store_memory(&self, node: &MemoryNode) -> MenteResult<PageId>
pub fn store_memory(&self, node: &MemoryNode) -> MenteResult<PageId>
Serialize and store a MemoryNode into a single page.
Returns the PageId where the node was stored.
Sourcepub fn load_memory(&self, page_id: PageId) -> MenteResult<MemoryNode>
pub fn load_memory(&self, page_id: PageId) -> MenteResult<MemoryNode>
Load and deserialize a MemoryNode from the given page.
Sourcepub fn checkpoint(&self) -> MenteResult<()>
pub fn checkpoint(&self) -> MenteResult<()>
Checkpoint: flush all dirty pages, sync to disk, and truncate the WAL.
Sourcepub fn scan_all_memories(&self) -> Vec<(MemoryId, PageId)>
pub fn scan_all_memories(&self) -> Vec<(MemoryId, PageId)>
Scan all pages and return (MemoryId, PageId) pairs for every valid memory node.
Used to rebuild the page map on startup.