Skip to content

Commit

Permalink
feat(redis): Redis同业务相同IP支持 #3867
Browse files Browse the repository at this point in the history
	1. master 替换
	2. 主从切换
	3. redis集群在线版本升级
	4. proxy下架
	5. 集群下架
	6. proxy 扩容
	7. 重建热备
	8. 集群切换
  • Loading branch information
xiepaup authored and zhangzhw8 committed Apr 11, 2024
1 parent f8e9d3b commit 9e3321a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
4 changes: 3 additions & 1 deletion dbm-ui/backend/db_meta/api/cluster/nosqlcomm/decommission.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def decommission_proxies(cluster: Cluster, proxies: List[Dict], is_all: bool = F
machine_obj[proxy_obj.machine.ip] = proxy_obj.machine

# 需要检查, 是否该机器上所有实例都已经清理干净,
if ProxyInstance.objects.filter(machine__ip=proxy_obj.machine.ip).exists():
if ProxyInstance.objects.filter(
machine__ip=proxy_obj.machine.ip, machine__bk_cloud_id=cluster.bk_cloud_id, bk_biz_id=cluster.bk_biz_id
).exists():
logger.info("ignore storage machine {} , another instance existed.".format(proxy_obj.machine))
else:
logger.info("proxy machine {}".format(proxy_obj.machine))
Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/nosqlcomm/scale_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def add_proxies(cluster: Cluster, proxies: List[Dict]):
proxy_objs = common.filter_out_instance_obj(
proxies,
ProxyInstance.objects.filter(
machine__bk_cloud_id=cluster.bk_cloud_id,
bk_biz_id=cluster.bk_biz_id,
machine_type=ClusterMachineAccessTypeDefine[cluster.cluster_type][AccessLayer.PROXY],
),
)
Expand Down
25 changes: 20 additions & 5 deletions dbm-ui/backend/db_meta/api/cluster/nosqlcomm/scale_tendis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ def redo_slaves(cluster: Cluster, tendisss: List[Dict], created_by: str = ""):
# 修改表 db_meta_storageinstancetuple ,## 这个时候会出现一主多从 !
for ms_pair in tendisss:
ejector_obj = StorageInstance.objects.get(
machine__ip=ms_pair["ejector"]["ip"], port=ms_pair["ejector"]["port"]
machine__ip=ms_pair["ejector"]["ip"],
port=ms_pair["ejector"]["port"],
machine__bk_cloud_id=cluster.bk_cloud_id,
bk_biz_id=cluster.bk_biz_id,
)
receiver_obj = StorageInstance.objects.get(
machine__ip=ms_pair["receiver"]["ip"], port=ms_pair["receiver"]["port"]
machine__ip=ms_pair["receiver"]["ip"],
port=ms_pair["receiver"]["port"],
machine__bk_cloud_id=cluster.bk_cloud_id,
bk_biz_id=cluster.bk_biz_id,
)
StorageInstanceTuple.objects.create(ejector=ejector_obj, receiver=receiver_obj, creator=created_by)
logger.info("create link info {} -> {}".format(ejector_obj, receiver_obj))
Expand Down Expand Up @@ -172,7 +178,10 @@ def switch_tendis(cluster: Cluster, tendisss: List[Dict], switch_type: str = Syn
# 执行切换,修改元数据
for ms_pair in tendisss:
old_ejector_obj = StorageInstance.objects.get(
machine__ip=ms_pair["ejector"]["ip"], port=ms_pair["ejector"]["port"]
machine__ip=ms_pair["ejector"]["ip"],
port=ms_pair["ejector"]["port"],
machine__bk_cloud_id=cluster.bk_cloud_id,
bk_biz_id=cluster.bk_biz_id,
)
tmp_proxy_objs = list(old_ejector_obj.proxyinstance_set.all())
logger.info(
Expand All @@ -181,7 +190,10 @@ def switch_tendis(cluster: Cluster, tendisss: List[Dict], switch_type: str = Syn
old_ejector_obj.proxyinstance_set.clear()

new_ejector_obj = StorageInstance.objects.get(
machine__ip=ms_pair["receiver"]["ip"], port=ms_pair["receiver"]["port"]
machine__ip=ms_pair["receiver"]["ip"],
port=ms_pair["receiver"]["port"],
machine__bk_cloud_id=cluster.bk_cloud_id,
bk_biz_id=cluster.bk_biz_id,
)
logger.info(
"add cluster {} proxys {} link with storage {}".format(cluster, tmp_proxy_objs, new_ejector_obj)
Expand All @@ -201,7 +213,10 @@ def switch_tendis(cluster: Cluster, tendisss: List[Dict], switch_type: str = Syn
ejector_objs, receiver_objs = [], []
for ms_pair in tendisss:
new_ejector_obj = StorageInstance.objects.get(
machine__ip=ms_pair["receiver"]["ip"], port=ms_pair["receiver"]["port"]
machine__ip=ms_pair["receiver"]["ip"],
port=ms_pair["receiver"]["port"],
machine__bk_cloud_id=cluster.bk_cloud_id,
bk_biz_id=cluster.bk_biz_id,
)
if switch_type != SyncType.MS.value:
logger.info("switch for sync {} need move cc module & add cc instance".format(switch_type))
Expand Down
21 changes: 18 additions & 3 deletions dbm-ui/backend/flow/utils/redis/redis_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,12 @@ def instances_failover_4_scene(self) -> bool:
with atomic():
cc_manage = CcManage(self.cluster["bk_biz_id"], db_type=DBType.Redis.value)
for port in self.cluster["meta_update_ports"]:
old_master = StorageInstance.objects.get(machine__ip=self.cluster["meta_update_ip"], port=port)
old_master = StorageInstance.objects.get(
machine__ip=self.cluster["meta_update_ip"],
port=port,
bk_biz_id=self.cluster["bk_biz_id"],
machine__bk_cloud_id=self.cluster["bk_cloud_id"],
)
old_slave = old_master.as_ejector.get().receiver
StorageInstanceTuple.objects.get(ejector=old_master, receiver=old_slave).delete(keep_parents=True)
StorageInstanceTuple.objects.create(ejector=old_slave, receiver=old_master)
Expand Down Expand Up @@ -751,8 +756,18 @@ def redis_role_swap_4_scene(self) -> bool:
cc_manage = CcManage(self.cluster["bk_biz_id"], db_type=DBType.Redis.value)
with atomic():
for ins in self.cluster["role_swap_ins"]:
ins1 = StorageInstance.objects.get(machine__ip=ins["new_receiver_ip"], port=ins["new_receiver_port"])
ins2 = StorageInstance.objects.get(machine__ip=ins["new_ejector_ip"], port=ins["new_ejector_port"])
ins1 = StorageInstance.objects.get(
machine__ip=ins["new_receiver_ip"],
port=ins["new_receiver_port"],
machine__bk_cloud_id=self.cluster["bk_cloud_id"],
bk_biz_id=self.cluster["bk_biz_id"],
)
ins2 = StorageInstance.objects.get(
machine__ip=ins["new_ejector_ip"],
port=ins["new_ejector_port"],
machine__bk_cloud_id=self.cluster["bk_cloud_id"],
bk_biz_id=self.cluster["bk_biz_id"],
)

# 修改 proxy backend
temp_proxy_set = list(ins1.proxyinstance_set.all())
Expand Down

0 comments on commit 9e3321a

Please sign in to comment.