Skip to content

Commit 0b0f15e

Browse files
committed
Add rocksdb_readoptions_set_table_filter to C API
Expose ReadOptions::table_filter through the C API. The new function accepts a state pointer, a filter callback, and a destructor. The implementation wraps these into a std::function lambda assigned to rep.table_filter, using shared_ptr for lifetime management.
1 parent 6cf9709 commit 0b0f15e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

db/c.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5765,6 +5765,21 @@ void rocksdb_readoptions_set_auto_readahead_size(rocksdb_readoptions_t* opt,
57655765
opt->rep.auto_readahead_size = v;
57665766
}
57675767

5768+
void rocksdb_readoptions_set_table_filter(
5769+
rocksdb_readoptions_t* opt, void* state,
5770+
unsigned char (*table_filter)(void*,
5771+
const rocksdb_table_properties_t*),
5772+
void (*destroy)(void*)) {
5773+
auto shared_state =
5774+
std::shared_ptr<void>(state, destroy ? destroy : [](void*) {});
5775+
opt->rep.table_filter =
5776+
[shared_state, table_filter](const TableProperties& props) -> bool {
5777+
rocksdb_table_properties_t c_props;
5778+
c_props.rep = &props;
5779+
return table_filter(shared_state.get(), &c_props);
5780+
};
5781+
}
5782+
57685783
rocksdb_writeoptions_t* rocksdb_writeoptions_create() {
57695784
return new rocksdb_writeoptions_t;
57705785
}

include/rocksdb/c.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,11 @@ extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_iter_start_ts(
23502350
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_auto_readahead_size(
23512351
rocksdb_readoptions_t*, unsigned char);
23522352

2353+
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_table_filter(
2354+
rocksdb_readoptions_t*, void* state,
2355+
unsigned char (*table_filter)(void*, const rocksdb_table_properties_t*),
2356+
void (*destroy)(void*));
2357+
23532358
/* Write options */
23542359

23552360
extern ROCKSDB_LIBRARY_API rocksdb_writeoptions_t* rocksdb_writeoptions_create(

0 commit comments

Comments
 (0)