Skip to content

Commit

Permalink
add function DeactivateSyncSlaveDB (#2801)
Browse files Browse the repository at this point in the history
Co-authored-by: cheniujh <1271435567@qq.com>
  • Loading branch information
cheniujh and cheniujh authored Jul 18, 2024
1 parent 057812f commit f4cfbde
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/pika_rm.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class PikaReplicaManager {
void RmStatus(std::string* debug_info);
pstd::Status CheckDBRole(const std::string& table, int* role);
pstd::Status LostConnection(const std::string& ip, int port);
pstd::Status DeactivateSyncSlaveDB(const std::string& ip, int port);

// Update binlog win and try to send next binlog
pstd::Status UpdateSyncBinlogStatus(const RmNode& slave, const LogOffset& offset_start, const LogOffset& offset_end);
Expand Down
11 changes: 11 additions & 0 deletions src/pika_rm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,17 @@ bool PikaReplicaManager::CheckSlaveDBState(const std::string& ip, const int port
return true;
}

Status PikaReplicaManager::DeactivateSyncSlaveDB(const std::string& ip, int port) {
std::shared_lock l(dbs_rw_);
for (auto& iter : sync_slave_dbs_) {
std::shared_ptr<SyncSlaveDB> db = iter.second;
if (db->MasterIp() == ip && db->MasterPort() == port) {
db->Deactivate();
}
}
return Status::OK();
}

Status PikaReplicaManager::LostConnection(const std::string& ip, int port) {
std::shared_lock l(dbs_rw_);
for (auto& iter : sync_master_dbs_) {
Expand Down
2 changes: 1 addition & 1 deletion src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void PikaServer::RemoveMaster() {

if (!master_ip_.empty() && master_port_ != -1) {
g_pika_rm->CloseReplClientConn(master_ip_, master_port_ + kPortShiftReplServer);
g_pika_rm->LostConnection(master_ip_, master_port_);
g_pika_rm->DeactivateSyncSlaveDB(master_ip_, master_port_);
UpdateMetaSyncTimestampWithoutLock();
LOG(INFO) << "Remove Master Success, ip_port: " << master_ip_ << ":" << master_port_;
}
Expand Down

0 comments on commit f4cfbde

Please sign in to comment.