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