Commit d7acfb70 authored by Huachao Huang's avatar Huachao Huang

fetch properties lazily

parent 0fe7d360
......@@ -35,7 +35,7 @@ pub struct CFHandle {
}
impl CFHandle {
pub fn get_id(&self) -> u32 {
pub fn id(&self) -> u32 {
unsafe { crocksdb_ffi::crocksdb_column_family_handle_get_id(self.inner) }
}
}
......@@ -1047,9 +1047,9 @@ impl DB {
pub fn get_properties_of_all_tables(&self) -> Result<TablePropertiesCollection, String> {
unsafe {
let props = TablePropertiesCollectionHandle::new();
ffi_try!(crocksdb_get_properties_of_all_tables(self.inner, props.inner));
props.normalize()
let handle = TablePropertiesCollectionHandle::new();
ffi_try!(crocksdb_get_properties_of_all_tables(self.inner, handle.inner));
Ok(TablePropertiesCollection::new(handle))
}
}
......@@ -1057,9 +1057,9 @@ impl DB {
cf: &CFHandle)
-> Result<TablePropertiesCollection, String> {
unsafe {
let props = TablePropertiesCollectionHandle::new();
ffi_try!(crocksdb_get_properties_of_all_tables_cf(self.inner, cf.inner, props.inner));
props.normalize()
let handle = TablePropertiesCollectionHandle::new();
ffi_try!(crocksdb_get_properties_of_all_tables_cf(self.inner, cf.inner, handle.inner));
Ok(TablePropertiesCollection::new(handle))
}
}
......@@ -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 props = TablePropertiesCollectionHandle::new();
let handle = TablePropertiesCollectionHandle::new();
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(),
props.inner));
props.normalize()
handle.inner));
Ok(TablePropertiesCollection::new(handle))
}
}
}
......
This diff is collapsed.
......@@ -16,6 +16,7 @@ use rocksdb::{DB, Range, Options, Writable, DBEntryType, TablePropertiesCollecti
TablePropertiesCollector, TablePropertiesCollectorFactory};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::ffi::CString;
use std::fmt;
use std::io::Cursor;
use tempdir::TempDir;
......@@ -39,6 +40,7 @@ fn decode_u32(x: &[u8]) -> u32 {
}
struct ExampleCollector {
name: CString,
num_keys: u32,
num_puts: u32,
num_merges: u32,
......@@ -49,6 +51,7 @@ struct ExampleCollector {
impl ExampleCollector {
fn new() -> ExampleCollector {
ExampleCollector {
name: CString::new("example-collector").unwrap(),
num_keys: 0,
num_puts: 0,
num_merges: 0,
......@@ -95,11 +98,11 @@ impl fmt::Display for ExampleCollector {
}
impl TablePropertiesCollector for ExampleCollector {
fn name(&self) -> &str {
"example-collector"
fn name(&self) -> &CString {
&self.name
}
fn add_userkey(&mut self, key: &[u8], _: &[u8], entry_type: DBEntryType) {
fn add_userkey(&mut self, key: &[u8], _: &[u8], entry_type: DBEntryType, _: u64, _: u64) {
if key.cmp(&self.last_key) != Ordering::Equal {
self.num_keys += 1;
self.last_key.clear();
......@@ -119,17 +122,19 @@ impl TablePropertiesCollector for ExampleCollector {
}
}
struct ExampleFactory {}
struct ExampleFactory {
name: CString,
}
impl ExampleFactory {
fn new() -> ExampleFactory {
ExampleFactory {}
ExampleFactory { name: CString::new("example-factory").unwrap() }
}
}
impl TablePropertiesCollectorFactory for ExampleFactory {
fn name(&self) -> &str {
"example-factory"
fn name(&self) -> &CString {
&self.name
}
fn create_table_properties_collector(&mut self, _: u32) -> Box<TablePropertiesCollector> {
......@@ -143,12 +148,19 @@ fn check_collection(collection: &TablePropertiesCollection,
num_puts: u32,
num_merges: u32,
num_deletes: u32) {
let mut len = 0;
let mut res = ExampleCollector::new();
for (_, props) in collection {
assert_eq!(props.property_collectors_names, "[example-factory]");
res.add(&ExampleCollector::decode(&props.user_collected_properties));
let mut iter = collection.iter();
while iter.valid() {
len += 1;
{
let v = iter.value();
assert_eq!(v.property_collectors_names(), "[example-factory]");
res.add(&ExampleCollector::decode(&v.user_collected_properties()));
}
iter.next();
}
assert_eq!(collection.len() as u32, num_files);
assert_eq!(len, num_files);
assert_eq!(res.num_keys, num_keys);
assert_eq!(res.num_puts, num_puts);
assert_eq!(res.num_merges, num_merges);
......
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