Skip to content

Commit

Permalink
fix(redis): rediscluster版本变更bug TencentBlueKing#6788
Browse files Browse the repository at this point in the history
  • Loading branch information
OMG-By committed Sep 12, 2024
1 parent b3aaf33 commit 88c474c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def generate_sync_relation(self, act_kwargs, master_ips, slave_ips, ins_num, sup
"""
计算新老实例对应关系
可能一对多,也可能多对一
20250806 需要兼容本地扩缩容场景:多余的实例数,可能是在老机器上
20240806 需要兼容本地扩缩容场景:多余的实例数,可能是在老机器上
- master_ips: 新机器master列表
- slave_ips: 新机器slave列表
- ins_num: 单台机器部署的最小实例数(有可能+1)
Expand Down Expand Up @@ -472,8 +472,6 @@ def redis_backend_scale_flow(self):

redis_sync_sub_pipelines = []
for sync_params in sync_relations:
if act_kwargs.cluster["cluster_type"] == ClusterType.TendisTwemproxyRedisInstance:
pass
sub_builder = RedisMakeSyncAtomJob(self.root_id, self.data, act_kwargs, sync_params)
redis_sync_sub_pipelines.append(sub_builder)
sub_pipeline.add_parallel_sub_pipeline(sub_flow_list=redis_sync_sub_pipelines)
Expand All @@ -490,8 +488,6 @@ def redis_backend_scale_flow(self):

redis_sync_sub_pipelines = []
for sync_params in sync_relations2:
if act_kwargs.cluster["cluster_type"] == ClusterType.TendisTwemproxyRedisInstance:
pass
sub_builder = RedisMakeSyncAtomJob(self.root_id, self.data, act_kwargs, sync_params)
redis_sync_sub_pipelines.append(sub_builder)
sub_pipeline.add_parallel_sub_pipeline(sub_flow_list=redis_sync_sub_pipelines)
Expand Down
46 changes: 19 additions & 27 deletions dbm-ui/backend/flow/utils/redis/redis_act_playload.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,13 @@ def redis_flush_data_payload(self, **kwargs) -> dict:
ip = kwargs["ip"]
params = kwargs["params"]
domain_name = params.get("domain_name", self.cluster.get("domain_name", ""))
db_version = params.get("db_version", self.cluster.get("db_version", ""))
cluster_type = params.get("cluster_type", self.cluster.get("cluster_type", ""))
ports = params.get("ports", self.cluster.get(ip, []))
force = params.get("force", self.cluster.get("force", False))
db_list = params.get("db_list", self.cluster.get("db_list", [0]))
flushall = params.get("flushall", self.cluster.get("flushall", True))

redis_config = self.__get_cluster_config(domain_name, db_version, ConfigTypeEnum.DBConf)
passwd_ret = PayloadHandler.redis_get_password_by_domain(domain_name)
return {
"db_type": DBActuatorTypeEnum.Redis.value,
"action": DBActuatorTypeEnum.Redis.value + "_" + RedisActuatorActionEnum.FlushData.value,
Expand All @@ -1013,7 +1012,7 @@ def redis_flush_data_payload(self, **kwargs) -> dict:
"db_type": cluster_type,
"ports": ports,
"is_force": force,
"password": redis_config["requirepass"],
"password": passwd_ret.get("redis_password"),
"db_list": db_list,
"is_flush_all": flushall,
},
Expand Down Expand Up @@ -1561,22 +1560,16 @@ def redis__switch_4_scene(self, **kwargs) -> dict:
"switch_condition":{},
}
"""
params, proxy_version = kwargs["params"], ""
params = kwargs["params"]
self.namespace = params["cluster_type"]
cluster_meta = nosqlcomm.other.get_cluster_detail(cluster_id=params["cluster_id"])[0]
if self.namespace == ClusterType.RedisInstance.value:
cluster_config = self.__get_cluster_config(
params["immute_domain"], params.get("db_version", ""), ConfigTypeEnum.DBConf
)
cluster_meta["storage_pass"] = cluster_config["requirepass"]
passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
cluster_meta["storage_pass"] = passwd_ret.get("redis_password")
else:
if is_twemproxy_proxy_type(self.namespace):
proxy_version = ConfigFileEnum.Twemproxy
elif is_predixy_proxy_type(self.namespace):
proxy_version = ConfigFileEnum.Predixy
proxy_config = self.__get_cluster_config(params["immute_domain"], proxy_version, ConfigTypeEnum.ProxyConf)
cluster_meta["proxy_pass"] = proxy_config["password"]
cluster_meta["storage_pass"] = proxy_config["redis_password"]
passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
cluster_meta["proxy_pass"] = passwd_ret.get("redis_proxy_password")
cluster_meta["storage_pass"] = passwd_ret.get("redis_password")

logger.info("switch cluster {}, switch infos : {}".format(params["immute_domain"], params["switch_info"]))
return {
Expand Down Expand Up @@ -1767,18 +1760,17 @@ def redis_tendisssd_dr_restore_4_scene(self, **kwargs) -> dict:
"""
params = kwargs["params"]
self.namespace = params["cluster_type"]
proxy_config = self.__get_cluster_config(params["immute_domain"], self.proxy_version, ConfigTypeEnum.ProxyConf)

passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
return {
"db_type": DBActuatorTypeEnum.Redis.value,
"action": DBActuatorTypeEnum.TendisSSD.value + "_" + RedisActuatorActionEnum.DR_RESTORE.value,
"payload": {
"master_ip": params["master_ip"],
"master_ports": params["master_ports"],
"master_auth": proxy_config["redis_password"],
"master_auth": passwd_ret.get("redis_password"),
"slave_ip": params["slave_ip"],
"slave_ports": params["slave_ports"],
"slave_password": proxy_config["redis_password"],
"slave_password": passwd_ret.get("redis_password"),
"task_dir": "/data/dbbak",
"backup_dir": "/data/dbbak",
},
Expand Down Expand Up @@ -1853,7 +1845,7 @@ def rollback_clustermeet_payload(self, **kwargs) -> dict:
数据构造 rediscluster 集群建立
"""
params = kwargs["params"]
redis_config = self.__get_cluster_config(params["immute_domain"], params["db_version"], ConfigTypeEnum.DBConf)
passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
bacth_pairs = []
for instance in params["all_instance"]:
ip, port = instance.split(":")
Expand All @@ -1866,7 +1858,7 @@ def rollback_clustermeet_payload(self, **kwargs) -> dict:
"db_type": DBActuatorTypeEnum.Redis.value,
"action": RedisActuatorActionEnum.CLUSTER_MEET.value,
"payload": {
"password": redis_config["requirepass"],
"password": passwd_ret.get("redis_password"),
"slots_auto_assign": True,
"replica_pairs": bacth_pairs,
},
Expand Down Expand Up @@ -1898,7 +1890,7 @@ def clustermeet_check_payload(self, **kwargs) -> dict:
数据构造 rediscluster meet建立集群关系并检查集群状态
"""
params = kwargs["params"]
redis_config = self.__get_cluster_config(params["immute_domain"], params["db_version"], ConfigTypeEnum.DBConf)
passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
bacth_pairs = []
for instance in params["all_instance"]:
ip, port = instance.split(IP_PORT_DIVIDER)
Expand All @@ -1912,7 +1904,7 @@ def clustermeet_check_payload(self, **kwargs) -> dict:
"db_type": DBActuatorTypeEnum.Redis.value,
"action": RedisActuatorActionEnum.CLUSTER_MEET_CHECK.value,
"payload": {
"password": redis_config["requirepass"],
"password": passwd_ret.get("redis_password"),
"replica_pairs": bacth_pairs,
},
}
Expand All @@ -1934,7 +1926,7 @@ def redis_cluster_meet_4_scene(self, **kwargs) -> dict:
}
"""
params = kwargs["params"]
redis_config = self.__get_cluster_config(params["immute_domain"], params["db_version"], ConfigTypeEnum.DBConf)
passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
cluster = Cluster.objects.get(immute_domain=params["immute_domain"])
cluster_info = metaApi.cluster.nosqlcomm.get_cluster_detail(cluster.id)[0]
bacth_pairs = []
Expand All @@ -1950,7 +1942,7 @@ def redis_cluster_meet_4_scene(self, **kwargs) -> dict:
"db_type": DBActuatorTypeEnum.Redis.value,
"action": RedisActuatorActionEnum.CLUSTER_MEET.value,
"payload": {
"password": redis_config["requirepass"],
"password": passwd_ret.get("redis_password"),
"replica_pairs": bacth_pairs,
"slots_auto_assign": False,
"use_for_expansion": False,
Expand All @@ -1966,7 +1958,7 @@ def redis_cluster_forget_4_scene(self, **kwargs) -> dict:
}
"""
params = kwargs["params"]
redis_config = self.__get_cluster_config(params["immute_domain"], params["db_version"], ConfigTypeEnum.DBConf)
passwd_ret = PayloadHandler.redis_get_password_by_domain(params["immute_domain"])
cluster = Cluster.objects.get(immute_domain=params["immute_domain"])
cluster_info = metaApi.cluster.nosqlcomm.get_cluster_detail(cluster.id)[0]

Expand All @@ -1975,7 +1967,7 @@ def redis_cluster_forget_4_scene(self, **kwargs) -> dict:
"action": DBActuatorTypeEnum.Redis.value + "_" + RedisActuatorActionEnum.ClusterForget.value,
"payload": {
"cluster_meta": {
"storage_pass": redis_config["requirepass"],
"storage_pass": passwd_ret.get("redis_password"),
"immute_domain": cluster_info["immute_domain"],
"cluster_type": cluster_info["cluster_type"],
"redis_master_set": cluster_info["redis_master_set"],
Expand Down

0 comments on commit 88c474c

Please sign in to comment.