Skip to content

Commit

Permalink
fix: return kErr status when Master handle MetaRsync reqeust if db is…
Browse files Browse the repository at this point in the history
… not exist or doing bgsave(OpenAtomFoundation#2289) (OpenAtomFoundation#2437)

Co-authored-by: liuchengyu <[email protected]>
  • Loading branch information
chengyu-l and liuchengyu authored Mar 6, 2024
1 parent cc44ab7 commit 740589c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/rsync_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ Status RsyncClient::PullRemoteMeta(std::string* snapshot_uuid, std::set<std::str
}

if (resp.get() == nullptr || resp->code() != RsyncService::kOk) {
s = Status::IOError("kRsyncMeta request failed! unknown reason");
s = Status::IOError("kRsyncMeta request failed! db is not exist or doing bgsave");
sleep(1);
retries++;
continue;
}
LOG(INFO) << "receive rsync meta infos, snapshot_uuid: " << resp->snapshot_uuid()
Expand Down
14 changes: 9 additions & 5 deletions src/rsync_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ void RsyncServerConn::HandleMetaRsyncRequest(void* arg) {
std::shared_ptr<net::PbConn> conn = task_arg->conn;
std::string db_name = req->db_name();
std::shared_ptr<DB> db = g_pika_server->GetDB(db_name);
if (!db || db->IsBgSaving()) {
LOG(WARNING) << "waiting bgsave done...";
return;
}

RsyncService::RsyncResponse response;
response.set_reader_index(req->reader_index());
Expand All @@ -133,8 +129,16 @@ void RsyncServerConn::HandleMetaRsyncRequest(void* arg) {
*/
response.set_slot_id(0);

std::vector<std::string> filenames;
std::string snapshot_uuid;
if (!db || db->IsBgSaving()) {
LOG(WARNING) << "waiting bgsave done...";
response.set_snapshot_uuid(snapshot_uuid);
response.set_code(RsyncService::kErr);
RsyncWriteResp(response, conn);
return;
}

std::vector<std::string> filenames;
g_pika_server->GetDumpMeta(db_name, &filenames, &snapshot_uuid);
response.set_snapshot_uuid(snapshot_uuid);

Expand Down

0 comments on commit 740589c

Please sign in to comment.