diff --git a/include/pika_server.h b/include/pika_server.h index d6c450fc5d..b5e5ae29b8 100644 --- a/include/pika_server.h +++ b/include/pika_server.h @@ -298,7 +298,7 @@ class PikaServer : public pstd::noncopyable { pstd::Status GetDumpMeta(const std::string& db_name, const uint32_t slot_id, std::vector* 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); diff --git a/src/pika_repl_server_conn.cc b/src/pika_repl_server_conn.cc index a5929f9444..94c0a140bc 100644 --- a/src/pika_repl_server_conn.cc +++ b/src/pika_repl_server_conn.cc @@ -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())) { @@ -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(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)) { diff --git a/src/pika_server.cc b/src/pika_server.cc index 6fa5d4919e..574ed2e5bb 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -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 = 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 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(); @@ -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) {