Skip to main content

ReaderSnapshot

Struct ReaderSnapshot 

Source
pub struct ReaderSnapshot<F: FileBackend> { /* private fields */ }
Expand description

A reader-side MVCC snapshot of the database.

Captures the WAL end-LSN at construction and a clone of the pager’s in-memory committed view. Reads through the snapshot observe main file ∪ WAL frames with LSN ≤ pinned_lsn; pending writes from a concurrent WriteTxn are NEVER visible.

ReaderSnapshot is Send so the user-facing read transaction can run on any thread. It is NOT Clone — each snapshot owns its own pin and cloning would double-register the pin entry.

Generic over F: FileBackend (Rule 9: no dyn); the production snapshot is ReaderSnapshot<FileHandle>. Read calls take a &mut Pager<F> parameter so the borrow checker can prove that the cache mutation a cache-miss read performs cannot race the snapshot’s own view; in practice the Db wraps the pager in a Mutex (M6 issue #47) and the snapshot’s pin is independent of the mutex.

Implementations§

Source§

impl<F: FileBackend> ReaderSnapshot<F>

Source

pub fn pinned_lsn(&self) -> Lsn

The LSN this snapshot pinned at construction. Reads through the snapshot only observe WAL frames with LSN <= pinned_lsn.

Source

pub fn frozen_pages(&self) -> impl Iterator<Item = (PageId, &Page)> + '_

Iterate over every (PageId, &Page) pair in the snapshot’s frozen WAL view — i.e. every WAL frame at LSN <= pinned_lsn at the moment the snapshot was created. Used by M11 #92 (Db::backup_to) to overlay the snapshot’s view onto a freshly-copied main file.

Source

pub fn frozen_header(&self) -> Option<&Page>

The WAL-staged page-0 (file header) frame at the snapshot’s pinned LSN, or None if no header frame sits in the committed view. Used by M11 #92 (Db::backup_to) to reconstruct the header bytes the snapshot would observe.

Source

pub fn id(&self) -> SnapshotId

Snapshot id. Diagnostic-only.

Source

pub fn root_catalog(&self) -> u64

M6 #51: the catalog B-tree root page-id this snapshot pinned. A concurrent WriteTxn that calls crate::pager::Pager::set_root_catalog does NOT mutate the value returned here — the snapshot is frozen at pin time. Use this when constructing a read-side crate::Catalog handle that should observe the catalog at the snapshot’s LSN.

Source

pub fn read_page(&self, pager: &Pager<F>, id: PageId) -> Result<Page>

Read page id consistent with the snapshot’s pin.

Lookup order (file-backed pagers):

  1. Frozen view (WAL frames at LSN ≤ pinned_lsn at snapshot creation time). Returns an owned Page clone.
  2. Main file via the pager (cache-bypassed; goes through read_through which verifies the page trailer).

On in-memory pagers (Pager::memory) there is no WAL and no MVCC: the snapshot’s frozen_view is always empty and the in-memory backend buffer may lag the cache (dirty cache frames have not yet been written back). For that mode the snapshot falls through to the LIVE cache (then main backend); the WAL overlay does not exist. No concurrent writer can race a reader on a memory pager, so the live read is the snapshot read.

§Errors

Trait Implementations§

Source§

impl<F: Debug + FileBackend> Debug for ReaderSnapshot<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> Freeze for ReaderSnapshot<F>

§

impl<F> RefUnwindSafe for ReaderSnapshot<F>

§

impl<F> Send for ReaderSnapshot<F>

§

impl<F> Sync for ReaderSnapshot<F>

§

impl<F> Unpin for ReaderSnapshot<F>

§

impl<F> UnsafeUnpin for ReaderSnapshot<F>

§

impl<F> UnwindSafe for ReaderSnapshot<F>

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, 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V