pub struct Transaction<'db> { /* private fields */ }Expand description
An in-flight cross-table transaction. Holds a read snapshot taken at begin
and stages writes; nothing is durable or visible until Self::commit.
S1B-001 state: the transaction carries its IsolationLevel, the HLC read
timestamp captured at begin, its read/predicate sets, and a formal
TransactionState inspectable through Self::state/Self::state_handle.
Implementations§
Source§impl<'db> Transaction<'db>
impl<'db> Transaction<'db>
pub fn read_snapshot(&self) -> Snapshot
Sourcepub fn txn_id(&self) -> u64
pub fn txn_id(&self) -> u64
The transaction’s id (generation-scoped: high 32 bits = open generation, low 32 = per-open counter). Mainly diagnostic / test-facing.
Sourcepub fn isolation(&self) -> IsolationLevel
pub fn isolation(&self) -> IsolationLevel
The isolation level this transaction was begun with (S1B-001/002).
Sourcepub fn read_ts(&self) -> Option<HlcTimestamp>
pub fn read_ts(&self) -> Option<HlcTimestamp>
The HLC read timestamp captured at begin (spec §8.2). None when
clock-skew rejection deferred allocation to the commit path.
Sourcepub fn state(&self) -> TransactionState
pub fn state(&self) -> TransactionState
The current formal state (S1B-001).
Sourcepub fn state_handle(&self) -> TxnStateHandle
pub fn state_handle(&self) -> TxnStateHandle
A cloneable handle to the formal state, inspectable after this value
is consumed by commit/rollback (S1B-001).
Sourcepub fn read_set(&self) -> &ReadSet
pub fn read_set(&self) -> &ReadSet
Point reads recorded so far (S1B-001; certified at Serializable).
Sourcepub fn predicate_set(&self) -> &PredicateSet
pub fn predicate_set(&self) -> &PredicateSet
Predicate/range reads recorded so far (S1B-001/002).
Sourcepub fn get(&mut self, table: &str, row_id: RowId) -> Result<Option<OwnedRow>>
pub fn get(&mut self, table: &str, row_id: RowId) -> Result<Option<OwnedRow>>
Read one row at this transaction’s current statement snapshot and
record the point read in the transaction’s read set. ReadCommitted
statements observe commits that landed since the previous statement;
RepeatableRead/Serializable observe the fixed begin snapshot.
Sourcepub fn track_predicate_read(&mut self, table: &str) -> Result<()>
pub fn track_predicate_read(&mut self, table: &str) -> Result<()>
Register a table-granularity predicate/range read (S1B-002). Scan and
range-lookup paths report here so Serializable certification detects
phantoms: any concurrent write on the table then invalidates the read.
pub fn put( &mut self, table: &str, cells: Vec<(u16, Value)>, ) -> Result<Option<i64>>
pub fn put_returning( &mut self, table: &str, cells: Vec<(u16, Value)>, ) -> Result<PutResult>
Sourcepub fn put_batch(
&mut self,
table: &str,
rows: Vec<Vec<(u16, Value)>>,
) -> Result<Vec<Option<i64>>>
pub fn put_batch( &mut self, table: &str, rows: Vec<Vec<(u16, Value)>>, ) -> Result<Vec<Option<i64>>>
Stage many puts on the same table with one table-id lookup + one
auto-inc lock pass. Each row is staged individually (same as repeated
put); the savings are the amortized lookups/locks for bulk guard-row
writes and batched application-row inserts. Returns the assigned
auto-increment values (Some only where the engine filled the column).
Sourcepub fn delete(&mut self, table: &str, row_id: RowId) -> Result<()>
pub fn delete(&mut self, table: &str, row_id: RowId) -> Result<()>
Stage a delete of row_id on table.
Sourcepub fn delete_batch(&mut self, table: &str, row_ids: Vec<RowId>) -> Result<()>
pub fn delete_batch(&mut self, table: &str, row_ids: Vec<RowId>) -> Result<()>
Stage deletes without materializing pre-images.
Sourcepub fn put_external_state(&mut self, table: &str, state: Vec<u8>) -> Result<()>
pub fn put_external_state(&mut self, table: &str, state: Vec<u8>) -> Result<()>
Stage opaque external-table module state. The payload is committed under
the same WAL TxnCommit as ordinary table writes.
Sourcepub fn set_materialized_view_definition(
&mut self,
definition: MaterializedViewEntry,
) -> Result<()>
pub fn set_materialized_view_definition( &mut self, definition: MaterializedViewEntry, ) -> Result<()>
Stage a materialized-view checkpoint in the same durable commit as its row deltas. This makes incremental refresh replay idempotent after a crash: data and the Last-Event-ID watermark advance together.
pub fn delete_many( &mut self, table: &str, row_ids: Vec<RowId>, ) -> Result<Vec<OwnedRow>>
pub fn update_many( &mut self, table: &str, updates: Vec<(RowId, Vec<(u16, Value)>)>, ) -> Result<Vec<OwnedRow>>
pub fn upsert( &mut self, table: &str, insert_cells: Vec<(u16, Value)>, action: UpsertAction, ) -> Result<UpsertResult>
pub fn truncate(&mut self, table: &str) -> Result<()>
Sourcepub fn commit(self) -> Result<Epoch>
pub fn commit(self) -> Result<Epoch>
Commit: durably seal the staging under one epoch and publish it.
Sourcepub fn commit_idempotent(self, request: IdempotencyRequest) -> Result<Epoch>
pub fn commit_idempotent(self, request: IdempotencyRequest) -> Result<Epoch>
Commit with idempotency parameters (spec §10.2, S1B-005): a repeated
key with an identical request fingerprint returns the original commit
epoch (the original receipt is visible through the state handle); a
repeated key with a different fingerprint returns Conflict.
pub fn commit_with_row_ids(self) -> Result<(Epoch, Vec<RowId>)>
Sourcepub fn commit_controlled<F>(
self,
control: &ExecutionControl,
before_commit: F,
) -> Result<Epoch>
pub fn commit_controlled<F>( self, control: &ExecutionControl, before_commit: F, ) -> Result<Epoch>
Cooperatively prepare this transaction, then invoke before_commit
immediately before the first WAL append can occur. If cancellation or
the callback wins, no commit epoch or WAL record is produced.
pub fn commit_controlled_with_row_ids<F>( self, control: &ExecutionControl, before_commit: F, ) -> Result<(Epoch, Vec<RowId>)>
Trait Implementations§
Source§impl Drop for Transaction<'_>
impl Drop for Transaction<'_>
Auto Trait Implementations§
impl<'db> !RefUnwindSafe for Transaction<'db>
impl<'db> !UnwindSafe for Transaction<'db>
impl<'db> Freeze for Transaction<'db>
impl<'db> Send for Transaction<'db>
impl<'db> Sync for Transaction<'db>
impl<'db> Unpin for Transaction<'db>
impl<'db> UnsafeUnpin for Transaction<'db>
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> 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