Skip to content

Commit

Permalink
fix(redis): 主从重建Slave Entry刷新 #7054
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepaup authored Oct 8, 2024
1 parent 4b2ca79 commit 25a573b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/nosqlcomm/scale_tendis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from backend.db_meta.models import Cluster, StorageInstance, StorageInstanceTuple
from backend.flow.utils.cc_manage import CcManage
from backend.flow.utils.dns_manage import DnsManage
from backend.flow.utils.redis.redis_module_operate import RedisCCTopoOperator

logger = logging.getLogger("flow")
Expand Down Expand Up @@ -74,6 +75,7 @@ def redo_slaves(cluster: Cluster, tendisss: List[Dict], created_by: str = ""):
)
)

dns_manage = DnsManage(bk_biz_id=cluster.bk_biz_id, bk_cloud_id=cluster.bk_cloud_id)
# 修改表 db_meta_storageinstancetuple ,## 这个时候会出现一主多从 !
for ms_pair in tendisss:
ejector_obj = StorageInstance.objects.get(
Expand All @@ -95,6 +97,17 @@ def redo_slaves(cluster: Cluster, tendisss: List[Dict], created_by: str = ""):
if cluster.clusterentry_set.filter(role=ClusterEntryRole.SLAVE_ENTRY.value).exists():
slave_entry = cluster.clusterentry_set.filter(role=ClusterEntryRole.SLAVE_ENTRY.value).first()
receiver_obj.bind_entry.add(slave_entry)
ejector_obj.bind_entry.remove(slave_entry)

old_instance = "{}#{}".format(ejector_obj.machine.ip, ejector_obj.port)
new_instance = "{}#{}".format(receiver_obj.machine.ip, receiver_obj.port)
logger.info(
"try update dns pointer {} from {} to {}".format(slave_entry.entry, old_instance, new_instance)
)
if not dns_manage.update_domain(
old_instance=old_instance, new_instance=new_instance, update_domain_name=slave_entry.entry
):
raise Exception("update domain {} failed ".format(slave_entry.entry))

# 修改表 db_meta_storageinstance_cluster
cluster.storageinstance_set.add(*receiver_objs)
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_meta/api/dbha/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def switch_instance_domain(ins1, ins2: StorageInstance, entry_obj: ClusterEntry)
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))
raise Exception("update domain {} failed ".format(entry_obj.entry))


@transaction.atomic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def slave_fix(self, flow_data, sub_kwargs, slave_fix_info):
act_component_code=ExecuteDBActuatorScriptComponent.code,
kwargs=asdict(sub_kwargs),
)
# 刷新slave域名 在《新节点加入集群》节点修改

# # #### 下架旧实例 (生产Ticket单据) ################################################## 完毕 ###
old_slaves = [fix_link["ip"] for fix_link in slave_fix_detail]
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/flow/utils/redis/redis_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ def cluster_add_slave_update_meta(self):
for entry_obj in cluster.clusterentry_set.filter(role=ClusterEntryRole.SLAVE_ENTRY):
slave_domain = entry_obj.entry
entry_obj.storageinstance_set.add(new_slave_obj)
entry_obj.storageinstance_set.remove(master_obj)
if old_slave_obj and old_slave_obj.ip_port != new_slave_obj.ip_port:
entry_obj.storageinstance_set.remove(old_slave_obj)
if slave_domain != "":
Expand Down

0 comments on commit 25a573b

Please sign in to comment.