From d78c250da8fdaf9ab4074dde68598a1580635d65 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:16:22 -0700 Subject: [PATCH 1/8] Now friendly with 1.1 stable! --- Cargo.toml | 3 +++ src/lib.rs | 4 ---- src/main.rs | 16 +++++++++------- src/merge_operator.rs | 15 ++++++++++----- src/rocksdb.rs | 27 ++++++++------------------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4a15f4..8a7e198 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,6 @@ valgrind=[] name = "test" path = "test/test.rs" + +[dependencies] +libc = "0.1.8" diff --git a/src/lib.rs b/src/lib.rs index 621add8..7cee152 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,10 +15,6 @@ */ #![crate_id = "rocksdb"] #![crate_type = "lib"] -#![feature(libc)] -#![feature(unique)] -#![feature(path_ext)] -#![feature(raw)] pub use ffi as rocksdb_ffi; pub use ffi::{new_bloom_filter, RocksDBCompactionStyle, RocksDBComparator}; diff --git a/src/main.rs b/src/main.rs index 14f0d51..0d134db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#![feature(test)] - extern crate rocksdb; -extern crate test; use rocksdb::{Options, RocksDB, MergeOperands, new_bloom_filter, Writable, }; use rocksdb::RocksDBCompactionStyle::RocksDBUniversalCompaction; @@ -72,11 +69,15 @@ fn concat_merge(new_key: &[u8], existing_val: Option<&[u8]>, mut operands: &mut MergeOperands) -> Vec { let mut result: Vec = Vec::with_capacity(operands.size_hint().0); match existing_val { - Some(v) => result.extend(v), + Some(v) => for e in v { + result.push(*e) + }, None => (), } for op in operands { - result.extend(op); + for e in op { + result.push(*e); + } } result } @@ -138,7 +139,6 @@ fn main() { #[cfg(test)] mod tests { - use test::Bencher; use std::thread::sleep_ms; use rocksdb::{BlockBasedOptions, Options, RocksDB, MergeOperands, new_bloom_filter, Writable }; @@ -171,7 +171,8 @@ mod tests { RocksDB::open(&opts, path).unwrap() } - + + /* TODO(tyler) unstable #[bench] fn a_writes(b: &mut Bencher) { // dirty hack due to parallel tests causing contention. @@ -205,4 +206,5 @@ mod tests { } RocksDB::destroy(&opts, path).is_ok(); } + */ } diff --git a/src/merge_operator.rs b/src/merge_operator.rs index 38766e6..6783e49 100644 --- a/src/merge_operator.rs +++ b/src/merge_operator.rs @@ -131,7 +131,6 @@ impl MergeOperands { impl<'a> Iterator for &'a mut MergeOperands { type Item = &'a [u8]; fn next(&mut self) -> Option<&'a [u8]> { - use std::raw::Slice; match self.cursor == self.num_operands { true => None, false => { @@ -145,8 +144,8 @@ impl<'a> Iterator for &'a mut MergeOperands { let len = *len_ptr as usize; let ptr = base + (spacing * self.cursor); self.cursor += 1; - Some(mem::transmute(Slice{data:*(ptr as *const *const u8) - as *const u8, len: len})) + Some(mem::transmute(slice::from_raw_parts(*(ptr as *const *const u8) + as *const u8, len))) } } } @@ -165,11 +164,17 @@ fn test_provided_merge(new_key: &[u8], let nops = operands.size_hint().0; let mut result: Vec = Vec::with_capacity(nops); match existing_val { - Some(v) => result.extend(v), + Some(v) => { + for e in v { + result.push(*e); + } + }, None => (), } for op in operands { - result.extend(op); + for e in op { + result.push(*e); + } } result } diff --git a/src/rocksdb.rs b/src/rocksdb.rs index f0f1e78..6ae0ab0 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -17,10 +17,9 @@ extern crate libc; use self::libc::{c_void, size_t}; use std::ffi::{CString, CStr}; -use std::fs::{self, PathExt}; +use std::fs; use std::ops::Deref; use std::path::Path; -use std::ptr::Unique; use std::slice; use std::str::from_utf8; use std::marker::PhantomData; @@ -192,11 +191,9 @@ impl RocksDB { let cpath_ptr = cpath.as_ptr(); let ospath = Path::new(path); - if !ospath.exists() { - match fs::create_dir_all(&ospath) { - Err(e) => return Err("Failed to create rocksdb directory.".to_string()), - Ok(_) => (), - } + match fs::create_dir_all(&ospath) { + Err(e) => return Err("Failed to create rocksdb directory.".to_string()), + Ok(_) => (), } let mut err: *const i8 = 0 as *const i8; @@ -222,10 +219,6 @@ impl RocksDB { let cpath_ptr = cpath.as_ptr(); let ospath = Path::new(path); - if !ospath.exists() { - return Err("path does not exist".to_string()); - } - let mut err: *const i8 = 0 as *const i8; let err_ptr: *mut *const i8 = &mut err; unsafe { @@ -242,10 +235,6 @@ impl RocksDB { let cpath_ptr = cpath.as_ptr(); let ospath = Path::new(path); - if !ospath.exists() { - return Err("path does not exist".to_string()); - } - let mut err: *const i8 = 0 as *const i8; let err_ptr: *mut *const i8 = &mut err; unsafe { @@ -442,21 +431,21 @@ impl ReadOptions { } pub struct RocksDBVector { - base: Unique, + base: *mut u8, len: usize, } impl Deref for RocksDBVector { type Target = [u8]; fn deref(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.base.get(), self.len) } + unsafe { slice::from_raw_parts(self.base, self.len) } } } impl Drop for RocksDBVector { fn drop(&mut self) { unsafe { - libc::free(*self.base.deref() as *mut libc::c_void); + libc::free(self.base as *mut libc::c_void); } } } @@ -465,7 +454,7 @@ impl RocksDBVector { pub fn from_c(val: *mut u8, val_len: size_t) -> RocksDBVector { unsafe { RocksDBVector { - base: Unique::new(val), + base: val, len: val_len as usize, } } From a0785a72965152d270e3620ef2a43ab90483ee93 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:25:13 -0700 Subject: [PATCH 2/8] Update travis build. --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 49bec80..af0b14b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,11 @@ language: rust rust: - nightly + - 1.1.0 + +os: + - linux + - osx script: - - rustc src/lib.rs + - cargo build From 11a982c77e88e2debd68c7aa9175b8ff2925cf50 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:29:57 -0700 Subject: [PATCH 3/8] Build rocksdb and run tests. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index af0b14b..39169ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,8 @@ language: rust +sudo: true + +before_install: + - wget https://github.com/facebook/rocksdb/archive/rocksdb-3.8.tar.gz; tar xvf rocksdb-3.8.tar.gz && cd rocksdb-rocksdb-3.8 && make shared_lib; make install rust: - nightly From 5003a29b4547745bd1d673cde2d8ec08117f4173 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:35:29 -0700 Subject: [PATCH 4/8] travis spaghetti --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 39169ca..4fec171 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: rust sudo: true +compiler: + - clang + before_install: - wget https://github.com/facebook/rocksdb/archive/rocksdb-3.8.tar.gz; tar xvf rocksdb-3.8.tar.gz && cd rocksdb-rocksdb-3.8 && make shared_lib; make install @@ -14,3 +17,4 @@ os: script: - cargo build + - cargo test From 7d67344678b7135b989b6e5c7454341017bcd147 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:41:33 -0700 Subject: [PATCH 5/8] travis spaghetti --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4fec171..ff0a6bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,11 @@ language: rust sudo: true compiler: - - clang + - gcc before_install: + - sudo apt-get update -qq + - sudo apt-get install -y gcc libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev - wget https://github.com/facebook/rocksdb/archive/rocksdb-3.8.tar.gz; tar xvf rocksdb-3.8.tar.gz && cd rocksdb-rocksdb-3.8 && make shared_lib; make install rust: From 8be7b68e32369b19abf2aaf82fb5213e00a69f1d Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:47:59 -0700 Subject: [PATCH 6/8] travis spaghetti --- .travis.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff0a6bc..1c4b5ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,4 @@ language: rust -sudo: true - -compiler: - - gcc - -before_install: - - sudo apt-get update -qq - - sudo apt-get install -y gcc libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev - - wget https://github.com/facebook/rocksdb/archive/rocksdb-3.8.tar.gz; tar xvf rocksdb-3.8.tar.gz && cd rocksdb-rocksdb-3.8 && make shared_lib; make install rust: - nightly @@ -18,5 +9,4 @@ os: - osx script: - - cargo build - - cargo test + - rustc -Z parse-only src/lib.rs From 163398cc87f37577040d67b9eb89ff1fd3315c34 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 13:54:30 -0700 Subject: [PATCH 7/8] Cut 0.1.0, first stable release! --- Cargo.toml | 2 +- README.md | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a7e198..7048181 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rocksdb" description = "A Rust wrapper for Facebook's RocksDB embeddable database." -version = "0.0.8" +version = "0.1.0" authors = ["Tyler Neely ", "David Greenberg "] license = "Apache-2.0" exclude = [ diff --git a/README.md b/README.md index 4e0cb7a..5392ca9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ rust-rocksdb ============ [![Build Status](https://travis-ci.org/spacejam/rust-rocksdb.svg?branch=master)](https://travis-ci.org/spacejam/rust-rocksdb) -This library has been tested against RocksDB 3.8.1 on linux and OSX. The 0.0.8 crate should work with the Rust nightly release as of 7/18/15. +This library has been tested against RocksDB 3.8.1 on linux and OSX. The 0.1.0 crate should work with the Rust 1.1 stable and nightly releases as of 8/2/15. ### status - [x] basic open/put/get/delete/close @@ -31,7 +31,7 @@ sudo make install ###### Cargo.toml ```rust [dependencies] -rocksdb = "~0.0.8" +rocksdb = "~0.1.0" ``` ###### Code ```rust @@ -42,7 +42,7 @@ fn main() { let mut db = RocksDB::open_default("/path/for/rocksdb/storage").unwrap(); db.put(b"my key", b"my value"); db.get(b"my key") - .map( |value| { + .map( |value| { println!("retrieved value {}", value.to_utf8().unwrap()) }) .on_absent( || { println!("value not found") }) @@ -112,9 +112,15 @@ use rocksdb::{Options, RocksDB, MergeOperands, Writable}; fn concat_merge(new_key: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOperands) -> Vec { let mut result: Vec = Vec::with_capacity(operands.size_hint().0); - existing_val.map(|v| { result.extend(v) }); + existing_val.map(|v| { + for e in v { + result.push(e) + } + }); for op in operands { - result.extend(op); + for e in op { + result.push(e) + } } result } From e2cc69101af244a3a89d77514544f0d18dfa14e4 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 2 Aug 2015 14:12:25 -0700 Subject: [PATCH 8/8] Fix readme. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5392ca9..4956dd9 100644 --- a/README.md +++ b/README.md @@ -114,12 +114,12 @@ fn concat_merge(new_key: &[u8], existing_val: Option<&[u8]>, let mut result: Vec = Vec::with_capacity(operands.size_hint().0); existing_val.map(|v| { for e in v { - result.push(e) + result.push(*e) } }); for op in operands { for e in op { - result.push(e) + result.push(*e) } } result