From c9e104a4e5e0c95425c585b5c67bdabd11502851 Mon Sep 17 00:00:00 2001 From: zhangjinpeng1987 Date: Mon, 11 Jul 2016 16:22:21 +0800 Subject: [PATCH] add filter policy interface && add set_cache_index_and_filter_blocks --- src/ffi.rs | 6 +++++- src/rocksdb_options.rs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ffi.rs b/src/ffi.rs index 367a211..3ffceff 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -13,7 +13,7 @@ // limitations under the License. // extern crate libc; -use self::libc::{c_char, c_int, c_void, size_t}; +use self::libc::{c_char, c_uchar, c_int, c_void, size_t}; use std::ffi::CStr; use std::str::from_utf8; @@ -122,6 +122,8 @@ extern "C" { pub fn rocksdb_block_based_options_set_block_restart_interval( block_options: DBBlockBasedTableOptions, block_restart_interval: c_int); + pub fn rocksdb_block_based_options_set_cache_index_and_filter_blocks( + block_options: DBBlockBasedTableOptions, v: c_uchar); pub fn rocksdb_block_based_options_set_filter_policy( block_options: DBBlockBasedTableOptions, filter_policy: DBFilterPolicy); @@ -194,6 +196,8 @@ extern "C" { pub fn rocksdb_options_set_disable_auto_compactions(options: DBOptions, v: c_int); pub fn rocksdb_options_set_report_bg_io_stats(options: DBOptions, v: c_int); + pub fn rocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) + -> DBFilterPolicy; pub fn rocksdb_filterpolicy_create_bloom(bits_per_key: c_int) -> DBFilterPolicy; pub fn rocksdb_open(options: DBOptions, diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index 92dd2a1..29a4931 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -74,6 +74,26 @@ impl BlockBasedOptions { rocksdb_ffi::rocksdb_block_based_options_set_block_cache(self.inner, cache); } } + + pub fn set_bloom_filter(&mut self, bits_per_key: c_int, block_based: bool) { + unsafe { + let bloom = if block_based { + rocksdb_ffi::rocksdb_filterpolicy_create_bloom(bits_per_key) + } else { + rocksdb_ffi::rocksdb_filterpolicy_create_bloom_full(bits_per_key) + }; + + rocksdb_ffi::rocksdb_block_based_options_set_filter_policy(self.inner, + bloom); + } + } + + pub fn set_cache_index_and_filter_blocks(&mut self, v: bool) { + unsafe { + rocksdb_ffi::rocksdb_block_based_options_set_cache_index_and_filter_blocks(self.inner, + v as u8); + } + } } impl Default for BlockBasedOptions {