aiondb-tx

Transaction lifecycle, lock management, and snapshot/oracle services. Owns the transaction id allocator, the active set, the commit timestamp oracle, the wait-graph lock manager, and the serializable conflict tracker. Snapshots are produced under the active-set lock so a concurrent thread can never observe an active transaction that has not yet been registered.

cargo

[dependencies]
aiondb-tx = { path = "../aiondb-tx" }

modules

modulepurpose
lifecycleTransactionLifecycle trait and InMemoryTransactionManager implementation.
lock_managerLockManager trait with WaitGraphLockManager (production) and NoopLockManager (tests).
oracleCommitTimestampOracle for monotonic commit timestamps.
serializableSerializableCoordinator trait and NoopSerializableCoordinator.
typesIsolationLevel, Snapshot, ActiveTransaction, LockMode, CommitResult.

key types

example

use aiondb_tx::{
    CommitTimestampOracle, InMemoryTransactionManager, IsolationLevel,
    TransactionLifecycle,
};

let manager = InMemoryTransactionManager::default();
let txn = manager
    .begin(IsolationLevel::SnapshotIsolation)
    .expect("begin txn");
assert_eq!(txn.isolation, IsolationLevel::SnapshotIsolation);

let result = manager.commit(txn).expect("commit txn");
assert!(result.commit_ts >= 1);

let oracle = CommitTimestampOracle::default();
assert_eq!(oracle.next(), 1);
assert_eq!(oracle.next(), 2);

locking

use aiondb_core::{RelationId, TupleId, TxnId};
use aiondb_tx::{LockManager, LockMode, WaitGraphLockManager};

let locks = WaitGraphLockManager::default();
let txn = TxnId::new(1);
let table = RelationId::new(42);

locks
    .acquire_table_lock(txn, table, LockMode::RowExclusive)
    .expect("acquire table lock");
locks
    .acquire_tuple_lock(txn, table, TupleId::new(7), LockMode::Update)
    .expect("acquire tuple lock");
locks.release_txn(txn).expect("release on commit");

isolation levels

ReadCommitted refreshes the snapshot at the start of each statement via the configured SnapshotOracle. SnapshotIsolation reuses the snapshot taken at begin. Serializable adds read-set tracking through SerializableCoordinator so commits that conflict with concurrent writes raise SQLSTATE 40001.