Skip to content

Concurrent Index Scaling: OLC B+Tree Concurrency #107

Closed
12 of 12 issues completed
Closed

Description

@nockawa

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 AccessControl per 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.

Phase 2: Contention Split + Epoch Scaling (Future)

Phase 3: Latch-Free Leaf Updates (Future)

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

Sub-issues

12 of 12 Issues completed
Loading 12 sub-issues

Activity

  1. added
    performance
    on Feb 26, 2026
  2. moved this to Backlog in Typhon devon Feb 26, 2026
  3. moved this from Backlog to In Progress in Typhon devon Feb 26, 2026
  4. nockawa commented on Feb 28, 2026

    @nockawa
    CollaboratorAuthor

    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).

  5. moved this from In Progress to Done in Typhon devon Feb 28, 2026
  6. moved this from Done to Review in Typhon devon Feb 28, 2026
  7. moved this from Review to Done in Typhon devon Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performance

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions