Applying rustfmt to all code...

master
Jordan Terrell 6 years ago
parent c04f0f5522
commit a824913a36
  1. 25
      librocksdb-sys/build.rs
  2. 672
      librocksdb-sys/tests/ffi.rs

@ -1,5 +1,5 @@
extern crate cc;
extern crate bindgen; extern crate bindgen;
extern crate cc;
extern crate glob; extern crate glob;
use std::env; use std::env;
@ -94,7 +94,6 @@ fn build_rocksdb() {
config.define("OS_MACOSX", Some("1")); config.define("OS_MACOSX", Some("1"));
config.define("ROCKSDB_PLATFORM_POSIX", Some("1")); config.define("ROCKSDB_PLATFORM_POSIX", Some("1"));
config.define("ROCKSDB_LIB_IO_POSIX", Some("1")); config.define("ROCKSDB_LIB_IO_POSIX", Some("1"));
} }
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
config.define("OS_LINUX", Some("1")); config.define("OS_LINUX", Some("1"));
@ -118,12 +117,9 @@ fn build_rocksdb() {
.iter() .iter()
.cloned() .cloned()
.filter(|file| match *file { .filter(|file| match *file {
"port/port_posix.cc" | "port/port_posix.cc" | "env/env_posix.cc" | "env/io_posix.cc" => false,
"env/env_posix.cc" |
"env/io_posix.cc" => false,
_ => true, _ => true,
}) }).collect::<Vec<&'static str>>();
.collect::<Vec<&'static str>>();
// Add Windows-specific sources // Add Windows-specific sources
lib_sources.push("port/win/port_win.cc"); lib_sources.push("port/win/port_win.cc");
@ -185,12 +181,11 @@ fn build_lz4() {
compiler.opt_level(3); compiler.opt_level(3);
match env::var("TARGET").unwrap().as_str() match env::var("TARGET").unwrap().as_str() {
{ "i686-pc-windows-gnu" => {
"i686-pc-windows-gnu" => { compiler.flag("-fno-tree-vectorize");
compiler.flag("-fno-tree-vectorize"); }
}, _ => {}
_ => {}
} }
compiler.compile("liblz4.a"); compiler.compile("liblz4.a");
@ -227,9 +222,7 @@ fn build_zstd() {
fn build_zlib() { fn build_zlib() {
let mut compiler = cc::Build::new(); let mut compiler = cc::Build::new();
let globs = &[ let globs = &["zlib/*.c"];
"zlib/*.c"
];
for pattern in globs { for pattern in globs {
for path in glob::glob(pattern).unwrap() { for path in glob::glob(pattern).unwrap() {

@ -15,7 +15,13 @@
// This code is based on <https://github.com/facebook/rocksdb/blob/master/db/c_test.c>, revision a10e8a056d569acf6a52045124e6414ad33bdfcd. // This code is based on <https://github.com/facebook/rocksdb/blob/master/db/c_test.c>, revision a10e8a056d569acf6a52045124e6414ad33bdfcd.
#![allow(non_snake_case, non_upper_case_globals, unused_mut, unused_unsafe, unused_variables)] #![allow(
non_snake_case,
non_upper_case_globals,
unused_mut,
unused_unsafe,
unused_variables
)]
#[macro_use] #[macro_use]
extern crate const_cstr; extern crate const_cstr;
@ -23,18 +29,18 @@ extern crate libc;
extern crate librocksdb_sys as ffi; extern crate librocksdb_sys as ffi;
extern crate uuid; extern crate uuid;
use ::ffi::*; use ffi::*;
use ::libc::*; use libc::*;
use ::std::borrow::Cow; use std::borrow::Cow;
use ::std::env; use std::env;
use ::std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use ::std::io::Write; use std::io::Write;
use ::std::mem; use std::mem;
use ::std::path::PathBuf; use std::path::PathBuf;
use ::std::ptr; use std::ptr;
use ::std::slice; use std::slice;
use ::std::str; use std::str;
use ::uuid::Uuid; use uuid::Uuid;
macro_rules! err_println { macro_rules! err_println {
($($arg:tt)*) => (writeln!(&mut ::std::io::stderr(), $($arg)*).expect("failed printing to stderr")); ($($arg:tt)*) => (writeln!(&mut ::std::io::stderr(), $($arg)*).expect("failed printing to stderr"));
@ -77,28 +83,37 @@ unsafe fn StartPhase(name: &'static str) {
} }
macro_rules! CheckNoError { macro_rules! CheckNoError {
($err:ident) => { unsafe { ($err:ident) => {
assert!($err.is_null(), "{}: {}", phase, rstr($err)); unsafe {
} }; assert!($err.is_null(), "{}: {}", phase, rstr($err));
}
};
} }
macro_rules! CheckCondition { macro_rules! CheckCondition {
($cond:expr) => { unsafe { ($cond:expr) => {
assert!($cond, "{}: {}", phase, stringify!($cond)); unsafe {
} }; assert!($cond, "{}: {}", phase, stringify!($cond));
}
};
} }
unsafe fn CheckEqual(expected: *const c_char, v: *const c_char, n: size_t) { unsafe fn CheckEqual(expected: *const c_char, v: *const c_char, n: size_t) {
if expected.is_null() && v.is_null() { if expected.is_null() && v.is_null() {
// ok // ok
} else if !expected.is_null() && !v.is_null() && n == strlen(expected) && } else if !expected.is_null()
memcmp(expected as *const c_void, v as *const c_void, n) == 0 { && !v.is_null()
&& n == strlen(expected)
&& memcmp(expected as *const c_void, v as *const c_void, n) == 0
{
// ok // ok
} else { } else {
panic!("{}: expected '{}', got '{}'", panic!(
phase, "{}: expected '{}', got '{}'",
rstr(strndup(expected, n)), phase,
rstr(strndup(v, 5))); rstr(strndup(expected, n)),
rstr(strndup(v, 5))
);
} }
} }
@ -109,10 +124,12 @@ unsafe fn Free<T>(ptr: *mut *mut T) {
} }
} }
unsafe fn CheckGet(mut db: *mut rocksdb_t, unsafe fn CheckGet(
options: *mut rocksdb_readoptions_t, mut db: *mut rocksdb_t,
key: *const c_char, options: *mut rocksdb_readoptions_t,
expected: *const c_char) { key: *const c_char,
expected: *const c_char,
) {
let mut err: *mut c_char = ptr::null_mut(); let mut err: *mut c_char = ptr::null_mut();
let mut val_len: size_t = 0; 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); let mut val: *mut c_char = rocksdb_get(db, options, key, strlen(key), &mut val_len, &mut err);
@ -121,20 +138,24 @@ unsafe fn CheckGet(mut db: *mut rocksdb_t,
Free(&mut val); Free(&mut val);
} }
unsafe fn CheckGetCF(db: *mut rocksdb_t, unsafe fn CheckGetCF(
options: *const rocksdb_readoptions_t, db: *mut rocksdb_t,
handle: *mut rocksdb_column_family_handle_t, options: *const rocksdb_readoptions_t,
key: *const c_char, handle: *mut rocksdb_column_family_handle_t,
expected: *const c_char) { key: *const c_char,
expected: *const c_char,
) {
let mut err: *mut c_char = ptr::null_mut(); let mut err: *mut c_char = ptr::null_mut();
let mut val_len: size_t = 0; let mut val_len: size_t = 0;
let mut val: *mut c_char = rocksdb_get_cf(db, let mut val: *mut c_char = rocksdb_get_cf(
options, db,
handle, options,
key, handle,
strlen(key), key,
&mut val_len, strlen(key),
&mut err); &mut val_len,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckEqual(expected, val, val_len); CheckEqual(expected, val, val_len);
Free(&mut val); Free(&mut val);
@ -150,11 +171,13 @@ unsafe fn CheckIter(iter: *mut rocksdb_iterator_t, key: *const c_char, val: *con
} }
// Callback from rocksdb_writebatch_iterate() // Callback from rocksdb_writebatch_iterate()
unsafe extern "C" fn CheckPut(ptr: *mut c_void, unsafe extern "C" fn CheckPut(
k: *const c_char, ptr: *mut c_void,
klen: size_t, k: *const c_char,
v: *const c_char, klen: size_t,
vlen: size_t) { v: *const c_char,
vlen: size_t,
) {
let mut state: *mut c_int = ptr as *mut c_int; let mut state: *mut c_int = ptr as *mut c_int;
CheckCondition!(*state < 2); CheckCondition!(*state < 2);
match *state { match *state {
@ -181,17 +204,14 @@ unsafe extern "C" fn CheckDel(ptr: *mut c_void, k: *const c_char, klen: size_t)
unsafe extern "C" fn CmpDestroy(arg: *mut c_void) {} unsafe extern "C" fn CmpDestroy(arg: *mut c_void) {}
unsafe extern "C" fn CmpCompare(arg: *mut c_void, unsafe extern "C" fn CmpCompare(
a: *const c_char, arg: *mut c_void,
alen: size_t, a: *const c_char,
b: *const c_char, alen: size_t,
blen: size_t) b: *const c_char,
-> c_int { blen: size_t,
let n = if alen < blen { ) -> c_int {
alen let n = if alen < blen { alen } else { blen };
} else {
blen
};
let mut r = memcmp(a as *const c_void, b as *const c_void, n); let mut r = memcmp(a as *const c_void, b as *const c_void, n);
if r == 0 { if r == 0 {
if alen < blen { if alen < blen {
@ -217,28 +237,34 @@ unsafe extern "C" fn FilterName(arg: *mut c_void) -> *const c_char {
cstrp!("TestFilter") cstrp!("TestFilter")
} }
unsafe extern "C" fn FilterCreate(arg: *mut c_void, unsafe extern "C" fn FilterCreate(
key_array: *const *const c_char, arg: *mut c_void,
key_length_array: *const size_t, key_array: *const *const c_char,
num_keys: c_int, key_length_array: *const size_t,
filter_length: *mut size_t) num_keys: c_int,
-> *mut c_char { filter_length: *mut size_t,
) -> *mut c_char {
*filter_length = 4; *filter_length = 4;
let result = malloc(4); let result = malloc(4);
memcpy(result, cstrp!("fake") as *const c_void, 4); memcpy(result, cstrp!("fake") as *const c_void, 4);
result as *mut c_char result as *mut c_char
} }
unsafe extern "C" fn FilterKeyMatch(arg: *mut c_void, unsafe extern "C" fn FilterKeyMatch(
key: *const c_char, arg: *mut c_void,
length: size_t, key: *const c_char,
filter: *const c_char, length: size_t,
filter_length: size_t) filter: *const c_char,
-> c_uchar { filter_length: size_t,
) -> c_uchar {
CheckCondition!(filter_length == 4); CheckCondition!(filter_length == 4);
CheckCondition!(memcmp(filter as *const c_void, CheckCondition!(
cstrp!("fake") as *const c_void, memcmp(
filter_length) == 0); filter as *const c_void,
cstrp!("fake") as *const c_void,
filter_length
) == 0
);
fake_filter_result fake_filter_result
} }
@ -250,24 +276,31 @@ unsafe extern "C" fn CFilterName(arg: *mut c_void) -> *const c_char {
cstrp!("foo") cstrp!("foo")
} }
unsafe extern "C" fn CFilterFilter(arg: *mut c_void, unsafe extern "C" fn CFilterFilter(
level: c_int, arg: *mut c_void,
key: *const c_char, level: c_int,
key_length: size_t, key: *const c_char,
existing_value: *const c_char, key_length: size_t,
value_length: size_t, existing_value: *const c_char,
new_value: *mut *mut c_char, value_length: size_t,
new_value_length: *mut size_t, new_value: *mut *mut c_char,
value_changed: *mut u8) new_value_length: *mut size_t,
-> c_uchar { value_changed: *mut u8,
) -> c_uchar {
if key_length == 3 { if key_length == 3 {
if memcmp(mem::transmute(key), if memcmp(
mem::transmute(cstrp!("bar")), mem::transmute(key),
key_length) == 0 { mem::transmute(cstrp!("bar")),
key_length,
) == 0
{
return 1; return 1;
} else if memcmp(mem::transmute(key), } else if memcmp(
mem::transmute(cstrp!("baz")), mem::transmute(key),
key_length) == 0 { mem::transmute(cstrp!("baz")),
key_length,
) == 0
{
*value_changed = 1; *value_changed = 1;
*new_value = cstrp!("newbazvalue") as *mut c_char; *new_value = cstrp!("newbazvalue") as *mut c_char;
*new_value_length = 11; *new_value_length = 11;
@ -283,49 +316,59 @@ unsafe extern "C" fn CFilterFactoryName(arg: *mut c_void) -> *const c_char {
cstrp!("foo") cstrp!("foo")
} }
unsafe extern "C" fn CFilterCreate(arg: *mut c_void, unsafe extern "C" fn CFilterCreate(
context: *mut rocksdb_compactionfiltercontext_t) arg: *mut c_void,
-> *mut rocksdb_compactionfilter_t { context: *mut rocksdb_compactionfiltercontext_t,
rocksdb_compactionfilter_create(ptr::null_mut(), ) -> *mut rocksdb_compactionfilter_t {
Some(CFilterDestroy), rocksdb_compactionfilter_create(
Some(CFilterFilter), ptr::null_mut(),
Some(CFilterName)) Some(CFilterDestroy),
Some(CFilterFilter),
Some(CFilterName),
)
} }
unsafe fn CheckCompaction(dbname: *const c_char, unsafe fn CheckCompaction(
db: *mut rocksdb_t, dbname: *const c_char,
options: *const rocksdb_options_t, db: *mut rocksdb_t,
roptions: *mut rocksdb_readoptions_t, options: *const rocksdb_options_t,
woptions: *mut rocksdb_writeoptions_t) roptions: *mut rocksdb_readoptions_t,
-> *mut rocksdb_t { woptions: *mut rocksdb_writeoptions_t,
) -> *mut rocksdb_t {
let mut err: *mut c_char = ptr::null_mut(); let mut err: *mut c_char = ptr::null_mut();
let db = rocksdb_open(options, dbname, &mut err); let db = rocksdb_open(options, dbname, &mut err);
CheckNoError!(err); CheckNoError!(err);
rocksdb_put(db, rocksdb_put(
woptions, db,
cstrp!("foo"), woptions,
3, cstrp!("foo"),
cstrp!("foovalue"), 3,
8, cstrp!("foovalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue"));
rocksdb_put(db, rocksdb_put(
woptions, db,
cstrp!("bar"), woptions,
3, cstrp!("bar"),
cstrp!("barvalue"), 3,
8, cstrp!("barvalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("bar"), cstrp!("barvalue")); CheckGet(db, roptions, cstrp!("bar"), cstrp!("barvalue"));
rocksdb_put(db, rocksdb_put(
woptions, db,
cstrp!("baz"), woptions,
3, cstrp!("baz"),
cstrp!("bazvalue"), 3,
8, cstrp!("bazvalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("baz"), cstrp!("bazvalue")); CheckGet(db, roptions, cstrp!("baz"), cstrp!("bazvalue"));
@ -346,17 +389,18 @@ unsafe extern "C" fn MergeOperatorName(arg: *mut c_void) -> *const c_char {
cstrp!("foo") cstrp!("foo")
} }
unsafe extern "C" fn MergeOperatorFullMerge(arg: *mut c_void, unsafe extern "C" fn MergeOperatorFullMerge(
key: *const c_char, arg: *mut c_void,
key_length: size_t, key: *const c_char,
existing_value: *const c_char, key_length: size_t,
existing_value_length: size_t, existing_value: *const c_char,
operands_list: *const *const c_char, existing_value_length: size_t,
operands_list_length: *const size_t, operands_list: *const *const c_char,
num_operands: c_int, operands_list_length: *const size_t,
success: *mut u8, num_operands: c_int,
new_value_length: *mut size_t) success: *mut u8,
-> *mut c_char { new_value_length: *mut size_t,
) -> *mut c_char {
*new_value_length = 4; *new_value_length = 4;
*success = 1; *success = 1;
let result: *mut c_char = malloc(4) as *mut _; let result: *mut c_char = malloc(4) as *mut _;
@ -364,15 +408,16 @@ unsafe extern "C" fn MergeOperatorFullMerge(arg: *mut c_void,
result result
} }
unsafe extern "C" fn MergeOperatorPartialMerge(arg: *mut c_void, unsafe extern "C" fn MergeOperatorPartialMerge(
key: *const c_char, arg: *mut c_void,
key_length: size_t, key: *const c_char,
operands_list: *const *const c_char, key_length: size_t,
operands_list_length: *const size_t, operands_list: *const *const c_char,
num_operands: c_int, operands_list_length: *const size_t,
success: *mut u8, num_operands: c_int,
new_value_length: *mut size_t) success: *mut u8,
-> *mut c_char { new_value_length: *mut size_t,
) -> *mut c_char {
*new_value_length = 4; *new_value_length = 4;
*success = 1; *success = 1;
let result: *mut c_char = malloc(4) as *mut _; let result: *mut c_char = malloc(4) as *mut _;
@ -413,10 +458,12 @@ fn ffi() {
let dbbackupname = dbbackupname.as_ptr(); let dbbackupname = dbbackupname.as_ptr();
StartPhase("create_objects"); StartPhase("create_objects");
cmp = rocksdb_comparator_create(ptr::null_mut(), cmp = rocksdb_comparator_create(
Some(CmpDestroy), ptr::null_mut(),
Some(CmpCompare), Some(CmpDestroy),
Some(CmpName)); Some(CmpCompare),
Some(CmpName),
);
env = rocksdb_create_default_env(); env = rocksdb_create_default_env();
cache = rocksdb_cache_create_lru(100000); cache = rocksdb_cache_create_lru(100000);
@ -440,10 +487,12 @@ fn ffi() {
no_compression, no_compression,
no_compression, no_compression,
no_compression, no_compression,
]; ];
rocksdb_options_set_compression_per_level(options, rocksdb_options_set_compression_per_level(
mem::transmute(compression_levels.as_ptr()), options,
compression_levels.len() as size_t); mem::transmute(compression_levels.as_ptr()),
compression_levels.len() as size_t,
);
roptions = rocksdb_readoptions_create(); roptions = rocksdb_readoptions_create();
rocksdb_readoptions_set_verify_checksums(roptions, 1); rocksdb_readoptions_set_verify_checksums(roptions, 1);
@ -513,11 +562,13 @@ fn ffi() {
let restore_options = rocksdb_restore_options_create(); let restore_options = rocksdb_restore_options_create();
rocksdb_restore_options_set_keep_log_files(restore_options, 0); rocksdb_restore_options_set_keep_log_files(restore_options, 0);
rocksdb_backup_engine_restore_db_from_latest_backup(be, rocksdb_backup_engine_restore_db_from_latest_backup(
dbname, be,
dbname, dbname,
restore_options, dbname,
&mut err); restore_options,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
rocksdb_restore_options_destroy(restore_options); rocksdb_restore_options_destroy(restore_options);
@ -553,10 +604,12 @@ fn ffi() {
CheckGet(db, roptions, cstrp!("bar"), ptr::null()); CheckGet(db, roptions, cstrp!("bar"), ptr::null());
CheckGet(db, roptions, cstrp!("box"), cstrp!("c")); CheckGet(db, roptions, cstrp!("box"), cstrp!("c"));
let mut pos: c_int = 0; let mut pos: c_int = 0;
rocksdb_writebatch_iterate(wb, rocksdb_writebatch_iterate(
mem::transmute(&mut pos), wb,
Some(CheckPut), mem::transmute(&mut pos),
Some(CheckDel)); Some(CheckPut),
Some(CheckDel),
);
CheckCondition!(pos == 3); CheckCondition!(pos == 3);
rocksdb_writebatch_destroy(wb); rocksdb_writebatch_destroy(wb);
} }
@ -568,13 +621,15 @@ fn ffi() {
let k_sizes: [size_t; 2] = [1, 2]; let k_sizes: [size_t; 2] = [1, 2];
let v_list: [*const c_char; 3] = [cstrp!("x"), cstrp!("y"), cstrp!("z")]; let v_list: [*const c_char; 3] = [cstrp!("x"), cstrp!("y"), cstrp!("z")];
let v_sizes: [size_t; 3] = [1, 1, 1]; let v_sizes: [size_t; 3] = [1, 1, 1];
rocksdb_writebatch_putv(wb, rocksdb_writebatch_putv(
k_list.len() as c_int, wb,
k_list.as_ptr(), k_list.len() as c_int,
k_sizes.as_ptr(), k_list.as_ptr(),
v_list.len() as c_int, k_sizes.as_ptr(),
v_list.as_ptr(), v_list.len() as c_int,
v_sizes.as_ptr()); v_list.as_ptr(),
v_sizes.as_ptr(),
);
rocksdb_write(db, woptions, wb, &mut err); rocksdb_write(db, woptions, wb, &mut err);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("zap"), cstrp!("xyz")); CheckGet(db, roptions, cstrp!("zap"), cstrp!("xyz"));
@ -596,10 +651,13 @@ fn ffi() {
let mut wb2 = rocksdb_writebatch_create_from(rep as *const c_char, repsize1); let mut wb2 = rocksdb_writebatch_create_from(rep as *const c_char, repsize1);
CheckCondition!(rocksdb_writebatch_count(wb1) == rocksdb_writebatch_count(wb2)); CheckCondition!(rocksdb_writebatch_count(wb1) == rocksdb_writebatch_count(wb2));
let mut repsize2: size_t = 0; let mut repsize2: size_t = 0;
CheckCondition!(memcmp(rep, CheckCondition!(
rocksdb_writebatch_data(wb2, &mut repsize2) as *const c_void, memcmp(
repsize1) == rep,
0); rocksdb_writebatch_data(wb2, &mut repsize2) as *const c_void,
repsize1
) == 0
);
rocksdb_writebatch_destroy(wb1); rocksdb_writebatch_destroy(wb1);
rocksdb_writebatch_destroy(wb2); rocksdb_writebatch_destroy(wb2);
} }
@ -633,14 +691,16 @@ fn ffi() {
let mut vals: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; 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 vals_sizes: [size_t; 3] = [0, 0, 0];
let mut errs: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; let mut errs: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()];
rocksdb_multi_get(db, rocksdb_multi_get(
roptions, db,
3, roptions,
keys.as_ptr(), 3,
keys_sizes.as_ptr(), keys.as_ptr(),
vals.as_mut_ptr(), keys_sizes.as_ptr(),
vals_sizes.as_mut_ptr(), vals.as_mut_ptr(),
errs.as_mut_ptr()); vals_sizes.as_mut_ptr(),
errs.as_mut_ptr(),
);
for i in 0..3 { for i in 0..3 {
CheckEqual(ptr::null(), errs[i], 0); CheckEqual(ptr::null(), errs[i], 0);
@ -667,22 +727,26 @@ fn ffi() {
let key = keybuf.to_bytes_with_nul(); let key = keybuf.to_bytes_with_nul();
let valbuf = CString::new(format!("v{:020}", i)).unwrap(); let valbuf = CString::new(format!("v{:020}", i)).unwrap();
let val = valbuf.to_bytes_with_nul(); let val = valbuf.to_bytes_with_nul();
rocksdb_put(db, rocksdb_put(
woptions, db,
key.as_ptr() as *const c_char, woptions,
key.len() as size_t, key.as_ptr() as *const c_char,
val.as_ptr() as *const c_char, key.len() as size_t,
val.len() as size_t, val.as_ptr() as *const c_char,
&mut err); val.len() as size_t,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
} }
rocksdb_approximate_sizes(db, rocksdb_approximate_sizes(
2, db,
start.as_ptr(), 2,
start_len.as_ptr(), start.as_ptr(),
limit.as_ptr(), start_len.as_ptr(),
limit_len.as_ptr(), limit.as_ptr(),
sizes.as_mut_ptr()); limit_len.as_ptr(),
sizes.as_mut_ptr(),
);
CheckCondition!(sizes[0] > 0); CheckCondition!(sizes[0] > 0);
CheckCondition!(sizes[1] > 0); CheckCondition!(sizes[1] > 0);
} }
@ -733,12 +797,14 @@ fn ffi() {
// First run uses custom filter, second run uses bloom filter // First run uses custom filter, second run uses bloom filter
CheckNoError!(err); CheckNoError!(err);
let mut policy: *mut rocksdb_filterpolicy_t = if run == 0 { let mut policy: *mut rocksdb_filterpolicy_t = if run == 0 {
rocksdb_filterpolicy_create(ptr::null_mut(), rocksdb_filterpolicy_create(
Some(FilterDestroy), ptr::null_mut(),
Some(FilterCreate), Some(FilterDestroy),
Some(FilterKeyMatch), Some(FilterCreate),
None, Some(FilterKeyMatch),
Some(FilterName)) None,
Some(FilterName),
)
} else { } else {
rocksdb_filterpolicy_create_bloom(10) rocksdb_filterpolicy_create_bloom(10)
}; };
@ -751,21 +817,25 @@ fn ffi() {
rocksdb_options_set_block_based_table_factory(options, table_options); rocksdb_options_set_block_based_table_factory(options, table_options);
db = rocksdb_open(options, dbname, &mut err); db = rocksdb_open(options, dbname, &mut err);
CheckNoError!(err); CheckNoError!(err);
rocksdb_put(db, rocksdb_put(
woptions, db,
cstrp!("foo"), woptions,
3, cstrp!("foo"),
cstrp!("foovalue"), 3,
8, cstrp!("foovalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
rocksdb_put(db, rocksdb_put(
woptions, db,
cstrp!("bar"), woptions,
3, cstrp!("bar"),
cstrp!("barvalue"), 3,
8, cstrp!("barvalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
rocksdb_compact_range(db, ptr::null(), 0, ptr::null(), 0); rocksdb_compact_range(db, ptr::null(), 0, ptr::null(), 0);
@ -791,10 +861,12 @@ fn ffi() {
{ {
let options_with_filter = rocksdb_options_create(); let options_with_filter = rocksdb_options_create();
rocksdb_options_set_create_if_missing(options_with_filter, 1); rocksdb_options_set_create_if_missing(options_with_filter, 1);
let cfilter = rocksdb_compactionfilter_create(ptr::null_mut(), let cfilter = rocksdb_compactionfilter_create(
Some(CFilterDestroy), ptr::null_mut(),
Some(CFilterFilter), Some(CFilterDestroy),
Some(CFilterName)); Some(CFilterFilter),
Some(CFilterName),
);
// Create new database // Create new database
rocksdb_close(db); rocksdb_close(db);
rocksdb_destroy_db(options_with_filter, dbname, &mut err); rocksdb_destroy_db(options_with_filter, dbname, &mut err);
@ -810,62 +882,74 @@ fn ffi() {
{ {
let mut options_with_filter_factory = rocksdb_options_create(); let mut options_with_filter_factory = rocksdb_options_create();
rocksdb_options_set_create_if_missing(options_with_filter_factory, 1); rocksdb_options_set_create_if_missing(options_with_filter_factory, 1);
let mut factory = rocksdb_compactionfilterfactory_create(ptr::null_mut(), let mut factory = rocksdb_compactionfilterfactory_create(
Some(CFilterFactoryDestroy), ptr::null_mut(),
Some(CFilterCreate), Some(CFilterFactoryDestroy),
Some(CFilterFactoryName)); Some(CFilterCreate),
Some(CFilterFactoryName),
);
// Create new database // Create new database
rocksdb_close(db); rocksdb_close(db);
rocksdb_destroy_db(options_with_filter_factory, dbname, &mut err); rocksdb_destroy_db(options_with_filter_factory, dbname, &mut err);
rocksdb_options_set_compaction_filter_factory(options_with_filter_factory, factory); rocksdb_options_set_compaction_filter_factory(options_with_filter_factory, factory);
db = CheckCompaction(dbname, db, options_with_filter_factory, roptions, woptions); db = CheckCompaction(dbname, db, options_with_filter_factory, roptions, woptions);
rocksdb_options_set_compaction_filter_factory(options_with_filter_factory, rocksdb_options_set_compaction_filter_factory(
ptr::null_mut()); options_with_filter_factory,
ptr::null_mut(),
);
rocksdb_options_destroy(options_with_filter_factory); rocksdb_options_destroy(options_with_filter_factory);
} }
StartPhase("merge_operator"); StartPhase("merge_operator");
{ {
let mut merge_operator = rocksdb_mergeoperator_create(ptr::null_mut(), let mut merge_operator = rocksdb_mergeoperator_create(
Some(MergeOperatorDestroy), ptr::null_mut(),
Some(MergeOperatorFullMerge), Some(MergeOperatorDestroy),
Some(MergeOperatorPartialMerge), Some(MergeOperatorFullMerge),
None, Some(MergeOperatorPartialMerge),
Some(MergeOperatorName)); None,
Some(MergeOperatorName),
);
// Create new database // Create new database
rocksdb_close(db); rocksdb_close(db);
rocksdb_destroy_db(options, dbname, &mut err); rocksdb_destroy_db(options, dbname, &mut err);
rocksdb_options_set_merge_operator(options, merge_operator); rocksdb_options_set_merge_operator(options, merge_operator);
db = rocksdb_open(options, dbname, &mut err); db = rocksdb_open(options, dbname, &mut err);
CheckNoError!(err); CheckNoError!(err);
rocksdb_put(db, rocksdb_put(
woptions, db,
cstrp!("foo"), woptions,
3, cstrp!("foo"),
cstrp!("foovalue"), 3,
8, cstrp!("foovalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue")); CheckGet(db, roptions, cstrp!("foo"), cstrp!("foovalue"));
rocksdb_merge(db, rocksdb_merge(
woptions, db,
cstrp!("foo"), woptions,
3, cstrp!("foo"),
cstrp!("barvalue"), 3,
8, cstrp!("barvalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("foo"), cstrp!("fake")); CheckGet(db, roptions, cstrp!("foo"), cstrp!("fake"));
// Merge of a non-existing value // Merge of a non-existing value
rocksdb_merge(db, rocksdb_merge(
woptions, db,
cstrp!("bar"), woptions,
3, cstrp!("bar"),
cstrp!("barvalue"), 3,
8, cstrp!("barvalue"),
&mut err); 8,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGet(db, roptions, cstrp!("bar"), cstrp!("fake")); CheckGet(db, roptions, cstrp!("bar"), cstrp!("fake"));
} }
@ -898,25 +982,29 @@ fn ffi() {
let mut cf_names: [*const c_char; 2] = [cstrp!("default"), cstrp!("cf1")]; 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 cf_opts: [*const rocksdb_options_t; 2] = [cf_options, cf_options];
let mut handles: [*mut rocksdb_column_family_handle_t; 2] = [ptr::null_mut(), let mut handles: [*mut rocksdb_column_family_handle_t; 2] =
ptr::null_mut()]; [ptr::null_mut(), ptr::null_mut()];
db = rocksdb_open_column_families(db_options, db = rocksdb_open_column_families(
dbname, db_options,
2, dbname,
cf_names.as_mut_ptr(), 2,
cf_opts.as_mut_ptr(), cf_names.as_mut_ptr(),
handles.as_mut_ptr(), cf_opts.as_mut_ptr(),
&mut err); handles.as_mut_ptr(),
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
rocksdb_put_cf(db, rocksdb_put_cf(
woptions, db,
handles[1], woptions,
cstrp!("foo"), handles[1],
3, cstrp!("foo"),
cstrp!("hello"), 3,
5, cstrp!("hello"),
&mut err); 5,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
CheckGetCF(db, roptions, handles[1], cstrp!("foo"), cstrp!("hello")); CheckGetCF(db, roptions, handles[1], cstrp!("foo"), cstrp!("hello"));
@ -940,21 +1028,23 @@ fn ffi() {
rocksdb_writebatch_destroy(wb); rocksdb_writebatch_destroy(wb);
let keys: [*const c_char; 3] = [cstrp!("box"), cstrp!("box"), cstrp!("barfooxx")]; 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], let get_handles: [*const rocksdb_column_family_handle_t; 3] =
handles[1]]; [handles[0], handles[1], handles[1]];
let keys_sizes: [size_t; 3] = [3, 3, 8]; 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: [*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 vals_sizes: [size_t; 3] = [0, 0, 0];
let mut errs: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()]; let mut errs: [*mut c_char; 3] = [ptr::null_mut(), ptr::null_mut(), ptr::null_mut()];
rocksdb_multi_get_cf(db, rocksdb_multi_get_cf(
roptions, db,
get_handles.as_ptr(), roptions,
3, get_handles.as_ptr(),
keys.as_ptr(), 3,
keys_sizes.as_ptr(), keys.as_ptr(),
vals.as_mut_ptr(), keys_sizes.as_ptr(),
vals_sizes.as_mut_ptr(), vals.as_mut_ptr(),
errs.as_mut_ptr()); vals_sizes.as_mut_ptr(),
errs.as_mut_ptr(),
);
for i in 0..3 { for i in 0..3 {
CheckEqual(ptr::null(), errs[i], 0); CheckEqual(ptr::null(), errs[i], 0);
@ -982,16 +1072,18 @@ fn ffi() {
CheckNoError!(err); CheckNoError!(err);
rocksdb_iter_destroy(iter); rocksdb_iter_destroy(iter);
let mut iters_cf_handles: [*mut rocksdb_column_family_handle_t; 2] = [handles[0], let mut iters_cf_handles: [*mut rocksdb_column_family_handle_t; 2] =
handles[1]]; [handles[0], handles[1]];
let mut iters_handles: [*mut rocksdb_iterator_t; 2] = [ptr::null_mut(), let mut iters_handles: [*mut rocksdb_iterator_t; 2] =
ptr::null_mut()]; [ptr::null_mut(), ptr::null_mut()];
rocksdb_create_iterators(db, rocksdb_create_iterators(
roptions, db,
iters_cf_handles.as_mut_ptr(), roptions,
iters_handles.as_mut_ptr(), iters_cf_handles.as_mut_ptr(),
2, iters_handles.as_mut_ptr(),
&mut err); 2,
&mut err,
);
CheckNoError!(err); CheckNoError!(err);
iter = iters_handles[0]; iter = iters_handles[0];
@ -1030,8 +1122,10 @@ fn ffi() {
{ {
// Create new database // Create new database
rocksdb_options_set_allow_mmap_reads(options, 1); rocksdb_options_set_allow_mmap_reads(options, 1);
rocksdb_options_set_prefix_extractor(options, rocksdb_options_set_prefix_extractor(
rocksdb_slicetransform_create_fixed_prefix(3)); options,
rocksdb_slicetransform_create_fixed_prefix(3),
);
rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4); rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4);
rocksdb_options_set_plain_table_factory(options, 4, 10, 0.75, 16); rocksdb_options_set_plain_table_factory(options, 4, 10, 0.75, 16);
rocksdb_options_set_allow_concurrent_memtable_write(options, 0); rocksdb_options_set_allow_concurrent_memtable_write(options, 0);

Loading…
Cancel
Save