From 44d90743e80925016aa1e6e0827307c90ead6646 Mon Sep 17 00:00:00 2001 From: wxnzb <3127484862@qq.com> Date: Sat, 18 Jan 2025 00:57:56 +0800 Subject: [PATCH 1/2] Synchronize-config-content --- src/config.cc | 15 +++++++++++++++ src/kiwi.h | 4 ++++ src/net/event_server.h | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/src/config.cc b/src/config.cc index a6bec78..4c535c1 100644 --- a/src/config.cc +++ b/src/config.cc @@ -14,6 +14,7 @@ #include "config.h" #include "std/std_string.h" #include "store.h" +#include "kiwi.h" namespace kiwi { @@ -222,6 +223,20 @@ Status Config::Set(std::string key, const std::string& value, bool init_stage) { if (iter == config_map_.end()) { return Status::NotFound("Non-existent configuration items."); } + if(key=="log_level") + g_kiwi->options_.SetLogLevel(value); + if(key=="redis_compatible_mode") + g_kiwi->options_.SetRedisCompatibleMode(stoi(value)); + if(key=="worker_threads_num") + { + g_kiwi->options_.SetThreadNum(stoi(value)+stoi((config_map_.find("salve_threads_num"))->second->Value())); + g_kiwi->GetEventServer()->UpdateOptions(g_kiwi->options_); + } + if(key=="salve_threads_num") + { + g_kiwi->options_.SetThreadNum(stoi(value)+stoi((config_map_.find("worker_threads_num"))->second->Value())); + g_kiwi->GetEventServer()->UpdateOptions(g_kiwi->options_); + } return iter->second->Set(value, init_stage); } diff --git a/src/kiwi.h b/src/kiwi.h index 038f5b6..e0939f8 100644 --- a/src/kiwi.h +++ b/src/kiwi.h @@ -76,6 +76,10 @@ class KiwiDB final { time_t GetStartTime() { return start_time_s_; } + net::EventServer>* GetEventServer() { + return event_server_.get(); + } + public: uint16_t port_{0}; diff --git a/src/net/event_server.h b/src/net/event_server.h index 7742842..7790397 100644 --- a/src/net/event_server.h +++ b/src/net/event_server.h @@ -72,6 +72,11 @@ class EventServer final { void TCPConnect(const SocketAddr &addr, const std::function &cb); + void UpdateOptions(const NetOptions& newOptions){ + opt_ = newOptions; + threadsManager_.reserve(opt_.GetThreadNum()); + } + private: int StartThreadManager(bool serverMode); @@ -273,4 +278,6 @@ int EventServer::StartThreadManager(bool serverMode) { return static_cast(NetListen::OK); } + + } // namespace net From 6a73ae11bb897a3cf8fb9f4f7dcf68b8cd2072f7 Mon Sep 17 00:00:00 2001 From: wxnzb <3127484862@qq.com> Date: Sat, 18 Jan 2025 01:01:55 +0800 Subject: [PATCH 2/2] Synchronize-config-content --- src/config.cc | 22 +++++++++------------- src/kiwi.h | 4 +--- src/net/event_server.h | 10 +++------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/config.cc b/src/config.cc index 4c535c1..7d3892f 100644 --- a/src/config.cc +++ b/src/config.cc @@ -12,9 +12,9 @@ #include #include "config.h" +#include "kiwi.h" #include "std/std_string.h" #include "store.h" -#include "kiwi.h" namespace kiwi { @@ -223,19 +223,15 @@ Status Config::Set(std::string key, const std::string& value, bool init_stage) { if (iter == config_map_.end()) { return Status::NotFound("Non-existent configuration items."); } - if(key=="log_level") - g_kiwi->options_.SetLogLevel(value); - if(key=="redis_compatible_mode") - g_kiwi->options_.SetRedisCompatibleMode(stoi(value)); - if(key=="worker_threads_num") - { - g_kiwi->options_.SetThreadNum(stoi(value)+stoi((config_map_.find("salve_threads_num"))->second->Value())); - g_kiwi->GetEventServer()->UpdateOptions(g_kiwi->options_); + if (key == "log_level") g_kiwi->options_.SetLogLevel(value); + if (key == "redis_compatible_mode") g_kiwi->options_.SetRedisCompatibleMode(stoi(value)); + if (key == "worker_threads_num") { + g_kiwi->options_.SetThreadNum(stoi(value) + stoi((config_map_.find("salve_threads_num"))->second->Value())); + g_kiwi->GetEventServer()->UpdateOptions(g_kiwi->options_); } - if(key=="salve_threads_num") - { - g_kiwi->options_.SetThreadNum(stoi(value)+stoi((config_map_.find("worker_threads_num"))->second->Value())); - g_kiwi->GetEventServer()->UpdateOptions(g_kiwi->options_); + if (key == "salve_threads_num") { + g_kiwi->options_.SetThreadNum(stoi(value) + stoi((config_map_.find("worker_threads_num"))->second->Value())); + g_kiwi->GetEventServer()->UpdateOptions(g_kiwi->options_); } return iter->second->Set(value, init_stage); } diff --git a/src/kiwi.h b/src/kiwi.h index e0939f8..3efa677 100644 --- a/src/kiwi.h +++ b/src/kiwi.h @@ -76,9 +76,7 @@ class KiwiDB final { time_t GetStartTime() { return start_time_s_; } - net::EventServer>* GetEventServer() { - return event_server_.get(); - } + net::EventServer>* GetEventServer() { return event_server_.get(); } public: uint16_t port_{0}; diff --git a/src/net/event_server.h b/src/net/event_server.h index 7790397..d8e3d5c 100644 --- a/src/net/event_server.h +++ b/src/net/event_server.h @@ -72,7 +72,7 @@ class EventServer final { void TCPConnect(const SocketAddr &addr, const std::function &cb); - void UpdateOptions(const NetOptions& newOptions){ + void UpdateOptions(const NetOptions &newOptions) { opt_ = newOptions; threadsManager_.reserve(opt_.GetThreadNum()); } @@ -106,8 +106,7 @@ class EventServer final { }; template -requires HasSetFdFunction -std::pair EventServer::StartServer(int64_t interval) { +requires HasSetFdFunction std::pair EventServer::StartServer(int64_t interval) { if (opt_.GetThreadNum() <= 0) { return std::pair(false, "thread num must be greater than 0"); } @@ -146,8 +145,7 @@ std::pair EventServer::StartServer(int64_t interval) { } template -requires HasSetFdFunction -std::pair EventServer::StartClientServer() { +requires HasSetFdFunction std::pair EventServer::StartClientServer() { if (opt_.GetThreadNum() <= 0) { return std::pair(false, "thread num must be greater than 0"); } @@ -278,6 +276,4 @@ int EventServer::StartThreadManager(bool serverMode) { return static_cast(NetListen::OK); } - - } // namespace net