Skip to content

Commit 0bd7e6d

Browse files
committed
Add batched multi-get for multiple cfs to C API
Signed-off-by: Jason Volk <jason@zemos.net>
1 parent 5036d90 commit 0bd7e6d

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

db/c.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,48 @@ void rocksdb_batched_multi_get_cf_slice(
23382338
delete[] statuses;
23392339
}
23402340

2341+
void rocksdb_batched_multi_get_multi_cf(rocksdb_t* db,
2342+
const rocksdb_readoptions_t* options,
2343+
size_t num_keys,
2344+
rocksdb_column_family_handle_t** column_families,
2345+
const char* const* keys_list,
2346+
const size_t* keys_list_sizes,
2347+
rocksdb_pinnableslice_t** values,
2348+
char** errs,
2349+
const bool sorted_input) {
2350+
Status* statuses = new Status[num_keys];
2351+
Slice* key_slices = new Slice[num_keys];
2352+
PinnableSlice* value_slices = new PinnableSlice[num_keys];
2353+
ColumnFamilyHandle **cfs = new ColumnFamilyHandle*[num_keys];
2354+
for (size_t i = 0; i < num_keys; ++i) {
2355+
key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]);
2356+
cfs[i] = column_families[i]->rep;
2357+
}
2358+
2359+
db->rep->MultiGet(options->rep, num_keys, cfs, key_slices,
2360+
value_slices, statuses, sorted_input);
2361+
2362+
for (size_t i = 0; i < num_keys; ++i) {
2363+
if (statuses[i].ok()) {
2364+
values[i] = new (rocksdb_pinnableslice_t);
2365+
values[i]->rep = std::move(value_slices[i]);
2366+
errs[i] = nullptr;
2367+
} else {
2368+
values[i] = nullptr;
2369+
if (!statuses[i].IsNotFound()) {
2370+
errs[i] = strdup(statuses[i].ToString().c_str());
2371+
} else {
2372+
errs[i] = nullptr;
2373+
}
2374+
}
2375+
}
2376+
2377+
delete[] cfs;
2378+
delete[] value_slices;
2379+
delete[] key_slices;
2380+
delete[] statuses;
2381+
}
2382+
23412383
unsigned char rocksdb_key_may_exist(rocksdb_t* db,
23422384
const rocksdb_readoptions_t* options,
23432385
const char* key, size_t key_len,

include/rocksdb/c.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ extern ROCKSDB_LIBRARY_API void rocksdb_batched_multi_get_cf_slice(
659659
const rocksdb_slice_t* keys_list, rocksdb_pinnableslice_t** values,
660660
char** errs, const bool sorted_input);
661661

662+
extern ROCKSDB_LIBRARY_API void rocksdb_batched_multi_get_multi_cf(
663+
rocksdb_t* db, const rocksdb_readoptions_t* options,
664+
size_t num_keys, rocksdb_column_family_handle_t** column_families,
665+
const char* const* keys_list, const size_t* keys_list_sizes,
666+
rocksdb_pinnableslice_t** values, char** errs, const bool sorted_input);
667+
662668
// The value is only allocated (using malloc) and returned if it is found and
663669
// value_found isn't NULL. In that case the user is responsible for freeing it.
664670
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_key_may_exist(

0 commit comments

Comments
 (0)