Skip to content

Commit

Permalink
fix: return wrong response code when DBSync request SyncMasterSlot no…
Browse files Browse the repository at this point in the history
…t exist(#2290, #2293) (#2308)

Co-authored-by: liuchengyu <liuchengyu@360.cn>
  • Loading branch information
chengyu-l and liuchengyu committed Jan 12, 2024
1 parent 73687f3 commit 59a5c30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class PikaServer : public pstd::noncopyable {
pstd::Status GetDumpMeta(const std::string& db_name, const uint32_t slot_id, std::vector<std::string>* files,
std::string* snapshot_uuid);
void DBSync(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id);
void TryDBSync(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id, int32_t top);
void DoBgSaveSlot(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id, int32_t top);
void DbSyncSendFile(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id);
std::string DbSyncTaskIndex(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id);

Expand Down
7 changes: 5 additions & 2 deletions src/pika_repl_server_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void PikaReplServerConn::HandleDBSyncRequest(void* arg) {
if (!master_slot) {
LOG(WARNING) << "Sync Master Slot: " << db_name << ":" << slot_id << ", NotFound";
prior_success = false;
response.set_code(InnerMessage::kError);
}
if (prior_success) {
if (!master_slot->CheckSlaveNodeExist(node.ip(), node.port())) {
Expand Down Expand Up @@ -348,11 +349,13 @@ void PikaReplServerConn::HandleDBSyncRequest(void* arg) {
}
}

g_pika_server->TryDBSync(node.ip(), node.port() + kPortShiftRSync, db_name, slot_id,
g_pika_server->DoBgSaveSlot(node.ip(), node.port() + kPortShiftRSync, db_name, slot_id,
static_cast<int32_t>(slave_boffset.filenum()));
// Change slave node's state to kSlaveDbSync so that the binlog will perserved.
// See details in SyncMasterSlot::BinlogCloudPurge.
master_slot->ActivateSlaveDbSync(node.ip(), node.port());
if (master_slot) {
master_slot->ActivateSlaveDbSync(node.ip(), node.port());
}

std::string reply_str;
if (!response.SerializeToString(&reply_str) || (conn->WriteResp(reply_str) != 0)) {
Expand Down
8 changes: 3 additions & 5 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,15 @@ pstd::Status PikaServer::GetDumpMeta(const std::string& db_name, const uint32_t
return pstd::Status::OK();
}

void PikaServer::TryDBSync(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id, int32_t top) {
void PikaServer::DoBgSaveSlot(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id, int32_t top) {
std::shared_ptr<Slot> slot = GetDBSlotById(db_name, slot_id);
if (!slot) {
LOG(WARNING) << "can not find Slot whose id is " << slot_id << " in db " << db_name << ", TryDBSync Failed";
LOG(WARNING) << "can not find Slot whose id is " << slot_id << " in db " << db_name << ", DoBgSaveSlot Failed";
return;
}
std::shared_ptr<SyncMasterSlot> sync_slot = g_pika_rm->GetSyncMasterSlotByName(SlotInfo(db_name, slot_id));
if (!sync_slot) {
LOG(WARNING) << "can not find Slot whose id is " << slot_id << " in db " << db_name << ", TryDBSync Failed";
LOG(WARNING) << "can not find Slot whose id is " << slot_id << " in db " << db_name << ", DoBgSaveSlot Failed";
return;
}
BgSaveInfo bgsave_info = slot->bgsave_info();
Expand All @@ -953,8 +953,6 @@ void PikaServer::TryDBSync(const std::string& ip, int port, const std::string& d
// Need Bgsave first
slot->BgSaveSlot();
}
// TODO: temporarily disable rsync server
// DBSync(ip, port, db_name, slot_id);
}

void PikaServer::DbSyncSendFile(const std::string& ip, int port, const std::string& db_name, uint32_t slot_id) {
Expand Down

0 comments on commit 59a5c30

Please sign in to comment.