Expand description
Transaction management and MVCC (Multi-Version Concurrency Control) for LLKV.
This crate provides transaction isolation using MVCC semantics. Each transaction operates with a consistent snapshot of the database, determined by its transaction ID and snapshot timestamp.
§Module Organization
core: Core MVCC primitives (TxnIdManager, TransactionSnapshot, RowVersion) - currentlymvccmoduletable: Table-level MVCC integration (row filtering, builders) - currentlyhelpersmodulecontext: Transaction context types (SessionTransaction, TransactionSession, TransactionManager)types: Data type definitions (TransactionResult, TransactionKind, TransactionCatalogSnapshot)
§Key Concepts
- Transaction ID (
TxnId): Unique 64-bit identifier for each transaction - Snapshot Isolation: Transactions see a consistent view of data as of their start time
- Row Versioning: Each row tracks when it was created and deleted via
created_byanddeleted_bycolumns TransactionSnapshot: Captures transaction ID and snapshot timestamp
§Reserved Transaction IDs
TXN_ID_NONE(u64::MAX): Indicates no transaction (uninitialized state)TXN_ID_AUTO_COMMIT(1): Used for auto-commit (single-statement) transactions- IDs 2+: Multi-statement transactions (allocated by
TxnIdManager)
§Visibility Rules
A row is visible to a transaction if:
- It was created before the transaction’s snapshot (
created_by <= snapshot_id) - It was not deleted, or deleted after the snapshot (
deleted_by == TXN_ID_NONE || deleted_by > snapshot_id)
§Architecture
TxnIdManager: Allocates transaction IDs and tracks commit statusTransactionSnapshot: Immutable view of transaction state for visibility checkscontext::TransactionContext: Main interface for executing operations within a transactioncontext::SessionTransaction: Per-transaction state machinecontext::TransactionSession: Session-level transaction managementcontext::TransactionManager: Cross-session transaction coordinatorRowVersion: Metadata tracking which transaction created/deleted a rowtypes::TransactionCatalogSnapshot: Catalog snapshot interface for table lookups
Re-exports§
pub use context::SessionTransaction;pub use context::TransactionContext;pub use context::TransactionManager;pub use context::TransactionSession;pub use context::TransactionSessionId;pub use helpers::MvccRowIdFilter;pub use helpers::TransactionMvccBuilder;pub use helpers::filter_row_ids_for_fk_check;pub use helpers::filter_row_ids_for_snapshot;pub use mvcc::RowVersion;pub use mvcc::TXN_ID_AUTO_COMMIT;pub use mvcc::TXN_ID_NONE;pub use mvcc::TransactionSnapshot;pub use mvcc::TxnId;pub use mvcc::TxnIdManager;pub use types::TransactionCatalogSnapshot;pub use types::TransactionKind;pub use types::TransactionResult;