Commit 9722aa63 authored by Huachao Huang's avatar Huachao Huang

address comment

parent 0eda4b6f
......@@ -3023,25 +3023,25 @@ const char* crocksdb_table_properties_get_str(crocksdb_table_properties_t* props
auto rep = props->rep_;
switch (prop) {
case kColumnFamilyName:
if (slen) *slen = rep->column_family_name.size();
*slen = rep->column_family_name.size();
return rep->column_family_name.data();
case kFilterPolicyName:
if (slen) *slen = rep->filter_policy_name.size();
*slen = rep->filter_policy_name.size();
return rep->filter_policy_name.data();
case kComparatorName:
if (slen) *slen = rep->comparator_name.size();
*slen = rep->comparator_name.size();
return rep->comparator_name.data();
case kMergeOperatorName:
if (slen) *slen = rep->merge_operator_name.size();
*slen = rep->merge_operator_name.size();
return rep->merge_operator_name.data();
case kPrefixExtractorName:
if (slen) *slen = rep->prefix_extractor_name.size();
*slen = rep->prefix_extractor_name.size();
return rep->prefix_extractor_name.data();
case kPropertyCollectorsNames:
if (slen) *slen = rep->property_collectors_names.size();
*slen = rep->property_collectors_names.size();
return rep->property_collectors_names.data();
case kCompressionName:
if (slen) *slen = rep->compression_name.size();
*slen = rep->compression_name.size();
return rep->compression_name.data();
}
return nullptr;
......@@ -3055,15 +3055,7 @@ crocksdb_table_properties_get_user_properties(crocksdb_table_properties_t* props
/* Table Properties Collection */
struct crocksdb_table_properties_collection_t {
TablePropertiesCollection* rep_ = nullptr;
crocksdb_table_properties_collection_t() {
rep_ = new TablePropertiesCollection;
}
~crocksdb_table_properties_collection_t() {
delete rep_;
}
TablePropertiesCollection rep_;
};
crocksdb_table_properties_collection_t*
......@@ -3085,8 +3077,8 @@ crocksdb_table_properties_collection_iterator_t*
crocksdb_table_properties_collection_iter_create(
crocksdb_table_properties_collection_t* collection) {
auto it = new crocksdb_table_properties_collection_iterator_t;
it->cur_ = collection->rep_->begin();
it->end_ = collection->rep_->end();
it->cur_ = collection->rep_.begin();
it->end_ = collection->rep_.end();
return it;
}
......@@ -3237,7 +3229,7 @@ void crocksdb_options_add_table_properties_collector_factory(
void crocksdb_get_properties_of_all_tables(crocksdb_t* db,
crocksdb_table_properties_collection_t* props, char** errptr) {
auto s = db->rep->GetPropertiesOfAllTables(props->rep_);
auto s = db->rep->GetPropertiesOfAllTables(&props->rep_);
if (!s.ok()) {
SaveError(errptr, s);
}
......@@ -3246,7 +3238,7 @@ void crocksdb_get_properties_of_all_tables(crocksdb_t* db,
void crocksdb_get_properties_of_all_tables_cf(
crocksdb_t* db, crocksdb_column_family_handle_t* cf,
crocksdb_table_properties_collection_t* props, char** errptr) {
auto s = db->rep->GetPropertiesOfAllTables(cf->rep, props->rep_);
auto s = db->rep->GetPropertiesOfAllTables(cf->rep, &props->rep_);
if (!s.ok()) {
SaveError(errptr, s);
}
......@@ -3266,7 +3258,7 @@ void crocksdb_get_properties_of_tables_in_range(
auto s = db->rep->GetPropertiesOfTablesInRange(cf->rep,
ranges.data(),
ranges.size(),
props->rep_);
&props->rep_);
if (!s.ok()) {
SaveError(errptr, s);
}
......
......@@ -26,7 +26,7 @@ use std::fmt::{self, Debug, Formatter};
use std::ops::Deref;
use std::path::Path;
use std::str::from_utf8;
use table_properties::{TablePropertiesCollection, TablePropertiesCollectionHandle};
use table_properties::{TablePropertiesCollection, new_table_properties_collection};
const DEFAULT_COLUMN_FAMILY: &'static str = "default";
......@@ -1047,9 +1047,9 @@ impl DB {
pub fn get_properties_of_all_tables(&self) -> Result<TablePropertiesCollection, String> {
unsafe {
let handle = TablePropertiesCollectionHandle::new();
ffi_try!(crocksdb_get_properties_of_all_tables(self.inner, handle.inner));
Ok(TablePropertiesCollection::new(handle))
let props = new_table_properties_collection();
ffi_try!(crocksdb_get_properties_of_all_tables(self.inner, props.inner));
Ok(props)
}
}
......@@ -1057,9 +1057,9 @@ impl DB {
cf: &CFHandle)
-> Result<TablePropertiesCollection, String> {
unsafe {
let handle = TablePropertiesCollectionHandle::new();
ffi_try!(crocksdb_get_properties_of_all_tables_cf(self.inner, cf.inner, handle.inner));
Ok(TablePropertiesCollection::new(handle))
let props = new_table_properties_collection();
ffi_try!(crocksdb_get_properties_of_all_tables_cf(self.inner, cf.inner, props.inner));
Ok(props)
}
}
......@@ -1072,7 +1072,7 @@ impl DB {
let limit_keys: Vec<*const u8> = ranges.iter().map(|x| x.end_key.as_ptr()).collect();
let limit_keys_lens: Vec<_> = ranges.iter().map(|x| x.end_key.len()).collect();
unsafe {
let handle = TablePropertiesCollectionHandle::new();
let props = new_table_properties_collection();
ffi_try!(crocksdb_get_properties_of_tables_in_range(self.inner,
cf.inner,
ranges.len() as i32,
......@@ -1080,8 +1080,8 @@ impl DB {
start_keys_lens.as_ptr(),
limit_keys.as_ptr(),
limit_keys_lens.as_ptr(),
handle.inner));
Ok(TablePropertiesCollection::new(handle))
props.inner));
Ok(props)
}
}
}
......
......@@ -19,11 +19,15 @@ use std::marker::PhantomData;
use std::slice;
use std::str;
pub struct TablePropertiesCollectionHandle {
pub fn new_table_properties_collection() -> TablePropertiesCollection {
TablePropertiesCollection::new()
}
pub struct TablePropertiesCollection {
pub inner: *mut DBTablePropertiesCollection,
}
impl Drop for TablePropertiesCollectionHandle {
impl Drop for TablePropertiesCollection {
fn drop(&mut self) {
unsafe {
crocksdb_ffi::crocksdb_table_properties_collection_destroy(self.inner);
......@@ -31,24 +35,14 @@ impl Drop for TablePropertiesCollectionHandle {
}
}
impl TablePropertiesCollectionHandle {
pub fn new() -> TablePropertiesCollectionHandle {
impl TablePropertiesCollection {
fn new() -> TablePropertiesCollection {
unsafe {
TablePropertiesCollectionHandle {
TablePropertiesCollection {
inner: crocksdb_ffi::crocksdb_table_properties_collection_create(),
}
}
}
}
pub struct TablePropertiesCollection {
handle: TablePropertiesCollectionHandle,
}
impl TablePropertiesCollection {
pub fn new(handle: TablePropertiesCollectionHandle) -> TablePropertiesCollection {
TablePropertiesCollection { handle: handle }
}
pub fn collect(&self) -> HashMap<&str, TableProperties> {
let mut res = HashMap::new();
......@@ -77,10 +71,9 @@ impl<'a> Drop for TablePropertiesCollectionIter<'a> {
impl<'a> TablePropertiesCollectionIter<'a> {
fn new(props: &'a TablePropertiesCollection) -> TablePropertiesCollectionIter<'a> {
unsafe {
let inner = props.handle.inner;
TablePropertiesCollectionIter {
props: PhantomData,
inner: crocksdb_ffi::crocksdb_table_properties_collection_iter_create(inner),
inner: crocksdb_ffi::crocksdb_table_properties_collection_iter_create(props.inner),
}
}
}
......
......@@ -61,8 +61,7 @@ extern "C" fn name(handle: *mut c_void) -> *const c_char {
extern "C" fn destruct(handle: *mut c_void) {
unsafe {
let handle = &mut *(handle as *mut TablePropertiesCollectorHandle);
Box::from_raw(handle);
Box::from_raw(handle as *mut TablePropertiesCollectorHandle);
}
}
......
......@@ -14,7 +14,6 @@
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use rocksdb::{DB, Range, Options, Writable, DBEntryType, TablePropertiesCollection,
TablePropertiesCollector, TablePropertiesCollectorFactory};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt;
use tempdir::TempDir;
......@@ -94,7 +93,7 @@ impl fmt::Display for ExampleCollector {
impl TablePropertiesCollector for ExampleCollector {
fn add(&mut self, key: &[u8], _: &[u8], entry_type: DBEntryType, _: u64, _: u64) {
if key.cmp(&self.last_key) != Ordering::Equal {
if key != self.last_key.as_slice() {
self.num_keys += 1;
self.last_key.clear();
self.last_key.extend_from_slice(key);
......
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