Skip to content

Lock-free TransactionChain + IndexRef & bulk enumerate (#145) - #159

Merged
nockawa merged 2 commits into
mainfrom
feature/145-lock-free-transaction-chain
Mar 12, 2026
Merged

nockawa merged 2 commits into
mainfrom
feature/145-lock-free-transaction-chain

Conversation

@nockawa

@nockawa nockawa commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Lock-free CreateTransaction: Replaced exclusive AccessControl lock with CAS-based lock-free push on the transaction chain head. The hot path (Create) no longer serializes with anything — only Remove (cold path) retains the exclusive lock.
  • Singly-linked chain: Dropped Previous pointers, replaced Tail.Previous?.TSN lookups with a scan-based ComputeNextMinTSN() helper under shared lock.
  • IndexRef: New lightweight struct for referencing indexes by name with type-safe access from ComponentTable.
  • Bulk enumerate: New DatabaseEngine.EnumerateEntities API for efficient bulk entity enumeration.
  • ConcurrentQueue pool: Transaction pool upgraded from Queue<Transaction> to ConcurrentQueue<Transaction> for thread-safe recycling without locks.

Changed Files (14 files, +1769 / -65)

  • TransactionChain.cs — Core lock-free refactor (CAS PushHead, singly-linked, ConcurrentQueue pool)
  • Transaction.cs — Drop Previous field, update 3 NextMinTSN call sites, expanded transaction logic
  • IndexRef.cs — New lightweight index reference struct
  • ComponentTable.cs / DatabaseEngine.cs / DatabaseEngineExtensions.cs — Bulk enumerate + IndexRef support
  • CacheLinePadded.cs — New cache-line padding utility
  • PagedMMF.cs — Minor storage adjustments
  • ThrowHelper.cs — New error helpers
  • Tests: TransactionChainTests.cs, BulkEnumerateTests.cs, IndexRefTests.cs (1122 lines of new tests)

Test Plan

  • Lock-free MPSC correctness — 4 threads creating, 1 disposing
  • MinTSN tracking — create 5 transactions, dispose oldest, verify advancement
  • Pool recycling — create/dispose cycle, verify reuse
  • Max active limit — exceed limit, verify exception + rollback
  • Stress test — 8 threads concurrent create/commit/dispose
  • IndexRef and bulk enumerate tests

Closes #145

nockawa added 2 commits March 12, 2026 08:14
Singly-linked lock-free chain (CAS PushHead/Remove), read-onlytransactions, dispose race fix. IndexRef readonly struct with layout-version staleness detection.
Zero-copy MVCC bulk enumerate over PK and secondary indexes via ref struct enumerators with ReadOnlySpan into epoch-protected page memory.
@nockawa
nockawa merged commit d6d4bb3 into main Mar 12, 2026
5 checks passed
@nockawa
nockawa deleted the feature/145-lock-free-transaction-chain branch March 12, 2026 07:25
@nockawa nockawa mentioned this pull request May 20, 2026
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock-free TransactionChain.CreateTransaction

1 participant