Commit 0fe7d360 authored by Huachao Huang's avatar Huachao Huang

address comment

parent 621b14de
...@@ -187,7 +187,7 @@ pub enum DBInfoLogLevel { ...@@ -187,7 +187,7 @@ pub enum DBInfoLogLevel {
DBNumInfoLog = 6, DBNumInfoLog = 6,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Eq, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum DBTableProperty { pub enum DBTableProperty {
DataSize = 1, DataSize = 1,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
use crocksdb_ffi::{self, DBEntryType, DBUserCollectedProperties, DBTablePropertiesCollector}; use crocksdb_ffi::{self, DBEntryType, DBUserCollectedProperties, DBTablePropertiesCollector};
use libc::{c_void, c_char, c_int, uint8_t, uint64_t, size_t}; use libc::{c_void, c_char, c_int, uint8_t, uint64_t, size_t};
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::CString;
use std::mem; use std::mem;
use std::slice; use std::slice;
...@@ -25,10 +26,15 @@ use std::slice; ...@@ -25,10 +26,15 @@ use std::slice;
/// TablePropertiesCollector object per table and then call it sequentially /// TablePropertiesCollector object per table and then call it sequentially
pub trait TablePropertiesCollector { pub trait TablePropertiesCollector {
/// The name of the properties collector. /// The name of the properties collector.
fn name(&self) -> &str; fn name(&self) -> &CString;
/// Will be called when a new key/value pair is inserted into the table. /// Will be called when a new key/value pair is inserted into the table.
fn add_userkey(&mut self, key: &[u8], value: &[u8], entry_type: DBEntryType); fn add_userkey(&mut self,
key: &[u8],
value: &[u8],
entry_type: DBEntryType,
seq: u64,
file_size: u64);
/// Will be called when a table has already been built and is ready for /// Will be called when a table has already been built and is ready for
/// writing the properties block. /// writing the properties block.
...@@ -38,7 +44,7 @@ pub trait TablePropertiesCollector { ...@@ -38,7 +44,7 @@ pub trait TablePropertiesCollector {
extern "C" fn name(collector: *mut c_void) -> *const c_char { extern "C" fn name(collector: *mut c_void) -> *const c_char {
unsafe { unsafe {
let collector = &mut *(collector as *mut Box<TablePropertiesCollector>); let collector = &mut *(collector as *mut Box<TablePropertiesCollector>);
collector.name().as_ptr() as *const c_char collector.name().as_ptr()
} }
} }
...@@ -55,13 +61,13 @@ pub extern "C" fn add_userkey(collector: *mut c_void, ...@@ -55,13 +61,13 @@ pub extern "C" fn add_userkey(collector: *mut c_void,
value: *const uint8_t, value: *const uint8_t,
value_len: size_t, value_len: size_t,
entry_type: c_int, entry_type: c_int,
_: uint64_t, seq: uint64_t,
_: uint64_t) { file_size: uint64_t) {
unsafe { unsafe {
let collector = &mut *(collector as *mut Box<TablePropertiesCollector>); let collector = &mut *(collector as *mut Box<TablePropertiesCollector>);
let key = slice::from_raw_parts(key, key_len); let key = slice::from_raw_parts(key, key_len);
let value = slice::from_raw_parts(value, value_len); let value = slice::from_raw_parts(value, value_len);
collector.add_userkey(key, value, mem::transmute(entry_type)); collector.add_userkey(key, value, mem::transmute(entry_type), seq, file_size);
} }
} }
......
...@@ -13,13 +13,14 @@ ...@@ -13,13 +13,14 @@
use crocksdb_ffi::{self, DBTablePropertiesCollector, DBTablePropertiesCollectorFactory}; use crocksdb_ffi::{self, DBTablePropertiesCollector, DBTablePropertiesCollectorFactory};
use libc::{c_void, c_char, uint32_t}; use libc::{c_void, c_char, uint32_t};
use std::ffi::CString;
use table_properties_collector::{TablePropertiesCollector, new_table_properties_collector}; use table_properties_collector::{TablePropertiesCollector, new_table_properties_collector};
/// Constructs `TablePropertiesCollector`. /// Constructs `TablePropertiesCollector`.
/// Internals create a new `TablePropertiesCollector` for each new table. /// Internals create a new `TablePropertiesCollector` for each new table.
pub trait TablePropertiesCollectorFactory { pub trait TablePropertiesCollectorFactory {
/// The name of the properties collector factory. /// The name of the properties collector factory.
fn name(&self) -> &str; fn name(&self) -> &CString;
/// Has to be thread-safe. /// Has to be thread-safe.
fn create_table_properties_collector(&mut self, cf: u32) -> Box<TablePropertiesCollector>; fn create_table_properties_collector(&mut self, cf: u32) -> Box<TablePropertiesCollector>;
} }
...@@ -27,7 +28,7 @@ pub trait TablePropertiesCollectorFactory { ...@@ -27,7 +28,7 @@ pub trait TablePropertiesCollectorFactory {
extern "C" fn name(factory: *mut c_void) -> *const c_char { extern "C" fn name(factory: *mut c_void) -> *const c_char {
unsafe { unsafe {
let factory = &mut *(factory as *mut Box<TablePropertiesCollectorFactory>); let factory = &mut *(factory as *mut Box<TablePropertiesCollectorFactory>);
factory.name().as_ptr() as *const c_char factory.name().as_ptr()
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment