-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user properties: clean up API #90
Conversation
BusyJay
commented
Jul 6, 2017
- reduce allocation
- collect lazily
- strict access mode
librocksdb_sys/crocksdb/c.cc
Outdated
crocksdb_table_properties_collection_t* props, char** errptr) { | ||
crocksdb_table_properties_collection_t * | ||
crocksdb_get_properties_of_all_tables(crocksdb_t *db, char **errptr) { | ||
std::unique_ptr<crocksdb_table_properties_collection_t> props( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use make_unique()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But make_unique
is introduced in c++14
?
e4dfd82
to
7cb2901
Compare
librocksdb_sys/crocksdb/c.cc
Outdated
@@ -1768,7 +1768,7 @@ void crocksdb_options_set_compression(crocksdb_options_t* opt, int t) { | |||
opt->rep.compression = static_cast<CompressionType>(t); | |||
} | |||
|
|||
int crocksdb_options_get_compression(crocksdb_options_t* opt) { | |||
int crocksdb_options_get_compression(crocksdb_options_t *opt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any style agreement on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clang-format with Google style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. We should use librocksdb_sys/crocksdb/format-diff.sh to format c/c++ codes, which is adapted from rocksdb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the same style with RocksDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but, I guess this may be a bug with the format tool 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 I know. We've borrowed the format-diff script, but leaves out .clang-format config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I myself use clang-format with google style as command line arguments, which is enough for this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andelf can you add the RocksDB clang format config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying the .clang-format from top dir of rocksdb solves
src/table_properties.rs
Outdated
|
||
pub fn new_table_properties_collection() -> TablePropertiesCollection { | ||
TablePropertiesCollection::new() | ||
} | ||
|
||
pub struct TablePropertiesCollection { | ||
pub inner: *mut DBTablePropertiesCollection, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need pub
anymore :)
impl Drop for TableProperties { | ||
fn drop(&mut self) { | ||
impl TableProperties { | ||
fn from_ptr<'a>(ptr: *const DBTableProperties) -> &'a TableProperties { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return a TableProperties<'a>
and keep the inner pointer here?
It's a bit of magic for me to figure out how this work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's suitable that TableProperties
contains a lifetime. Maybe we can rename it to TablePropertiesRef
. But I believe &'a TableProperties
is more clear and rusty than TablePropertiesRef
. Actually I don't invent the magic by myself, both CStr
and str
are implemented via similar logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this has already been discussed here, I think I'm OK with that.
librocksdb_sys/crocksdb/c.cc
Outdated
const crocksdb_user_collected_properties_t * | ||
crocksdb_table_properties_get_user_properties( | ||
const crocksdb_table_properties_t *props) { | ||
return (const crocksdb_user_collected_properties_t *)&props->rep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use c++ style cast
src/table_properties.rs
Outdated
iter.next(); | ||
} | ||
res | ||
pub fn user_collected_properties(&self) -> UserCollectedPropertiesIter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wrapping UserCollectedProperties struct is better.
Since we need fast index access for propties, not iterating over style access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it. UserCollectedProperties
is a map, how do you access it via index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl Index<&str> for it, wraps std::map operator[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. I thought you want to get (k, v) pair at specific position.
const char* crocksdb_user_collected_properties_get( | ||
const crocksdb_user_collected_properties_t* props, const char* key, | ||
size_t klen, size_t* vlen) { | ||
auto val = props->rep.find(std::string(key, klen)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can iterate the map to avoid constructing the string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends. I prefer using index access here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it invokes copying the key here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But it compare less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems C++ 14 can find without constructing the string, can we use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I prefer stick to C++ 11 for now since rocksdb itself still just require C++ 11. It may be surprising if the wrapper requires a newer version of compiler.
@@ -1072,16 +1070,14 @@ 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 = new_table_properties_collection(); | |||
ffi_try!(crocksdb_get_properties_of_tables_in_range(self.inner, | |||
let props = ffi_try!(crocksdb_get_properties_of_tables_in_range(self.inner, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems not formatted here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'm waiting Travis to tell me the exact code he likes.
src/table_properties.rs
Outdated
} | ||
} | ||
|
||
pub struct UserCollectedPropertiesIter<'a> { | ||
props: PhantomData<&'a TableProperties>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should change to UserCollectedProperties
?
LGTM |
Btw, a |
A |
b72feff
to
7912996
Compare
LGTM |
@huachaohuang PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- reduce allocation - collect lazily - strict access mode
e5d79d6
to
fcef2d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM