diff --git a/src/cmd_admin.cc b/src/cmd_admin.cc index 24be00f04..ae7d61701 100644 --- a/src/cmd_admin.cc +++ b/src/cmd_admin.cc @@ -60,7 +60,7 @@ void FlushdbCmd::DoCmd(PClient* client) { int currentDBIndex = client->GetCurrentDB(); PSTORE.GetBackend(currentDBIndex).get()->Lock(); - std::string db_path = g_config.db_path.ToString() + std::to_string(currentDBIndex); + std::string db_path = g_config.db_path + std::to_string(currentDBIndex); std::string path_temp = db_path; path_temp.append("_deleting/"); pstd::RenameFile(db_path, path_temp); @@ -81,7 +81,7 @@ bool FlushallCmd::DoInitial(PClient* client) { return true; } void FlushallCmd::DoCmd(PClient* client) { for (size_t i = 0; i < g_config.databases; ++i) { PSTORE.GetBackend(i).get()->Lock(); - std::string db_path = g_config.db_path.ToString() + std::to_string(i); + std::string db_path = g_config.db_path + std::to_string(i); std::string path_temp = db_path; path_temp.append("_deleting/"); pstd::RenameFile(db_path, path_temp); @@ -115,7 +115,7 @@ ShutdownCmd::ShutdownCmd(const std::string& name, int16_t arity) bool ShutdownCmd::DoInitial(PClient* client) { // For now, only shutdown need check local if (client->PeerIP().find("127.0.0.1") == std::string::npos && - client->PeerIP().find(g_config.ip.ToString()) == std::string::npos) { + client->PeerIP().find(g_config.ip) == std::string::npos) { client->SetRes(CmdRes::kErrOther, kCmdNameShutdown + " should be localhost"); return false; } diff --git a/src/config.cc b/src/config.cc index 96d2d8fe9..67e253ddd 100644 --- a/src/config.cc +++ b/src/config.cc @@ -5,10 +5,6 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#include -#include -#include - #include "config.h" #include "pstd/pstd_string.h" #include "store.h" @@ -76,6 +72,43 @@ Status StringValue::SetValue(const std::string& value) { } Status BoolValue::SetValue(const std::string& value) { + if (pstd::StringEqualCaseInsensitive(value, "yes")) { + *value_ = true; + } else { + *value_ = false; + } + return Status::OK(); +} + +template +Status NumberValue::SetValue(const std::string& value) { + T v; + auto [ptr, ec] = std::from_chars(value.data(), value.data() + value.length(), v); + if (ec != std::errc()) { + return Status::InvalidArgument("Failed to convert to a number."); + } + if (v < value_min_) { + v = value_min_; + } + if (v > value_max_) { + v = value_max_; + } + *value_ = v; + return Status::OK(); +} + +Status AtomicStringValue::SetValue(const std::string& value) { + auto values = SplitString(value, delimiter_); + if (values.size() != values_.size()) { + return Status::InvalidArgument("The number of parameters does not match."); + } + for (int i = 0; i < values_.size(); i++) { + *values_[i] = std::move(values[i]); + } + return Status::OK(); +} + +Status AtomicBoolValue::SetValue(const std::string& value) { if (pstd::StringEqualCaseInsensitive(value, "yes")) { value_->store(true); } else { @@ -85,7 +118,7 @@ Status BoolValue::SetValue(const std::string& value) { } template -Status NumberValue::SetValue(const std::string& value) { +Status AtomicNumberValue::SetValue(const std::string& value) { T v; auto [ptr, ec] = std::from_chars(value.data(), value.data() + value.length(), v); if (ec != std::errc()) { @@ -102,28 +135,29 @@ Status NumberValue::SetValue(const std::string& value) { } PConfig::PConfig() { + // TODO(lihuan): update all affected references AddBool("daemonize", &CheckYesNo, false, &daemonize); AddString("ip", false, {&ip}); AddNumberWihLimit("port", false, &port, PORT_LIMIT_MIN, PORT_LIMIT_MAX); - AddNumber("raft-port-offset", true, &raft_port_offset); - AddNumber("timeout", true, &timeout); + AddAtomicNumber("raft-port-offset", true, &raft_port_offset); + AddAtomicNumber("timeout", true, &timeout); AddString("db-path", false, {&db_path}); AddStrinWithFunc("loglevel", &CheckLogLevel, false, {&log_level}); AddString("logfile", false, {&log_dir}); AddNumberWihLimit("databases", false, &databases, 1, DBNUMBER_MAX); - AddString("requirepass", true, {&password}); - AddNumber("maxclients", true, &max_clients); + AddAtomicString("requirepass", true, {&password}); + AddAtomicNumber("maxclients", true, &max_clients); AddNumberWihLimit("worker-threads", false, &worker_threads_num, 1, THREAD_MAX); AddNumberWihLimit("slave-threads", false, &worker_threads_num, 1, THREAD_MAX); - AddNumber("slowlog-log-slower-than", true, &slow_log_time); - AddNumber("slowlog-max-len", true, &slow_log_max_len); - AddNumberWihLimit("db-instance-num", true, &db_instance_num, 1, ROCKSDB_INSTANCE_NUMBER_MAX); + AddAtomicNumber("slowlog-log-slower-than", true, &slow_log_time); + AddAtomicNumber("slowlog-max-len", true, &slow_log_max_len); + AddAtomicNumberWihLimit("db-instance-num", true, &db_instance_num, 1, ROCKSDB_INSTANCE_NUMBER_MAX); AddNumberWihLimit("fast-cmd-threads-num", false, &fast_cmd_threads_num, 1, THREAD_MAX); AddNumberWihLimit("slow-cmd-threads-num", false, &slow_cmd_threads_num, 1, THREAD_MAX); - AddNumber("max-client-response-size", true, &max_client_response_size); - AddString("runid", false, {&run_id}); - AddNumber("small-compaction-threshold", true, &small_compaction_threshold); - AddNumber("small-compaction-duration-threshold", true, &small_compaction_duration_threshold); + AddAtomicNumber("max-client-response-size", true, &max_client_response_size); + AddAtomicString("runid", false, {&run_id}); + AddAtomicNumber("small-compaction-threshold", true, &small_compaction_threshold); + AddAtomicNumber("small-compaction-duration-threshold", true, &small_compaction_duration_threshold); AddBool("use-raft", &CheckYesNo, false, &use_raft); // rocksdb config @@ -133,11 +167,10 @@ PConfig::PConfig() { AddNumber("rocksdb-min-write-buffer-number-to-merge", false, &rocksdb_min_write_buffer_number_to_merge); AddNumber("rocksdb-write-buffer-size", false, &rocksdb_write_buffer_size); AddNumber("rocksdb-level0-file-num-compaction-trigger", false, &rocksdb_level0_file_num_compaction_trigger); - AddNumber("rocksdb-number-levels", true, &rocksdb_num_levels); + AddAtomicNumber("rocksdb-number-levels", true, &rocksdb_num_levels); AddBool("rocksdb-enable-pipelined-write", CheckYesNo, false, &rocksdb_enable_pipelined_write); AddNumber("rocksdb-level0-slowdown-writes-trigger", false, &rocksdb_level0_slowdown_writes_trigger); AddNumber("rocksdb-level0-stop-writes-trigger", false, &rocksdb_level0_stop_writes_trigger); - AddNumber("rocksdb-level0-slowdown-writes-trigger", false, &rocksdb_level0_slowdown_writes_trigger); } bool PConfig::LoadFromFile(const std::string& file_name) { diff --git a/src/config.h b/src/config.h index 7b1196388..08572835c 100644 --- a/src/config.h +++ b/src/config.h @@ -33,8 +33,8 @@ extern PConfig g_config; class BaseValue { public: - BaseValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable = false) - : key_(key), custom_check_func_ptr_(check_func_ptr), rewritable_(rewritable) {} + BaseValue(std::string key, CheckFunc check_func_ptr, bool rewritable = false) + : key_(std::move(key)), custom_check_func_ptr_(std::move(check_func_ptr)), rewritable_(rewritable) {} virtual ~BaseValue() = default; @@ -42,7 +42,7 @@ class BaseValue { virtual std::string Value() const = 0; - Status Set(const std::string& value, bool force); + Status Set(const std::string& value, bool init_stage); protected: virtual Status SetValue(const std::string&) = 0; @@ -62,8 +62,10 @@ class BaseValue { class StringValue : public BaseValue { public: StringValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, - const std::vector& value_ptr_vec, char delimiter = ' ') - : BaseValue(key, check_func_ptr, rewritable), values_(value_ptr_vec), delimiter_(delimiter) { + std::vector value_ptr_vec, char delimiter = ' ') + : BaseValue(key, std::move(check_func_ptr), rewritable), + values_(std::move(value_ptr_vec)), + delimiter_(delimiter) { assert(!values_.empty()); } ~StringValue() override = default; @@ -73,15 +75,69 @@ class StringValue : public BaseValue { private: Status SetValue(const std::string& value) override; - std::vector values_; + std::vector values_; char delimiter_ = 0; }; template class NumberValue : public BaseValue { public: - NumberValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, std::atomic* value_ptr, + NumberValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, T* value, T min = std::numeric_limits::min(), T max = std::numeric_limits::max()) + : BaseValue(key, check_func_ptr, rewritable), value_(value), value_min_(min), value_max_(max) { + assert(value_ != nullptr); + assert(value_min_ <= value_max_); + }; + + std::string Value() const override { return std::to_string(*value_); } + + private: + Status SetValue(const std::string& value) override; + + T* value_; + T value_min_; + T value_max_; +}; + +class BoolValue : public BaseValue { + public: + BoolValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, bool* value) + : BaseValue(key, std::move(check_func_ptr), rewritable), value_(value) { + assert(value_ != nullptr); + }; + + std::string Value() const override { return *value_ ? "yes" : "no"; }; + + private: + Status SetValue(const std::string& value) override; + bool* value_ = nullptr; +}; + +class AtomicStringValue : public BaseValue { + public: + AtomicStringValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, + std::vector value_ptr_vec, char delimiter = ' ') + : BaseValue(key, std::move(check_func_ptr), rewritable), + values_(std::move(value_ptr_vec)), + delimiter_(delimiter) { + assert(!values_.empty()); + } + ~AtomicStringValue() override = default; + + std::string Value() const override { return MergeString(values_, delimiter_); }; + + private: + Status SetValue(const std::string& value) override; + + std::vector values_; + char delimiter_ = 0; +}; + +template +class AtomicNumberValue : public BaseValue { + public: + AtomicNumberValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, std::atomic* value_ptr, + T min = std::numeric_limits::min(), T max = std::numeric_limits::max()) : BaseValue(key, check_func_ptr, rewritable), value_(value_ptr), value_min_(min), value_max_(max) { assert(value_ != nullptr); assert(value_min_ <= value_max_); @@ -97,10 +153,10 @@ class NumberValue : public BaseValue { T value_max_; }; -class BoolValue : public BaseValue { +class AtomicBoolValue : public BaseValue { public: - BoolValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, std::atomic* value_ptr) - : BaseValue(key, check_func_ptr, rewritable), value_(value_ptr) { + AtomicBoolValue(const std::string& key, CheckFunc check_func_ptr, bool rewritable, std::atomic* value_ptr) + : BaseValue(key, std::move(check_func_ptr), rewritable), value_(value_ptr) { assert(value_ != nullptr); }; @@ -121,7 +177,7 @@ class PConfig { bool LoadFromFile(const std::string& file_name); const std::string& ConfigFileName() const { return config_file_name_; } void Get(const std::string&, std::vector*) const; - Status Set(std::string, const std::string&, bool force = false); + Status Set(std::string, const std::string&, bool init_stage = false); public: std::atomic_uint32_t timeout = 0; @@ -136,41 +192,41 @@ class PConfig { std::atomic_uint32_t master_port; // replication AtomicString include_file; // the template config std::vector modules; // modules - std::atomic_int32_t fast_cmd_threads_num = 4; - std::atomic_int32_t slow_cmd_threads_num = 4; + int32_t fast_cmd_threads_num = 4; + int32_t slow_cmd_threads_num = 4; std::atomic_uint64_t max_client_response_size = 1073741824; std::atomic_uint64_t small_compaction_threshold = 604800; std::atomic_uint64_t small_compaction_duration_threshold = 259200; - std::atomic_bool daemonize = false; + bool daemonize = false; AtomicString pid_file = "./pikiwidb.pid"; - AtomicString ip = "127.0.0.1"; - std::atomic_uint16_t port = 9221; + std::string ip = "127.0.0.1"; + uint16_t port = 9221; std::atomic_uint16_t raft_port_offset = 10; - AtomicString db_path = "./db/"; - AtomicString log_dir = "stdout"; // the log directory, differ from redis - AtomicString log_level = "warning"; + std::string db_path = "./db/"; + std::string log_dir = "stdout"; // the log directory, differ from redis + std::string log_level = "warning"; AtomicString run_id; - std::atomic databases = 16; - std::atomic_uint32_t worker_threads_num = 2; + size_t databases = 16; + uint32_t worker_threads_num = 2; std::atomic_uint32_t slave_threads_num = 2; std::atomic db_instance_num = 3; - std::atomic_bool use_raft = true; + bool use_raft = true; - std::atomic_uint32_t rocksdb_max_subcompactions = 0; + uint32_t rocksdb_max_subcompactions = 0; // default 2 - std::atomic_int rocksdb_max_background_jobs = 4; + int rocksdb_max_background_jobs = 4; // default 2 - std::atomic rocksdb_max_write_buffer_number = 2; + size_t rocksdb_max_write_buffer_number = 2; // default 2 - std::atomic_int rocksdb_min_write_buffer_number_to_merge = 2; + int rocksdb_min_write_buffer_number_to_merge = 2; // default 64M - std::atomic rocksdb_write_buffer_size = 64 << 20; - std::atomic_int rocksdb_level0_file_num_compaction_trigger = 4; + size_t rocksdb_write_buffer_size = 64 << 20; + int rocksdb_level0_file_num_compaction_trigger = 4; std::atomic_int rocksdb_num_levels = 7; - std::atomic_bool rocksdb_enable_pipelined_write = false; - std::atomic_int rocksdb_level0_slowdown_writes_trigger = 20; - std::atomic_int rocksdb_level0_stop_writes_trigger = 36; + bool rocksdb_enable_pipelined_write = false; + int rocksdb_level0_slowdown_writes_trigger = 20; + int rocksdb_level0_stop_writes_trigger = 36; std::atomic_uint64_t rocksdb_ttl_second = 604800; // default 86400 * 7 std::atomic_uint64_t rocksdb_periodic_second = 259200; // default 86400 * 3 @@ -179,26 +235,48 @@ class PConfig { rocksdb::BlockBasedTableOptions GetRocksDBBlockBasedTableOptions(); private: - inline void AddString(const std::string& key, bool rewritable, std::vector values_ptr_vector) { + inline void AddString(const std::string& key, bool rewritable, const std::vector& values_ptr_vector) { config_map_.emplace(key, std::make_unique(key, nullptr, rewritable, values_ptr_vector)); } inline void AddStrinWithFunc(const std::string& key, const CheckFunc& checkfunc, bool rewritable, - std::vector values_ptr_vector) { + const std::vector& values_ptr_vector) { config_map_.emplace(key, std::make_unique(key, checkfunc, rewritable, values_ptr_vector)); } - inline void AddBool(const std::string& key, const CheckFunc& checkfunc, bool rewritable, - std::atomic* value_ptr) { + inline void AddBool(const std::string& key, const CheckFunc& checkfunc, bool rewritable, bool* value_ptr) { config_map_.emplace(key, std::make_unique(key, checkfunc, rewritable, value_ptr)); } template - inline void AddNumber(const std::string& key, bool rewritable, std::atomic* value_ptr) { + inline void AddNumber(const std::string& key, bool rewritable, T* value_ptr) { config_map_.emplace(key, std::make_unique>(key, nullptr, rewritable, value_ptr)); } template - inline void AddNumberWihLimit(const std::string& key, bool rewritable, std::atomic* value_ptr, T min, T max) { + inline void AddNumberWihLimit(const std::string& key, bool rewritable, T* value_ptr, T min, T max) { config_map_.emplace(key, std::make_unique>(key, nullptr, rewritable, value_ptr, min, max)); } + // inline functions for add atomic Values + inline void AddAtomicString(const std::string& key, bool rewritable, + const std::vector& values_ptr_vector) { + config_map_.emplace(key, std::make_unique(key, nullptr, rewritable, values_ptr_vector)); + } + inline void AddAtomicStrinWithFunc(const std::string& key, const CheckFunc& checkfunc, bool rewritable, + const std::vector& values_ptr_vector) { + config_map_.emplace(key, std::make_unique(key, checkfunc, rewritable, values_ptr_vector)); + } + inline void AddAtomicBool(const std::string& key, const CheckFunc& checkfunc, bool rewritable, + std::atomic* value_ptr) { + config_map_.emplace(key, std::make_unique(key, checkfunc, rewritable, value_ptr)); + } + template + inline void AddAtomicNumber(const std::string& key, bool rewritable, std::atomic* value_ptr) { + config_map_.emplace(key, std::make_unique>(key, nullptr, rewritable, value_ptr)); + } + template + inline void AddAtomicNumberWihLimit(const std::string& key, bool rewritable, std::atomic* value_ptr, T min, + T max) { + config_map_.emplace(key, std::make_unique>(key, nullptr, rewritable, value_ptr, min, max)); + } + private: ConfigParser parser_; ConfigMap config_map_; diff --git a/src/db.cc b/src/db.cc index ac6974b5f..2bde2c3f8 100644 --- a/src/db.cc +++ b/src/db.cc @@ -33,7 +33,7 @@ rocksdb::Status DB::Open() { storage_options.small_compaction_threshold = g_config.small_compaction_threshold.load(); storage_options.small_compaction_duration_threshold = g_config.small_compaction_duration_threshold.load(); - if (g_config.use_raft.load(std::memory_order_relaxed)) { + if (g_config.use_raft) { storage_options.append_log_function = [&r = PRAFT](const Binlog& log, std::promise&& promise) { r.AppendLog(log, std::move(promise)); }; @@ -107,7 +107,7 @@ void DB::LoadDBFromCheckpoint(const std::string& checkpoint_path, bool sync [[ma storage_options.options.ttl = g_config.rocksdb_ttl_second.load(std::memory_order_relaxed); storage_options.options.periodic_compaction_seconds = g_config.rocksdb_periodic_second.load(std::memory_order_relaxed); - if (g_config.use_raft.load(std::memory_order_relaxed)) { + if (g_config.use_raft) { storage_options.append_log_function = [&r = PRAFT](const Binlog& log, std::promise&& promise) { r.AppendLog(log, std::move(promise)); }; diff --git a/src/pikiwidb.cc b/src/pikiwidb.cc index 0638c3c49..dcb6ef1bf 100644 --- a/src/pikiwidb.cc +++ b/src/pikiwidb.cc @@ -137,28 +137,28 @@ bool PikiwiDB::Init() { } NewTcpConnectionCallback cb = std::bind(&PikiwiDB::OnNewConnection, this, std::placeholders::_1); - if (!worker_threads_.Init(g_config.ip.ToString().c_str(), g_config.port.load(), cb)) { - ERROR("worker_threads Init failed. IP = {} Port = {}", g_config.ip.ToString(), g_config.port.load()); + if (!worker_threads_.Init(g_config.ip.c_str(), g_config.port, cb)) { + ERROR("worker_threads Init failed. IP = {} Port = {}", g_config.ip, g_config.port); return false; } - auto num = g_config.worker_threads_num.load() + g_config.slave_threads_num.load(); + auto num = g_config.worker_threads_num + g_config.slave_threads_num.load(); auto kMaxWorkerNum = IOThreadPool::GetMaxWorkerNum(); if (num > kMaxWorkerNum) { ERROR("number of threads can't exceeds {}, now is {}", kMaxWorkerNum, num); return false; } - worker_threads_.SetWorkerNum(static_cast(g_config.worker_threads_num.load())); + worker_threads_.SetWorkerNum(static_cast(g_config.worker_threads_num)); slave_threads_.SetWorkerNum(static_cast(g_config.slave_threads_num.load())); // now we only use fast cmd thread pool - auto status = cmd_threads_.Init(g_config.fast_cmd_threads_num.load(), 0, "pikiwidb-cmd"); + auto status = cmd_threads_.Init(g_config.fast_cmd_threads_num, 0, "pikiwidb-cmd"); if (!status.ok()) { ERROR("init cmd thread pool failed: {}", status.ToString()); return false; } - PSTORE.Init(g_config.databases.load(std::memory_order_relaxed)); + PSTORE.Init(g_config.databases); PSlowLog::Instance().SetThreshold(g_config.slow_log_time.load()); PSlowLog::Instance().SetLogLimit(static_cast(g_config.slow_log_max_len.load())); @@ -256,7 +256,7 @@ int main(int ac, char* av[]) { static_cast(g_config.port)); std::cout << logo; - if (g_config.daemonize.load()) { + if (g_config.daemonize) { daemonize(); } @@ -264,7 +264,7 @@ int main(int ac, char* av[]) { SignalSetup(); InitLogs(); - if (g_config.daemonize.load()) { + if (g_config.daemonize) { closeStd(); } diff --git a/src/praft/praft.cc b/src/praft/praft.cc index 26239c743..5a837b75d 100644 --- a/src/praft/praft.cc +++ b/src/praft/praft.cc @@ -120,9 +120,9 @@ butil::Status PRaft::Init(std::string& group_id, bool initial_conf_is_null) { this->group_id_ = group_id; // FIXME: g_config.ip is default to 127.0.0.0, which may not work in cluster. - raw_addr_ = g_config.ip.ToString() + ":" + std::to_string(port); + raw_addr_ = g_config.ip + ":" + std::to_string(port); butil::ip_t ip; - auto ret = butil::str2ip(g_config.ip.ToString().c_str(), &ip); + auto ret = butil::str2ip(g_config.ip.c_str(), &ip); if (ret != 0) { server_.reset(); return ERROR_LOG_AND_STATUS("Failed to convert str_ip to butil::ip_t"); @@ -150,7 +150,7 @@ butil::Status PRaft::Init(std::string& group_id, bool initial_conf_is_null) { node_options_.fsm = this; node_options_.node_owns_fsm = false; node_options_.snapshot_interval_s = 0; - std::string prefix = "local://" + g_config.db_path.ToString() + "_praft"; + std::string prefix = "local://" + g_config.db_path + "_praft"; node_options_.log_uri = prefix + "/log"; node_options_.raft_meta_uri = prefix + "/raft_meta"; node_options_.snapshot_uri = prefix + "/snapshot"; @@ -273,7 +273,7 @@ void PRaft::SendNodeAddRequest(PClient* client) { // Node id in braft are ip:port, the node id param in RAFT.NODE ADD cmd will be ignored. int unused_node_id = 0; auto port = g_config.port + pikiwidb::g_config.raft_port_offset; - auto raw_addr = g_config.ip.ToString() + ":" + std::to_string(port); + auto raw_addr = g_config.ip + ":" + std::to_string(port); UnboundedBuffer req; req.PushData("RAFT.NODE ADD ", 14); req.PushData(std::to_string(unused_node_id).c_str(), std::to_string(unused_node_id).size()); @@ -629,8 +629,8 @@ void PRaft::on_snapshot_save(braft::SnapshotWriter* writer, braft::Closure* done int PRaft::on_snapshot_load(braft::SnapshotReader* reader) { CHECK(!IsLeader()) << "Leader is not supposed to load snapshot"; assert(reader); - auto reader_path = reader->get_path(); // xx/snapshot_0000001 - auto path = g_config.db_path.ToString() + std::to_string(db_id_); // db/db_id + auto reader_path = reader->get_path(); // xx/snapshot_0000001 + auto path = g_config.db_path + std::to_string(db_id_); // db/db_id TasksVector tasks(1, {TaskType::kLoadDBFromCheckpoint, db_id_, {{TaskArg::kCheckpointPath, reader_path}}, true}); PSTORE.HandleTaskSpecificDB(tasks); return 0; diff --git a/src/replication.cc b/src/replication.cc index a1f1125f7..66bd722ad 100644 --- a/src/replication.cc +++ b/src/replication.cc @@ -175,7 +175,7 @@ void PReplication::Cron() { if (masterInfo_.addr.IsValid()) { switch (masterInfo_.state) { case kPReplStateNone: { - if (masterInfo_.addr.GetIP() == g_config.ip.ToString() && masterInfo_.addr.GetPort() == g_config.port) { + if (masterInfo_.addr.GetIP() == g_config.ip && masterInfo_.addr.GetPort() == g_config.port) { ERROR("Fix config, master addr is self addr!"); assert(!!!"wrong config for master addr"); } @@ -225,11 +225,11 @@ void PReplication::Cron() { } else if (master->GetAuth()) { // send replconf char req[128]; - auto len = snprintf(req, sizeof req - 1, "replconf listening-port %hu\r\n", g_config.port.load()); + auto len = snprintf(req, sizeof req - 1, "replconf listening-port %hu\r\n", g_config.port); master->SendPacket(req, len); masterInfo_.state = kPReplStateWaitReplconf; - INFO("Send replconf listening-port {}", g_config.port.load()); + INFO("Send replconf listening-port {}", g_config.port); } else { WARN("Haven't auth to master yet, or check masterauth password"); }