pub struct VersionChain { /* private fields */ }Expand description
Multi-version data for a single key with O(log v) read complexity
§Optimization: Binary Search with Sorted Commit Ordering
Separates committed versions (sorted descending by commit_ts) from uncommitted version (single optional slot per transaction).
Before: O(v) linear scan + O(v) max computation = O(v) After: O(1) uncommitted check + O(log v) binary search = O(log v)
For v=10 versions: 3.3x speedup For v=100 versions: 7x speedup
Implementations§
Source§impl VersionChain
impl VersionChain
Sourcepub fn add_uncommitted(&mut self, value: Option<Vec<u8>>, txn_id: u64)
pub fn add_uncommitted(&mut self, value: Option<Vec<u8>>, txn_id: u64)
Add a new uncommitted version If there’s already an uncommitted version from this txn, update it in place
O(1) - just updates the uncommitted slot
Sourcepub fn commit(&mut self, txn_id: u64, commit_ts: u64) -> bool
pub fn commit(&mut self, txn_id: u64, commit_ts: u64) -> bool
Commit a version - moves from uncommitted slot to sorted committed list
O(log v) - inserts into sorted position using binary search
Sourcepub fn abort(&mut self, txn_id: u64)
pub fn abort(&mut self, txn_id: u64)
Abort a version (remove uncommitted version for txn)
O(1) - just clears the uncommitted slot if it matches
Sourcepub fn read_at(
&self,
snapshot_ts: u64,
current_txn_id: Option<u64>,
) -> Option<&Version>
pub fn read_at( &self, snapshot_ts: u64, current_txn_id: Option<u64>, ) -> Option<&Version>
Read at a snapshot timestamp, optionally seeing own uncommitted writes Returns the most recent committed version visible at snapshot_ts, or an uncommitted version if it belongs to current_txn_id.
§Complexity: O(1) + O(log v) = O(log v)
- O(1) check for uncommitted version from current transaction
- O(log v) binary search for most recent visible committed version
Snapshot isolation: we see commits with commit_ts < snapshot_ts (strictly less)
Sourcepub fn has_write_conflict(&self, my_txn_id: u64) -> bool
pub fn has_write_conflict(&self, my_txn_id: u64) -> bool
Check if there’s an uncommitted version by another transaction
O(1) - just checks the uncommitted slot
Sourcepub fn gc(&mut self, min_active_ts: u64)
pub fn gc(&mut self, min_active_ts: u64)
Garbage collect old versions
Keeps only versions that might be visible to active transactions, plus one committed version before min_active_ts for new snapshots.
Sourcepub fn version_count(&self) -> usize
pub fn version_count(&self) -> usize
Get total version count (committed + uncommitted)
Trait Implementations§
Source§impl Debug for VersionChain
impl Debug for VersionChain
Source§impl Default for VersionChain
impl Default for VersionChain
Source§fn default() -> VersionChain
fn default() -> VersionChain
Auto Trait Implementations§
impl Freeze for VersionChain
impl RefUnwindSafe for VersionChain
impl Send for VersionChain
impl Sync for VersionChain
impl Unpin for VersionChain
impl UnwindSafe for VersionChain
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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