Skip to main content

laminar_storage/per_core_wal/
error.rs

1//! Error types for per-core WAL operations.
2
3use std::path::PathBuf;
4
5/// Errors that can occur in per-core WAL operations.
6#[derive(Debug, thiserror::Error)]
7pub enum PerCoreWalError {
8    /// IO error during WAL operations.
9    #[error("IO error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// Serialization error when writing entries.
13    #[error("Serialization error: {0}")]
14    Serialization(String),
15
16    /// Deserialization error when reading entries.
17    #[error("Deserialization error: {0}")]
18    Deserialization(String),
19
20    /// CRC32 checksum mismatch.
21    #[error("CRC32 checksum mismatch at position {position} in segment {core_id}: expected {expected:#010x}, got {actual:#010x}")]
22    ChecksumMismatch {
23        /// Core ID of the segment.
24        core_id: usize,
25        /// Position of the corrupted record.
26        position: u64,
27        /// Expected CRC32 value.
28        expected: u32,
29        /// Actual CRC32 value.
30        actual: u32,
31    },
32
33    /// Torn write detected (partial record at end of WAL).
34    #[error("Torn write detected at position {position} in segment {core_id}: {reason}")]
35    TornWrite {
36        /// Core ID of the segment.
37        core_id: usize,
38        /// Position where torn write was detected.
39        position: u64,
40        /// Description of the torn write.
41        reason: String,
42    },
43
44    /// Data corruption detected (e.g., oversized entry).
45    #[error("Corrupted WAL entry at position {position} in segment {core_id}: {reason}")]
46    Corrupted {
47        /// Core ID of the segment.
48        core_id: usize,
49        /// Position of the corrupted record.
50        position: u64,
51        /// Description of the corruption.
52        reason: String,
53    },
54
55    /// Invalid core ID.
56    #[error("Invalid core ID {core_id}: max is {max_core_id}")]
57    InvalidCoreId {
58        /// The invalid core ID.
59        core_id: usize,
60        /// The maximum valid core ID.
61        max_core_id: usize,
62    },
63
64    /// Segment file not found.
65    #[error("Segment file not found for core {core_id}: {path}")]
66    SegmentNotFound {
67        /// Core ID.
68        core_id: usize,
69        /// Expected path.
70        path: PathBuf,
71    },
72
73    /// Checkpoint not found.
74    #[error("Checkpoint not found at {path}")]
75    CheckpointNotFound {
76        /// Expected path.
77        path: PathBuf,
78    },
79
80    /// Recovery failed.
81    #[error("Recovery failed: {0}")]
82    RecoveryFailed(String),
83
84    /// Writer not initialized.
85    #[error("Writer for core {0} not initialized")]
86    WriterNotInitialized(usize),
87
88    /// Epoch mismatch during checkpoint.
89    #[error("Epoch mismatch: expected {expected}, got {actual}")]
90    EpochMismatch {
91        /// Expected epoch.
92        expected: u64,
93        /// Actual epoch.
94        actual: u64,
95    },
96
97    /// Incremental checkpoint error.
98    #[error("Incremental checkpoint error: {0}")]
99    IncrementalCheckpoint(#[from] crate::incremental::IncrementalCheckpointError),
100}