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 the most recent committed transaction ID. All reads using this snapshot are guaranteed to see only data that has been durably committed.
§Implementation Note
- For native-v2 backend: Returns the maximum committed LSN from the WAL manager
- For SQLite backend: Returns 0 to indicate “all committed data”
§Example
let snapshot = SnapshotId::current();
// snapshot now points to the most recent committed transactionSourcepub 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<()> {
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SnapshotId
impl Debug for SnapshotId
Source§impl Hash for SnapshotId
impl Hash for SnapshotId
Source§impl PartialEq for SnapshotId
impl PartialEq for SnapshotId
impl Copy for SnapshotId
impl Eq for SnapshotId
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 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§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<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