@@ -415,15 +415,26 @@ fn get_default_hord_db_file_path_rocks_db(base_dir: &PathBuf) -> PathBuf {
415
415
destination_path
416
416
}
417
417
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
+
418
432
pub fn open_readonly_hord_db_conn_rocks_db (
419
433
base_dir : & PathBuf ,
420
434
_ctx : & Context ,
421
435
) -> Result < DB , String > {
422
436
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 ( ) ;
427
438
let db = DB :: open_for_read_only ( & opts, path, false )
428
439
. map_err ( |e| format ! ( "unable to open blocks_db: {}" , e. to_string( ) ) ) ?;
429
440
Ok ( db)
@@ -434,10 +445,7 @@ pub fn open_readwrite_hord_db_conn_rocks_db(
434
445
_ctx : & Context ,
435
446
) -> Result < DB , String > {
436
447
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 ( ) ;
441
449
let db = DB :: open ( & opts, path)
442
450
. map_err ( |e| format ! ( "unable to open blocks_db: {}" , e. to_string( ) ) ) ?;
443
451
Ok ( db)
0 commit comments