Skip to content

Commit 7f4b70e

Browse files
committed
fix conflicts
Signed-off-by: fredchenbj <[email protected]>
1 parent 942426c commit 7f4b70e

File tree

6 files changed

+32
-69
lines changed

6 files changed

+32
-69
lines changed

Diff for: src/event_listener.rs

-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ macro_rules! fetch_str {
3131
})
3232
}
3333

34-
#[repr(transparent)]
3534
pub struct FlushJobInfo(crocksdb_flushjobinfo_t);
3635

3736
impl FlushJobInfo {
@@ -60,7 +59,6 @@ impl FlushJobInfo {
6059
}
6160
}
6261

63-
#[repr(transparent)]
6462
pub struct CompactionJobInfo(crocksdb_compactionjobinfo_t);
6563

6664
impl CompactionJobInfo {
@@ -131,7 +129,6 @@ impl CompactionJobInfo {
131129
}
132130
}
133131

134-
#[repr(transparent)]
135132
pub struct IngestionInfo(crocksdb_externalfileingestioninfo_t);
136133

137134
impl IngestionInfo {
@@ -156,7 +153,6 @@ impl IngestionInfo {
156153
}
157154
}
158155

159-
#[repr(transparent)]
160156
pub struct WriteStallInfo(crocksdb_writestallinfo_t);
161157

162158
impl WriteStallInfo {

Diff for: src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod table_properties;
6868
mod table_properties_collector;
6969
mod table_properties_collector_factory;
7070
mod titan;
71+
mod util;
7172

7273
#[cfg(test)]
7374
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {

Diff for: src/merge_operator.rs

+26-30
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,20 @@ pub unsafe extern "C" fn full_merge_callback(
4949
success: *mut u8,
5050
new_value_length: *mut size_t,
5151
) -> *mut c_char {
52-
unsafe {
53-
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
54-
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
55-
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
56-
let oldval: &[u8] =
57-
slice::from_raw_parts(existing_value as *const u8, existing_value_len as usize);
58-
let mut result = (cb.merge_fn)(key, Some(oldval), operands);
59-
result.shrink_to_fit();
60-
// TODO(tan) investigate zero-copy techniques to improve performance
61-
let buf = libc::malloc(result.len() as size_t);
62-
assert!(!buf.is_null());
63-
*new_value_length = result.len() as size_t;
64-
*success = 1 as u8;
65-
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
66-
buf as *mut c_char
67-
}
52+
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
53+
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
54+
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
55+
let oldval: &[u8] =
56+
slice::from_raw_parts(existing_value as *const u8, existing_value_len as usize);
57+
let mut result = (cb.merge_fn)(key, Some(oldval), operands);
58+
result.shrink_to_fit();
59+
// TODO(tan) investigate zero-copy techniques to improve performance
60+
let buf = libc::malloc(result.len() as size_t);
61+
assert!(!buf.is_null());
62+
*new_value_length = result.len() as size_t;
63+
*success = 1 as u8;
64+
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
65+
buf as *mut c_char
6866
}
6967

7068
pub unsafe extern "C" fn partial_merge_callback(
@@ -77,20 +75,18 @@ pub unsafe extern "C" fn partial_merge_callback(
7775
success: *mut u8,
7876
new_value_length: *mut size_t,
7977
) -> *mut c_char {
80-
unsafe {
81-
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
82-
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
83-
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
84-
let mut result = (cb.merge_fn)(key, None, operands);
85-
result.shrink_to_fit();
86-
// TODO(tan) investigate zero-copy techniques to improve performance
87-
let buf = libc::malloc(result.len() as size_t);
88-
assert!(!buf.is_null());
89-
*new_value_length = result.len() as size_t;
90-
*success = 1 as u8;
91-
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
92-
buf as *mut c_char
93-
}
78+
let cb: &mut MergeOperatorCallback = &mut *(raw_cb as *mut MergeOperatorCallback);
79+
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
80+
let key: &[u8] = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
81+
let mut result = (cb.merge_fn)(key, None, operands);
82+
result.shrink_to_fit();
83+
// TODO(tan) investigate zero-copy techniques to improve performance
84+
let buf = libc::malloc(result.len() as size_t);
85+
assert!(!buf.is_null());
86+
*new_value_length = result.len() as size_t;
87+
*success = 1 as u8;
88+
ptr::copy(result.as_ptr() as *mut c_void, &mut *buf, result.len());
89+
buf as *mut c_char
9490
}
9591

9692
pub struct MergeOperands {

Diff for: src/rocksdb.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crocksdb_ffi::{
1818
crocksdb_sequential_file_t, crocksdb_t, crocksdb_writebatch_t, ctitandb_options_t,
1919
DBCompressionType, DBStatisticsHistogramType, DBStatisticsTickerType,
2020
};
21-
use libc::{self, c_int, c_void, size_t};
21+
use libc::{self, c_char, c_int, c_void, size_t};
2222
use metadata::ColumnFamilyMetaData;
2323
use rocksdb_options::{
2424
CColumnFamilyDescriptor, ColumnFamilyDescriptor, ColumnFamilyOptions, CompactOptions,
@@ -39,7 +39,6 @@ use std::str::from_utf8;
3939
use std::sync::Arc;
4040
use std::{fs, ptr, slice};
4141
use table_properties::{TableProperties, TablePropertiesCollection};
42-
use util::is_power_of_two;
4342
use util::opt_bytes_to_ptr;
4443

4544
pub struct CFHandle {
@@ -2560,10 +2559,9 @@ pub struct Cache {
25602559
impl Cache {
25612560
pub fn new_lru_cache(opt: LRUCacheOptions) -> Cache {
25622561
// This is ok because LRUCacheOptions always contains a valid pointer
2563-
unsafe {
2564-
Cache {
2565-
inner: crocksdb_ffi::new_lru_cache(opt.inner),
2566-
}
2562+
2563+
Cache {
2564+
inner: crocksdb_ffi::new_lru_cache(opt.inner),
25672565
}
25682566
}
25692567
}
@@ -2636,7 +2634,7 @@ pub fn load_latest_options(
26362634
dbpath.as_ptr(),
26372635
env.inner,
26382636
db_options.inner,
2639-
&raw_cf_descs,
2637+
&mut raw_cf_descs,
26402638
&mut cf_descs_len,
26412639
ignore_unknown_options as u8
26422640
));

Diff for: src/table_properties.rs

-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::marker::PhantomData;
2121
use std::ops::{Deref, Index};
2222
use std::{slice, str};
2323

24-
#[repr(transparent)]
2524
pub struct TablePropertiesCollectionView(crocksdb_table_properties_collection_t);
2625

2726
impl TablePropertiesCollectionView {
@@ -133,7 +132,6 @@ impl Deref for TablePropertiesCollection {
133132
}
134133
}
135134

136-
#[repr(transparent)]
137135
pub struct TableProperties {
138136
inner: crocksdb_table_properties_t,
139137
}
@@ -238,7 +236,6 @@ impl TableProperties {
238236
}
239237
}
240238

241-
#[repr(transparent)]
242239
pub struct UserCollectedProperties {
243240
inner: crocksdb_user_collected_properties_t,
244241
}

Diff for: src/util.rs

-25
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,9 @@
1414
use libc::c_char;
1515
use std::ptr;
1616

17-
pub fn is_power_of_two(mut n: usize) -> bool {
18-
if n == 0 {
19-
return false;
20-
}
21-
while n % 2 == 0 {
22-
n = n / 2;
23-
}
24-
n == 1
25-
}
26-
2717
pub fn opt_bytes_to_ptr<T: AsRef<[u8]>>(opt: Option<T>) -> *const c_char {
2818
match opt {
2919
Some(v) => v.as_ref().as_ptr() as *const c_char,
3020
None => ptr::null(),
3121
}
3222
}
33-
34-
#[cfg(test)]
35-
mod test {
36-
use super::*;
37-
38-
#[test]
39-
fn test_is_power_of_two() {
40-
assert_eq!(is_power_of_two(0), false);
41-
assert_eq!(is_power_of_two(1), true);
42-
assert_eq!(is_power_of_two(2), true);
43-
assert_eq!(is_power_of_two(4), true);
44-
assert_eq!(is_power_of_two(8), true);
45-
assert_eq!(is_power_of_two(5), false);
46-
}
47-
}

0 commit comments

Comments
 (0)