Repository navigation
Closed
12 / 1212 of 12 issues completed
Copy link
Labels
performancePerformance improvement
Description
Concurrent Index Scaling: From Whole-Tree Locks to Per-Node Optimistic Concurrency
Summary
Replace the whole-tree AccessControl reader-writer lock on BTree<TKey> with Optimistic Lock Coupling (OLC) — per-node version counters that let readers traverse lock-free and writers latch only the nodes they modify. Add Move/MoveValue as first-class compound operations to eliminate redundant traversals for secondary index updates.
Design doc: claude/design/Indexing/concurrent-index-scaling.md
Motivation
- Single
AccessControlper BTree serializes all writes and generates CAS contention among readers - At 256+ cores, the CAS costs 100-400 ns cross-socket per reader enter/exit
- Secondary index updates currently require 2-4 separate BTree operations (Remove + Add + TryGet calls) when a single compound Move can share traversal and locking
- Monotonic PK inserts create double serialization (tree lock + rightmost leaf hotspot)
Phase 1: OLC Foundation (Target)
Core implementation — replace whole-tree locking with per-node OLC.
- OlcLatch implementation + Control field redesign (OLC: OlcLatch implementation + Control field redesign #108)
- EpochThreadRegistry false-sharing fix (OLC: EpochThreadRegistry false-sharing fix #109)
- MutationContext + atomic tree metadata (OLC: MutationContext + atomic tree metadata #110)
- OLC optimistic read path (TryGet/TryGetMultiple) (OLC: Optimistic read path (TryGet/TryGetMultiple) #111)
- OLC write path: Insert with per-node locking + splits (OLC: Write path — Insert with per-node locking + splits #112)
- OLC write path: Remove with per-node locking + merges (OLC: Write path — Remove with per-node locking + merges #113)
- Compound Move/MoveValue operations (OLC: Compound Move/MoveValue operations #114)
- Pessimistic fallback + epoch-deferred node deallocation (OLC: Pessimistic fallback + epoch-deferred node deallocation #115)
- EnumerateLeaves conversion + whole-tree lock removal (OLC: EnumerateLeaves conversion + whole-tree lock removal #116)
- Concurrent stress test suite (OLC: Concurrent stress test suite #117)
Phase 2: Contention Split + Epoch Scaling (Future)
- Contention Split + epoch scaling + node sizing (OLC Phase 2: Contention Split + epoch scaling + node sizing #118)
Phase 3: Latch-Free Leaf Updates (Future)
- FB+-tree inspired CAS leaf updates (OLC Phase 3: Latch-free leaf updates (FB+-tree inspired) #119)
Dependency Graph
#108 (OlcLatch) ──┬──→ #110 (MutationContext) ──→ #111 (Read Path) ──→ #112 (Insert) ──→ #113 (Remove) ──→ #114 (Move)
│ │ │ │ │
#109 (Epoch Pad) ──┘ └──→ #115 (Fallback + Epoch Dealloc) ◄────────────────┘
│
▼
#116 (Enumerate + Cleanup) ──→ #117 (Stress Tests)
│
▼
#118 (Phase 2) ──→ #119 (Phase 3)
Key Design Decisions
| Decision | Choice | Rationale |
|---|---|---|
| Concurrency model | OLC (Leis 2019) | Proven in CedarDB/LeanStore; readers lock-free; writers latch only modified nodes |
| Node size (Phase 1) | Keep 128 bytes | Version counter fits in existing Control field; benchmark 256-byte in Phase 2 |
| High keys | Not stored (Phase 1) | 14% fanout loss at 128 bytes; use Next + first-key-of-next instead |
| Accessor strategy | Per-operation (Phase 1) | Thread-local pool deferred to Phase 2 if profiling warrants |
| Epoch advancement | Keep per-exit (Phase 1) | Silo-style dedicated thread deferred to Phase 2 |
Performance Projections
| Operation | Current | Phase 1 (OLC) | Improvement |
|---|---|---|---|
| Move (same leaf) | ~934 ns (Remove+Add) | ~350-400 ns | -57-62% |
| MoveValue (same leaf) | ~1400+ ns (4 ops) | ~400-500 ns | -64-71% |
| Multi-threaded reads (256t) | CAS-limited | Near-linear scaling | Dramatic |
| Mixed read-write (200R+56W) | Writers block all readers | Leaf-level only | Dramatic |
Sub-issues
Collapse Sub-issuesSub-issues
Loading 12 sub-issues
Metadata
Metadata
Assignees
Labels
performancePerformance improvement
Type
Fields
Priority
None yet
Activity
nockawa commentedon Feb 28, 2026
All phases complete. OLC B+Tree concurrency implemented with optimistic lock coupling, compound Move/MoveValue operations, pessimistic fallbacks, stress test suite, and file structure cleanup (BTree.cs split into partial files).
Optimistic Lock Coupling for B+Tree concurrency (#107) (#120)