Skip to content

Commit

Permalink
1) bugfix for pink; 2) check 'ulimit -n' at startup 3) do not remove …
Browse files Browse the repository at this point in the history
…master when master reply already_exist
  • Loading branch information
KernelMaker committed Jun 29, 2016
1 parent e8ce0da commit 4ec72d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/pika_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct SlaveItem {
struct timeval create_time;
};

#define PIKA_MIN_RESERVED_FDS 5000

#define SLAVE_ITEM_STAGE_ONE 1
#define SLAVE_ITEM_STAGE_TWO 2

Expand Down
16 changes: 16 additions & 0 deletions src/pika.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <glog/logging.h>
#include <sys/resource.h>
#include "pika_server.h"
#include "pika_command.h"
#include "pika_conf.h"
Expand Down Expand Up @@ -132,6 +133,21 @@ int main(int argc, char *argv[]) {

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
if (g_pika_conf->daemonize()) {
daemonize();
Expand Down
6 changes: 3 additions & 3 deletions src/pika_trysync_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ bool PikaTrysyncThread::RecvProc() {
// 3, Master do dbsyncing
LOG(INFO) << "Need wait to sync";
g_pika_server->NeedWaitDBSync();
} else {
LOG(WARNING) << "remove master";
g_pika_server->RemoveMaster();
// } else {
// LOG(WARNING) << "remove master";
// g_pika_server->RemoveMaster();
}
return false;
}
Expand Down

0 comments on commit 4ec72d1

Please sign in to comment.