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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! # Error Types for the Concurrent B+ Tree
//!
//! This module defines error types used internally by the B+ tree for
//! handling optimistic concurrency failures.
//!
//! ## Error Handling Strategy
//!
//! The B+ tree uses optimistic concurrency control, where most operations
//! proceed without blocking and validate their reads at the end. When
//! validation fails, operations don't panic - they return errors that
//! signal the caller to retry.
//!
//! ## Error Flow
//!
//! ```text
//! Operation starts
//! │
//! ▼
//! Acquire optimistic access
//! │
//! ▼
//! Read data (may be inconsistent)
//! │
//! ▼
//! Validate reads ──────────► Err(Unwind) ───► Retry operation
//! │
//! ▼ (Ok)
//! Perform side effects
//! │
//! ▼
//! Return success
//! ```
//!
//! ## Common Patterns
//!
//! Most tree operations follow this pattern:
//!
//! ```ignore
//! loop {
//! let perform = || {
//! let guard = self.find_leaf(key, eg)?; // May return Unwind
//! let result = guard.some_operation()?; // May return Unwind
//! guard.recheck()?; // May return Unwind
//! Ok(result)
//! };
//!
//! match perform() {
//! Ok(result) => return result,
//! Err(Error::Unwind) => continue, // Retry
//! Err(Error::Reclaimed) => continue, // Retry
//! }
//! }
//! ```
use Error;
/// Errors that can occur during B+ tree operations.
///
/// These errors are used for internal flow control in the optimistic
/// concurrency system. They typically cause operations to retry rather
/// than fail permanently.
/// A Result type alias using our custom Error type.
///
/// Used throughout the B+ tree codebase for operations that can fail
/// due to optimistic concurrency issues.
pub type Result<T> = Result;