Skip to content

Commit

Permalink
bugfix: 1) master-slave error(rarely); 2) should exit trysync thread …
Browse files Browse the repository at this point in the history
…first in shutdown
  • Loading branch information
KernelMaker committed Aug 22, 2016
1 parent d89ef5c commit 047afe9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pika_binlog_sender_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ void* PikaBinlogSenderThread::ThreadMain() {

while (!should_exit_) {

sleep(1);
// 1. Connect to slave
result = cli_->Connect(ip_, port_, g_pika_server->host());
LOG(INFO) << "BinlogSender Connect slave(" << ip_ << ":" << port_ << ") " << result.ToString();
Expand Down
9 changes: 7 additions & 2 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ PikaServer::~PikaServer() {
LOG(INFO) << "Delete slave success";
}
}
delete pika_trysync_thread_;
delete ping_thread_;
delete pika_binlog_receiver_thread_;

Expand All @@ -112,7 +113,6 @@ PikaServer::~PikaServer() {
delete (*binlogbg_iter);
binlogbg_iter++;
}
delete pika_trysync_thread_;
delete pika_heartbeat_thread_;
delete monitor_thread_;

Expand Down Expand Up @@ -450,7 +450,8 @@ void PikaServer::PlusMasterConnection() {
bool PikaServer::ShouldAccessConnAsMaster(const std::string& ip) {
slash::RWLock l(&state_protector_, false);
DLOG(INFO) << "ShouldAccessConnAsMaster, repl_state_: " << repl_state_ << " ip: " << ip << " master_ip: " << master_ip_;
if (repl_state_ != PIKA_REPL_NO_CONNECT && repl_state_ != PIKA_REPL_WAIT_DBSYNC && ip == master_ip_) {
// if (repl_state_ != PIKA_REPL_NO_CONNECT && repl_state_ != PIKA_REPL_WAIT_DBSYNC && ip == master_ip_) {
if (repl_state_ == PIKA_REPL_CONNECTING && ip == master_ip_) {
return true;
}
return false;
Expand Down Expand Up @@ -494,6 +495,10 @@ void PikaServer::RemoveMaster() {
delete ping_thread_;
ping_thread_ = NULL;
}
{
slash::RWLock l(&state_protector_, true);
master_connection_ = 0;
}
LOG(INFO) << "close read-only mode";
g_pika_conf->SetReadonly(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/pika_slaveping_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void* PikaSlavepingThread::ThreadMain() {
}
sleep(1);
}
sleep(2);
g_pika_server->MinusMasterConnection();
} else if (!should_exit_) {
LOG(WARNING) << "Slaveping, Connect timeout";
Expand Down

0 comments on commit 047afe9

Please sign in to comment.