Move database config to separate section

This renames:

database_backend -> database.backend
database_path -> database.path
db_cache_capacity_mb -> database.cache_capacity_mb
rocksdb_max_open_files -> database.rocksdb_max_open_files

Charles updated the NixOS module.

Co-authored-by: Charles Hall <charles@computer.surgery>
This commit is contained in:
Lambda 2024-06-16 13:24:28 +00:00 committed by Charles Hall
parent 79d5d306cc
commit d26b87a2f2
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
6 changed files with 39 additions and 28 deletions

View file

@ -78,32 +78,36 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
clippy::cast_possible_truncation
)]
let cache_capacity_bytes =
(config.db_cache_capacity_mb * 1024.0 * 1024.0) as usize;
(config.database.cache_capacity_mb * 1024.0 * 1024.0) as usize;
let rocksdb_cache = Cache::new_lru_cache(cache_capacity_bytes);
let db_opts = db_options(config.rocksdb_max_open_files, &rocksdb_cache);
let db_opts =
db_options(config.database.rocksdb_max_open_files, &rocksdb_cache);
let cfs = DBWithThreadMode::<MultiThreaded>::list_cf(
&db_opts,
&config.database_path,
&config.database.path,
)
.map(|x| x.into_iter().collect::<HashSet<_>>())
.unwrap_or_default();
let db = DBWithThreadMode::<MultiThreaded>::open_cf_descriptors(
&db_opts,
&config.database_path,
&config.database.path,
cfs.iter().map(|name| {
ColumnFamilyDescriptor::new(
name,
db_options(config.rocksdb_max_open_files, &rocksdb_cache),
db_options(
config.database.rocksdb_max_open_files,
&rocksdb_cache,
),
)
}),
)?;
Ok(Arc::new(Engine {
rocks: db,
max_open_files: config.rocksdb_max_open_files,
max_open_files: config.database.rocksdb_max_open_files,
cache: rocksdb_cache,
old_cfs: cfs,
new_cfs: Mutex::default(),

View file

@ -110,7 +110,7 @@ impl Engine {
impl KeyValueDatabaseEngine for Arc<Engine> {
fn open(config: &Config) -> Result<Self> {
let path = Path::new(&config.database_path).join(format!(
let path = Path::new(&config.database.path).join(format!(
"{}.db",
if config.conduit_compat {
"conduit"
@ -130,9 +130,9 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
clippy::cast_precision_loss,
clippy::cast_sign_loss
)]
let cache_size_per_thread = ((config.db_cache_capacity_mb * 1024.0)
/ ((num_cpus::get() as f64 * 2.0) + 1.0))
as u32;
let cache_size_per_thread =
((config.database.cache_capacity_mb * 1024.0)
/ ((num_cpus::get() as f64 * 2.0) + 1.0)) as u32;
let writer =
Mutex::new(Engine::prepare_conn(&path, cache_size_per_thread)?);