Commit cd24a696 authored by zhangjinpeng1987's avatar zhangjinpeng1987 Committed by siddontang

support memtable_insert_with_hint_prefix_extractor (#10)

parent ccaa7407
......@@ -1705,6 +1705,11 @@ void crocksdb_options_set_prefix_extractor(
opt->rep.prefix_extractor.reset(prefix_extractor);
}
void crocksdb_options_set_memtable_insert_with_hint_prefix_extractor(
crocksdb_options_t* opt, crocksdb_slicetransform_t* prefix_extractor) {
opt->rep.memtable_insert_with_hint_prefix_extractor.reset(prefix_extractor);
}
void crocksdb_options_set_disable_data_sync(
crocksdb_options_t* opt, int disable_data_sync) {
opt->rep.disableDataSync = disable_data_sync;
......
......@@ -587,6 +587,9 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_compression_options(
crocksdb_options_t*, int, int, int, int);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_prefix_extractor(
crocksdb_options_t*, crocksdb_slicetransform_t*);
extern C_ROCKSDB_LIBRARY_API void
crocksdb_options_set_memtable_insert_with_hint_prefix_extractor(
crocksdb_options_t*, crocksdb_slicetransform_t*);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_num_levels(
crocksdb_options_t*, int);
extern C_ROCKSDB_LIBRARY_API void
......
......@@ -255,12 +255,15 @@ extern "C" {
percentile95: *mut c_double,
percentile99: *mut c_double,
average: *mut c_double,
standard_deviation: *mut c_double) -> bool;
standard_deviation: *mut c_double)
-> bool;
pub fn crocksdb_options_set_stats_dump_period_sec(options: *mut DBOptions, v: usize);
pub fn crocksdb_options_set_num_levels(options: *mut DBOptions, v: c_int);
pub fn crocksdb_options_set_db_log_dir(options: *mut DBOptions, path: *const c_char);
pub fn crocksdb_options_set_prefix_extractor(options: *mut DBOptions,
prefix_extractor: *mut DBSliceTransform);
pub fn crocksdb_options_set_memtable_insert_with_hint_prefix_extractor(options: *mut DBOptions,
prefix_extractor: *mut DBSliceTransform);
pub fn crocksdb_options_set_memtable_prefix_bloom_size_ratio(options: *mut DBOptions,
ratio: c_double);
pub fn crocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) -> *mut DBFilterPolicy;
......
......@@ -649,6 +649,24 @@ impl Options {
}
}
pub fn set_memtable_insert_hint_prefix_extractor<S>(&mut self,
name: S,
transform: Box<SliceTransform>)
-> Result<(), String>
where S: Into<Vec<u8>>
{
unsafe {
let c_name = match CString::new(name) {
Ok(s) => s,
Err(e) => return Err(format!("failed to convert to cstring: {:?}", e)),
};
let transform = try!(new_slice_transform(c_name, transform));
crocksdb_ffi::crocksdb_options_set_memtable_insert_with_hint_prefix_extractor(
self.inner, transform);
Ok(())
}
}
pub fn set_memtable_prefix_bloom_size_ratio(&mut self, ratio: f64) {
unsafe {
crocksdb_ffi::crocksdb_options_set_memtable_prefix_bloom_size_ratio(self.inner, ratio);
......
......@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::{DB, Options};
use rocksdb::{DB, Options, WriteOptions, SliceTransform};
use rocksdb::crocksdb_ffi::{DBStatisticsHistogramType as HistogramType,
DBStatisticsTickerType as TickerType};
use tempdir::TempDir;
......@@ -72,3 +72,38 @@ fn test_enable_statistics() {
let opts = Options::new();
assert!(opts.get_statistics().is_none());
}
struct FixedPrefixTransform {
pub prefix_len: usize,
}
impl SliceTransform for FixedPrefixTransform {
fn transform<'a>(&mut self, key: &'a [u8]) -> &'a [u8] {
&key[..self.prefix_len]
}
fn in_domain(&mut self, key: &[u8]) -> bool {
key.len() >= self.prefix_len
}
}
#[test]
fn test_memtable_insert_hint_prefix_extractor() {
let path = TempDir::new("_rust_rocksdb_memtable_insert_hint_prefix_extractor").expect("");
let mut opts = Options::new();
opts.create_if_missing(true);
opts.set_memtable_insert_hint_prefix_extractor("FixedPrefixTransform",
Box::new(FixedPrefixTransform {
prefix_len: 2,
}))
.unwrap();
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let wopts = WriteOptions::new();
db.put_opt(b"k0-1", b"a", &wopts).unwrap();
db.put_opt(b"k0-2", b"b", &wopts).unwrap();
db.put_opt(b"k0-3", b"c", &wopts).unwrap();
assert_eq!(db.get(b"k0-1").unwrap().unwrap(), b"a");
assert_eq!(db.get(b"k0-2").unwrap().unwrap(), b"b");
assert_eq!(db.get(b"k0-3").unwrap().unwrap(), b"c");
}
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