diff --git a/Cargo.toml b/Cargo.toml index 624c0842..2134a493 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ serde_json = { version = "1.0.114", default-features = false } serde_yaml = { version = "0.9" } smallvec = "1.11.0" syn = { version = "2.0.53" } +tempfile = "3.10.1" thiserror = { version = "1.0.48" } tracing-subscriber = { version = "0.3.18" } diff --git a/storage/file-storage/Cargo.toml b/storage/file-storage/Cargo.toml index 9c9f1181..59911251 100644 --- a/storage/file-storage/Cargo.toml +++ b/storage/file-storage/Cargo.toml @@ -15,7 +15,7 @@ serde = { workspace = true } thiserror = { workspace = true } [dev-dependencies] -tempfile = "3.10.1" +tempfile = { workspace = true } [lints] workspace = true diff --git a/storage/file-storage/src/piecestore/mod.rs b/storage/file-storage/src/piecestore/mod.rs index 5ef4b2cd..cd2201b5 100644 --- a/storage/file-storage/src/piecestore/mod.rs +++ b/storage/file-storage/src/piecestore/mod.rs @@ -1,12 +1,10 @@ use std::collections::HashMap; use cid::Cid; -use rocksdb::RocksDBError; use thiserror::Error; use self::types::{BlockLocation, CidInfo, DealInfo, PieceInfo}; -pub mod rocksdb; mod types; pub trait PieceStore { @@ -65,5 +63,5 @@ pub enum PieceStoreError { Deserialization(String), #[error(transparent)] - StoreError(#[from] RocksDBError), + StoreError(#[from] rocksdb::Error), } diff --git a/storage/file-storage/src/piecestore/rocksdb.rs b/storage/file-storage/src/piecestore/rocksdb.rs index 1f9e1572..3739a159 100644 --- a/storage/file-storage/src/piecestore/rocksdb.rs +++ b/storage/file-storage/src/piecestore/rocksdb.rs @@ -10,9 +10,10 @@ use super::{ }; use crate::piecestore::types::{PieceBlockLocation, PieceInfo}; -pub type RocksDBError = rocksdb::Error; - +/// Column family name used to store piece. const PIECES_CF: &str = "pieces"; + +/// Column family name used to store CID infos. const CID_INFOS_CF: &str = "cid_infos"; pub struct RocksDBStateStoreConfig { @@ -26,7 +27,8 @@ pub struct RocksDBPieceStore { impl RocksDBPieceStore { /// Get the column family handle for the given column family name. Panics if - /// the column family is not present. + /// the column family is not present. The column families needed and used + /// are created at initialization. They will always be present. #[track_caller] fn cf_handle(&self, cf_name: &str) -> &ColumnFamily { self.database @@ -42,18 +44,14 @@ impl RocksDBPieceStore { .iterator_cf(self.cf_handle(cf_name), IteratorMode::Start); for cid in iterator { - match cid { - Ok((key, _)) => { - let parsed_cid = Cid::try_from(key.as_ref()).map_err(|err| { - // We know that all stored CIDs are valid, so this - // should only happen if database is corrupted. - PieceStoreError::Deserialization(format!("invalid CID: {}", err)) - })?; - - result.push(parsed_cid); - } - Err(e) => return Err(e.into()), - } + let (key, _) = cid?; + let parsed_cid = Cid::try_from(key.as_ref()).map_err(|err| { + // We know that all stored CIDs are valid, so this + // should only happen if database is corrupted. + PieceStoreError::Deserialization(format!("invalid CID: {}", err)) + })?; + + result.push(parsed_cid); } Ok(result)