Skip to content

Commit

Permalink
dont panic on error during disk buffer creation (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Mar 8, 2024
1 parent 243d00b commit 7fb14f9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
CachedStore, Obj, ShaleError, ShaleStore, SpaceId, Storable, StoredView,
},
};
use aiofut::AioError;
use async_trait::async_trait;
use bytemuck::{cast_slice, Pod, Zeroable};

Expand Down Expand Up @@ -65,6 +66,7 @@ pub type SharedStore = CompactSpace<Node, StoreRevShared>;
#[derive(Debug)]
#[non_exhaustive]
pub enum DbError {
Aio(AioError),
InvalidParams,
Merkle(MerkleError),
System(nix::Error),
Expand All @@ -78,6 +80,7 @@ pub enum DbError {
impl fmt::Display for DbError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DbError::Aio(e) => write!(f, "aio error: {e:?}"),
DbError::InvalidParams => write!(f, "invalid parameters provided"),
DbError::Merkle(e) => write!(f, "merkle error: {e:?}"),
DbError::System(e) => write!(f, "system error: {e:?}"),
Expand Down Expand Up @@ -542,9 +545,8 @@ impl Db {
.max_revisions(cfg.wal.max_revisions)
.build();

#[allow(clippy::unwrap_used)]
let disk_buffer =
DiskBuffer::new(inbound, &cfg.buffer, &wal_config).expect("DiskBuffer::new");
DiskBuffer::new(inbound, &cfg.buffer, &wal_config).map_err(DbError::Aio)?;

let disk_thread = Some(
std::thread::Builder::new()
Expand Down
4 changes: 4 additions & 0 deletions firewood/src/merkle/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::collections::HashMap;
use crate::shale::ObjWriteSizeError;
use crate::shale::{disk_address::DiskAddress, ShaleError, ShaleStore};
use crate::v2::api::HashKey;
use aiofut::AioError;
use nix::errno::Errno;
use sha3::Digest;
use thiserror::Error;
Expand All @@ -23,6 +24,8 @@ use super::{BinarySerde, EncodedNode, NodeObjRef};

#[derive(Debug, Error)]
pub enum ProofError {
#[error("aio error: {0:?}")]
AioError(AioError),
#[error("decoding error")]
DecodeError(#[from] bincode::Error),
#[error("no such node")]
Expand Down Expand Up @@ -74,6 +77,7 @@ impl From<DataStoreError> for ProofError {
impl From<DbError> for ProofError {
fn from(d: DbError) -> ProofError {
match d {
DbError::Aio(e) => ProofError::AioError(e),
DbError::InvalidParams => ProofError::InvalidProof,
DbError::Merkle(e) => ProofError::InvalidNode(e),
DbError::System(e) => ProofError::SystemError(e),
Expand Down
1 change: 1 addition & 0 deletions firewood/src/v2/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{db::DbError, v2::api};
impl From<DbError> for api::Error {
fn from(value: DbError) -> Self {
match value {
DbError::Aio(e) => api::Error::InternalError(Box::new(e)),
DbError::InvalidParams => api::Error::InternalError(Box::new(value)),
DbError::Merkle(e) => api::Error::InternalError(Box::new(e)),
DbError::System(e) => api::Error::IO(e.into()),
Expand Down
1 change: 1 addition & 0 deletions libaio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ emulated-failure = []
libc = "0.2.153"
parking_lot = "0.12.1"
crossbeam-channel = "0.5.11"
thiserror = "1.0.57"

[dev-dependencies]
futures = "0.3.30"
Expand Down
7 changes: 6 additions & 1 deletion libaio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ use std::sync::{
atomic::{AtomicPtr, AtomicUsize, Ordering},
Arc,
};
use thiserror::Error;

const LIBAIO_EAGAIN: libc::c_int = -libc::EAGAIN;
const LIBAIO_ENOMEM: libc::c_int = -libc::ENOMEM;
const LIBAIO_ENOSYS: libc::c_int = -libc::ENOSYS;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Error)]
pub enum AioError {
#[error("maxevents is too large")]
MaxEventsTooLarge,
#[error("low kernel resources")]
LowKernelRes,
#[error("not supported")]
NotSupported,
#[error("other aio error")]
OtherError,
}

Expand Down

0 comments on commit 7fb14f9

Please sign in to comment.