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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Copyright (c) 2026 Mike Grier
//! Epoch bookkeeping and group commit (M13.3).
//!
//! This is the construction from "Durability on the ring" in the crate's
//! `DESIGN-NOTES.md`, and it is what turns [`crate::contract`]'s guarantee
//! from a sentence into a value a caller can ask about:
//!
//! 1. Records stream into whatever epoch is currently **open**, carrying no
//! durability flag of their own.
//! 2. Closing epoch *N* pushes **one covering flush**, whose `UserData` is
//! *N*'s identity for the rest of its life.
//! 3. When that flush's completion is observed, every epoch `<= N` is durable.
//! 4. Callers wait on epochs, never on records.
//!
//! One expensive operation amortized over many records. Step 2's barrier is
//! not decoration: without [`FlushCoverage::CoversPrecedingOperations`] the
//! flush is an ordinary operation racing the writes it is supposed to cover
//! (D-23), and step 3 would be false.
//!
//! # What the barrier costs, and why this module says so out loud
//!
//! [`FlushCoverage::CoversPrecedingOperations`] waits for every operation
//! outstanding on the ring, so the commit itself is a long operation -- but it
//! is **one-sided** and does not hold back appends pushed after it (D-47,
//! measured; D-24 originally claimed it did). What a commit costs is its own
//! latency, and the arena slots of the epoch being committed stay occupied
//! until it finishes.
//!
//! The next epoch's appends are *not* blocked by the ring. This sample still
//! serialises them, because it waits for the commit before opening the next
//! epoch -- that is this sample's own sequencing, not the ring's.
//!
//! That is the cost the design notes name, and it is the reason a real
//! consumer has to choose between the three strategies M14.3 implements. This
//! module deliberately picks the simplest one -- the drained flush -- because
//! it is the one whose correctness is easiest to see.
//!
//! # Reporting less than is true, on purpose
//!
//! Because the barrier is ring-wide, a commit of epoch *N* may in fact also
//! reach records already pushed into epoch *N+1*. Those records really are
//! durable when the flush completes. This module does **not** report them as
//! such: `durable_through` advances only to *N*, because *N* is what the
//! caller was promised and what the identity of that flush means. Reporting
//! less than reality is always safe; reporting more never is.
use HashMap;
use io;
use RawHandle;
use ;
/// The unit of durability. Records belong to exactly one, decided when the
/// append is accepted and never changed afterwards.
;
/// Tracks which epoch is open, which commits are in flight, and how far
/// durability has actually reached.