Skip to content

Commit bdb45e6

Browse files
authored
fix: make SlaveDB stay in WaitDBSync state instead of sink into Error State if rsync init failed (OpenAtomFoundation#2667)
* make pika Slave DB stay in WaitDBSync state if rsync init failed(Pull meta from master timeout) to ensure the slave DB will continue to retry,instead of sinking into Error state * add MaxRetryCount --------- Co-authored-by: cjh <1271435567@qq.com>
1 parent d5e29f3 commit bdb45e6

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

include/pika_define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const std::string kDefaultRsyncAuth = "default";
4343

4444
/* Rsync */
4545
const int kMaxRsyncParallelNum = 4;
46+
constexpr int kMaxRsyncInitReTryTimes = 64;
4647

4748
struct DBStruct {
4849
DBStruct(std::string tn, int32_t inst_num)

include/pika_rm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class SyncSlaveDB : public SyncDB {
120120

121121
private:
122122
std::unique_ptr<rsync::RsyncClient> rsync_cli_;
123+
int32_t rsync_init_retry_count_{0};
123124
pstd::Mutex db_mu_;
124125
RmNode m_info_;
125126
ReplState repl_state_{kNoConnect};

src/pika_rm.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,19 @@ pstd::Status SyncSlaveDB::ActivateRsync() {
507507
if (!rsync_cli_->IsIdle()) {
508508
return s;
509509
}
510-
LOG(WARNING) << "ActivateRsync ...";
510+
LOG(WARNING) << "Slave DB: " << DBName() << " Activating Rsync ... (retry count:" << rsync_init_retry_count_ << ")";
511511
if (rsync_cli_->Init()) {
512+
rsync_init_retry_count_ = 0;
512513
rsync_cli_->Start();
513514
return s;
514515
} else {
515-
SetReplState(ReplState::kError);
516-
return Status::Error("rsync client init failed!");;
516+
rsync_init_retry_count_ += 1;
517+
if (rsync_init_retry_count_ >= kMaxRsyncInitReTryTimes) {
518+
SetReplState(ReplState::kError);
519+
LOG(ERROR) << "Full Sync Stage - Rsync Init failed: Slave failed to pull meta info(generated by bgsave task in Master) from Master after MaxRsyncInitReTryTimes("
520+
<< kMaxRsyncInitReTryTimes << " times) is reached. This usually means the Master's bgsave task has costed an unexpected-long time.";
521+
}
522+
return Status::Error("rsync client init failed!");
517523
}
518524
}
519525

@@ -977,8 +983,7 @@ Status PikaReplicaManager::RunSyncSlaveDBStateMachine() {
977983
} else if (s_db->State() == ReplState::kWaitDBSync) {
978984
Status s = s_db->ActivateRsync();
979985
if (!s.ok()) {
980-
g_pika_server->SetForceFullSync(true);
981-
LOG(WARNING) << "Slave DB: " << s_db->DBName() << " rsync failed! full synchronization will be retried later, error info:" << s.ToString();
986+
LOG(WARNING) << "Slave DB: " << s_db->DBName() << " rsync failed! full synchronization will be retried later";
982987
continue;
983988
}
984989

tests/integration/rsync_dynamic_reconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var _ = Describe("Rsync Reconfig Test", func() {
136136
slave1.FlushDB(ctx)
137137
master1.FlushDB(ctx)
138138
time.Sleep(3 * time.Second)
139-
RefillMaster(MASTERADDR, 128, ctx)
139+
RefillMaster(MASTERADDR, 64, ctx)
140140
key1 := "45vs45f4s5d6"
141141
value1 := "afd54g5s4f545"
142142
//set key before sync happened, slave is supposed to fetch it when sync done

0 commit comments

Comments
 (0)