Skip to main content

BinarySearchChain

Struct BinarySearchChain 

Source
pub struct BinarySearchChain<E: ChainEntry> { /* private fields */ }
Expand description

A binary-search optimized version chain — the consolidated core.

Stores committed versions sorted descending by commit_ts, with at most one uncommitted version slot. Uses partition_point for O(log V) lookups.

This struct captures the duplicated logic previously in:

  • durable_storage::VersionChain
  • mvcc_concurrent::VersionChain

Both modules now wrap BinarySearchChain<E> and delegate the core binary-search / commit / abort / read / conflict-check operations to it.

Implementations§

Source§

impl<E: ChainEntry> BinarySearchChain<E>

Source

pub fn new() -> Self

Create a new empty chain.

Source

pub fn set_uncommitted(&mut self, entry: E) -> Option<E>

Replace the uncommitted slot. Returns the previous entry if any.

Source

pub fn uncommitted(&self) -> Option<&E>

Reference to the uncommitted entry.

Source

pub fn uncommitted_mut(&mut self) -> Option<&mut E>

Mutable reference to the uncommitted entry.

Source

pub fn commit(&mut self, txn_id: u64, commit_ts: u64) -> bool

Commit the uncommitted version with the given commit_ts.

Moves the entry from the uncommitted slot into the sorted committed list at the correct position. Returns true on success.

Complexity: O(log V) binary search + O(V) insert (amortised O(1) for newest).

Source

pub fn abort(&mut self, txn_id: u64)

Abort a transaction — clear the uncommitted slot if it matches txn_id.

Source

pub fn read_at( &self, snapshot_ts: u64, current_txn_id: Option<u64>, ) -> Option<&E>

Read the visible version at the given snapshot timestamp.

If current_txn_id is provided and matches the uncommitted version’s transaction, the uncommitted version is returned (read-own-writes).

Otherwise performs O(log V) binary search for the newest committed version with commit_ts < snapshot_ts.

Source

pub fn has_write_conflict(&self, my_txn_id: u64) -> bool

Check if there’s a write-write conflict with another transaction.

Source

pub fn gc_by_ts(&mut self, min_active_ts: u64)

GC versions older than min_active_ts.

Retention must agree with read_at, whose visibility rule is strict: a reader at snapshot S observes the newest version with commit_ts < S. The smallest live snapshot is min_active_ts, so the oldest version any reader can still need is the newest one with commit_ts < min_active_ts. We therefore keep every version with commit_ts >= min_active_ts plus one anchor — the newest version strictly below min_active_ts.

Using >= here (rather than >) is load-bearing for read-safety: with >, a boundary version whose commit_ts == min_active_ts would be chosen as the anchor and the genuinely-needed older version (the one a reader at snapshot == min_active_ts resolves, since that boundary version is not visible to it under the strict < rule) would be freed — causing the reader to observe a spurious None.

Source

pub fn version_count(&self) -> usize

Total version count (committed + uncommitted).

Source

pub fn committed_count(&self) -> usize

Number of committed versions.

Source

pub fn is_empty(&self) -> bool

Check if chain is empty.

Source

pub fn committed_versions(&self) -> &[E]

Slice of committed versions (newest first).

Source

pub fn committed_versions_mut(&mut self) -> &mut Vec<E>

Mutable access to committed versions (for custom GC).

Source

pub fn latest(&self) -> Option<&E>

Latest version: uncommitted if present, else newest committed.

Source

pub fn latest_committed(&self) -> Option<&E>

Newest committed version only.

Trait Implementations§

Source§

impl<E: Debug + ChainEntry> Debug for BinarySearchChain<E>

Source§

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

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

impl<E: ChainEntry> Default for BinarySearchChain<E>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<E> Freeze for BinarySearchChain<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for BinarySearchChain<E>
where E: RefUnwindSafe,

§

impl<E> Send for BinarySearchChain<E>
where E: Send,

§

impl<E> Sync for BinarySearchChain<E>
where E: Sync,

§

impl<E> Unpin for BinarySearchChain<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for BinarySearchChain<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for BinarySearchChain<E>
where E: UnwindSafe,

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> 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, 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.