Skip to main content

laminar_storage/incremental/
error.rs

1//! Error types for incremental checkpointing.
2
3use thiserror::Error;
4
5/// Errors that can occur during incremental checkpointing.
6#[derive(Debug, Error)]
7pub enum IncrementalCheckpointError {
8    /// I/O error during checkpoint operations.
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// Serialization error.
13    #[error("Serialization error: {0}")]
14    Serialization(String),
15
16    /// Deserialization error.
17    #[error("Deserialization error: {0}")]
18    Deserialization(String),
19
20    /// WAL error.
21    #[error("WAL error: {0}")]
22    Wal(String),
23
24    /// Checkpoint not found.
25    #[error("Checkpoint not found: {0}")]
26    NotFound(String),
27
28    /// Checkpoint corruption detected.
29    #[error("Checkpoint corruption: {0}")]
30    Corruption(String),
31
32    /// Recovery failed.
33    #[error("Recovery failed: {0}")]
34    Recovery(String),
35
36    /// Buffer overflow (backpressure signal).
37    #[error("Changelog buffer overflow at epoch {epoch}")]
38    BufferOverflow {
39        /// The epoch at which overflow occurred.
40        epoch: u64,
41    },
42
43    /// Invalid configuration.
44    #[error("Invalid configuration: {0}")]
45    InvalidConfig(String),
46
47    /// Checkpoint already exists.
48    #[error("Checkpoint already exists for epoch {0}")]
49    AlreadyExists(u64),
50
51    /// Epoch mismatch during recovery.
52    #[error("Epoch mismatch: expected {expected}, found {found}")]
53    EpochMismatch {
54        /// Expected epoch.
55        expected: u64,
56        /// Found epoch.
57        found: u64,
58    },
59
60    /// CRC checksum mismatch.
61    #[error("CRC mismatch at offset {offset}: expected {expected:#x}, computed {computed:#x}")]
62    CrcMismatch {
63        /// Offset where mismatch occurred.
64        offset: u64,
65        /// Expected CRC.
66        expected: u32,
67        /// Computed CRC.
68        computed: u32,
69    },
70}
71
72impl IncrementalCheckpointError {
73    /// Returns true if this error indicates a transient failure that may succeed on retry.
74    #[must_use]
75    pub fn is_transient(&self) -> bool {
76        matches!(self, Self::Io(_) | Self::BufferOverflow { .. })
77    }
78
79    /// Returns true if this error indicates data corruption.
80    #[must_use]
81    pub fn is_corruption(&self) -> bool {
82        matches!(self, Self::Corruption(_) | Self::CrcMismatch { .. })
83    }
84}