Skip to content

Commit f7677f0

Browse files
mjc2-stripemeta-codesync[bot]
authored andcommitted
add rocksdb_set_db_options for dynamic DB option updates (#14615)
Summary: # Context The C API lacks a SetDBOptions wrapper, so callers using the C bindings cannot dynamically reconfigure DB-level options at runtime without dropping down to the C++ API. # Changes - Add `rocksdb_set_db_options` to the C API as a wrapper around `DB::SetDBOptions` - Adds new tests in `c_test.c` covering both valid and invalid option updates Pull Request resolved: #14615 Reviewed By: joshkang97 Differential Revision: D101010593 Pulled By: xingbowang fbshipit-source-id: 3feac94bd0e3b7d6a4913ce9bc014e1233292309
1 parent c9252b9 commit f7677f0

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎db/c.cc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,6 +4266,15 @@ void rocksdb_set_options(rocksdb_t* db, int count, const char* const keys[],
42664266
SaveError(errptr, db->rep->SetOptions(options_map));
42674267
}
42684268

4269+
void rocksdb_set_db_options(rocksdb_t* db, int count, const char* const keys[],
4270+
const char* const values[], char** errptr) {
4271+
std::unordered_map<std::string, std::string> options_map;
4272+
for (int i = 0; i < count; i++) {
4273+
options_map[keys[i]] = values[i];
4274+
}
4275+
SaveError(errptr, db->rep->SetDBOptions(options_map));
4276+
}
4277+
42694278
void rocksdb_set_options_cf(rocksdb_t* db,
42704279
rocksdb_column_family_handle_t* handle, int count,
42714280
const char* const keys[],

‎db/c_test.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,19 @@ int main(int argc, char** argv) {
960960
CheckNoError(err);
961961
CheckGet(db, roptions, "foo", "hello");
962962

963+
StartPhase("set_db_options");
964+
{
965+
const char* keys[] = {"stats_dump_period_sec"};
966+
const char* values[] = {"10"};
967+
rocksdb_set_db_options(db, 1, keys, values, &err);
968+
CheckNoError(err);
969+
970+
keys[0] = "not_a_db_option";
971+
rocksdb_set_db_options(db, 1, keys, values, &err);
972+
CheckCondition(err != NULL);
973+
Free(&err);
974+
}
975+
963976
StartPhase("backup_and_restore");
964977
{
965978
rocksdb_destroy_db(options, dbbackupname, &err);

‎include/rocksdb/c.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,10 @@ extern ROCKSDB_LIBRARY_API void rocksdb_set_options(rocksdb_t* db, int count,
14521452
const char* const values[],
14531453
char** errptr);
14541454

1455+
extern ROCKSDB_LIBRARY_API void rocksdb_set_db_options(
1456+
rocksdb_t* db, int count, const char* const keys[],
1457+
const char* const values[], char** errptr);
1458+
14551459
extern ROCKSDB_LIBRARY_API void rocksdb_set_options_cf(
14561460
rocksdb_t* db, rocksdb_column_family_handle_t* handle, int count,
14571461
const char* const keys[], const char* const values[], char** errptr);

0 commit comments

Comments
 (0)