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>
impl<B: Backend> MvccEngine<B>
Sourcepub fn backend_mut(&mut self) -> &mut B
pub fn backend_mut(&mut self) -> &mut B
Returns a mutable reference to the underlying backend.
Sourcepub fn read(
&self,
key: &[u8],
read_ts: Timestamp,
) -> Result<Option<Vec<u8>>, ReadError>
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.
Sourcepub fn read_with_version(
&self,
key: &[u8],
read_ts: Timestamp,
) -> Result<Option<(Timestamp, Option<Vec<u8>>)>, ReadError>
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)))).
Sourcepub fn read_own_write(
&self,
key: &[u8],
txn_id: TxnId,
start_ts: Timestamp,
read_ts: Timestamp,
) -> Result<Option<Vec<u8>>, ReadError>
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.
Sourcepub fn prewrite(
&mut self,
txn_id: TxnId,
start_ts: Timestamp,
key: Vec<u8>,
mutation: Mutation,
) -> Result<(), PrewriteError>
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.
Sourcepub fn commit(
&mut self,
txn_id: TxnId,
key: &[u8],
start_ts: Timestamp,
commit_ts: Timestamp,
) -> Result<(), CommitError>
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).
Sourcepub fn abort(
&mut self,
txn_id: TxnId,
key: &[u8],
start_ts: Timestamp,
) -> Result<(), AbortError>
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(()).
Sourcepub fn prewrite_batch(
&mut self,
txn_id: TxnId,
start_ts: Timestamp,
writes: Vec<PhysicalWrite>,
) -> Result<(), BatchPrewriteError>
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.
Sourcepub fn commit_batch(
&mut self,
txn_id: TxnId,
start_ts: Timestamp,
commit_ts: Timestamp,
keys: Vec<Vec<u8>>,
) -> Result<(), BatchCommitError>
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.
Sourcepub fn abort_batch(
&mut self,
txn_id: TxnId,
start_ts: Timestamp,
keys: Vec<Vec<u8>>,
) -> Result<(), BatchAbortError>
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).
Sourcepub fn apply_direct_batch(
&mut self,
commit_ts: Timestamp,
writes: Vec<PhysicalWrite>,
) -> Result<(), BatchError>
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.
Sourcepub fn apply_guarded_batch(
&mut self,
commit_ts: Timestamp,
guards: Vec<ReadGuard>,
writes: Vec<PhysicalWrite>,
) -> Result<(), BatchError>
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.
Sourcepub fn gc_incremental(
&mut self,
safe_point_ts: Timestamp,
cursor: Option<IncrementalGcCursor>,
options: GcOptions,
) -> Result<IncrementalGcResult, GcError>
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.