Expand description
ActiveTxRegistry — the live-transaction table that
garbage collection consults to know which row versions are still
possibly visible (Phase 11.2).
Per docs/concurrent-writes-plan.md:
Versions whose
endtimestamp is older than the oldest active reader’s begin-timestamp are dead and may be reclaimed.
The registry is the source of “oldest active reader’s
begin-timestamp” — ActiveTxRegistry::min_active_begin_ts.
Phase 11.6 (GC) reads it on every sweep; Phase 11.4 (commit
validation) registers each BEGIN CONCURRENT transaction here
and unregisters at COMMIT/ROLLBACK.
The current shape uses a Mutex<BTreeMap> for simplicity. Two
reasons not to over-engineer this for v0:
- The map is only touched twice per transaction (begin +
commit/rollback). Even a thousand concurrent writers hit a
couple-thousand
lockcalls per second — well below mutex contention thresholds. min_active_begin_tsisO(log N)on aBTreeMap(the smallest key is atiter().next()), which is fine for the “GC asks once per sweep” use case.
When the GC profile shows the registry on the hot path, swap to
a sharded skip list or an RwLock-protected sorted set. Until
then this is sufficient.
Structs§
- Active
TxRegistry - Live-transaction table. Cheap to clone (internally
Arc-wrapped state); pass clones into worker threads. - TxHandle
- RAII guard returned by
ActiveTxRegistry::register. Dropping it unregisters the transaction. A typical caller doesn’t deal with it explicitly — it lives on theConcurrentTxstruct (Phase 11.4) and is dropped when the transaction commits or rolls back. - TxId
- Opaque transaction identifier. Newtype around a
u64so a stray timestamp doesn’t accidentally pass as aTxIdand vice versa. Allocated byActiveTxRegistry::register.
Enums§
- TxTimestamp
OrId - Tagged-union “this version is in-flight under transaction
id” vs. “this version was committed at timestampts”. Per the plan, row versions carry abegin: TxTimestampOrIdso reads can ignore versions belonging to still-open transactions while still seeing the latest committed version.