Skip to content

Commit

Permalink
bugfix: make mario consumer add command after auth command
Browse files Browse the repository at this point in the history
  • Loading branch information
songzhao committed Nov 10, 2015
1 parent 24e3deb commit e113241
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ write_buffer_size : 268435456
# Pika timeout
timeout : 60
# Requirepass
requirepass :
requirepass : abc
# Dump Prefix
dump_prefix :
# daemonize [yes | no]
Expand Down
1 change: 1 addition & 0 deletions include/pika_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PikaConn
int fd() { return fd_; };
int role() {return role_; };
void set_role(int role) { MutexLock l(&mutex_); role_ = role; }
void set_role_nolock(int role) { role_ = role; }
std::string ip_port() { return ip_port_; };
// struct timeval lastinteraction() { return lastinteraction_; };
// void UpdateLastInteraction() { gettimeofday(&lastinteraction_, NULL); };
Expand Down
6 changes: 5 additions & 1 deletion src/pika_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ int PikaConn::DoCmd() {
char buf[32];
ll2string(buf, sizeof(buf), fd_);
argv_.push_back(std::string(buf));
mutex_.Lock();
}
pthread_rwlock_rdlock(g_pikaServer->rwlock());

Expand Down Expand Up @@ -493,7 +494,10 @@ int PikaConn::DoCmd() {
LOG(INFO) << "Authentication required, close connection";
cmd_ret = -2;
}
if (role_ != PIKA_MASTER && !(role_ == PIKA_SLAVE && opt == "ping")) {
if (opt == "pikasync") {
wbuf_ = sdscatlen(wbuf_, ret.data(), ret.size());
mutex_.Unlock();
} else if (role_ != PIKA_MASTER && !(role_ == PIKA_SLAVE && opt == "ping")) {
if (role_ == PIKA_SLAVE) {
MutexLock l(&mutex_);
wbuf_ = sdscatlen(wbuf_, ret.data(), ret.size());
Expand Down
2 changes: 1 addition & 1 deletion src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ int PikaServer::TrySync(/*std::string &ip, std::string &str_port,*/ int fd, uint
iter_cl->second.role = PIKA_SLAVE;
}
}
conn->set_role(PIKA_SLAVE);
conn->set_role_nolock(PIKA_SLAVE);
return PIKA_REP_STRATEGY_PSYNC;
} else {
return PIKA_REP_STRATEGY_ERROR;
Expand Down

0 comments on commit e113241

Please sign in to comment.