Skip to content

Commit

Permalink
feat: tendbCluster定点回档增加中控节点的回档 TencentBlueKing#7352
Browse files Browse the repository at this point in the history
  • Loading branch information
zfrendo committed Oct 22, 2024
1 parent dc9578c commit 8698b27
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.utils.translation import ugettext as _

from backend.configuration.constants import DBType
from backend.constants import IP_PORT_DIVIDER
from backend.db_meta.enums import InstanceStatus
from backend.db_meta.models import Cluster
from backend.db_services.mysql.fixpoint_rollback.handlers import FixPointRollbackHandler
Expand Down Expand Up @@ -178,8 +179,32 @@ def tendb_rollback_data(self):
)
),
)
ins_sub_pipeline_list.append(
spd_sub_pipeline.build_sub_process(sub_name=_("{} spider节点恢复".format(spider_node["instance"])))
)
# 恢复中控节点,有且只有1个中控
if spider_node["is_admin"]:
if "tdbctl_node" not in backup_info:
raise TendbGetBackupInfoFailedException(message=_("获取中控节点备份信息不存在"))
if backup_info["tdbctl_node"] == "":
raise TendbGetBackupInfoFailedException(message=_("获取中控节点备份信息为空"))
ctl_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data))
ctl_cluster = copy.deepcopy(spd_cluster)
ctl_cluster["backupinfo"] = backup_info["tdbctl_node"]
ctl_cluster["rollback_port"] = spider_node["admin_port"]
ctl_cluster["file_target_path"] = f'{self.backup_target_path}/{spider_node["admin_port"]}'
ctl_cluster["instance"] = f'{spider_node["ip"]}{IP_PORT_DIVIDER}{spider_node["admin_port"]}'
ctl_cluster["init_command"] = "set tc_admin=0"
ctl_cluster["enable_binlog"] = True
ctl_sub_pipeline.add_sub_pipeline(
sub_flow=spider_recover_sub_flow(
root_id=self.root_id, ticket_data=copy.deepcopy(self.data), cluster=ctl_cluster
)
)
ins_sub_pipeline_list.insert(
0, ctl_sub_pipeline.build_sub_process(sub_name=_("{} 中控节点恢复".format(ctl_cluster["instance"])))
)

ins_sub_pipeline_list.append(spd_sub_pipeline.build_sub_process(sub_name=_("恢复spider节点数据")))
for shard_id, remote_node in clusters_info["shards"].items():
if int(shard_id) not in backup_info["remote_node"]:
raise TendbGetBackupInfoFailedException(message=_("获取remotedb分片 {} 的备份信息不存在".format(shard_id)))
Expand Down Expand Up @@ -255,7 +280,9 @@ def tendb_rollback_data(self):
)
),
)
ins_sub_pipeline_list.append(ins_sub_pipeline.build_sub_process(sub_name=_("恢复remote节点数据")))
ins_sub_pipeline_list.append(
ins_sub_pipeline.build_sub_process(sub_name=_("{} 分片主从恢复".format(shard_id)))
)
tendb_rollback_pipeline.add_parallel_sub_pipeline(sub_flow_list=ins_sub_pipeline_list)
tendb_rollback_list.append(
tendb_rollback_pipeline.build_sub_process(
Expand Down
10 changes: 4 additions & 6 deletions dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,8 @@ def get_rollback_data_restore_payload(self, **kwargs):
"""
MYSQL 定点回档恢复备份介质
"""
# if (
# self.ticket_data["ticket_type"] == TicketType.TENDBCLUSTER_ROLLBACK_CLUSTER
# or self.ticket_data["ticket_type"] == TicketType.MYSQL_ROLLBACK_CLUSTER
# ):
# self.cluster["master_ip"] = ""
# self.cluster["master_port"] = 0
init_command = self.cluster.get("init_command", "")
enable_binlog = self.cluster.get("enable_binlog", False)
index_file = os.path.basename(self.cluster["backupinfo"]["index"]["file_name"])
payload = {
"db_type": DBActuatorTypeEnum.MySQL.value,
Expand Down Expand Up @@ -1059,6 +1055,8 @@ def get_rollback_data_restore_payload(self, **kwargs):
"ignore_databases": self.cluster["databases_ignore"],
"ignore_tables": self.cluster["tables_ignore"],
"recover_binlog": self.cluster["recover_binlog"],
"enable_binlog": enable_binlog,
"init_command": init_command,
},
"src_instance": {"host": "", "port": 0},
"change_master": self.cluster["change_master"],
Expand Down
10 changes: 9 additions & 1 deletion dbm-ui/backend/flow/utils/spider/tendb_cluster_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
import copy

from backend.constants import IP_PORT_DIVIDER
from backend.db_meta.models import Cluster, StorageInstance


Expand Down Expand Up @@ -44,10 +45,17 @@ def get_rollback_clusters_info(
target_obj = Cluster.objects.get(id=target_cluster_id)
source_spiders = source_obj.proxyinstance_set.filter()
target_spiders = target_obj.proxyinstance_set.filter()
primary_map = Cluster.get_cluster_id__primary_address_map([source_obj.id, target_obj.id])
for spider in source_spiders:
cluster_info["source_spiders"].append(spider.simple_desc)

for spider in target_spiders:
cluster_info["target_spiders"].append(spider.simple_desc)
spider_info = spider.simple_desc
if f'{spider_info["ip"]}{IP_PORT_DIVIDER}{spider_info["admin_port"]}' == primary_map[target_obj.id]:
spider_info["is_admin"] = True
else:
spider_info["is_admin"] = False
cluster_info["target_spiders"].append(spider_info)
ip_list.append(spider.machine.ip)

cluster_info["bk_cloud_id"] = source_obj.bk_cloud_id
Expand Down

0 comments on commit 8698b27

Please sign in to comment.