Skip to content

Commit

Permalink
feat: add wal errors
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds authored and mergify[bot] committed Dec 11, 2023
1 parent 31cf545 commit df4039d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions curp/src/server/storage/wal/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::io;

use thiserror::Error;

/// Errors of the `WALStorage`
#[derive(Debug, Error)]
pub(crate) enum WALError {
/// The WAL segment might reach on end
///
/// NOTE: This exists because we cannot tell the difference between a corrupted WAL
/// and a normally ended WAL, as the segment files are all preallocated with zeros
#[error("WAL ended")]
MaybeEnded,
/// The WAL corrupt error
#[error("WAL corrupted: {0}")]
Corrupted(CorruptType),
/// The IO error
#[error("IO error: {0}")]
IO(#[from] io::Error),
}

/// The type of the `Corrupted` error
#[derive(Debug, Error)]
pub(crate) enum CorruptType {
/// Corrupt because of decode failure
#[error("Error occurred when decoding WAL: {0}")]
Codec(String),
/// Corrupt because of checksum failure
#[error("Checksumming for the file has failed")]
Checksum,
/// Corrupt because of some logs is missing
#[error("The recovered logs are not continue")]
LogNotContinue,
}
3 changes: 3 additions & 0 deletions curp/src/server/storage/wal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![allow(unused)] // TODO: remove this until used

/// WAL errors
mod error;

/// File utils
mod util;

0 comments on commit df4039d

Please sign in to comment.