Changed rocksdb module name prefix to db.

Also rustfmt on source.
master
Alexander Regueiro 8 years ago
parent d28eba2ff5
commit 12d79986b2
  1. 61
      src/backup.rs
  2. 4
      src/comparator.rs
  3. 16
      src/db.rs
  4. 16
      src/db_options.rs
  5. 14
      src/lib.rs
  6. 4
      src/merge_operator.rs

@ -13,14 +13,14 @@
// limitations under the License. // limitations under the License.
// //
use std::ffi::CString;
use std::path::{Path};
use libc::{uint32_t};
use {DB, Error}; use {DB, Error};
use ffi; use ffi;
use libc::{c_int, uint32_t};
use std::ffi::CString;
use std::path::Path;
pub struct BackupEngine { pub struct BackupEngine {
inner: *mut ffi::rocksdb_backup_engine_t, inner: *mut ffi::rocksdb_backup_engine_t,
} }
@ -29,9 +29,15 @@ pub struct BackupEngineOptions {
inner: *mut ffi::rocksdb_options_t, inner: *mut ffi::rocksdb_options_t,
} }
pub struct RestoreOptions {
inner: *mut ffi::rocksdb_restore_options_t,
}
impl BackupEngine { impl BackupEngine {
/// Open a backup engine with the specified options. /// Open a backup engine with the specified options.
pub fn open<P: AsRef<Path>>(opts: &BackupEngineOptions, path: P) -> Result<BackupEngine, Error> { pub fn open<P: AsRef<Path>>(opts: &BackupEngineOptions,
path: P)
-> Result<BackupEngine, Error> {
let path = path.as_ref(); let path = path.as_ref();
let cpath = match CString::new(path.to_string_lossy().as_bytes()) { let cpath = match CString::new(path.to_string_lossy().as_bytes()) {
Ok(c) => c, Ok(c) => c,
@ -43,17 +49,13 @@ impl BackupEngine {
}; };
let be: *mut ffi::rocksdb_backup_engine_t; let be: *mut ffi::rocksdb_backup_engine_t;
unsafe { unsafe { be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr())) }
be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr()))
}
if be.is_null() { if be.is_null() {
return Err(Error::new("Could not initialize backup engine.".to_owned())); return Err(Error::new("Could not initialize backup engine.".to_owned()));
} }
Ok(BackupEngine { Ok(BackupEngine { inner: be })
inner: be,
})
} }
fn create_new_backup(&mut self, db: &DB) -> Result<(), Error> { fn create_new_backup(&mut self, db: &DB) -> Result<(), Error> {
@ -65,24 +67,49 @@ impl BackupEngine {
fn purge_old_backups(&mut self, num_backups_to_keep: usize) -> Result<(), Error> { fn purge_old_backups(&mut self, num_backups_to_keep: usize) -> Result<(), Error> {
unsafe { unsafe {
ffi_try!(ffi::rocksdb_backup_engine_purge_old_backups(self.inner, num_backups_to_keep as uint32_t)); ffi_try!(ffi::rocksdb_backup_engine_purge_old_backups(self.inner,
num_backups_to_keep as uint32_t));
Ok(()) Ok(())
} }
} }
} }
impl BackupEngineOptions {
//
}
impl RestoreOptions {
pub fn set_keep_log_files(&mut self, keep_log_files: bool) {
unsafe {
ffi::rocksdb_restore_options_set_keep_log_files(self.inner, keep_log_files as c_int);
}
}
}
impl Default for BackupEngineOptions { impl Default for BackupEngineOptions {
fn default() -> BackupEngineOptions { fn default() -> BackupEngineOptions {
unsafe { unsafe {
let opts = ffi::rocksdb_options_create(); let opts = ffi::rocksdb_options_create();
if opts.is_null() { if opts.is_null() {
panic!("Could not create backup options".to_owned()); panic!("Could not create RocksDB backup options".to_owned());
} }
BackupEngineOptions { inner: opts } BackupEngineOptions { inner: opts }
} }
} }
} }
impl Default for RestoreOptions {
fn default() -> RestoreOptions {
unsafe {
let opts = ffi::rocksdb_restore_options_create();
if opts.is_null() {
panic!("Could not create RocksDB restore options".to_owned());
}
RestoreOptions { inner: opts }
}
}
}
impl Drop for BackupEngine { impl Drop for BackupEngine {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
@ -98,3 +125,11 @@ impl Drop for BackupEngineOptions {
} }
} }
} }
impl Drop for RestoreOptions {
fn drop(&mut self) {
unsafe {
ffi::rocksdb_restore_options_destroy(self.inner);
}
}
}

@ -13,13 +13,13 @@
// limitations under the License. // limitations under the License.
// //
use libc::{c_char, c_int, c_void, size_t};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::ffi::CString; use std::ffi::CString;
use std::mem; use std::mem;
use std::slice; use std::slice;
use libc::{c_char, c_int, c_void, size_t};
pub type CompareFn = fn(&[u8], &[u8]) -> Ordering; pub type CompareFn = fn(&[u8], &[u8]) -> Ordering;
pub struct ComparatorCallback { pub struct ComparatorCallback {

@ -13,29 +13,25 @@
// limitations under the License. // limitations under the License.
// //
use {DB, Error, Options, WriteOptions};
use ffi;
use libc::{self, c_char, c_int, c_uchar, c_void, size_t};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::ffi::CString; use std::ffi::CString;
use std::fmt; use std::fmt;
use std::fs; use std::fs;
use std::ops::Deref; use std::ops::Deref;
use std::path::{Path}; use std::path::Path;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
use std::str; use std::str;
use libc::{self, c_char, c_int, c_uchar, c_void, size_t};
use {DB, Error, Options, WriteOptions};
use ffi;
pub fn new_bloom_filter(bits: c_int) -> *mut ffi::rocksdb_filterpolicy_t { pub fn new_bloom_filter(bits: c_int) -> *mut ffi::rocksdb_filterpolicy_t {
unsafe { ffi::rocksdb_filterpolicy_create_bloom(bits) } unsafe { ffi::rocksdb_filterpolicy_create_bloom(bits) }
} }
pub fn new_cache(capacity: size_t) -> *mut ffi::rocksdb_cache_t {
unsafe { ffi::rocksdb_cache_create_lru(capacity) }
}
unsafe impl Send for DB {} unsafe impl Send for DB {}
unsafe impl Sync for DB {} unsafe impl Sync for DB {}

@ -13,17 +13,21 @@
// limitations under the License. // limitations under the License.
// //
use std::ffi::{CStr, CString};
use std::mem;
use libc::{self, c_int, c_uchar, c_uint, c_void, size_t, uint64_t}; use {BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Options,
WriteOptions};
use {BlockBasedOptions, Options, WriteOptions};
use comparator::{self, ComparatorCallback, CompareFn}; use comparator::{self, ComparatorCallback, CompareFn};
use ffi; use ffi;
use libc::{self, c_int, c_uchar, c_uint, c_void, size_t, uint64_t};
use merge_operator::{self, MergeFn, MergeOperatorCallback, full_merge_callback, use merge_operator::{self, MergeFn, MergeOperatorCallback, full_merge_callback,
partial_merge_callback}; partial_merge_callback};
use rocksdb::{DBCompactionStyle, DBCompressionType, DBRecoveryMode, new_cache}; use std::ffi::{CStr, CString};
use std::mem;
pub fn new_cache(capacity: size_t) -> *mut ffi::rocksdb_cache_t {
unsafe { ffi::rocksdb_cache_create_lru(capacity) }
}
impl Drop for Options { impl Drop for Options {
fn drop(&mut self) { fn drop(&mut self) {

@ -40,17 +40,17 @@ mod ffi_util;
pub mod backup; pub mod backup;
mod comparator; mod comparator;
pub mod merge_operator; pub mod merge_operator;
mod rocksdb; mod db;
mod rocksdb_options; mod db_options;
pub use db::{DBCompactionStyle, DBCompressionType, DBIterator, DBRecoveryMode, DBVector,
Direction, IteratorMode, Snapshot, WriteBatch, new_bloom_filter};
pub use merge_operator::MergeOperands;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::error; use std::error;
use std::fmt; use std::fmt;
use std::path::{PathBuf}; use std::path::PathBuf;
pub use merge_operator::MergeOperands;
pub use rocksdb::{DBCompactionStyle, DBCompressionType, DBIterator, DBRecoveryMode, DBVector,
Direction, IteratorMode, Snapshot, WriteBatch, new_bloom_filter};
/// A RocksDB database. /// A RocksDB database.
pub struct DB { pub struct DB {

@ -53,13 +53,13 @@
//! } //! }
//! ``` //! ```
use libc::{self, c_char, c_int, c_void, size_t};
use std::ffi::CString; use std::ffi::CString;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
use libc::{self, c_char, c_int, c_void, size_t};
pub type MergeFn = fn(&[u8], Option<&[u8]>, &mut MergeOperands) -> Vec<u8>; pub type MergeFn = fn(&[u8], Option<&[u8]>, &mut MergeOperands) -> Vec<u8>;
pub struct MergeOperatorCallback { pub struct MergeOperatorCallback {

Loading…
Cancel
Save