Add methods for compacting ranges.

master
Thayne McCombs 8 years ago
parent 3310bc669b
commit a467e6bfed
  1. 27
      src/db.rs
  2. 8
      src/ffi_util.rs

@ -16,6 +16,7 @@
use {DB, Error, Options, WriteOptions};
use ffi;
use ffi_util::opt_bytes_to_ptr;
use libc::{self, c_char, c_int, c_uchar, c_void, size_t};
use std::collections::BTreeMap;
@ -674,6 +675,32 @@ impl DB {
-> Result<(), Error> {
self.delete_cf_opt(cf, key, &WriteOptions::default())
}
pub fn compact_range(&self,
start: Option<&[u8]>,
end: Option<&[u8]>) {
unsafe {
ffi::rocksdb_compact_range(self.inner,
opt_bytes_to_ptr(start),
start.map_or(0, |s| s.len()) as size_t,
opt_bytes_to_ptr(end),
end.map_or(0, |e| e.len()) as size_t);
}
}
pub fn compact_range_cf(&self,
cf: *mut ffi::rocksdb_column_family_handle_t,
start: Option<&[u8]>,
end: Option<&[u8]>) {
unsafe {
ffi::rocksdb_compact_range_cf(self.inner,
cf,
opt_bytes_to_ptr(start),
start.map_or(0, |s| s.len()) as size_t,
opt_bytes_to_ptr(end),
end.map_or(0, |e| e.len()) as size_t);
}
}
}
impl WriteBatch {

@ -15,6 +15,7 @@
use libc::{self, c_char, c_void};
use std::ffi::CStr;
use std::ptr;
pub fn error_message(ptr: *const c_char) -> String {
let cstr = unsafe { CStr::from_ptr(ptr as *const _) };
@ -25,6 +26,13 @@ pub fn error_message(ptr: *const c_char) -> String {
s
}
pub fn opt_bytes_to_ptr(opt: Option<&[u8]>) -> *const c_char {
match opt {
Some(v) => v.as_ptr() as *const c_char,
None => ptr::null()
}
}
macro_rules! ffi_try {
( $($function:ident)::*( $( $arg:expr ),* ) ) => ({
let mut err: *mut ::libc::c_char = ::std::ptr::null_mut();

Loading…
Cancel
Save