1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Lehman-Yao concurrent B-tree support — runtime switch + helpers.
//!
//! The reddb B-tree already carries `prev_leaf` / `next_leaf`
//! pointers on every leaf page, which covers the "right-link" half
//! of the Lehman-Yao contract (Lehman & Yao, ACM TODS 1981). The
//! missing pieces are:
//!
//! 1. A `high_key` separator on each leaf so readers can detect
//! that a concurrent split moved their target key to the right
//! sibling without restarting from the root.
//! 2. A reader descent path that pins pages rather than locking,
//! following `next_leaf` when `key > high_key`.
//! 3. Split routines that hold the page-exclusive lock locally and
//! release it the moment the right-link is wired up (so other
//! readers can immediately follow through).
//!
//! Items (1)–(3) require an on-disk format bump (`STORE_VERSION_V8`)
//! plus a migration that fills `high_key` on existing leaves from
//! their current highest key, followed by lock protocol changes
//! across `nbtree`-analogous modules.
//!
//! This module is the coordination surface for that work:
//!
//! - `is_enabled()` reports the effective runtime value of
//! `storage.btree.lehman_yao` so read / split callers can branch
//! on the future path without sprinkling `config_bool` everywhere
//! on the hot path.
//! - `set_enabled(bool)` is called by the runtime at boot after it
//! has resolved the matrix value (env > file > red_config >
//! default). Defaults to `true` so a library-only user gets
//! Lehman-Yao semantics once the storage changes land.
//! - `HighKey` is the on-disk shape for the leaf-page upper bound.
//! Today it's only written by callers that opt in; the full
//! wire-up lands with `STORE_VERSION_V8`.
use ;
/// Process-wide runtime flag. Atomics so the read / split paths
/// can branch without taking a lock on every probe. `true` on
/// start — callers that want legacy semantics flip it during boot.
static LEHMAN_YAO_ENABLED: AtomicBool = new;
/// On-disk shape for a leaf page's upper bound. Contiguous
/// `len` + `bytes` layout — matches the cell encoding the
/// rest of the leaf uses so the migration can copy the last
/// live cell's key verbatim.