Skip to content

Commit

Permalink
Purge log before slaveof only when the filenum and offset was given
Browse files Browse the repository at this point in the history
  • Loading branch information
CatKang committed Apr 29, 2016
1 parent c256a88 commit f7a3275
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ void SlaveofCmd::Do() {
return;
}
if (have_offset_) {
// Before we send the trysync command, we need purge current logs older than the sync point
if (filenum_ > 0) {
g_pika_server->PurgeLogs(filenum_ - 1, true, true);
}
g_pika_server->logger_->SetProducerStatus(filenum_, pro_offset_);
}
bool sm_ret = g_pika_server->SetMaster(master_ip_, master_port_);
Expand Down
4 changes: 2 additions & 2 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ void PikaServer::DispatchBinlogBG(const std::string &key,

bool PikaServer::WaitTillBinlogBGSerial(uint64_t my_serial) {
binlogbg_mutex_.Lock();
DLOG(INFO) << "Binlog serial wait: " << my_serial << ", current: " << binlogbg_serial_;
//DLOG(INFO) << "Binlog serial wait: " << my_serial << ", current: " << binlogbg_serial_;
while (binlogbg_serial_ != my_serial && !binlogbg_exit_) {
binlogbg_cond_.Wait();
}
Expand All @@ -903,7 +903,7 @@ bool PikaServer::WaitTillBinlogBGSerial(uint64_t my_serial) {

void PikaServer::SignalNextBinlogBGSerial() {
binlogbg_mutex_.Lock();
DLOG(INFO) << "Binlog serial signal: " << binlogbg_serial_;
//DLOG(INFO) << "Binlog serial signal: " << binlogbg_serial_;
++binlogbg_serial_;
binlogbg_cond_.SignalAll();
binlogbg_mutex_.Unlock();
Expand Down
8 changes: 1 addition & 7 deletions src/pika_trysync_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ bool PikaTrysyncThread::Send() {
uint64_t pro_offset;
g_pika_server->logger_->GetProducerStatus(&filenum, &pro_offset);

// Before we send the trysync command, we need purge current logs older than the sync point
if (filenum > 0) {
g_pika_server->PurgeLogs(filenum - 1, true, true);
}

argv.push_back(std::to_string(filenum));
argv.push_back(std::to_string(pro_offset));
pink::RedisCli::SerializeCommand(argv, &tbuf_str);
Expand Down Expand Up @@ -115,7 +110,6 @@ bool PikaTrysyncThread::TryUpdateMasterOffset() {
// Check dbsync finished
std::string info_path = g_pika_conf->db_sync_path() + kBgsaveInfoFile;
if (!slash::FileExists(info_path)) {
LOG(INFO) << "Info file not found : " << info_path;
return false;
}

Expand Down Expand Up @@ -192,7 +186,7 @@ void* PikaTrysyncThread::ThreadMain() {
if (g_pika_server->WaitingDBSync()) {
//Try to update offset by db sync
if (TryUpdateMasterOffset()) {
LOG(INFO) << "Success Update Master Offset";
DLOG(INFO) << "Success Update Master Offset";
}
}

Expand Down

0 comments on commit f7a3275

Please sign in to comment.