pub struct SnapshotId(pub u64);Expand description
Snapshot identifier - points to committed transaction state
Only data committed at or before this snapshot_id is visible. If a value cannot be tied to a committed snapshot_id → it does not exist.
§Invariant
snapshot_id.0 MUST correspond to a committed transaction. Uncommitted transactions do not create valid snapshots.
§Representation
Internally, SnapshotId wraps a TransactionId (u64). This is valid because:
- TransactionId is allocated at begin_transaction()
- SnapshotId is created at commit_transaction()
- The 1:1 mapping ensures snapshot_id uniquely identifies committed state
Tuple Fields§
§0: u64Implementations§
Source§impl SnapshotId
impl SnapshotId
Sourcepub fn current() -> Self
pub fn current() -> Self
The “current” snapshot - sees only committed data
This returns a special sentinel value (0) that represents “all committed data”. All reads using this snapshot are guaranteed to see only data that has been durably committed.
§Backend Behavior
- SQLite backend: Uses SnapshotId(0) to indicate “current” (no historical snapshots)
- Native-v3 backend: May use SnapshotId(0) or use
new_incrementing()for sequential snapshots
§Why SnapshotId(0)?
SQLite backend does not support historical snapshots (no AS OF queries or MVCC). Only the current committed state is accessible, which we represent as SnapshotId(0).
§Example
let snapshot = SnapshotId::current();
// snapshot is now SnapshotId(0) - "current committed data"Sourcepub fn new_incrementing() -> Self
pub fn new_incrementing() -> Self
Create a new incrementing snapshot ID
This generates a new snapshot ID using a global atomic counter. Each call returns a unique, monotonically increasing snapshot ID.
§When to Use
- Native-v3 backend: Use this when you need unique snapshot IDs for MVCC
- SQLite backend: Do NOT use this - SQLite only supports SnapshotId(0)
§Example
let snapshot1 = SnapshotId::new_incrementing();
let snapshot2 = SnapshotId::new_incrementing();
assert!(snapshot2.as_u64() > snapshot1.as_u64());Sourcepub fn from_tx(tx_id: u64) -> Self
pub fn from_tx(tx_id: u64) -> Self
Create from explicit transaction ID
§Arguments
tx_id- A committed transaction ID
§Important
The caller MUST ensure that tx_id corresponds to a committed transaction. Using an uncommitted transaction ID violates snapshot isolation guarantees.
§Example
// After commit returns SnapshotId
let snapshot = coordinator.commit_transaction(tx_id)?;
// Later, reuse same snapshot for repeatable reads
let node = backend.get_node(snapshot, node_id)?;Sourcepub fn from_lsn(lsn: u64) -> Self
pub fn from_lsn(lsn: u64) -> Self
Create snapshot from explicit LSN (Log Sequence Number)
§Arguments
lsn- A commit LSN representing a committed transaction
§Important
The caller MUST ensure that lsn corresponds to a committed transaction. Using an uncommitted LSN violates snapshot isolation guarantees.
§Example
// Create snapshot at specific LSN
let snapshot = SnapshotId::from_lsn(12345);Sourcepub fn invalid() -> Self
pub fn invalid() -> Self
Invalid snapshot - used for error cases
This sentinel value indicates that no valid snapshot exists. Read operations receiving this snapshot should return an error.
§Example
fn validate_snapshot(snapshot: SnapshotId) -> Result<(), &'static str> {
if snapshot == SnapshotId::invalid() {
return Err("Invalid snapshot");
}
Ok(())
}Trait Implementations§
Source§impl Clone for SnapshotId
impl Clone for SnapshotId
Source§fn clone(&self) -> SnapshotId
fn clone(&self) -> SnapshotId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SnapshotId
Source§impl Debug for SnapshotId
impl Debug for SnapshotId
impl Eq for SnapshotId
Source§impl Hash for SnapshotId
impl Hash for SnapshotId
Source§impl PartialEq for SnapshotId
impl PartialEq for SnapshotId
Source§fn eq(&self, other: &SnapshotId) -> bool
fn eq(&self, other: &SnapshotId) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SnapshotId
Auto Trait Implementations§
impl Freeze for SnapshotId
impl RefUnwindSafe for SnapshotId
impl Send for SnapshotId
impl Sync for SnapshotId
impl Unpin for SnapshotId
impl UnsafeUnpin for SnapshotId
impl UnwindSafe for SnapshotId
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 more