Skip to content

Commit

Permalink
Modify server role when waiting dbsync
Browse files Browse the repository at this point in the history
  • Loading branch information
CatKang committed Apr 19, 2016
1 parent c0ba218 commit d345e27
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifeq ($(__REL), 1)
#CXXFLAGS = -Wall -W -DDEBUG -g -O0 -D__XDEBUG__ -fPIC -Wno-unused-function -std=c++11
CXXFLAGS = -O2 -g -pipe -fPIC -W -DNDEBUG -Wwrite-strings -Wpointer-arith -Wreorder -Wswitch -Wsign-promo -Wredundant-decls -Wformat -Wall -Wno-unused-parameter -D_GNU_SOURCE -D__STDC_FORMAT_MACROS -std=c++11 -gdwarf-2 -Wno-redundant-decls
else
CXXFLAGS = -O0 -g -pg -pipe -fPIC -W -DDEBUG -Wwrite-strings -Wpointer-arith -Wreorder -Wswitch -Wsign-promo -Wredundant-decls -Wformat -Wall -Wno-unused-parameter -D_GNU_SOURCE -std=c++11 -D__STDC_FORMAT_MACROS -std=c++11 -Wno-redundant-decls
CXXFLAGS = -O0 -g -pg -pipe -fPIC -W -DDEBUG -Wwrite-strings -Wpointer-arith -Wreorder -Wswitch -Wsign-promo -Wredundant-decls -Wformat -Wall -Wno-unused-parameter -D_GNU_SOURCE -D__STDC_FORMAT_MACROS -std=c++11 -Wno-redundant-decls
endif

OBJECT = pika
Expand Down
3 changes: 2 additions & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ void InfoCmd::InfoServer(std::string &info) {
tmp_stream << "db_size:" << (slash::Du(g_pika_conf->db_path()) >> 20) << "M\r\n";
tmp_stream << "log_size:" << (slash::Du(g_pika_conf->log_path()) >> 20) << "M\r\n";
tmp_stream << "compression:" << g_pika_conf->compression() << "\r\n";
tmp_stream << "safety_purge:" << (g_pika_server->GetPurgeWindow(purge_max) ? std::to_string(static_cast<int32_t>(purge_max)) : "none") << "\r\n";
tmp_stream << "safety_purge:" << (g_pika_server->GetPurgeWindow(purge_max) ?
kBinlogPrefix + std::to_string(static_cast<int32_t>(purge_max)) : "none") << "\r\n";
tmp_stream << "expire_logs_days:" << g_pika_conf->expire_logs_days() << "\r\n";
tmp_stream << "expire_logs_nums:" << g_pika_conf->expire_logs_nums() << "\r\n";

Expand Down
2 changes: 1 addition & 1 deletion src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void PikaServer::NeedWaitDBSync() {
void PikaServer::WaitDBSyncFinish() {
slash::RWLock l(&state_protector_, true);
if (repl_state_ == PIKA_REPL_WAIT_DBSYNC) {
repl_state_ = PIKA_REPL_NO_CONNECT;
repl_state_ = PIKA_REPL_CONNECT;
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/pika_trysync_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ bool PikaTrysyncThread::RecvProc() {
break;
}
// Failed
g_pika_server->RemoveMaster();

if (kInnerReplWait == reply) {
// You can't sync this time, but may be different next time,
Expand All @@ -97,6 +96,8 @@ bool PikaTrysyncThread::RecvProc() {
// 3, Master do dbsyncing
DLOG(INFO) << "Need wait to sync";
g_pika_server->NeedWaitDBSync();
} else {
g_pika_server->RemoveMaster();
}
return false;
}
Expand Down Expand Up @@ -153,6 +154,13 @@ bool PikaTrysyncThread::TryUpdateMasterOffset() {
<< ", filenum: " << filenum
<< ", offset: " << offset;

// Sanity check
if (master_ip != g_pika_server->master_ip() ||
master_port != g_pika_server->master_port()) {
LOG(ERROR) << "Error master ip port: " << master_ip << ":" << master_port;
return false;
}

// Replace the old db
slash::StopRsync(g_pika_conf->db_sync_path());
slash::DeleteFile(info_path);
Expand All @@ -164,10 +172,6 @@ bool PikaTrysyncThread::TryUpdateMasterOffset() {
// Update master offset
g_pika_server->logger_->SetProducerStatus(filenum, offset);
g_pika_server->WaitDBSyncFinish();
if (!g_pika_server->SetMaster(master_ip, static_cast<int>(master_port))) {
LOG(ERROR) << "Server is not in correct state for slaveof";
return false;
}
return true;
}

Expand Down

0 comments on commit d345e27

Please sign in to comment.