Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlserver): 修复恢复数据出现问题 #6968 #6972

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *RestoreDBSForFullComp) PreCheck() error {
}

// GetRestorePath 获取这次恢复路径
// 全量备份恢复的路径的优先级:app_setting表[RESTORE_PATH] > app_setting表[DATA_PATH] > 默认
// 全量备份恢复的路径的优先级:app_setting表[RESTORE_PATH] > 默认
func (r *RestoreDBSForFullComp) GetRestorePath() error {
var infos []AppSettingInfo
checkSQL := fmt.Sprintf(
Expand All @@ -154,17 +154,21 @@ func (r *RestoreDBSForFullComp) GetRestorePath() error {
if err := r.LocalDB.Queryx(&infos, checkSQL); err != nil {
return fmt.Errorf("select APP_SETTING failed: %v", err)
}
if infos[0].RestorePath.Valid && infos[0].RestorePath.String != "" {
r.RestoreDataPath = infos[0].RestorePath.String
r.RestoreLogPath = infos[0].RestorePath.String
return nil
}
if infos[0].DataPath.Valid && infos[0].LogPath.Valid &&
infos[0].DataPath.String != "" && infos[0].LogPath.String != "" {
r.RestoreDataPath = infos[0].DataPath.String
r.RestoreLogPath = infos[0].LogPath.String
return nil
// 如果aap_setting没有记录,则走默认
if len(infos) > 0 {
if infos[0].RestorePath.Valid && infos[0].RestorePath.String != "" {
r.RestoreDataPath = infos[0].RestorePath.String
r.RestoreLogPath = infos[0].RestorePath.String
return nil
}
if infos[0].DataPath.Valid && infos[0].LogPath.Valid &&
infos[0].DataPath.String != "" && infos[0].LogPath.String != "" {
r.RestoreDataPath = infos[0].DataPath.String
r.RestoreLogPath = infos[0].LogPath.String
return nil
}
}
// 获取默认值
if defaultPath, err := r.LocalDB.GetDefaultPath(); err != nil {
return fmt.Errorf("get default path failed: %v", err)
} else {
Expand Down
8 changes: 7 additions & 1 deletion dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ def switch_slave(
new_slave_obj.machine.save(update_fields=["db_module_id"])
cluster.storageinstance_set.add(new_slave_obj)

# 切换slave域名信息
slave_entry_list = old_slave_obj.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all()
for slave_entry in slave_entry_list:
slave_entry.storageinstance_set.remove(old_slave_obj)
slave_entry.storageinstance_set.add(new_slave_obj)

# 添加对应cmdb服务实例信息
SqlserverCCTopoOperator(cluster).transfer_instances_to_cluster_module([new_slave_obj])

Expand Down Expand Up @@ -397,7 +403,7 @@ def reduce_slave(
old_slave_obj = cluster.storageinstance_set.get(machine__ip=old_slave_host.ip)

# 替换域名关联信息
entry_list = old_slave_obj.bind_entry.all()
entry_list = old_slave_obj.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all()
for entry in entry_list:
entry.storageinstance_set.remove(old_slave_obj)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def switch_domain_sub_flow_for_cluster(
cluster: Cluster,
old_master: StorageInstance,
new_master: StorageInstance,
is_force: bool = False,
):
"""
主从切换后做域名切换处理
Expand All @@ -214,6 +215,7 @@ def switch_domain_sub_flow_for_cluster(
@param old_master: 集群原主实例
@param new_master: 集群新主实例
@param cluster: 集群id
@param is_force: 是否属于强切行为,默认不是,强切行为认为主故障,从域名不切换到旧主上
"""
# 构造只读上下文
global_data = {"uid": uid, "bk_biz_id": cluster.bk_biz_id}
Expand All @@ -232,30 +234,31 @@ def switch_domain_sub_flow_for_cluster(
"kwargs": asdict(
UpdateDnsRecordKwargs(
bk_cloud_id=cluster.bk_cloud_id,
old_instance=f"{new_master.machine.ip}#{new_master.port}",
new_instance=f"{old_master.machine.ip}#{old_master.port}",
old_instance=f"{old_master.machine.ip}#{old_master.port}",
new_instance=f"{new_master.machine.ip}#{new_master.port}",
update_domain_name=old_master_dns.entry,
),
),
}
)
# 并发替换从域名映射
slave_dns_list = new_master.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all()
for slave_dns in slave_dns_list:
acts_list.append(
{
"act_name": _("[{}]替换从域名映射".format(slave_dns.entry)),
"act_component_code": MySQLDnsManageComponent.code,
"kwargs": asdict(
UpdateDnsRecordKwargs(
bk_cloud_id=cluster.bk_cloud_id,
old_instance=f"{new_master.machine.ip}#{new_master.port}",
new_instance=f"{old_master.machine.ip}#{old_master.port}",
update_domain_name=slave_dns.entry,
if not is_force:
slave_dns_list = new_master.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all()
for slave_dns in slave_dns_list:
acts_list.append(
{
"act_name": _("[{}]替换从域名映射".format(slave_dns.entry)),
"act_component_code": MySQLDnsManageComponent.code,
"kwargs": asdict(
UpdateDnsRecordKwargs(
bk_cloud_id=cluster.bk_cloud_id,
old_instance=f"{new_master.machine.ip}#{new_master.port}",
new_instance=f"{old_master.machine.ip}#{old_master.port}",
update_domain_name=slave_dns.entry,
),
),
),
}
)
}
)
sub_pipeline.add_parallel_acts(acts_list=acts_list)

return sub_pipeline.build_sub_process(sub_name=_("变更集群[{}]域名映射".format(cluster.name)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from backend.flow.engine.bamboo.scene.sqlserver.base_flow import BaseFlow
from backend.flow.engine.bamboo.scene.sqlserver.common_sub_flow import (
build_always_on_sub_flow,
clone_configs_sub_flow,
install_sqlserver_sub_flow,
install_surrounding_apps_sub_flow,
sync_dbs_for_cluster_sub_flow,
Expand Down Expand Up @@ -186,6 +187,18 @@ def run_flow(self):
)
)

# 先做克隆周边配置
cluster_sub_pipeline.add_sub_pipeline(
sub_flow=clone_configs_sub_flow(
uid=self.data["uid"],
root_id=self.root_id,
source_host=Host(ip=master_instance.machine.ip, bk_cloud_id=cluster.bk_cloud_id),
source_port=master_instance.port,
target_host=Host(**info["new_slave_host"]),
target_port=master_instance.port,
)
)

# 删除随机账号
cluster_sub_pipeline.add_act(
act_name=_("drop job user"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def run_flow(self):
cluster=cluster,
old_master=old_master,
new_master=new_master,
is_force=self.data["force"],
)
)

Expand Down
Loading