Skip to main content

Pager

Struct Pager 

Source
pub struct Pager { /* private fields */ }
Expand description

Page I/O Manager

Handles reading/writing pages and manages the page cache.

Implementations§

Source§

impl Pager

Source

pub fn open<P: AsRef<Path>>( path: P, config: PagerConfig, ) -> Result<Self, PagerError>

Open or create a database file

Source

pub fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, PagerError>

Open with default configuration

Source

pub fn read_page(&self, page_id: u32) -> Result<Page, PagerError>

Read a page (cache-aware)

Source

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).

Source

pub fn write_page(&self, page_id: u32, page: Page) -> Result<(), PagerError>

Write a page (cache-aware)

Source

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_checksum directly.
Source

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.

Source

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).

Source

pub fn allocate_page(&self, page_type: PageType) -> Result<Page, PagerError>

Allocate a new page

Source

pub fn free_page(&self, page_id: u32) -> Result<(), PagerError>

Free a page (return to freelist)

Source

pub fn header(&self) -> Result<DatabaseHeader, PagerError>

Get database header

Source

pub fn physical_header(&self) -> Result<PhysicalFileHeader, PagerError>

Source

pub fn update_physical_header( &self, physical: PhysicalFileHeader, ) -> Result<(), PagerError>

Source

pub fn page_count(&self) -> Result<u32, PagerError>

Get page count

Source

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.

Source

pub fn clear_wal_writer(&self)

Detach the WAL writer (test / shutdown path).

Source

pub fn has_wal_writer(&self) -> bool

Has a WAL writer been attached?

Source

pub fn flush(&self) -> Result<(), PagerError>

Flush all dirty pages to disk

Source

pub fn sync(&self) -> Result<(), PagerError>

Sync file to disk (fsync)

Source

pub fn cache_stats(&self) -> CacheStats

Get cache statistics

Source

pub fn dirty_page_count(&self) -> usize

Count dirty pages currently in the page cache.

Source

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.

Source

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.

Source

pub fn path(&self) -> &Path

Get database file path

Source

pub fn is_read_only(&self) -> bool

Check if database is read-only

Source

pub fn file_size(&self) -> Result<u64, PagerError>

Get file size in bytes

Source

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.

Source

pub fn write_meta_shadow(&self, page: &Page) -> Result<(), PagerError>

Write a shadow copy of the metadata page to .rdb-meta

Source

pub fn recover_meta_from_shadow(&self) -> Result<Page, PagerError>

Recover metadata page from shadow file when page 1 is corrupted

Source

pub fn write_header_and_sync(&self) -> Result<(), PagerError>

Write header and sync to disk (public for checkpointer).

Source

pub fn set_checkpoint_in_progress( &self, in_progress: bool, target_lsn: u64, ) -> Result<(), PagerError>

Set the checkpoint_in_progress flag in the header.

Source

pub fn complete_checkpoint(&self, lsn: u64) -> Result<(), PagerError>

Update the checkpoint LSN and clear the in-progress flag.

Trait Implementations§

Source§

impl Drop for Pager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more