Skip to content

Commit

Permalink
fix: 修复获取binlog错误 TencentBlueKing#6867
Browse files Browse the repository at this point in the history
  • Loading branch information
zfrendo committed Sep 11, 2024
1 parent 3d6020f commit e1292da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ def query_binlog_from_bklog(
)

if not binlogs:
raise AppBaseException(_("无法查找在时间范围内{}-{},主机{}的binlog日志").format(start_time, end_time, host_ip))
return {}
# raise AppBaseException(_("无法查找在时间范围内{}-{},主机{}的binlog日志").format(start_time, end_time, host_ip))

# 根据stop_time和host进行过滤(字典外层参数cluster_domain,cluster_id,host,port都一样)
binlog_record: Dict[str, Union[str, List]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@ def get_backup_binlog(
return result
# 先从别分文件的主节点查询,查询不到改为从节点查询。
rollback_handler = FixPointRollbackHandler(cluster_id)
backup_binlog = rollback_handler.query_binlog_from_bklog(
start_time=start_time,
end_time=end_time,
host_ip=binlog_info["show_master_status"]["master_host"],
port=binlog_info["show_master_status"]["master_port"],
minute_range=minute_range,
)
result["binlog_start_file"] = binlog_info["show_master_status"]["binlog_file"]
result["binlog_start_pos"] = binlog_info["show_master_status"]["binlog_pos"]
if backup_binlog is None:
if "show_slave_status" not in binlog_info.keys():
result["query_binlog_error"] = _(
"获取原主节点 {} binlog失败".format(binlog_info["show_master_status"]["master_host"])
)
return result
backup_binlog = None
if "show_slave_status" in binlog_info.keys():
backup_binlog = rollback_handler.query_binlog_from_bklog(
start_time=start_time,
end_time=end_time,
Expand All @@ -51,9 +38,21 @@ def get_backup_binlog(
)
result["binlog_start_file"] = binlog_info["show_slave_status"]["binlog_file"]
result["binlog_start_pos"] = binlog_info["show_slave_status"]["binlog_pos"]
logger.info("master binlog is:", backup_binlog)

if backup_binlog is None or len(backup_binlog) == 0:
backup_binlog = rollback_handler.query_binlog_from_bklog(
start_time=start_time,
end_time=end_time,
host_ip=binlog_info["show_master_status"]["master_host"],
port=binlog_info["show_master_status"]["master_port"],
minute_range=minute_range,
)
result["binlog_start_file"] = binlog_info["show_master_status"]["binlog_file"]
result["binlog_start_pos"] = binlog_info["show_master_status"]["binlog_pos"]
if backup_binlog is None:
result["query_binlog_error"] = _("获取原主节点{} 和 原从节点{} 的binlog失败").format(
binlog_info["show_master_status"]["master_host"], binlog_info["show_slave_status"]["master_host"]
result["query_binlog_error"] = _("原备份节点节点{} 的binlog失败").format(
binlog_info["show_master_status"]["master_host"]
)
return result
result["binlog_task_ids"] = [i["task_id"] for i in backup_binlog["file_list_details"]]
Expand Down

0 comments on commit e1292da

Please sign in to comment.