Commit c712a98e authored by zhangjinpeng1987's avatar zhangjinpeng1987

make filter policy live as long as BlockBasedOptions

parent c61e7a89
...@@ -182,7 +182,7 @@ mod tests { ...@@ -182,7 +182,7 @@ mod tests {
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); let bloom_filter = FilterPolicy::new_bloom_filter(10, false);
blockopts.set_filter_policy(&bloom_filter); 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);
......
...@@ -28,6 +28,10 @@ pub struct FilterPolicy { ...@@ -28,6 +28,10 @@ pub struct FilterPolicy {
pub struct BlockBasedOptions { pub struct BlockBasedOptions {
inner: rocksdb_ffi::DBBlockBasedTableOptions, inner: rocksdb_ffi::DBBlockBasedTableOptions,
// FilterPolicy must live as long as BlockBasedTableOptions,
// so we introduce this field
filter_policy: Option<FilterPolicy>,
} }
pub struct Options { pub struct Options {
...@@ -78,7 +82,7 @@ impl Default for BlockBasedOptions { ...@@ -78,7 +82,7 @@ impl Default for BlockBasedOptions {
if opt_ptr.is_null() { if opt_ptr.is_null() {
panic!("Could not create rocksdb block based options".to_string()); panic!("Could not create rocksdb block based options".to_string());
} }
BlockBasedOptions { inner: block_opts } BlockBasedOptions { inner: block_opts, filter_policy: None }
} }
} }
...@@ -115,10 +119,11 @@ impl BlockBasedOptions { ...@@ -115,10 +119,11 @@ impl BlockBasedOptions {
} }
} }
pub fn set_filter_policy(&mut self, filter: &FilterPolicy) { pub fn set_filter_policy(&mut self, filter: FilterPolicy) {
self.filter_policy = Some(filter);
unsafe { unsafe {
rocksdb_ffi::rocksdb_block_based_options_set_filter_policy(self.inner, rocksdb_ffi::rocksdb_block_based_options_set_filter_policy(self.inner,
filter.inner); self.filter_policy.as_ref().unwrap().inner);
} }
} }
......
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