Skip to content

Commit

Permalink
MRG: propagate error from RocksDB::open on bad directory (#3306)
Browse files Browse the repository at this point in the history
Extracted from #3305

This PR adjusts `RevIndex::open` to propagate a `RocksDBError` when
opening a non-RocksDB directory.

It also modifies the creation printout in `RevIndex::create` to
distinguish index completion from interim output, for slightly easier
debugging.
  • Loading branch information
ctb authored Aug 26, 2024
1 parent 38af8fe commit c46618e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/src/index/revindex/disk_revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl RevIndex {

info!("Compact SSTs");
index.compact();
info!("Processed {} reference sigs", processed_sigs.into_inner());
info!("Done! Processed {} reference sigs", processed_sigs.into_inner());

Ok(module::RevIndex::Plain(index))
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/src/index/revindex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl RevIndex {

pub fn open<P: AsRef<Path>>(index: P, read_only: bool, spec: Option<&str>) -> Result<Self> {
let opts = db_options();
let cfs = DB::list_cf(&opts, index.as_ref()).unwrap();
let cfs = DB::list_cf(&opts, index.as_ref())?;

if cfs.into_iter().any(|c| c == COLORS) {
// TODO: ColorRevIndex can't be read-only for now,
Expand Down Expand Up @@ -1020,4 +1020,14 @@ mod test {

Ok(())
}

#[test]
fn rocksdb_storage_fail_bad_directory() -> Result<()> {
let testdir = TempDir::new()?;

match RevIndex::open(testdir, true, None) {
Err(_) => Ok(()),
Ok(_) => panic!("test should not reach here"),
}
}
}

0 comments on commit c46618e

Please sign in to comment.