Unverified Commit 064ab221 authored by Huachao Huang's avatar Huachao Huang Committed by GitHub

*: improve build process and update rocksdb (#243)

Some trivial changes are applied:
- Refactor Makefile
- Refactor README.md
- Add the rust-toolchain
- Update RocksDB submodule
- Reorganize the tests structure
parent 79b56519
[submodule "librocksdb_sys/rocksdb"] [submodule "rocksdb"]
path = librocksdb_sys/rocksdb path = librocksdb_sys/rocksdb
url = https://github.com/pingcap/rocksdb.git url = https://github.com/pingcap/rocksdb.git
branch = release-5.15 branch = release-5.15
shallow = true
...@@ -19,10 +19,6 @@ valgrind = [] ...@@ -19,10 +19,6 @@ valgrind = []
portable = ["librocksdb_sys/portable"] portable = ["librocksdb_sys/portable"]
sse = ["librocksdb_sys/sse"] sse = ["librocksdb_sys/sse"]
[[test]]
name = "test"
path = "tests/test.rs"
[dependencies] [dependencies]
libc = "0.2.11" libc = "0.2.11"
crc = "1.2" crc = "1.2"
......
.PHONY: all format
# format rust code using the specified command for the specified file or directory.
# $(call do-format-with-cmd,cmd,file-or-dir)
define do-format-with-cmd
$1 --write-mode diff $2 | grep -E "Diff .*at line" > /dev/null && $1 --write-mode overwrite $2 || exit 0
endef
# format rust code in the specified file or directory
# a file of rust code follows the convention of having suffix '.rs'
# $(call format-code-in,file-or-dir)
define format-code-in
$(if $(filter %.rs, $1), \
$(call do-format-with-cmd, rustfmt, $1), \
cd $1 && $(call do-format-with-cmd, cargo fmt --))
endef
all: format build test all: format build test
format:
@cargo fmt --all
@librocksdb_sys/crocksdb/format-diff.sh > /dev/null || true
build: build:
@cargo build @cargo build
test: test:
@export RUST_BACKTRACE=1 && cargo test -- --nocapture @export RUST_BACKTRACE=1 && cargo test -- --nocapture
format:
@$(call format-code-in, .)
@$(call format-code-in, tests/test.rs)
@$(call format-code-in, librocksdb_sys)
# User may not install clang-format-diff.py, ignore any error here.
@librocksdb_sys/crocksdb/format-diff.sh > /dev/null || true
clean: clean:
@cargo clean @cargo clean
@cd librocksdb_sys && cargo clean @cd librocksdb_sys && cargo clean
update-rocksdb:
@git subtree pull -P librocksdb_sys/rocksdb https://github.com/pingcap/rocksdb.git release-5.15 --squash
rust-rocksdb # rust-rocksdb
============
This library has been tested against RocksDB 5.15 on Linux and macOS. This library has been tested against RocksDB 5.15 on Linux and macOS.
### status ## Status
- [x] basic open/put/get/delete/close - [x] basic open/put/get/delete/close
- [x] rustic merge operator - [x] rustic merge operator
- [x] write batch (thanks @dgrnbrg!) - [x] write batch (thanks @dgrnbrg!)
...@@ -28,25 +27,24 @@ This library has been tested against RocksDB 5.15 on Linux and macOS. ...@@ -28,25 +27,24 @@ This library has been tested against RocksDB 5.15 on Linux and macOS.
Feedback and pull requests welcome! If a particular feature of RocksDB is important to you, please let us know by opening an issue, and we will prioritize it. Feedback and pull requests welcome! If a particular feature of RocksDB is important to you, please let us know by opening an issue, and we will prioritize it.
###### Prerequisite: RocksDB ## Build
First, use your system's package manager to install snappy. This is optional, but lets rocksdb take advantage of better compression, and some code may require it. ```
$ git submodule update --init --recursive # if you just cloned the repository
To install rocksdb, please refer to it's installation guide. For Windows users, please make sure you configure rocksdb with `CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS` enabled. $ cargo build
Or enable feature `static-link`, the crate will download and complie RocksDB automatically, including its dependencies.
```bash
cargo build --features static-link
``` ```
### Running ## Running
###### Cargo.toml ###### Cargo.toml
```rust ```rust
[dependencies.rocksdb] [dependencies.rocksdb]
git = "https://github.com/pingcap/rust-rocksdb.git" git = "https://github.com/pingcap/rust-rocksdb.git"
``` ```
###### Code ###### Code
```rust ```rust
extern crate rocksdb; extern crate rocksdb;
use rocksdb::{DB, Writable}; use rocksdb::{DB, Writable};
...@@ -65,6 +63,7 @@ fn main() { ...@@ -65,6 +63,7 @@ fn main() {
``` ```
###### Doing an atomic commit of several writes ###### Doing an atomic commit of several writes
```rust ```rust
extern crate rocksdb; extern crate rocksdb;
use rocksdb::{DB, WriteBatch, Writable}; use rocksdb::{DB, WriteBatch, Writable};
...@@ -83,6 +82,7 @@ fn main() { ...@@ -83,6 +82,7 @@ fn main() {
``` ```
###### Getting an Iterator ###### Getting an Iterator
```rust ```rust
extern crate rocksdb; extern crate rocksdb;
use rocksdb::{DB, Direction, IteratorMode}; use rocksdb::{DB, Direction, IteratorMode};
...@@ -112,6 +112,7 @@ fn main() { ...@@ -112,6 +112,7 @@ fn main() {
``` ```
###### Getting an Iterator from a Snapshot ###### Getting an Iterator from a Snapshot
```rust ```rust
extern crate rocksdb; extern crate rocksdb;
use rocksdb::{DB, Direction}; use rocksdb::{DB, Direction};
...@@ -125,6 +126,7 @@ fn main() { ...@@ -125,6 +126,7 @@ fn main() {
``` ```
###### Rustic Merge Operator ###### Rustic Merge Operator
```rust ```rust
extern crate rocksdb; extern crate rocksdb;
use rocksdb::{Options, DB, MergeOperands, Writable}; use rocksdb::{Options, DB, MergeOperands, Writable};
...@@ -162,7 +164,9 @@ fn main() { ...@@ -162,7 +164,9 @@ fn main() {
``` ```
###### Apply Some Tunings ###### Apply Some Tunings
Please read [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide), and most importantly, measure performance under realistic workloads with realistic hardware. Please read [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide), and most importantly, measure performance under realistic workloads with realistic hardware.
```rust ```rust
use rocksdb::{Options, DB}; use rocksdb::{Options, DB};
use rocksdb::DBCompactionStyle::DBUniversalCompaction; use rocksdb::DBCompactionStyle::DBUniversalCompaction;
......
Subproject commit adf83d4ce771ea188292e4da427eafd2667b9338 Subproject commit 84eaf9c23a1a277835608dcb979ae97229391981
extern crate byteorder;
extern crate crc;
extern crate rand;
extern crate rocksdb;
extern crate tempdir;
mod test_column_family; mod test_column_family;
mod test_compact_range; mod test_compact_range;
mod test_compaction_filter; mod test_compaction_filter;
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use cases::test_ingest_external_file::gen_sst;
use rocksdb::*; use rocksdb::*;
use std::sync::atomic::*; use std::sync::atomic::*;
use std::sync::Arc; use std::sync::Arc;
use tempdir::TempDir; use tempdir::TempDir;
use test_ingest_external_file::gen_sst;
#[derive(Default, Clone)] #[derive(Default, Clone)]
struct EventCounter { struct EventCounter {
......
extern crate byteorder;
extern crate crc;
extern crate rand;
extern crate rocksdb;
extern crate tempdir;
mod cases;
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