From da0785abfeea8d88629c289e916c66146ec88e1b Mon Sep 17 00:00:00 2001 From: xiepaup Date: Fri, 20 Sep 2024 15:27:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(dbm-services):=20=E4=BF=AE=E5=A4=8DRedis?= =?UTF-8?q?=E4=B8=BB=E4=BB=8E=E5=9F=9F=E5=90=8D=E5=88=87=E6=8D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20#7044?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_meta/api/dbha/apis.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dbm-ui/backend/db_meta/api/dbha/apis.py b/dbm-ui/backend/db_meta/api/dbha/apis.py index 0aead585df..c591f8e2ce 100644 --- a/dbm-ui/backend/db_meta/api/dbha/apis.py +++ b/dbm-ui/backend/db_meta/api/dbha/apis.py @@ -40,12 +40,14 @@ BKCity, Cluster, ClusterDBHAExt, + ClusterEntry, ProxyInstance, StorageInstance, StorageInstanceTuple, ) from backend.db_meta.request_validator import DBHASwapRequestSerializer, DBHAUpdateStatusRequestSerializer from backend.flow.utils.cc_manage import CcManage +from backend.flow.utils.dns_manage import DnsManage from backend.flow.utils.sqlserver.sqlserver_host import Host logger = logging.getLogger("root") @@ -314,6 +316,8 @@ def tendis_cluster_swap(payload: Dict, bk_cloud_id: int): # 1. master 故障,需要把master 的entry 转移到 slave ,重建热备的时候,再纠正slave域名 for bind_entry in ins1_obj.bind_entry.all(): entry_obj = cluster_obj.clusterentry_set.get(id=bind_entry.id) + if entry_obj.cluster_entry_type == ClusterEntryType.DNS.value: + switch_instance_domain(ins1_obj, ins2_obj, entry_obj) ins1_obj.bind_entry.remove(entry_obj) ins2_obj.bind_entry.add(entry_obj) # 2. slave 故障,需要把slave 的entry 转移到master,重建热备的时候,再纠正slave域名 // TODO(update_status.) @@ -348,6 +352,18 @@ def tendis_cluster_swap(payload: Dict, bk_cloud_id: int): swap_cc_svr_instance_role(ins1_obj, ins2_obj) +@transaction.atomic +def switch_instance_domain(ins1, ins2: StorageInstance, entry_obj: ClusterEntry): + dns_manage = DnsManage(bk_biz_id=ins1.bk_biz_id, bk_cloud_id=ins1.machine.bk_cloud_id) + old_instance = "{}#{}".format(ins1.machine.ip, ins1.port) + new_instance = "{}#{}".format(ins2.machine.ip, ins2.port) + logger.info("try update dns pointer {} from {} to {}".format(entry_obj.entry, ins1, ins2)) + if not dns_manage.update_domain( + old_instance=old_instance, new_instance=new_instance, update_domain_name=entry_obj.entry + ): + raise Exception("update domain {} failed ".format(entry_obj.domain)) + + @transaction.atomic def swap_ctl_role(payloads: List): DBHASwapRequestSerializer(data={"payloads": payloads}).is_valid(raise_exception=True)