Skip to main content

MvccEngine

Struct MvccEngine 

Source
pub struct MvccEngine<B: Backend> { /* private fields */ }
Expand description

The central state machine for executing MVCC operations.

MvccEngine wraps a durable Backend and provides high-level APIs for single-key and multi-key reads, transactional intents, and direct batches.

Implementations§

Source§

impl<B: Backend> MvccEngine<B>

Source

pub fn new(backend: B) -> Self

Creates a new MvccEngine with the given backend.

Source

pub fn backend(&self) -> &B

Returns an immutable reference to the underlying backend.

Source

pub fn backend_mut(&mut self) -> &mut B

Returns a mutable reference to the underlying backend.

Source

pub fn read( &self, key: &[u8], read_ts: Timestamp, ) -> Result<Option<Vec<u8>>, ReadError>

Reads the visible value for a key at a given logical read_ts.

This method ignores uncommitted intents and finds the newest committed version that has a commit_ts <= read_ts.

Source

pub fn read_with_version( &self, key: &[u8], read_ts: Timestamp, ) -> Result<Option<(Timestamp, Option<Vec<u8>>)>, ReadError>

Reads the visible value for a key at read_ts and returns its commit timestamp and value.

If no version is visible at or before read_ts, returns Ok(None). If a tombstone is visible, returns Ok(Some((ts, None))). If a value is visible, returns Ok(Some((ts, Some(value)))).

Source

pub fn read_own_write( &self, key: &[u8], txn_id: TxnId, start_ts: Timestamp, read_ts: Timestamp, ) -> Result<Option<Vec<u8>>, ReadError>

Reads the visible value for a key, prioritizing the transaction’s own active intent.

If the transaction has an active intent on the key, its value is returned. Otherwise, it falls back to a normal historical read at read_ts.

Source

pub fn prewrite( &mut self, txn_id: TxnId, start_ts: Timestamp, key: Vec<u8>, mutation: Mutation, ) -> Result<(), PrewriteError>

Prewrites a single intent for a distributed transaction.

Fails if another transaction holds an intent on the key, or if a newer committed version exists (write conflict). It is idempotent for the same transaction and start_ts.

Source

pub fn commit( &mut self, txn_id: TxnId, key: &[u8], start_ts: Timestamp, commit_ts: Timestamp, ) -> Result<(), CommitError>

Commits a single intent, creating a durable version.

Converts the intent at start_ts into a committed version at commit_ts. The backend must execute this atomically (create version and remove intent).

Source

pub fn abort( &mut self, txn_id: TxnId, key: &[u8], start_ts: Timestamp, ) -> Result<(), AbortError>

Aborts a single intent, removing it from the backend.

This method is idempotent: if the intent is not found, it returns Ok(()).

Source

pub fn prewrite_batch( &mut self, txn_id: TxnId, start_ts: Timestamp, writes: Vec<PhysicalWrite>, ) -> Result<(), BatchPrewriteError>

Prewrites multiple intents atomically for a transaction.

Rejects empty batches with EmptyBatch. Identical replay semantics apply as in single-key prewrite.

Source

pub fn commit_batch( &mut self, txn_id: TxnId, start_ts: Timestamp, commit_ts: Timestamp, keys: Vec<Vec<u8>>, ) -> Result<(), BatchCommitError>

Commits multiple intents atomically, creating durable versions.

Rejects empty batches with EmptyBatch.

Source

pub fn abort_batch( &mut self, txn_id: TxnId, start_ts: Timestamp, keys: Vec<Vec<u8>>, ) -> Result<(), BatchAbortError>

Aborts multiple intents, removing them atomically.

If the key list is empty, it returns Ok(()) (idempotent).

Source

pub fn apply_direct_batch( &mut self, commit_ts: Timestamp, writes: Vec<PhysicalWrite>, ) -> Result<(), BatchError>

Applies a batch of writes directly, bypassing intents.

Rejects empty batches with EmptyBatch. Fails if any key has an active intent or if commit_ts is not strictly greater than the latest committed version.

Source

pub fn apply_guarded_batch( &mut self, commit_ts: Timestamp, guards: Vec<ReadGuard>, writes: Vec<PhysicalWrite>, ) -> Result<(), BatchError>

Applies a batch of writes conditionally, validating read guards first.

Useful for Read-Modify-Write operations (e.g. Compare-And-Swap) without interactive two-phase commit transactions. Rejects empty writes or empty guards.

Source

pub fn gc_incremental( &mut self, safe_point_ts: Timestamp, cursor: Option<IncrementalGcCursor>, options: GcOptions, ) -> Result<IncrementalGcResult, GcError>

Performs an incremental step of garbage collection.

Obsolete versions older than safe_point_ts are removed up to the budget.

Source

pub fn gc( &mut self, safe_point_ts: Timestamp, options: GcOptions, ) -> Result<GcStats, GcError>

Performs a full garbage collection by repeatedly calling gc_incremental.

This is maintained for compatibility.

Auto Trait Implementations§

§

impl<B> Freeze for MvccEngine<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for MvccEngine<B>
where B: RefUnwindSafe,

§

impl<B> Send for MvccEngine<B>
where B: Send,

§

impl<B> Sync for MvccEngine<B>
where B: Sync,

§

impl<B> Unpin for MvccEngine<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for MvccEngine<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for MvccEngine<B>
where B: 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.