Skip to content

Commit

Permalink
fix: 主从迁移多slave切换后关系链修复 TencentBlueKing#7754
Browse files Browse the repository at this point in the history
  • Loading branch information
zfrendo authored and zhangzhw8 committed Nov 7, 2024
1 parent 3a0f7e2 commit a63cd7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/tendbha/storage_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ def remove_storage_tuple(master_ip: str, slave_ip: str, bk_cloud_id: int, port_l
)
slave_storage = StorageInstance.objects.get(machine__ip=slave_ip, port=port, machine__bk_cloud_id=bk_cloud_id)
StorageInstanceTuple.objects.filter(ejector=master_storage, receiver=slave_storage).delete()


@transaction.atomic
def update_storage_tuple(master_ip: str, new_master_ip: str, bk_cloud_id: int, port_list: list):
for port in port_list:
master_storage = StorageInstance.objects.get(
machine__ip=master_ip, port=port, machine__bk_cloud_id=bk_cloud_id
)
new_master_storage = StorageInstance.objects.get(
machine__ip=new_master_ip, port=port, machine__bk_cloud_id=bk_cloud_id
)
StorageInstanceTuple.objects.filter(ejector=master_storage).update(ejector=new_master_storage)
7 changes: 7 additions & 0 deletions dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ def mysql_migrate_cluster_switch_storage(self):
bk_cloud_id=self.cluster["bk_cloud_id"],
port_list=[self.cluster["mysql_port"]],
)
# 修改所有原主节点映射的slave到新的主节点
api.cluster.tendbha.storage_tuple.update_storage_tuple(
master_ip=self.cluster["old_master_ip"],
new_master_ip=self.cluster["new_master_ip"],
bk_cloud_id=self.cluster["bk_cloud_id"],
port_list=[self.cluster["mysql_port"]],
)
# add new slave 对应关系
if self.cluster.get("new_ro_slave_ips"):
for new_ro_slave_ip in self.cluster["new_ro_slave_ips"]:
Expand Down

0 comments on commit a63cd7c

Please sign in to comment.