Crate llkv_transaction

Crate llkv_transaction 

Source
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) - currently mvcc module
  • table: Table-level MVCC integration (row filtering, builders) - currently helpers module
  • context: 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_by and deleted_by columns
  • 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:

  1. It was created before the transaction’s snapshot (created_by <= snapshot_id)
  2. It was not deleted, or deleted after the snapshot (deleted_by == TXN_ID_NONE || deleted_by > snapshot_id)

§Architecture

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;

Modules§

context
Transaction context types for orchestrating transaction lifecycles.
helpers
MVCC row filtering and builder utilities.
mvcc
types
Transaction types and result enums.