LLKV Transaction
Work in Progress
llkv-transaction implements the MVCC substrate used across the LLKV stack. It allocates transaction IDs, enforces snapshot isolation, and persists commit metadata so row visibility stays deterministic.
Responsibilities
- Allocate monotonic
TxnIds and expose the currentlast_committedwatermark. - Capture
TransactionSnapshots for sessions so every statement runs against a consistent view. - Track commit, abort, and rollback status for active transactions.
- Surface MVCC visibility rules to higher layers through helpers that evaluate
created_byanddeleted_bymetadata.
MVCC Metadata Columns
- Each table automatically manages three hidden columns stored by
llkv-tableandllkv-column-map:row_id: monotonically increasing identifier assigned during inserts.created_by:TxnIdthat wrote the row.deleted_by:TxnIdthat removed the row, orTXN_ID_NONEif the row is visible.
- Visibility is determined by comparing these columns against the transaction snapshot (
snapshot_id) and the current transaction identifier.
Snapshot Isolation Rules
A row is visible to transaction T with snapshot S when:
created_by <= S.last_committeddeleted_by == TXN_ID_NONEordeleted_by > S.last_committeddeleted_by != T.txn_id
These rules implement snapshot isolation with optimistic conflict detection at commit.
Transaction Lifecycle
begin_transactioncaptures the current watermark, allocates a newTxnId, and freezes a catalog snapshot for schema stability.commit_transactionperforms conflict detection (write/write conflicts, dropped tables, DDL races), replays staged operations, and persists the updated watermark.rollback_transactiondiscards staged operations and leaves persistent data untouched so uncommitted changes never leak.- Auto-commit mode uses
TXN_ID_AUTO_COMMITto run single statements without replay.
Integration
- Embedded by
llkv-runtimefor session control and MVCC metadata injection. - Works with
llkv-tablescans to filter rows according to snapshot visibility. - Supports the SQLogic Test harness and benchmarking flows by exposing stats hooks consumed through runtime APIs.
License
Licensed under the Apache-2.0 License.