Skip to content

Commit

Permalink
support dynamic change max-total-wal-size (OpenAtomFoundation#2563)
Browse files Browse the repository at this point in the history
Co-authored-by: wangshaoyi <[email protected]>
  • Loading branch information
wangshao1 and wangshaoyi committed Apr 1, 2024
1 parent 2a0b1a6 commit 45a072e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class PikaConf : public pstd::BaseConf {
std::shared_lock l(rwlock_);
return max_write_buffer_num_;
}
uint64_t MaxTotalWalSize() {
std::shared_lock l(rwlock_);
return max_total_wal_size_;
}
int64_t max_client_response_size() {
std::shared_lock l(rwlock_);
return max_client_response_size_;
Expand Down Expand Up @@ -670,6 +674,11 @@ class PikaConf : public pstd::BaseConf {
TryPushDiffCommands("max-write-buffer-num", std::to_string(value));
max_write_buffer_num_ = value;
}
void SetMaxTotalWalSize(uint64_t value) {
std::lock_guard l(rwlock_);
TryPushDiffCommands("max-total-wal-size", std::to_string(value));
max_total_wal_size_ = value;
}
void SetArenaBlockSize(const int& value) {
std::lock_guard l(rwlock_);
TryPushDiffCommands("arena-block-size", std::to_string(value));
Expand Down Expand Up @@ -765,6 +774,7 @@ class PikaConf : public pstd::BaseConf {
int64_t slotmigrate_thread_num_ = 0;
int64_t thread_migrate_keys_num_ = 0;
int64_t max_write_buffer_size_ = 0;
int64_t max_total_wal_size_ = 0;
int max_write_buffer_num_ = 0;
int min_write_buffer_number_to_merge_ = 1;
int level0_stop_writes_trigger_ = 36;
Expand Down
21 changes: 21 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,12 @@ void ConfigCmd::ConfigGet(std::string& ret) {
EncodeNumber(&config_body, g_pika_conf->max_write_buffer_size());
}

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

if (pstd::stringmatch(pattern.data(), "min-write-buffer-number-to-merge", 1) != 0) {
elements += 2;
EncodeString(&config_body, "min-write-buffer-number-to-merge");
Expand Down Expand Up @@ -2140,6 +2146,7 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
"write-buffer-size",
"max-write-buffer-num",
"min-write-buffer-number-to-merge",
"max-total-wal-size",
"level0-slowdown-writes-trigger",
"level0-stop-writes-trigger",
"level0-file-num-compaction-trigger",
Expand Down Expand Up @@ -2536,6 +2543,20 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
}
g_pika_conf->SetLevel0SlowdownWritesTrigger(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");

} else if (set_item == "max-total-wal-size") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0) {
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-total-wal-size'\r\n");
return;
}
std::unordered_map<std::string, std::string> options_map{{"max_total_wal_size", value}};
storage::Status s = g_pika_server->RewriteStorageOptions(storage::OptionType::kDB, options_map);
if (!s.ok()) {
res_.AppendStringRaw("-ERR Set max-total-wal-size: " + s.ToString() + "\r\n");
return;
}
g_pika_conf->SetMaxTotalWalSize(static_cast<uint64_t>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "level0-file-num-compaction-trigger") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0) {
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'level0-file-num-compaction-trigger'\r\n");
Expand Down
1 change: 1 addition & 0 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ void PikaServer::InitStorageOptions() {
storage_options_.options.arena_block_size = g_pika_conf->arena_block_size();
storage_options_.options.write_buffer_manager =
std::make_shared<rocksdb::WriteBufferManager>(g_pika_conf->max_write_buffer_size());
storage_options_.options.max_total_wal_size = g_pika_conf->MaxTotalWalSize();
storage_options_.options.max_write_buffer_number = g_pika_conf->max_write_buffer_number();
storage_options_.options.level0_file_num_compaction_trigger = g_pika_conf->level0_file_num_compaction_trigger();
storage_options_.options.level0_stop_writes_trigger = g_pika_conf->level0_stop_writes_trigger();
Expand Down

0 comments on commit 45a072e

Please sign in to comment.