From 6c7f6af7d741fa939ca6422d6436b4ab1c5e800a Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 12 Nov 2019 08:54:10 +0100 Subject: [PATCH] Options: add set_verify_checksums and set_level_compaction_dynamic_level_bytes (#349) --- src/db.rs | 10 ++++++++++ src/db_options.rs | 26 ++++++++++++++++++++++++++ tests/test_rocksdb_options.rs | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/db.rs b/src/db.rs index a6e2d5f..4a296ac 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1930,6 +1930,16 @@ impl ReadOptions { unsafe { ffi::rocksdb_readoptions_set_total_order_seek(self.inner, v as c_uchar) } } + /// If true, all data read from underlying storage will be + /// verified against corresponding checksums. + /// + /// Default: true + pub fn set_verify_checksums(&mut self, v: bool) { + unsafe { + ffi::rocksdb_readoptions_set_verify_checksums(self.inner, v as c_uchar); + } + } + /// If non-zero, an iterator will create a new table reader which /// performs reads of the given size. Using a large size (> 2MB) can /// improve the performance of forward iteration on spinning disks. diff --git a/src/db_options.rs b/src/db_options.rs index b5339c2..8b5c283 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -135,6 +135,21 @@ impl BlockBasedOptions { ffi::rocksdb_block_based_options_set_index_type(self.inner, index); } } + + /// If cache_index_and_filter_blocks is true and the below is true, then + /// filter and index blocks are stored in the cache, but a reference is + /// held in the "table reader" object so the blocks are pinned and only + /// evicted from cache when the table reader is freed. + /// + /// Default: false. + pub fn set_pin_l0_filter_and_index_blocks_in_cache(&mut self, v: bool) { + unsafe { + ffi::rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache( + self.inner, + v as c_uchar, + ); + } + } } impl Default for BlockBasedOptions { @@ -330,6 +345,17 @@ impl Options { } } + /// Allow RocksDB to pick dynamic base of bytes for levels. + /// With this feature turned on, RocksDB will automatically adjust max bytes for each level. + /// The goal of this feature is to have lower bound on size amplification. + /// + /// Default: false. + pub fn set_level_compaction_dynamic_level_bytes(&mut self, v: bool) { + unsafe { + ffi::rocksdb_options_set_level_compaction_dynamic_level_bytes(self.inner, v as c_uchar); + } + } + pub fn set_merge_operator( &mut self, name: &str, diff --git a/tests/test_rocksdb_options.rs b/tests/test_rocksdb_options.rs index bf2853e..edb360c 100644 --- a/tests/test_rocksdb_options.rs +++ b/tests/test_rocksdb_options.rs @@ -15,7 +15,7 @@ extern crate rocksdb; mod util; -use rocksdb::{Options, DB}; +use rocksdb::{BlockBasedOptions, Options, ReadOptions, DB}; use util::DBPath; #[test] @@ -39,3 +39,34 @@ fn test_increase_parallelism() { let _db = DB::open(&opts, &n).unwrap(); } } + +#[test] +fn test_set_level_compaction_dynamic_level_bytes() { + let n = DBPath::new("_rust_rocksdb_test_set_level_compaction_dynamic_level_bytes"); + { + let mut opts = Options::default(); + opts.create_if_missing(true); + opts.set_level_compaction_dynamic_level_bytes(true); + let _db = DB::open(&opts, &n).unwrap(); + } +} + +#[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"); + { + 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); + opts.set_block_based_table_factory(&block_opts); + let _db = DB::open(&opts, &n).unwrap(); + } +} + +#[test] +fn test_read_options() { + let mut read_opts = ReadOptions::default(); + read_opts.set_verify_checksums(false); +}