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.
//
use std::ffi::CString;
use std::path::{Path};
use libc::{uint32_t};
use {DB, Error};
use ffi;
use libc::{c_int, uint32_t};
use std::ffi::CString;
use std::path::Path;
pub struct BackupEngine {
inner: *mut ffi::rocksdb_backup_engine_t,
}
@ -29,9 +29,15 @@ pub struct BackupEngineOptions {
inner: *mut ffi::rocksdb_options_t,
}
pub struct RestoreOptions {
inner: *mut ffi::rocksdb_restore_options_t,
}
impl BackupEngine {
/// 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 cpath = match CString::new(path.to_string_lossy().as_bytes()) {
Ok(c) => c,
@ -43,17 +49,13 @@ impl BackupEngine {
};
let be: *mut ffi::rocksdb_backup_engine_t;
unsafe {
be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr()))
}
unsafe { be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr())) }
if be.is_null() {
return Err(Error::new("Could not initialize backup engine.".to_owned()));
}
Ok(BackupEngine {
inner: be,
})
Ok(BackupEngine { inner: be })
}
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> {
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(())
}
}
}
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 {
fn default() -> BackupEngineOptions {
unsafe {
let opts = ffi::rocksdb_options_create();
if opts.is_null() {
panic!("Could not create backup options".to_owned());
panic!("Could not create RocksDB backup options".to_owned());
}
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 {
fn drop(&mut self) {
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.
//
use libc::{c_char, c_int, c_void, size_t};
use std::cmp::Ordering;
use std::ffi::CString;
use std::mem;
use std::slice;
use libc::{c_char, c_int, c_void, size_t};
pub type CompareFn = fn(&[u8], &[u8]) -> Ordering;
pub struct ComparatorCallback {

@ -13,29 +13,25 @@
// 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::ffi::CString;
use std::fmt;
use std::fs;
use std::ops::Deref;
use std::path::{Path};
use std::path::Path;
use std::ptr;
use std::slice;
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 {
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 Sync for DB {}

@ -13,17 +13,21 @@
// 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, Options, WriteOptions};
use {BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Options,
WriteOptions};
use comparator::{self, ComparatorCallback, CompareFn};
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,
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 {
fn drop(&mut self) {

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

@ -53,13 +53,13 @@
//! }
//! ```
use libc::{self, c_char, c_int, c_void, size_t};
use std::ffi::CString;
use std::mem;
use std::ptr;
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 struct MergeOperatorCallback {

Loading…
Cancel
Save