Skip to content

Commit

Permalink
make mario binlog_file_size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
flabby committed Dec 25, 2015
1 parent 8d04125 commit 91a308f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ expire_logs_nums : 10
root_connection_num : 2
# Slowlog_log_slower_than
slowlog_log_slower_than : 10000

###################
## Critical Settings
###################
# binlog file size: default is 100M, limited in [1K, 2G]
binlog_file_size : 104857600
2 changes: 2 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PikaConf : public BaseConf
int expire_logs_nums() { RWLock l(&rwlock_, false); return expire_logs_nums_; }
int root_connection_num() { RWLock l(&rwlock_, false); return root_connection_num_; }
int64_t slowlog_slower_than() { RWLock l(&rwlock_, false); return slowlog_slower_than_; }
int binlog_file_size() { return binlog_file_size_; }

void SetPort(const int value) { RWLock l(&rwlock_, true); port_ = value; }
void SetThreadNum(const int value) { RWLock l(&rwlock_, true); thread_num_ = value; }
Expand Down Expand Up @@ -71,6 +72,7 @@ class PikaConf : public BaseConf
int expire_logs_nums_;
int root_connection_num_;
int slowlog_slower_than_;
int binlog_file_size_;

char conf_path_[PIKA_WORD_SIZE];
pthread_rwlock_t rwlock_;
Expand Down
3 changes: 2 additions & 1 deletion src/pika.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ int main(int argc, char **argv)
} else {
LOG(FATAL) << "Pika Server init error";
}
g_pikaMario = new mario::Mario(g_pikaConf->log_path(), 100);
g_pikaMario = new mario::Mario(g_pikaConf->log_path(),
static_cast<uint64_t>(g_pikaConf->binlog_file_size()), 100);
LOG(WARNING) << "Pika init mario ok";

LOG(WARNING) << "Pika Server going to start";
Expand Down
5 changes: 5 additions & 0 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ PikaConf::PikaConf(const char* path) :
getConfInt("expire_logs_nums", &expire_logs_nums_);
getConfInt("root_connection_num", &root_connection_num_);
getConfInt("slowlog_log_slower_than", &slowlog_slower_than_);
getConfInt("binlog_file_size", &binlog_file_size_);

if (thread_num_ <= 0) {
thread_num_ = 16;
Expand Down Expand Up @@ -63,5 +64,9 @@ PikaConf::PikaConf(const char* path) :
daemonize_ = false;
}

if (binlog_file_size_ < 1024 || static_cast<int64_t>(binlog_file_size_) > (1024LL * 1024 * 1024 * 2)) {
binlog_file_size_ = 100 * 1024 * 1024; // 100M
}

pthread_rwlock_init(&rwlock_, NULL);
}
2 changes: 1 addition & 1 deletion third/mario/include/mario.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct ThreadArg {
class Mario
{
public:
Mario(const char* mario_path, int32_t retry = 10);
Mario(const char* mario_path, uint64_t file_size, int32_t retry = 10);
~Mario();
Status Put(const std::string &item);
Status Put(const char* item, int len);
Expand Down
2 changes: 1 addition & 1 deletion third/mario/include/mario_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static const int64_t kPoolSize = 1073741824;
/*
* The size of write2file when we need to rotate
*/
static const uint64_t kMmapSize = 1024 * 1024 * 100;
static uint64_t kMmapSize = 1024 * 1024 * 100;

static std::string kWrite2file = "/write2file";

Expand Down
4 changes: 3 additions & 1 deletion third/mario/src/mario.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Mario::Writer {
explicit Writer(port::Mutex* mu) : cv(mu) { }
};

Mario::Mario(const char* mario_path, int32_t retry)
Mario::Mario(const char* mario_path, uint64_t file_size, int32_t retry)
: consumer_num_(0),
item_num_(0),
env_(Env::Default()),
Expand All @@ -41,6 +41,8 @@ Mario::Mario(const char* mario_path, int32_t retry)
mario_path_(mario_path)
{
// env_->set_thread_num(consumer_num_);
kMmapSize = file_size;

filename_ = mario_path_ + kWrite2file;
const std::string manifest = mario_path_ + kManifest;
std::string profile;
Expand Down

0 comments on commit 91a308f

Please sign in to comment.