Skip to main content

Snapshot

Struct Snapshot 

Source
pub struct Snapshot {
    pub version: u64,
    pub in_progress: InProgressSet,
    pub oldest_active: u64,
    pub tx_id: u64,
    pub locked_out: Option<(RelId, BTreeSet<usize>)>,
}
Expand description

Per-statement / per-transaction snapshot.

Cheap to clone (Vec inside an InProgressSet is the only non-Copy field; bounded at active-tx count which is small).

Fields§

§version: u64

The upper bound. A row whose xmin exceeds this is in the snapshot’s future — invisible.

§in_progress: InProgressSet

In-flight transactions at snapshot time.

§oldest_active: u64

Floor used by vacuum. Any row whose xmax < oldest_active is dead to every live snapshot.

§tx_id: u64

The reading transaction’s OWN id. Used to implement “see your own writes” — a row your transaction inserted is visible to you even before commit. 0 for non- transactional reads (autocommit SELECT).

§locked_out: Option<(RelId, BTreeSet<usize>)>

v7.39 (round 297, E3 Phase 1b) — rows a SKIP LOCKED pre-pass found held by another transaction, as (relation, row indices).

It rides the SNAPSHOT because that is the only channel every row source already threads. Adding the filter at individual scan sites missed the real path three times running — index_access alone performs the visibility test in ten places. A row that someone else holds is, for this statement, exactly as unavailable as a row the snapshot cannot see.

Implementations§

Source§

impl Snapshot

Source

pub const fn unbounded() -> Snapshot

A “see everything visible” snapshot — version at the current upper-bound u64, in-progress empty. Equivalent to the pre-v7.37.15 “Arc-snapshot reads the entire catalog” behaviour; useful for phase-A migration where the engine doesn’t yet track per-tx state.

Source

pub fn new( version: u64, in_progress: InProgressSet, oldest_active: u64, tx_id: u64, ) -> Snapshot

Construct from explicit fields. The version cursor and in-progress set come from the engine’s per-process version counter at snapshot time; oldest_active is the MIN of every live snapshot’s version (vacuum reads it).

Source

pub fn visible(&self, h: &RowHeader) -> bool

Should the row be visible to a reader holding this snapshot? The five-step rule mirrors PG’s HeapTupleSatisfiesMVCC.

  1. Self-write: if the row’s writer is THIS reader’s own tx, the row is visible (READ COMMITTED sees its own writes).
  2. xmin in the future: invisible.
  3. xmin still in-progress: invisible.
  4. Alive (xmax == ALIVE): visible.
  5. xmax in the future or in-progress: visible (the delete hasn’t committed yet from this reader’s point of view).
  6. xmax in the past + committed: invisible (deleted before this reader’s snapshot).
Source

pub fn visible_with_status<O>(&self, h: &RowHeader, xact: &O) -> bool
where O: XactStatusOracle + ?Sized,

v7.37.15 (Phase C.2) — abort-aware visibility. Same as Self::visible but consults a XactStatusOracle to distinguish a committed version from an aborted one when neither is in the snapshot’s in_progress set. Phase C.3’s in-place write path needs this: a rolled-back or crash-orphaned version leaves its xmin/xmax stamp physically present until vacuum reclaims it, and the two-state Self::visible would wrongly treat it as committed.

Two extra branches vs visible (marked NEW):

  • xmin aborted → the insert never happened → invisible.
  • xmax aborted → the delete never happened → still visible.

The frozen-and-alive fast path returns before any oracle call, so steady-state scans over old data pay no oracle cost — preserving the Phase B “≤5% overhead” result. Passing AllCommitted makes this behave exactly like visible.

Trait Implementations§

Source§

impl Clone for Snapshot

Source§

fn clone(&self) -> Snapshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Snapshot

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Snapshot

Source§

fn default() -> Snapshot

Returns the “default value” for a type. Read more
Source§

impl Eq for Snapshot

Source§

impl PartialEq for Snapshot

Source§

fn eq(&self, other: &Snapshot) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Snapshot

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.