Merge pull request #296 from crisp-dev/master

Add `rocksdb_flush` method on DB
master
Oleksandr Anyshchenko 6 years ago committed by GitHub
commit 184440b209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/db.rs
  2. 44
      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, FlushOptions, Options, 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,19 @@ impl DB {
&self.path.as_path() &self.path.as_path()
} }
/// Flush database memtable to SST files on disk (with options).
pub fn flush_opt(&self, flushopts: &FlushOptions) -> Result<(), Error> {
unsafe {
ffi_try!(ffi::rocksdb_flush(self.inner, flushopts.inner,));
}
Ok(())
}
/// Flush database memtable to SST files on disk.
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, FlushOptions, MemtableFactory, Options, PlainTableFactoryOptions, 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,40 @@ impl Default for Options {
} }
} }
impl FlushOptions {
pub fn new() -> FlushOptions {
FlushOptions::default()
}
/// Waits until the flush is done.
///
/// Default: true
///
/// # Example
///
/// ```
/// use rocksdb::FlushOptions;
///
/// let mut options = FlushOptions::default();
/// options.set_wait(false);
/// ```
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