Skip to main content
← CONCEPTS / DATABASES-STORAGE
An end-to-end domain learning journey

B-Link Trees & Latch
Crabbing Optimization (PostgreSQL nbtree).

Pessimistic latch crabbing holds exclusive parent latches down B+Tree paths during splits, creating 64-core lock convoys; Lehman-Yao B-Link Trees add High Keys and Right-Sibling Links for lock-free descent.
Start the journey2 sections· Last modified Dec 2, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When implementing concurrent B+Trees, release parent latches early and follow rightLink whenever searchKey > highKey.

TL;DR30-second simplified summary
▾

Sustains 100k+ concurrent writes/sec without 64-core root lock convoys.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
B+Tree Page Splits
Divides full leaf/internal pages and propagates separator keys upward.
Latch Crabbing
Acquiring child latch before releasing parent latch during tree traversal.
Full walkthrough · 2 stages
01
STAGE 01intermediate

Why Pessimistic Latch Crabbing Stalls 64-Core Servers.

Why this matters: Contrast lock-coupled latch crabbing against B-Link horizontal recovery.

Holding exclusive latches on upper internal nodes blocks every reader and writer traversing that subtree.

Before · Pessimistic Latch Crabbing
After · Lehman-Yao B-Link Tree
ChoiceWhat it buysWhat it costs
Pessimistic CrabbingNo right-link pointer neededSerializes writes behind upper-level X-latches
Lehman-Yao B-LinkZero parent-child lock coupling; 100k+ writes/sRequires High Key + right-sibling pointer per page
def blink_search(root, key: int):
    curr = root
    while not curr.is_leaf:
        curr.shared_lock()
        while curr.right_link is not None and key > curr.high_key:
            nxt = curr.right_link
            curr.shared_unlock()
            curr = nxt
            curr.shared_lock()
        child = curr.find_child(key)
        curr.shared_unlock()  # Released BEFORE latching child
        curr = child
    return curr
02
STAGE 02advanced

Right-Link Split Ordering & Deadlock Freedom.

Why this matters: Guarantee readers never miss a key during a concurrent split.

A splitting writer creates the new right sibling, sets its High Key and rightLink, and links left->right BEFORE updating the parent—ensuring a continuous left-to-right path.

Engineering Decision Framework
Problem
How to allow 64+ concurrent threads to search and insert into a B+Tree simultaneously without holding multi-level exclusive latches.
Naive Solution
Use pessimistic latch crabbing: hold parent exclusive latches until verifying the child will not split.
Why It Fails
Near-full internal nodes force threads to hold exclusive latches near the root, creating a severe lock convoy.
Alternatives
Global tree lock, pessimistic latch crabbing, or Lehman-Yao B-Link Trees with High Keys and right-sibling links.
Engineering Decision
Store a High Key and right-sibling link on every page, release parent latches before acquiring child latches, and hop right if key > highKey.
Trade-Offs
Adds ~16 bytes per page for High Key + rightLink and requires left-to-right split ordering, but eliminates upper-tree lock convoys.
Decision Exercise · Make the Call

A reader releases the parent latch and lands on Child Page A for key 45, but a writer just split Child A (highKey=40) and moved 45 to Child B. What prevents a false 'not found'?

public Page descendBLink(Page curr, int key) {
    curr.sharedLock();
    while (curr.rightLink != null && key > curr.highKey) {
        Page right = curr.rightLink;
        curr.sharedUnlock();
        curr = right;
        curr.sharedLock();
    }
    Page child = curr.findChild(key);
    curr.sharedUnlock();
    return child;
}
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

What two fields enable Lehman-Yao B-Link Trees to release parent latches early?

Recommended Learning Flow