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

feat: Force quit rocksdb worker threads upon dropping. #734

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading