Skip to main content

ConcurrentTx

Struct ConcurrentTx 

Source
pub struct ConcurrentTx {
    pub handle: TxHandle,
    pub tables: HashMap<String, Table>,
    pub tables_at_begin: HashMap<String, Table>,
    pub schema_at_begin: Vec<String>,
}
Expand description

Per-Connection snapshot of BEGIN CONCURRENT state.

Lives on Connection, not on Database — multiple sibling connections each carry their own concurrent transaction without stepping on each other’s snapshots.

Fields§

§handle: TxHandle

RAII handle into the ActiveTxRegistry. Drops when this struct drops (commit, rollback, or Connection close), at which point the transaction is unregistered.

§tables: HashMap<String, Table>

Working snapshot of Database::tables taken at BEGIN CONCURRENT via Table::deep_clone. Each statement’s executor pass transparently swaps this in for db.tables so writes land here, not on the live database.

§tables_at_begin: HashMap<String, Table>

Immutable second clone of Database::tables taken at BEGIN. Diffing tables against this at commit produces the write-set. We can’t diff against the live Database::tables directly because between our BEGIN and our COMMIT, other concurrent transactions may have committed — their writes show up as differences against the live state but aren’t ours, and treating them as our DELETEs would silently undo someone else’s commit. The doubled memory cost (two full clones per transaction) is the price for that correctness in v0; the obvious follow-up is a per-touched-row begin-state map that captures only the rows we actually read or wrote.

§schema_at_begin: Vec<String>

Sorted table-name fingerprint of Database::tables at BEGIN. Used at commit to detect that DDL ran on the live database under us — v0 rejects DDL inside the tx, but nothing prevents another connection from running it outside.

Implementations§

Source§

impl ConcurrentTx

Source

pub fn begin( clock: &MvccClock, registry: &ActiveTxRegistry, live_tables: &HashMap<String, Table>, ) -> Self

Allocates a new transaction. Advances the clock by one (the TxHandle::begin_ts), records the table-name fingerprint, and deep-clones every table.

Caller is expected to have already verified journal_mode == Mvcc and that no transaction is open.

Source

pub fn begin_ts(&self) -> u64

Convenience — the begin_ts snapshot timestamp this transaction took at BEGIN. Used at commit to validate against MvStore versions that committed after this snapshot.

Source

pub fn schema_unchanged(&self, live_tables: &HashMap<String, Table>) -> bool

True if live_tables has the same table-name set this transaction recorded at BEGIN. Used at commit to surface a typed error rather than silently committing onto a schema that drifted under us.

Trait Implementations§

Source§

impl Debug for ConcurrentTx

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.