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
§Rec 11: Consolidated
Delegates binary-search logic to BinarySearchChain<Version> from sochdb-core,
eliminating duplication with mvcc_concurrent::VersionChain.
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
§Complexity: O(1) + O(log v) = O(log v)
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 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
Source§impl MvccVersionChain for VersionChain
impl MvccVersionChain for VersionChain
Source§fn get_visible(&self, ctx: &VisibilityContext) -> Option<&Self::Value>
fn get_visible(&self, ctx: &VisibilityContext) -> Option<&Self::Value>
Source§fn get_latest(&self) -> Option<&Self::Value>
fn get_latest(&self) -> Option<&Self::Value>
Source§fn version_count(&self) -> usize
fn version_count(&self) -> usize
Source§impl MvccVersionChainMut for VersionChain
impl MvccVersionChainMut for VersionChain
Source§impl WriteConflictDetection for VersionChain
impl WriteConflictDetection for VersionChain
Source§fn has_write_conflict(&self, txn_id: TxnId) -> bool
fn has_write_conflict(&self, txn_id: TxnId) -> bool
Auto Trait Implementations§
impl Freeze for VersionChain
impl RefUnwindSafe for VersionChain
impl Send for VersionChain
impl Sync for VersionChain
impl Unpin for VersionChain
impl UnsafeUnpin for VersionChain
impl UnwindSafe for VersionChain
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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