Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: fredchenbj <[email protected]>
  • Loading branch information
fredbjer committed Dec 4, 2019
1 parent 942426c commit 7f4b70e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 69 deletions.
4 changes: 0 additions & 4 deletions src/event_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ macro_rules! fetch_str {
})
}

#[repr(transparent)]
pub struct FlushJobInfo(crocksdb_flushjobinfo_t);

impl FlushJobInfo {
Expand Down Expand Up @@ -60,7 +59,6 @@ impl FlushJobInfo {
}
}

#[repr(transparent)]
pub struct CompactionJobInfo(crocksdb_compactionjobinfo_t);

impl CompactionJobInfo {
Expand Down Expand Up @@ -131,7 +129,6 @@ impl CompactionJobInfo {
}
}

#[repr(transparent)]
pub struct IngestionInfo(crocksdb_externalfileingestioninfo_t);

impl IngestionInfo {
Expand All @@ -156,7 +153,6 @@ impl IngestionInfo {
}
}

#[repr(transparent)]
pub struct WriteStallInfo(crocksdb_writestallinfo_t);

impl WriteStallInfo {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod table_properties;
mod table_properties_collector;
mod table_properties_collector_factory;
mod titan;
mod util;

#[cfg(test)]
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
Expand Down
56 changes: 26 additions & 30 deletions src/merge_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,20 @@ pub unsafe extern "C" fn full_merge_callback(
success: *mut u8,
new_value_length: *mut size_t,
) -> *mut c_char {
unsafe {
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
let oldval: &[u8] =
slice::from_raw_parts(existing_value as *const u8, existing_value_len as usize);
let mut result = (cb.merge_fn)(key, Some(oldval), operands);
result.shrink_to_fit();
// TODO(tan) investigate zero-copy techniques to improve performance
let buf = libc::malloc(result.len() as size_t);
assert!(!buf.is_null());
*new_value_length = result.len() as size_t;
*success = 1 as u8;
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
buf as *mut c_char
}
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
let oldval: &[u8] =
slice::from_raw_parts(existing_value as *const u8, existing_value_len as usize);
let mut result = (cb.merge_fn)(key, Some(oldval), operands);
result.shrink_to_fit();
// TODO(tan) investigate zero-copy techniques to improve performance
let buf = libc::malloc(result.len() as size_t);
assert!(!buf.is_null());
*new_value_length = result.len() as size_t;
*success = 1 as u8;
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
buf as *mut c_char
}

pub unsafe extern "C" fn partial_merge_callback(
Expand All @@ -77,20 +75,18 @@ pub unsafe extern "C" fn partial_merge_callback(
success: *mut u8,
new_value_length: *mut size_t,
) -> *mut c_char {
unsafe {
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
let mut result = (cb.merge_fn)(key, None, operands);
result.shrink_to_fit();
// TODO(tan) investigate zero-copy techniques to improve performance
let buf = libc::malloc(result.len() as size_t);
assert!(!buf.is_null());
*new_value_length = result.len() as size_t;
*success = 1 as u8;
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
buf as *mut c_char
}
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
let mut result = (cb.merge_fn)(key, None, operands);
result.shrink_to_fit();
// TODO(tan) investigate zero-copy techniques to improve performance
let buf = libc::malloc(result.len() as size_t);
assert!(!buf.is_null());
*new_value_length = result.len() as size_t;
*success = 1 as u8;
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
buf as *mut c_char
}

pub struct MergeOperands {
Expand Down
12 changes: 5 additions & 7 deletions src/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crocksdb_ffi::{
crocksdb_sequential_file_t, crocksdb_t, crocksdb_writebatch_t, ctitandb_options_t,
DBCompressionType, DBStatisticsHistogramType, DBStatisticsTickerType,
};
use libc::{self, c_int, c_void, size_t};
use libc::{self, c_char, c_int, c_void, size_t};
use metadata::ColumnFamilyMetaData;
use rocksdb_options::{
CColumnFamilyDescriptor, ColumnFamilyDescriptor, ColumnFamilyOptions, CompactOptions,
Expand All @@ -39,7 +39,6 @@ use std::str::from_utf8;
use std::sync::Arc;
use std::{fs, ptr, slice};
use table_properties::{TableProperties, TablePropertiesCollection};
use util::is_power_of_two;
use util::opt_bytes_to_ptr;

pub struct CFHandle {
Expand Down Expand Up @@ -2560,10 +2559,9 @@ pub struct Cache {
impl Cache {
pub fn new_lru_cache(opt: LRUCacheOptions) -> Cache {
// This is ok because LRUCacheOptions always contains a valid pointer
unsafe {
Cache {
inner: crocksdb_ffi::new_lru_cache(opt.inner),
}

Cache {
inner: crocksdb_ffi::new_lru_cache(opt.inner),
}
}
}
Expand Down Expand Up @@ -2636,7 +2634,7 @@ pub fn load_latest_options(
dbpath.as_ptr(),
env.inner,
db_options.inner,
&raw_cf_descs,
&mut raw_cf_descs,
&mut cf_descs_len,
ignore_unknown_options as u8
));
Expand Down
3 changes: 0 additions & 3 deletions src/table_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::marker::PhantomData;
use std::ops::{Deref, Index};
use std::{slice, str};

#[repr(transparent)]
pub struct TablePropertiesCollectionView(crocksdb_table_properties_collection_t);

impl TablePropertiesCollectionView {
Expand Down Expand Up @@ -133,7 +132,6 @@ impl Deref for TablePropertiesCollection {
}
}

#[repr(transparent)]
pub struct TableProperties {
inner: crocksdb_table_properties_t,
}
Expand Down Expand Up @@ -238,7 +236,6 @@ impl TableProperties {
}
}

#[repr(transparent)]
pub struct UserCollectedProperties {
inner: crocksdb_user_collected_properties_t,
}
Expand Down
25 changes: 0 additions & 25 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,9 @@
use libc::c_char;
use std::ptr;

pub fn is_power_of_two(mut n: usize) -> bool {
if n == 0 {
return false;
}
while n % 2 == 0 {
n = n / 2;
}
n == 1
}

pub fn opt_bytes_to_ptr<T: AsRef<[u8]>>(opt: Option<T>) -> *const c_char {
match opt {
Some(v) => v.as_ref().as_ptr() as *const c_char,
None => ptr::null(),
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_is_power_of_two() {
assert_eq!(is_power_of_two(0), false);
assert_eq!(is_power_of_two(1), true);
assert_eq!(is_power_of_two(2), true);
assert_eq!(is_power_of_two(4), true);
assert_eq!(is_power_of_two(8), true);
assert_eq!(is_power_of_two(5), false);
}
}

0 comments on commit 7f4b70e

Please sign in to comment.