pub struct Pager { /* private fields */ }Expand description
Page I/O Manager
Handles reading/writing pages and manages the page cache.
Implementations§
Source§impl Pager
impl Pager
Sourcepub fn open<P: AsRef<Path>>(
path: P,
config: PagerConfig,
) -> Result<Self, PagerError>
pub fn open<P: AsRef<Path>>( path: P, config: PagerConfig, ) -> Result<Self, PagerError>
Open or create a database file
Sourcepub fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, PagerError>
pub fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, PagerError>
Open with default configuration
Sourcepub fn read_page_no_checksum(&self, page_id: u32) -> Result<Page, PagerError>
pub fn read_page_no_checksum(&self, page_id: u32) -> Result<Page, PagerError>
Read a page without verifying checksum (for encrypted pages)
Use this when the page content has its own integrity protection (e.g., AES-GCM authentication tag for encrypted pages).
Sourcepub fn write_page(&self, page_id: u32, page: Page) -> Result<(), PagerError>
pub fn write_page(&self, page_id: u32, page: Page) -> Result<(), PagerError>
Write a page (cache-aware)
Sourcepub fn read_page_decrypted(&self, page_id: u32) -> Result<Page, PagerError>
pub fn read_page_decrypted(&self, page_id: u32) -> Result<Page, PagerError>
Read a page through the configured encryptor if any. Page 0 is always returned plaintext (it carries the encryption marker
- header). Callers that want raw cipher bytes can use
read_page_no_checksumdirectly.
Sourcepub fn write_page_encrypted(
&self,
page_id: u32,
page: Page,
) -> Result<(), PagerError>
pub fn write_page_encrypted( &self, page_id: u32, page: Page, ) -> Result<(), PagerError>
Write a page through the configured encryptor if any. Page 0 bypasses encryption and goes through the normal checksummed path. Encrypted pages skip the checksum update because AES-GCM’s authentication tag is the integrity guarantee.
Sourcepub fn write_page_no_checksum(
&self,
page_id: u32,
page: Page,
) -> Result<(), PagerError>
pub fn write_page_no_checksum( &self, page_id: u32, page: Page, ) -> Result<(), PagerError>
Write a page without updating checksum (for encrypted pages)
Use this when the page content has its own integrity protection (e.g., AES-GCM authentication tag for encrypted pages).
Sourcepub fn allocate_page(&self, page_type: PageType) -> Result<Page, PagerError>
pub fn allocate_page(&self, page_type: PageType) -> Result<Page, PagerError>
Allocate a new page
Sourcepub fn free_page(&self, page_id: u32) -> Result<(), PagerError>
pub fn free_page(&self, page_id: u32) -> Result<(), PagerError>
Free a page (return to freelist)
Sourcepub fn header(&self) -> Result<DatabaseHeader, PagerError>
pub fn header(&self) -> Result<DatabaseHeader, PagerError>
Get database header
pub fn physical_header(&self) -> Result<PhysicalFileHeader, PagerError>
pub fn update_physical_header( &self, physical: PhysicalFileHeader, ) -> Result<(), PagerError>
Sourcepub fn page_count(&self) -> Result<u32, PagerError>
pub fn page_count(&self) -> Result<u32, PagerError>
Get page count
Sourcepub fn set_wal_writer(&self, wal: Arc<Mutex<WalWriter>>)
pub fn set_wal_writer(&self, wal: Arc<Mutex<WalWriter>>)
Attach a WAL writer to enforce WAL-first flush ordering.
After this call, Pager::flush computes the maximum
header.lsn over all dirty pages and calls
WalWriter::flush_until(max_lsn) before any page is written
to the data file. This is the postgres rule: a page on disk
implies its WAL record is already durable on disk.
Existing call sites that construct a Pager without a WAL keep their previous behaviour (no LSN check) — wiring is strictly opt-in.
Sourcepub fn clear_wal_writer(&self)
pub fn clear_wal_writer(&self)
Detach the WAL writer (test / shutdown path).
Sourcepub fn has_wal_writer(&self) -> bool
pub fn has_wal_writer(&self) -> bool
Has a WAL writer been attached?
Sourcepub fn flush(&self) -> Result<(), PagerError>
pub fn flush(&self) -> Result<(), PagerError>
Flush all dirty pages to disk
Sourcepub fn sync(&self) -> Result<(), PagerError>
pub fn sync(&self) -> Result<(), PagerError>
Sync file to disk (fsync)
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn dirty_page_count(&self) -> usize
pub fn dirty_page_count(&self) -> usize
Count dirty pages currently in the page cache.
Sourcepub fn dirty_fraction(&self) -> f64
pub fn dirty_fraction(&self) -> f64
Estimated fraction of the page cache holding dirty pages.
Returned in [0, 1]. Used by the background writer to
decide when to kick in aggressive flushing.
Sourcepub fn flush_some_dirty(&self, max: usize) -> Result<usize, PagerError>
pub fn flush_some_dirty(&self, max: usize) -> Result<usize, PagerError>
Flush up to max dirty pages from the cache. Returns the
number actually written. Background-writer entry point —
reuses the same persistence path as flush() but bounded.
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Check if database is read-only
Sourcepub fn file_size(&self) -> Result<u64, PagerError>
pub fn file_size(&self) -> Result<u64, PagerError>
Get file size in bytes
Sourcepub fn prefetch_hint(&self, page_id: u32)
pub fn prefetch_hint(&self, page_id: u32)
Issue an OS-level read-ahead hint for page_id.
A6 prefetch wire: called from BTreeCursor::next when the
cursor passes 50% of the current leaf, so the kernel fetches
the next leaf page while CPU processes the remaining half of
the current one. Failures are silent — a missed prefetch is a
performance miss, never a correctness bug.
Sourcepub fn write_meta_shadow(&self, page: &Page) -> Result<(), PagerError>
pub fn write_meta_shadow(&self, page: &Page) -> Result<(), PagerError>
Write a shadow copy of the metadata page to .rdb-meta
Sourcepub fn recover_meta_from_shadow(&self) -> Result<Page, PagerError>
pub fn recover_meta_from_shadow(&self) -> Result<Page, PagerError>
Recover metadata page from shadow file when page 1 is corrupted
Sourcepub fn write_header_and_sync(&self) -> Result<(), PagerError>
pub fn write_header_and_sync(&self) -> Result<(), PagerError>
Write header and sync to disk (public for checkpointer).
Sourcepub fn set_checkpoint_in_progress(
&self,
in_progress: bool,
target_lsn: u64,
) -> Result<(), PagerError>
pub fn set_checkpoint_in_progress( &self, in_progress: bool, target_lsn: u64, ) -> Result<(), PagerError>
Set the checkpoint_in_progress flag in the header.
Sourcepub fn complete_checkpoint(&self, lsn: u64) -> Result<(), PagerError>
pub fn complete_checkpoint(&self, lsn: u64) -> Result<(), PagerError>
Update the checkpoint LSN and clear the in-progress flag.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Pager
impl RefUnwindSafe for Pager
impl Send for Pager
impl Sync for Pager
impl Unpin for Pager
impl UnsafeUnpin for Pager
impl UnwindSafe for Pager
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
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request