fix: tweak rocksdb options

This commit is contained in:
Ludo Galabru
2023-05-08 12:16:03 -04:00
parent b0378c3099
commit a0a69502d8

View File

@@ -415,15 +415,26 @@ fn get_default_hord_db_file_path_rocks_db(base_dir: &PathBuf) -> PathBuf {
destination_path
}
fn rocks_db_default_options() -> rocksdb::Options {
let mut opts = rocksdb::Options::default();
opts.create_if_missing(true);
// Per rocksdb documentation:
// If cache_index_and_filter_blocks is false (which is default),
// the number of index/filter blocks is controlled by option max_open_files.
// If you are certain that your ulimit will always be bigger than number of files in the database,
// we recommend setting max_open_files to -1, which means infinity.
// This option will preload all filter and index blocks and will not need to maintain LRU of files.
// Setting max_open_files to -1 will get you the best possible performance.
opts.set_max_open_files(-1);
opts
}
pub fn open_readonly_hord_db_conn_rocks_db(
base_dir: &PathBuf,
_ctx: &Context,
) -> Result<DB, String> {
let path = get_default_hord_db_file_path_rocks_db(&base_dir);
let mut opts = rocksdb::Options::default();
opts.create_if_missing(true);
opts.set_max_open_files(5000);
// opts.set_disable_auto_compactions(true);
let opts = rocks_db_default_options();
let db = DB::open_for_read_only(&opts, path, false)
.map_err(|e| format!("unable to open blocks_db: {}", e.to_string()))?;
Ok(db)
@@ -434,10 +445,7 @@ pub fn open_readwrite_hord_db_conn_rocks_db(
_ctx: &Context,
) -> Result<DB, String> {
let path = get_default_hord_db_file_path_rocks_db(&base_dir);
let mut opts = rocksdb::Options::default();
opts.create_if_missing(true);
opts.set_max_open_files(5000);
// opts.set_disable_auto_compactions(true);
let opts = rocks_db_default_options();
let db = DB::open(&opts, path)
.map_err(|e| format!("unable to open blocks_db: {}", e.to_string()))?;
Ok(db)