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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
use crate::{
declaration::DeclarationSnapshotError,
key::{StableKey, StableKeyError},
physical::CommitRecoveryError,
schema::SchemaMetadataError,
slot::AllocationSlotDescriptor,
};
///
/// LedgerCompatibilityError
///
/// Decoded ledger format is unsupported by this reader.
#[derive(Clone, Copy, Debug, Eq, thiserror::Error, PartialEq)]
pub enum LedgerCompatibilityError {
/// Ledger schema version is outside the supported range.
#[error(
"ledger_schema_version {found} is unsupported; supported range is {min_supported}-{max_supported}"
)]
UnsupportedLedgerSchemaVersion {
/// Version found in the ledger.
found: u32,
/// Minimum supported version.
min_supported: u32,
/// Maximum supported version.
max_supported: u32,
},
/// Physical format ID is not supported by this reader.
#[error("physical_format_id {found} is unsupported; supported format is {supported}")]
UnsupportedPhysicalFormat {
/// Format found in the ledger.
found: u32,
/// Supported format ID.
supported: u32,
},
}
///
/// LedgerIntegrityError
///
/// Decoded ledger violates structural allocation-history invariants.
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum LedgerIntegrityError {
/// Stable key appears in more than one allocation record.
#[error("stable key '{stable_key}' appears in more than one allocation record")]
DuplicateStableKey {
/// Duplicate stable key.
stable_key: StableKey,
},
/// Allocation slot appears in more than one allocation record.
#[error("allocation slot '{slot:?}' appears in more than one allocation record")]
DuplicateSlot {
/// Duplicate allocation slot.
slot: Box<AllocationSlotDescriptor>,
},
/// Allocation record generation ordering is invalid.
#[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
InvalidRecordGenerationOrder {
/// Stable key whose record is invalid.
stable_key: StableKey,
/// First generation in the record.
first_generation: u64,
/// Last seen generation in the record.
last_seen_generation: u64,
},
/// Allocation record points past the current generation.
#[error(
"stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
)]
FutureRecordGeneration {
/// Stable key whose record is invalid.
stable_key: StableKey,
/// Generation referenced by the record.
generation: u64,
/// Current ledger generation.
current_generation: u64,
},
/// Non-retired allocation carries retired metadata.
#[error("stable key '{stable_key}' is not retired but has retired_generation metadata")]
UnexpectedRetiredGeneration {
/// Stable key whose record is invalid.
stable_key: StableKey,
},
/// Retired allocation is missing retired metadata.
#[error("stable key '{stable_key}' is retired but retired_generation is missing")]
MissingRetiredGeneration {
/// Stable key whose record is invalid.
stable_key: StableKey,
},
/// Retired generation predates the allocation record.
#[error("stable key '{stable_key}' has retired_generation before first_generation")]
RetiredBeforeFirstGeneration {
/// Stable key whose record is invalid.
stable_key: StableKey,
/// First generation in the record.
first_generation: u64,
/// Retired generation in the record.
retired_generation: u64,
},
/// Allocation record has no schema metadata history.
#[error("stable key '{stable_key}' has empty schema metadata history")]
EmptySchemaHistory {
/// Stable key whose record is invalid.
stable_key: StableKey,
},
/// Schema metadata generation history is not strictly increasing.
#[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
NonIncreasingSchemaHistory {
/// Stable key whose record is invalid.
stable_key: StableKey,
},
/// Schema metadata generation is outside the allocation record lifetime.
#[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
SchemaHistoryOutOfBounds {
/// Stable key whose record is invalid.
stable_key: StableKey,
/// Schema metadata generation.
generation: u64,
},
/// Schema metadata in committed allocation history is invalid.
#[error("stable key '{stable_key}' has invalid schema metadata at generation {generation}")]
InvalidSchemaMetadata {
/// Stable key whose schema metadata is invalid.
stable_key: StableKey,
/// Generation that recorded the invalid schema metadata.
generation: u64,
/// Schema metadata validation error.
error: SchemaMetadataError,
},
/// Generation record appears more than once.
#[error("generation {generation} appears more than once")]
DuplicateGeneration {
/// Duplicate generation.
generation: u64,
},
/// Generation record points past the current generation.
#[error("generation {generation} is after current generation {current_generation}")]
FutureGeneration {
/// Generation record value.
generation: u64,
/// Current ledger generation.
current_generation: u64,
},
/// Generation parent does not precede the child generation.
#[error("generation {generation} has invalid parent generation {parent_generation:?}")]
InvalidParentGeneration {
/// Generation record value.
generation: u64,
/// Invalid parent generation.
parent_generation: Option<u64>,
},
/// Current ledger generation has no committed generation record.
#[error("current generation {current_generation} has no committed generation record")]
MissingCurrentGenerationRecord {
/// Current ledger generation.
current_generation: u64,
},
/// Generation records are not strictly increasing in durable order.
#[error("generation records are not strictly increasing at generation {generation}")]
NonIncreasingGenerationRecords {
/// Non-increasing generation.
generation: u64,
},
/// Generation record parent does not match the previous committed generation.
#[error(
"generation {generation} does not link to previous committed generation {expected_parent:?}"
)]
BrokenGenerationChain {
/// Generation whose parent link is invalid.
generation: u64,
/// Expected parent generation.
expected_parent: Option<u64>,
/// Actual parent generation.
actual_parent: Option<u64>,
},
/// Allocation record refers to a generation absent from committed history.
#[error("stable key '{stable_key}' references unknown generation {generation}")]
UnknownRecordGeneration {
/// Stable key whose record is invalid.
stable_key: StableKey,
/// Unknown generation.
generation: u64,
},
/// Generation diagnostic metadata is invalid.
#[error(transparent)]
DiagnosticMetadata(DeclarationSnapshotError),
}
///
/// LedgerCommitError
///
/// Failure to recover or commit a logical allocation ledger.
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum LedgerCommitError<E> {
/// Protected physical commit recovery failed.
#[error(transparent)]
Recovery(CommitRecoveryError),
/// Physical slot generation and decoded logical ledger generation disagree.
#[error(
"physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
)]
PhysicalLogicalGenerationMismatch {
/// Generation encoded in the physical commit slot.
physical_generation: u64,
/// Generation decoded from the logical allocation ledger.
logical_generation: u64,
},
/// Integration-supplied codec failed.
#[error("allocation ledger codec failed")]
Codec(E),
/// Decoded ledger format is not compatible with this reader.
#[error(transparent)]
Compatibility(LedgerCompatibilityError),
/// Decoded ledger violates structural allocation-history invariants.
#[error(transparent)]
Integrity(LedgerIntegrityError),
}
///
/// AllocationStageError
///
/// Failure to stage a validated allocation generation.
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationStageError {
/// Validated declarations were produced against a different ledger generation.
#[error(
"validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
)]
StaleValidatedAllocations {
/// Generation carried by the validated allocation session.
validated_generation: u64,
/// Current ledger generation.
ledger_generation: u64,
},
/// Ledger generation cannot be advanced without overflow.
#[error("ledger generation {generation} cannot be advanced without overflow")]
GenerationOverflow {
/// Current ledger generation.
generation: u64,
},
/// A staged declaration carries invalid schema metadata.
#[error("stable key '{stable_key}' has invalid schema metadata")]
InvalidSchemaMetadata {
/// Stable key whose schema metadata is invalid.
stable_key: StableKey,
/// Schema metadata validation error.
error: SchemaMetadataError,
},
/// Stable key was historically bound to a different slot.
#[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
StableKeySlotConflict {
/// Stable key being declared.
stable_key: StableKey,
/// Historical slot for the stable key.
historical_slot: Box<AllocationSlotDescriptor>,
/// Slot claimed by the declaration.
declared_slot: Box<AllocationSlotDescriptor>,
},
/// Slot was historically bound to a different stable key.
#[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
SlotStableKeyConflict {
/// Slot being declared.
slot: Box<AllocationSlotDescriptor>,
/// Historical stable key for the slot.
historical_key: StableKey,
/// Stable key claimed by the declaration.
declared_key: StableKey,
},
/// Current declaration attempted to revive a retired allocation.
#[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
RetiredAllocation {
/// Retired stable key.
stable_key: StableKey,
/// Retired allocation slot.
slot: Box<AllocationSlotDescriptor>,
},
}
///
/// AllocationReservationError
///
/// Failure to stage a reservation generation.
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationReservationError {
/// Ledger generation cannot be advanced without overflow.
#[error("ledger generation {generation} cannot be advanced without overflow")]
GenerationOverflow {
/// Current ledger generation.
generation: u64,
},
/// A staged reservation carries invalid schema metadata.
#[error("stable key '{stable_key}' has invalid schema metadata")]
InvalidSchemaMetadata {
/// Stable key whose schema metadata is invalid.
stable_key: StableKey,
/// Schema metadata validation error.
error: SchemaMetadataError,
},
/// Stable key was historically bound to a different slot.
#[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
StableKeySlotConflict {
/// Stable key being reserved.
stable_key: StableKey,
/// Historical slot for the stable key.
historical_slot: Box<AllocationSlotDescriptor>,
/// Slot claimed by the reservation.
reserved_slot: Box<AllocationSlotDescriptor>,
},
/// Slot was historically bound to a different stable key.
#[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
SlotStableKeyConflict {
/// Slot being reserved.
slot: Box<AllocationSlotDescriptor>,
/// Historical stable key for the slot.
historical_key: StableKey,
/// Stable key claimed by the reservation.
reserved_key: StableKey,
},
/// Allocation already exists as an active record.
#[error("stable key '{stable_key}' is already active and cannot be reserved")]
ActiveAllocation {
/// Active stable key.
stable_key: StableKey,
/// Active allocation slot.
slot: Box<AllocationSlotDescriptor>,
},
/// Allocation was already retired and cannot be reserved.
#[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
RetiredAllocation {
/// Retired stable key.
stable_key: StableKey,
/// Retired allocation slot.
slot: Box<AllocationSlotDescriptor>,
},
}
///
/// AllocationRetirementError
///
/// Failure to stage an explicit retirement generation.
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationRetirementError {
/// Stable-key grammar failure.
#[error(transparent)]
Key(StableKeyError),
/// Ledger generation cannot be advanced without overflow.
#[error("ledger generation {generation} cannot be advanced without overflow")]
GenerationOverflow {
/// Current ledger generation.
generation: u64,
},
/// Stable key has no historical allocation record.
#[error("stable key '{0}' has no allocation record to retire")]
UnknownStableKey(StableKey),
/// Stable key was historically bound to a different slot.
#[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
SlotMismatch {
/// Stable key being retired.
stable_key: StableKey,
/// Historical slot for the stable key.
historical_slot: Box<AllocationSlotDescriptor>,
/// Slot named by the retirement request.
retired_slot: Box<AllocationSlotDescriptor>,
},
/// Allocation was already retired.
#[error("stable key '{stable_key}' was already retired")]
AlreadyRetired {
/// Retired stable key.
stable_key: StableKey,
/// Retired allocation slot.
slot: Box<AllocationSlotDescriptor>,
},
}