Unverified Commit 244a8dfc authored by dorianzheng's avatar dorianzheng Committed by GitHub

cherry-pick: ci and test fix (#263)

* *: update ci and format (#248)

(cherry picked from commit dd413e47)

* *: 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

(cherry picked from commit 064ab221)

* make format

* allow nightly version fail

* minor fix
parent 18df66dd
[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 branch = release
language: rust
dist: trusty dist: trusty
sudo: required sudo: required
rust: language: rust
- beta
- nightly
- stable
cache:
directories:
- target
os: os:
- linux - linux
rust:
- stable
- beta
- nightly
matrix: matrix:
include: include:
- os: osx - os: osx
rust: stable rust: stable
- rust: stable allow_failures:
install: - rust: nightly
- rustup component add rustfmt-preview
before_script:
- cargo fmt --all -- --check
script:
- cargo build
- cargo test --all
env: env:
global: global:
- RUST_TEST_THREADS=1 - RUST_BACKTRACE=1
- LD_LIBRARY_PATH: "/usr/local/lib"
cache:
directories:
- target
before_script:
- rustup component add rustfmt-preview
script:
- cargo fmt --all -- --check
- cargo build
- cargo test --all
...@@ -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 --squash
rust-rocksdb # rust-rocksdb
============
This library has been tested against RocksDB 5.8 on Linux and macOS. This library has been tested against RocksDB 5.8 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.8 on Linux and macOS. ...@@ -28,25 +27,24 @@ This library has been tested against RocksDB 5.8 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;
......
...@@ -1473,7 +1473,10 @@ extern "C" { ...@@ -1473,7 +1473,10 @@ extern "C" {
state: *mut c_void, state: *mut c_void,
name: extern "C" fn(*mut c_void) -> *const c_char, name: extern "C" fn(*mut c_void) -> *const c_char,
destruct: extern "C" fn(*mut c_void), destruct: extern "C" fn(*mut c_void),
create_table_properties_collector: extern "C" fn(*mut c_void, uint32_t) create_table_properties_collector: extern "C" fn(
*mut c_void,
uint32_t,
)
-> *mut DBTablePropertiesCollector, -> *mut DBTablePropertiesCollector,
) -> *mut DBTablePropertiesCollectorFactory; ) -> *mut DBTablePropertiesCollectorFactory;
......
1.31.0
\ No newline at end of file
...@@ -68,9 +68,11 @@ fn main() { ...@@ -68,9 +68,11 @@ fn main() {
fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOperands) -> Vec<u8> { fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOperands) -> Vec<u8> {
let mut result: Vec<u8> = Vec::with_capacity(operands.size_hint().0); let mut result: Vec<u8> = Vec::with_capacity(operands.size_hint().0);
match existing_val { match existing_val {
Some(v) => for e in v { Some(v) => {
for e in v {
result.push(*e) result.push(*e)
}, }
}
None => (), None => (),
} }
for op in operands { for op in operands {
......
...@@ -88,7 +88,7 @@ pub extern "C" fn partial_merge_callback( ...@@ -88,7 +88,7 @@ pub extern "C" fn partial_merge_callback(
// TODO(tan) investigate zero-copy techniques to improve performance // TODO(tan) investigate zero-copy techniques to improve performance
let buf = libc::malloc(result.len() as size_t); let buf = libc::malloc(result.len() as size_t);
assert!(!buf.is_null()); assert!(!buf.is_null());
*new_value_length = 1 as size_t; *new_value_length = result.len() as size_t;
*success = 1 as u8; *success = 1 as u8;
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len()); ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
buf as *const c_char buf as *const c_char
...@@ -188,7 +188,8 @@ mod test { ...@@ -188,7 +188,8 @@ mod test {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let p = db.put(b"k1", b"a"); let p = db.put(b"k1", b"a");
assert!(p.is_ok()); assert!(p.is_ok());
let _ = db.merge(b"k1", b"b"); let _ = db.merge(b"k1", b"b");
......
...@@ -2285,7 +2285,8 @@ mod test { ...@@ -2285,7 +2285,8 @@ mod test {
db.put( db.put(
format!("{:04}", i).as_bytes(), format!("{:04}", i).as_bytes(),
format!("{:04}", i).as_bytes(), format!("{:04}", i).as_bytes(),
).expect(""); )
.expect("");
} }
db.flush(true).expect(""); db.flush(true).expect("");
assert!(db.get(b"0001").expect("").is_some()); assert!(db.get(b"0001").expect("").is_some());
...@@ -2373,7 +2374,8 @@ mod test { ...@@ -2373,7 +2374,8 @@ mod test {
restore_dir.path().to_str().unwrap(), restore_dir.path().to_str().unwrap(),
restore_dir.path().to_str().unwrap(), restore_dir.path().to_str().unwrap(),
&ropt, &ropt,
).unwrap(); )
.unwrap();
let r = restored_db.get(key); let r = restored_db.get(key);
assert!(r.unwrap().unwrap().to_utf8().unwrap() == str::from_utf8(value).unwrap()); assert!(r.unwrap().unwrap().to_utf8().unwrap() == str::from_utf8(value).unwrap());
...@@ -2454,7 +2456,8 @@ mod test { ...@@ -2454,7 +2456,8 @@ mod test {
db1.put(b"k2", b"v2").unwrap(); db1.put(b"k2", b"v2").unwrap();
db1.flush(true).unwrap(); db1.flush(true).unwrap();
db1.compact_range(None, None); db1.compact_range(None, None);
}).unwrap(); })
.unwrap();
// Wait until all currently running background processes finish. // Wait until all currently running background processes finish.
db.pause_bg_work(); db.pause_bg_work();
assert_eq!( assert_eq!(
...@@ -2637,11 +2640,9 @@ mod test { ...@@ -2637,11 +2640,9 @@ mod test {
let cf_name: &str = "cf_dynamic_level_bytes"; let cf_name: &str = "cf_dynamic_level_bytes";
// test when options not exist // test when options not exist
assert!( assert!(load_latest_options(dbpath, &Env::default(), false)
load_latest_options(dbpath, &Env::default(), false)
.unwrap() .unwrap()
.is_none() .is_none());
);
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
......
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;
......
...@@ -116,7 +116,8 @@ pub fn test_column_family() { ...@@ -116,7 +116,8 @@ pub fn test_column_family() {
DBOptions::new(), DBOptions::new(),
path_str, path_str,
vec![("cf1", ColumnFamilyOptions::new())], vec![("cf1", ColumnFamilyOptions::new())],
).unwrap(); )
.unwrap();
match db.drop_cf("cf1") { match db.drop_cf("cf1") {
Ok(_) => println!("cf1 successfully dropped."), Ok(_) => println!("cf1 successfully dropped."),
Err(e) => panic!("failed to drop column family: {}", e), Err(e) => panic!("failed to drop column family: {}", e),
...@@ -132,9 +133,11 @@ fn test_provided_merge( ...@@ -132,9 +133,11 @@ fn test_provided_merge(
let nops = operands.size_hint().0; let nops = operands.size_hint().0;
let mut result: Vec<u8> = Vec::with_capacity(nops); let mut result: Vec<u8> = Vec::with_capacity(nops);
match existing_val { match existing_val {
Some(v) => for e in v { Some(v) => {
for e in v {
result.push(*e); result.push(*e);
}, }
}
None => (), None => (),
} }
for op in operands { for op in operands {
......
...@@ -59,7 +59,8 @@ fn test_compact_range_change_level() { ...@@ -59,7 +59,8 @@ fn test_compact_range_change_level() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let samples = vec![ let samples = vec![
(b"k1".to_vec(), b"value--------1".to_vec()), (b"k1".to_vec(), b"value--------1".to_vec()),
(b"k2".to_vec(), b"value--------2".to_vec()), (b"k2".to_vec(), b"value--------2".to_vec()),
......
...@@ -52,14 +52,16 @@ fn test_compaction_filter() { ...@@ -52,14 +52,16 @@ fn test_compaction_filter() {
drop_called: drop_called.clone(), drop_called: drop_called.clone(),
filtered_kvs: filtered_kvs.clone(), filtered_kvs: filtered_kvs.clone(),
}), }),
).unwrap(); )
.unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let samples = vec![ let samples = vec![
(b"key1".to_vec(), b"value1".to_vec()), (b"key1".to_vec(), b"value1".to_vec()),
(b"key2".to_vec(), b"value2".to_vec()), (b"key2".to_vec(), b"value2".to_vec()),
...@@ -91,7 +93,8 @@ fn test_compaction_filter() { ...@@ -91,7 +93,8 @@ fn test_compaction_filter() {
drop_called: drop_called.clone(), drop_called: drop_called.clone(),
filtered_kvs: filtered_kvs.clone(), filtered_kvs: filtered_kvs.clone(),
}), }),
).unwrap(); )
.unwrap();
assert!(drop_called.load(Ordering::Relaxed)); assert!(drop_called.load(Ordering::Relaxed));
drop_called.store(false, Ordering::Relaxed); drop_called.store(false, Ordering::Relaxed);
{ {
...@@ -99,7 +102,8 @@ fn test_compaction_filter() { ...@@ -99,7 +102,8 @@ fn test_compaction_filter() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let _snap = db.snapshot(); let _snap = db.snapshot();
// Because ignore_snapshots is true, so all the keys will be compacted. // Because ignore_snapshots is true, so all the keys will be compacted.
db.compact_range(Some(b"key1"), Some(b"key3")); db.compact_range(Some(b"key1"), Some(b"key3"));
......
...@@ -640,7 +640,8 @@ fn test_delete_range_prefix_bloom_case_1() { ...@@ -640,7 +640,8 @@ fn test_delete_range_prefix_bloom_case_1() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -714,7 +715,8 @@ fn test_delete_range_prefix_bloom_case_2() { ...@@ -714,7 +715,8 @@ fn test_delete_range_prefix_bloom_case_2() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -769,7 +771,8 @@ fn test_delete_range_prefix_bloom_case_2() { ...@@ -769,7 +771,8 @@ fn test_delete_range_prefix_bloom_case_2() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -805,7 +808,8 @@ fn test_delete_range_prefix_bloom_case_3() { ...@@ -805,7 +808,8 @@ fn test_delete_range_prefix_bloom_case_3() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -849,7 +853,8 @@ fn test_delete_range_prefix_bloom_case_3() { ...@@ -849,7 +853,8 @@ fn test_delete_range_prefix_bloom_case_3() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -899,7 +904,8 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -899,7 +904,8 @@ fn test_delete_range_prefix_bloom_case_4() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -943,7 +949,8 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -943,7 +949,8 @@ fn test_delete_range_prefix_bloom_case_4() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -994,7 +1001,8 @@ fn test_delete_range_prefix_bloom_case_5() { ...@@ -994,7 +1001,8 @@ fn test_delete_range_prefix_bloom_case_5() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -1036,7 +1044,8 @@ fn test_delete_range_prefix_bloom_case_5() { ...@@ -1036,7 +1044,8 @@ fn test_delete_range_prefix_bloom_case_5() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let db2 = DB::open_cf(opts, path_str, vec![(cf, cf_opts)]).unwrap(); let db2 = DB::open_cf(opts, path_str, vec![(cf, cf_opts)]).unwrap();
...@@ -1084,7 +1093,8 @@ fn test_delete_range_prefix_bloom_case_6() { ...@@ -1084,7 +1093,8 @@ fn test_delete_range_prefix_bloom_case_6() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -1128,7 +1138,8 @@ fn test_delete_range_prefix_bloom_case_6() { ...@@ -1128,7 +1138,8 @@ fn test_delete_range_prefix_bloom_case_6() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let db2 = DB::open_cf(opts, path_str, vec![(cf, cf_opts)]).unwrap(); let db2 = DB::open_cf(opts, path_str, vec![(cf, cf_opts)]).unwrap();
...@@ -1200,7 +1211,8 @@ fn test_delete_range_prefix_bloom_compact_case() { ...@@ -1200,7 +1211,8 @@ fn test_delete_range_prefix_bloom_compact_case() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default"; let cf = "default";
...@@ -1244,7 +1256,8 @@ fn test_delete_range_prefix_bloom_compact_case() { ...@@ -1244,7 +1256,8 @@ fn test_delete_range_prefix_bloom_compact_case() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixSliceTransform", "FixedSuffixSliceTransform",
Box::new(FixedSuffixSliceTransform::new(3)), Box::new(FixedSuffixSliceTransform::new(3)),
).unwrap_or_else(|err| panic!(format!("{:?}", err))); )
.unwrap_or_else(|err| panic!(format!("{:?}", err)));
// Create prefix bloom filter for memtable. // Create prefix bloom filter for memtable.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let db2 = DB::open_cf(opts, path_str, vec![(cf, cf_opts)]).unwrap(); let db2 = DB::open_cf(opts, path_str, vec![(cf, cf_opts)]).unwrap();
......
...@@ -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 {
...@@ -99,7 +99,8 @@ fn test_event_listener_basic() { ...@@ -99,7 +99,8 @@ fn test_event_listener_basic() {
db.put( db.put(
format!("{:04}", i).as_bytes(), format!("{:04}", i).as_bytes(),
format!("{:04}", i).as_bytes(), format!("{:04}", i).as_bytes(),
).unwrap(); )
.unwrap();
} }
db.flush(true).unwrap(); db.flush(true).unwrap();
assert_ne!(counter.flush.load(Ordering::SeqCst), 0); assert_ne!(counter.flush.load(Ordering::SeqCst), 0);
...@@ -108,7 +109,8 @@ fn test_event_listener_basic() { ...@@ -108,7 +109,8 @@ fn test_event_listener_basic() {
db.put( db.put(
format!("{:04}", i).as_bytes(), format!("{:04}", i).as_bytes(),
format!("{:04}", i).as_bytes(), format!("{:04}", i).as_bytes(),
).unwrap(); )
.unwrap();
} }
db.flush(true).unwrap(); db.flush(true).unwrap();
let flush_cnt = counter.flush.load(Ordering::SeqCst); let flush_cnt = counter.flush.load(Ordering::SeqCst);
......
...@@ -82,9 +82,11 @@ fn gen_sst_delete(opt: ColumnFamilyOptions, cf: Option<&CFHandle>, path: &str) { ...@@ -82,9 +82,11 @@ fn gen_sst_delete(opt: ColumnFamilyOptions, cf: Option<&CFHandle>, path: &str) {
fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOperands) -> Vec<u8> { fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOperands) -> Vec<u8> {
let mut result: Vec<u8> = Vec::with_capacity(operands.size_hint().0); let mut result: Vec<u8> = Vec::with_capacity(operands.size_hint().0);
match existing_val { match existing_val {
Some(v) => for e in v { Some(v) => {
for e in v {
result.push(*e) result.push(*e)
}, }
}
None => (), None => (),
} }
for op in operands { for op in operands {
...@@ -342,7 +344,8 @@ fn test_ingest_simulate_real_world() { ...@@ -342,7 +344,8 @@ fn test_ingest_simulate_real_world() {
handle, handle,
&ingest_opt, &ingest_opt,
&[gen_path.path().join(cf).to_str().unwrap()], &[gen_path.path().join(cf).to_str().unwrap()],
).unwrap(); )
.unwrap();
check_kv( check_kv(
&db, &db,
db.cf_handle(cf), db.cf_handle(cf),
...@@ -369,7 +372,8 @@ fn test_ingest_simulate_real_world() { ...@@ -369,7 +372,8 @@ fn test_ingest_simulate_real_world() {
handle, handle,
&ingest_opt, &ingest_opt,
&[gen_path.path().join(cf).to_str().unwrap()], &[gen_path.path().join(cf).to_str().unwrap()],
).unwrap(); )
.unwrap();
check_kv( check_kv(
&db, &db,
db.cf_handle(cf), db.cf_handle(cf),
......
...@@ -300,7 +300,8 @@ fn test_total_order_seek() { ...@@ -300,7 +300,8 @@ fn test_total_order_seek() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedPrefixTransform", "FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 }), Box::new(FixedPrefixTransform { prefix_len: 2 }),
).unwrap(); )
.unwrap();
// also create prefix bloom for memtable // also create prefix bloom for memtable
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
...@@ -311,7 +312,8 @@ fn test_total_order_seek() { ...@@ -311,7 +312,8 @@ fn test_total_order_seek() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let wopts = WriteOptions::new(); let wopts = WriteOptions::new();
// sst1 // sst1
...@@ -386,13 +388,15 @@ fn test_fixed_suffix_seek() { ...@@ -386,13 +388,15 @@ fn test_fixed_suffix_seek() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedSuffixTransform", "FixedSuffixTransform",
Box::new(FixedSuffixTransform { suffix_len: 2 }), Box::new(FixedSuffixTransform { suffix_len: 2 }),
).unwrap(); )
.unwrap();
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
db.put(b"k-eghe-5", b"a").unwrap(); db.put(b"k-eghe-5", b"a").unwrap();
db.put(b"k-24yfae-6", b"a").unwrap(); db.put(b"k-24yfae-6", b"a").unwrap();
db.put(b"k-h1fwd-7", b"a").unwrap(); db.put(b"k-h1fwd-7", b"a").unwrap();
......
...@@ -27,7 +27,8 @@ fn test_metadata() { ...@@ -27,7 +27,8 @@ fn test_metadata() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let cf_handle = db.cf_handle("default").unwrap(); let cf_handle = db.cf_handle("default").unwrap();
let num_files = 5; let num_files = 5;
...@@ -80,7 +81,8 @@ fn test_compact_files() { ...@@ -80,7 +81,8 @@ fn test_compact_files() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let cf_handle = db.cf_handle("default").unwrap(); let cf_handle = db.cf_handle("default").unwrap();
let cf_opts = db.get_options_cf(cf_handle); let cf_opts = db.get_options_cf(cf_handle);
......
...@@ -45,9 +45,11 @@ pub fn test_multithreaded() { ...@@ -45,9 +45,11 @@ pub fn test_multithreaded() {
let j3 = thread::spawn(move || { let j3 = thread::spawn(move || {
for _ in 1..N { for _ in 1..N {
match db3.get(b"key") { match db3.get(b"key") {
Ok(Some(v)) => if &v[..] != b"value1" && &v[..] != b"value2" { Ok(Some(v)) => {
if &v[..] != b"value1" && &v[..] != b"value2" {
assert!(false); assert!(false);
}, }
}
_ => { _ => {
assert!(false); assert!(false);
} }
......
...@@ -62,14 +62,16 @@ fn test_prefix_extractor_compatibility() { ...@@ -62,14 +62,16 @@ fn test_prefix_extractor_compatibility() {
.set_prefix_extractor( .set_prefix_extractor(
"FixedPrefixTransform", "FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 }), Box::new(FixedPrefixTransform { prefix_len: 2 }),
).unwrap(); )
.unwrap();
// also create prefix bloom for memtable // also create prefix bloom for memtable
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let wopts = WriteOptions::new(); let wopts = WriteOptions::new();
// sst2 with prefix bloom. // sst2 with prefix bloom.
......
...@@ -36,7 +36,8 @@ fn test_set_num_levels() { ...@@ -36,7 +36,8 @@ fn test_set_num_levels() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
drop(db); drop(db);
} }
...@@ -74,14 +75,12 @@ fn test_enable_statistics() { ...@@ -74,14 +75,12 @@ fn test_enable_statistics() {
opts.enable_statistics(true); opts.enable_statistics(true);
opts.set_stats_dump_period_sec(60); opts.set_stats_dump_period_sec(60);
assert!(opts.get_statistics().is_some()); assert!(opts.get_statistics().is_some());
assert!( assert!(opts
opts.get_statistics_histogram(HistogramType::SeekMicros) .get_statistics_histogram(HistogramType::SeekMicros)
.is_some() .is_some());
); assert!(opts
assert!( .get_statistics_histogram_string(HistogramType::SeekMicros)
opts.get_statistics_histogram_string(HistogramType::SeekMicros) .is_some());
.is_some()
);
assert_eq!( assert_eq!(
opts.get_statistics_ticker_count(TickerType::BlockCacheMiss), opts.get_statistics_ticker_count(TickerType::BlockCacheMiss),
0 0
...@@ -123,12 +122,14 @@ fn test_memtable_insert_hint_prefix_extractor() { ...@@ -123,12 +122,14 @@ fn test_memtable_insert_hint_prefix_extractor() {
.set_memtable_insert_hint_prefix_extractor( .set_memtable_insert_hint_prefix_extractor(
"FixedPrefixTransform", "FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 }), Box::new(FixedPrefixTransform { prefix_len: 2 }),
).unwrap(); )
.unwrap();
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let wopts = WriteOptions::new(); let wopts = WriteOptions::new();
db.put_opt(b"k0-1", b"a", &wopts).unwrap(); db.put_opt(b"k0-1", b"a", &wopts).unwrap();
...@@ -261,7 +262,8 @@ fn test_set_pin_l0_filter_and_index_blocks_in_cache() { ...@@ -261,7 +262,8 @@ fn test_set_pin_l0_filter_and_index_blocks_in_cache() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
...@@ -289,7 +291,8 @@ fn test_set_cache_index_and_filter_blocks_with_high_priority() { ...@@ -289,7 +291,8 @@ fn test_set_cache_index_and_filter_blocks_with_high_priority() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
...@@ -304,7 +307,8 @@ fn test_pending_compaction_bytes_limit() { ...@@ -304,7 +307,8 @@ fn test_pending_compaction_bytes_limit() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
...@@ -337,7 +341,8 @@ fn test_set_optimize_filters_for_hits() { ...@@ -337,7 +341,8 @@ fn test_set_optimize_filters_for_hits() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
...@@ -356,7 +361,8 @@ fn test_get_block_cache_usage() { ...@@ -356,7 +361,8 @@ fn test_get_block_cache_usage() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
for i in 0..200 { for i in 0..200 {
db.put(format!("k_{}", i).as_bytes(), b"v").unwrap(); db.put(format!("k_{}", i).as_bytes(), b"v").unwrap();
...@@ -383,7 +389,8 @@ fn test_block_cache_capacity() { ...@@ -383,7 +389,8 @@ fn test_block_cache_capacity() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
assert_eq!( assert_eq!(
db.get_options().get_block_cache_capacity(), db.get_options().get_block_cache_capacity(),
...@@ -420,7 +427,8 @@ fn test_set_level_compaction_dynamic_level_bytes() { ...@@ -420,7 +427,8 @@ fn test_set_level_compaction_dynamic_level_bytes() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
...@@ -476,7 +484,8 @@ fn test_set_compaction_pri() { ...@@ -476,7 +484,8 @@ fn test_set_compaction_pri() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
...@@ -551,7 +560,8 @@ fn test_bottommost_compression() { ...@@ -551,7 +560,8 @@ fn test_bottommost_compression() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
} }
#[test] #[test]
......
...@@ -53,7 +53,8 @@ fn test_slice_transform() { ...@@ -53,7 +53,8 @@ fn test_slice_transform() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let samples = vec![ let samples = vec![
(b"key_01".to_vec(), b"1".to_vec()), (b"key_01".to_vec(), b"1".to_vec()),
(b"key_02".to_vec(), b"2".to_vec()), (b"key_02".to_vec(), b"2".to_vec()),
......
...@@ -35,14 +35,12 @@ fn test_db_statistics() { ...@@ -35,14 +35,12 @@ fn test_db_statistics() {
assert!(db.get_statistics_ticker_count(TickerType::BlockCacheHit) > 0); assert!(db.get_statistics_ticker_count(TickerType::BlockCacheHit) > 0);
assert!(db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit) > 0); assert!(db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit) > 0);
assert_eq!(db.get_statistics_ticker_count(TickerType::BlockCacheHit), 0); assert_eq!(db.get_statistics_ticker_count(TickerType::BlockCacheHit), 0);
assert!( assert!(db
db.get_statistics_histogram_string(HistogramType::GetMicros) .get_statistics_histogram_string(HistogramType::GetMicros)
.is_some() .is_some());
); assert!(db
assert!( .get_statistics_histogram(HistogramType::GetMicros)
db.get_statistics_histogram(HistogramType::GetMicros) .is_some());
.is_some()
);
let get_micros = db let get_micros = db
.get_statistics_histogram(HistogramType::GetMicros) .get_statistics_histogram(HistogramType::GetMicros)
...@@ -77,12 +75,10 @@ fn test_disable_db_statistics() { ...@@ -77,12 +75,10 @@ fn test_disable_db_statistics() {
db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit), db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit),
0 0
); );
assert!( assert!(db
db.get_statistics_histogram_string(HistogramType::GetMicros) .get_statistics_histogram_string(HistogramType::GetMicros)
.is_none() .is_none());
); assert!(db
assert!( .get_statistics_histogram(HistogramType::GetMicros)
db.get_statistics_histogram(HistogramType::GetMicros) .is_none());
.is_none()
);
} }
...@@ -84,11 +84,9 @@ impl ExampleCollector { ...@@ -84,11 +84,9 @@ impl ExampleCollector {
for (k, v) in props { for (k, v) in props {
assert_eq!(v, props.get(k).unwrap()); assert_eq!(v, props.get(k).unwrap());
} }
assert!( assert!(props
props
.get(&[Props::NumKeys as u8, Props::NumPuts as u8]) .get(&[Props::NumKeys as u8, Props::NumPuts as u8])
.is_none() .is_none());
);
assert!(props.len() >= 4); assert!(props.len() >= 4);
c c
...@@ -176,7 +174,8 @@ fn test_table_properties_collector_factory() { ...@@ -176,7 +174,8 @@ fn test_table_properties_collector_factory() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
let samples = vec![ let samples = vec![
(b"key1".to_vec(), b"value1".to_vec()), (b"key1".to_vec(), b"value1".to_vec()),
...@@ -249,7 +248,8 @@ fn test_table_properties_with_table_filter() { ...@@ -249,7 +248,8 @@ fn test_table_properties_with_table_filter() {
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
vec![("default", cf_opts)], vec![("default", cf_opts)],
).unwrap(); )
.unwrap();
// Generate a sst with 4 entries. // Generate a sst with 4 entries.
let samples = vec![ let samples = vec![
......
use rocksdb::{ColumnFamilyOptions, DBOptions, Writable, DB};
use tempdir::TempDir;
#[test]
pub fn test_ttl() {
let path = TempDir::new("_rust_rocksdb_ttl_test").expect("");
let path_str = path.path().to_str().unwrap();
// should be able to open db with ttl
{
let mut opts = DBOptions::new();
let cf_opts = ColumnFamilyOptions::new();
let ttl = 10;
opts.create_if_missing(true);
let mut db = match DB::open_cf_with_ttl(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
&[ttl],
) {
Ok(db) => {
println!("successfully opened db with ttl");
db
}
Err(e) => panic!("failed to open db with ttl: {}", e),
};
match db.create_cf("cf1") {
Ok(_) => println!("cf1 created successfully"),
Err(e) => {
panic!("could not create column family: {}", e);
}
}
assert_eq!(db.cf_names(), vec!["cf1", "default"]);
match db.create_cf("cf2") {
Ok(_) => println!("cf2 created successfully"),
Err(e) => {
panic!("could not create column family: {}", e);
}
}
assert_eq!(db.cf_names(), vec!["cf1", "cf2", "default"]);
drop(db);
}
// should be able to write, read over a cf with the length of ttls equals to that of cfs
{
let db = match DB::open_cf_with_ttl(
DBOptions::new(),
path_str,
vec![
("cf1", ColumnFamilyOptions::new()),
("cf2", ColumnFamilyOptions::new()),
("default", ColumnFamilyOptions::new()),
],
&[10, 10, 10],
) {
Ok(db) => {
println!("successfully opened cf with ttl");
db
}
Err(e) => panic!("failed to open cf with ttl: {}", e),
};
let cf1 = db.cf_handle("cf1").unwrap();
assert!(db.put_cf(cf1, b"k1", b"v1").is_ok());
assert!(db.get_cf(cf1, b"k1").unwrap().unwrap().to_utf8().unwrap() == "v1");
let p = db.put_cf(cf1, b"k1", b"a");
assert!(p.is_ok());
}
// should be able to write, read over a cf with the length of ttls equals to that of cfs.
// default cf could be with ttl 0 if it is not in cfds
{
let db = match DB::open_cf_with_ttl(
DBOptions::new(),
path_str,
vec![
("cf1", ColumnFamilyOptions::new()),
("cf2", ColumnFamilyOptions::new()),
],
&[10, 10],
) {
Ok(db) => {
println!("successfully opened cf with ttl");
db
}
Err(e) => panic!("failed to open cf with ttl: {}", e),
};
let cf1 = db.cf_handle("cf1").unwrap();
assert!(db.put_cf(cf1, b"k1", b"v1").is_ok());
assert!(db.get_cf(cf1, b"k1").unwrap().unwrap().to_utf8().unwrap() == "v1");
let p = db.put_cf(cf1, b"k1", b"a");
assert!(p.is_ok());
}
// should fail to open cf with ttl when the length of ttls not equal to that of cfs
{
let _db = match DB::open_cf_with_ttl(
DBOptions::new(),
path_str,
vec![
("cf1", ColumnFamilyOptions::new()),
("cf2", ColumnFamilyOptions::new()),
],
&[10],
) {
Ok(_) => panic!(
"should not have opened DB successfully with ttl \
when the length of ttl not equal to that of cfs"
),
Err(e) => assert!(e.starts_with("the length of ttls not equal to length of cfs")),
};
}
// should fail to open cf with ttl when the length of ttls not equal to that of cfs
// when default is in cfds, it's ttl must be supplied
{
let _db = match DB::open_cf_with_ttl(
DBOptions::new(),
path_str,
vec![
("cf1", ColumnFamilyOptions::new()),
("cf2", ColumnFamilyOptions::new()),
("default", ColumnFamilyOptions::new()),
],
&[10, 10],
) {
Ok(_) => panic!(
"should not have opened DB successfully with ttl \
when the length of ttl not equal to that of cfs"
),
Err(e) => assert!(e.starts_with("the length of ttls not equal to length of cfs")),
};
}
}
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