1use crate::{
2 key::{StableKey, StableKeyError},
3 ledger::LedgerPayloadEnvelopeError,
4 physical::CommitRecoveryError,
5 slot::MemoryManagerSlot,
6};
7
8#[non_exhaustive]
15#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
16pub enum LedgerIntegrityError {
17 #[error("ledger exceeds {resource} limit {limit}")]
19 LimitExceeded {
20 resource: &'static str,
21 limit: usize,
22 },
23 #[error("stable key '{stable_key}' appears in more than one allocation record")]
25 DuplicateStableKey {
26 stable_key: StableKey,
28 },
29 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
31 DuplicateSlot {
32 slot: MemoryManagerSlot,
34 },
35 #[error("stable key '{stable_key}' has first_generation after last_seen_generation")]
37 InvalidRecordGenerationOrder {
38 stable_key: StableKey,
40 first_generation: u64,
42 last_seen_generation: u64,
44 },
45 #[error(
47 "stable key '{stable_key}' references generation {generation} after current generation {current_generation}"
48 )]
49 FutureRecordGeneration {
50 stable_key: StableKey,
52 generation: u64,
54 current_generation: u64,
56 },
57 #[error("stable key '{stable_key}' was retired before first_generation")]
59 RetiredBeforeFirstGeneration {
60 stable_key: StableKey,
62 first_generation: u64,
64 retired_generation: u64,
66 },
67 #[error("stable key '{stable_key}' was retired at or before last_seen_generation")]
69 RetirementNotAfterLastSeen {
70 stable_key: StableKey,
72 last_seen_generation: u64,
74 retired_generation: u64,
76 },
77 #[error("stable key '{stable_key}' has empty schema metadata history")]
79 EmptySchemaHistory {
80 stable_key: StableKey,
82 },
83 #[error(
85 "stable key '{stable_key}' has schema metadata that does not begin at first_generation"
86 )]
87 SchemaHistoryStartMismatch {
88 stable_key: StableKey,
90 first_generation: u64,
92 schema_generation: u64,
94 },
95 #[error("stable key '{stable_key}' has non-increasing schema metadata generation history")]
97 NonIncreasingSchemaHistory {
98 stable_key: StableKey,
100 },
101 #[error("stable key '{stable_key}' has schema metadata generation outside the ledger bounds")]
103 SchemaHistoryOutOfBounds {
104 stable_key: StableKey,
106 generation: u64,
108 },
109 #[error("stable key '{stable_key}' has schema metadata after last_seen_generation")]
111 SchemaHistoryAfterLastSeen {
112 stable_key: StableKey,
114 generation: u64,
116 last_seen_generation: u64,
118 },
119 #[error("generation {generation} appears more than once")]
121 DuplicateGeneration {
122 generation: u64,
124 },
125 #[error("generation {generation} is after current generation {current_generation}")]
127 FutureGeneration {
128 generation: u64,
130 current_generation: u64,
132 },
133 #[error("generation {generation} has invalid parent generation {parent_generation}")]
135 InvalidParentGeneration {
136 generation: u64,
138 parent_generation: u64,
140 },
141 #[error("current generation {current_generation} has no committed generation record")]
143 MissingCurrentGenerationRecord {
144 current_generation: u64,
146 },
147 #[error("generation records are not strictly increasing at generation {generation}")]
149 NonIncreasingGenerationRecords {
150 generation: u64,
152 },
153 #[error(
155 "generation {generation} does not link to previous committed generation {expected_parent}"
156 )]
157 BrokenGenerationChain {
158 generation: u64,
160 expected_parent: u64,
162 actual_parent: u64,
164 },
165 #[error("stable key '{stable_key}' references unknown generation {generation}")]
167 UnknownRecordGeneration {
168 stable_key: StableKey,
170 generation: u64,
172 },
173}
174
175#[non_exhaustive]
180#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
181pub enum LedgerCommitError {
182 #[error(transparent)]
184 Recovery(CommitRecoveryError),
185 #[error(transparent)]
187 PayloadEnvelope(LedgerPayloadEnvelopeError),
188 #[error(
190 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
191 )]
192 PhysicalLogicalGenerationMismatch {
193 physical_generation: u64,
195 logical_generation: u64,
197 },
198 #[error("allocation ledger codec failed: {0}")]
200 Codec(String),
201 #[error(transparent)]
203 Integrity(LedgerIntegrityError),
204}
205
206#[non_exhaustive]
213#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
214pub enum AllocationStageError {
215 #[error(transparent)]
216 Integrity(#[from] LedgerIntegrityError),
217 #[error(
219 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
220 )]
221 StaleValidatedAllocations {
222 validated_generation: u64,
224 ledger_generation: u64,
226 },
227 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
229 StableKeySlotConflict {
230 stable_key: StableKey,
232 historical_slot: MemoryManagerSlot,
234 declared_slot: MemoryManagerSlot,
236 },
237 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
239 SlotStableKeyConflict {
240 slot: MemoryManagerSlot,
242 historical_key: StableKey,
244 declared_key: StableKey,
246 },
247 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
249 RetiredAllocation {
250 stable_key: StableKey,
252 slot: MemoryManagerSlot,
254 },
255}
256
257#[non_exhaustive]
262#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
263pub enum AllocationReservationError {
264 #[error(transparent)]
265 Integrity(#[from] LedgerIntegrityError),
266 #[error("ledger generation {generation} cannot be advanced without overflow")]
268 GenerationOverflow {
269 generation: u64,
271 },
272 #[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
274 TooManyReservations {
275 count: usize,
277 },
278 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
280 StableKeySlotConflict {
281 stable_key: StableKey,
283 historical_slot: MemoryManagerSlot,
285 reserved_slot: MemoryManagerSlot,
287 },
288 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
290 SlotStableKeyConflict {
291 slot: MemoryManagerSlot,
293 historical_key: StableKey,
295 reserved_key: StableKey,
297 },
298 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
300 ActiveAllocation {
301 stable_key: StableKey,
303 slot: MemoryManagerSlot,
305 },
306 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
308 RetiredAllocation {
309 stable_key: StableKey,
311 slot: MemoryManagerSlot,
313 },
314}
315
316#[non_exhaustive]
321#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
322pub enum AllocationRetirementError {
323 #[error(transparent)]
324 Integrity(#[from] LedgerIntegrityError),
325 #[error(transparent)]
327 Key(StableKeyError),
328 #[error("ledger generation {generation} cannot be advanced without overflow")]
330 GenerationOverflow {
331 generation: u64,
333 },
334 #[error("stable key '{0}' has no allocation record to retire")]
336 UnknownStableKey(StableKey),
337 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
339 SlotMismatch {
340 stable_key: StableKey,
342 historical_slot: MemoryManagerSlot,
344 retired_slot: MemoryManagerSlot,
346 },
347 #[error("stable key '{stable_key}' was already retired")]
349 AlreadyRetired {
350 stable_key: StableKey,
352 slot: MemoryManagerSlot,
354 },
355}