Skip to content

Commit

Permalink
make log-retention-time dynamically changeable (#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheniujh authored Dec 11, 2024
1 parent 0db3c5c commit bc46bad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ class PikaConf : public pstd::BaseConf {
TryPushDiffCommands("write-buffer-size", std::to_string(value));
write_buffer_size_ = value;
}
void SetLogRetentionTime(const int& value) {
std::lock_guard l(rwlock_);
TryPushDiffCommands("log-retention-time", std::to_string(value));
log_retention_time_ = value;
}
void SetMinWriteBufferNumberToMerge(const int& value) {
std::lock_guard l(rwlock_);
TryPushDiffCommands("min-write-buffer-number-to-merge", std::to_string(value));
Expand Down
13 changes: 13 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,12 @@ void ConfigCmd::ConfigGet(std::string& ret) {
EncodeNumber(&config_body, g_pika_conf->port());
}

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

if (pstd::stringmatch(pattern.data(), "thread-num", 1) != 0) {
elements += 2;
EncodeString(&config_body, "thread-num");
Expand Down Expand Up @@ -2351,6 +2357,13 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
}
g_pika_conf->SetTimeout(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "log-retention-time") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0 || ival <= 0) {
res_.AppendStringRaw("-ERR Invalid argument " + value + " for CONFIG SET 'log-retention-time'\r\n");
return;
}
g_pika_conf->SetLogRetentionTime(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "requirepass") {
g_pika_conf->SetRequirePass(value);
g_pika_server->Acl()->UpdateDefaultUserPassword(value);
Expand Down

0 comments on commit bc46bad

Please sign in to comment.