Commit 91e7dd74 authored by Tyler Neely's avatar Tyler Neely

remove some debugging cruft

parent 1a02679f
...@@ -21,12 +21,16 @@ fn writes(b: &mut Bencher) { ...@@ -21,12 +21,16 @@ fn writes(b: &mut Bencher) {
db.close(); db.close();
} }
#[bench] #[bbench]
fn reads(b: &mut Bencher) { fn reads(b: &mut Bencher) {
let db = open("testdb".to_string(), true).unwrap(); let db = open("testdb".to_string(), true).unwrap();
let mut i = 0 as u64; let mut i = 0 as u64;
b.iter(|| { b.iter(|| {
db.get(i.to_string().as_bytes()); db.get(i.to_string().as_bytes()).on_error(
|e| {
println!("error: {}", e);
e
});
i += 1; i += 1;
}); });
db.close(); db.close();
......
...@@ -47,6 +47,27 @@ impl <T,E> RocksdbResult<T,E> { ...@@ -47,6 +47,27 @@ impl <T,E> RocksdbResult<T,E> {
} }
} }
#[unstable = "waiting for unboxed closures"]
pub fn on_error<U>(self, f: |E| -> U) -> RocksdbResult<T,U> {
match self {
RocksdbResult::Some(x) => RocksdbResult::Some(x),
RocksdbResult::None => RocksdbResult::None,
RocksdbResult::Error(e) => RocksdbResult::Error(f(e)),
}
}
#[unstable = "waiting for unboxed closures"]
pub fn on_absent<U>(self, f: || -> ()) -> RocksdbResult<T,E> {
match self {
RocksdbResult::Some(x) => RocksdbResult::Some(x),
RocksdbResult::None => {
f();
RocksdbResult::None
},
RocksdbResult::Error(e) => RocksdbResult::Error(e),
}
}
pub fn is_some(self) -> bool { pub fn is_some(self) -> bool {
match self { match self {
RocksdbResult::Some(T) => true, RocksdbResult::Some(T) => true,
...@@ -76,7 +97,7 @@ pub struct Rocksdb { ...@@ -76,7 +97,7 @@ pub struct Rocksdb {
} }
impl Rocksdb { impl Rocksdb {
pub fn put(&self, key: &[u8], value: &[u8]) -> IoResult<bool> { pub fn put(&self, key: &[u8], value: &[u8]) -> Result<bool, String> {
unsafe { unsafe {
let writeopts = ffi::rocksdb_writeoptions_create(); let writeopts = ffi::rocksdb_writeoptions_create();
let err = 0 as *mut i8; let err = 0 as *mut i8;
...@@ -84,10 +105,20 @@ impl Rocksdb { ...@@ -84,10 +105,20 @@ impl Rocksdb {
key.len() as size_t, value.as_ptr(), key.len() as size_t, value.as_ptr(),
value.len() as size_t, err); value.len() as size_t, err);
if err.is_not_null() { if err.is_not_null() {
libc::free(err as *mut c_void); let cs = CString::new(err as *const i8, true);
return Err(IoError::last_error()); match cs.as_str() {
Some(error_string) =>
return Err(error_string.to_string()),
None => {
let ie = IoError::last_error();
return Err(format!(
"ERROR: desc:{}, details:{}",
ie.desc,
ie.detail.unwrap_or_else(
|| {"none provided by OS".to_string()})))
}
}
} }
libc::free(err as *mut c_void);
return Ok(true) return Ok(true)
} }
} }
...@@ -142,8 +173,8 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> { ...@@ -142,8 +173,8 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> {
return Err("Could not create options".to_string()); return Err("Could not create options".to_string());
} }
ffi::rocksdb_options_increase_parallelism(opts, 0); ffi::rocksdb_options_increase_parallelism(opts, 2);
ffi::rocksdb_options_optimize_level_style_compaction(opts, 0); //ffi::rocksdb_options_optimize_level_style_compaction(opts, 0);
match create_if_missing { match create_if_missing {
true => ffi::rocksdb_options_set_create_if_missing(opts, 1), true => ffi::rocksdb_options_set_create_if_missing(opts, 1),
...@@ -157,10 +188,14 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> { ...@@ -157,10 +188,14 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> {
let db = ffi::rocksdb_open(opts, cpath_ptr, err); let db = ffi::rocksdb_open(opts, cpath_ptr, err);
let ffi::RocksdbInstance(db_ptr) = db; let ffi::RocksdbInstance(db_ptr) = db;
if err.is_not_null() { if err.is_not_null() {
libc::free(err as *mut c_void); let cs = CString::new(err as *const i8, true);
return Err("Could not initialize database.".to_string()); match cs.as_str() {
Some(error_string) =>
return Err(error_string.to_string()),
None =>
return Err("Could not initialize database.".to_string()),
}
} }
libc::free(err as *mut c_void);
if db_ptr.is_null() { if db_ptr.is_null() {
return Err("Could not initialize database.".to_string()); return Err("Could not initialize database.".to_string());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment