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: TxHandleRAII 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
impl ConcurrentTx
Sourcepub fn begin(
clock: &MvccClock,
registry: &ActiveTxRegistry,
live_tables: &HashMap<String, Table>,
) -> Self
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.