some scaffolding, refactoring, clearing of todo's

master
Tyler Neely 10 years ago
parent b87ca6bce8
commit 14a68671e7
  1. 84
      src/ffi.rs
  2. 1
      src/lib.rs
  3. 28
      src/rocksdb.rs

@ -33,6 +33,8 @@ pub struct RocksDBBlockBasedTableOptions(pub *const c_void);
pub struct RocksDBCache(pub *const c_void);
#[repr(C)]
pub struct RocksDBFilterPolicy(pub *const c_void);
#[repr(C)]
pub struct RocksDBSnapshot(pub *const c_void);
impl Copy for RocksDBOptions {}
impl Copy for RocksDBInstance {}
@ -45,6 +47,7 @@ impl Copy for RocksDBFilterPolicy {}
impl Copy for RocksDBCompactionStyle {}
impl Copy for RocksDBCompressionType {}
impl Copy for RocksDBUniversalCompactionStyle {}
impl Copy for RocksDBSnapshot {}
pub fn new_bloom_filter(bits: c_int) -> RocksDBFilterPolicy {
unsafe {
@ -168,50 +171,73 @@ extern {
pub fn rocksdb_filterpolicy_create_bloom(
bits_per_key: c_int) -> RocksDBFilterPolicy;
pub fn rocksdb_open(options: RocksDBOptions,
path: *const i8, err: *mut i8) -> RocksDBInstance;
path: *const i8,
err: *mut i8
) -> RocksDBInstance;
pub fn rocksdb_writeoptions_create() -> RocksDBWriteOptions;
pub fn rocksdb_put(db: RocksDBInstance, writeopts: RocksDBWriteOptions,
k: *const u8, kLen: size_t, v: *const u8,
vLen: size_t, err: *mut i8);
pub fn rocksdb_put(db: RocksDBInstance,
writeopts: RocksDBWriteOptions,
k: *const u8, kLen: size_t,
v: *const u8, vLen: size_t,
err: *mut i8);
pub fn rocksdb_readoptions_create() -> RocksDBReadOptions;
pub fn rocksdb_get(db: RocksDBInstance, readopts: RocksDBReadOptions,
pub fn rocksdb_get(db: RocksDBInstance,
readopts: RocksDBReadOptions,
k: *const u8, kLen: size_t,
valLen: *const size_t,
err: *mut i8
) -> *mut c_void;
pub fn rocksdb_delete(db: RocksDBInstance,
writeopts: RocksDBWriteOptions,
k: *const u8, kLen: size_t,
valLen: *const size_t, err: *mut i8) -> *mut c_void;
pub fn rocksdb_delete(db: RocksDBInstance, writeopts: RocksDBWriteOptions,
k: *const u8, kLen: size_t, err: *mut i8) -> *mut c_void;
err: *mut i8
) -> *mut c_void;
pub fn rocksdb_close(db: RocksDBInstance);
pub fn rocksdb_destroy_db(
options: RocksDBOptions, path: *const i8, err: *mut i8);
pub fn rocksdb_repair_db(
options: RocksDBOptions, path: *const i8, err: *mut i8);
pub fn rocksdb_destroy_db(options: RocksDBOptions,
path: *const i8, err: *mut i8);
pub fn rocksdb_repair_db(options: RocksDBOptions,
path: *const i8, err: *mut i8);
// Merge
pub fn rocksdb_merge(db: RocksDBInstance, writeopts: RocksDBWriteOptions,
pub fn rocksdb_merge(db: RocksDBInstance,
writeopts: RocksDBWriteOptions,
k: *const u8, kLen: size_t,
v: *const u8, vLen: size_t, err: *mut i8);
v: *const u8, vLen: size_t,
err: *mut i8);
pub fn rocksdb_mergeoperator_create(
state: *mut c_void,
destroy: extern fn(*mut c_void) -> (),
full_merge: extern fn (
arg: *mut c_void, key: *const c_char, key_len: size_t,
existing_value: *const c_char, existing_value_len: size_t,
operands_list: *const *const c_char, operands_list_len: *const size_t,
num_operands: c_int,
success: *mut u8, new_value_length: *mut size_t
full_merge: extern fn (arg: *mut c_void,
key: *const c_char, key_len: size_t,
existing_value: *const c_char,
existing_value_len: size_t,
operands_list: *const *const c_char,
operands_list_len: *const size_t,
num_operands: c_int, success: *mut u8,
new_value_length: *mut size_t
) -> *const c_char,
partial_merge: extern fn(
arg: *mut c_void, key: *const c_char, key_len: size_t,
operands_list: *const *const c_char, operands_list_len: *const size_t,
num_operands: c_int,
success: *mut u8, new_value_length: *mut size_t
partial_merge: extern fn(arg: *mut c_void,
key: *const c_char, key_len: size_t,
operands_list: *const *const c_char,
operands_list_len: *const size_t,
num_operands: c_int, success: *mut u8,
new_value_length: *mut size_t
) -> *const c_char,
delete_value: Option<extern "C" fn(*mut c_void, value: *const c_char,
value_len: *mut size_t) -> ()>,
delete_value: Option<extern "C" fn(*mut c_void,
value: *const c_char,
value_len: *mut size_t
) -> ()>,
name_fn: extern fn(*mut c_void) -> *const c_char,
) -> RocksDBMergeOperator;
pub fn rocksdb_mergeoperator_destroy(mo: RocksDBMergeOperator);
pub fn rocksdb_options_set_merge_operator(
options: RocksDBOptions,
pub fn rocksdb_options_set_merge_operator(options: RocksDBOptions,
mo: RocksDBMergeOperator);
// Snapshot
pub fn rocksdb_create_snapshot(db: RocksDBInstance) -> RocksDBSnapshot;
pub fn rocksdb_readoptions_set_snapshot(read_opts: RocksDBReadOptions,
snapshot: RocksDBSnapshot);
pub fn rocksdb_release_snapshot(db: RocksDBInstance,
snapshot: RocksDBSnapshot);
}
#[allow(dead_code)]

@ -24,6 +24,7 @@ pub use ffi::{
RocksDBUniversalCompactionStyle,
RocksDBCompactionStyle,
RocksDBCompressionType,
RocksDBSnapshot,
};
pub use rocksdb::{
RocksDB,

@ -23,8 +23,12 @@ use std::ffi::CString;
use std::str::from_utf8;
use std::slice;
use std::str::from_c_str;
use std::io::fs::PathExtensions;
use std::io;
use std::io::fs;
use rocksdb_ffi;
use rocksdb_ffi::RocksDBSnapshot;
use rocksdb_options::RocksDBOptions;
pub struct RocksDB {
@ -43,8 +47,13 @@ impl RocksDB {
let cpath = CString::from_slice(path.as_bytes());
let cpath_ptr = cpath.as_ptr();
//TODO test path here, as if rocksdb fails it will just crash the
// process currently
let ospath = Path::new(path);
if !ospath.exists() {
match fs::mkdir_recursive(&ospath, io::USER_DIR) {
Err(e) => return Err(e.desc),
Ok(_) => (),
}
}
let err = 0 as *mut i8;
let db = rocksdb_ffi::rocksdb_open(opts.inner, cpath_ptr, err);
@ -65,8 +74,13 @@ impl RocksDB {
let cpath = CString::from_slice(path.as_bytes());
let cpath_ptr = cpath.as_ptr();
//TODO test path here, as if rocksdb fails it will just crash the
// process currently
let ospath = Path::new(path);
if !ospath.exists() {
match fs::mkdir_recursive(&ospath, io::USER_DIR) {
Err(e) => return Err(e.desc),
Ok(_) => (),
}
}
let err = 0 as *mut i8;
let result = rocksdb_ffi::rocksdb_destroy_db(
@ -79,6 +93,12 @@ impl RocksDB {
}
}
pub fn create_snapshot(self) -> RocksDBSnapshot {
unsafe {
rocksdb_ffi::rocksdb_create_snapshot(self.inner)
}
}
pub fn put(&self, key: &[u8], value: &[u8]) -> Result<(), &str> {
unsafe {
let writeopts = rocksdb_ffi::rocksdb_writeoptions_create();

Loading…
Cancel
Save