Skip to content

Commit

Permalink
Remvoe some pika_conf lock in DoCmd process (OpenAtomFoundation#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
whoiami committed Sep 3, 2019
1 parent 7fae751 commit 94a4473
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 9 additions & 8 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <map>
#include <set>
#include <unordered_set>
#include <atomic>

#include "slash/include/base_conf.h"
#include "slash/include/slash_mutex.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ class PikaConf : public slash::BaseConf {
std::string userpass() { RWLock l(&rwlock_, false); return userpass_; }
const std::string suser_blacklist() { RWLock l(&rwlock_, false); return slash::StringConcat(user_blacklist_, COMMA); }
const std::vector<std::string>& vuser_blacklist() { RWLock l(&rwlock_, false); return user_blacklist_;}
bool classic_mode() { RWLock l(&rwlock_, false); return classic_mode_;}
bool classic_mode() { return classic_mode_.load();}
int databases() { RWLock l(&rwlock_, false); return databases_;}
int default_slot_num() { RWLock l(&rwlock_, false); return default_slot_num_;}
const std::vector<TableStruct>& table_structs() { RWLock l(&rwlock_, false); return table_structs_; }
Expand All @@ -76,8 +77,8 @@ class PikaConf : public slash::BaseConf {
bool slave_read_only() { RWLock l(&rwlock_, false); return slave_read_only_; }
int maxclients() { RWLock l(&rwlock_, false); return maxclients_; }
int root_connection_num() { RWLock l(&rwlock_, false); return root_connection_num_; }
bool slowlog_write_errorlog() { RWLock l(&rwlock_, false); return slowlog_write_errorlog_;}
int slowlog_slower_than() { RWLock l(&rwlock_, false); return slowlog_log_slower_than_; }
bool slowlog_write_errorlog() { return slowlog_write_errorlog_.load();}
int slowlog_slower_than() { return slowlog_log_slower_than_.load(); }
int slowlog_max_len() { RWLock L(&rwlock_, false); return slowlog_max_len_; }
std::string network_interface() { RWLock l(&rwlock_, false); return network_interface_; }

Expand Down Expand Up @@ -192,12 +193,12 @@ class PikaConf : public slash::BaseConf {
void SetSlowlogWriteErrorlog(const bool value) {
RWLock l(&rwlock_, true);
TryPushDiffCommands("slowlog-write-errorlog", value == true ? "yes" : "no");
slowlog_write_errorlog_ = value;
slowlog_write_errorlog_.store(value);
}
void SetSlowlogSlowerThan(const int value) {
RWLock l(&rwlock_, true);
TryPushDiffCommands("slowlog-log-slower-than", std::to_string(value));
slowlog_log_slower_than_ = value;
slowlog_log_slower_than_.store(value);
}
void SetSlowlogMaxLen(const int value) {
RWLock l(&rwlock_, true);
Expand Down Expand Up @@ -257,7 +258,7 @@ class PikaConf : public slash::BaseConf {
std::string masterauth_;
std::string userpass_;
std::vector<std::string> user_blacklist_;
bool classic_mode_;
std::atomic<bool> classic_mode_;
int databases_;
int default_slot_num_;
std::vector<TableStruct> table_structs_;
Expand All @@ -269,8 +270,8 @@ class PikaConf : public slash::BaseConf {
std::string compression_;
int maxclients_;
int root_connection_num_;
bool slowlog_write_errorlog_;
int slowlog_log_slower_than_;
std::atomic<bool> slowlog_write_errorlog_;
std::atomic<int> slowlog_log_slower_than_;
int slowlog_max_len_;
int expire_logs_days_;
int expire_logs_nums_;
Expand Down
14 changes: 8 additions & 6 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ int PikaConf::Load()

std::string swe;
GetConfStr("slowlog-write-errorlog", &swe);
slowlog_write_errorlog_ = swe == "yes" ? true : false;
slowlog_write_errorlog_.store(swe == "yes" ? true : false);

GetConfInt("slowlog-log-slower-than", &slowlog_log_slower_than_);
int tmp_slowlog_log_slower_than;
GetConfInt("slowlog-log-slower-than", &tmp_slowlog_log_slower_than);
slowlog_log_slower_than_.store(tmp_slowlog_log_slower_than);
GetConfInt("slowlog-max-len", &slowlog_max_len_);
if (slowlog_max_len_ == 0) {
slowlog_max_len_ = 128;
Expand Down Expand Up @@ -207,10 +209,10 @@ int PikaConf::Load()

std::string instance_mode;
GetConfStr("instance-mode", &instance_mode);
classic_mode_ = (instance_mode.empty()
classic_mode_.store(instance_mode.empty()
|| !strcasecmp(instance_mode.data(), "classic"));

if (classic_mode_) {
if (classic_mode_.load()) {
GetConfInt("databases", &databases_);
if (databases_ < 1 || databases_ > 8) {
LOG(FATAL) << "config databases error, limit [1 ~ 8], the actual is: "
Expand Down Expand Up @@ -432,8 +434,8 @@ int PikaConf::ConfigRewrite() {
SetConfInt("expire-logs-days", expire_logs_days_);
SetConfInt("expire-logs-nums", expire_logs_nums_);
SetConfInt("root-connection-num", root_connection_num_);
SetConfStr("slowlog-write-errorlog", slowlog_write_errorlog_ ? "yes" : "no");
SetConfInt("slowlog-log-slower-than", slowlog_log_slower_than_);
SetConfStr("slowlog-write-errorlog", slowlog_write_errorlog_.load() ? "yes" : "no");
SetConfInt("slowlog-log-slower-than", slowlog_log_slower_than_.load());
SetConfInt("slowlog-max-len", slowlog_max_len_);
SetConfStr("write-binlog", write_binlog_ ? "yes" : "no");
SetConfInt("max-cache-statistic-keys", max_cache_statistic_keys_);
Expand Down

0 comments on commit 94a4473

Please sign in to comment.