diff --git a/.travis.yml b/.travis.yml index e87f39d..3632ba6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,12 @@ addons: apt: sources: - ubuntu-toolchain-r-test + - llvm-toolchain-trusty packages: - g++-5 + - llvm-3.9-dev + - libclang-3.9-dev + - clang-3.9 script: - cargo test --manifest-path=librocksdb-sys/Cargo.toml diff --git a/librocksdb-sys/Cargo.toml b/librocksdb-sys/Cargo.toml index 67d0460..4f5adc0 100644 --- a/librocksdb-sys/Cargo.toml +++ b/librocksdb-sys/Cargo.toml @@ -22,5 +22,6 @@ libc = "0.2" const-cstr = "0.2" [build-dependencies] -gcc = { version = "0.3", features = ["parallel"] } +cc = { version = "^1.0", features = ["parallel"] } make-cmd = "0.1" +bindgen = "0.29" diff --git a/librocksdb-sys/build.rs b/librocksdb-sys/build.rs index 2292b07..b0b2d10 100644 --- a/librocksdb-sys/build.rs +++ b/librocksdb-sys/build.rs @@ -1,6 +1,9 @@ -extern crate gcc; +extern crate cc; +extern crate bindgen; +use std::env; use std::fs; +use std::path::PathBuf; fn link(name: &str, bundled: bool) { use std::env::var; @@ -30,7 +33,19 @@ fn build_rocksdb() { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=rocksdb/"); - let mut config = gcc::Config::new(); + let bindings = bindgen::Builder::default() + .header("rocksdb/include/rocksdb/c.h") + .hide_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550 + .ctypes_prefix("libc") + .generate() + .expect("unable to generate rocksdb bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("unable to write rocksdb bindings"); + + let mut config = cc::Build::new(); config.include("rocksdb/include/"); config.include("rocksdb/"); config.include("rocksdb/third-party/gtest-1.7.0/fused-src/"); @@ -115,7 +130,7 @@ fn build_rocksdb() { } fn build_snappy() { - let mut config = gcc::Config::new(); + let mut config = cc::Build::new(); config.include("snappy/"); config.include("."); diff --git a/librocksdb-sys/src/lib.rs b/librocksdb-sys/src/lib.rs index 5c3999a..192e860 100644 --- a/librocksdb-sys/src/lib.rs +++ b/librocksdb-sys/src/lib.rs @@ -11,1022 +11,11 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// - -//! Raw bindings for RocksDB. -//! -//! This is simply a raw interface to the RocksDB C API. It is intended to underpin a higher-level library rather than for direct use. -#![allow(dead_code, non_camel_case_types, non_upper_case_globals, non_snake_case)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] extern crate libc; -#[cfg(test)] -mod test; - -use libc::*; - -extern "C" { - // Database operations - - pub fn rocksdb_open(options: *const rocksdb_options_t, - name: *const c_char, - errptr: *mut *mut c_char) - -> *mut rocksdb_t; - - pub fn rocksdb_open_for_read_only(options: *const rocksdb_options_t, - name: *const c_char, - error_if_log_file_exist: c_uchar, - errptr: *mut *mut c_char) - -> *mut rocksdb_t; - - pub fn rocksdb_backup_engine_open(options: *const rocksdb_options_t, - path: *const c_char, - errptr: *mut *mut c_char) - -> *mut rocksdb_backup_engine_t; - - pub fn rocksdb_backup_engine_create_new_backup(be: *mut rocksdb_backup_engine_t, - db: *mut rocksdb_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_backup_engine_purge_old_backups(be: *mut rocksdb_backup_engine_t, - num_backups_to_keep: uint32_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_restore_options_create() -> *mut rocksdb_restore_options_t; - - pub fn rocksdb_restore_options_destroy(opt: *mut rocksdb_restore_options_t); - - pub fn rocksdb_restore_options_set_keep_log_files(opt: *mut rocksdb_restore_options_t, - v: c_int); - - pub fn rocksdb_backup_engine_restore_db_from_latest_backup(be: *mut rocksdb_backup_engine_t, db_dir: *const c_char, wal_dir: *const c_char, restore_options: *const rocksdb_restore_options_t, errptr: *mut *mut c_char); - - pub fn rocksdb_backup_engine_get_backup_info(be: *mut rocksdb_backup_engine_t) - -> *const rocksdb_backup_engine_info_t; - - pub fn rocksdb_backup_engine_info_count(info: *const rocksdb_backup_engine_info_t) -> c_int; - - pub fn rocksdb_backup_engine_info_timestamp(info: *const rocksdb_backup_engine_info_t, - index: c_int) - -> int64_t; - - pub fn rocksdb_backup_engine_info_backup_id(info: *const rocksdb_backup_engine_info_t, - index: c_int) - -> uint32_t; - - pub fn rocksdb_backup_engine_info_size(info: *const rocksdb_backup_engine_info_t, - index: c_int) - -> uint64_t; - - pub fn rocksdb_backup_engine_info_number_files(info: *const rocksdb_backup_engine_info_t, - index: c_int) - -> uint32_t; - - pub fn rocksdb_backup_engine_info_destroy(info: *const rocksdb_backup_engine_info_t); - - pub fn rocksdb_backup_engine_close(be: *mut rocksdb_backup_engine_t); - - pub fn rocksdb_open_column_families(options: *const rocksdb_options_t, name: *const c_char, num_column_families: c_int, column_family_names: *const *const c_char, column_family_options: *const *const rocksdb_options_t, column_family_handles: *mut *mut rocksdb_column_family_handle_t, errptr: *mut *mut c_char) -> *mut rocksdb_t; - - pub fn rocksdb_open_for_read_only_column_families(options: *const rocksdb_options_t, name: *const c_char, num_column_families: c_int, column_family_names: *const *const c_char, column_family_options: *const *const rocksdb_options_t, column_family_handles: *mut *mut rocksdb_column_family_handle_t, error_if_log_file_exist: c_uchar, errptr: *mut *mut c_char) -> *mut rocksdb_t; - - pub fn rocksdb_list_column_families(options: *const rocksdb_options_t, - name: *const c_char, - lencf: *mut size_t, - errptr: *mut *mut c_char) - -> *mut *mut c_char; - - pub fn rocksdb_list_column_families_destroy(list: *mut *mut c_char, len: size_t); - - pub fn rocksdb_create_column_family(db: *mut rocksdb_t, - column_family_options: *const rocksdb_options_t, - column_family_name: *const c_char, - errptr: *mut *mut c_char) - -> *mut rocksdb_column_family_handle_t; - - pub fn rocksdb_drop_column_family(db: *mut rocksdb_t, - handle: *mut rocksdb_column_family_handle_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_column_family_handle_destroy(handle: *mut rocksdb_column_family_handle_t); - - pub fn rocksdb_close(db: *mut rocksdb_t); - - pub fn rocksdb_put(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - key: *const c_char, - keylen: size_t, - val: *const c_char, - vallen: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_put_cf(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - keylen: size_t, - val: *const c_char, - vallen: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_delete(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - key: *const c_char, - keylen: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_delete_cf(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - keylen: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_merge(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - key: *const c_char, - keylen: size_t, - val: *const c_char, - vallen: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_merge_cf(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - keylen: size_t, - val: *const c_char, - vallen: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_write(db: *mut rocksdb_t, - options: *const rocksdb_writeoptions_t, - batch: *mut rocksdb_writebatch_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_get(db: *mut rocksdb_t, - options: *const rocksdb_readoptions_t, - key: *const c_char, - keylen: size_t, - vallen: *mut size_t, - errptr: *mut *mut c_char) - -> *mut c_char; - - pub fn rocksdb_get_cf(db: *mut rocksdb_t, - options: *const rocksdb_readoptions_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - keylen: size_t, - vallen: *mut size_t, - errptr: *mut *mut c_char) - -> *mut c_char; - - pub fn rocksdb_multi_get(db: *mut rocksdb_t, - options: *const rocksdb_readoptions_t, - num_keys: size_t, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t, - values_list: *mut *mut c_char, - values_list_sizes: *mut size_t, - errs: *mut *mut c_char); - - pub fn rocksdb_multi_get_cf(db: *mut rocksdb_t, - options: *const rocksdb_readoptions_t, - column_families: *const *const rocksdb_column_family_handle_t, - num_keys: size_t, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t, - values_list: *mut *mut c_char, - values_list_sizes: *mut size_t, - errs: *mut *mut c_char); - - pub fn rocksdb_create_iterator(db: *mut rocksdb_t, - options: *const rocksdb_readoptions_t) - -> *mut rocksdb_iterator_t; - - pub fn rocksdb_create_iterator_cf(db: *mut rocksdb_t, - options: *const rocksdb_readoptions_t, - column_family: *mut rocksdb_column_family_handle_t) - -> *mut rocksdb_iterator_t; - - pub fn rocksdb_create_iterators(db: *mut rocksdb_t, - opts: *mut rocksdb_readoptions_t, - column_families: *mut *mut rocksdb_column_family_handle_t, - iterators: *mut *mut rocksdb_iterator_t, - size: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_create_snapshot(db: *mut rocksdb_t) -> *const rocksdb_snapshot_t; - - pub fn rocksdb_release_snapshot(db: *mut rocksdb_t, snapshot: *const rocksdb_snapshot_t); - - pub fn rocksdb_property_value(db: *mut rocksdb_t, propname: *const c_char) -> *mut c_char; - - pub fn rocksdb_property_value_cf(db: *mut rocksdb_t, - column_family: *mut rocksdb_column_family_handle_t, - propname: *const c_char) - -> *mut c_char; - - pub fn rocksdb_approximate_sizes(db: *mut rocksdb_t, - num_ranges: c_int, - range_start_key: *const *const c_char, - range_start_key_len: *const size_t, - range_limit_key: *const *const c_char, - range_limit_key_len: *const size_t, - sizes: *mut uint64_t); - - pub fn rocksdb_approximate_sizes_cf(db: *mut rocksdb_t, - column_family: *mut rocksdb_column_family_handle_t, - num_ranges: c_int, - range_start_key: *const *const c_char, - range_start_key_len: *const size_t, - range_limit_key: *const *const c_char, - range_limit_key_len: *const size_t, - sizes: *mut uint64_t); - - pub fn rocksdb_compact_range(db: *mut rocksdb_t, - start_key: *const c_char, - start_key_len: size_t, - limit_key: *const c_char, - limit_key_len: size_t); - - pub fn rocksdb_compact_range_cf(db: *mut rocksdb_t, - column_family: *mut rocksdb_column_family_handle_t, - start_key: *const c_char, - start_key_len: size_t, - limit_key: *const c_char, - limit_key_len: size_t); - - pub fn rocksdb_delete_file(db: *mut rocksdb_t, name: *const c_char); - - pub fn rocksdb_livefiles(db: *mut rocksdb_t) -> *const rocksdb_livefiles_t; - - pub fn rocksdb_flush(db: *mut rocksdb_t, - options: *const rocksdb_flushoptions_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_disable_file_deletions(db: *mut rocksdb_t, errptr: *mut *mut c_char); - - pub fn rocksdb_enable_file_deletions(db: *mut rocksdb_t, - force: c_uchar, - errptr: *mut *mut c_char); - - // Management operations - - pub fn rocksdb_destroy_db(options: *const rocksdb_options_t, - name: *const c_char, - errptr: *mut *mut c_char); - - pub fn rocksdb_repair_db(options: *const rocksdb_options_t, - name: *const c_char, - errptr: *mut *mut c_char); - - // Iterator - - pub fn rocksdb_iter_destroy(iterator: *mut rocksdb_iterator_t); - - pub fn rocksdb_iter_valid(iterator: *const rocksdb_iterator_t) -> c_uchar; - - pub fn rocksdb_iter_seek_to_first(iterator: *mut rocksdb_iterator_t); - - pub fn rocksdb_iter_seek_to_last(iterator: *mut rocksdb_iterator_t); - - pub fn rocksdb_iter_seek(iterator: *mut rocksdb_iterator_t, k: *const c_char, klen: size_t); - - pub fn rocksdb_iter_seek_for_prev(iterator: *mut rocksdb_iterator_t, k: *const c_char, klen: size_t); - - pub fn rocksdb_iter_next(iterator: *mut rocksdb_iterator_t); - - pub fn rocksdb_iter_prev(iterator: *mut rocksdb_iterator_t); - - pub fn rocksdb_iter_key(iterator: *const rocksdb_iterator_t, - klen: *mut size_t) - -> *const c_char; - - pub fn rocksdb_iter_value(iterator: *const rocksdb_iterator_t, - vlen: *mut size_t) - -> *const c_char; - - pub fn rocksdb_iter_get_error(iterator: *const rocksdb_iterator_t, errptr: *mut *mut c_char); - - // Write batch - - pub fn rocksdb_writebatch_create() -> *mut rocksdb_writebatch_t; - - pub fn rocksdb_writebatch_create_from(rep: *const c_char, - size: size_t) - -> *mut rocksdb_writebatch_t; - - pub fn rocksdb_writebatch_destroy(batch: *mut rocksdb_writebatch_t); - - pub fn rocksdb_writebatch_clear(batch: *mut rocksdb_writebatch_t); - - pub fn rocksdb_writebatch_count(batch: *mut rocksdb_writebatch_t) -> c_int; - - pub fn rocksdb_writebatch_put(batch: *mut rocksdb_writebatch_t, - key: *const c_char, - klen: size_t, - val: *const c_char, - vlen: size_t); - - pub fn rocksdb_writebatch_put_cf(batch: *mut rocksdb_writebatch_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - klen: size_t, - val: *const c_char, - vlen: size_t); - - pub fn rocksdb_writebatch_putv(b: *mut rocksdb_writebatch_t, - num_keys: c_int, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t, - num_values: c_int, - values_list: *const *const c_char, - values_list_sizes: *const size_t); - - pub fn rocksdb_writebatch_putv_cf(b: *mut rocksdb_writebatch_t, - column_family: *mut rocksdb_column_family_handle_t, - num_keys: c_int, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t, - num_values: c_int, - values_list: *const *const c_char, - values_list_sizes: *const size_t); - - pub fn rocksdb_writebatch_merge(batch: *mut rocksdb_writebatch_t, - key: *const c_char, - klen: size_t, - val: *const c_char, - vlen: size_t); - - pub fn rocksdb_writebatch_merge_cf(batch: *mut rocksdb_writebatch_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - klen: size_t, - val: *const c_char, - vlen: size_t); - - pub fn rocksdb_writebatch_mergev(b: *mut rocksdb_writebatch_t, - num_keys: c_int, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t, - num_values: c_int, - values_list: *const *const c_char, - values_list_sizes: *const size_t); - - pub fn rocksdb_writebatch_mergev_cf(b: *mut rocksdb_writebatch_t, - column_family: *mut rocksdb_column_family_handle_t, - num_keys: c_int, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t, - num_values: c_int, - values_list: *const *const c_char, - values_list_sizes: *const size_t); - - pub fn rocksdb_writebatch_delete(batch: *mut rocksdb_writebatch_t, - key: *const c_char, - klen: size_t); - - pub fn rocksdb_writebatch_delete_cf(batch: *mut rocksdb_writebatch_t, - column_family: *mut rocksdb_column_family_handle_t, - key: *const c_char, - klen: size_t); - - pub fn rocksdb_writebatch_deletev(b: *mut rocksdb_writebatch_t, - num_keys: c_int, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t); - - pub fn rocksdb_writebatch_deletev_cf(b: *mut rocksdb_writebatch_t, - column_family: *mut rocksdb_column_family_handle_t, - num_keys: c_int, - keys_list: *const *const c_char, - keys_list_sizes: *const size_t); - - pub fn rocksdb_writebatch_put_log_data(batch: *mut rocksdb_writebatch_t, - blob: *const c_char, - len: size_t); - - pub fn rocksdb_writebatch_iterate(batch: *mut rocksdb_writebatch_t, - state: *mut c_void, - put: Option, - deleted: Option); - - pub fn rocksdb_writebatch_data(batch: *mut rocksdb_writebatch_t, - size: *mut size_t) - -> *const c_char; - - // Block-based table options - - pub fn rocksdb_block_based_options_create() -> *mut rocksdb_block_based_table_options_t; - - pub fn rocksdb_block_based_options_destroy(options: *mut rocksdb_block_based_table_options_t); - - pub fn rocksdb_block_based_options_set_block_size(options: *mut rocksdb_block_based_table_options_t, v: size_t); - - pub fn rocksdb_block_based_options_set_block_size_deviation(options: *mut rocksdb_block_based_table_options_t, v: c_int); - - pub fn rocksdb_block_based_options_set_block_restart_interval(options: *mut rocksdb_block_based_table_options_t, v: c_int); - - pub fn rocksdb_block_based_options_set_filter_policy(options: *mut rocksdb_block_based_table_options_t, v: *mut rocksdb_filterpolicy_t); - - pub fn rocksdb_block_based_options_set_no_block_cache(options: *mut rocksdb_block_based_table_options_t, v: c_uchar); - - pub fn rocksdb_block_based_options_set_block_cache(options: *mut rocksdb_block_based_table_options_t, v: *mut rocksdb_cache_t); - - pub fn rocksdb_block_based_options_set_block_cache_compressed(options: *mut rocksdb_block_based_table_options_t, v: *mut rocksdb_cache_t); - - pub fn rocksdb_block_based_options_set_whole_key_filtering(options: *mut rocksdb_block_based_table_options_t, v: c_uchar); - - pub fn rocksdb_block_based_options_set_format_version(options: *mut rocksdb_block_based_table_options_t, v: c_int); - - pub fn rocksdb_block_based_options_set_index_type(options: *mut rocksdb_block_based_table_options_t, v: c_int); - - pub fn rocksdb_block_based_options_set_hash_index_allow_collision(options: *mut rocksdb_block_based_table_options_t, v: c_uchar); - - pub fn rocksdb_block_based_options_set_cache_index_and_filter_blocks(options: *mut rocksdb_block_based_table_options_t, v: c_uchar); - - pub fn rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache - (options: *mut rocksdb_block_based_table_options_t, - v: c_uchar); - - pub fn rocksdb_block_based_options_set_skip_table_builder_flush(options: *mut rocksdb_block_based_table_options_t, skip_table_builder_flush: c_uchar); - - pub fn rocksdb_options_set_block_based_table_factory(opt: *mut rocksdb_options_t, table_options: *mut rocksdb_block_based_table_options_t); - - // Cuckoo table options - - pub fn rocksdb_cuckoo_options_create() -> *mut rocksdb_cuckoo_table_options_t; - - pub fn rocksdb_cuckoo_options_destroy(options: *mut rocksdb_cuckoo_table_options_t); - - pub fn rocksdb_cuckoo_options_set_hash_ratio(options: *mut rocksdb_cuckoo_table_options_t, - v: f64); - - pub fn rocksdb_cuckoo_options_set_max_search_depth(options: *mut rocksdb_cuckoo_table_options_t, - v: uint32_t); - - pub fn rocksdb_cuckoo_options_set_cuckoo_block_size(options: *mut rocksdb_cuckoo_table_options_t, v: uint32_t); - - pub fn rocksdb_cuckoo_options_set_identity_as_first_hash(options: *mut rocksdb_cuckoo_table_options_t, v: c_uchar); - - pub fn rocksdb_cuckoo_options_set_use_module_hash(options: *mut rocksdb_cuckoo_table_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_cuckoo_table_factory(opt: *mut rocksdb_options_t, table_options: *mut rocksdb_cuckoo_table_options_t); - - // Options - - pub fn rocksdb_options_create() -> *mut rocksdb_options_t; - - pub fn rocksdb_options_destroy(opt: *mut rocksdb_options_t); - - pub fn rocksdb_options_increase_parallelism(opt: *mut rocksdb_options_t, - total_threads: c_int); - - pub fn rocksdb_options_optimize_for_point_lookup(opt: *mut rocksdb_options_t, - block_cache_size_mb: uint64_t); - - pub fn rocksdb_options_optimize_level_style_compaction(opt: *mut rocksdb_options_t, - memtable_memory_budget: uint64_t); - - pub fn rocksdb_options_optimize_universal_style_compaction(opt: *mut rocksdb_options_t, - memtable_memory_budget: uint64_t); - - pub fn rocksdb_options_set_compaction_filter(opt: *mut rocksdb_options_t, - filter: *mut rocksdb_compactionfilter_t); - - pub fn rocksdb_options_set_compaction_filter_factory(opt: *mut rocksdb_options_t, factory: *mut rocksdb_compactionfilterfactory_t); - - pub fn rocksdb_options_compaction_readahead_size(opt: *mut rocksdb_options_t, s: size_t); - - pub fn rocksdb_options_set_comparator(opt: *mut rocksdb_options_t, - cmp: *mut rocksdb_comparator_t); - - pub fn rocksdb_options_set_merge_operator(opt: *mut rocksdb_options_t, - merge_operator: *mut rocksdb_mergeoperator_t); - - pub fn rocksdb_options_set_uint64add_merge_operator(opt: *mut rocksdb_options_t); - - pub fn rocksdb_options_set_compression_per_level(opt: *mut rocksdb_options_t, - level_values: *const c_int, - num_levels: size_t); - - pub fn rocksdb_options_set_create_if_missing(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_create_missing_column_families(opt: *mut rocksdb_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_error_if_exists(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_paranoid_checks(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_env(opt: *mut rocksdb_options_t, env: *mut rocksdb_env_t); - - pub fn rocksdb_options_set_info_log(opt: *mut rocksdb_options_t, l: *mut rocksdb_logger_t); - - pub fn rocksdb_options_set_info_log_level(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_write_buffer_size(opt: *mut rocksdb_options_t, s: size_t); - - pub fn rocksdb_options_set_db_write_buffer_size(opt: *mut rocksdb_options_t, s: size_t); - - pub fn rocksdb_options_set_max_open_files(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_max_total_wal_size(opt: *mut rocksdb_options_t, n: uint64_t); - - pub fn rocksdb_options_set_compression_options(opt: *mut rocksdb_options_t, - w_bits: c_int, - level: c_int, - strategy: c_int, - max_dict_bytes: c_int); - - pub fn rocksdb_options_set_prefix_extractor(opt: *mut rocksdb_options_t, - prefix_extractor: *mut rocksdb_slicetransform_t); - - pub fn rocksdb_options_set_num_levels(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_level0_file_num_compaction_trigger(opt: *mut rocksdb_options_t, - n: c_int); - - pub fn rocksdb_options_set_level0_slowdown_writes_trigger(opt: *mut rocksdb_options_t, - n: c_int); - - pub fn rocksdb_options_set_level0_stop_writes_trigger(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_max_mem_compaction_level(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_target_file_size_base(opt: *mut rocksdb_options_t, n: uint64_t); - - pub fn rocksdb_options_set_target_file_size_multiplier(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_max_bytes_for_level_base(opt: *mut rocksdb_options_t, n: uint64_t); - - pub fn rocksdb_options_set_max_bytes_for_level_multiplier(opt: *mut rocksdb_options_t, - n: c_int); - - pub fn rocksdb_options_set_expanded_compaction_factor(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_max_grandparent_overlap_factor(opt: *mut rocksdb_options_t, - v: c_int); - - pub fn rocksdb_options_set_max_bytes_for_level_multiplier_additional(opt: *mut rocksdb_options_t, level_values: *mut c_int, num_levels: size_t); - - pub fn rocksdb_options_enable_statistics(opt: *mut rocksdb_options_t); - - pub fn rocksdb_options_statistics_get_string(opt: *mut rocksdb_options_t) -> *mut c_char; - - pub fn rocksdb_options_set_max_write_buffer_number(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_min_write_buffer_number_to_merge(opt: *mut rocksdb_options_t, - n: c_int); - - pub fn rocksdb_options_set_max_write_buffer_number_to_maintain(opt: *mut rocksdb_options_t, - n: c_int); - - pub fn rocksdb_options_set_max_background_compactions(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_max_background_flushes(opt: *mut rocksdb_options_t, n: c_int); - - pub fn rocksdb_options_set_max_log_file_size(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_log_file_time_to_roll(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_keep_log_file_num(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_recycle_log_file_num(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_soft_rate_limit(opt: *mut rocksdb_options_t, v: f64); - - pub fn rocksdb_options_set_hard_rate_limit(opt: *mut rocksdb_options_t, v: f64); - - pub fn rocksdb_options_set_rate_limit_delay_max_milliseconds(opt: *mut rocksdb_options_t, - v: c_uint); - - pub fn rocksdb_options_set_max_manifest_file_size(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_table_cache_numshardbits(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_table_cache_remove_scan_count_limit(opt: *mut rocksdb_options_t, - v: c_int); - - pub fn rocksdb_options_set_arena_block_size(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_use_fsync(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_db_log_dir(opt: *mut rocksdb_options_t, v: *const c_char); - - pub fn rocksdb_options_set_wal_dir(opt: *mut rocksdb_options_t, v: *const c_char); - - pub fn rocksdb_options_set_WAL_ttl_seconds(opt: *mut rocksdb_options_t, ttl: uint64_t); - - pub fn rocksdb_options_set_WAL_size_limit_MB(opt: *mut rocksdb_options_t, limit: uint64_t); - - pub fn rocksdb_options_set_manifest_preallocation_size(opt: *mut rocksdb_options_t, - v: size_t); - - pub fn rocksdb_options_set_purge_redundant_kvs_while_flush(opt: *mut rocksdb_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_use_direct_reads(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_use_direct_io_for_flush_and_compaction(opt: *mut rocksdb_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_allow_mmap_reads(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_allow_mmap_writes(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_is_fd_close_on_exec(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_skip_log_error_on_recovery(opt: *mut rocksdb_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_stats_dump_period_sec(opt: *mut rocksdb_options_t, v: c_uint); - - pub fn rocksdb_options_set_advise_random_on_open(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_access_hint_on_compaction_start(opt: *mut rocksdb_options_t, - v: c_int); - - pub fn rocksdb_options_set_use_adaptive_mutex(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_bytes_per_sync(opt: *mut rocksdb_options_t, v: uint64_t); - - pub fn rocksdb_options_set_allow_concurrent_memtable_write(opt: *mut rocksdb_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_verify_checksums_in_compaction(opt: *mut rocksdb_options_t, - v: c_uchar); - - pub fn rocksdb_options_set_filter_deletes(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_max_sequential_skip_in_iterations(opt: *mut rocksdb_options_t, - v: uint64_t); - - pub fn rocksdb_options_set_disable_auto_compactions(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_delete_obsolete_files_period_micros(opt: *mut rocksdb_options_t, - v: uint64_t); - - pub fn rocksdb_options_set_source_compaction_factor(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_prepare_for_bulk_load(opt: *mut rocksdb_options_t); - - pub fn rocksdb_options_set_memtable_vector_rep(opt: *mut rocksdb_options_t); - - pub fn rocksdb_options_set_hash_skip_list_rep(opt: *mut rocksdb_options_t, - bucket_count: size_t, - skiplist_height: int32_t, - skiplist_branching_factor: int32_t); - - pub fn rocksdb_options_set_hash_link_list_rep(opt: *mut rocksdb_options_t, - bucket_count: size_t); - - pub fn rocksdb_options_set_plain_table_factory(opt: *mut rocksdb_options_t, - user_key_len: uint32_t, - bloom_bits_per_key: c_int, - hash_table_ratio: f64, - index_sparseness: size_t); - - pub fn rocksdb_options_set_min_level_to_compress(opt: *mut rocksdb_options_t, level: c_int); - - pub fn rocksdb_options_set_memtable_prefix_bloom_bits(opt: *mut rocksdb_options_t, - v: uint32_t); - - pub fn rocksdb_options_set_memtable_prefix_bloom_probes(opt: *mut rocksdb_options_t, - v: uint32_t); - - pub fn rocksdb_options_set_memtable_huge_page_size(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_max_successive_merges(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_min_partial_merge_operands(opt: *mut rocksdb_options_t, - v: uint32_t); - - pub fn rocksdb_options_set_bloom_locality(opt: *mut rocksdb_options_t, v: uint32_t); - - pub fn rocksdb_options_set_inplace_update_support(opt: *mut rocksdb_options_t, v: c_uchar); - - pub fn rocksdb_options_set_inplace_update_num_locks(opt: *mut rocksdb_options_t, v: size_t); - - pub fn rocksdb_options_set_report_bg_io_stats(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_wal_recovery_mode(opt: *mut rocksdb_options_t, v: c_int); - - pub fn rocksdb_options_set_compression(opt: *mut rocksdb_options_t, t: c_int); - - pub fn rocksdb_options_set_compaction_style(opt: *mut rocksdb_options_t, style: c_int); - - pub fn rocksdb_options_set_universal_compaction_options(opt: *mut rocksdb_options_t, uco: *mut rocksdb_universal_compaction_options_t); - - pub fn rocksdb_options_set_fifo_compaction_options(opt: *mut rocksdb_options_t, - fifo: *mut rocksdb_fifo_compaction_options_t); - - // Compaction filter - - pub fn rocksdb_compactionfilter_create - (state: *mut c_void, - destructor: Option, - filter: Option c_uchar>, - name: Option *const c_char>) - -> *mut rocksdb_compactionfilter_t; - - pub fn rocksdb_compactionfilter_set_ignore_snapshots(filter: *mut rocksdb_compactionfilter_t, - v: c_uchar); - - pub fn rocksdb_compactionfilter_destroy(filter: *mut rocksdb_compactionfilter_t); - - // Compaction Filter context - - pub fn rocksdb_compactionfiltercontext_is_full_compaction(context: *mut rocksdb_compactionfiltercontext_t) -> c_uchar; - - pub fn rocksdb_compactionfiltercontext_is_manual_compaction(context: *mut rocksdb_compactionfiltercontext_t) -> c_uchar; - - // Compaction Filter factory - - pub fn rocksdb_compactionfilterfactory_create(state: *mut c_void, destructor: Option, create_compaction_filter: Option *mut rocksdb_compactionfilter_t>, name: Option *const c_char>) -> *mut rocksdb_compactionfilterfactory_t; - - pub fn rocksdb_compactionfilterfactory_destroy(factory: *mut rocksdb_compactionfilterfactory_t); - - // Comparator - - pub fn rocksdb_comparator_create(state: *mut c_void, - destructor: Option, - compare: Option c_int>, - name: Option *const c_char>) - -> *mut rocksdb_comparator_t; - - pub fn rocksdb_comparator_destroy(cmp: *mut rocksdb_comparator_t); - - // Filter policy - - pub fn rocksdb_filterpolicy_create(state: *mut c_void, destructor: Option, create_filter: Option *mut c_char>, key_may_match: Option c_uchar>, delete_filter: Option, name: Option *const c_char>) -> *mut rocksdb_filterpolicy_t; - - pub fn rocksdb_filterpolicy_destroy(filter: *mut rocksdb_filterpolicy_t); - - pub fn rocksdb_filterpolicy_create_bloom(bits_per_key: c_int) -> *mut rocksdb_filterpolicy_t; - - pub fn rocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) -> *mut rocksdb_filterpolicy_t; - - // Merge Operator - - pub fn rocksdb_mergeoperator_create(state: *mut c_void, destructor: Option, full_merge: Option *mut c_char>, partial_merge: Option *mut c_char>, delete_value: Option, name: Option *const c_char>) -> *mut rocksdb_mergeoperator_t; - - pub fn rocksdb_mergeoperator_destroy(merge_operator: *mut rocksdb_mergeoperator_t); - - // Read options - - pub fn rocksdb_readoptions_create() -> *mut rocksdb_readoptions_t; - - pub fn rocksdb_readoptions_destroy(opt: *mut rocksdb_readoptions_t); - - pub fn rocksdb_readoptions_set_verify_checksums(opt: *mut rocksdb_readoptions_t, v: c_uchar); - - pub fn rocksdb_readoptions_set_fill_cache(opt: *mut rocksdb_readoptions_t, v: c_uchar); - - pub fn rocksdb_readoptions_set_snapshot(opt: *mut rocksdb_readoptions_t, - v: *const rocksdb_snapshot_t); - - pub fn rocksdb_readoptions_set_iterate_upper_bound(opt: *mut rocksdb_readoptions_t, - key: *const c_char, - keylen: size_t); - - pub fn rocksdb_readoptions_set_read_tier(opt: *mut rocksdb_readoptions_t, v: c_int); - - pub fn rocksdb_readoptions_set_tailing(opt: *mut rocksdb_readoptions_t, v: c_uchar); - - pub fn rocksdb_readoptions_set_readahead_size(opt: *mut rocksdb_readoptions_t, v: size_t); - - // Write options - - pub fn rocksdb_writeoptions_create() -> *mut rocksdb_writeoptions_t; - - pub fn rocksdb_writeoptions_destroy(opt: *mut rocksdb_writeoptions_t); - - pub fn rocksdb_writeoptions_set_sync(opt: *mut rocksdb_writeoptions_t, v: c_uchar); - - pub fn rocksdb_writeoptions_disable_WAL(opt: *mut rocksdb_writeoptions_t, disable: c_int); - - // Flush options - - pub fn rocksdb_flushoptions_create() -> *mut rocksdb_flushoptions_t; - - pub fn rocksdb_flushoptions_destroy(opt: *mut rocksdb_flushoptions_t); - - pub fn rocksdb_flushoptions_set_wait(opt: *mut rocksdb_flushoptions_t, v: c_uchar); - - // Cache - - pub fn rocksdb_cache_create_lru(capacity: size_t) -> *mut rocksdb_cache_t; - - pub fn rocksdb_cache_destroy(cache: *mut rocksdb_cache_t); - - pub fn rocksdb_cache_set_capacity(cache: *mut rocksdb_cache_t, capacity: size_t); - - // Environment - - pub fn rocksdb_create_default_env() -> *mut rocksdb_env_t; - - pub fn rocksdb_create_mem_env() -> *mut rocksdb_env_t; - - pub fn rocksdb_env_set_background_threads(env: *mut rocksdb_env_t, n: c_int); - - pub fn rocksdb_env_set_high_priority_background_threads(env: *mut rocksdb_env_t, n: c_int); - - pub fn rocksdb_env_join_all_threads(env: *mut rocksdb_env_t); - - pub fn rocksdb_env_destroy(env: *mut rocksdb_env_t); - - // Slice Transform - - pub fn rocksdb_slicetransform_create(state: *mut c_void, destructor: Option, transform: Option *mut c_char>, in_domain: Option c_uchar>, in_range: Option c_uchar>, name: Option *const c_char>) -> *mut rocksdb_slicetransform_t; - - pub fn rocksdb_slicetransform_create_fixed_prefix(len: size_t) -> *mut rocksdb_slicetransform_t; - - pub fn rocksdb_slicetransform_create_noop() -> *mut rocksdb_slicetransform_t; - - pub fn rocksdb_slicetransform_destroy(st: *mut rocksdb_slicetransform_t); - - // Universal Compaction options - - pub fn rocksdb_universal_compaction_options_create - () - -> *mut rocksdb_universal_compaction_options_t; - - pub fn rocksdb_universal_compaction_options_set_size_ratio(uco: *mut rocksdb_universal_compaction_options_t, ratio: c_int); - - pub fn rocksdb_universal_compaction_options_set_min_merge_width(uco: *mut rocksdb_universal_compaction_options_t, w: c_int); - - pub fn rocksdb_universal_compaction_options_set_max_merge_width(uco: *mut rocksdb_universal_compaction_options_t, w: c_int); - - pub fn rocksdb_universal_compaction_options_set_max_size_amplification_percent - (uco: *mut rocksdb_universal_compaction_options_t, - p: c_int); - - pub fn rocksdb_universal_compaction_options_set_compression_size_percent - (uco: *mut rocksdb_universal_compaction_options_t, - p: c_int); - - pub fn rocksdb_universal_compaction_options_set_stop_style(uco: *mut rocksdb_universal_compaction_options_t, style: c_int); - - pub fn rocksdb_universal_compaction_options_destroy(uco: *mut rocksdb_universal_compaction_options_t); - - pub fn rocksdb_fifo_compaction_options_create() -> *mut rocksdb_fifo_compaction_options_t; - - pub fn rocksdb_fifo_compaction_options_set_max_table_files_size(fifo_opts: *mut rocksdb_fifo_compaction_options_t, size: uint64_t); - - pub fn rocksdb_fifo_compaction_options_destroy(fifo_opts: *mut rocksdb_fifo_compaction_options_t); - - pub fn rocksdb_livefiles_count(files: *const rocksdb_livefiles_t) -> c_int; - - pub fn rocksdb_livefiles_name(files: *const rocksdb_livefiles_t, - index: c_int) - -> *const c_char; - - pub fn rocksdb_livefiles_level(files: *const rocksdb_livefiles_t, index: c_int) -> c_int; - - pub fn rocksdb_livefiles_size(files: *const rocksdb_livefiles_t, index: c_int) -> size_t; - - pub fn rocksdb_livefiles_smallestkey(files: *const rocksdb_livefiles_t, - index: c_int, - size: *mut size_t) - -> *const c_char; - - pub fn rocksdb_livefiles_largestkey(files: *const rocksdb_livefiles_t, - index: c_int, - size: *mut size_t) - -> *const c_char; - - pub fn rocksdb_livefiles_destroy(files: *const rocksdb_livefiles_t); - - // Utilities - - pub fn rocksdb_get_options_from_string(base_options: *const rocksdb_options_t, - opts_str: *const c_char, - new_options: *mut rocksdb_options_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_delete_file_in_range(db: *mut rocksdb_t, - start_key: *const c_char, - start_key_len: size_t, - limit_key: *const c_char, - limit_key_len: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_delete_file_in_range_cf(db: *mut rocksdb_t, - column_family: *mut rocksdb_column_family_handle_t, - start_key: *const c_char, - start_key_len: size_t, - limit_key: *const c_char, - limit_key_len: size_t, - errptr: *mut *mut c_char); - - pub fn rocksdb_free(ptr: *mut c_void); -} - -pub const rocksdb_block_based_table_index_type_binary_search: c_int = 0; -pub const rocksdb_block_based_table_index_type_hash_search: c_int = 1; - -pub const rocksdb_no_compression: c_int = 0; -pub const rocksdb_snappy_compression: c_int = 1; -pub const rocksdb_zlib_compression: c_int = 2; -pub const rocksdb_bz2_compression: c_int = 3; -pub const rocksdb_lz4_compression: c_int = 4; -pub const rocksdb_lz4hc_compression: c_int = 5; - -pub const rocksdb_level_compaction: c_int = 0; -pub const rocksdb_universal_compaction: c_int = 1; -pub const rocksdb_fifo_compaction: c_int = 2; - -pub const rocksdb_similar_size_compaction_stop_style: c_int = 0; -pub const rocksdb_total_size_compaction_stop_style: c_int = 1; - -pub const rocksdb_recovery_mode_tolerate_corrupted_tail_records: c_int = 0; -pub const rocksdb_recovery_mode_absolute_consistency: c_int = 1; -pub const rocksdb_recovery_mode_point_in_time: c_int = 2; -pub const rocksdb_recovery_mode_skip_any_corrupted_record: c_int = 3; - -pub enum rocksdb_t { } - -pub enum rocksdb_backup_engine_t { } - -pub enum rocksdb_backup_engine_info_t { } - -pub enum rocksdb_restore_options_t { } - -pub enum rocksdb_cache_t { } - -pub enum rocksdb_compactionfilter_t { } - -pub enum rocksdb_compactionfiltercontext_t { } - -pub enum rocksdb_compactionfilterfactory_t { } - -pub enum rocksdb_comparator_t { } - -pub enum rocksdb_env_t { } - -pub enum rocksdb_fifo_compaction_options_t { } - -pub enum rocksdb_filelock_t { } - -pub enum rocksdb_filterpolicy_t { } - -pub enum rocksdb_flushoptions_t { } - -pub enum rocksdb_iterator_t { } - -pub enum rocksdb_logger_t { } - -pub enum rocksdb_mergeoperator_t { } - -pub enum rocksdb_options_t { } - -pub enum rocksdb_block_based_table_options_t { } - -pub enum rocksdb_cuckoo_table_options_t { } - -pub enum rocksdb_randomfile_t { } - -pub enum rocksdb_readoptions_t { } - -pub enum rocksdb_seqfile_t { } - -pub enum rocksdb_slicetransform_t { } - -pub enum rocksdb_snapshot_t { } - -pub enum rocksdb_writablefile_t { } - -pub enum rocksdb_writebatch_t { } - -pub enum rocksdb_writeoptions_t { } - -pub enum rocksdb_universal_compaction_options_t { } - -pub enum rocksdb_livefiles_t { } - -pub enum rocksdb_column_family_handle_t { } +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/librocksdb-sys/tests/ffi.rs b/librocksdb-sys/tests/ffi.rs index d230322..e5face9 100644 --- a/librocksdb-sys/tests/ffi.rs +++ b/librocksdb-sys/tests/ffi.rs @@ -429,7 +429,7 @@ fn ffi() { rocksdb_options_set_block_based_table_factory(options, table_options); let no_compression = rocksdb_no_compression; - rocksdb_options_set_compression(options, no_compression); + rocksdb_options_set_compression(options, no_compression as i32); rocksdb_options_set_compression_options(options, -14, -1, 0, 0); let compression_levels = vec![ no_compression, @@ -892,15 +892,15 @@ fn ffi() { let mut cf_options = rocksdb_options_create(); - let cf_names: [*const c_char; 2] = [cstrp!("default"), cstrp!("cf1")]; - let cf_opts: [*const rocksdb_options_t; 2] = [cf_options, cf_options]; + let mut cf_names: [*const c_char; 2] = [cstrp!("default"), cstrp!("cf1")]; + let mut cf_opts: [*const rocksdb_options_t; 2] = [cf_options, cf_options]; let mut handles: [*mut rocksdb_column_family_handle_t; 2] = [ptr::null_mut(), ptr::null_mut()]; db = rocksdb_open_column_families(db_options, dbname, 2, - cf_names.as_ptr(), - cf_opts.as_ptr(), + cf_names.as_mut_ptr(), + cf_opts.as_mut_ptr(), handles.as_mut_ptr(), &mut err); CheckNoError!(err); diff --git a/rustfmt.toml b/rustfmt.toml index 2e81e37..6582e8c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ reorder_imports = true max_width = 100 ideal_width = 100 +trailing_comma = always diff --git a/src/backup.rs b/src/backup.rs index ab99cb8..9319f4d 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -35,21 +35,24 @@ pub struct RestoreOptions { impl BackupEngine { /// Open a backup engine with the specified options. - pub fn open>(opts: &BackupEngineOptions, - path: P) - -> Result { + pub fn open>( + opts: &BackupEngineOptions, + path: P, + ) -> Result { let path = path.as_ref(); let cpath = match CString::new(path.to_string_lossy().as_bytes()) { Ok(c) => c, Err(_) => { - return Err(Error::new("Failed to convert path to CString \ + return Err(Error::new( + "Failed to convert path to CString \ when opening backup engine" - .to_owned())) + .to_owned(), + )) } }; let be: *mut ffi::rocksdb_backup_engine_t; - unsafe { be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr())) } + unsafe { be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr(),)) } if be.is_null() { return Err(Error::new("Could not initialize backup engine.".to_owned())); @@ -60,15 +63,20 @@ impl BackupEngine { pub fn create_new_backup(&mut self, db: &DB) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_backup_engine_create_new_backup(self.inner, db.inner)); + ffi_try!(ffi::rocksdb_backup_engine_create_new_backup( + self.inner, + db.inner, + )); Ok(()) } } pub fn purge_old_backups(&mut self, num_backups_to_keep: usize) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_backup_engine_purge_old_backups(self.inner, - num_backups_to_keep as uint32_t)); + ffi_try!(ffi::rocksdb_backup_engine_purge_old_backups( + self.inner, + num_backups_to_keep as uint32_t, + )); Ok(()) } } diff --git a/src/compaction_filter.rs b/src/compaction_filter.rs index efdbf89..b846699 100644 --- a/src/compaction_filter.rs +++ b/src/compaction_filter.rs @@ -43,42 +43,48 @@ pub enum Decision { /// [set_compaction_filter]: ../struct.Options.html#method.set_compaction_filter pub trait CompactionFilterFn: FnMut(u32, &[u8], &[u8]) -> Decision {} impl CompactionFilterFn for F - where F: FnMut(u32, &[u8], &[u8]) -> Decision, - F: Send + 'static +where + F: FnMut(u32, &[u8], &[u8]) -> Decision, + F: Send + 'static, { } pub struct CompactionFilterCallback - where F: CompactionFilterFn +where + F: CompactionFilterFn, { pub name: CString, pub filter_fn: F, } pub unsafe extern "C" fn destructor_callback(raw_cb: *mut c_void) - where F: CompactionFilterFn +where + F: CompactionFilterFn, { let _: Box> = mem::transmute(raw_cb); } pub unsafe extern "C" fn name_callback(raw_cb: *mut c_void) -> *const c_char - where F: CompactionFilterFn +where + F: CompactionFilterFn, { let cb = &*(raw_cb as *mut CompactionFilterCallback); cb.name.as_ptr() } -pub unsafe extern "C" fn filter_callback(raw_cb: *mut c_void, - level: c_int, - raw_key: *const c_char, - key_length: size_t, - existing_value: *const c_char, - value_length: size_t, - new_value: *mut *mut c_char, - new_value_length: *mut size_t, - value_changed: *mut c_uchar) - -> c_uchar - where F: CompactionFilterFn +pub unsafe extern "C" fn filter_callback( + raw_cb: *mut c_void, + level: c_int, + raw_key: *const c_char, + key_length: size_t, + existing_value: *const c_char, + value_length: size_t, + new_value: *mut *mut c_char, + new_value_length: *mut size_t, + value_changed: *mut c_uchar, +) -> c_uchar +where + F: CompactionFilterFn, { use self::Decision::*; diff --git a/src/comparator.rs b/src/comparator.rs index d75bb7b..459a47c 100644 --- a/src/comparator.rs +++ b/src/comparator.rs @@ -37,12 +37,13 @@ pub unsafe extern "C" fn name_callback(raw_cb: *mut c_void) -> *const c_char { ptr as *const c_char } -pub unsafe extern "C" fn compare_callback(raw_cb: *mut c_void, - a_raw: *const c_char, - a_len: size_t, - b_raw: *const c_char, - b_len: size_t) - -> c_int { +pub unsafe extern "C" fn compare_callback( + raw_cb: *mut c_void, + a_raw: *const c_char, + a_len: size_t, + b_raw: *const c_char, + b_len: size_t, +) -> c_int { let cb: &mut ComparatorCallback = &mut *(raw_cb as *mut ComparatorCallback); let a: &[u8] = slice::from_raw_parts(a_raw as *const u8, a_len as usize); let b: &[u8] = slice::from_raw_parts(b_raw as *const u8, b_len as usize); diff --git a/src/db.rs b/src/db.rs index d73ff63..256f12f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -55,10 +55,10 @@ pub enum DBCompactionStyle { #[derive(Debug, Copy, Clone, PartialEq)] pub enum DBRecoveryMode { - TolerateCorruptedTailRecords = ffi::rocksdb_recovery_mode_tolerate_corrupted_tail_records as isize, - AbsoluteConsistency = ffi::rocksdb_recovery_mode_absolute_consistency as isize, - PointInTime = ffi::rocksdb_recovery_mode_point_in_time as isize, - SkipAnyCorruptedRecord = ffi::rocksdb_recovery_mode_skip_any_corrupted_record as isize, + TolerateCorruptedTailRecords = ffi::rocksdb_tolerate_corrupted_tail_records_recovery as isize, + AbsoluteConsistency = ffi::rocksdb_absolute_consistency_recovery as isize, + PointInTime = ffi::rocksdb_point_in_time_recovery as isize, + SkipAnyCorruptedRecord = ffi::rocksdb_skip_any_corrupted_records_recovery as isize, } /// An atomic batch of write operations. @@ -197,17 +197,14 @@ pub enum IteratorMode<'a> { impl DBRawIterator { fn new(db: &DB, readopts: &ReadOptions) -> DBRawIterator { - unsafe { - DBRawIterator { - inner: ffi::rocksdb_create_iterator(db.inner, readopts.inner), - } - } + unsafe { DBRawIterator { inner: ffi::rocksdb_create_iterator(db.inner, readopts.inner) } } } - fn new_cf(db: &DB, - cf_handle: ColumnFamily, - readopts: &ReadOptions) - -> Result { + fn new_cf( + db: &DB, + cf_handle: ColumnFamily, + readopts: &ReadOptions, + ) -> Result { unsafe { Ok(DBRawIterator { inner: ffi::rocksdb_create_iterator_cf(db.inner, readopts.inner, cf_handle.inner), @@ -251,7 +248,9 @@ impl DBRawIterator { /// } /// ``` pub fn seek_to_first(&mut self) { - unsafe { ffi::rocksdb_iter_seek_to_first(self.inner); } + unsafe { + ffi::rocksdb_iter_seek_to_first(self.inner); + } } /// Seeks to the last key in the database. @@ -285,7 +284,9 @@ impl DBRawIterator { /// } /// ``` pub fn seek_to_last(&mut self) { - unsafe { ffi::rocksdb_iter_seek_to_last(self.inner); } + unsafe { + ffi::rocksdb_iter_seek_to_last(self.inner); + } } /// Seeks to the specified key or the first key that lexicographically follows it. @@ -312,7 +313,13 @@ impl DBRawIterator { /// } /// ``` pub fn seek(&mut self, key: &[u8]) { - unsafe { ffi::rocksdb_iter_seek(self.inner, key.as_ptr() as *const c_char, key.len() as size_t); } + unsafe { + ffi::rocksdb_iter_seek( + self.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + ); + } } /// Seeks to the specified key, or the first key that lexicographically precedes it. @@ -339,21 +346,31 @@ impl DBRawIterator { /// // There are no keys in the database /// } pub fn seek_for_prev(&mut self, key: &[u8]) { - unsafe { ffi::rocksdb_iter_seek_for_prev(self.inner, key.as_ptr() as *const c_char, key.len() as size_t); } + unsafe { + ffi::rocksdb_iter_seek_for_prev( + self.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + ); + } } /// Seeks to the next key. /// /// Returns true if the iterator is valid after this operation. pub fn next(&mut self) { - unsafe { ffi::rocksdb_iter_next(self.inner); } + unsafe { + ffi::rocksdb_iter_next(self.inner); + } } /// Seeks to the previous key. /// /// Returns true if the iterator is valid after this operation. pub fn prev(&mut self) { - unsafe { ffi::rocksdb_iter_prev(self.inner); } + unsafe { + ffi::rocksdb_iter_prev(self.inner); + } } /// Returns a slice to the internal buffer storing the current key. @@ -377,9 +394,7 @@ impl DBRawIterator { /// Returns a copy of the current key. pub fn key(&self) -> Option> { - unsafe { - self.key_inner().map(|key| key.to_vec()) - } + unsafe { self.key_inner().map(|key| key.to_vec()) } } /// Returns a slice to the internal buffer storing the current value. @@ -403,9 +418,7 @@ impl DBRawIterator { /// Returns a copy of the current value. pub fn value(&self) -> Option> { - unsafe { - self.value_inner().map(|value| value.to_vec()) - } + unsafe { self.value_inner().map(|value| value.to_vec()) } } } @@ -428,11 +441,12 @@ impl DBIterator { rv } - fn new_cf(db: &DB, - cf_handle: ColumnFamily, - readopts: &ReadOptions, - mode: IteratorMode) - -> Result { + fn new_cf( + db: &DB, + cf_handle: ColumnFamily, + readopts: &ReadOptions, + mode: IteratorMode, + ) -> Result { let mut rv = DBIterator { raw: try!(DBRawIterator::new_cf(db, cf_handle, readopts)), direction: Direction::Forward, // blown away by set_mode() @@ -484,7 +498,10 @@ impl Iterator for DBIterator { if self.raw.valid() { // .key() and .value() only ever return None if valid == false, which we've just cheked - Some((self.raw.key().unwrap().into_boxed_slice(), self.raw.value().unwrap().into_boxed_slice())) + Some(( + self.raw.key().unwrap().into_boxed_slice(), + self.raw.value().unwrap().into_boxed_slice(), + )) } else { None } @@ -512,10 +529,11 @@ impl<'a> Snapshot<'a> { DBIterator::new(self.db, &readopts, mode) } - pub fn iterator_cf(&self, - cf_handle: ColumnFamily, - mode: IteratorMode) - -> Result { + pub fn iterator_cf( + &self, + cf_handle: ColumnFamily, + mode: IteratorMode, + ) -> Result { let mut readopts = ReadOptions::default(); readopts.set_snapshot(self); DBIterator::new_cf(self.db, cf_handle, &readopts, mode) @@ -527,9 +545,7 @@ impl<'a> Snapshot<'a> { DBRawIterator::new(self.db, &readopts) } - pub fn raw_iterator_cf(&self, - cf_handle: ColumnFamily) - -> Result { + pub fn raw_iterator_cf(&self, cf_handle: ColumnFamily) -> Result { let mut readopts = ReadOptions::default(); readopts.set_snapshot(self); DBRawIterator::new_cf(self.db, cf_handle, &readopts) @@ -541,10 +557,7 @@ impl<'a> Snapshot<'a> { self.db.get_opt(key, &readopts) } - pub fn get_cf(&self, - cf: ColumnFamily, - key: &[u8]) - -> Result, Error> { + pub fn get_cf(&self, cf: ColumnFamily, key: &[u8]) -> Result, Error> { let mut readopts = ReadOptions::default(); readopts.set_snapshot(self); self.db.get_cf_opt(cf, key, &readopts) @@ -584,16 +597,20 @@ impl DB { let cpath = match CString::new(path.to_string_lossy().as_bytes()) { Ok(c) => c, Err(_) => { - return Err(Error::new("Failed to convert path to CString \ + return Err(Error::new( + "Failed to convert path to CString \ when opening DB." - .to_owned())) + .to_owned(), + )) } }; if let Err(e) = fs::create_dir_all(&path) { - return Err(Error::new(format!("Failed to create RocksDB\ + return Err(Error::new(format!( + "Failed to create RocksDB\ directory: `{:?}`.", - e))); + e + ))); } let db: *mut ffi::rocksdb_t; @@ -601,7 +618,7 @@ impl DB { if cfs.len() == 0 { unsafe { - db = ffi_try!(ffi::rocksdb_open(opts.inner, cpath.as_ptr() as *const _)); + db = ffi_try!(ffi::rocksdb_open(opts.inner, cpath.as_ptr() as *const _,)); } } else { let mut cfs_v = cfs.to_vec(); @@ -612,34 +629,39 @@ impl DB { // We need to store our CStrings in an intermediate vector // so that their pointers remain valid. - let c_cfs: Vec = cfs_v.iter() + let c_cfs: Vec = cfs_v + .iter() .map(|cf| CString::new(cf.as_bytes()).unwrap()) .collect(); - let cfnames: Vec<_> = c_cfs.iter().map(|cf| cf.as_ptr()).collect(); + let mut cfnames: Vec<_> = c_cfs.iter().map(|cf| cf.as_ptr()).collect(); // These handles will be populated by DB. let mut cfhandles: Vec<_> = cfs_v.iter().map(|_| ptr::null_mut()).collect(); // TODO(tyler) allow options to be passed in. - let cfopts: Vec<_> = cfs_v.iter() + let mut cfopts: Vec<_> = cfs_v + .iter() .map(|_| unsafe { ffi::rocksdb_options_create() as *const _ }) .collect(); unsafe { - db = ffi_try!(ffi::rocksdb_open_column_families(opts.inner, - cpath.as_ptr() as *const _, - cfs_v.len() as c_int, - cfnames.as_ptr() as *const _, - cfopts.as_ptr(), - cfhandles.as_mut_ptr())); + db = ffi_try!(ffi::rocksdb_open_column_families( + opts.inner, + cpath.as_ptr(), + cfs_v.len() as c_int, + cfnames.as_mut_ptr(), + cfopts.as_mut_ptr(), + cfhandles.as_mut_ptr(),)); } for handle in &cfhandles { if handle.is_null() { - return Err(Error::new("Received null column family \ + return Err(Error::new( + "Received null column family \ handle from DB." - .to_owned())); + .to_owned(), + )); } } @@ -664,22 +686,27 @@ impl DB { let cpath = match CString::new(path.to_string_lossy().as_bytes()) { Ok(c) => c, Err(_) => { - return Err(Error::new("Failed to convert path to CString \ + return Err(Error::new( + "Failed to convert path to CString \ when opening DB." - .to_owned())) + .to_owned(), + )) } }; let mut length = 0; unsafe { - let ptr = ffi_try!(ffi::rocksdb_list_column_families(opts.inner, - cpath.as_ptr() as *const _, - &mut length)); - - let vec = Vec::from_raw_parts(ptr, length, length).iter().map(|&ptr| { - CString::from_raw(ptr).into_string().unwrap() - }).collect(); + let ptr = ffi_try!(ffi::rocksdb_list_column_families( + opts.inner, + cpath.as_ptr() as *const _, + &mut length, + )); + + let vec = Vec::from_raw_parts(ptr, length, length) + .iter() + .map(|&ptr| CString::from_raw(ptr).into_string().unwrap()) + .collect(); Ok(vec) } } @@ -688,7 +715,7 @@ impl DB { pub fn destroy>(opts: &Options, path: P) -> Result<(), Error> { let cpath = CString::new(path.as_ref().to_string_lossy().as_bytes()).unwrap(); unsafe { - ffi_try!(ffi::rocksdb_destroy_db(opts.inner, cpath.as_ptr())); + ffi_try!(ffi::rocksdb_destroy_db(opts.inner, cpath.as_ptr(),)); } Ok(()) } @@ -696,7 +723,7 @@ impl DB { pub fn repair>(opts: Options, path: P) -> Result<(), Error> { let cpath = CString::new(path.as_ref().to_string_lossy().as_bytes()).unwrap(); unsafe { - ffi_try!(ffi::rocksdb_repair_db(opts.inner, cpath.as_ptr())); + ffi_try!(ffi::rocksdb_repair_db(opts.inner, cpath.as_ptr(),)); } Ok(()) } @@ -707,7 +734,7 @@ impl DB { pub fn write_opt(&self, batch: WriteBatch, writeopts: &WriteOptions) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_write(self.inner, writeopts.inner, batch.inner)); + ffi_try!(ffi::rocksdb_write(self.inner, writeopts.inner, batch.inner,)); } Ok(()) } @@ -724,21 +751,25 @@ impl DB { pub fn get_opt(&self, key: &[u8], readopts: &ReadOptions) -> Result, Error> { if readopts.inner.is_null() { - return Err(Error::new("Unable to create RocksDB read options. \ + return Err(Error::new( + "Unable to create RocksDB read options. \ This is a fairly trivial call, and its \ failure may be indicative of a \ mis-compiled or mis-loaded RocksDB \ library." - .to_owned())); + .to_owned(), + )); } unsafe { let mut val_len: size_t = 0; - let val = ffi_try!(ffi::rocksdb_get(self.inner, - readopts.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - &mut val_len)) as *mut u8; + let val = ffi_try!(ffi::rocksdb_get( + self.inner, + readopts.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + &mut val_len, + )) as *mut u8; if val.is_null() { Ok(None) } else { @@ -752,28 +783,33 @@ impl DB { self.get_opt(key, &ReadOptions::default()) } - pub fn get_cf_opt(&self, - cf: ColumnFamily, - key: &[u8], - readopts: &ReadOptions) - -> Result, Error> { + pub fn get_cf_opt( + &self, + cf: ColumnFamily, + key: &[u8], + readopts: &ReadOptions, + ) -> Result, Error> { if readopts.inner.is_null() { - return Err(Error::new("Unable to create RocksDB read options. \ + return Err(Error::new( + "Unable to create RocksDB read options. \ This is a fairly trivial call, and its \ failure may be indicative of a \ mis-compiled or mis-loaded RocksDB \ library." - .to_owned())); + .to_owned(), + )); } unsafe { let mut val_len: size_t = 0; - let val = ffi_try!(ffi::rocksdb_get_cf(self.inner, - readopts.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - &mut val_len)) as *mut u8; + let val = ffi_try!(ffi::rocksdb_get_cf( + self.inner, + readopts.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + &mut val_len, + )) as *mut u8; if val.is_null() { Ok(None) } else { @@ -782,28 +818,27 @@ impl DB { } } - pub fn get_cf(&self, - cf: ColumnFamily, - key: &[u8]) - -> Result, Error> { + pub fn get_cf(&self, cf: ColumnFamily, key: &[u8]) -> Result, Error> { self.get_cf_opt(cf, key, &ReadOptions::default()) } - pub fn create_cf(&mut self, - name: &str, - opts: &Options) - -> Result { + pub fn create_cf(&mut self, name: &str, opts: &Options) -> Result { let cname = match CString::new(name.as_bytes()) { Ok(c) => c, Err(_) => { - return Err(Error::new("Failed to convert path to CString \ + return Err(Error::new( + "Failed to convert path to CString \ when opening rocksdb" - .to_owned())) + .to_owned(), + )) } }; let cf = unsafe { - let cf_handler = - ffi_try!(ffi::rocksdb_create_column_family(self.inner, opts.inner, cname.as_ptr())); + let cf_handler = ffi_try!(ffi::rocksdb_create_column_family( + self.inner, + opts.inner, + cname.as_ptr(), + )); let cf = ColumnFamily { inner: cf_handler }; self.cfs.insert(name.to_string(), cf); cf @@ -814,10 +849,15 @@ impl DB { pub fn drop_cf(&mut self, name: &str) -> Result<(), Error> { let cf = self.cfs.get(name); if cf.is_none() { - return Err(Error::new(format!("Invalid column family: {}", name).to_owned())); + return Err(Error::new( + format!("Invalid column family: {}", name).to_owned(), + )); } unsafe { - ffi_try!(ffi::rocksdb_drop_column_family(self.inner, cf.unwrap().inner)); + ffi_try!(ffi::rocksdb_drop_column_family( + self.inner, + cf.unwrap().inner, + )); } Ok(()) } @@ -832,10 +872,11 @@ impl DB { DBIterator::new(self, &opts, mode) } - pub fn iterator_cf(&self, - cf_handle: ColumnFamily, - mode: IteratorMode) - -> Result { + pub fn iterator_cf( + &self, + cf_handle: ColumnFamily, + mode: IteratorMode, + ) -> Result { let opts = ReadOptions::default(); DBIterator::new_cf(self, cf_handle, &opts, mode) } @@ -845,9 +886,7 @@ impl DB { DBRawIterator::new(self, &opts) } - pub fn raw_iterator_cf(&self, - cf_handle: ColumnFamily) - -> Result { + pub fn raw_iterator_cf(&self, cf_handle: ColumnFamily) -> Result { let opts = ReadOptions::default(); DBRawIterator::new_cf(self, cf_handle, &opts) } @@ -858,89 +897,105 @@ impl DB { pub fn put_opt(&self, key: &[u8], value: &[u8], writeopts: &WriteOptions) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_put(self.inner, - writeopts.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t)); + ffi_try!(ffi::rocksdb_put( + self.inner, + writeopts.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + )); Ok(()) } } - pub fn put_cf_opt(&self, - cf: ColumnFamily, - key: &[u8], - value: &[u8], - writeopts: &WriteOptions) - -> Result<(), Error> { + pub fn put_cf_opt( + &self, + cf: ColumnFamily, + key: &[u8], + value: &[u8], + writeopts: &WriteOptions, + ) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_put_cf(self.inner, - writeopts.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t)); + ffi_try!(ffi::rocksdb_put_cf( + self.inner, + writeopts.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + )); Ok(()) } } - pub fn merge_opt(&self, - key: &[u8], - value: &[u8], - writeopts: &WriteOptions) - -> Result<(), Error> { + pub fn merge_opt( + &self, + key: &[u8], + value: &[u8], + writeopts: &WriteOptions, + ) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_merge(self.inner, - writeopts.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t)); + ffi_try!(ffi::rocksdb_merge( + self.inner, + writeopts.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + )); Ok(()) } } - pub fn merge_cf_opt(&self, - cf: ColumnFamily, - key: &[u8], - value: &[u8], - writeopts: &WriteOptions) - -> Result<(), Error> { + pub fn merge_cf_opt( + &self, + cf: ColumnFamily, + key: &[u8], + value: &[u8], + writeopts: &WriteOptions, + ) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_merge_cf(self.inner, - writeopts.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t)); + ffi_try!(ffi::rocksdb_merge_cf( + self.inner, + writeopts.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + )); Ok(()) } } pub fn delete_opt(&self, key: &[u8], writeopts: &WriteOptions) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_delete(self.inner, - writeopts.inner, - key.as_ptr() as *const c_char, - key.len() as size_t)); + ffi_try!(ffi::rocksdb_delete( + self.inner, + writeopts.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + )); Ok(()) } } - pub fn delete_cf_opt(&self, - cf: ColumnFamily, - key: &[u8], - writeopts: &WriteOptions) - -> Result<(), Error> { + pub fn delete_cf_opt( + &self, + cf: ColumnFamily, + key: &[u8], + writeopts: &WriteOptions, + ) -> Result<(), Error> { unsafe { - ffi_try!(ffi::rocksdb_delete_cf(self.inner, - writeopts.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t)); + ffi_try!(ffi::rocksdb_delete_cf( + self.inner, + writeopts.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + )); Ok(()) } } @@ -949,11 +1004,7 @@ impl DB { self.put_opt(key, value, &WriteOptions::default()) } - pub fn put_cf(&self, - cf: ColumnFamily, - key: &[u8], - value: &[u8]) - -> Result<(), Error> { + pub fn put_cf(&self, cf: ColumnFamily, key: &[u8], value: &[u8]) -> Result<(), Error> { self.put_cf_opt(cf, key, value, &WriteOptions::default()) } @@ -961,11 +1012,7 @@ impl DB { self.merge_opt(key, value, &WriteOptions::default()) } - pub fn merge_cf(&self, - cf: ColumnFamily, - key: &[u8], - value: &[u8]) - -> Result<(), Error> { + pub fn merge_cf(&self, cf: ColumnFamily, key: &[u8], value: &[u8]) -> Result<(), Error> { self.merge_cf_opt(cf, key, value, &WriteOptions::default()) } @@ -973,34 +1020,32 @@ impl DB { self.delete_opt(key, &WriteOptions::default()) } - pub fn delete_cf(&self, - cf: ColumnFamily, - key: &[u8]) - -> Result<(), Error> { + pub fn delete_cf(&self, cf: ColumnFamily, key: &[u8]) -> Result<(), Error> { self.delete_cf_opt(cf, key, &WriteOptions::default()) } pub fn compact_range(&self, start: Option<&[u8]>, end: Option<&[u8]>) { unsafe { - ffi::rocksdb_compact_range(self.inner, - opt_bytes_to_ptr(start), - start.map_or(0, |s| s.len()) as size_t, - opt_bytes_to_ptr(end), - end.map_or(0, |e| e.len()) as size_t); + ffi::rocksdb_compact_range( + self.inner, + opt_bytes_to_ptr(start), + start.map_or(0, |s| s.len()) as size_t, + opt_bytes_to_ptr(end), + end.map_or(0, |e| e.len()) as size_t, + ); } } - pub fn compact_range_cf(&self, - cf: ColumnFamily, - start: Option<&[u8]>, - end: Option<&[u8]>) { + pub fn compact_range_cf(&self, cf: ColumnFamily, start: Option<&[u8]>, end: Option<&[u8]>) { unsafe { - ffi::rocksdb_compact_range_cf(self.inner, - cf.inner, - opt_bytes_to_ptr(start), - start.map_or(0, |s| s.len()) as size_t, - opt_bytes_to_ptr(end), - end.map_or(0, |e| e.len()) as size_t); + ffi::rocksdb_compact_range_cf( + self.inner, + cf.inner, + opt_bytes_to_ptr(start), + start.map_or(0, |s| s.len()) as size_t, + opt_bytes_to_ptr(end), + end.map_or(0, |e| e.len()) as size_t, + ); } } } @@ -1017,54 +1062,54 @@ impl WriteBatch { /// Insert a value into the database under the given key. pub fn put(&mut self, key: &[u8], value: &[u8]) -> Result<(), Error> { unsafe { - ffi::rocksdb_writebatch_put(self.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t); + ffi::rocksdb_writebatch_put( + self.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + ); Ok(()) } } - pub fn put_cf(&mut self, - cf: ColumnFamily, - key: &[u8], - value: &[u8]) - -> Result<(), Error> { + pub fn put_cf(&mut self, cf: ColumnFamily, key: &[u8], value: &[u8]) -> Result<(), Error> { unsafe { - ffi::rocksdb_writebatch_put_cf(self.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t); + ffi::rocksdb_writebatch_put_cf( + self.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + ); Ok(()) } } pub fn merge(&mut self, key: &[u8], value: &[u8]) -> Result<(), Error> { unsafe { - ffi::rocksdb_writebatch_merge(self.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t); + ffi::rocksdb_writebatch_merge( + self.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + ); Ok(()) } } - pub fn merge_cf(&mut self, - cf: ColumnFamily, - key: &[u8], - value: &[u8]) - -> Result<(), Error> { + pub fn merge_cf(&mut self, cf: ColumnFamily, key: &[u8], value: &[u8]) -> Result<(), Error> { unsafe { - ffi::rocksdb_writebatch_merge_cf(self.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t, - value.as_ptr() as *const c_char, - value.len() as size_t); + ffi::rocksdb_writebatch_merge_cf( + self.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + value.as_ptr() as *const c_char, + value.len() as size_t, + ); Ok(()) } } @@ -1074,22 +1119,23 @@ impl WriteBatch { /// Returns an error if the key was not found. pub fn delete(&mut self, key: &[u8]) -> Result<(), Error> { unsafe { - ffi::rocksdb_writebatch_delete(self.inner, - key.as_ptr() as *const c_char, - key.len() as size_t); + ffi::rocksdb_writebatch_delete( + self.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + ); Ok(()) } } - pub fn delete_cf(&mut self, - cf: ColumnFamily, - key: &[u8]) - -> Result<(), Error> { + pub fn delete_cf(&mut self, cf: ColumnFamily, key: &[u8]) -> Result<(), Error> { unsafe { - ffi::rocksdb_writebatch_delete_cf(self.inner, - cf.inner, - key.as_ptr() as *const c_char, - key.len() as size_t); + ffi::rocksdb_writebatch_delete_cf( + self.inner, + cf.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + ); Ok(()) } } @@ -1149,9 +1195,11 @@ impl ReadOptions { pub fn set_iterate_upper_bound(&mut self, key: &[u8]) { unsafe { - ffi::rocksdb_readoptions_set_iterate_upper_bound(self.inner, - key.as_ptr() as *const c_char, - key.len() as size_t); + ffi::rocksdb_readoptions_set_iterate_upper_bound( + self.inner, + key.as_ptr() as *const c_char, + key.len() as size_t, + ); } } } @@ -1310,9 +1358,11 @@ fn iterator_test() { assert!(p.is_ok()); let iter = db.iterator(IteratorMode::Start); for (k, v) in iter { - println!("Hello {}: {}", - str::from_utf8(&*k).unwrap(), - str::from_utf8(&*v).unwrap()); + println!( + "Hello {}: {}", + str::from_utf8(&*k).unwrap(), + str::from_utf8(&*v).unwrap() + ); } } let opts = Options::default(); diff --git a/src/db_options.rs b/src/db_options.rs index 21063f3..8f3a1b2 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -16,13 +16,13 @@ use {BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Options, WriteOptions}; +use compaction_filter::{self, CompactionFilterCallback, CompactionFilterFn, filter_callback}; use comparator::{self, ComparatorCallback, CompareFn}; use ffi; use libc::{self, c_int, c_uchar, c_uint, c_void, size_t, uint64_t}; use merge_operator::{self, MergeFn, MergeOperatorCallback, full_merge_callback, partial_merge_callback}; -use compaction_filter::{self, CompactionFilterCallback, CompactionFilterFn, filter_callback}; use std::ffi::{CStr, CString}; use std::mem; @@ -124,7 +124,8 @@ impl Options { unsafe { ffi::rocksdb_options_optimize_level_style_compaction( self.inner, - memtable_memory_budget as uint64_t); + memtable_memory_budget as uint64_t, + ); } } @@ -190,10 +191,12 @@ impl Options { /// ``` pub fn set_compression_per_level(&mut self, level_types: &[DBCompressionType]) { unsafe { - let level_types: Vec<_> = level_types.iter().map(|&t| t as c_int).collect(); - ffi::rocksdb_options_set_compression_per_level(self.inner, - level_types.as_ptr(), - level_types.len() as size_t) + let mut level_types: Vec<_> = level_types.iter().map(|&t| t as c_int).collect(); + ffi::rocksdb_options_set_compression_per_level( + self.inner, + level_types.as_mut_ptr(), + level_types.len() as size_t, + ) } } @@ -204,17 +207,20 @@ impl Options { }); unsafe { - let mo = ffi::rocksdb_mergeoperator_create(mem::transmute(cb), - Some(merge_operator::destructor_callback), - Some(full_merge_callback), - Some(partial_merge_callback), - None, - Some(merge_operator::name_callback)); + let mo = ffi::rocksdb_mergeoperator_create( + mem::transmute(cb), + Some(merge_operator::destructor_callback), + Some(full_merge_callback), + Some(partial_merge_callback), + None, + Some(merge_operator::name_callback), + ); ffi::rocksdb_options_set_merge_operator(self.inner, mo); } } - #[deprecated(since="0.5.0", note="add_merge_operator has been renamed to set_merge_operator")] + #[deprecated(since = "0.5.0", + note = "add_merge_operator has been renamed to set_merge_operator")] pub fn add_merge_operator(&mut self, name: &str, merge_fn: MergeFn) { self.set_merge_operator(name, merge_fn); } @@ -230,7 +236,8 @@ impl Options { /// If multi-threaded compaction is used, `filter_fn` may be called multiple times /// simultaneously. pub fn set_compaction_filter(&mut self, name: &str, filter_fn: F) - where F: CompactionFilterFn + Send + 'static + where + F: CompactionFilterFn + Send + 'static, { let cb = Box::new(CompactionFilterCallback { name: CString::new(name.as_bytes()).unwrap(), @@ -238,10 +245,12 @@ impl Options { }); unsafe { - let cf = ffi::rocksdb_compactionfilter_create(mem::transmute(cb), - Some(compaction_filter::destructor_callback::), - Some(filter_callback::), - Some(compaction_filter::name_callback::)); + let cf = ffi::rocksdb_compactionfilter_create( + mem::transmute(cb), + Some(compaction_filter::destructor_callback::), + Some(filter_callback::), + Some(compaction_filter::name_callback::), + ); ffi::rocksdb_options_set_compaction_filter(self.inner, cf); } } @@ -259,10 +268,12 @@ impl Options { }); unsafe { - let cmp = ffi::rocksdb_comparator_create(mem::transmute(cb), - Some(comparator::destructor_callback), - Some(comparator::compare_callback), - Some(comparator::name_callback)); + let cmp = ffi::rocksdb_comparator_create( + mem::transmute(cb), + Some(comparator::destructor_callback), + Some(comparator::compare_callback), + Some(comparator::name_callback), + ); ffi::rocksdb_options_set_comparator(self.inner, cmp); } } @@ -365,8 +376,9 @@ impl Options { /// opts.set_allow_concurrent_memtable_write(false); /// ``` pub fn set_allow_concurrent_memtable_write(&mut self, allow: bool) { - unsafe { ffi::rocksdb_options_set_allow_concurrent_memtable_write(self.inner, - allow as c_uchar) } + unsafe { + ffi::rocksdb_options_set_allow_concurrent_memtable_write(self.inner, allow as c_uchar) + } } /// Enable direct I/O mode for reading @@ -413,8 +425,10 @@ impl Options { /// ``` pub fn set_use_direct_io_for_flush_and_compaction(&mut self, enabled: bool) { unsafe { - ffi::rocksdb_options_set_use_direct_io_for_flush_and_compaction(self.inner, - enabled as c_uchar); + ffi::rocksdb_options_set_use_direct_io_for_flush_and_compaction( + self.inner, + enabled as c_uchar, + ); } } @@ -446,7 +460,8 @@ impl Options { /// let mut opts = Options::default(); /// opts.set_allow_os_buffer(false); /// ``` - #[deprecated(since="0.7.0", note="replaced with set_use_direct_reads/set_use_direct_io_for_flush_and_compaction methods")] + #[deprecated(since = "0.7.0", + note = "replaced with set_use_direct_reads/set_use_direct_io_for_flush_and_compaction methods")] pub fn set_allow_os_buffer(&mut self, is_allow: bool) { self.set_use_direct_reads(!is_allow); self.set_use_direct_io_for_flush_and_compaction(!is_allow); @@ -599,9 +614,9 @@ impl Options { /// use rocksdb::Options; /// /// let mut opts = Options::default(); - /// opts.set_max_bytes_for_level_multiplier(4); + /// opts.set_max_bytes_for_level_multiplier(4.0); /// ``` - pub fn set_max_bytes_for_level_multiplier(&mut self, mul: i32) { + pub fn set_max_bytes_for_level_multiplier(&mut self, mul: f64) { unsafe { ffi::rocksdb_options_set_max_bytes_for_level_multiplier(self.inner, mul); } diff --git a/src/ffi_util.rs b/src/ffi_util.rs index e9b3119..49c298e 100644 --- a/src/ffi_util.rs +++ b/src/ffi_util.rs @@ -34,7 +34,7 @@ pub fn opt_bytes_to_ptr(opt: Option<&[u8]>) -> *const c_char { } macro_rules! ffi_try { - ( $($function:ident)::*( $( $arg:expr ),* ) ) => ({ + ( $($function:ident)::*( $( $arg:expr,)* ) ) => ({ let mut err: *mut ::libc::c_char = ::std::ptr::null_mut(); let result = $($function)::*($($arg),*, &mut err); if !err.is_null() { diff --git a/src/lib.rs b/src/lib.rs index 56778d7..d2f7394 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,11 +44,12 @@ pub mod compaction_filter; mod db; mod db_options; -pub use db::{DBCompactionStyle, DBCompressionType, DBIterator, DBRawIterator, DBRecoveryMode, DBVector, - ReadOptions, Direction, IteratorMode, Snapshot, WriteBatch, new_bloom_filter}; +pub use compaction_filter::Decision as CompactionDecision; +pub use db::{DBCompactionStyle, DBCompressionType, DBIterator, DBRawIterator, DBRecoveryMode, + DBVector, ReadOptions, Direction, IteratorMode, Snapshot, WriteBatch, + new_bloom_filter}; pub use merge_operator::MergeOperands; -pub use compaction_filter::Decision as CompactionDecision; use std::collections::BTreeMap; use std::error; use std::fmt; diff --git a/src/merge_operator.rs b/src/merge_operator.rs index 283e71f..6085a1e 100644 --- a/src/merge_operator.rs +++ b/src/merge_operator.rs @@ -76,17 +76,18 @@ pub unsafe extern "C" fn name_callback(raw_cb: *mut c_void) -> *const c_char { cb.name.as_ptr() } -pub unsafe extern "C" fn full_merge_callback(raw_cb: *mut c_void, - raw_key: *const c_char, - key_len: size_t, - existing_value: *const c_char, - existing_value_len: size_t, - operands_list: *const *const c_char, - operands_list_len: *const size_t, - num_operands: c_int, - success: *mut u8, - new_value_length: *mut size_t) - -> *mut c_char { +pub unsafe extern "C" fn full_merge_callback( + raw_cb: *mut c_void, + raw_key: *const c_char, + key_len: size_t, + existing_value: *const c_char, + existing_value_len: size_t, + operands_list: *const *const c_char, + operands_list_len: *const size_t, + num_operands: c_int, + success: *mut u8, + new_value_length: *mut size_t, +) -> *mut c_char { let cb = &mut *(raw_cb as *mut MergeOperatorCallback); let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands); let key = slice::from_raw_parts(raw_key as *const u8, key_len as usize); @@ -102,15 +103,16 @@ pub unsafe extern "C" fn full_merge_callback(raw_cb: *mut c_void, buf as *mut c_char } -pub unsafe extern "C" fn partial_merge_callback(raw_cb: *mut c_void, - raw_key: *const c_char, - key_len: size_t, - operands_list: *const *const c_char, - operands_list_len: *const size_t, - num_operands: c_int, - success: *mut u8, - new_value_length: *mut size_t) - -> *mut c_char { +pub unsafe extern "C" fn partial_merge_callback( + raw_cb: *mut c_void, + raw_key: *const c_char, + key_len: size_t, + operands_list: *const *const c_char, + operands_list_len: *const size_t, + num_operands: c_int, + success: *mut u8, + new_value_length: *mut size_t, +) -> *mut c_char { let cb = &mut *(raw_cb as *mut MergeOperatorCallback); let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands); let key = slice::from_raw_parts(raw_key as *const u8, key_len as usize); @@ -134,10 +136,11 @@ pub struct MergeOperands { } impl MergeOperands { - fn new(operands_list: *const *const c_char, - operands_list_len: *const size_t, - num_operands: c_int) - -> MergeOperands { + fn new( + operands_list: *const *const c_char, + operands_list_len: *const size_t, + num_operands: c_int, + ) -> MergeOperands { assert!(num_operands >= 0); MergeOperands { operands_list: operands_list, @@ -164,8 +167,10 @@ impl<'a> Iterator for &'a mut MergeOperands { let len = *len_ptr as usize; let ptr = base + (spacing * self.cursor); self.cursor += 1; - Some(mem::transmute(slice::from_raw_parts(*(ptr as *const *const u8) as *const u8, - len))) + Some(mem::transmute(slice::from_raw_parts( + *(ptr as *const *const u8) as *const u8, + len, + ))) } } } @@ -178,10 +183,11 @@ impl<'a> Iterator for &'a mut MergeOperands { #[cfg(test)] #[allow(unused_variables)] -fn test_provided_merge(new_key: &[u8], - existing_val: Option<&[u8]>, - operands: &mut MergeOperands) - -> Vec { +fn test_provided_merge( + new_key: &[u8], + existing_val: Option<&[u8]>, + operands: &mut MergeOperands, +) -> Vec { let nops = operands.size_hint().0; let mut result: Vec = Vec::with_capacity(nops); if let Some(v) = existing_val {