diff --git a/CHANGELOG.md b/CHANGELOG.md index b386b8a..0ece974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Updated lz4 to v1.9.2 (ordian) +* BlockBasedOptions: expose `format_version`, `[index_]block_restart_interval` (ordian) ## 0.13.0 (2019-11-12) diff --git a/src/db_options.rs b/src/db_options.rs index 8b5c283..7e90e4a 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -150,6 +150,40 @@ impl BlockBasedOptions { ); } } + + /// Format version, reserved for backward compatibility. + /// See https://github.com/facebook/rocksdb/blob/f059c7d9b96300091e07429a60f4ad55dac84859/include/rocksdb/table.h#L249-L274. + /// + /// Default: 2. + pub fn set_format_version(&mut self, version: i32) { + unsafe { + ffi::rocksdb_block_based_options_set_format_version(self.inner, version); + } + } + + /// Number of keys between restart points for delta encoding of keys. + /// This parameter can be changed dynamically. Most clients should + /// leave this parameter alone. The minimum value allowed is 1. Any smaller + /// value will be silently overwritten with 1. + /// + /// Default: 16. + pub fn set_block_restart_interval(&mut self, interval: i32) { + unsafe { + ffi::rocksdb_block_based_options_set_block_restart_interval(self.inner, interval); + } + } + + /// Same as block_restart_interval but used for the index block. + /// If you don't plan to run RocksDB before version 5.16 and you are + /// using `index_block_restart_interval` > 1, you should + /// probably set the `format_version` to >= 4 as it would reduce the index size. + /// + /// Default: 1. + pub fn set_index_block_restart_interval(&mut self, interval: i32) { + unsafe { + ffi::rocksdb_block_based_options_set_index_block_restart_interval(self.inner, interval); + } + } } impl Default for BlockBasedOptions { diff --git a/tests/test_rocksdb_options.rs b/tests/test_rocksdb_options.rs index edb360c..ad715ca 100644 --- a/tests/test_rocksdb_options.rs +++ b/tests/test_rocksdb_options.rs @@ -16,6 +16,7 @@ extern crate rocksdb; mod util; use rocksdb::{BlockBasedOptions, Options, ReadOptions, DB}; +use std::{fs, io::Read as _}; use util::DBPath; #[test] @@ -52,16 +53,33 @@ fn test_set_level_compaction_dynamic_level_bytes() { } #[test] -fn test_set_pin_l0_filter_and_index_blocks_in_cache() { - let n = DBPath::new("_rust_rocksdb_test_set_pin_l0_filter_and_index_blocks_in_cache"); +fn test_block_based_options() { + let path = "_rust_rocksdb_test_block_based_options"; + let n = DBPath::new(path); { let mut opts = Options::default(); opts.create_if_missing(true); + let mut block_opts = BlockBasedOptions::default(); block_opts.set_cache_index_and_filter_blocks(true); block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); + block_opts.set_format_version(4); + block_opts.set_index_block_restart_interval(16); + opts.set_block_based_table_factory(&block_opts); let _db = DB::open(&opts, &n).unwrap(); + + // read the setting from the LOG file + let mut rocksdb_log = fs::File::open(format!("{}/LOG", n.as_ref().to_str().unwrap())) + .expect("rocksdb creates a LOG file"); + let mut settings = String::new(); + rocksdb_log.read_to_string(&mut settings).unwrap(); + + // check the settings are set in the LOG file + assert!(settings.contains("cache_index_and_filter_blocks: 1")); + assert!(settings.contains("pin_l0_filter_and_index_blocks_in_cache: 1")); + assert!(settings.contains("format_version: 4")); + assert!(settings.contains("index_block_restart_interval: 16")); } }