Merge remote-tracking branch 'origin' into tyler_cleanup

master
Tyler Neely 9 years ago
commit 235a738632
No known key found for this signature in database
GPG Key ID: 23E6C4FBEAE5E4E3
  1. 97
      src/ffi.rs
  2. 12
      src/rocksdb.rs
  3. 13
      src/rocksdb_options.rs

@ -17,45 +17,50 @@ use self::libc::{c_char, c_int, c_void, size_t};
use std::ffi::CStr;
use std::str::from_utf8;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBOptions(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBInstance(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBWriteOptions(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBReadOptions(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBMergeOperator(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBBlockBasedTableOptions(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBCache(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBFilterPolicy(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBSnapshot(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBIterator(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBCFHandle(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBWriteBatch(pub *const c_void);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct DBComparator(pub *const c_void);
pub enum DBOptionsOpaque {}
pub type DBOptions = *const DBOptionsOpaque;
pub enum DBInstanceOpaque {}
pub type DBInstance = *const DBInstanceOpaque;
pub enum DBWriteOptionsOpaque {}
pub type DBWriteOptions = *const DBWriteOptionsOpaque;
pub enum DBReadOptionsOpaque {}
pub type DBReadOptions = *const DBReadOptionsOpaque;
pub enum DBMergeOperatorOpaque {}
pub type DBMergeOperator = *const DBMergeOperatorOpaque;
pub enum DBBlockBasedTableOptionsOpaque {}
pub type DBBlockBasedTableOptions = *const DBBlockBasedTableOptionsOpaque;
pub enum DBCacheOpaque {}
pub type DBCache = *const DBCacheOpaque;
pub enum DBFilterPolicyOpaque {}
pub type DBFilterPolicy = *const DBFilterPolicyOpaque;
pub enum DBSnapshotOpaque {}
pub type DBSnapshot = *const DBSnapshotOpaque;
pub enum DBIteratorOpaque {}
pub type DBIterator = *const DBIteratorOpaque;
pub enum DBCFHandleOpaque {}
pub type DBCFHandle = *const DBCFHandleOpaque;
pub enum DBWriteBatchOpaque {}
pub type DBWriteBatch = *const DBWriteBatchOpaque;
pub enum DBComparatorOpaque {}
pub type DBComparator = *const DBComparatorOpaque;
pub enum DBSliceTransformOpaque {}
pub type DBSliceTransform = *const DBSliceTransformOpaque;
pub const BLOCK_BASED_INDEX_TYPE_BINARY_SEARCH: c_int = 0;
pub const BLOCK_BASED_INDEX_TYPE_HASH_SEARCH: c_int = 1;
pub fn new_bloom_filter(bits: c_int) -> DBFilterPolicy {
unsafe { rocksdb_filterpolicy_create_bloom(bits) }
@ -157,17 +162,17 @@ extern "C" {
pub fn rocksdb_options_set_level0_stop_writes_trigger(options: DBOptions,
no: c_int);
pub fn rocksdb_options_set_write_buffer_size(options: DBOptions,
bytes: size_t);
bytes: usize);
pub fn rocksdb_options_set_target_file_size_base(options: DBOptions,
bytes: u64);
pub fn rocksdb_options_set_target_file_size_multiplier(options: DBOptions,
mul: c_int);
pub fn rocksdb_options_set_max_log_file_size(options: DBOptions,
bytes: u64);
bytes: usize);
pub fn rocksdb_options_set_max_manifest_file_size(options: DBOptions,
bytes: u64);
bytes: usize);
pub fn rocksdb_options_set_hash_skip_list_rep(options: DBOptions,
bytes: u64,
bytes: usize,
a1: i32,
a2: i32);
pub fn rocksdb_options_set_compaction_style(options: DBOptions,
@ -417,7 +422,7 @@ fn internal() {
unsafe {
use std::ffi::CString;
let opts = rocksdb_options_create();
assert!(!opts.0.is_null());
assert!(!opts.is_null());
rocksdb_options_increase_parallelism(opts, 0);
rocksdb_options_optimize_level_style_compaction(opts, 0);
@ -436,7 +441,7 @@ fn internal() {
assert!(err.is_null());
let writeopts = rocksdb_writeoptions_create();
assert!(!writeopts.0.is_null());
assert!(!writeopts.is_null());
let key = b"name\x00";
let val = b"spacejam\x00";
@ -451,7 +456,7 @@ fn internal() {
assert!(err.is_null());
let readopts = rocksdb_readoptions_create();
assert!(!readopts.0.is_null());
assert!(!readopts.is_null());
let val_len: size_t = 0;
let val_len_ptr = &val_len as *const size_t;

@ -23,7 +23,7 @@ use std::path::Path;
use std::slice;
use std::str::from_utf8;
use self::libc::{c_void, size_t};
use self::libc::size_t;
use rocksdb_ffi::{self, DBCFHandle, error_message};
use rocksdb_options::{Options, WriteOptions};
@ -314,7 +314,7 @@ impl DB {
// These handles will be populated by DB.
let cfhandles: Vec<rocksdb_ffi::DBCFHandle> =
cfs_v.iter()
.map(|_| rocksdb_ffi::DBCFHandle(0 as *mut c_void))
.map(|_| 0 as rocksdb_ffi::DBCFHandle)
.collect();
// TODO(tyler) allow options to be passed in.
@ -335,7 +335,7 @@ impl DB {
}
for handle in &cfhandles {
if handle.0.is_null() {
if handle.is_null() {
return Err("Received null column family handle from DB."
.to_string());
}
@ -349,7 +349,7 @@ impl DB {
if !err.is_null() {
return Err(error_message(err));
}
if db.0.is_null() {
if db.is_null() {
return Err("Could not initialize database.".to_string());
}
@ -419,7 +419,7 @@ impl DB {
key: &[u8],
readopts: &ReadOptions)
-> Result<Option<DBVector>, String> {
if readopts.inner.0.is_null() {
if readopts.inner.is_null() {
return Err("Unable to create rocksdb read options. This is a \
fairly trivial call, and its failure may be \
indicative of a mis-compiled or mis-loaded rocksdb \
@ -459,7 +459,7 @@ impl DB {
key: &[u8],
readopts: &ReadOptions)
-> Result<Option<DBVector>, String> {
if readopts.inner.0.is_null() {
if readopts.inner.is_null() {
return Err("Unable to create rocksdb read options. This is a \
fairly trivial call, and its failure may be \
indicative of a mis-compiled or mis-loaded rocksdb \

@ -59,10 +59,6 @@ impl Drop for WriteOptions {
}
impl BlockBasedOptions {
pub fn new() -> BlockBasedOptions {
BlockBasedOptions::default()
}
pub fn set_block_size(&mut self, size: usize) {
unsafe {
rocksdb_ffi::rocksdb_block_based_options_set_block_size(self.inner,
@ -76,8 +72,7 @@ impl Default for BlockBasedOptions {
let block_opts = unsafe {
rocksdb_ffi::rocksdb_block_based_options_create()
};
let rocksdb_ffi::DBBlockBasedTableOptions(opt_ptr) = block_opts;
if opt_ptr.is_null() {
if block_opts.is_null() {
panic!("Could not create rocksdb block based options".to_string());
}
BlockBasedOptions { inner: block_opts }
@ -292,8 +287,7 @@ impl Default for Options {
fn default() -> Options {
unsafe {
let opts = rocksdb_ffi::rocksdb_options_create();
let rocksdb_ffi::DBOptions(opt_ptr) = opts;
if opt_ptr.is_null() {
if opts.is_null() {
panic!("Could not create rocksdb options".to_string());
}
Options { inner: opts }
@ -316,8 +310,7 @@ impl WriteOptions {
impl Default for WriteOptions {
fn default() -> WriteOptions {
let write_opts = unsafe { rocksdb_ffi::rocksdb_writeoptions_create() };
let rocksdb_ffi::DBWriteOptions(opt_ptr) = write_opts;
if opt_ptr.is_null() {
if write_opts.is_null() {
panic!("Could not create rocksdb write options".to_string());
}
WriteOptions { inner: write_opts }

Loading…
Cancel
Save