This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
352 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,179 +1,105 @@ | ||
use failure::Fail; | ||
use crate::kernel::lsm::compactor::CompactTask; | ||
use crate::kernel::lsm::version::cleaner::CleanTag; | ||
use std::io; | ||
use thiserror::Error; | ||
use tokio::sync::mpsc::error::SendError; | ||
use tokio::sync::oneshot::error::RecvError; | ||
|
||
/// Error type for kvs | ||
#[derive(Fail, Debug)] | ||
#[derive(Error, Debug)] | ||
#[non_exhaustive] | ||
pub enum KernelError { | ||
/// IO error | ||
#[fail(display = "{}", _0)] | ||
Io(#[cause] io::Error), | ||
#[fail(display = "{}", _0)] | ||
Recv(#[cause] RecvError), | ||
#[error("{0}")] | ||
Io(#[from] io::Error), | ||
|
||
#[error("{0}")] | ||
RecvError(#[from] RecvError), | ||
|
||
#[error("Failed to send compact task")] | ||
SendCompactTaskError(#[from] SendError<CompactTask>), | ||
|
||
#[error("Failed to send clean tag")] | ||
SendCleanTagError(#[from] SendError<CleanTag>), | ||
|
||
/// Serialization or deserialization error | ||
#[fail(display = "{}", _0)] | ||
SerdeBinCode(#[cause] Box<bincode::ErrorKind>), | ||
#[error("{0}")] | ||
SerdeBinCode(#[from] Box<bincode::ErrorKind>), | ||
|
||
/// Remove no-existent key error | ||
#[fail(display = "Key not found")] | ||
#[error("Key not found")] | ||
KeyNotFound, | ||
#[fail(display = "Data is empty")] | ||
|
||
#[error("Data is empty")] | ||
DataEmpty, | ||
#[fail(display = "Max Level is 7")] | ||
|
||
#[error("Max Level is 7")] | ||
LevelOver, | ||
#[fail(display = "Not the correct type of Cmd")] | ||
|
||
#[error("Not the correct type of Cmd")] | ||
NotMatchCmd, | ||
#[fail(display = "CRC code does not match")] | ||
|
||
#[error("CRC code does not match")] | ||
CrcMisMatch, | ||
#[fail(display = "{}", _0)] | ||
SledErr(#[cause] sled::Error), | ||
#[fail(display = "Cache size overflow")] | ||
|
||
#[error("{0}")] | ||
SledErr(#[from] sled::Error), | ||
|
||
#[error("Cache size overflow")] | ||
CacheSizeOverFlow, | ||
#[fail(display = "Cache sharding and size overflow")] | ||
|
||
#[error("Cache sharding and size overflow")] | ||
CacheShardingNotAlign, | ||
#[fail(display = "File not found")] | ||
|
||
#[error("File not found")] | ||
FileNotFound, | ||
|
||
/// 正常情况wal在内存中存在索引则表示硬盘中存在有对应的数据 | ||
/// 而错误则是内存存在索引却在硬盘中不存在这个数据 | ||
#[fail(display = "WAL log load error")] | ||
#[error("WAL log load error")] | ||
WalLoad, | ||
|
||
/// Unexpected command type error. | ||
/// It indicated a corrupted log or a program bug. | ||
#[fail(display = "Unexpected command type")] | ||
#[error("Unexpected command type")] | ||
UnexpectedCommandType, | ||
#[fail(display = "Process already exists")] | ||
|
||
#[error("Process already exists")] | ||
ProcessExists, | ||
#[fail(display = "channel is closed")] | ||
|
||
#[error("channel is closed")] | ||
ChannelClose, | ||
#[fail(display = "{}", _0)] | ||
|
||
#[error("{0}")] | ||
NotSupport(&'static str), | ||
|
||
#[error("The number of caches cannot be divisible by the number of shards")] | ||
ShardingNotAlign, | ||
} | ||
|
||
#[derive(Fail, Debug)] | ||
#[derive(Error, Debug)] | ||
#[non_exhaustive] | ||
pub enum ConnectionError { | ||
#[fail(display = "{}", _0)] | ||
IO(#[cause] io::Error), | ||
#[fail(display = "disconnected")] | ||
#[error("{0}")] | ||
IO(#[from] io::Error), | ||
#[error("disconnected")] | ||
Disconnected, | ||
#[fail(display = "write failed")] | ||
#[error("write failed")] | ||
WriteFailed, | ||
#[fail(display = "wrong instruction")] | ||
#[error("wrong instruction")] | ||
WrongInstruction, | ||
#[fail(display = "encode error")] | ||
#[error("encode error")] | ||
EncodeErr, | ||
#[fail(display = "decode error")] | ||
#[error("decode error")] | ||
DecodeErr, | ||
#[fail(display = "server flush error")] | ||
#[error("server flush error")] | ||
FlushError, | ||
#[fail(display = "{}", _0)] | ||
StoreErr(#[cause] KernelError), | ||
#[fail(display = "Failed to connect to server, {}", _0)] | ||
TonicTransportErr(#[cause] tonic::transport::Error), | ||
#[fail(display = "Failed to call server, {}", _0)] | ||
TonicFailureStatus(#[cause] tonic::Status), | ||
#[fail(display = "Failed to parse addr, {}", _0)] | ||
AddrParseError(#[cause] std::net::AddrParseError), | ||
} | ||
|
||
#[derive(Fail, Debug)] | ||
#[non_exhaustive] | ||
#[allow(missing_copy_implementations)] | ||
pub enum CacheError { | ||
#[fail(display = "The number of caches cannot be divisible by the number of shards")] | ||
ShardingNotAlign, | ||
#[fail(display = "Cache size overflow")] | ||
CacheSizeOverFlow, | ||
#[fail(display = "{}", _0)] | ||
StoreErr(#[cause] KernelError), | ||
} | ||
|
||
impl<T> From<SendError<T>> for KernelError { | ||
#[inline] | ||
fn from(_: SendError<T>) -> Self { | ||
KernelError::ChannelClose | ||
} | ||
} | ||
|
||
impl From<io::Error> for ConnectionError { | ||
#[inline] | ||
fn from(err: io::Error) -> Self { | ||
ConnectionError::IO(err) | ||
} | ||
} | ||
|
||
impl From<io::Error> for KernelError { | ||
#[inline] | ||
fn from(err: io::Error) -> Self { | ||
KernelError::Io(err) | ||
} | ||
} | ||
|
||
impl From<RecvError> for KernelError { | ||
#[inline] | ||
fn from(err: RecvError) -> Self { | ||
KernelError::Recv(err) | ||
} | ||
} | ||
|
||
impl From<Box<bincode::ErrorKind>> for KernelError { | ||
#[inline] | ||
fn from(err: Box<bincode::ErrorKind>) -> Self { | ||
KernelError::SerdeBinCode(err) | ||
} | ||
} | ||
|
||
impl From<sled::Error> for KernelError { | ||
#[inline] | ||
fn from(err: sled::Error) -> Self { | ||
KernelError::SledErr(err) | ||
} | ||
} | ||
|
||
impl From<KernelError> for ConnectionError { | ||
#[inline] | ||
fn from(err: KernelError) -> Self { | ||
ConnectionError::StoreErr(err) | ||
} | ||
} | ||
|
||
impl From<tonic::Status> for ConnectionError { | ||
#[inline] | ||
fn from(status: tonic::Status) -> Self { | ||
ConnectionError::TonicFailureStatus(status) | ||
} | ||
} | ||
|
||
impl From<tonic::transport::Error> for ConnectionError { | ||
#[inline] | ||
fn from(err: tonic::transport::Error) -> Self { | ||
ConnectionError::TonicTransportErr(err) | ||
} | ||
} | ||
|
||
impl From<std::net::AddrParseError> for ConnectionError { | ||
#[inline] | ||
fn from(err: std::net::AddrParseError) -> Self { | ||
ConnectionError::AddrParseError(err) | ||
} | ||
} | ||
|
||
impl From<CacheError> for KernelError { | ||
#[inline] | ||
fn from(value: CacheError) -> Self { | ||
match value { | ||
CacheError::StoreErr(kv_error) => kv_error, | ||
CacheError::CacheSizeOverFlow => KernelError::CacheSizeOverFlow, | ||
CacheError::ShardingNotAlign => KernelError::CacheShardingNotAlign, | ||
} | ||
} | ||
} | ||
|
||
impl From<KernelError> for CacheError { | ||
#[inline] | ||
fn from(value: KernelError) -> Self { | ||
CacheError::StoreErr(value) | ||
} | ||
#[error("Failed to connect to server, {0}")] | ||
TonicTransportErr(#[from] tonic::transport::Error), | ||
#[error("Failed to call server, {0}")] | ||
TonicFailureStatus(#[from] tonic::Status), | ||
#[error("Failed to parse addr, {0}")] | ||
AddrParseError(#[from] std::net::AddrParseError), | ||
#[error("{0}")] | ||
KernelError(#[from] KernelError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.