Commit 9b78173e authored by zhangjinpeng1987's avatar zhangjinpeng1987

address comments

parent e951a51d
...@@ -28,5 +28,5 @@ pub use librocksdb_sys::{DBCompactionStyle, DBComparator, DBCompressionType, ...@@ -28,5 +28,5 @@ pub use librocksdb_sys::{DBCompactionStyle, DBComparator, DBCompressionType,
new_bloom_filter, self as rocksdb_ffi}; new_bloom_filter, self as rocksdb_ffi};
pub use rocksdb::{DB, DBIterator, DBVector, Kv, ReadOptions, SeekKey, pub use rocksdb::{DB, DBIterator, DBVector, Kv, ReadOptions, SeekKey,
Writable, WriteBatch}; Writable, WriteBatch};
pub use rocksdb_options::{BlockBasedOptions, Options, WriteOptions, FilterPolicy}; pub use rocksdb_options::{BlockBasedOptions, Options, WriteOptions};
pub use merge_operator::MergeOperands; pub use merge_operator::MergeOperands;
...@@ -143,7 +143,7 @@ fn main() { ...@@ -143,7 +143,7 @@ fn main() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use rocksdb::{BlockBasedOptions, DB, DBCompressionType, Options, FilterPolicy}; use rocksdb::{BlockBasedOptions, DB, DBCompressionType, Options};
use rocksdb::DBCompactionStyle::DBUniversal; use rocksdb::DBCompactionStyle::DBUniversal;
#[allow(dead_code)] #[allow(dead_code)]
...@@ -181,8 +181,7 @@ mod tests { ...@@ -181,8 +181,7 @@ mod tests {
opts.compression_per_level(&per_level_compression); opts.compression_per_level(&per_level_compression);
blockopts.set_block_size(524288); blockopts.set_block_size(524288);
blockopts.set_cache_index_and_filter_blocks(true); blockopts.set_cache_index_and_filter_blocks(true);
let bloom_filter = FilterPolicy::new_bloom_filter(10, false); blockopts.set_bloom_filter(10, false);
blockopts.set_filter_policy(bloom_filter);
opts.set_block_based_table_factory(blockopts); opts.set_block_based_table_factory(blockopts);
opts.set_disable_auto_compactions(true); opts.set_disable_auto_compactions(true);
......
...@@ -22,10 +22,6 @@ use merge_operator::{self, MergeOperatorCallback, full_merge_callback, ...@@ -22,10 +22,6 @@ use merge_operator::{self, MergeOperatorCallback, full_merge_callback,
use comparator::{self, ComparatorCallback, compare_callback}; use comparator::{self, ComparatorCallback, compare_callback};
use merge_operator::MergeFn; use merge_operator::MergeFn;
pub struct FilterPolicy {
inner: rocksdb_ffi::DBFilterPolicy,
}
pub struct BlockBasedOptions { pub struct BlockBasedOptions {
inner: rocksdb_ffi::DBBlockBasedTableOptions, inner: rocksdb_ffi::DBBlockBasedTableOptions,
} }
...@@ -74,18 +70,6 @@ impl Default for BlockBasedOptions { ...@@ -74,18 +70,6 @@ impl Default for BlockBasedOptions {
} }
} }
impl FilterPolicy {
pub fn new_bloom_filter(bits_per_key: c_int, block_based: bool) -> FilterPolicy {
let filter = if block_based {
unsafe { rocksdb_ffi::rocksdb_filterpolicy_create_bloom(bits_per_key) }
} else {
unsafe { rocksdb_ffi::rocksdb_filterpolicy_create_bloom_full(bits_per_key) }
};
FilterPolicy { inner: filter }
}
}
impl BlockBasedOptions { impl BlockBasedOptions {
pub fn new() -> BlockBasedOptions { pub fn new() -> BlockBasedOptions {
BlockBasedOptions::default() BlockBasedOptions::default()
...@@ -107,10 +91,16 @@ impl BlockBasedOptions { ...@@ -107,10 +91,16 @@ impl BlockBasedOptions {
} }
} }
pub fn set_filter_policy(&mut self, filter: FilterPolicy) { pub fn set_bloom_filter(&mut self, bits_per_key: c_int, block_based: bool) {
unsafe { 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, rocksdb_ffi::rocksdb_block_based_options_set_filter_policy(self.inner,
filter.inner); bloom);
} }
} }
......
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