Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
feat: Force quit rocksdb worker threads upon dropping. (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell authored Jan 16, 2024
1 parent 45ab315 commit 21bf742
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions rust/noosphere-storage/src/implementation/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@ type DbInner = DBWithThreadMode<rocksdb::MultiThreaded>;
#[cfg(feature = "rocksdb-multi-thread")]
type ColumnType<'a> = Arc<rocksdb::BoundColumnFamily<'a>>;

struct Db(DbInner);

impl Drop for Db {
fn drop(&mut self) {
self.0.cancel_all_background_work(true);
}
}

impl std::ops::Deref for Db {
type Target = DbInner;
fn deref(&self) -> &Self::Target {
&self.0
}
}

/// A RocksDB implementation of [Storage].
///
/// Caveats:
/// * Values are limited to 4GB(?) [https://github.com/facebook/rocksdb/wiki/Basic-Operations#reads]
/// TODO(#631): Further improvements to the implementation.
#[derive(Clone)]
pub struct RocksDbStorage {
db: Arc<DbInner>,
db: Arc<Db>,
debug_data: Arc<(PathBuf, StorageConfig)>,
}

Expand Down Expand Up @@ -57,7 +72,7 @@ impl RocksDbStorage {
db_opts.set_db_write_buffer_size(memory_cache_limit);
}

Arc::new(DbInner::open_cf_descriptors(&db_opts, path, cfs)?)
Arc::new(Db(DbInner::open_cf_descriptors(&db_opts, path, cfs)?))
};

Ok(RocksDbStorage {
Expand Down Expand Up @@ -115,11 +130,11 @@ impl std::fmt::Debug for RocksDbStorage {
#[derive(Clone)]
pub struct RocksDbStore {
name: String,
db: Arc<DbInner>,
db: Arc<Db>,
}

impl RocksDbStore {
pub fn new(db: Arc<DbInner>, name: String) -> Result<Self> {
fn new(db: Arc<Db>, name: String) -> Result<Self> {
Ok(RocksDbStore { db, name })
}

Expand Down

0 comments on commit 21bf742

Please sign in to comment.