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.
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(&mut self) -> MenteResult<usize>
pub fn recover(&mut 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(&mut self) -> MenteResult<()>
pub fn close(&mut self) -> MenteResult<()>
Gracefully shut down: flush dirty pages, sync files.
Sourcepub fn allocate_page(&mut self) -> MenteResult<PageId>
pub fn allocate_page(&mut self) -> MenteResult<PageId>
Allocate a fresh page.
Sourcepub fn read_page(&mut self, page_id: PageId) -> MenteResult<Box<Page>>
pub fn read_page(&mut self, page_id: PageId) -> MenteResult<Box<Page>>
Read a page through the buffer pool.
Sourcepub fn write_page(&mut self, page_id: PageId, data: &[u8]) -> MenteResult<()>
pub fn write_page(&mut self, page_id: PageId, data: &[u8]) -> MenteResult<()>
Write data into a page with WAL protection.
Sourcepub fn store_memory(&mut self, node: &MemoryNode) -> MenteResult<PageId>
pub fn store_memory(&mut 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(&mut self, page_id: PageId) -> MenteResult<MemoryNode>
pub fn load_memory(&mut self, page_id: PageId) -> MenteResult<MemoryNode>
Load and deserialize a MemoryNode from the given page.
Sourcepub fn checkpoint(&mut self) -> MenteResult<()>
pub fn checkpoint(&mut self) -> MenteResult<()>
Checkpoint: flush all dirty pages, sync to disk, and truncate the WAL.
Sourcepub fn scan_all_memories(&mut self) -> Vec<(MemoryId, PageId)>
pub fn scan_all_memories(&mut 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.