From 711f64b2d1fd47af7f63dafe351be80985bcb702 Mon Sep 17 00:00:00 2001 From: cheniujh <1271435567@qq.com> Date: Thu, 5 Dec 2024 11:25:26 +0800 Subject: [PATCH] support dynamically change max-subcompactions --- src/pika_admin.cc | 19 +++++++++++++++++++ src/storage/src/options_helper.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 3c0cf13b11..42861349ae 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -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"); @@ -2677,6 +2683,19 @@ void ConfigCmd::ConfigSet(std::shared_ptr db) { } g_pika_conf->SetMaxBackgroudCompactions(static_cast(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 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(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"); diff --git a/src/storage/src/options_helper.h b/src/storage/src/options_helper.h index 5907e2116f..f7830f23b5 100644 --- a/src/storage/src/options_helper.h +++ b/src/storage/src/options_helper.h @@ -38,6 +38,7 @@ inline int offset_of(T1 T2::*member) { static std::unordered_map 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}},