Skip to content
Snippets Groups Projects
Commit d4cfee4e authored by Jason Volk's avatar Jason Volk Committed by 🥺
Browse files

add rocksdb env to options. keep options in engine state.


Signed-off-by: default avatarJason Volk <jason@zemos.net>
parent af605a03
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,8 @@ pub(crate) struct Engine { ...@@ -17,6 +17,8 @@ pub(crate) struct Engine {
rocks: rust_rocksdb::DBWithThreadMode<rust_rocksdb::MultiThreaded>, rocks: rust_rocksdb::DBWithThreadMode<rust_rocksdb::MultiThreaded>,
cache: rust_rocksdb::Cache, cache: rust_rocksdb::Cache,
old_cfs: Vec<String>, old_cfs: Vec<String>,
opts: rust_rocksdb::Options,
env: rust_rocksdb::Env,
config: Config, config: Config,
} }
...@@ -27,7 +29,7 @@ struct RocksDbEngineTree<'a> { ...@@ -27,7 +29,7 @@ struct RocksDbEngineTree<'a> {
write_lock: RwLock<()>, write_lock: RwLock<()>,
} }
fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rocksdb::Options { fn db_options(config: &Config, env: &rust_rocksdb::Env, rocksdb_cache: &rust_rocksdb::Cache) -> rust_rocksdb::Options {
// block-based options: https://docs.rs/rocksdb/latest/rocksdb/struct.BlockBasedOptions.html# // block-based options: https://docs.rs/rocksdb/latest/rocksdb/struct.BlockBasedOptions.html#
let mut block_based_options = rust_rocksdb::BlockBasedOptions::default(); let mut block_based_options = rust_rocksdb::BlockBasedOptions::default();
...@@ -44,6 +46,7 @@ fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rock ...@@ -44,6 +46,7 @@ fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rock
// database options: https://docs.rs/rocksdb/latest/rocksdb/struct.Options.html# // database options: https://docs.rs/rocksdb/latest/rocksdb/struct.Options.html#
let mut db_opts = rust_rocksdb::Options::default(); let mut db_opts = rust_rocksdb::Options::default();
db_opts.set_env(env);
let rocksdb_log_level = match config.rocksdb_log_level.as_ref() { let rocksdb_log_level = match config.rocksdb_log_level.as_ref() {
"debug" => Debug, "debug" => Debug,
...@@ -125,8 +128,8 @@ impl KeyValueDatabaseEngine for Arc<Engine> { ...@@ -125,8 +128,8 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
fn open(config: &Config) -> Result<Self> { fn open(config: &Config) -> Result<Self> {
let cache_capacity_bytes = (config.db_cache_capacity_mb * 1024.0 * 1024.0) as usize; let cache_capacity_bytes = (config.db_cache_capacity_mb * 1024.0 * 1024.0) as usize;
let rocksdb_cache = rust_rocksdb::Cache::new_lru_cache(cache_capacity_bytes); let rocksdb_cache = rust_rocksdb::Cache::new_lru_cache(cache_capacity_bytes);
let db_env = rust_rocksdb::Env::new()?;
let db_opts = db_options(&rocksdb_cache, config); let db_opts = db_options(config, &db_env, &rocksdb_cache);
debug!("Listing column families in database"); debug!("Listing column families in database");
let cfs = let cfs =
...@@ -138,13 +141,15 @@ fn open(config: &Config) -> Result<Self> { ...@@ -138,13 +141,15 @@ fn open(config: &Config) -> Result<Self> {
let db = rust_rocksdb::DBWithThreadMode::<rust_rocksdb::MultiThreaded>::open_cf_descriptors( let db = rust_rocksdb::DBWithThreadMode::<rust_rocksdb::MultiThreaded>::open_cf_descriptors(
&db_opts, &db_opts,
&config.database_path, &config.database_path,
cfs.iter().map(|name| rust_rocksdb::ColumnFamilyDescriptor::new(name, db_options(&rocksdb_cache, config))), cfs.iter().map(|name| rust_rocksdb::ColumnFamilyDescriptor::new(name, db_opts.clone())),
)?; )?;
Ok(Arc::new(Engine { Ok(Arc::new(Engine {
rocks: db, rocks: db,
cache: rocksdb_cache, cache: rocksdb_cache,
old_cfs: cfs, old_cfs: cfs,
opts: db_opts,
env: db_env,
config: config.clone(), config: config.clone(),
})) }))
} }
...@@ -153,7 +158,7 @@ fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>> { ...@@ -153,7 +158,7 @@ fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>> {
if !self.old_cfs.contains(&name.to_owned()) { if !self.old_cfs.contains(&name.to_owned()) {
// Create if it didn't exist // Create if it didn't exist
debug!("Creating new column family in database: {}", name); debug!("Creating new column family in database: {}", name);
let _ = self.rocks.create_cf(name, &db_options(&self.cache, &self.config)); let _ = self.rocks.create_cf(name, &self.opts);
} }
Ok(Arc::new(RocksDbEngineTree { Ok(Arc::new(RocksDbEngineTree {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment