Skip to content

Commit c4d237d

Browse files
committed
Expose AdvancedColumnFamilyOptions::memtable_batch_lookup_optimization in the C API
The skip-list memtable gained an opt-in batch-lookup optimization that caches the search path between consecutive MultiGet keys, reducing per-key cost from O(log N) to O(log d) where d is the distance between consecutive keys. The optimization is gated by a new immutable AdvancedColumnFamilyOptions field (default: false) which had no C API setter, so the optimization was unreachable from C/Rust. Add a setter/getter pair mirroring the existing rocksdb_options_{set,get}_memtable_huge_page_size — the closest sibling on both the C API side (adjacent memtable knob) and the C++ side (same AdvancedColumnFamilyOptions parent struct). The field is immutable on the C++ side, so the setter only takes effect on options used to open a column family. No change to the C++ API.
1 parent e82af29 commit c4d237d

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

db/c.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5398,6 +5398,16 @@ size_t rocksdb_options_get_memtable_huge_page_size(rocksdb_options_t* opt) {
53985398
return opt->rep.memtable_huge_page_size;
53995399
}
54005400

5401+
void rocksdb_options_set_memtable_batch_lookup_optimization(
5402+
rocksdb_options_t* opt, unsigned char v) {
5403+
opt->rep.memtable_batch_lookup_optimization = v;
5404+
}
5405+
5406+
unsigned char rocksdb_options_get_memtable_batch_lookup_optimization(
5407+
rocksdb_options_t* opt) {
5408+
return opt->rep.memtable_batch_lookup_optimization;
5409+
}
5410+
54015411
void rocksdb_options_set_hash_skip_list_rep(rocksdb_options_t* opt,
54025412
size_t bucket_count,
54035413
int32_t skiplist_height,

db/c_test.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,15 @@ int main(int argc, char** argv) {
28122812
rocksdb_options_set_memtable_huge_page_size(o, 25);
28132813
CheckCondition(25 == rocksdb_options_get_memtable_huge_page_size(o));
28142814

2815+
// memtable_batch_lookup_optimization defaults to 0; flip to 1 to verify
2816+
// the setter is wired through to the underlying C++ ColumnFamilyOptions
2817+
// field.
2818+
CheckCondition(0 ==
2819+
rocksdb_options_get_memtable_batch_lookup_optimization(o));
2820+
rocksdb_options_set_memtable_batch_lookup_optimization(o, 1);
2821+
CheckCondition(1 ==
2822+
rocksdb_options_get_memtable_batch_lookup_optimization(o));
2823+
28152824
rocksdb_options_set_max_successive_merges(o, 26);
28162825
CheckCondition(26 == rocksdb_options_get_max_successive_merges(o));
28172826

@@ -2998,6 +3007,8 @@ int main(int argc, char** argv) {
29983007
rocksdb_options_get_memtable_prefix_bloom_size_ratio(copy));
29993008
CheckCondition(24 == rocksdb_options_get_max_compaction_bytes(copy));
30003009
CheckCondition(25 == rocksdb_options_get_memtable_huge_page_size(copy));
3010+
CheckCondition(
3011+
1 == rocksdb_options_get_memtable_batch_lookup_optimization(copy));
30013012
CheckCondition(26 == rocksdb_options_get_max_successive_merges(copy));
30023013
CheckCondition(27 == rocksdb_options_get_bloom_locality(copy));
30033014
CheckCondition(1 == rocksdb_options_get_inplace_update_support(copy));

include/rocksdb/c.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,12 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_memtable_huge_page_size(
19901990
extern ROCKSDB_LIBRARY_API size_t
19911991
rocksdb_options_get_memtable_huge_page_size(rocksdb_options_t*);
19921992

1993+
extern ROCKSDB_LIBRARY_API void
1994+
rocksdb_options_set_memtable_batch_lookup_optimization(rocksdb_options_t*,
1995+
unsigned char);
1996+
extern ROCKSDB_LIBRARY_API unsigned char
1997+
rocksdb_options_get_memtable_batch_lookup_optimization(rocksdb_options_t*);
1998+
19931999
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_successive_merges(
19942000
rocksdb_options_t*, size_t);
19952001
extern ROCKSDB_LIBRARY_API size_t
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `rocksdb_options_set_memtable_batch_lookup_optimization()` and `rocksdb_options_get_memtable_batch_lookup_optimization()` to the C API, exposing the existing `AdvancedColumnFamilyOptions::memtable_batch_lookup_optimization` field. This allows C API users (and downstream language bindings) to enable the skip-list memtable's batch-lookup optimization for `MultiGet`, which caches the search path between consecutive keys and reduces per-key cost from O(log N) to O(log d) where d is the distance between consecutive keys.

0 commit comments

Comments
 (0)