pub struct PageManager { /* private fields */ }Expand description
Manages a file-backed page store with free-list allocation.
Implementations§
Source§impl PageManager
impl PageManager
Sourcepub fn open(dir_path: &Path) -> MenteResult<Self>
pub fn open(dir_path: &Path) -> MenteResult<Self>
Open (or create) a page file at dir_path/pages.db.
Sourcepub fn reload_header(&mut self) -> MenteResult<()>
pub fn reload_header(&mut self) -> MenteResult<()>
Re-read the file header from disk to pick up changes made by another process.
Sourcepub fn allocate_page(&mut self) -> MenteResult<PageId>
pub fn allocate_page(&mut self) -> MenteResult<PageId>
Allocate a new page, reusing from the free list when possible.
Sourcepub fn write_page(&mut self, page_id: PageId, page: &Page) -> MenteResult<()>
pub fn write_page(&mut self, page_id: PageId, page: &Page) -> MenteResult<()>
Write a page to disk.
Sourcepub fn free_page(&mut self, page_id: PageId) -> MenteResult<()>
pub fn free_page(&mut self, page_id: PageId) -> MenteResult<()>
Return a page to the free list.
Sourcepub fn rebuild_free_list(&mut self) -> MenteResult<()>
pub fn rebuild_free_list(&mut self) -> MenteResult<()>
Rebuild the free list by scanning page types.
Used after WAL recovery: header updates are not fsynced per write, so the persisted free list can disagree with WAL-replayed page states. Page types are WAL-authoritative; the chain is derived from them.
Sourcepub fn rebuild_free_list_from(
&mut self,
pages: &BTreeSet<u64>,
) -> MenteResult<bool>
pub fn rebuild_free_list_from( &mut self, pages: &BTreeSet<u64>, ) -> MenteResult<bool>
Rebuild the free list from a known set of free pages instead of
scanning every page. Every listed page is read first and must be typed
Free; if any is not, nothing is written and false is returned so the
caller falls back to Self::rebuild_free_list. A Data page must never
be put on the free list, since the next allocation would overwrite it.
Sourcepub fn page_count(&self) -> u64
pub fn page_count(&self) -> u64
Total number of pages (including the header page).
Sourcepub fn sync(&mut self) -> MenteResult<()>
pub fn sync(&mut self) -> MenteResult<()>
Sync page file data to disk.