Skip to content

Commit

Permalink
add max_background_flushes and max_background_compactions support
Browse files Browse the repository at this point in the history
  • Loading branch information
flabby committed May 19, 2016
1 parent e43f411 commit 57a9548
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ db_sync_speed : -1
binlog_file_size : 104857600
# Compression
compression : snappy
# max_background_flushes: default is 1, limited in [1, 4]
max_background_flushes : 1
# max_background_compactions: default is 1, limited in [1, 4]
max_background_compactions : 1
5 changes: 5 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class PikaConf : public slash::BaseConf {
}
std::string compression() { RWLock l(&rwlock_, false); return compression_; }
int target_file_size_base() { RWLock l(&rwlock_, false); return target_file_size_base_; }
int max_background_flushes() { RWLock l(&rwlock_, false); return max_background_flushes_; }
int max_background_compactions() { RWLock l(&rwlock_, false); return max_background_compactions_; }
int expire_logs_nums() { RWLock l(&rwlock_, false); return expire_logs_nums_; }
int expire_logs_days() { RWLock l(&rwlock_, false); return expire_logs_days_; }
std::string conf_path() { RWLock l(&rwlock_, false); return conf_path_; }
Expand Down Expand Up @@ -145,6 +147,9 @@ class PikaConf : public slash::BaseConf {
int expire_logs_nums_;
bool readonly_;
std::string conf_path_;
int max_background_flushes_;
int max_background_compactions_;

//char username_[30];
//char password_[30];

Expand Down
12 changes: 11 additions & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,14 @@ void ConfigCmd::ConfigGet(std::string &ret) {
ret = "*2\r\n";
EncodeString(&ret, "target_file_size_base");
EncodeInt32(&ret, g_pika_conf->target_file_size_base());
} else if (get_item == "max_background_flushes") {
ret = "*2\r\n";
EncodeString(&ret, "max_background_flushes");
EncodeInt32(&ret, g_pika_conf->max_background_flushes());
} else if (get_item == "max_background_compactions") {
ret = "*2\r\n";
EncodeString(&ret, "max_background_compactions");
EncodeInt32(&ret, g_pika_conf->max_background_compactions());
} else if (get_item == "expire_logs_days") {
ret = "*2\r\n";
EncodeString(&ret, "expire_logs_days");
Expand Down Expand Up @@ -742,7 +750,7 @@ void ConfigCmd::ConfigGet(std::string &ret) {
EncodeString(&ret, "no");
}
} else if (get_item == "*") {
ret = "*28\r\n";
ret = "*30\r\n";
EncodeString(&ret, "port");
EncodeString(&ret, "thread_num");
EncodeString(&ret, "sync_thread_num");
Expand All @@ -762,6 +770,8 @@ void ConfigCmd::ConfigGet(std::string &ret) {
EncodeString(&ret, "pidfile");
EncodeString(&ret, "maxconnection");
EncodeString(&ret, "target_file_size_base");
EncodeString(&ret, "max_background_flushes");
EncodeString(&ret, "max_background_compactions");
EncodeString(&ret, "expire_logs_days");
EncodeString(&ret, "expire_logs_nums");
EncodeString(&ret, "root_connection_num");
Expand Down
20 changes: 20 additions & 0 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ int PikaConf::Load()
target_file_size_base_ = 1048576; // 10M
}

max_background_flushes_ = 1;
GetConfInt("max_background_flushes", &max_background_flushes_);
if (max_background_flushes_ <= 0) {
max_background_flushes_ = 1;
}
if (max_background_flushes_ >= 4) {
max_background_flushes_ = 4;
}

max_background_compactions_ = 1;
GetConfInt("max_background_compactions", &max_background_compactions_);
if (max_background_compactions_ <= 0) {
max_background_compactions_ = 1;
}
if (max_background_compactions_ >= 4) {
max_background_compactions_ = 4;
}

// daemonize
std::string dmz;
GetConfStr("daemonize", &dmz);
Expand Down Expand Up @@ -142,6 +160,8 @@ int PikaConf::ConfigRewrite() {
SetConfInt("root_connection_num", root_connection_num_);
SetConfInt("slowlog_log_slower_than", slowlog_log_slower_than_);
SetConfInt("target_file_size_base", target_file_size_base_);
SetConfInt("max_background_flushes", max_background_flushes_);
SetConfInt("max_background_compactions", max_background_compactions_);
SetConfInt("expire_logs_nums", expire_logs_nums_);
SetConfInt("expire_logs_days", expire_logs_days_);
SetConfBool("slave_read_only", readonly_);
Expand Down
2 changes: 2 additions & 0 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ PikaServer::PikaServer() :

option.write_buffer_size = g_pika_conf->write_buffer_size();
option.target_file_size_base = g_pika_conf->target_file_size_base();
option.max_background_flushes = g_pika_conf->max_background_flushes();
option.max_background_compactions = g_pika_conf->max_background_compactions();
if (g_pika_conf->compression() == "none") {
option.compression = false;
}
Expand Down
2 changes: 1 addition & 1 deletion third/nemo
Submodule nemo updated from 78d0c6 to d2253f

0 comments on commit 57a9548

Please sign in to comment.