-
Notifications
You must be signed in to change notification settings - Fork 155
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
export mulit_get interface #59
Conversation
Please add test. |
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.
doubt about error handing, return types, and Vec<&[u8]>
as parameter type.
librocksdb_sys/src/lib.rs
Outdated
num_keys: size_t, | ||
keys_list: *const *const u8, | ||
keys_list_sizes: *const size_t, | ||
values_list: *mut *mut u8, |
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.
should it be *mut *const u8
?
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.
DBVector type use *mut u8.
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 think it should be *mut *mut u8
. Both the values_list and its content needs to be dropped explicitly.
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 understand. value_list is created by crocksdb, malloc().
so we need to own it in DBVector and drop() it by free() via ffi.
src/rocksdb.rs
Outdated
cf: &CFHandle, | ||
keys_vec: Vec<&[u8]>, | ||
readopts: &ReadOptions) | ||
-> Result<Option<Vec<DBVector>>, 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.
should be Result<Vec<Option<DBVector>>, _>
or more precisely
Vec<Result<Option<DBVector>, String>>
since we use Option<>
to denote Status::NotFound
src/rocksdb.rs
Outdated
@@ -513,6 +513,81 @@ impl DB { | |||
self.get_cf_opt(cf, key, &ReadOptions::new()) | |||
} | |||
|
|||
pub fn multi_get_cf_opt(&self, | |||
cf: &CFHandle, | |||
keys_vec: Vec<&[u8]>, |
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.
should this be &[&[u8]]
?
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.
well, i'm not sure, maybe &[Vec].
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.
&[Vec] is kind of strange. we've already use &[u8] to denote Slice.
I think &[&[u8]]
is ok.
@siddontang
src/rocksdb.rs
Outdated
let keys_list_sizes = keys_list_sizes.as_ptr(); | ||
let mut value_list = Vec::<*mut u8>::with_capacity(num_keys); | ||
let mut value_list_sizes = Vec::<size_t>::with_capacity(num_keys); | ||
ffi_try!(crocksdb_multi_get_cf(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.
wrong.
since errs is c array of error string, not a pointer to a c string
src/rocksdb.rs
Outdated
pub fn multi_get_opt(&self, | ||
keys_vec: Vec<&[u8]>, | ||
readopts: &ReadOptions) | ||
-> Result<Option<Vec<DBVector>>, 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.
if you export DB::DefaultColumnFamily()
you can impl all the other fn by multi_get_cf_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.
we can use cf_handle("default")
to get the default CF handle.
librocksdb_sys/src/lib.rs
Outdated
keys_list: *const *const u8, | ||
keys_list_sizes: *const size_t, | ||
values_list: *mut *mut u8, | ||
values_list_sizes: *const size_t, |
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.
Should be *mut
.
librocksdb_sys/src/lib.rs
Outdated
num_keys: size_t, | ||
keys_list: *const *const u8, | ||
keys_list_sizes: *const size_t, | ||
values_list: *mut *mut u8, |
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 think it should be *mut *mut u8
. Both the values_list and its content needs to be dropped explicitly.
src/rocksdb.rs
Outdated
} | ||
let keys_list = keys_list.as_ptr(); | ||
let keys_list_sizes = keys_list_sizes.as_ptr(); | ||
let mut value_list = Vec::<*mut u8>::with_capacity(num_keys); |
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.
Type annotation is redundant.
all comments considered, PTAL again. @zhangjinpeng1987 @siddontang @andelf @BusyJay |
src/rocksdb.rs
Outdated
@@ -513,6 +513,71 @@ impl DB { | |||
self.get_cf_opt(cf, key, &ReadOptions::new()) | |||
} | |||
|
|||
pub fn multi_get_cf_opt(&self, | |||
cf: &CFHandle, | |||
keys_vec: &[Vec<u8>], |
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.
s/keys/keys_vec/g
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.
&[&[u8]]
may be better?
/cc @BusyJay
@@ -513,6 +513,71 @@ impl DB { | |||
self.get_cf_opt(cf, key, &ReadOptions::new()) | |||
} | |||
|
|||
pub fn multi_get_cf_opt(&self, |
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 think for easy use, we can declare the return type as Result<Vec<Option<DBVector>>, String>
, If we meet any error in multi_get, we will return error directly.
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.
In what case get will return error?
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.
to �name a few, db corruption, unsupported compression, io error, db busy?
src/rocksdb.rs
Outdated
@@ -513,6 +513,71 @@ impl DB { | |||
self.get_cf_opt(cf, key, &ReadOptions::new()) | |||
} | |||
|
|||
pub fn multi_get_cf_opt(&self, | |||
cf: &CFHandle, | |||
keys: &[Vec<u8>], |
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.
Should be &[&[u8]]
, so we don't need to move the key when query.
src/rocksdb.rs
Outdated
let mut value_vec = Vec::with_capacity(num_keys); | ||
for i in 0..num_keys { | ||
if !err_list[i].is_null() { | ||
return Err(crocksdb_ffi::error_message(err_list[i])); |
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.
memory leaks?
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.
strdup without free
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.
There are still memory leaks. But the content in value_list and err_list should be dropped.
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.
If we want to changed the return type from Vec to Result, the implementation in crocksdb.c can be changed directly.
src/rocksdb.rs
Outdated
let mut value_vec = Vec::with_capacity(num_keys); | ||
for i in 0..num_keys { | ||
if !err_list[i].is_null() { | ||
return Err(crocksdb_ffi::error_message(err_list[i])); |
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.
There are still memory leaks. But the content in value_list and err_list should be dropped.
librocksdb_sys/crocksdb/c.cc
Outdated
@@ -854,6 +854,7 @@ void crocksdb_multi_get_cf( | |||
values_list_sizes[i] = 0; | |||
if (!statuses[i].IsNotFound()) { | |||
errs[i] = strdup(statuses[i].ToString().c_str()); | |||
break; |
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.
please update multi_get too.
Any test? |
src/rocksdb.rs
Outdated
@@ -513,6 +513,71 @@ impl DB { | |||
self.get_cf_opt(cf, key, &ReadOptions::new()) | |||
} | |||
|
|||
pub fn multi_get_cf_opt(&self, | |||
cf: &CFHandle, | |||
keys: &[&[u8]], |
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.
Looks like using generic type here is more suitable. like f<F: AsRef<[u8]>>(keys: &[F])
librocksdb_sys/crocksdb/c.cc
Outdated
@@ -854,6 +854,7 @@ void crocksdb_multi_get_cf( | |||
values_list_sizes[i] = 0; | |||
if (!statuses[i].IsNotFound()) { | |||
errs[i] = strdup(statuses[i].ToString().c_str()); | |||
break; |
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.
errs
should not be accessed as an array any more. Because only the first error is cared now. And copied values should be dropped.
src/rocksdb.rs
Outdated
value_sizes.as_mut_ptr(), | ||
err); | ||
if !err.is_null() { | ||
return Err(crocksdb_ffi::error_message(err)); |
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.
may still meet memory leak if value list has values.
librocksdb_sys/crocksdb/c.cc
Outdated
errs[i] = strdup(statuses[i].ToString().c_str()); | ||
} else { | ||
errs[i] = nullptr; | ||
err = strdup(statuses[i].ToString().c_str()); |
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 is wrong. err
is a pointer which will be passed by value. Use char** err
and SaveError
instead. And should drop all the content in values_list too.
any benchmark to show multi get is better than seek + next if we want to get data in a range. |
benched on my own laptop fetch one kv
fetch two kv
it seems using |
How about get from SST file? |
If there is only one memtable, |
benchmark resultwith about 10 sst file and some keys in memtable, fetch 8 kvs which is in memtable
by the way, the differ between different count fetching in the same condition indicates
|
according to #62, this pr should be closed. 😿 @lishihai9017 |
PTAL @zhangjinpeng1987