Skip to content

Commit 9a3a213

Browse files
committed
Add batched multi-get for multiple cfs to C API
Signed-off-by: Jason Volk <jason@zemos.net>
1 parent 786f2cd commit 9a3a213

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

db/c.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,48 @@ void rocksdb_batched_multi_get_cf(rocksdb_t* db,
17031703
delete[] statuses;
17041704
}
17051705

1706+
void rocksdb_batched_multi_get_multi_cf(rocksdb_t* db,
1707+
const rocksdb_readoptions_t* options,
1708+
size_t num_keys,
1709+
rocksdb_column_family_handle_t** column_families,
1710+
const char* const* keys_list,
1711+
const size_t* keys_list_sizes,
1712+
rocksdb_pinnableslice_t** values,
1713+
char** errs,
1714+
const bool sorted_input) {
1715+
Status* statuses = new Status[num_keys];
1716+
Slice* key_slices = new Slice[num_keys];
1717+
PinnableSlice* value_slices = new PinnableSlice[num_keys];
1718+
ColumnFamilyHandle **cfs = new ColumnFamilyHandle*[num_keys];
1719+
for (size_t i = 0; i < num_keys; ++i) {
1720+
key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]);
1721+
cfs[i] = column_families[i]->rep;
1722+
}
1723+
1724+
db->rep->MultiGet(options->rep, num_keys, cfs, key_slices,
1725+
value_slices, statuses, sorted_input);
1726+
1727+
for (size_t i = 0; i < num_keys; ++i) {
1728+
if (statuses[i].ok()) {
1729+
values[i] = new (rocksdb_pinnableslice_t);
1730+
values[i]->rep = std::move(value_slices[i]);
1731+
errs[i] = nullptr;
1732+
} else {
1733+
values[i] = nullptr;
1734+
if (!statuses[i].IsNotFound()) {
1735+
errs[i] = strdup(statuses[i].ToString().c_str());
1736+
} else {
1737+
errs[i] = nullptr;
1738+
}
1739+
}
1740+
}
1741+
1742+
delete[] cfs;
1743+
delete[] value_slices;
1744+
delete[] key_slices;
1745+
delete[] statuses;
1746+
}
1747+
17061748
unsigned char rocksdb_key_may_exist(rocksdb_t* db,
17071749
const rocksdb_readoptions_t* options,
17081750
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
@@ -610,6 +610,12 @@ extern ROCKSDB_LIBRARY_API void rocksdb_batched_multi_get_cf(
610610
const char* const* keys_list, const size_t* keys_list_sizes,
611611
rocksdb_pinnableslice_t** values, char** errs, const bool sorted_input);
612612

613+
extern ROCKSDB_LIBRARY_API void rocksdb_batched_multi_get_multi_cf(
614+
rocksdb_t* db, const rocksdb_readoptions_t* options,
615+
size_t num_keys, rocksdb_column_family_handle_t** column_families,
616+
const char* const* keys_list, const size_t* keys_list_sizes,
617+
rocksdb_pinnableslice_t** values, char** errs, const bool sorted_input);
618+
613619
// The value is only allocated (using malloc) and returned if it is found and
614620
// value_found isn't NULL. In that case the user is responsible for freeing it.
615621
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_key_may_exist(

0 commit comments

Comments
 (0)