Skip to content

Commit

Permalink
fix: 原地重建重置serverId主从迁移切换后提前卸载周边 TencentBlueKing#7171
Browse files Browse the repository at this point in the history
  • Loading branch information
zfrendo authored and iSecloud committed Sep 27, 2024
1 parent 645ed1c commit 85fea48
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ class DBActuatorActionEnum(str, StructuredEnum):
PushChecksumConfig = EnumField("push-checksum-config", _("推送mysql-table-checksum配置"))
PushNewDbBackupConfig = EnumField("push-new-db-backup-config", _("推送备份配置"))
PushMySQLRotatebinlogConfig = EnumField("push-mysql-rotatebinlog-config", _("推送rotatebinlog配置"))
ChangeServerId = EnumField("change-server-id", _("change-server-id"))


class RedisActuatorActionEnum(str, StructuredEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ def migrate_cluster_flow(self, use_for_upgrade=False):
)
# 第四步 卸载实例
uninstall_svr_sub_pipeline_list = []
uninstall_surrounding_sub_pipeline_list = []
for ip in [self.data["slave_ip"], self.data["master_ip"]]:
uninstall_surrounding_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data))
uninstall_svr_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data))
# 考虑到部分实例成对迁移的情况(即拆分)
cluster = {
Expand All @@ -354,7 +356,7 @@ def migrate_cluster_flow(self, use_for_upgrade=False):
"bk_cloud_id": cluster_class.bk_cloud_id,
}

uninstall_svr_sub_pipeline.add_act(
uninstall_surrounding_sub_pipeline.add_act(
act_name=_("下发db-actor到节点{}".format(ip)),
act_component_code=TransFileComponent.code,
kwargs=asdict(
Expand All @@ -366,7 +368,7 @@ def migrate_cluster_flow(self, use_for_upgrade=False):
),
)

uninstall_svr_sub_pipeline.add_act(
uninstall_surrounding_sub_pipeline.add_act(
act_name=_("清理实例级别周边配置"),
act_component_code=ExecuteDBActuatorScriptComponent.code,
kwargs=asdict(
Expand Down Expand Up @@ -413,6 +415,10 @@ def migrate_cluster_flow(self, use_for_upgrade=False):
root_id=self.root_id, ticket_data=copy.deepcopy(self.data), ip=ip, ports=self.data["ports"]
)
)

uninstall_surrounding_sub_pipeline_list.append(
uninstall_surrounding_sub_pipeline.build_sub_process(sub_name=_("卸载remote节点周边{}".format(ip)))
)
uninstall_svr_sub_pipeline_list.append(
uninstall_svr_sub_pipeline.build_sub_process(sub_name=_("卸载remote节点{}".format(ip)))
)
Expand Down Expand Up @@ -494,6 +500,7 @@ def migrate_cluster_flow(self, use_for_upgrade=False):
)
),
)
tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=uninstall_surrounding_sub_pipeline_list)
# 卸载流程人工确认
tendb_migrate_pipeline.add_act(act_name=_("人工确认卸载实例"), act_component_code=PauseComponent.code, kwargs={})
# 卸载remote节点
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ def restore_local_slave_flow(self):
kwargs=asdict(exec_act_kwargs),
)

exec_act_kwargs.get_mysql_payload_func = MysqlActPayload.mysql_change_server_id.__name__
tendb_migrate_pipeline.add_act(
act_name=_("重置server_id {}".format(exec_act_kwargs.exec_ip)),
act_component_code=ExecuteDBActuatorScriptComponent.code,
kwargs=asdict(exec_act_kwargs),
)

cluster = {
"cluster_id": cluster_model.id,
"master_ip": master.machine.ip,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ def tendb_remote_slave_local_recover(self):
act_component_code=ExecuteDBActuatorScriptComponent.code,
kwargs=asdict(exec_act_kwargs),
)

exec_act_kwargs.get_mysql_payload_func = MysqlActPayload.mysql_change_server_id.__name__
tendb_migrate_pipeline.add_act(
act_name=_("重置server_id {}".format(exec_act_kwargs.exec_ip)),
act_component_code=ExecuteDBActuatorScriptComponent.code,
kwargs=asdict(exec_act_kwargs),
)

cluster = {
"cluster_id": cluster_class.id,
"master_ip": master.machine.ip,
Expand Down
16 changes: 16 additions & 0 deletions dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,3 +2686,19 @@ def truncate_pre_drop_stage_on_remote(self, **kwargs) -> dict:
},
},
}

def mysql_change_server_id(self, **kwargs):
payload = {
"db_type": DBActuatorTypeEnum.MySQL.value,
"action": DBActuatorActionEnum.ChangeServerId.value,
"payload": {
"general": {"runtime_account": self.account},
"extend": [
{
"host": self.cluster["new_slave_ip"],
"port": self.cluster["new_slave_port"],
}
],
},
}
return payload

0 comments on commit 85fea48

Please sign in to comment.