librocksdb-sys-0.17.1+9.9.3/.cargo_vcs_info.json0000644000000001540000000000100145300ustar { "git": { "sha1": "3525109490bcdf66565e5d22ff8a19fdd7240bba" }, "path_in_vcs": "librocksdb-sys" }librocksdb-sys-0.17.1+9.9.3/Cargo.toml0000644000000040720000000000100125310ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.71.1" name = "librocksdb-sys" version = "0.17.1+9.9.3" authors = [ "Karl Hobley ", "Arkadiy Paronyan ", ] links = "rocksdb" description = "Native bindings to librocksdb" readme = "README.md" keywords = [ "bindings", "ffi", "rocksdb", ] categories = [ "api-bindings", "database", "external-ffi-bindings", ] license = "MIT/Apache-2.0/BSD-3-Clause" repository = "https://github.com/rust-rocksdb/rust-rocksdb" [dependencies.bzip2-sys] version = "0.1" optional = true default-features = false [dependencies.libc] version = "0.2" [dependencies.libz-sys] version = "1.1" optional = true default-features = false [dependencies.lz4-sys] version = "1.10" optional = true [dependencies.tikv-jemalloc-sys] version = "0.6" features = ["unprefixed_malloc_on_supported_platforms"] optional = true [dependencies.zstd-sys] version = "2.0" features = ["zdict_builder"] optional = true [dev-dependencies.uuid] version = "1.0" features = ["v4"] [build-dependencies.bindgen] version = "0.69" default-features = false [build-dependencies.cc] version = "1.0" features = ["parallel"] [build-dependencies.pkg-config] version = "0.3" optional = true [features] bindgen-runtime = ["bindgen/runtime"] bindgen-static = ["bindgen/static"] bzip2 = ["bzip2-sys"] default = [ "static", "bindgen/runtime", ] io-uring = ["pkg-config"] jemalloc = ["tikv-jemalloc-sys"] lto = [] lz4 = ["lz4-sys"] mt_static = [] rtti = [] snappy = [] static = [ "libz-sys?/static", "bzip2-sys?/static", ] zlib = ["libz-sys"] zstd = ["zstd-sys"] librocksdb-sys-0.17.1+9.9.3/Cargo.toml.orig0000644000000027710000000000100134740ustar [package] name = "librocksdb-sys" version = "0.17.1+9.9.3" edition = "2021" rust-version = "1.71.1" authors = [ "Karl Hobley ", "Arkadiy Paronyan ", ] license = "MIT/Apache-2.0/BSD-3-Clause" description = "Native bindings to librocksdb" readme = "README.md" repository = "https://github.com/rust-rocksdb/rust-rocksdb" keywords = ["bindings", "ffi", "rocksdb"] categories = ["api-bindings", "database", "external-ffi-bindings"] links = "rocksdb" [features] default = ["static", "bindgen/runtime"] jemalloc = ["tikv-jemalloc-sys"] static = ["libz-sys?/static", "bzip2-sys?/static"] bindgen-runtime = ["bindgen/runtime"] bindgen-static = ["bindgen/static"] mt_static = [] io-uring = ["pkg-config"] snappy = [] lz4 = ["lz4-sys"] zstd = ["zstd-sys"] zlib = ["libz-sys"] bzip2 = ["bzip2-sys"] rtti = [] lto = [] [dependencies] libc = "0.2" tikv-jemalloc-sys = { version = "0.6", features = [ "unprefixed_malloc_on_supported_platforms", ], optional = true } lz4-sys = { version = "1.10", optional = true } zstd-sys = { version = "2.0", features = ["zdict_builder"], optional = true } libz-sys = { version = "1.1", default-features = false, optional = true } bzip2-sys = { version = "0.1", default-features = false, optional = true } [dev-dependencies] uuid = { version = "1.0", features = ["v4"] } [build-dependencies] cc = { version = "1.0", features = ["parallel"] } bindgen = { version = "0.69", default-features = false } pkg-config = { version = "0.3", optional = true } librocksdb-sys-0.17.1+9.9.3/Cargo.toml.orig000064400000000000000000000027711046102023000162160ustar 00000000000000[package] name = "librocksdb-sys" version = "0.17.1+9.9.3" edition = "2021" rust-version = "1.71.1" authors = [ "Karl Hobley ", "Arkadiy Paronyan ", ] license = "MIT/Apache-2.0/BSD-3-Clause" description = "Native bindings to librocksdb" readme = "README.md" repository = "https://github.com/rust-rocksdb/rust-rocksdb" keywords = ["bindings", "ffi", "rocksdb"] categories = ["api-bindings", "database", "external-ffi-bindings"] links = "rocksdb" [features] default = ["static", "bindgen/runtime"] jemalloc = ["tikv-jemalloc-sys"] static = ["libz-sys?/static", "bzip2-sys?/static"] bindgen-runtime = ["bindgen/runtime"] bindgen-static = ["bindgen/static"] mt_static = [] io-uring = ["pkg-config"] snappy = [] lz4 = ["lz4-sys"] zstd = ["zstd-sys"] zlib = ["libz-sys"] bzip2 = ["bzip2-sys"] rtti = [] lto = [] [dependencies] libc = "0.2" tikv-jemalloc-sys = { version = "0.6", features = [ "unprefixed_malloc_on_supported_platforms", ], optional = true } lz4-sys = { version = "1.10", optional = true } zstd-sys = { version = "2.0", features = ["zdict_builder"], optional = true } libz-sys = { version = "1.1", default-features = false, optional = true } bzip2-sys = { version = "0.1", default-features = false, optional = true } [dev-dependencies] uuid = { version = "1.0", features = ["v4"] } [build-dependencies] cc = { version = "1.0", features = ["parallel"] } bindgen = { version = "0.69", default-features = false } pkg-config = { version = "0.3", optional = true } librocksdb-sys-0.17.1+9.9.3/Makefile000064400000000000000000000005701046102023000147620ustar 00000000000000include rocksdb/src.mk rocksdb_lib_sources.txt: rocksdb/src.mk @echo -n "${LIB_SOURCES}" | tr ' ' '\n' > rocksdb_lib_sources.txt gen_lib_sources: rocksdb_lib_sources.txt gen_statistics: rocksdb/monitoring/statistics.cc bash gen_statistics.bash $< Ticker > ../src/statistics_enum_ticker.rs bash gen_statistics.bash $< Histogram > ../src/statistics_enum_histogram.rs librocksdb-sys-0.17.1+9.9.3/README.md000064400000000000000000000007101046102023000145750ustar 00000000000000# RocksDB bindings Low-level bindings to [RocksDB's](https://github.com/facebook/rocksdb) C API. Based on original work by Tyler Neely https://github.com/rust-rocksdb/rust-rocksdb and Jeremy Fitzhardinge https://github.com/jsgf/rocksdb-sys ### Version The librocksdb-sys version number is in the format `X.Y.Z+RX.RY.RZ`, where `X.Y.Z` is the version of this crate and follows SemVer conventions, while `RX.RY.RZ` is the version of the bundled rocksdb. librocksdb-sys-0.17.1+9.9.3/build.rs000064400000000000000000000344151046102023000147740ustar 00000000000000use std::path::Path; use std::{env, fs, path::PathBuf, process::Command}; fn link(name: &str, bundled: bool) { use std::env::var; let target = var("TARGET").unwrap(); let target: Vec<_> = target.split('-').collect(); if target.get(2) == Some(&"windows") { println!("cargo:rustc-link-lib=dylib={name}"); if bundled && target.get(3) == Some(&"gnu") { let dir = var("CARGO_MANIFEST_DIR").unwrap(); println!("cargo:rustc-link-search=native={}/{}", dir, target[0]); } } } fn fail_on_empty_directory(name: &str) { if fs::read_dir(name).unwrap().count() == 0 { println!("The `{name}` directory is empty, did you forget to pull the submodules?"); println!("Try `git submodule update --init --recursive`"); panic!(); } } fn rocksdb_include_dir() -> String { env::var("ROCKSDB_INCLUDE_DIR").unwrap_or_else(|_| "rocksdb/include".to_string()) } fn bindgen_rocksdb() { let bindings = bindgen::Builder::default() .header(rocksdb_include_dir() + "/rocksdb/c.h") .derive_debug(false) .blocklist_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550 .ctypes_prefix("libc") .size_t_is_usize(true) .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"); } fn build_rocksdb() { let target = env::var("TARGET").unwrap(); let mut config = cc::Build::new(); config.include("rocksdb/include/"); config.include("rocksdb/"); config.include("rocksdb/third-party/gtest-1.8.1/fused-src/"); if cfg!(feature = "snappy") { config.define("SNAPPY", Some("1")); config.include("snappy/"); } if cfg!(feature = "lz4") { config.define("LZ4", Some("1")); if let Some(path) = env::var_os("DEP_LZ4_INCLUDE") { config.include(path); } } if cfg!(feature = "zstd") { config.define("ZSTD", Some("1")); if let Some(path) = env::var_os("DEP_ZSTD_INCLUDE") { config.include(path); } } if cfg!(feature = "zlib") { config.define("ZLIB", Some("1")); if let Some(path) = env::var_os("DEP_Z_INCLUDE") { config.include(path); } } if cfg!(feature = "bzip2") { config.define("BZIP2", Some("1")); if let Some(path) = env::var_os("DEP_BZIP2_INCLUDE") { config.include(path); } } if cfg!(feature = "rtti") { config.define("USE_RTTI", Some("1")); } // https://github.com/facebook/rocksdb/blob/be7703b27d9b3ac458641aaadf27042d86f6869c/Makefile#L195 if cfg!(feature = "lto") { config.flag("-flto"); if !config.get_compiler().is_like_clang() { panic!( "LTO is only supported with clang. Either disable the `lto` feature\ or set `CC=/usr/bin/clang CXX=/usr/bin/clang++` environment variables." ); } } config.include("."); config.define("NDEBUG", Some("1")); let mut lib_sources = include_str!("rocksdb_lib_sources.txt") .trim() .split('\n') .map(str::trim) // We have a pre-generated a version of build_version.cc in the local directory .filter(|file| !matches!(*file, "util/build_version.cc")) .collect::>(); if let (true, Ok(target_feature_value)) = ( target.contains("x86_64"), env::var("CARGO_CFG_TARGET_FEATURE"), ) { // This is needed to enable hardware CRC32C. Technically, SSE 4.2 is // only available since Intel Nehalem (about 2010) and AMD Bulldozer // (about 2011). let target_features: Vec<_> = target_feature_value.split(',').collect(); if target_features.contains(&"sse2") { config.flag_if_supported("-msse2"); } if target_features.contains(&"sse4.1") { config.flag_if_supported("-msse4.1"); } if target_features.contains(&"sse4.2") { config.flag_if_supported("-msse4.2"); } // Pass along additional target features as defined in // build_tools/build_detect_platform. if target_features.contains(&"avx2") { config.flag_if_supported("-mavx2"); } if target_features.contains(&"bmi1") { config.flag_if_supported("-mbmi"); } if target_features.contains(&"lzcnt") { config.flag_if_supported("-mlzcnt"); } if !target.contains("android") && target_features.contains(&"pclmulqdq") { config.flag_if_supported("-mpclmul"); } } if target.contains("apple-ios") { config.define("OS_MACOSX", None); config.define("IOS_CROSS_COMPILE", None); config.define("PLATFORM", "IOS"); config.define("NIOSTATS_CONTEXT", None); config.define("NPERF_CONTEXT", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); env::set_var("IPHONEOS_DEPLOYMENT_TARGET", "12.0"); } else if target.contains("darwin") { config.define("OS_MACOSX", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); } else if target.contains("android") { config.define("OS_ANDROID", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); if &target == "armv7-linux-androideabi" { config.define("_FILE_OFFSET_BITS", Some("32")); } } else if target.contains("linux") { config.define("OS_LINUX", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); config.define("ROCKSDB_SCHED_GETCPU_PRESENT", None); } else if target.contains("dragonfly") { config.define("OS_DRAGONFLYBSD", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); } else if target.contains("freebsd") { config.define("OS_FREEBSD", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); } else if target.contains("netbsd") { config.define("OS_NETBSD", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); } else if target.contains("openbsd") { config.define("OS_OPENBSD", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); } else if target.contains("windows") { link("rpcrt4", false); link("shlwapi", false); config.define("DWIN32", None); config.define("OS_WIN", None); config.define("_MBCS", None); config.define("WIN64", None); config.define("NOMINMAX", None); config.define("ROCKSDB_WINDOWS_UTF8_FILENAMES", None); if &target == "x86_64-pc-windows-gnu" { // Tell MinGW to create localtime_r wrapper of localtime_s function. config.define("_POSIX_C_SOURCE", Some("1")); // Tell MinGW to use at least Windows Vista headers instead of the ones of Windows XP. // (This is minimum supported version of rocksdb) config.define("_WIN32_WINNT", Some("_WIN32_WINNT_VISTA")); } // Remove POSIX-specific sources lib_sources = lib_sources .iter() .cloned() .filter(|file| { !matches!( *file, "port/port_posix.cc" | "env/env_posix.cc" | "env/fs_posix.cc" | "env/io_posix.cc" ) }) .collect::>(); // Add Windows-specific sources lib_sources.extend([ "port/win/env_default.cc", "port/win/port_win.cc", "port/win/xpress_win.cc", "port/win/io_win.cc", "port/win/win_thread.cc", "port/win/env_win.cc", "port/win/win_logger.cc", ]); if cfg!(feature = "jemalloc") { lib_sources.push("port/win/win_jemalloc.cc"); } } config.define("ROCKSDB_SUPPORT_THREAD_LOCAL", None); if cfg!(feature = "jemalloc") { config.define("WITH_JEMALLOC", "ON"); } #[cfg(feature = "io-uring")] if target.contains("linux") { pkg_config::probe_library("liburing") .expect("The io-uring feature was requested but the library is not available"); config.define("ROCKSDB_IOURING_PRESENT", Some("1")); } if &target != "armv7-linux-androideabi" && env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() != "64" { config.define("_FILE_OFFSET_BITS", Some("64")); config.define("_LARGEFILE64_SOURCE", Some("1")); } if target.contains("msvc") { if cfg!(feature = "mt_static") { config.static_crt(true); } config.flag("-EHsc"); config.flag("-std:c++17"); } else { config.flag(&cxx_standard()); // matches the flags in CMakeLists.txt from rocksdb config.flag("-Wsign-compare"); config.flag("-Wshadow"); config.flag("-Wno-unused-parameter"); config.flag("-Wno-unused-variable"); config.flag("-Woverloaded-virtual"); config.flag("-Wnon-virtual-dtor"); config.flag("-Wno-missing-field-initializers"); config.flag("-Wno-strict-aliasing"); config.flag("-Wno-invalid-offsetof"); } if target.contains("riscv64gc") { // link libatomic required to build for riscv64gc println!("cargo:rustc-link-lib=atomic"); } for file in lib_sources { config.file(format!("rocksdb/{file}")); } config.file("build_version.cc"); config.cpp(true); config.flag_if_supported("-std=c++17"); config.compile("librocksdb.a"); } fn build_snappy() { let target = env::var("TARGET").unwrap(); let endianness = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap(); let mut config = cc::Build::new(); config.include("snappy/"); config.include("."); config.define("NDEBUG", Some("1")); config.extra_warnings(false); if target.contains("msvc") { config.flag("-EHsc"); if cfg!(feature = "mt_static") { config.static_crt(true); } } else { // Snappy requires C++11. // See: https://github.com/google/snappy/blob/master/CMakeLists.txt#L32-L38 config.flag("-std=c++11"); } if endianness == "big" { config.define("SNAPPY_IS_BIG_ENDIAN", Some("1")); } config.file("snappy/snappy.cc"); config.file("snappy/snappy-sinksource.cc"); config.file("snappy/snappy-c.cc"); config.cpp(true); config.compile("libsnappy.a"); } fn try_to_find_and_link_lib(lib_name: &str) -> bool { println!("cargo:rerun-if-env-changed={lib_name}_COMPILE"); if let Ok(v) = env::var(format!("{lib_name}_COMPILE")) { if v.to_lowercase() == "true" || v == "1" { return false; } } println!("cargo:rerun-if-env-changed={lib_name}_LIB_DIR"); println!("cargo:rerun-if-env-changed={lib_name}_STATIC"); if let Ok(lib_dir) = env::var(format!("{lib_name}_LIB_DIR")) { println!("cargo:rustc-link-search=native={lib_dir}"); let mode = match env::var_os(format!("{lib_name}_STATIC")) { Some(_) => "static", None => "dylib", }; println!("cargo:rustc-link-lib={}={}", mode, lib_name.to_lowercase()); return true; } false } fn cxx_standard() -> String { env::var("ROCKSDB_CXX_STD").map_or("-std=c++17".to_owned(), |cxx_std| { if !cxx_std.starts_with("-std=") { format!("-std={cxx_std}") } else { cxx_std } }) } fn update_submodules() { let program = "git"; let dir = "../"; let args = ["submodule", "update", "--init"]; println!( "Running command: \"{} {}\" in dir: {}", program, args.join(" "), dir ); let ret = Command::new(program).current_dir(dir).args(args).status(); match ret.map(|status| (status.success(), status.code())) { Ok((true, _)) => (), Ok((false, Some(c))) => panic!("Command failed with error code {}", c), Ok((false, None)) => panic!("Command got killed"), Err(e) => panic!("Command failed with error: {}", e), } } fn main() { if !Path::new("rocksdb/AUTHORS").exists() { update_submodules(); } bindgen_rocksdb(); let target = env::var("TARGET").unwrap(); if !try_to_find_and_link_lib("ROCKSDB") { // rocksdb only works with the prebuilt rocksdb system lib on freebsd. // we don't need to rebuild rocksdb if target.contains("freebsd") { println!("cargo:rustc-link-search=native=/usr/local/lib"); let mode = match env::var_os("ROCKSDB_STATIC") { Some(_) => "static", None => "dylib", }; println!("cargo:rustc-link-lib={}=rocksdb", mode); return; } println!("cargo:rerun-if-changed=rocksdb/"); fail_on_empty_directory("rocksdb"); build_rocksdb(); } else { // according to https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L2189 if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") { println!("cargo:rustc-link-lib=dylib=c++"); } else if target.contains("linux") { println!("cargo:rustc-link-lib=dylib=stdc++"); } } if cfg!(feature = "snappy") && !try_to_find_and_link_lib("SNAPPY") { println!("cargo:rerun-if-changed=snappy/"); fail_on_empty_directory("snappy"); build_snappy(); } // Allow dependent crates to locate the sources and output directory of // this crate. Notably, this allows a dependent crate to locate the RocksDB // sources and built archive artifacts provided by this crate. println!( "cargo:cargo_manifest_dir={}", env::var("CARGO_MANIFEST_DIR").unwrap() ); println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap()); } librocksdb-sys-0.17.1+9.9.3/gen_statistics.bash000064400000000000000000000011151046102023000172000ustar 00000000000000File=$1 EnumType=$2 echo "// **** DO NOT modify this file! ****" echo "// This file is generated by cmd:" echo "// gen_statistics.bash $@" echo "iterable_named_enum! {" echo " #[derive(Debug, Copy, Clone, PartialEq, Eq)]" echo " #[repr(u32)]" echo " pub enum $EnumType {" perl -n0e '/const std::vector> '$EnumType'sNameMap.*?\};/sm && print $&' $File | perl -n0e ' while (/\{\s*([\w_]+)\s*,.*?"(.*?)"/smg) { $val = $2; $name = lc($1); $name =~ s/(\b|_)(\w)/\U$2/g; print " $name(\"$val\"),\n" }' echo " }" echo "}" librocksdb-sys-0.17.1+9.9.3/rocksdb_lib_sources.txt000064400000000000000000000231571046102023000201110ustar 00000000000000cache/cache.cc cache/cache_entry_roles.cc cache/cache_key.cc cache/cache_helpers.cc cache/cache_reservation_manager.cc cache/charged_cache.cc cache/clock_cache.cc cache/lru_cache.cc cache/compressed_secondary_cache.cc cache/secondary_cache.cc cache/secondary_cache_adapter.cc cache/sharded_cache.cc cache/tiered_secondary_cache.cc db/arena_wrapped_db_iter.cc db/attribute_group_iterator_impl.cc db/blob/blob_contents.cc db/blob/blob_fetcher.cc db/blob/blob_file_addition.cc db/blob/blob_file_builder.cc db/blob/blob_file_cache.cc db/blob/blob_file_garbage.cc db/blob/blob_file_meta.cc db/blob/blob_file_reader.cc db/blob/blob_garbage_meter.cc db/blob/blob_log_format.cc db/blob/blob_log_sequential_reader.cc db/blob/blob_log_writer.cc db/blob/blob_source.cc db/blob/prefetch_buffer_collection.cc db/builder.cc db/c.cc db/coalescing_iterator.cc db/column_family.cc db/compaction/compaction.cc db/compaction/compaction_iterator.cc db/compaction/compaction_job.cc db/compaction/compaction_picker.cc db/compaction/compaction_picker_fifo.cc db/compaction/compaction_picker_level.cc db/compaction/compaction_picker_universal.cc db/compaction/compaction_service_job.cc db/compaction/compaction_state.cc db/compaction/compaction_outputs.cc db/compaction/sst_partitioner.cc db/compaction/subcompaction_state.cc db/convenience.cc db/db_filesnapshot.cc db/db_impl/compacted_db_impl.cc db/db_impl/db_impl.cc db/db_impl/db_impl_compaction_flush.cc db/db_impl/db_impl_debug.cc db/db_impl/db_impl_experimental.cc db/db_impl/db_impl_files.cc db/db_impl/db_impl_follower.cc db/db_impl/db_impl_open.cc db/db_impl/db_impl_readonly.cc db/db_impl/db_impl_secondary.cc db/db_impl/db_impl_write.cc db/db_info_dumper.cc db/db_iter.cc db/dbformat.cc db/error_handler.cc db/event_helpers.cc db/experimental.cc db/external_sst_file_ingestion_job.cc db/file_indexer.cc db/flush_job.cc db/flush_scheduler.cc db/forward_iterator.cc db/import_column_family_job.cc db/internal_stats.cc db/logs_with_prep_tracker.cc db/log_reader.cc db/log_writer.cc db/malloc_stats.cc db/memtable.cc db/memtable_list.cc db/merge_helper.cc db/merge_operator.cc db/output_validator.cc db/periodic_task_scheduler.cc db/range_del_aggregator.cc db/range_tombstone_fragmenter.cc db/repair.cc db/seqno_to_time_mapping.cc db/snapshot_impl.cc db/table_cache.cc db/table_properties_collector.cc db/transaction_log_impl.cc db/trim_history_scheduler.cc db/version_builder.cc db/version_edit.cc db/version_edit_handler.cc db/version_set.cc db/wal_edit.cc db/wal_manager.cc db/wide/wide_column_serialization.cc db/wide/wide_columns.cc db/wide/wide_columns_helper.cc db/write_batch.cc db/write_batch_base.cc db/write_controller.cc db/write_stall_stats.cc db/write_thread.cc env/composite_env.cc env/env.cc env/env_chroot.cc env/env_encryption.cc env/env_posix.cc env/file_system.cc env/fs_on_demand.cc env/fs_posix.cc env/fs_remap.cc env/file_system_tracer.cc env/io_posix.cc env/mock_env.cc env/unique_id_gen.cc file/delete_scheduler.cc file/file_prefetch_buffer.cc file/file_util.cc file/filename.cc file/line_file_reader.cc file/random_access_file_reader.cc file/read_write_util.cc file/readahead_raf.cc file/sequence_file_reader.cc file/sst_file_manager_impl.cc file/writable_file_writer.cc logging/auto_roll_logger.cc logging/event_logger.cc logging/log_buffer.cc memory/arena.cc memory/concurrent_arena.cc memory/jemalloc_nodump_allocator.cc memory/memkind_kmem_allocator.cc memory/memory_allocator.cc memtable/alloc_tracker.cc memtable/hash_linklist_rep.cc memtable/hash_skiplist_rep.cc memtable/skiplistrep.cc memtable/vectorrep.cc memtable/wbwi_memtable.cc memtable/write_buffer_manager.cc monitoring/histogram.cc monitoring/histogram_windowing.cc monitoring/in_memory_stats_history.cc monitoring/instrumented_mutex.cc monitoring/iostats_context.cc monitoring/perf_context.cc monitoring/perf_level.cc monitoring/persistent_stats_history.cc monitoring/statistics.cc monitoring/thread_status_impl.cc monitoring/thread_status_updater.cc monitoring/thread_status_updater_debug.cc monitoring/thread_status_util.cc monitoring/thread_status_util_debug.cc options/cf_options.cc options/configurable.cc options/customizable.cc options/db_options.cc options/offpeak_time_info.cc options/options.cc options/options_helper.cc options/options_parser.cc port/mmap.cc port/port_posix.cc port/stack_trace.cc table/adaptive/adaptive_table_factory.cc table/block_based/binary_search_index_reader.cc table/block_based/block.cc table/block_based/block_based_table_builder.cc table/block_based/block_based_table_factory.cc table/block_based/block_based_table_iterator.cc table/block_based/block_based_table_reader.cc table/block_based/block_builder.cc table/block_based/block_cache.cc table/block_based/block_prefetcher.cc table/block_based/block_prefix_index.cc table/block_based/data_block_hash_index.cc table/block_based/data_block_footer.cc table/block_based/filter_block_reader_common.cc table/block_based/filter_policy.cc table/block_based/flush_block_policy.cc table/block_based/full_filter_block.cc table/block_based/hash_index_reader.cc table/block_based/index_builder.cc table/block_based/index_reader_common.cc table/block_based/parsed_full_filter_block.cc table/block_based/partitioned_filter_block.cc table/block_based/partitioned_index_iterator.cc table/block_based/partitioned_index_reader.cc table/block_based/reader_common.cc table/block_based/uncompression_dict_reader.cc table/block_fetcher.cc table/cuckoo/cuckoo_table_builder.cc table/cuckoo/cuckoo_table_factory.cc table/cuckoo/cuckoo_table_reader.cc table/format.cc table/get_context.cc table/iterator.cc table/merging_iterator.cc table/compaction_merging_iterator.cc table/meta_blocks.cc table/persistent_cache_helper.cc table/plain/plain_table_bloom.cc table/plain/plain_table_builder.cc table/plain/plain_table_factory.cc table/plain/plain_table_index.cc table/plain/plain_table_key_coding.cc table/plain/plain_table_reader.cc table/sst_file_dumper.cc table/sst_file_reader.cc table/sst_file_writer.cc table/table_factory.cc table/table_properties.cc table/two_level_iterator.cc table/unique_id.cc test_util/sync_point.cc test_util/sync_point_impl.cc test_util/transaction_test_util.cc tools/dump/db_dump_tool.cc trace_replay/trace_record_handler.cc trace_replay/trace_record_result.cc trace_replay/trace_record.cc trace_replay/trace_replay.cc trace_replay/block_cache_tracer.cc trace_replay/io_tracer.cc util/async_file_reader.cc util/build_version.cc util/cleanable.cc util/coding.cc util/compaction_job_stats_impl.cc util/comparator.cc util/compression.cc util/compression_context_cache.cc util/concurrent_task_limiter_impl.cc util/crc32c.cc util/crc32c_arm64.cc util/data_structure.cc util/dynamic_bloom.cc util/hash.cc util/murmurhash.cc util/random.cc util/rate_limiter.cc util/ribbon_config.cc util/slice.cc util/file_checksum_helper.cc util/status.cc util/stderr_logger.cc util/string_util.cc util/thread_local.cc util/threadpool_imp.cc util/udt_util.cc util/write_batch_util.cc util/xxhash.cc utilities/agg_merge/agg_merge.cc utilities/backup/backup_engine.cc utilities/blob_db/blob_compaction_filter.cc utilities/blob_db/blob_db.cc utilities/blob_db/blob_db_impl.cc utilities/blob_db/blob_db_impl_filesnapshot.cc utilities/blob_db/blob_file.cc utilities/cache_dump_load.cc utilities/cache_dump_load_impl.cc utilities/cassandra/cassandra_compaction_filter.cc utilities/cassandra/format.cc utilities/cassandra/merge_operator.cc utilities/checkpoint/checkpoint_impl.cc utilities/compaction_filters.cc utilities/compaction_filters/remove_emptyvalue_compactionfilter.cc utilities/convenience/info_log_finder.cc utilities/counted_fs.cc utilities/debug.cc utilities/env_mirror.cc utilities/env_timed.cc utilities/fault_injection_env.cc utilities/fault_injection_fs.cc utilities/fault_injection_secondary_cache.cc utilities/leveldb_options/leveldb_options.cc utilities/memory/memory_util.cc utilities/merge_operators.cc utilities/merge_operators/max.cc utilities/merge_operators/put.cc utilities/merge_operators/sortlist.cc utilities/merge_operators/string_append/stringappend.cc utilities/merge_operators/string_append/stringappend2.cc utilities/merge_operators/uint64add.cc utilities/merge_operators/bytesxor.cc utilities/object_registry.cc utilities/option_change_migration/option_change_migration.cc utilities/options/options_util.cc utilities/persistent_cache/block_cache_tier.cc utilities/persistent_cache/block_cache_tier_file.cc utilities/persistent_cache/block_cache_tier_metadata.cc utilities/persistent_cache/persistent_cache_tier.cc utilities/persistent_cache/volatile_tier_impl.cc utilities/simulator_cache/cache_simulator.cc utilities/simulator_cache/sim_cache.cc utilities/table_properties_collectors/compact_for_tiering_collector.cc utilities/table_properties_collectors/compact_on_deletion_collector.cc utilities/trace/file_trace_reader_writer.cc utilities/trace/replayer_impl.cc utilities/transactions/lock/lock_manager.cc utilities/transactions/lock/point/point_lock_tracker.cc utilities/transactions/lock/point/point_lock_manager.cc utilities/transactions/optimistic_transaction.cc utilities/transactions/optimistic_transaction_db_impl.cc utilities/transactions/pessimistic_transaction.cc utilities/transactions/pessimistic_transaction_db.cc utilities/transactions/snapshot_checker.cc utilities/transactions/transaction_base.cc utilities/transactions/transaction_db_mutex_impl.cc utilities/transactions/transaction_util.cc utilities/transactions/write_prepared_txn.cc utilities/transactions/write_prepared_txn_db.cc utilities/transactions/write_unprepared_txn.cc utilities/transactions/write_unprepared_txn_db.cc utilities/ttl/db_ttl_impl.cc utilities/types_util.cc utilities/wal_filter.cc utilities/write_batch_with_index/write_batch_with_index.cc utilities/write_batch_with_index/write_batch_with_index_internal.cc librocksdb-sys-0.17.1+9.9.3/snappy-stubs-public.h000064400000000000000000000062521046102023000174220ustar 00000000000000// Copyright 2011 Google Inc. All Rights Reserved. // Author: sesse@google.com (Steinar H. Gunderson) // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Various type stubs for the open-source version of Snappy. // // This file cannot include config.h, as it is included from snappy.h, // which is a public header. Instead, snappy-stubs-public.h is generated by // from snappy-stubs-public.h.in at configure time. #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ #define HAVE_STDINT_H 1 #include #include //#include #if defined(_MSC_VER) #define ssize_t intptr_t #endif #define SNAPPY_MAJOR 1 #define SNAPPY_MINOR 1 #define SNAPPY_PATCHLEVEL 3 #define SNAPPY_VERSION \ ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) #include namespace snappy { #if HAVE_STDINT_H typedef int8_t int8; typedef uint8_t uint8; typedef int16_t int16; typedef uint16_t uint16; typedef int32_t int32; typedef uint32_t uint32; typedef int64_t int64; typedef uint64_t uint64; #else typedef signed char int8; typedef unsigned char uint8; typedef short int16; typedef unsigned short uint16; typedef int int32; typedef unsigned int uint32; typedef long long int64; typedef unsigned long long uint64; #endif typedef std::string string; #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) // Windows does not have an iovec type, yet the concept is universally useful. // It is simple to define it ourselves, so we put it inside our own namespace. struct iovec { void* iov_base; size_t iov_len; }; } // namespace snappy #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ librocksdb-sys-0.17.1+9.9.3/src/lib.rs000064400000000000000000000020271046102023000152240ustar 00000000000000// Copyright 2020 Tyler Neely, Alex Regueiro // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // 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. #![allow( clippy::all, non_snake_case, non_camel_case_types, non_upper_case_globals )] // Ensure the libraries are linked in, despite it not being used directly #[cfg(feature = "bzip2")] extern crate bzip2_sys; #[cfg(feature = "zlib")] extern crate libz_sys; #[cfg(feature = "lz4")] extern crate lz4_sys; #[cfg(feature = "zstd")] extern crate zstd_sys; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); #[cfg(test)] mod test; librocksdb-sys-0.17.1+9.9.3/src/test.rs000064400000000000000000000053121046102023000154350ustar 00000000000000// Copyright 2020 Tyler Neely // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // 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. // use libc::*; use std::ffi::{CStr, CString}; use std::ptr; use std::str; use super::*; pub fn error_message(ptr: *const i8) -> String { let c_str = unsafe { CStr::from_ptr(ptr as *const _) }; let s = str::from_utf8(c_str.to_bytes()).unwrap().to_owned(); unsafe { free(ptr as *mut c_void); } s } #[test] fn internal() { unsafe { let opts = rocksdb_options_create(); assert!(!opts.is_null()); rocksdb_options_increase_parallelism(opts, 0); rocksdb_options_optimize_level_style_compaction(opts, 0); rocksdb_options_set_create_if_missing(opts, u8::from(true)); let rustpath = std::env::temp_dir().join("_rust_rocksdb_internaltest"); let cpath = CString::new(rustpath.into_os_string().to_string_lossy().as_bytes()).unwrap(); let mut err: *mut c_char = ptr::null_mut(); let err_ptr: *mut *mut c_char = &mut err; let db = rocksdb_open(opts, cpath.as_ptr() as *const _, err_ptr); if !err.is_null() { println!("failed to open rocksdb: {}", error_message(err)); } assert!(err.is_null()); let writeopts = rocksdb_writeoptions_create(); assert!(!writeopts.is_null()); let key = b"name\x00"; let val = b"spacejam\x00"; rocksdb_put( db, writeopts.clone(), key.as_ptr() as *const c_char, 4, val.as_ptr() as *const c_char, 8, err_ptr, ); rocksdb_writeoptions_destroy(writeopts); assert!(err.is_null()); let readopts = rocksdb_readoptions_create(); assert!(!readopts.is_null()); let mut val_len: size_t = 0; let val_len_ptr = &mut val_len as *mut size_t; rocksdb_get( db, readopts.clone(), key.as_ptr() as *const c_char, 4, val_len_ptr, err_ptr, ); rocksdb_readoptions_destroy(readopts); assert!(err.is_null()); rocksdb_close(db); rocksdb_destroy_db(opts, cpath.as_ptr() as *const _, err_ptr); assert!(err.is_null()); } } librocksdb-sys-0.17.1+9.9.3/tests/ffi.rs000064400000000000000000001255031046102023000156020ustar 00000000000000// Copyright 2016 Alex Regueiro // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // 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. // // This code is based on , revision a10e8a056d569acf6a52045124e6414ad33bdfcd. #![allow( non_snake_case, non_upper_case_globals, unused_mut, unused_unsafe, unused_variables )] use libc::*; use librocksdb_sys::*; use std::borrow::Cow; use std::env; use std::ffi::{CStr, CString}; use std::io::Write; use std::path::PathBuf; use std::ptr; use std::slice; use std::str; use uuid::Uuid; macro_rules! err_println { ($($arg:tt)*) => (writeln!(&mut ::std::io::stderr(), $($arg)*).expect("failed printing to stderr")); } macro_rules! cstrp { ($s:expr) => {{ static CSTR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(concat!($s, "\0").as_bytes()) }; CSTR.as_ptr() }}; } static mut phase: &'static str = ""; // static mut dbname: *mut c_uchar = ptr::null_mut(); // static mut dbbackupname: *mut c_uchar = ptr::null_mut(); unsafe fn strndup(s: *const c_char, n: size_t) -> *mut c_char { let r: *mut c_char = malloc(n + 1) as *mut c_char; if r.is_null() { return r; } strncpy(r, s, n) } unsafe fn rstr<'a>(s: *const c_char) -> Cow<'a, str> { CStr::from_ptr(s).to_string_lossy() } fn GetTempDir() -> PathBuf { option_env!("TEST_TMPDIR") .filter(|s| !s.is_empty()) .map(PathBuf::from) .unwrap_or_else(|| env::temp_dir()) } unsafe fn StartPhase(name: &'static str) { err_println!("=== Test {}\n", name); phase = name; } macro_rules! CheckNoError { ($err:ident) => { unsafe { assert!($err.is_null(), "{}: {}", phase, rstr($err)); } }; } macro_rules! CheckCondition { ($cond:expr) => { unsafe { assert!($cond, "{}: {}", phase, stringify!($cond)); } }; } unsafe fn CheckEqual(expected: *const c_char, actual: *const c_char, n: size_t) { let is_equal = if expected.is_null() && actual.is_null() { true } else if !expected.is_null() && !actual.is_null() && n == strlen(expected) && memcmp(expected as *const c_void, actual as *const c_void, n) == 0 { true } else { false }; if !is_equal { panic!( "{}: expected '{}', got '{}'", phase, rstr(strndup(expected, n)), rstr(strndup(actual, 5)) ); } } unsafe fn Free(ptr: *mut *mut T) { if !(*ptr).is_null() { free(*ptr as *mut c_void); *ptr = ptr::null_mut(); } } unsafe fn CheckGet( mut db: *mut rocksdb_t, options: *mut rocksdb_readoptions_t, key: *const c_char, expected: *const c_char, ) { let mut err: *mut c_char = ptr::null_mut(); let mut val_len: size_t = 0; let mut val: *mut c_char = rocksdb_get(db, options, key, strlen(key), &mut val_len, &mut err); CheckNoError!(err); CheckEqual(expected, val, val_len); Free(&mut val); } unsafe fn CheckGetCF( db: *mut rocksdb_t, options: *const rocksdb_readoptions_t, handle: *mut rocksdb_column_family_handle_t, key: *const c_char, expected: *const c_char, ) { let mut err: *mut c_char = ptr::null_mut(); let mut val_len: size_t = 0; let mut val: *mut c_char = rocksdb_get_cf( db, options, handle, key, strlen(key), &mut val_len, &mut err, ); CheckNoError!(err); CheckEqual(expected, val, val_len); Free(&mut val); } unsafe fn CheckIter(iter: *mut rocksdb_iterator_t, key: *const c_char, val: *const c_char) { let mut len: size_t = 0; let mut str: *const c_char; str = rocksdb_iter_key(iter, &mut len); CheckEqual(key, str, len); str = rocksdb_iter_value(iter, &mut len); CheckEqual(val, str, len); } // Callback from rocksdb_writebatch_iterate() unsafe extern "C" fn CheckPut( ptr: *mut c_void, k: *const c_char, klen: size_t, v: *const c_char, vlen: size_t, ) { let mut state: *mut c_int = ptr as *mut c_int; CheckCondition!(*state < 2); match *state { 0 => { CheckEqual(cstrp!("bar"), k, klen); CheckEqual(cstrp!("b"), v, vlen); } 1 => { CheckEqual(cstrp!("box"), k, klen); CheckEqual(cstrp!("c"), v, vlen); } _ => {} } *state += 1; } // Callback from rocksdb_writebatch_iterate() unsafe extern "C" fn CheckDel(ptr: *mut c_void, k: *const c_char, klen: size_t) { let mut state: *mut c_int = ptr as *mut c_int; CheckCondition!(*state == 2); CheckEqual(cstrp!("bar"), k, klen); *state += 1; } unsafe extern "C" fn CmpDestroy(arg: *mut c_void) {} unsafe extern "C" fn CmpCompare( arg: *mut c_void, a: *const c_char, alen: size_t, b: *const c_char, blen: size_t, ) -> c_int { let n = if alen < blen { alen } else { blen }; let mut r = memcmp(a as *const c_void, b as *const c_void, n); if r == 0 { if alen < blen { r = -1; } else if alen > blen { r = 1; } } r } unsafe extern "C" fn CmpName(arg: *mut c_void) -> *const c_char { cstrp!("foo") } // Custom compaction filter static mut fake_filter_result: c_uchar = 1; unsafe extern "C" fn CFilterDestroy(arg: *mut c_void) {} unsafe extern "C" fn CFilterName(arg: *mut c_void) -> *const c_char { cstrp!("foo") } unsafe extern "C" fn CFilterFilter( arg: *mut c_void, level: c_int, 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 u8, ) -> c_uchar { if key_length == 3 { if memcmp( key.cast::(), cstrp!("bar").cast::(), key_length, ) == 0 { return 1; } else if memcmp( key.cast::(), cstrp!("baz").cast::(), key_length, ) == 0 { *value_changed = 1; *new_value = cstrp!("newbazvalue") as *mut c_char; *new_value_length = 11; return 0; } } 0 } unsafe extern "C" fn CFilterFactoryDestroy(arg: *mut c_void) {} unsafe extern "C" fn CFilterFactoryName(arg: *mut c_void) -> *const c_char { cstrp!("foo") } unsafe extern "C" fn CFilterCreate( arg: *mut c_void, context: *mut rocksdb_compactionfiltercontext_t, ) -> *mut rocksdb_compactionfilter_t { rocksdb_compactionfilter_create( ptr::null_mut(), Some(CFilterDestroy), Some(CFilterFilter), Some(CFilterName), ) } unsafe fn CheckCompaction( dbname: *const c_char, db: *mut rocksdb_t, options: *const rocksdb_options_t, roptions: *mut rocksdb_readoptions_t, woptions: *mut rocksdb_writeoptions_t, ) -> *mut rocksdb_t { let mut err: *mut c_char = ptr::null_mut(); let db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_put( db, woptions, cstrp!("foo"), 3, cstrp!("foovalue"), 8, &mut err, ); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); rocksdb_put( db, woptions, cstrp!("bar"), 3, cstrp!("barvalue"), 8, &mut err, ); CheckNoError!(err); CheckGet(db, roptions, cstrp!("bar"), cstrp!("barvalue")); rocksdb_put( db, woptions, cstrp!("baz"), 3, cstrp!("bazvalue"), 8, &mut err, ); CheckNoError!(err); CheckGet(db, roptions, cstrp!("baz"), cstrp!("bazvalue")); // Force compaction rocksdb_compact_range(db, ptr::null(), 0, ptr::null(), 0); // should have filtered bar, but not foo CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); CheckGet(db, roptions, cstrp!("bar"), ptr::null()); CheckGet(db, roptions, cstrp!("baz"), cstrp!("newbazvalue")); db } // Custom merge operator unsafe extern "C" fn MergeOperatorDestroy(arg: *mut c_void) {} unsafe extern "C" fn MergeOperatorName(arg: *mut c_void) -> *const c_char { cstrp!("foo") } unsafe extern "C" fn MergeOperatorFullMerge( arg: *mut c_void, key: *const c_char, key_length: size_t, existing_value: *const c_char, existing_value_length: size_t, operands_list: *const *const c_char, operands_list_length: *const size_t, num_operands: c_int, success: *mut u8, new_value_length: *mut size_t, ) -> *mut c_char { *new_value_length = 4; *success = 1; let result: *mut c_char = malloc(4) as *mut _; memcpy(result as *mut _, cstrp!("fake") as *mut _, 4); result } unsafe extern "C" fn MergeOperatorPartialMerge( arg: *mut c_void, key: *const c_char, key_length: size_t, operands_list: *const *const c_char, operands_list_length: *const size_t, num_operands: c_int, success: *mut u8, new_value_length: *mut size_t, ) -> *mut c_char { *new_value_length = 4; *success = 1; let result: *mut c_char = malloc(4) as *mut _; memcpy(result as *mut _, cstrp!("fake") as *const _, 4); result } #[test] fn ffi() { unsafe { let mut db: *mut rocksdb_t; let mut cmp: *mut rocksdb_comparator_t; let mut cache: *mut rocksdb_cache_t; let mut env: *mut rocksdb_env_t; let mut options: *mut rocksdb_options_t; let mut table_options: *mut rocksdb_block_based_table_options_t; let mut roptions: *mut rocksdb_readoptions_t; let mut woptions: *mut rocksdb_writeoptions_t; let mut err: *mut c_char = ptr::null_mut(); let run: c_int = -1; let test_uuid = Uuid::new_v4().simple(); let dbname = { let mut dir = GetTempDir(); dir.push(format!("rocksdb_c_test-{}", test_uuid)); let path = dir.to_str().unwrap(); CString::new(path).unwrap() }; let dbbackupname = { let mut dir = GetTempDir(); dir.push(format!("rocksdb_c_test-{}-backup", test_uuid)); let path = dir.to_str().unwrap(); CString::new(path).unwrap() }; let dbname = dbname.as_ptr(); let dbbackupname = dbbackupname.as_ptr(); StartPhase("create_objects"); cmp = rocksdb_comparator_create( ptr::null_mut(), Some(CmpDestroy), Some(CmpCompare), Some(CmpName), ); env = rocksdb_create_default_env(); cache = rocksdb_cache_create_lru(100000); options = rocksdb_options_create(); rocksdb_options_set_comparator(options, cmp); rocksdb_options_set_error_if_exists(options, 1); rocksdb_options_set_env(options, env); rocksdb_options_set_info_log(options, ptr::null_mut()); rocksdb_options_set_write_buffer_size(options, 100000); rocksdb_options_set_paranoid_checks(options, 1); rocksdb_options_set_max_open_files(options, 10); table_options = rocksdb_block_based_options_create(); rocksdb_block_based_options_set_block_cache(table_options, cache); rocksdb_options_set_block_based_table_factory(options, table_options); let no_compression = rocksdb_no_compression as c_int; rocksdb_options_set_compression(options, no_compression); rocksdb_options_set_compression_options(options, -14, -1, 0, 0); let mut compression_levels = vec![ no_compression, no_compression, no_compression, no_compression, ]; rocksdb_options_set_compression_per_level( options, compression_levels.as_mut_ptr(), compression_levels.len() as size_t, ); roptions = rocksdb_readoptions_create(); rocksdb_readoptions_set_verify_checksums(roptions, 1); rocksdb_readoptions_set_fill_cache(roptions, 0); woptions = rocksdb_writeoptions_create(); rocksdb_writeoptions_set_sync(woptions, 1); StartPhase("destroy"); rocksdb_destroy_db(options, dbname, &mut err); Free(&mut err); StartPhase("open_error"); rocksdb_open(options, dbname, &mut err); CheckCondition!(!err.is_null()); Free(&mut err); StartPhase("open"); rocksdb_options_set_create_if_missing(options, 1); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo") as *const _, ptr::null()); StartPhase("put"); rocksdb_put(db, woptions, cstrp!("foo"), 3, cstrp!("hello"), 5, &mut err); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo"), cstrp!("hello")); StartPhase("backup_and_restore"); { rocksdb_destroy_db(options, dbbackupname, &mut err); CheckNoError!(err); let be = rocksdb_backup_engine_open(options, dbbackupname, &mut err); CheckNoError!(err); rocksdb_backup_engine_create_new_backup(be, db, &mut err); CheckNoError!(err); // need a change to trigger a new backup rocksdb_delete(db, woptions, cstrp!("does-not-exist"), 14, &mut err); CheckNoError!(err); rocksdb_backup_engine_create_new_backup(be, db, &mut err); CheckNoError!(err); let bei: *const rocksdb_backup_engine_info_t = rocksdb_backup_engine_get_backup_info(be); CheckCondition!(rocksdb_backup_engine_info_count(bei) > 1); rocksdb_backup_engine_info_destroy(bei); rocksdb_backup_engine_purge_old_backups(be, 1, &mut err); CheckNoError!(err); let bei: *const rocksdb_backup_engine_info_t = rocksdb_backup_engine_get_backup_info(be); CheckCondition!(rocksdb_backup_engine_info_count(bei) == 1); rocksdb_backup_engine_info_destroy(bei); rocksdb_delete(db, woptions, cstrp!("foo"), 3, &mut err); CheckNoError!(err); rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); CheckNoError!(err); let restore_options = rocksdb_restore_options_create(); rocksdb_restore_options_set_keep_log_files(restore_options, 0); rocksdb_backup_engine_restore_db_from_latest_backup( be, dbname, dbname, restore_options, &mut err, ); CheckNoError!(err); rocksdb_restore_options_destroy(restore_options); rocksdb_options_set_error_if_exists(options, 0); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_options_set_error_if_exists(options, 1); CheckGet(db, roptions, cstrp!("foo"), cstrp!("hello")); rocksdb_backup_engine_close(be); } StartPhase("compactall"); rocksdb_compact_range(db, ptr::null(), 0, ptr::null(), 0); CheckGet(db, roptions, cstrp!("foo"), cstrp!("hello")); StartPhase("compactrange"); rocksdb_compact_range(db, cstrp!("a"), 1, cstrp!("z"), 1); CheckGet(db, roptions, cstrp!("foo"), cstrp!("hello")); StartPhase("writebatch"); { let mut wb = rocksdb_writebatch_create(); rocksdb_writebatch_put(wb, cstrp!("foo"), 3, cstrp!("a"), 1); rocksdb_writebatch_clear(wb); rocksdb_writebatch_put(wb, cstrp!("bar"), 3, cstrp!("b"), 1); rocksdb_writebatch_put(wb, cstrp!("box"), 3, cstrp!("c"), 1); rocksdb_writebatch_delete(wb, cstrp!("bar"), 3); rocksdb_write(db, woptions, wb, &mut err); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo"), cstrp!("hello")); CheckGet(db, roptions, cstrp!("bar"), ptr::null()); CheckGet(db, roptions, cstrp!("box"), cstrp!("c")); let mut pos: c_int = 0; rocksdb_writebatch_iterate( wb, (&mut pos as *mut c_int).cast::(), Some(CheckPut), Some(CheckDel), ); CheckCondition!(pos == 3); rocksdb_writebatch_destroy(wb); } StartPhase("writebatch_vectors"); { let wb = rocksdb_writebatch_create(); let k_list: [*const c_char; 2] = [cstrp!("z"), cstrp!("ap")]; let k_sizes: [size_t; 2] = [1, 2]; let v_list: [*const c_char; 3] = [cstrp!("x"), cstrp!("y"), cstrp!("z")]; let v_sizes: [size_t; 3] = [1, 1, 1]; rocksdb_writebatch_putv( wb, k_list.len() as c_int, k_list.as_ptr(), k_sizes.as_ptr(), v_list.len() as c_int, v_list.as_ptr(), v_sizes.as_ptr(), ); rocksdb_write(db, woptions, wb, &mut err); CheckNoError!(err); CheckGet(db, roptions, cstrp!("zap"), cstrp!("xyz")); rocksdb_writebatch_delete(wb, cstrp!("zap"), 3); rocksdb_write(db, woptions, wb, &mut err); CheckNoError!(err); CheckGet(db, roptions, cstrp!("zap"), ptr::null()); rocksdb_writebatch_destroy(wb); } StartPhase("writebatch_rep"); { let wb1: *mut rocksdb_writebatch_t = rocksdb_writebatch_create(); rocksdb_writebatch_put(wb1, cstrp!("baz"), 3, cstrp!("d"), 1); rocksdb_writebatch_put(wb1, cstrp!("quux"), 4, cstrp!("e"), 1); rocksdb_writebatch_delete(wb1, cstrp!("quux"), 4); let mut repsize1: size_t = 0; let mut rep = rocksdb_writebatch_data(wb1, &mut repsize1) as *const c_void; let mut wb2 = rocksdb_writebatch_create_from(rep as *const c_char, repsize1); CheckCondition!(rocksdb_writebatch_count(wb1) == rocksdb_writebatch_count(wb2)); let mut repsize2: size_t = 0; CheckCondition!( memcmp( rep, rocksdb_writebatch_data(wb2, &mut repsize2) as *const c_void, repsize1 ) == 0 ); rocksdb_writebatch_destroy(wb1); rocksdb_writebatch_destroy(wb2); } StartPhase("iter"); { let mut iter = rocksdb_create_iterator(db, roptions); CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_seek_to_first(iter); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("box"), cstrp!("c")); rocksdb_iter_next(iter); CheckIter(iter, cstrp!("foo"), cstrp!("hello")); rocksdb_iter_prev(iter); CheckIter(iter, cstrp!("box"), cstrp!("c")); rocksdb_iter_prev(iter); CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_seek_to_last(iter); CheckIter(iter, cstrp!("foo"), cstrp!("hello")); rocksdb_iter_seek(iter, cstrp!("b"), 1); CheckIter(iter, cstrp!("box"), cstrp!("c")); rocksdb_iter_get_error(iter, &mut err); CheckNoError!(err); rocksdb_iter_destroy(iter); } StartPhase("multiget"); { let keys: [*const c_char; 3] = [cstrp!("box"), cstrp!("foo"), cstrp!("notfound")]; let keys_sizes: [size_t; 3] = [3, 3, 8]; let mut vals: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; let mut vals_sizes: [size_t; 3] = [0, 0, 0]; let mut errs: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; rocksdb_multi_get( db, roptions, 3, keys.as_ptr(), keys_sizes.as_ptr(), vals.as_mut_ptr(), vals_sizes.as_mut_ptr(), errs.as_mut_ptr(), ); for i in 0..3 { CheckEqual(ptr::null(), errs[i], 0); match i { 0 => CheckEqual(cstrp!("c"), vals[i], vals_sizes[i]), 1 => CheckEqual(cstrp!("hello"), vals[i], vals_sizes[i]), 2 => CheckEqual(ptr::null(), vals[i], vals_sizes[i]), _ => {} } Free(&mut vals[i]); } } StartPhase("approximate_sizes"); { let mut sizes: [u64; 2] = [0, 0]; let start: [*const c_char; 2] = [cstrp!("a"), cstrp!("k00000000000000010000")]; let start_len: [size_t; 2] = [1, 21]; let limit: [*const c_char; 2] = [cstrp!("k00000000000000010000"), cstrp!("z")]; let limit_len: [size_t; 2] = [21, 1]; rocksdb_writeoptions_set_sync(woptions, 0); for i in 0..20000 { let keybuf = CString::new(format!("k{:020}", i)).unwrap(); let key = keybuf.to_bytes_with_nul(); let valbuf = CString::new(format!("v{:020}", i)).unwrap(); let val = valbuf.to_bytes_with_nul(); rocksdb_put( db, woptions, key.as_ptr() as *const c_char, key.len() as size_t, val.as_ptr() as *const c_char, val.len() as size_t, &mut err, ); CheckNoError!(err); } rocksdb_approximate_sizes( db, 2, start.as_ptr(), start_len.as_ptr(), limit.as_ptr(), limit_len.as_ptr(), sizes.as_mut_ptr(), &mut err, ); CheckNoError!(err); CheckCondition!(sizes[0] > 0); CheckCondition!(sizes[1] > 0); } StartPhase("property"); { let mut prop: *mut c_char; prop = rocksdb_property_value(db, cstrp!("nosuchprop")); CheckCondition!(prop.is_null()); prop = rocksdb_property_value(db, cstrp!("rocksdb.stats")); CheckCondition!(!prop.is_null()); Free(&mut prop); } StartPhase("snapshot"); { let snap: *const rocksdb_snapshot_t = rocksdb_create_snapshot(db); rocksdb_delete(db, woptions, cstrp!("foo"), 3, &mut err); CheckNoError!(err); rocksdb_readoptions_set_snapshot(roptions, snap); CheckGet(db, roptions, cstrp!("foo"), cstrp!("hello")); rocksdb_readoptions_set_snapshot(roptions, ptr::null()); CheckGet(db, roptions, cstrp!("foo"), ptr::null()); rocksdb_release_snapshot(db, snap); } StartPhase("repair"); { // If we do not compact here, then the lazy deletion of files (https://reviews.facebook.net/D6123) would leave around deleted files and the repair process will find those files and put them back into the database. rocksdb_compact_range(db, ptr::null(), 0, ptr::null(), 0); rocksdb_close(db); rocksdb_options_set_create_if_missing(options, 0); rocksdb_options_set_error_if_exists(options, 0); // rocksdb_options_set_wal_recovery_mode(options, 2); rocksdb_repair_db(options, dbname, &mut err); CheckNoError!(err); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo"), ptr::null()); CheckGet(db, roptions, cstrp!("bar"), ptr::null()); CheckGet(db, roptions, cstrp!("box"), cstrp!("c")); rocksdb_options_set_create_if_missing(options, 1); rocksdb_options_set_error_if_exists(options, 1); } StartPhase("filter"); for run in 0..2 { CheckNoError!(err); let mut policy: *mut rocksdb_filterpolicy_t = rocksdb_filterpolicy_create_bloom(10.0); rocksdb_block_based_options_set_filter_policy(table_options, policy); // Create new database rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); rocksdb_options_set_block_based_table_factory(options, table_options); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_put( db, woptions, cstrp!("foo"), 3, cstrp!("foovalue"), 8, &mut err, ); CheckNoError!(err); rocksdb_put( db, woptions, cstrp!("bar"), 3, cstrp!("barvalue"), 8, &mut err, ); CheckNoError!(err); rocksdb_compact_range(db, ptr::null(), 0, ptr::null(), 0); fake_filter_result = 1; CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); CheckGet(db, roptions, cstrp!("bar"), cstrp!("barvalue")); if phase == "" { // Must not find value when custom filter returns false fake_filter_result = 0; CheckGet(db, roptions, cstrp!("foo"), ptr::null()); CheckGet(db, roptions, cstrp!("bar"), ptr::null()); fake_filter_result = 1; CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); CheckGet(db, roptions, cstrp!("bar"), cstrp!("barvalue")); } // Reset the policy rocksdb_block_based_options_set_filter_policy(table_options, ptr::null_mut()); rocksdb_options_set_block_based_table_factory(options, table_options); } StartPhase("compaction_filter"); { let options_with_filter = rocksdb_options_create(); rocksdb_options_set_create_if_missing(options_with_filter, 1); let cfilter = rocksdb_compactionfilter_create( ptr::null_mut(), Some(CFilterDestroy), Some(CFilterFilter), Some(CFilterName), ); // Create new database rocksdb_close(db); rocksdb_destroy_db(options_with_filter, dbname, &mut err); rocksdb_options_set_compaction_filter(options_with_filter, cfilter); db = CheckCompaction(dbname, db, options_with_filter, roptions, woptions); rocksdb_options_set_compaction_filter(options_with_filter, ptr::null_mut()); rocksdb_compactionfilter_destroy(cfilter); rocksdb_options_destroy(options_with_filter); } StartPhase("compaction_filter_factory"); { let mut options_with_filter_factory = rocksdb_options_create(); rocksdb_options_set_create_if_missing(options_with_filter_factory, 1); let mut factory = rocksdb_compactionfilterfactory_create( ptr::null_mut(), Some(CFilterFactoryDestroy), Some(CFilterCreate), Some(CFilterFactoryName), ); // Create new database rocksdb_close(db); rocksdb_destroy_db(options_with_filter_factory, dbname, &mut err); rocksdb_options_set_compaction_filter_factory(options_with_filter_factory, factory); db = CheckCompaction(dbname, db, options_with_filter_factory, roptions, woptions); rocksdb_options_set_compaction_filter_factory( options_with_filter_factory, ptr::null_mut(), ); rocksdb_options_destroy(options_with_filter_factory); } StartPhase("merge_operator"); { let mut merge_operator = rocksdb_mergeoperator_create( ptr::null_mut(), Some(MergeOperatorDestroy), Some(MergeOperatorFullMerge), Some(MergeOperatorPartialMerge), None, Some(MergeOperatorName), ); // Create new database rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); rocksdb_options_set_merge_operator(options, merge_operator); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_put( db, woptions, cstrp!("foo"), 3, cstrp!("foovalue"), 8, &mut err, ); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); rocksdb_merge( db, woptions, cstrp!("foo"), 3, cstrp!("barvalue"), 8, &mut err, ); CheckNoError!(err); CheckGet(db, roptions, cstrp!("foo"), cstrp!("fake")); // Merge of a non-existing value rocksdb_merge( db, woptions, cstrp!("bar"), 3, cstrp!("barvalue"), 8, &mut err, ); CheckNoError!(err); CheckGet(db, roptions, cstrp!("bar"), cstrp!("fake")); } StartPhase("columnfamilies"); { rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); CheckNoError!(err); let mut db_options = rocksdb_options_create(); rocksdb_options_set_create_if_missing(db_options, 1); db = rocksdb_open(db_options, dbname, &mut err); CheckNoError!(err); let mut cfh = rocksdb_create_column_family(db, db_options, cstrp!("cf1"), &mut err); rocksdb_column_family_handle_destroy(cfh); CheckNoError!(err); rocksdb_close(db); let mut cflen: size_t = 0; let column_fams_raw = rocksdb_list_column_families(db_options, dbname, &mut cflen, &mut err); let column_fams = slice::from_raw_parts(column_fams_raw, cflen as usize); CheckEqual(cstrp!("default"), column_fams[0], 7); CheckEqual(cstrp!("cf1"), column_fams[1], 3); CheckCondition!(cflen == 2); rocksdb_list_column_families_destroy(column_fams_raw, cflen); let mut cf_options = rocksdb_options_create(); 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_mut_ptr(), cf_opts.as_mut_ptr(), handles.as_mut_ptr(), &mut err, ); CheckNoError!(err); rocksdb_put_cf( db, woptions, handles[1], cstrp!("foo"), 3, cstrp!("hello"), 5, &mut err, ); CheckNoError!(err); CheckGetCF(db, roptions, handles[1], cstrp!("foo"), cstrp!("hello")); rocksdb_delete_cf(db, woptions, handles[1], cstrp!("foo"), 3, &mut err); CheckNoError!(err); CheckGetCF(db, roptions, handles[1], cstrp!("foo"), ptr::null()); let mut wb = rocksdb_writebatch_create(); rocksdb_writebatch_put_cf(wb, handles[1], cstrp!("baz"), 3, cstrp!("a"), 1); rocksdb_writebatch_clear(wb); rocksdb_writebatch_put_cf(wb, handles[1], cstrp!("bar"), 3, cstrp!("b"), 1); rocksdb_writebatch_put_cf(wb, handles[1], cstrp!("box"), 3, cstrp!("c"), 1); rocksdb_writebatch_delete_cf(wb, handles[1], cstrp!("bar"), 3); rocksdb_write(db, woptions, wb, &mut err); CheckNoError!(err); CheckGetCF(db, roptions, handles[1], cstrp!("baz"), ptr::null()); CheckGetCF(db, roptions, handles[1], cstrp!("bar"), ptr::null()); CheckGetCF(db, roptions, handles[1], cstrp!("box"), cstrp!("c")); rocksdb_writebatch_destroy(wb); let keys: [*const c_char; 3] = [cstrp!("box"), cstrp!("box"), cstrp!("barfooxx")]; let get_handles: [*const rocksdb_column_family_handle_t; 3] = [handles[0], handles[1], handles[1]]; let keys_sizes: [size_t; 3] = [3, 3, 8]; let mut vals: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; let mut vals_sizes: [size_t; 3] = [0, 0, 0]; let mut errs: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; rocksdb_multi_get_cf( db, roptions, get_handles.as_ptr(), 3, keys.as_ptr(), keys_sizes.as_ptr(), vals.as_mut_ptr(), vals_sizes.as_mut_ptr(), errs.as_mut_ptr(), ); for i in 0..3 { CheckEqual(ptr::null(), errs[i], 0); match i { 0 => CheckEqual(ptr::null(), vals[i], vals_sizes[i]), // wrong cf 1 => CheckEqual(cstrp!("c"), vals[i], vals_sizes[i]), // bingo 2 => CheckEqual(ptr::null(), vals[i], vals_sizes[i]), // normal not found _ => {} } Free(&mut vals[i]); } let mut iter = rocksdb_create_iterator_cf(db, roptions, handles[1]); CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_seek_to_first(iter); CheckCondition!(rocksdb_iter_valid(iter) != 0); let mut i: u32 = 0; while rocksdb_iter_valid(iter) != 0 { rocksdb_iter_next(iter); i += 1; } CheckCondition!(i == 1); rocksdb_iter_get_error(iter, &mut err); CheckNoError!(err); rocksdb_iter_destroy(iter); let mut iters_cf_handles: [*mut rocksdb_column_family_handle_t; 2] = [handles[0], handles[1]]; let mut iters_handles: [*mut rocksdb_iterator_t; 2] = [ptr::null_mut(), ptr::null_mut()]; rocksdb_create_iterators( db, roptions, iters_cf_handles.as_mut_ptr(), iters_handles.as_mut_ptr(), 2, &mut err, ); CheckNoError!(err); iter = iters_handles[0]; CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_seek_to_first(iter); CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_destroy(iter); iter = iters_handles[1]; CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_seek_to_first(iter); CheckCondition!(rocksdb_iter_valid(iter) != 0); let mut i: u32 = 0; while rocksdb_iter_valid(iter) != 0 { rocksdb_iter_next(iter); i += 1; } CheckCondition!(i == 1); rocksdb_iter_get_error(iter, &mut err); CheckNoError!(err); rocksdb_iter_destroy(iter); rocksdb_drop_column_family(db, handles[1], &mut err); CheckNoError!(err); for i in 0..2 { rocksdb_column_family_handle_destroy(handles[i]); } rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); rocksdb_options_destroy(db_options); rocksdb_options_destroy(cf_options); } StartPhase("prefix"); { // Create new database rocksdb_options_set_allow_mmap_reads(options, 1); rocksdb_options_set_prefix_extractor( options, rocksdb_slicetransform_create_fixed_prefix(3), ); rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4); rocksdb_options_set_plain_table_factory(options, 4, 10, 0.75, 16, 0, 0, 0, 0); rocksdb_options_set_allow_concurrent_memtable_write(options, 0); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("foo1"), 4, cstrp!("foo"), 3, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("foo2"), 4, cstrp!("foo"), 3, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("foo3"), 4, cstrp!("foo"), 3, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("bar1"), 4, cstrp!("bar"), 3, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("bar2"), 4, cstrp!("bar"), 3, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("bar3"), 4, cstrp!("bar"), 3, &mut err); CheckNoError!(err); let mut iter = rocksdb_create_iterator(db, roptions); CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_seek(iter, cstrp!("bar"), 3); rocksdb_iter_get_error(iter, &mut err); CheckNoError!(err); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("bar1"), cstrp!("bar")); rocksdb_iter_next(iter); CheckIter(iter, cstrp!("bar2"), cstrp!("bar")); rocksdb_iter_next(iter); CheckIter(iter, cstrp!("bar3"), cstrp!("bar")); rocksdb_iter_get_error(iter, &mut err); CheckNoError!(err); rocksdb_iter_destroy(iter); rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); } StartPhase("cuckoo_options"); { let mut cuckoo_options = rocksdb_cuckoo_options_create(); rocksdb_cuckoo_options_set_hash_ratio(cuckoo_options, 0.5); rocksdb_cuckoo_options_set_max_search_depth(cuckoo_options, 200); rocksdb_cuckoo_options_set_cuckoo_block_size(cuckoo_options, 10); rocksdb_cuckoo_options_set_identity_as_first_hash(cuckoo_options, 1); rocksdb_cuckoo_options_set_use_module_hash(cuckoo_options, 0); rocksdb_options_set_cuckoo_table_factory(options, cuckoo_options); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_cuckoo_options_destroy(cuckoo_options); } StartPhase("iterate_upper_bound"); { // Create new empty database rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); CheckNoError!(err); rocksdb_options_set_prefix_extractor(options, ptr::null_mut()); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("a"), 1, cstrp!("0"), 1, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("foo"), 3, cstrp!("bar"), 3, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("foo1"), 4, cstrp!("bar1"), 4, &mut err); CheckNoError!(err); rocksdb_put(db, woptions, cstrp!("g1"), 2, cstrp!("0"), 1, &mut err); CheckNoError!(err); // testing basic case with no iterate_upper_bound and no prefix_extractor { rocksdb_readoptions_set_iterate_upper_bound(roptions, ptr::null(), 0); let mut iter = rocksdb_create_iterator(db, roptions); rocksdb_iter_seek(iter, cstrp!("foo"), 3); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("foo"), cstrp!("bar")); rocksdb_iter_next(iter); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("foo1"), cstrp!("bar1")); rocksdb_iter_next(iter); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("g1"), cstrp!("0")); rocksdb_iter_destroy(iter); } // testing iterate_upper_bound and forward iterator // to make sure it stops at bound { // iterate_upper_bound points beyond the last expected entry rocksdb_readoptions_set_iterate_upper_bound(roptions, cstrp!("foo2"), 4); let mut iter = rocksdb_create_iterator(db, roptions); rocksdb_iter_seek(iter, cstrp!("foo"), 3); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("foo"), cstrp!("bar")); rocksdb_iter_next(iter); CheckCondition!(rocksdb_iter_valid(iter) != 0); CheckIter(iter, cstrp!("foo1"), cstrp!("bar1")); rocksdb_iter_next(iter); // should stop here... CheckCondition!(rocksdb_iter_valid(iter) == 0); rocksdb_iter_destroy(iter); } } // Simple sanity check that setting memtable rep works. StartPhase("memtable_reps"); { // Create database with vector memtable. rocksdb_close(db); rocksdb_destroy_db(options, dbname, &mut err); CheckNoError!(err); rocksdb_options_set_memtable_vector_rep(options); db = rocksdb_open(options, dbname, &mut err); CheckNoError!(err); // // Create database with hash skiplist memtable. // rocksdb_close(db); // rocksdb_destroy_db(options, dbname, &mut err); // CheckNoError!(err); // // rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4); // db = rocksdb_open(options, dbname, &mut err); // CheckNoError!(err); } StartPhase("cleanup"); rocksdb_close(db); rocksdb_options_destroy(options); rocksdb_block_based_options_destroy(table_options); rocksdb_readoptions_destroy(roptions); rocksdb_writeoptions_destroy(woptions); rocksdb_cache_destroy(cache); rocksdb_comparator_destroy(cmp); rocksdb_env_destroy(env); err_println!("PASS"); } }