提交 67c87514 编写于 作者: Z zhaoanan

Merge branch 'master' of github.com:Qihoo360/pika

...@@ -35,6 +35,8 @@ struct SlaveItem { ...@@ -35,6 +35,8 @@ struct SlaveItem {
struct timeval create_time; struct timeval create_time;
}; };
#define PIKA_MIN_RESERVED_FDS 5000
#define SLAVE_ITEM_STAGE_ONE 1 #define SLAVE_ITEM_STAGE_ONE 1
#define SLAVE_ITEM_STAGE_TWO 2 #define SLAVE_ITEM_STAGE_TWO 2
......
#include <glog/logging.h> #include <glog/logging.h>
#include <sys/resource.h>
#include "pika_server.h" #include "pika_server.h"
#include "pika_command.h" #include "pika_command.h"
#include "pika_conf.h" #include "pika_conf.h"
...@@ -132,6 +133,21 @@ int main(int argc, char *argv[]) { ...@@ -132,6 +133,21 @@ int main(int argc, char *argv[]) {
PikaConfInit(path); PikaConfInit(path);
rlimit limit;
if (getrlimit(RLIMIT_NOFILE,&limit) == -1) {
LOG(WARNING) << "getrlimit error: " << strerror(errno);
} else if (limit.rlim_cur < g_pika_conf->maxclients() + PIKA_MIN_RESERVED_FDS) {
rlim_t old_limit = limit.rlim_cur;
rlim_t best_limit = g_pika_conf->maxclients() + PIKA_MIN_RESERVED_FDS;
limit.rlim_cur = best_limit > limit.rlim_max ? limit.rlim_max-1 : best_limit;
limit.rlim_max = best_limit > limit.rlim_max ? limit.rlim_max-1 : best_limit;
if (setrlimit(RLIMIT_NOFILE,&limit) != -1) {
LOG(WARNING) << "your 'limit -n ' of " << old_limit << " is not enough for Redis to start. pika have successfully reconfig it to " << limit.rlim_cur;
} else {
LOG(FATAL) << "your 'limit -n ' of " << old_limit << " is not enough for Redis to start. pika can not reconfig it(" << strerror(errno) << "), do it by yourself";
}
}
// daemonize if needed // daemonize if needed
if (g_pika_conf->daemonize()) { if (g_pika_conf->daemonize()) {
daemonize(); daemonize();
......
...@@ -64,7 +64,7 @@ std::string PikaClientConn::DoCmd(const std::string& opt) { ...@@ -64,7 +64,7 @@ std::string PikaClientConn::DoCmd(const std::string& opt) {
if (is_monitoring) { if (is_monitoring) {
monitor_message = std::to_string(1.0*slash::NowMicros()/1000000) + " [" + this->ip_port() + "]"; monitor_message = std::to_string(1.0*slash::NowMicros()/1000000) + " [" + this->ip_port() + "]";
for (PikaCmdArgsType::iterator iter = argv_.begin(); iter != argv_.end(); iter++) { for (PikaCmdArgsType::iterator iter = argv_.begin(); iter != argv_.end(); iter++) {
monitor_message += " \"" + *iter + "\""; monitor_message += " " + slash::ToRead(*iter);
} }
g_pika_server->monitor_thread()->AddMonitorMessage(monitor_message); g_pika_server->monitor_thread()->AddMonitorMessage(monitor_message);
} }
......
...@@ -42,7 +42,7 @@ int PikaMasterConn::DealMessage() { ...@@ -42,7 +42,7 @@ int PikaMasterConn::DealMessage() {
if (is_monitoring) { if (is_monitoring) {
monitor_message = std::to_string(1.0*slash::NowMicros()/1000000) + " [" + this->ip_port() + "]"; monitor_message = std::to_string(1.0*slash::NowMicros()/1000000) + " [" + this->ip_port() + "]";
for (PikaCmdArgsType::iterator iter = argv_.begin(); iter != argv_.end(); iter++) { for (PikaCmdArgsType::iterator iter = argv_.begin(); iter != argv_.end(); iter++) {
monitor_message += " \"" + *iter + "\""; monitor_message += " " + slash::ToRead(*iter);
} }
g_pika_server->monitor_thread()->AddMonitorMessage(monitor_message); g_pika_server->monitor_thread()->AddMonitorMessage(monitor_message);
} }
......
...@@ -60,8 +60,8 @@ PikaServer::PikaServer() : ...@@ -60,8 +60,8 @@ PikaServer::PikaServer() :
} }
pika_dispatch_thread_ = new PikaDispatchThread(port_, worker_num_, pika_worker_thread_, 3000); pika_dispatch_thread_ = new PikaDispatchThread(port_, worker_num_, pika_worker_thread_, 3000);
pika_binlog_receiver_thread_ = new PikaBinlogReceiverThread(port_ + 100, 1000); pika_binlog_receiver_thread_ = new PikaBinlogReceiverThread(port_ + 1000, 1000);
pika_heartbeat_thread_ = new PikaHeartbeatThread(port_ + 200, 1000); pika_heartbeat_thread_ = new PikaHeartbeatThread(port_ + 2000, 1000);
pika_trysync_thread_ = new PikaTrysyncThread(); pika_trysync_thread_ = new PikaTrysyncThread();
monitor_thread_ = new PikaMonitorThread(); monitor_thread_ = new PikaMonitorThread();
......
...@@ -93,9 +93,9 @@ bool PikaTrysyncThread::RecvProc() { ...@@ -93,9 +93,9 @@ bool PikaTrysyncThread::RecvProc() {
// 3, Master do dbsyncing // 3, Master do dbsyncing
LOG(INFO) << "Need wait to sync"; LOG(INFO) << "Need wait to sync";
g_pika_server->NeedWaitDBSync(); g_pika_server->NeedWaitDBSync();
} else { // } else {
LOG(WARNING) << "remove master"; // LOG(WARNING) << "remove master";
g_pika_server->RemoveMaster(); // g_pika_server->RemoveMaster();
} }
return false; return false;
} }
...@@ -208,7 +208,7 @@ void* PikaTrysyncThread::ThreadMain() { ...@@ -208,7 +208,7 @@ void* PikaTrysyncThread::ThreadMain() {
std::string ip_port = slash::IpPortString(master_ip, master_port); std::string ip_port = slash::IpPortString(master_ip, master_port);
// We append the master ip port after module name // We append the master ip port after module name
// To make sure only data from current master is received // To make sure only data from current master is received
int ret = slash::StartRsync(dbsync_path, kDBSyncModule + "_" + ip_port, g_pika_conf->port() + 300); int ret = slash::StartRsync(dbsync_path, kDBSyncModule + "_" + ip_port, g_pika_conf->port() + 3000);
if (0 != ret) { if (0 != ret) {
LOG(WARNING) << "Failed to start rsync, path:" << dbsync_path << " error : " << ret; LOG(WARNING) << "Failed to start rsync, path:" << dbsync_path << " error : " << ret;
} }
......
Subproject commit a0b3f5896567ac7bbe8838abde12f819c5803c6e Subproject commit 5774732aec5a9066a009d7311561808dd5e25820
Subproject commit 2446f4b6b6465836567f717eb6960cbed6a358ab Subproject commit adaf7837e2562e8c8d92a345d0382d91e28df63b
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册