Skip to content

Commit

Permalink
support dynamically change max-subcompactions
Browse files Browse the repository at this point in the history
  • Loading branch information
cheniujh committed Dec 5, 2024
1 parent 937ebde commit 711f64b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,12 @@ void ConfigCmd::ConfigGet(std::string& ret) {
EncodeNumber(&config_body, g_pika_conf->max_background_compactions());
}

if (pstd::stringmatch(pattern.data(), "max-subcompactions", 1) != 0) {
elements += 2;
EncodeString(&config_body, "max-subcompactions");
EncodeNumber(&config_body, g_pika_conf->max_subcompactions());
}

if (pstd::stringmatch(pattern.data(), "max-background-jobs", 1) != 0) {
elements += 2;
EncodeString(&config_body, "max-background-jobs");
Expand Down Expand Up @@ -2677,6 +2683,19 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
}
g_pika_conf->SetMaxBackgroudCompactions(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "max-subcompactions") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0 || ival <= 0) {
res_.AppendStringRaw( "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-subcompactions'\r\n");
return;
}
std::unordered_map<std::string, std::string> options_map{{"max_subcompactions", value}};
storage::Status s = g_pika_server->RewriteStorageOptions(storage::OptionType::kDB, options_map);
if (!s.ok()) {
res_.AppendStringRaw("-ERR Set max_subcompactions wrong: " + s.ToString() + "\r\n");
return;
}
g_pika_conf->SetMaxSubcompactions(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "rocksdb-periodic-second") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0) {
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'rocksdb-periodic-second'\r\n");
Expand Down
1 change: 1 addition & 0 deletions src/storage/src/options_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ inline int offset_of(T1 T2::*member) {
static std::unordered_map<std::string, MemberTypeInfo> mutable_db_options_member_type_info = {
{"max_background_jobs", {offsetof(struct rocksdb::DBOptions, max_background_jobs), MemberType::kInt}},
{"max_background_compactions", {offsetof(struct rocksdb::DBOptions, max_background_compactions), MemberType::kInt}},
{"max_subcompactions", {offsetof(struct rocksdb::DBOptions, max_subcompactions), MemberType::kInt}},
// {"base_background_compactions", {offsetof(struct rocksdb::DBOptions, base_background_compactions),
// MemberType::kInt}},
{"max_open_files", {offsetof(struct rocksdb::DBOptions, max_open_files), MemberType::kInt}},
Expand Down

0 comments on commit 711f64b

Please sign in to comment.