Commit ffdce61a authored by goroutine's avatar goroutine Committed by GitHub

Merge pull request #25 from zhangjinpeng1987/master

add filter policy interface && add set_cache_index_and_filter_blocks
parents fd83e59b 9b78173e
......@@ -17,7 +17,7 @@ extern crate libc;
#[cfg(test)]
extern crate tempdir;
use libc::{c_char, c_int, c_void, size_t, uint64_t};
use libc::{c_char, c_uchar, c_int, c_void, size_t, uint64_t};
use std::ffi::CStr;
use std::str::from_utf8;
......@@ -124,6 +124,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);
......@@ -198,6 +200,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,
......
......@@ -180,6 +180,8 @@ mod tests {
opts.set_report_bg_io_stats(true);
opts.compression_per_level(&per_level_compression);
blockopts.set_block_size(524288);
blockopts.set_cache_index_and_filter_blocks(true);
blockopts.set_bloom_filter(10, false);
opts.set_block_based_table_factory(blockopts);
opts.set_disable_auto_compactions(true);
......
......@@ -90,6 +90,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);
}
}
}
// TODO figure out how to create these in a Rusty way
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment