Commit 5bddde53 authored by Huachao Huang's avatar Huachao Huang Committed by A. Hobden

*: reformat code (#208)

* *: reformat code

Just reformat code without other changes.

* travis: add cargo fmt

* travis: update rust version

* travis: use stable version
parent 2a150c32
...@@ -17,6 +17,11 @@ matrix: ...@@ -17,6 +17,11 @@ matrix:
include: include:
- os: osx - os: osx
rust: stable rust: stable
- rust: stable
install:
- rustup component add rustfmt-preview
before_script:
- cargo fmt --all -- --write-mode diff
script: script:
- cargo build - cargo build
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
extern crate cc; extern crate cc;
extern crate cmake; extern crate cmake;
use std::path::PathBuf;
use cc::Build; use cc::Build;
use std::{env, str};
use cmake::Config; use cmake::Config;
use std::path::PathBuf;
use std::{env, str};
fn main() { fn main() {
let mut build = build_rocksdb(); let mut build = build_rocksdb();
...@@ -40,7 +40,11 @@ fn link_cpp(build: &mut Build) { ...@@ -40,7 +40,11 @@ fn link_cpp(build: &mut Build) {
// Don't link to c++ statically on windows. // Don't link to c++ statically on windows.
return; return;
}; };
let output = tool.to_command().arg("--print-file-name").arg(stdlib).output().unwrap(); let output = tool.to_command()
.arg("--print-file-name")
.arg(stdlib)
.output()
.unwrap();
if !output.status.success() || output.stdout.is_empty() { if !output.status.success() || output.stdout.is_empty() {
// fallback to dynamically // fallback to dynamically
return; return;
...@@ -53,8 +57,14 @@ fn link_cpp(build: &mut Build) { ...@@ -53,8 +57,14 @@ fn link_cpp(build: &mut Build) {
return; return;
} }
// remove lib prefix and .a postfix. // remove lib prefix and .a postfix.
println!("cargo:rustc-link-lib=static={}", &stdlib[3..stdlib.len() - 2]); println!(
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display()); "cargo:rustc-link-lib=static={}",
&stdlib[3..stdlib.len() - 2]
);
println!(
"cargo:rustc-link-search=native={}",
path.parent().unwrap().display()
);
build.cpp_link_stdlib(None); build.cpp_link_stdlib(None);
} }
...@@ -71,12 +81,18 @@ fn build_rocksdb() -> Build { ...@@ -71,12 +81,18 @@ fn build_rocksdb() -> Build {
if cfg!(feature = "sse") { if cfg!(feature = "sse") {
cfg.define("FORCE_SSE42", "ON"); cfg.define("FORCE_SSE42", "ON");
} }
let dst = cfg.register_dep("Z").define("WITH_ZLIB", "ON") let dst = cfg.register_dep("Z")
.register_dep("BZIP2").define("WITH_BZ2", "ON") .define("WITH_ZLIB", "ON")
.register_dep("LZ4").define("WITH_LZ4", "ON") .register_dep("BZIP2")
.register_dep("ZSTD").define("WITH_ZSTD", "ON") .define("WITH_BZ2", "ON")
.register_dep("SNAPPY").define("WITH_SNAPPY", "ON") .register_dep("LZ4")
.build_target("rocksdb").build(); .define("WITH_LZ4", "ON")
.register_dep("ZSTD")
.define("WITH_ZSTD", "ON")
.register_dep("SNAPPY")
.define("WITH_SNAPPY", "ON")
.build_target("rocksdb")
.build();
let build_dir = format!("{}/build", dst.display()); let build_dir = format!("{}/build", dst.display());
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
let profile = match &*env::var("PROFILE").unwrap_or("debug".to_owned()) { let profile = match &*env::var("PROFILE").unwrap_or("debug".to_owned()) {
......
...@@ -541,7 +541,11 @@ extern "C" { ...@@ -541,7 +541,11 @@ extern "C" {
pub fn crocksdb_options_set_ratelimiter(options: *mut Options, limiter: *mut DBRateLimiter); pub fn crocksdb_options_set_ratelimiter(options: *mut Options, limiter: *mut DBRateLimiter);
pub fn crocksdb_options_set_info_log(options: *mut Options, logger: *mut DBLogger); pub fn crocksdb_options_set_info_log(options: *mut Options, logger: *mut DBLogger);
pub fn crocksdb_options_get_block_cache_usage(options: *const Options) -> usize; pub fn crocksdb_options_get_block_cache_usage(options: *const Options) -> usize;
pub fn crocksdb_options_set_block_cache_capacity(options: *const Options, capacity: usize, err: *mut *mut c_char); pub fn crocksdb_options_set_block_cache_capacity(
options: *const Options,
capacity: usize,
err: *mut *mut c_char,
);
pub fn crocksdb_options_get_block_cache_capacity(options: *const Options) -> usize; pub fn crocksdb_options_get_block_cache_capacity(options: *const Options) -> usize;
pub fn crocksdb_ratelimiter_create( pub fn crocksdb_ratelimiter_create(
rate_bytes_per_sec: i64, rate_bytes_per_sec: i64,
...@@ -1284,8 +1288,7 @@ extern "C" { ...@@ -1284,8 +1288,7 @@ extern "C" {
pub fn crocksdb_slicetransform_create( pub fn crocksdb_slicetransform_create(
state: *mut c_void, state: *mut c_void,
destructor: extern "C" fn(*mut c_void), destructor: extern "C" fn(*mut c_void),
transform: extern "C" fn(*mut c_void, *const u8, size_t, *mut size_t) transform: extern "C" fn(*mut c_void, *const u8, size_t, *mut size_t) -> *const u8,
-> *const u8,
in_domain: extern "C" fn(*mut c_void, *const u8, size_t) -> u8, in_domain: extern "C" fn(*mut c_void, *const u8, size_t) -> u8,
in_range: extern "C" fn(*mut c_void, *const u8, size_t) -> u8, in_range: extern "C" fn(*mut c_void, *const u8, size_t) -> u8,
name: extern "C" fn(*mut c_void) -> *const c_char, name: extern "C" fn(*mut c_void) -> *const c_char,
...@@ -1509,8 +1512,12 @@ extern "C" { ...@@ -1509,8 +1512,12 @@ extern "C" {
pub fn crocksdb_compactionjobinfo_output_level(info: *const DBCompactionJobInfo) -> c_int; pub fn crocksdb_compactionjobinfo_output_level(info: *const DBCompactionJobInfo) -> c_int;
pub fn crocksdb_compactionjobinfo_input_records(info: *const DBCompactionJobInfo) -> uint64_t; pub fn crocksdb_compactionjobinfo_input_records(info: *const DBCompactionJobInfo) -> uint64_t;
pub fn crocksdb_compactionjobinfo_output_records(info: *const DBCompactionJobInfo) -> uint64_t; pub fn crocksdb_compactionjobinfo_output_records(info: *const DBCompactionJobInfo) -> uint64_t;
pub fn crocksdb_compactionjobinfo_total_input_bytes(info: *const DBCompactionJobInfo) -> uint64_t; pub fn crocksdb_compactionjobinfo_total_input_bytes(
pub fn crocksdb_compactionjobinfo_total_output_bytes(info: *const DBCompactionJobInfo) -> uint64_t; info: *const DBCompactionJobInfo,
) -> uint64_t;
pub fn crocksdb_compactionjobinfo_total_output_bytes(
info: *const DBCompactionJobInfo,
) -> uint64_t;
pub fn crocksdb_externalfileingestioninfo_cf_name( pub fn crocksdb_externalfileingestioninfo_cf_name(
info: *const DBIngestionInfo, info: *const DBIngestionInfo,
...@@ -1626,8 +1633,8 @@ extern "C" { ...@@ -1626,8 +1633,8 @@ extern "C" {
mod test { mod test {
use super::*; use super::*;
use libc::{self, c_void}; use libc::{self, c_void};
use std::{fs, ptr, slice};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::{fs, ptr, slice};
use tempdir::TempDir; use tempdir::TempDir;
#[test] #[test]
......
...@@ -11,14 +11,13 @@ ...@@ -11,14 +11,13 @@
// 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 {TableProperties, TablePropertiesCollectionView};
use crocksdb_ffi::{self, DBCompactionJobInfo, DBEventListener, DBFlushJobInfo, DBIngestionInfo,
DBInstance};
use libc::c_void; use libc::c_void;
use std::{mem, slice, str};
use std::path::Path; use std::path::Path;
use std::{mem, slice, str};
use crocksdb_ffi::{self, DBCompactionJobInfo, DBEventListener, DBFlushJobInfo, DBIngestionInfo,
DBInstance};
use {TableProperties, TablePropertiesCollectionView};
macro_rules! fetch_str { macro_rules! fetch_str {
($func:ident($($arg:expr),*)) => ({ ($func:ident($($arg:expr),*)) => ({
......
...@@ -20,18 +20,18 @@ extern crate tempdir; ...@@ -20,18 +20,18 @@ extern crate tempdir;
#[macro_use] #[macro_use]
pub extern crate librocksdb_sys; pub extern crate librocksdb_sys;
mod compaction_filter;
pub mod comparator;
mod event_listener;
pub mod merge_operator;
mod metadata;
pub mod rocksdb; pub mod rocksdb;
pub mod rocksdb_options; pub mod rocksdb_options;
pub mod merge_operator;
pub mod comparator;
mod compaction_filter;
mod slice_transform; mod slice_transform;
mod table_filter;
mod table_properties; mod table_properties;
mod table_properties_collector; mod table_properties_collector;
mod table_properties_collector_factory; mod table_properties_collector_factory;
mod event_listener;
mod table_filter;
mod metadata;
pub use compaction_filter::CompactionFilter; pub use compaction_filter::CompactionFilter;
pub use event_listener::{CompactionJobInfo, EventListener, FlushJobInfo, IngestionInfo}; pub use event_listener::{CompactionJobInfo, EventListener, FlushJobInfo, IngestionInfo};
......
...@@ -110,9 +110,9 @@ fn custom_merge() { ...@@ -110,9 +110,9 @@ fn custom_merge() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use rocksdb::{BlockBasedOptions, ColumnFamilyOptions, DBCompressionType, DBOptions, DB};
use rocksdb::DBCompactionStyle; use rocksdb::DBCompactionStyle;
use rocksdb::DBRecoveryMode; use rocksdb::DBRecoveryMode;
use rocksdb::{BlockBasedOptions, ColumnFamilyOptions, DBCompressionType, DBOptions, DB};
#[allow(dead_code)] #[allow(dead_code)]
fn tuned_for_somebody_elses_disk( fn tuned_for_somebody_elses_disk(
......
...@@ -19,7 +19,6 @@ use std::mem; ...@@ -19,7 +19,6 @@ use std::mem;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
pub type MergeFn = fn(&[u8], Option<&[u8]>, &mut MergeOperands) -> Vec<u8>; pub type MergeFn = fn(&[u8], Option<&[u8]>, &mut MergeOperands) -> Vec<u8>;
pub struct MergeOperatorCallback { pub struct MergeOperatorCallback {
...@@ -96,7 +95,6 @@ pub extern "C" fn partial_merge_callback( ...@@ -96,7 +95,6 @@ pub extern "C" fn partial_merge_callback(
} }
} }
pub struct MergeOperands { pub struct MergeOperands {
operands_list: *const *const c_char, operands_list: *const *const c_char,
operands_list_len: *const size_t, operands_list_len: *const size_t,
......
...@@ -21,15 +21,15 @@ use rocksdb_options::{ColumnFamilyDescriptor, ColumnFamilyOptions, CompactOption ...@@ -21,15 +21,15 @@ use rocksdb_options::{ColumnFamilyDescriptor, ColumnFamilyOptions, CompactOption
CompactionOptions, DBOptions, EnvOptions, FlushOptions, HistogramData, CompactionOptions, DBOptions, EnvOptions, FlushOptions, HistogramData,
IngestExternalFileOptions, ReadOptions, RestoreOptions, UnsafeSnap, IngestExternalFileOptions, ReadOptions, RestoreOptions, UnsafeSnap,
WriteOptions}; WriteOptions};
use std::{fs, ptr, slice};
use std::collections::BTreeMap;
use std::collections::btree_map::Entry; use std::collections::btree_map::Entry;
use std::collections::BTreeMap;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::fmt::{self, Debug, Formatter}; use std::fmt::{self, Debug, Formatter};
use std::io; use std::io;
use std::ops::Deref; use std::ops::Deref;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::from_utf8; use std::str::from_utf8;
use std::{fs, ptr, slice};
use table_properties::TablePropertiesCollection; use table_properties::TablePropertiesCollection;
pub struct CFHandle { pub struct CFHandle {
...@@ -410,8 +410,7 @@ impl DB { ...@@ -410,8 +410,7 @@ impl DB {
const ERR_NULL_DB_ONINIT: &str = "Could not initialize database"; const ERR_NULL_DB_ONINIT: &str = "Could not initialize database";
const ERR_NULL_CF_HANDLE: &str = "Received null column family handle from DB"; const ERR_NULL_CF_HANDLE: &str = "Received null column family handle from DB";
let cpath = CString::new(path.as_bytes()) let cpath = CString::new(path.as_bytes()).map_err(|_| ERR_CONVERT_PATH.to_owned())?;
.map_err(|_| ERR_CONVERT_PATH.to_owned())?;
fs::create_dir_all(&Path::new(path)).map_err(|e| { fs::create_dir_all(&Path::new(path)).map_err(|e| {
format!( format!(
"Failed to create rocksdb directory: \ "Failed to create rocksdb directory: \
...@@ -514,11 +513,9 @@ impl DB { ...@@ -514,11 +513,9 @@ impl DB {
let cpath = match CString::new(path.as_bytes()) { let cpath = match CString::new(path.as_bytes()) {
Ok(c) => c, Ok(c) => c,
Err(_) => { Err(_) => {
return Err( return Err("Failed to convert path to CString when list \
"Failed to convert path to CString when list \
column families" column families"
.to_owned(), .to_owned())
)
} }
}; };
...@@ -631,9 +628,7 @@ impl DB { ...@@ -631,9 +628,7 @@ impl DB {
let cname = match CString::new(cfd.name.as_bytes()) { let cname = match CString::new(cfd.name.as_bytes()) {
Ok(c) => c, Ok(c) => c,
Err(_) => { Err(_) => {
return Err( return Err("Failed to convert path to CString when opening rocksdb".to_owned())
"Failed to convert path to CString when opening rocksdb".to_owned(),
)
} }
}; };
let cname_ptr = cname.as_ptr(); let cname_ptr = cname.as_ptr();
...@@ -1369,8 +1364,7 @@ impl DB { ...@@ -1369,8 +1364,7 @@ impl DB {
) -> Result<TablePropertiesCollection, String> { ) -> Result<TablePropertiesCollection, String> {
unsafe { unsafe {
let props = ffi_try!(crocksdb_get_properties_of_all_tables_cf( let props = ffi_try!(crocksdb_get_properties_of_all_tables_cf(
self.inner, self.inner, cf.inner
cf.inner
)); ));
Ok(TablePropertiesCollection::from_raw(props)) Ok(TablePropertiesCollection::from_raw(props))
} }
...@@ -1845,9 +1839,10 @@ impl SstFileWriter { ...@@ -1845,9 +1839,10 @@ impl SstFileWriter {
Ok(p) => p, Ok(p) => p,
}; };
unsafe { unsafe {
Ok(ffi_try!( Ok(ffi_try!(crocksdb_sstfilewriter_open(
crocksdb_sstfilewriter_open(self.inner, path.as_ptr()) self.inner,
)) path.as_ptr()
)))
} }
} }
......
...@@ -22,8 +22,8 @@ use crocksdb_ffi::{self, DBBlockBasedTableOptions, DBCompactOptions, DBCompactio ...@@ -22,8 +22,8 @@ use crocksdb_ffi::{self, DBBlockBasedTableOptions, DBCompactOptions, DBCompactio
Options}; Options};
use event_listener::{new_event_listener, EventListener}; use event_listener::{new_event_listener, EventListener};
use libc::{self, c_double, c_int, c_uchar, c_void, size_t}; use libc::{self, c_double, c_int, c_uchar, c_void, size_t};
use merge_operator::{self, full_merge_callback, partial_merge_callback, MergeOperatorCallback};
use merge_operator::MergeFn; use merge_operator::MergeFn;
use merge_operator::{self, full_merge_callback, partial_merge_callback, MergeOperatorCallback};
use rocksdb::Env; use rocksdb::Env;
use slice_transform::{new_slice_transform, SliceTransform}; use slice_transform::{new_slice_transform, SliceTransform};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
...@@ -119,8 +119,7 @@ impl BlockBasedOptions { ...@@ -119,8 +119,7 @@ impl BlockBasedOptions {
pub fn set_cache_index_and_filter_blocks(&mut self, v: bool) { pub fn set_cache_index_and_filter_blocks(&mut self, v: bool) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_block_based_options_set_cache_index_and_filter_blocks( crocksdb_ffi::crocksdb_block_based_options_set_cache_index_and_filter_blocks(
self.inner, self.inner, v as u8,
v as u8,
); );
} }
} }
...@@ -144,16 +143,15 @@ impl BlockBasedOptions { ...@@ -144,16 +143,15 @@ impl BlockBasedOptions {
pub fn set_pin_l0_filter_and_index_blocks_in_cache(&mut self, v: bool) { pub fn set_pin_l0_filter_and_index_blocks_in_cache(&mut self, v: bool) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache( crocksdb_ffi::crocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache(
self.inner, self.inner, v as u8,
v as u8); );
} }
} }
pub fn set_read_amp_bytes_per_bit(&mut self, v: u32) { pub fn set_read_amp_bytes_per_bit(&mut self, v: u32) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_block_based_options_set_read_amp_bytes_per_bit( crocksdb_ffi::crocksdb_block_based_options_set_read_amp_bytes_per_bit(
self.inner, self.inner, v as c_int,
v as c_int,
) )
} }
} }
...@@ -362,8 +360,7 @@ impl ReadOptions { ...@@ -362,8 +360,7 @@ impl ReadOptions {
pub fn set_background_purge_on_iterator_cleanup(&mut self, v: bool) { pub fn set_background_purge_on_iterator_cleanup(&mut self, v: bool) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_readoptions_set_background_purge_on_iterator_cleanup( crocksdb_ffi::crocksdb_readoptions_set_background_purge_on_iterator_cleanup(
self.inner, self.inner, v,
v,
); );
} }
} }
...@@ -647,8 +644,7 @@ impl DBOptions { ...@@ -647,8 +644,7 @@ impl DBOptions {
pub fn set_use_direct_io_for_flush_and_compaction(&mut self, v: bool) { pub fn set_use_direct_io_for_flush_and_compaction(&mut self, v: bool) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_options_set_use_direct_io_for_flush_and_compaction( crocksdb_ffi::crocksdb_options_set_use_direct_io_for_flush_and_compaction(
self.inner, self.inner, v,
v,
); );
} }
} }
...@@ -746,8 +742,7 @@ impl DBOptions { ...@@ -746,8 +742,7 @@ impl DBOptions {
) -> Option<String> { ) -> Option<String> {
unsafe { unsafe {
let value = crocksdb_ffi::crocksdb_options_statistics_get_histogram_string( let value = crocksdb_ffi::crocksdb_options_statistics_get_histogram_string(
self.inner, self.inner, hist_type,
hist_type,
); );
if value.is_null() { if value.is_null() {
...@@ -1151,7 +1146,9 @@ impl ColumnFamilyOptions { ...@@ -1151,7 +1146,9 @@ impl ColumnFamilyOptions {
pub fn set_max_bytes_for_level_multiplier(&mut self, mul: i32) { pub fn set_max_bytes_for_level_multiplier(&mut self, mul: i32) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_options_set_max_bytes_for_level_multiplier(self.inner, mul as f64); crocksdb_ffi::crocksdb_options_set_max_bytes_for_level_multiplier(
self.inner, mul as f64,
);
} }
} }
...@@ -1176,8 +1173,7 @@ impl ColumnFamilyOptions { ...@@ -1176,8 +1173,7 @@ impl ColumnFamilyOptions {
pub fn set_soft_pending_compaction_bytes_limit(&mut self, size: u64) { pub fn set_soft_pending_compaction_bytes_limit(&mut self, size: u64) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_options_set_soft_pending_compaction_bytes_limit( crocksdb_ffi::crocksdb_options_set_soft_pending_compaction_bytes_limit(
self.inner, self.inner, size,
size,
); );
} }
} }
...@@ -1191,8 +1187,7 @@ impl ColumnFamilyOptions { ...@@ -1191,8 +1187,7 @@ impl ColumnFamilyOptions {
pub fn set_hard_pending_compaction_bytes_limit(&mut self, size: u64) { pub fn set_hard_pending_compaction_bytes_limit(&mut self, size: u64) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_options_set_hard_pending_compaction_bytes_limit( crocksdb_ffi::crocksdb_options_set_hard_pending_compaction_bytes_limit(
self.inner, self.inner, size,
size,
); );
} }
} }
...@@ -1216,8 +1211,7 @@ impl ColumnFamilyOptions { ...@@ -1216,8 +1211,7 @@ impl ColumnFamilyOptions {
pub fn set_min_write_buffer_number_to_merge(&mut self, to_merge: c_int) { pub fn set_min_write_buffer_number_to_merge(&mut self, to_merge: c_int) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_options_set_min_write_buffer_number_to_merge( crocksdb_ffi::crocksdb_options_set_min_write_buffer_number_to_merge(
self.inner, self.inner, to_merge,
to_merge,
); );
} }
} }
...@@ -1342,8 +1336,7 @@ impl ColumnFamilyOptions { ...@@ -1342,8 +1336,7 @@ impl ColumnFamilyOptions {
}; };
let transform = new_slice_transform(c_name, transform)?; let transform = new_slice_transform(c_name, transform)?;
crocksdb_ffi::crocksdb_options_set_memtable_insert_with_hint_prefix_extractor( crocksdb_ffi::crocksdb_options_set_memtable_insert_with_hint_prefix_extractor(
self.inner, self.inner, transform,
transform,
); );
Ok(()) Ok(())
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
// 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 crocksdb_ffi::{self, DBSliceTransform}; use crocksdb_ffi::{self, DBSliceTransform};
use libc::{c_char, c_void, size_t}; use libc::{c_char, c_void, size_t};
use std::ffi::CString; use std::ffi::CString;
...@@ -85,7 +84,6 @@ extern "C" fn in_range(transform: *mut c_void, key: *const u8, key_len: size_t) ...@@ -85,7 +84,6 @@ extern "C" fn in_range(transform: *mut c_void, key: *const u8, key_len: size_t)
} }
} }
pub unsafe fn new_slice_transform( pub unsafe fn new_slice_transform(
c_name: CString, c_name: CString,
f: Box<SliceTransform>, f: Box<SliceTransform>,
......
...@@ -11,15 +11,13 @@ ...@@ -11,15 +11,13 @@
// 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 crocksdb_ffi::{self, DBTableProperties, DBTablePropertiesCollection, use crocksdb_ffi::{self, DBTableProperties, DBTablePropertiesCollection,
DBTablePropertiesCollectionIterator, DBTableProperty, DBTablePropertiesCollectionIterator, DBTableProperty,
DBUserCollectedProperties, DBUserCollectedPropertiesIterator}; DBUserCollectedProperties, DBUserCollectedPropertiesIterator};
use libc::size_t; use libc::size_t;
use std::{mem, slice, str};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::{Deref, Index}; use std::ops::{Deref, Index};
use std::{mem, slice, str};
pub struct TablePropertiesCollectionView(DBTablePropertiesCollection); pub struct TablePropertiesCollectionView(DBTablePropertiesCollection);
......
...@@ -4,20 +4,20 @@ extern crate rand; ...@@ -4,20 +4,20 @@ extern crate rand;
extern crate rocksdb; extern crate rocksdb;
extern crate tempdir; extern crate tempdir;
mod test_iterator;
mod test_multithreaded;
mod test_column_family; mod test_column_family;
mod test_compaction_filter;
mod test_compact_range; mod test_compact_range;
mod test_rocksdb_options; mod test_compaction_filter;
mod test_delete_files_in_range;
mod test_delete_range;
mod test_event_listener;
mod test_ingest_external_file; mod test_ingest_external_file;
mod test_slice_transform; mod test_iterator;
mod test_metadata;
mod test_multithreaded;
mod test_prefix_extractor; mod test_prefix_extractor;
mod test_rate_limiter;
mod test_read_only;
mod test_rocksdb_options;
mod test_slice_transform;
mod test_statistics; mod test_statistics;
mod test_table_properties; mod test_table_properties;
mod test_event_listener;
mod test_delete_range;
mod test_delete_files_in_range;
mod test_read_only;
mod test_rate_limiter;
mod test_metadata;
...@@ -11,10 +11,9 @@ ...@@ -11,10 +11,9 @@
// 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 rocksdb::{DBOptions, Range, Writable, DB, CompactOptions, ColumnFamilyOptions}; use rocksdb::{ColumnFamilyOptions, CompactOptions, DBOptions, Range, Writable, DB};
use tempdir::TempDir; use tempdir::TempDir;
#[test] #[test]
fn test_compact_range() { fn test_compact_range() {
let path = TempDir::new("_rust_rocksdb_test_compact_range").expect(""); let path = TempDir::new("_rust_rocksdb_test_compact_range").expect("");
...@@ -53,7 +52,11 @@ fn test_compact_range_change_level() { ...@@ -53,7 +52,11 @@ fn test_compact_range_change_level() {
opts.create_if_missing(true); opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.set_level_zero_file_num_compaction_trigger(10); cf_opts.set_level_zero_file_num_compaction_trigger(10);
let db = DB::open_cf(opts, path.path().to_str().unwrap(), vec![("default", cf_opts)]).unwrap(); let db = DB::open_cf(
opts,
path.path().to_str().unwrap(),
vec![("default", cf_opts)],
).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()),
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// limitations under the License. // limitations under the License.
use rocksdb::{ColumnFamilyOptions, CompactionFilter, DBOptions, Writable, DB}; use rocksdb::{ColumnFamilyOptions, CompactionFilter, DBOptions, Writable, DB};
use std::sync::{Arc, RwLock};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use tempdir::TempDir; use tempdir::TempDir;
struct Filter { struct Filter {
......
...@@ -512,7 +512,6 @@ fn test_delete_range_case_6() { ...@@ -512,7 +512,6 @@ fn test_delete_range_case_6() {
assert_eq!(before, after); assert_eq!(before, after);
} }
#[test] #[test]
fn test_delete_range_compact() { fn test_delete_range_compact() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_6").expect(""); let path = TempDir::new("_rust_rocksdb_test_delete_range_case_6").expect("");
...@@ -958,7 +957,6 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -958,7 +957,6 @@ fn test_delete_range_prefix_bloom_case_4() {
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();
let handle2 = get_cf_handle(&db2, cf).unwrap(); let handle2 = get_cf_handle(&db2, cf).unwrap();
let samples_b = vec![(b"keyd44444", b"value4"), (b"keye55555", b"value5")]; let samples_b = vec![(b"keyd44444", b"value4"), (b"keye55555", b"value5")];
for (k, v) in samples_b { for (k, v) in samples_b {
db2.put_cf(handle2, k, v).unwrap(); db2.put_cf(handle2, k, v).unwrap();
...@@ -991,7 +989,6 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -991,7 +989,6 @@ fn test_delete_range_prefix_bloom_case_4() {
assert_eq!(before, after); assert_eq!(before, after);
} }
#[test] #[test]
fn test_delete_range_prefix_bloom_case_5() { fn test_delete_range_prefix_bloom_case_5() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_5").expect(""); let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_5").expect("");
...@@ -1418,7 +1415,6 @@ fn test_delete_range_sst_files() { ...@@ -1418,7 +1415,6 @@ fn test_delete_range_sst_files() {
); );
} }
#[test] #[test]
fn test_delete_range_ingest_file() { fn test_delete_range_ingest_file() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_ingest_file").expect(""); let path = TempDir::new("_rust_rocksdb_test_delete_range_ingest_file").expect("");
......
...@@ -11,11 +11,9 @@ ...@@ -11,11 +11,9 @@
// 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 rocksdb::*; use rocksdb::*;
use std::sync::Arc;
use std::sync::atomic::*; use std::sync::atomic::*;
use std::sync::Arc;
use tempdir::TempDir; use tempdir::TempDir;
use test_ingest_external_file::gen_sst; use test_ingest_external_file::gen_sst;
...@@ -122,8 +120,8 @@ fn test_event_listener_basic() { ...@@ -122,8 +120,8 @@ fn test_event_listener_basic() {
drop(db); drop(db);
assert_eq!(counter.drop_count.load(Ordering::SeqCst), 1); assert_eq!(counter.drop_count.load(Ordering::SeqCst), 1);
assert!( assert!(
counter.input_records.load(Ordering::SeqCst) > counter.input_records.load(Ordering::SeqCst)
counter.output_records.load(Ordering::SeqCst) > counter.output_records.load(Ordering::SeqCst)
); );
assert!( assert!(
counter.input_bytes.load(Ordering::SeqCst) > counter.output_bytes.load(Ordering::SeqCst) counter.input_bytes.load(Ordering::SeqCst) > counter.output_bytes.load(Ordering::SeqCst)
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
// 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 rocksdb::*;
use rocksdb::rocksdb::Snapshot; use rocksdb::rocksdb::Snapshot;
use rocksdb::*;
use std::ops::Deref; use std::ops::Deref;
use std::sync::*; use std::sync::*;
use std::thread; use std::thread;
...@@ -306,15 +306,7 @@ fn test_total_order_seek() { ...@@ -306,15 +306,7 @@ fn test_total_order_seek() {
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 keys = vec![ let keys = vec![
b"k1-1", b"k1-1", b"k1-2", b"k1-3", b"k2-1", b"k2-2", b"k2-3", b"k3-1", b"k3-2", b"k3-3",
b"k1-2",
b"k1-3",
b"k2-1",
b"k2-2",
b"k2-3",
b"k3-1",
b"k3-2",
b"k3-3",
]; ];
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
......
...@@ -28,17 +28,22 @@ pub fn test_multithreaded() { ...@@ -28,17 +28,22 @@ pub fn test_multithreaded() {
db.put(b"key", b"value1").unwrap(); db.put(b"key", b"value1").unwrap();
let db1 = db.clone(); let db1 = db.clone();
let j1 = thread::spawn(move || for _ in 1..N { let j1 = thread::spawn(move || {
for _ in 1..N {
db1.put(b"key", b"value1").unwrap(); db1.put(b"key", b"value1").unwrap();
}
}); });
let db2 = db.clone(); let db2 = db.clone();
let j2 = thread::spawn(move || for _ in 1..N { let j2 = thread::spawn(move || {
for _ in 1..N {
db2.put(b"key", b"value2").unwrap(); db2.put(b"key", b"value2").unwrap();
}
}); });
let db3 = db.clone(); let db3 = db.clone();
let j3 = thread::spawn(move || for _ in 1..N { let j3 = thread::spawn(move || {
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);
...@@ -47,6 +52,7 @@ pub fn test_multithreaded() { ...@@ -47,6 +52,7 @@ pub fn test_multithreaded() {
assert!(false); assert!(false);
} }
} }
}
}); });
j1.join().unwrap(); j1.join().unwrap();
......
...@@ -32,15 +32,7 @@ impl SliceTransform for FixedPrefixTransform { ...@@ -32,15 +32,7 @@ impl SliceTransform for FixedPrefixTransform {
fn test_prefix_extractor_compatibility() { fn test_prefix_extractor_compatibility() {
let path = TempDir::new("_rust_rocksdb_prefix_extractor_compatibility").expect(""); let path = TempDir::new("_rust_rocksdb_prefix_extractor_compatibility").expect("");
let keys = vec![ let keys = vec![
b"k1-0", b"k1-0", b"k1-1", b"k1-2", b"k1-3", b"k1-4", b"k1-5", b"k1-6", b"k1-7", b"k1-8",
b"k1-1",
b"k1-2",
b"k1-3",
b"k1-4",
b"k1-5",
b"k1-6",
b"k1-7",
b"k1-8",
]; ];
// create db with no prefix extractor, and insert data // create db with no prefix extractor, and insert data
......
...@@ -43,7 +43,9 @@ fn test_rate_limiter() { ...@@ -43,7 +43,9 @@ fn test_rate_limiter() {
fn test_rate_limiter_sendable() { fn test_rate_limiter_sendable() {
let rate_limiter = RateLimiter::new(10 * 1024 * 1024, 100 * 1000, 10); let rate_limiter = RateLimiter::new(10 * 1024 * 1024, 100 * 1000, 10);
let handle = thread::spawn(move || { rate_limiter.request(1024, 0); }); let handle = thread::spawn(move || {
rate_limiter.request(1024, 0);
});
handle.join().unwrap(); handle.join().unwrap();
} }
...@@ -2,12 +2,12 @@ use rocksdb::{DBOptions, Writable, DB}; ...@@ -2,12 +2,12 @@ use rocksdb::{DBOptions, Writable, DB};
use tempdir::TempDir; use tempdir::TempDir;
macro_rules! check_kv { macro_rules! check_kv {
( $db:expr, $key:expr, $val:expr ) => { ($db:expr, $key:expr, $val:expr) => {
assert_eq!($db.get($key).unwrap().unwrap(), $val); assert_eq!($db.get($key).unwrap().unwrap(), $val);
}; };
( $db:expr, $cf:expr, $key:expr, $val:expr ) => { ($db:expr, $cf:expr, $key:expr, $val:expr) => {
assert_eq!($db.get_cf($cf, $key).unwrap().unwrap(), $val); assert_eq!($db.get_cf($cf, $key).unwrap().unwrap(), $val);
} };
} }
#[test] #[test]
......
...@@ -11,18 +11,17 @@ ...@@ -11,18 +11,17 @@
// 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 rocksdb::{BlockBasedOptions, ColumnFamilyOptions, CompactOptions, DBOptions,
FifoCompactionOptions, ReadOptions, SeekKey, SliceTransform, Writable, WriteOptions,
DB};
use rocksdb::crocksdb_ffi::{CompactionPriority, DBCompressionType, DBInfoLogLevel as InfoLogLevel, use rocksdb::crocksdb_ffi::{CompactionPriority, DBCompressionType, DBInfoLogLevel as InfoLogLevel,
DBStatisticsHistogramType as HistogramType, DBStatisticsHistogramType as HistogramType,
DBStatisticsTickerType as TickerType}; DBStatisticsTickerType as TickerType};
use rocksdb::{BlockBasedOptions, ColumnFamilyOptions, CompactOptions, DBOptions,
FifoCompactionOptions, ReadOptions, SeekKey, SliceTransform, Writable, WriteOptions,
DB};
use std::path::Path; use std::path::Path;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use tempdir::TempDir; use tempdir::TempDir;
#[test] #[test]
fn test_set_num_levels() { fn test_set_num_levels() {
let path = TempDir::new("_rust_rocksdb_test_set_num_levels").expect(""); let path = TempDir::new("_rust_rocksdb_test_set_num_levels").expect("");
......
...@@ -98,10 +98,7 @@ impl fmt::Display for ExampleCollector { ...@@ -98,10 +98,7 @@ impl fmt::Display for ExampleCollector {
write!( write!(
f, f,
"keys={}, puts={}, merges={}, deletes={}", "keys={}, puts={}, merges={}, deletes={}",
self.num_keys, self.num_keys, self.num_puts, self.num_merges, self.num_deletes
self.num_puts,
self.num_merges,
self.num_deletes
) )
} }
} }
......
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