Add ‘flush’

Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
master
Valerian Saliou 6 years ago
parent ea770309c8
commit a4b60075b9
No known key found for this signature in database
GPG Key ID: C648A8138046772A
  1. 13
      src/db.rs
  2. 32
      src/db_options.rs
  3. 24
      src/lib.rs

@ -15,7 +15,7 @@
use ffi; use ffi;
use ffi_util::opt_bytes_to_ptr; use ffi_util::opt_bytes_to_ptr;
use {ColumnFamily, ColumnFamilyDescriptor, Error, Options, WriteOptions, DB}; use {ColumnFamily, ColumnFamilyDescriptor, Error, Options, FlushOptions, WriteOptions, DB};
use libc::{self, c_char, c_int, c_uchar, c_void, size_t}; use libc::{self, c_char, c_int, c_uchar, c_void, size_t};
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -836,6 +836,17 @@ impl DB {
&self.path.as_path() &self.path.as_path()
} }
pub fn flush_opt(&self, flushopts: &FlushOptions) -> Result<(), Error> {
unsafe {
ffi_try!(ffi::rocksdb_flush(self.inner, flushopts.inner,));
}
Ok(())
}
pub fn flush(&self) -> Result<(), Error> {
self.flush_opt(&FlushOptions::default())
}
pub fn write_opt(&self, batch: WriteBatch, writeopts: &WriteOptions) -> Result<(), Error> { pub fn write_opt(&self, batch: WriteBatch, writeopts: &WriteOptions) -> Result<(), Error> {
unsafe { unsafe {
ffi_try!(ffi::rocksdb_write(self.inner, writeopts.inner, batch.inner,)); ffi_try!(ffi::rocksdb_write(self.inner, writeopts.inner, batch.inner,));

@ -27,7 +27,7 @@ use merge_operator::{
use slice_transform::SliceTransform; use slice_transform::SliceTransform;
use { use {
BlockBasedIndexType, BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, BlockBasedIndexType, BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode,
MemtableFactory, Options, PlainTableFactoryOptions, WriteOptions, MemtableFactory, Options, PlainTableFactoryOptions, FlushOptions, WriteOptions,
}; };
pub fn new_cache(capacity: size_t) -> *mut ffi::rocksdb_cache_t { pub fn new_cache(capacity: size_t) -> *mut ffi::rocksdb_cache_t {
@ -52,6 +52,14 @@ impl Drop for BlockBasedOptions {
} }
} }
impl Drop for FlushOptions {
fn drop(&mut self) {
unsafe {
ffi::rocksdb_flushoptions_destroy(self.inner);
}
}
}
impl Drop for WriteOptions { impl Drop for WriteOptions {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
@ -1208,6 +1216,28 @@ impl Default for Options {
} }
} }
impl FlushOptions {
pub fn new() -> FlushOptions {
FlushOptions::default()
}
pub fn set_wait(&mut self, wait: bool) {
unsafe {
ffi::rocksdb_flushoptions_set_wait(self.inner, wait as c_uchar);
}
}
}
impl Default for FlushOptions {
fn default() -> FlushOptions {
let flush_opts = unsafe { ffi::rocksdb_flushoptions_create() };
if flush_opts.is_null() {
panic!("Could not create RocksDB flush options");
}
FlushOptions { inner: flush_opts }
}
}
impl WriteOptions { impl WriteOptions {
pub fn new() -> WriteOptions { pub fn new() -> WriteOptions {
WriteOptions::default() WriteOptions::default()

@ -228,6 +228,30 @@ pub struct Options {
inner: *mut ffi::rocksdb_options_t, inner: *mut ffi::rocksdb_options_t,
} }
/// Optionally wait for the memtable flush to be performed.
///
/// # Examples
///
/// Manually flushing the memtable:
///
/// ```
/// use rocksdb::{DB, Options, FlushOptions};
///
/// let path = "_path_for_rocksdb_storageY";
/// {
/// let db = DB::open_default(path).unwrap();
///
/// let mut flush_options = FlushOptions::default();
/// flush_options.set_wait(true);
///
/// db.flush_opt(&flush_options);
/// }
/// let _ = DB::destroy(&Options::default(), path);
/// ```
pub struct FlushOptions {
inner: *mut ffi::rocksdb_flushoptions_t,
}
/// Optionally disable WAL or sync for this write. /// Optionally disable WAL or sync for this write.
/// ///
/// # Examples /// # Examples

Loading…
Cancel
Save