Skip to main content

Module registry

Module registry 

Source
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 end timestamp 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:

  1. The map is only touched twice per transaction (begin + commit/rollback). Even a thousand concurrent writers hit a couple-thousand lock calls per second — well below mutex contention thresholds.
  2. min_active_begin_ts is O(log N) on a BTreeMap (the smallest key is at iter().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§

ActiveTxRegistry
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 the ConcurrentTx struct (Phase 11.4) and is dropped when the transaction commits or rolls back.
TxId
Opaque transaction identifier. Newtype around a u64 so a stray timestamp doesn’t accidentally pass as a TxId and vice versa. Allocated by ActiveTxRegistry::register.

Enums§

TxTimestampOrId
Tagged-union “this version is in-flight under transaction id” vs. “this version was committed at timestamp ts”. Per the plan, row versions carry a begin: TxTimestampOrId so reads can ignore versions belonging to still-open transactions while still seeing the latest committed version.