Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: after full synchronization fails, full synchronization will be skipped directly(#2433) #2439

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/pika_rm.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class SyncSlaveDB : public SyncDB {
void SetMasterSessionId(int32_t session_id);
void SetLocalIp(const std::string& local_ip);
void StopRsync();
void ActivateRsync();
pstd::Status ActivateRsync();
bool IsRsyncRunning() {return rsync_cli_->IsRunning();}

private:
Expand Down
15 changes: 12 additions & 3 deletions src/pika_rm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,18 @@ void SyncSlaveDB::StopRsync() {
rsync_cli_->Stop();
}

void SyncSlaveDB::ActivateRsync() {
pstd::Status SyncSlaveDB::ActivateRsync() {
Status s = Status::OK();
if (!rsync_cli_->IsIdle()) {
return;
return s;
}
LOG(WARNING) << "ActivateRsync ...";
if (rsync_cli_->Init()) {
rsync_cli_->Start();
return s;
} else {
SetReplState(ReplState::kError);
return Status::Error("rsync client init failed!");;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 969 处我看没有记录 s error 的具体内容,所以你定义这个错误没啥用吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来想着定义个bool就行,表示成功或失败。你建议修改成 int 方便以后扩展,所以使用了 Status 。这里的 error 可以记录日志,也可以不记录日志。在调用 ActivateRsync() 函数的地方,有记录日志,需要重新进行全量同步。

}
}

Expand Down Expand Up @@ -960,7 +963,13 @@ Status PikaReplicaManager::RunSyncSlaveDBStateMachine() {
} else if (s_db->State() == ReplState::kWaitReply) {
continue;
} else if (s_db->State() == ReplState::kWaitDBSync) {
s_db->ActivateRsync();
Status s = s_db->ActivateRsync();
if (!s.ok()) {
g_pika_server->SetForceFullSync(true);
LOG(WARNING) << "Slave DB: " << s_db->DBName() << " rsync failed! full synchronization will be retried later";
continue;
}

std::shared_ptr<DB> db =
g_pika_server->GetDB(p_info.db_name_);
if (db) {
Expand Down
1 change: 1 addition & 0 deletions src/rsync_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ bool RsyncClient::Init() {
if (!ret) {
LOG(WARNING) << "RsyncClient recover failed";
client_thread_->StopThread();
state_.store(IDLE);
return false;
}
finished_work_cnt_.store(0);
Expand Down
Loading