fjall/journal/
error.rs

1// Copyright (c) 2024-present, fjall-rs
2// This source code is licensed under both the Apache 2.0 and MIT License
3// (found in the LICENSE-* files in the repository)
4
5/// Recovery mode to use
6///
7/// Based on `RocksDB`'s WAL Recovery Modes: <https://github.com/facebook/rocksdb/wiki/WAL-Recovery-Modes>
8#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
9#[non_exhaustive]
10pub enum RecoveryMode {
11    /// The last batch in the journal may be corrupt on crash,
12    /// and will be discarded without error.
13    ///
14    /// This mode will error on any other IO or consistency error, so
15    /// any data up to the tail will be consistent.
16    ///
17    /// This is the default mode.
18    #[default]
19    TolerateCorruptTail,
20    // TODO: in the future?
21    /*  /// Skips corrupt (invalid checksum) batches. This may violate
22    /// consistency, but will recover as much data as possible.
23    SkipInvalidBatches, */
24    // TODO: absolute consistency
25}
26
27/// Errors that can occur during journal recovery
28#[derive(Clone, Copy, Debug, Eq, PartialEq)]
29#[allow(clippy::module_name_repetitions)]
30pub enum RecoveryError {
31    /// Batch had less items than expected, so it's incomplete
32    InsufficientLength,
33
34    /* /// Batch was not terminated, so it's possibly incomplete
35    MissingTerminator, */
36    /// Too many items in batch
37    TooManyItems,
38
39    /// The checksum value does not match the expected value
40    ChecksumMismatch,
41}
42
43impl std::fmt::Display for RecoveryError {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        write!(f, "RecoveryError({self:?})")
46    }
47}
48
49impl std::error::Error for RecoveryError {}