Skip to main content

Transaction

Struct Transaction 

Source
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>

Source

pub fn read_snapshot(&self) -> Snapshot

Source

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.

Source

pub fn isolation(&self) -> IsolationLevel

The isolation level this transaction was begun with (S1B-001/002).

Source

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.

Source

pub fn state(&self) -> TransactionState

The current formal state (S1B-001).

Source

pub fn state_handle(&self) -> TxnStateHandle

A cloneable handle to the formal state, inspectable after this value is consumed by commit/rollback (S1B-001).

Source

pub fn read_set(&self) -> &ReadSet

Point reads recorded so far (S1B-001; certified at Serializable).

Source

pub fn predicate_set(&self) -> &PredicateSet

Predicate/range reads recorded so far (S1B-001/002).

Source

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.

Source

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.

Source

pub fn put( &mut self, table: &str, cells: Vec<(u16, Value)>, ) -> Result<Option<i64>>

Source

pub fn put_returning( &mut self, table: &str, cells: Vec<(u16, Value)>, ) -> Result<PutResult>

Source

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

Source

pub fn delete(&mut self, table: &str, row_id: RowId) -> Result<()>

Stage a delete of row_id on table.

Source

pub fn delete_batch(&mut self, table: &str, row_ids: Vec<RowId>) -> Result<()>

Stage deletes without materializing pre-images.

Source

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.

Source

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.

Source

pub fn delete_many( &mut self, table: &str, row_ids: Vec<RowId>, ) -> Result<Vec<OwnedRow>>

Source

pub fn update_many( &mut self, table: &str, updates: Vec<(RowId, Vec<(u16, Value)>)>, ) -> Result<Vec<OwnedRow>>

Source

pub fn upsert( &mut self, table: &str, insert_cells: Vec<(u16, Value)>, action: UpsertAction, ) -> Result<UpsertResult>

Source

pub fn truncate(&mut self, table: &str) -> Result<()>

Source

pub fn commit(self) -> Result<Epoch>

Commit: durably seal the staging under one epoch and publish it.

Source

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.

Source

pub fn commit_with_row_ids(self) -> Result<(Epoch, Vec<RowId>)>

Source

pub fn commit_controlled<F>( self, control: &ExecutionControl, before_commit: F, ) -> Result<Epoch>
where F: FnMut() -> Result<()>,

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.

Source

pub fn commit_controlled_with_row_ids<F>( self, control: &ExecutionControl, before_commit: F, ) -> Result<(Epoch, Vec<RowId>)>
where F: FnMut() -> Result<()>,

Source

pub fn rollback(self)

Rollback: discard staging. Nothing is appended to the WAL.

Trait Implementations§

Source§

impl Drop for Transaction<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.