Skip to content

Commit

Permalink
fix: pr related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cernicc committed May 28, 2024
1 parent bb2d427 commit f860151
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
2 changes: 1 addition & 1 deletion storage/file-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
tempfile = "3.10.1"
tempfile = { workspace = true }

[lints]
workspace = true
4 changes: 1 addition & 3 deletions storage/file-storage/src/piecestore/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -65,5 +63,5 @@ pub enum PieceStoreError {
Deserialization(String),

#[error(transparent)]
StoreError(#[from] RocksDBError),
StoreError(#[from] rocksdb::Error),
}
28 changes: 13 additions & 15 deletions storage/file-storage/src/piecestore/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f860151

Please sign in to comment.