From 99e6e7c5d459764bf5ba76a83768112fcd547be9 Mon Sep 17 00:00:00 2001 From: cheniujh <1271435567@qq.com> Date: Wed, 11 Dec 2024 14:36:06 +0800 Subject: [PATCH] make log-retention-time dynamically changeable (#2963) --- include/pika_conf.h | 7 +++++++ src/pika_admin.cc | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/pika_conf.h b/include/pika_conf.h index 259efc437..3096624d4 100644 --- a/include/pika_conf.h +++ b/include/pika_conf.h @@ -681,6 +681,13 @@ 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 SetMaxWriteBufferNumber(const int& value) { std::lock_guard l(rwlock_); TryPushDiffCommands("max-write-buffer-num", std::to_string(value)); diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 7e6c9d132..14a527b25 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -1625,6 +1625,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"); @@ -2327,6 +2333,13 @@ void ConfigCmd::ConfigSet(std::shared_ptr db) { } g_pika_conf->SetTimeout(static_cast(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(ival)); + res_.AppendStringRaw("+OK\r\n"); } else if (set_item == "requirepass") { g_pika_conf->SetRequirePass(value); g_pika_server->Acl()->UpdateDefaultUserPassword(value);