Skip to content

Commit a0a6950

Browse files
author
Ludo Galabru
committed
fix: tweak rocksdb options
1 parent b0378c3 commit a0a6950

File tree

1 file changed

+16
-8
lines changed
  • components/chainhook-event-observer/src/hord/db

1 file changed

+16
-8
lines changed

components/chainhook-event-observer/src/hord/db/mod.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,26 @@ fn get_default_hord_db_file_path_rocks_db(base_dir: &PathBuf) -> PathBuf {
415415
destination_path
416416
}
417417

418+
fn rocks_db_default_options() -> rocksdb::Options {
419+
let mut opts = rocksdb::Options::default();
420+
opts.create_if_missing(true);
421+
// Per rocksdb documentation:
422+
// If cache_index_and_filter_blocks is false (which is default),
423+
// the number of index/filter blocks is controlled by option max_open_files.
424+
// If you are certain that your ulimit will always be bigger than number of files in the database,
425+
// we recommend setting max_open_files to -1, which means infinity.
426+
// This option will preload all filter and index blocks and will not need to maintain LRU of files.
427+
// Setting max_open_files to -1 will get you the best possible performance.
428+
opts.set_max_open_files(-1);
429+
opts
430+
}
431+
418432
pub fn open_readonly_hord_db_conn_rocks_db(
419433
base_dir: &PathBuf,
420434
_ctx: &Context,
421435
) -> Result<DB, String> {
422436
let path = get_default_hord_db_file_path_rocks_db(&base_dir);
423-
let mut opts = rocksdb::Options::default();
424-
opts.create_if_missing(true);
425-
opts.set_max_open_files(5000);
426-
// opts.set_disable_auto_compactions(true);
437+
let opts = rocks_db_default_options();
427438
let db = DB::open_for_read_only(&opts, path, false)
428439
.map_err(|e| format!("unable to open blocks_db: {}", e.to_string()))?;
429440
Ok(db)
@@ -434,10 +445,7 @@ pub fn open_readwrite_hord_db_conn_rocks_db(
434445
_ctx: &Context,
435446
) -> Result<DB, String> {
436447
let path = get_default_hord_db_file_path_rocks_db(&base_dir);
437-
let mut opts = rocksdb::Options::default();
438-
opts.create_if_missing(true);
439-
opts.set_max_open_files(5000);
440-
// opts.set_disable_auto_compactions(true);
448+
let opts = rocks_db_default_options();
441449
let db = DB::open(&opts, path)
442450
.map_err(|e| format!("unable to open blocks_db: {}", e.to_string()))?;
443451
Ok(db)

0 commit comments

Comments
 (0)