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
url = https://github.com/pingcap/rocksdb.git
branch = release
language: rust
dist: trusty
sudo: required
rust:
- beta
- nightly
- stable
cache:
directories:
- target
language: rust
os:
- linux
rust:
- stable
- beta
- nightly
matrix:
include:
- os: osx
rust: stable
- rust: stable
install:
- rustup component add rustfmt-preview
before_script:
- cargo fmt --all -- --check
script:
- cargo build
- cargo test --all
allow_failures:
- rust: nightly
env:
global:
- RUST_TEST_THREADS=1
- LD_LIBRARY_PATH: "/usr/local/lib"
- RUST_BACKTRACE=1
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 = []
portable = ["librocksdb_sys/portable"]
sse = ["librocksdb_sys/sse"]
[[test]]
name = "test"
path = "tests/test.rs"
[dependencies]
libc = "0.2.11"
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
format:
@cargo fmt --all
@librocksdb_sys/crocksdb/format-diff.sh > /dev/null || true
build:
@cargo build
@cargo build
test:
@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
@export RUST_BACKTRACE=1 && cargo test -- --nocapture
clean:
@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.
### status
## Status
- [x] basic open/put/get/delete/close
- [x] rustic merge operator
- [x] write batch (thanks @dgrnbrg!)
......@@ -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.
###### 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.
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.
Or enable feature `static-link`, the crate will download and complie RocksDB automatically, including its dependencies.
```bash
cargo build --features static-link
```
$ git submodule update --init --recursive # if you just cloned the repository
$ cargo build
```
### Running
## Running
###### Cargo.toml
```rust
[dependencies.rocksdb]
git = "https://github.com/pingcap/rust-rocksdb.git"
```
###### Code
```rust
extern crate rocksdb;
use rocksdb::{DB, Writable};
......@@ -65,6 +63,7 @@ fn main() {
```
###### Doing an atomic commit of several writes
```rust
extern crate rocksdb;
use rocksdb::{DB, WriteBatch, Writable};
......@@ -83,6 +82,7 @@ fn main() {
```
###### Getting an Iterator
```rust
extern crate rocksdb;
use rocksdb::{DB, Direction, IteratorMode};
......@@ -112,6 +112,7 @@ fn main() {
```
###### Getting an Iterator from a Snapshot
```rust
extern crate rocksdb;
use rocksdb::{DB, Direction};
......@@ -125,6 +126,7 @@ fn main() {
```
###### Rustic Merge Operator
```rust
extern crate rocksdb;
use rocksdb::{Options, DB, MergeOperands, Writable};
......@@ -162,7 +164,9 @@ fn main() {
```
###### 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.
```rust
use rocksdb::{Options, DB};
use rocksdb::DBCompactionStyle::DBUniversalCompaction;
......
......@@ -1473,7 +1473,10 @@ extern "C" {
state: *mut c_void,
name: extern "C" fn(*mut c_void) -> *const c_char,
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 DBTablePropertiesCollectorFactory;
......
1.31.0
\ No newline at end of file
......@@ -68,9 +68,11 @@ fn main() {
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);
match existing_val {
Some(v) => for e in v {
result.push(*e)
},
Some(v) => {
for e in v {
result.push(*e)
}
}
None => (),
}
for op in operands {
......
......@@ -88,7 +88,7 @@ pub extern "C" fn partial_merge_callback(
// TODO(tan) investigate zero-copy techniques to improve performance
let buf = libc::malloc(result.len() as size_t);
assert!(!buf.is_null());
*new_value_length = 1 as size_t;
*new_value_length = result.len() as size_t;
*success = 1 as u8;
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
buf as *const c_char
......@@ -188,7 +188,8 @@ mod test {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let p = db.put(b"k1", b"a");
assert!(p.is_ok());
let _ = db.merge(b"k1", b"b");
......
......@@ -2285,7 +2285,8 @@ mod test {
db.put(
format!("{:04}", i).as_bytes(),
format!("{:04}", i).as_bytes(),
).expect("");
)
.expect("");
}
db.flush(true).expect("");
assert!(db.get(b"0001").expect("").is_some());
......@@ -2373,7 +2374,8 @@ mod test {
restore_dir.path().to_str().unwrap(),
restore_dir.path().to_str().unwrap(),
&ropt,
).unwrap();
)
.unwrap();
let r = restored_db.get(key);
assert!(r.unwrap().unwrap().to_utf8().unwrap() == str::from_utf8(value).unwrap());
......@@ -2454,7 +2456,8 @@ mod test {
db1.put(b"k2", b"v2").unwrap();
db1.flush(true).unwrap();
db1.compact_range(None, None);
}).unwrap();
})
.unwrap();
// Wait until all currently running background processes finish.
db.pause_bg_work();
assert_eq!(
......@@ -2637,11 +2640,9 @@ mod test {
let cf_name: &str = "cf_dynamic_level_bytes";
// test when options not exist
assert!(
load_latest_options(dbpath, &Env::default(), false)
.unwrap()
.is_none()
);
assert!(load_latest_options(dbpath, &Env::default(), false)
.unwrap()
.is_none());
let mut opts = DBOptions::new();
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_compact_range;
mod test_compaction_filter;
......
......@@ -116,7 +116,8 @@ pub fn test_column_family() {
DBOptions::new(),
path_str,
vec![("cf1", ColumnFamilyOptions::new())],
).unwrap();
)
.unwrap();
match db.drop_cf("cf1") {
Ok(_) => println!("cf1 successfully dropped."),
Err(e) => panic!("failed to drop column family: {}", e),
......@@ -132,9 +133,11 @@ fn test_provided_merge(
let nops = operands.size_hint().0;
let mut result: Vec<u8> = Vec::with_capacity(nops);
match existing_val {
Some(v) => for e in v {
result.push(*e);
},
Some(v) => {
for e in v {
result.push(*e);
}
}
None => (),
}
for op in operands {
......
......@@ -59,7 +59,8 @@ fn test_compact_range_change_level() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let samples = vec![
(b"k1".to_vec(), b"value--------1".to_vec()),
(b"k2".to_vec(), b"value--------2".to_vec()),
......
......@@ -52,14 +52,16 @@ fn test_compaction_filter() {
drop_called: drop_called.clone(),
filtered_kvs: filtered_kvs.clone(),
}),
).unwrap();
)
.unwrap();
let mut opts = DBOptions::new();
opts.create_if_missing(true);
let db = DB::open_cf(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let samples = vec![
(b"key1".to_vec(), b"value1".to_vec()),
(b"key2".to_vec(), b"value2".to_vec()),
......@@ -91,7 +93,8 @@ fn test_compaction_filter() {
drop_called: drop_called.clone(),
filtered_kvs: filtered_kvs.clone(),
}),
).unwrap();
)
.unwrap();
assert!(drop_called.load(Ordering::Relaxed));
drop_called.store(false, Ordering::Relaxed);
{
......@@ -99,7 +102,8 @@ fn test_compaction_filter() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let _snap = db.snapshot();
// Because ignore_snapshots is true, so all the keys will be compacted.
db.compact_range(Some(b"key1"), Some(b"key3"));
......
......@@ -640,7 +640,8 @@ fn test_delete_range_prefix_bloom_case_1() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -714,7 +715,8 @@ fn test_delete_range_prefix_bloom_case_2() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -769,7 +771,8 @@ fn test_delete_range_prefix_bloom_case_2() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -805,7 +808,8 @@ fn test_delete_range_prefix_bloom_case_3() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -849,7 +853,8 @@ fn test_delete_range_prefix_bloom_case_3() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -899,7 +904,8 @@ fn test_delete_range_prefix_bloom_case_4() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -943,7 +949,8 @@ fn test_delete_range_prefix_bloom_case_4() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -994,7 +1001,8 @@ fn test_delete_range_prefix_bloom_case_5() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -1036,7 +1044,8 @@ fn test_delete_range_prefix_bloom_case_5() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
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();
......@@ -1084,7 +1093,8 @@ fn test_delete_range_prefix_bloom_case_6() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -1128,7 +1138,8 @@ fn test_delete_range_prefix_bloom_case_6() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
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();
......@@ -1200,7 +1211,8 @@ fn test_delete_range_prefix_bloom_compact_case() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let cf = "default";
......@@ -1244,7 +1256,8 @@ fn test_delete_range_prefix_bloom_compact_case() {
.set_prefix_extractor(
"FixedSuffixSliceTransform",
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.
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();
......
......@@ -11,11 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use cases::test_ingest_external_file::gen_sst;
use rocksdb::*;
use std::sync::atomic::*;
use std::sync::Arc;
use tempdir::TempDir;
use test_ingest_external_file::gen_sst;
#[derive(Default, Clone)]
struct EventCounter {
......@@ -99,7 +99,8 @@ fn test_event_listener_basic() {
db.put(
format!("{:04}", i).as_bytes(),
format!("{:04}", i).as_bytes(),
).unwrap();
)
.unwrap();
}
db.flush(true).unwrap();
assert_ne!(counter.flush.load(Ordering::SeqCst), 0);
......@@ -108,7 +109,8 @@ fn test_event_listener_basic() {
db.put(
format!("{:04}", i).as_bytes(),
format!("{:04}", i).as_bytes(),
).unwrap();
)
.unwrap();
}
db.flush(true).unwrap();
let flush_cnt = counter.flush.load(Ordering::SeqCst);
......
......@@ -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> {
let mut result: Vec<u8> = Vec::with_capacity(operands.size_hint().0);
match existing_val {
Some(v) => for e in v {
result.push(*e)
},
Some(v) => {
for e in v {
result.push(*e)
}
}
None => (),
}
for op in operands {
......@@ -342,7 +344,8 @@ fn test_ingest_simulate_real_world() {
handle,
&ingest_opt,
&[gen_path.path().join(cf).to_str().unwrap()],
).unwrap();
)
.unwrap();
check_kv(
&db,
db.cf_handle(cf),
......@@ -369,7 +372,8 @@ fn test_ingest_simulate_real_world() {
handle,
&ingest_opt,
&[gen_path.path().join(cf).to_str().unwrap()],
).unwrap();
)
.unwrap();
check_kv(
&db,
db.cf_handle(cf),
......
......@@ -300,7 +300,8 @@ fn test_total_order_seek() {
.set_prefix_extractor(
"FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 }),
).unwrap();
)
.unwrap();
// also create prefix bloom for memtable
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
......@@ -311,7 +312,8 @@ fn test_total_order_seek() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let wopts = WriteOptions::new();
// sst1
......@@ -386,13 +388,15 @@ fn test_fixed_suffix_seek() {
.set_prefix_extractor(
"FixedSuffixTransform",
Box::new(FixedSuffixTransform { suffix_len: 2 }),
).unwrap();
)
.unwrap();
let db = DB::open_cf(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
db.put(b"k-eghe-5", b"a").unwrap();
db.put(b"k-24yfae-6", b"a").unwrap();
db.put(b"k-h1fwd-7", b"a").unwrap();
......
......@@ -27,7 +27,8 @@ fn test_metadata() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let cf_handle = db.cf_handle("default").unwrap();
let num_files = 5;
......@@ -80,7 +81,8 @@ fn test_compact_files() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let cf_handle = db.cf_handle("default").unwrap();
let cf_opts = db.get_options_cf(cf_handle);
......
......@@ -45,9 +45,11 @@ pub fn test_multithreaded() {
let j3 = thread::spawn(move || {
for _ in 1..N {
match db3.get(b"key") {
Ok(Some(v)) => if &v[..] != b"value1" && &v[..] != b"value2" {
assert!(false);
},
Ok(Some(v)) => {
if &v[..] != b"value1" && &v[..] != b"value2" {
assert!(false);
}
}
_ => {
assert!(false);
}
......
......@@ -62,14 +62,16 @@ fn test_prefix_extractor_compatibility() {
.set_prefix_extractor(
"FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 }),
).unwrap();
)
.unwrap();
// also create prefix bloom for memtable
cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let db = DB::open_cf(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let wopts = WriteOptions::new();
// sst2 with prefix bloom.
......
......@@ -36,7 +36,8 @@ fn test_set_num_levels() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
drop(db);
}
......@@ -74,14 +75,12 @@ fn test_enable_statistics() {
opts.enable_statistics(true);
opts.set_stats_dump_period_sec(60);
assert!(opts.get_statistics().is_some());
assert!(
opts.get_statistics_histogram(HistogramType::SeekMicros)
.is_some()
);
assert!(
opts.get_statistics_histogram_string(HistogramType::SeekMicros)
.is_some()
);
assert!(opts
.get_statistics_histogram(HistogramType::SeekMicros)
.is_some());
assert!(opts
.get_statistics_histogram_string(HistogramType::SeekMicros)
.is_some());
assert_eq!(
opts.get_statistics_ticker_count(TickerType::BlockCacheMiss),
0
......@@ -123,12 +122,14 @@ fn test_memtable_insert_hint_prefix_extractor() {
.set_memtable_insert_hint_prefix_extractor(
"FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 }),
).unwrap();
)
.unwrap();
let db = DB::open_cf(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let wopts = WriteOptions::new();
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() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......@@ -289,7 +291,8 @@ fn test_set_cache_index_and_filter_blocks_with_high_priority() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......@@ -304,7 +307,8 @@ fn test_pending_compaction_bytes_limit() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......@@ -337,7 +341,8 @@ fn test_set_optimize_filters_for_hits() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......@@ -356,7 +361,8 @@ fn test_get_block_cache_usage() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
for i in 0..200 {
db.put(format!("k_{}", i).as_bytes(), b"v").unwrap();
......@@ -383,7 +389,8 @@ fn test_block_cache_capacity() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
assert_eq!(
db.get_options().get_block_cache_capacity(),
......@@ -420,7 +427,8 @@ fn test_set_level_compaction_dynamic_level_bytes() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......@@ -476,7 +484,8 @@ fn test_set_compaction_pri() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......@@ -551,7 +560,8 @@ fn test_bottommost_compression() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
}
#[test]
......
......@@ -53,7 +53,8 @@ fn test_slice_transform() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let samples = vec![
(b"key_01".to_vec(), b"1".to_vec()),
(b"key_02".to_vec(), b"2".to_vec()),
......
......@@ -35,14 +35,12 @@ fn test_db_statistics() {
assert!(db.get_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!(
db.get_statistics_histogram_string(HistogramType::GetMicros)
.is_some()
);
assert!(
db.get_statistics_histogram(HistogramType::GetMicros)
.is_some()
);
assert!(db
.get_statistics_histogram_string(HistogramType::GetMicros)
.is_some());
assert!(db
.get_statistics_histogram(HistogramType::GetMicros)
.is_some());
let get_micros = db
.get_statistics_histogram(HistogramType::GetMicros)
......@@ -77,12 +75,10 @@ fn test_disable_db_statistics() {
db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit),
0
);
assert!(
db.get_statistics_histogram_string(HistogramType::GetMicros)
.is_none()
);
assert!(
db.get_statistics_histogram(HistogramType::GetMicros)
.is_none()
);
assert!(db
.get_statistics_histogram_string(HistogramType::GetMicros)
.is_none());
assert!(db
.get_statistics_histogram(HistogramType::GetMicros)
.is_none());
}
......@@ -84,11 +84,9 @@ impl ExampleCollector {
for (k, v) in props {
assert_eq!(v, props.get(k).unwrap());
}
assert!(
props
.get(&[Props::NumKeys as u8, Props::NumPuts as u8])
.is_none()
);
assert!(props
.get(&[Props::NumKeys as u8, Props::NumPuts as u8])
.is_none());
assert!(props.len() >= 4);
c
......@@ -176,7 +174,8 @@ fn test_table_properties_collector_factory() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
let samples = vec![
(b"key1".to_vec(), b"value1".to_vec()),
......@@ -249,7 +248,8 @@ fn test_table_properties_with_table_filter() {
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).unwrap();
)
.unwrap();
// Generate a sst with 4 entries.
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