add filter policy interface && add set_cache_index_and_filter_blocks

master
zhangjinpeng1987 8 years ago committed by Karl Hobley
parent ab9028c778
commit c9e104a4e5
  1. 6
      src/ffi.rs
  2. 20
      src/rocksdb_options.rs

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// //
extern crate libc; 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::ffi::CStr;
use std::str::from_utf8; use std::str::from_utf8;
@ -122,6 +122,8 @@ extern "C" {
pub fn rocksdb_block_based_options_set_block_restart_interval( pub fn rocksdb_block_based_options_set_block_restart_interval(
block_options: DBBlockBasedTableOptions, block_options: DBBlockBasedTableOptions,
block_restart_interval: c_int); 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( pub fn rocksdb_block_based_options_set_filter_policy(
block_options: DBBlockBasedTableOptions, block_options: DBBlockBasedTableOptions,
filter_policy: DBFilterPolicy); filter_policy: DBFilterPolicy);
@ -194,6 +196,8 @@ extern "C" {
pub fn rocksdb_options_set_disable_auto_compactions(options: DBOptions, pub fn rocksdb_options_set_disable_auto_compactions(options: DBOptions,
v: c_int); v: c_int);
pub fn rocksdb_options_set_report_bg_io_stats(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) pub fn rocksdb_filterpolicy_create_bloom(bits_per_key: c_int)
-> DBFilterPolicy; -> DBFilterPolicy;
pub fn rocksdb_open(options: DBOptions, pub fn rocksdb_open(options: DBOptions,

@ -74,6 +74,26 @@ impl BlockBasedOptions {
rocksdb_ffi::rocksdb_block_based_options_set_block_cache(self.inner, cache); 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 { impl Default for BlockBasedOptions {

Loading…
Cancel
Save