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>
impl<F: FileBackend> ReaderSnapshot<F>
Sourcepub fn pinned_lsn(&self) -> Lsn
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.
Sourcepub fn frozen_pages(&self) -> impl Iterator<Item = (PageId, &Page)> + '_
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.
Sourcepub fn frozen_header(&self) -> Option<&Page>
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.
Sourcepub fn id(&self) -> SnapshotId
pub fn id(&self) -> SnapshotId
Snapshot id. Diagnostic-only.
Sourcepub fn root_catalog(&self) -> u64
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.
Sourcepub fn read_page(&self, pager: &Pager<F>, id: PageId) -> Result<Page>
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):
- Frozen view (WAL frames at LSN ≤
pinned_lsnat snapshot creation time). Returns an ownedPageclone. - Main file via the pager (cache-bypassed; goes through
read_throughwhich 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
Error::InvalidArgumentifidis out of range.Error::Ioon syscall failure during the main-file read.Error::Corruptionif the on-disk page trailer fails to verify.