Skip to content

Commit

Permalink
fix(redis): PredixyCluster替换Proxy+Master修复 #8374
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepaup authored and iSecloud committed Dec 5, 2024
1 parent a2d201f commit 8765faa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
21 changes: 19 additions & 2 deletions dbm-ui/backend/db_meta/api/cluster/nosqlcomm/scale_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

from backend.db_meta.api import common
from backend.db_meta.api.cluster.nosqlcomm.create_cluster import update_cluster_type
from backend.db_meta.enums import AccessLayer, ClusterMachineAccessTypeDefine, InstanceInnerRole
from backend.db_meta.enums import (
AccessLayer,
ClusterEntryRole,
ClusterMachineAccessTypeDefine,
ClusterType,
InstanceInnerRole,
)
from backend.db_meta.models import Cluster, ProxyInstance
from backend.flow.utils.cc_manage import CcManage
from backend.flow.utils.redis.redis_module_operate import RedisCCTopoOperator
Expand Down Expand Up @@ -64,8 +70,19 @@ def add_proxies(cluster: Cluster, proxies: List[Dict]):
cluster.proxyinstance_set.add(*proxy_objs)
logger.info("cluster {} add proxyinstance {}".format(cluster.immute_domain, proxy_objs))

# 修改表 db_meta_proxyinstance_bind_entry
# 修改表 db_meta_proxyinstance_bind_entry # 这里要去掉node 域名。
for cluster_entry_obj in cluster.clusterentry_set.all():
if cluster.cluster_type in [
ClusterType.TendisPredixyRedisCluster,
ClusterType.TendisPredixyTendisplusCluster,
]:
if cluster_entry_obj.role == ClusterEntryRole.NODE_ENTRY:
logger.info(
"cluster {} entry {} ignore add proxyinstance {}".format(
cluster.immute_domain, cluster_entry_obj.entry, proxy_objs
)
)
continue
cluster_entry_obj.proxyinstance_set.add(*proxy_objs)
logger.info(
"cluster {} entry {} add proxyinstance {}".format(
Expand Down
5 changes: 5 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 @@ -112,6 +112,11 @@ def redo_slaves(cluster: Cluster, tendisss: List[Dict], created_by: str = ""):
# 修改表 db_meta_storageinstance_cluster
cluster.storageinstance_set.add(*receiver_objs)

# 修改表 db_meta_storageinstance_proxyinstance
proxy_objs = cluster.proxyinstance_set.all()
for rece_obj in receiver_objs:
rece_obj.proxyinstance_set.add(*proxy_objs)

# 更新 nodes. 域名对应的 cluster_entry信息
cluster_entry = cluster.clusterentry_set.filter(role=ClusterEntryRole.NODE_ENTRY.value).first()
if cluster_entry and cluster_entry.entry.startswith("nodes."):
Expand Down
17 changes: 4 additions & 13 deletions dbm-ui/backend/flow/utils/redis/redis_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,25 +859,16 @@ def redis_role_swap_4_scene(self) -> bool:
bk_biz_id=self.cluster["bk_biz_id"],
)

# 修改 proxy backend
temp_proxy_set = list(ins1.proxyinstance_set.all())
ins1.proxyinstance_set.clear()
ins1.proxyinstance_set.add(*ins2.proxyinstance_set.all())
ins2.proxyinstance_set.clear()
ins2.proxyinstance_set.add(*temp_proxy_set)
# 变更同步关系
StorageInstanceTuple.objects.get(ejector=ins1, receiver=ins2).delete(keep_parents=True)
StorageInstanceTuple.objects.create(ejector=ins2, receiver=ins1)

# 变更角色
temp_instance_role = ins1.instance_role
tmep_instance_inner_role = ins1.instance_inner_role
ins1.instance_role = InstanceRole.REDIS_SLAVE.value
ins1.instance_inner_role = InstanceInnerRole.SLAVE.value

ins1.instance_role = ins2.instance_role
ins1.instance_inner_role = ins2.instance_inner_role

ins2.instance_role = temp_instance_role
ins2.instance_inner_role = tmep_instance_inner_role
ins2.instance_role = InstanceRole.REDIS_MASTER.value
ins2.instance_inner_role = InstanceInnerRole.MASTER.value

ins1.save(update_fields=["instance_role", "instance_inner_role"])
ins2.save(update_fields=["instance_role", "instance_inner_role"])
Expand Down

0 comments on commit 8765faa

Please sign in to comment.