Skip to content

Commit

Permalink
feat(dbm-services): dbha optimize spider switch close TencentBlueKing…
Browse files Browse the repository at this point in the history
  • Loading branch information
xjxia authored and zhangzhw8 committed Sep 11, 2024
1 parent 5be0098 commit 4e41839
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
4 changes: 4 additions & 0 deletions dbm-services/common/dbha/ha-module/constvar/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ const (
SlaveIpKey = "slave_ip"
// SlavePortKey use to set slave port
SlavePortKey = "slave_port"
//BinlogFile consistent switch binlog file
BinlogFile = "binlog_file"
//BinlogPos consistent switch binlog pos
BinlogPos = "binlog_pos"
)

// checksum sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ func (ins *MySQLCommonSwitch) ResetSlave() (string, uint64, error) {
return "", 0, fmt.Errorf("reset slave failed. err:%s", err.Error())
}
log.Logger.Infof("executed %s on %s:%d successd", resetSql, slaveIp, slavePort)
ins.SetInfo(constvar.BinlogFile, masterStatus.File)
ins.SetInfo(constvar.BinlogPos, masterStatus.Position)

return masterStatus.File, masterStatus.Position, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ func (ins *SpiderStorageSwitch) DoSwitch() error {
_ = primaryConn.Close()
}()

ins.ReportLogs(constvar.InfoResult, "try to reset slave")
binlogFile, binlogPosition, err := ins.ResetSlave()
if err != nil {
ins.ReportLogs(constvar.FailResult, fmt.Sprintf("reset slave failed:%s", err.Error()))
return fmt.Errorf("reset slave failed")
}
ins.StandBySlave.BinlogFile = binlogFile
ins.StandBySlave.BinlogPosition = binlogPosition
ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("reset slave success, consistent binlog info:%s,%s",
ins.StandBySlave.BinlogFile, ins.StandBySlave.BinlogPosition))

ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("try to update route from old master to new master"))
alterSQL := fmt.Sprintf(AlterNodeFormat, oldMaster.ServerName, newMaster.Host,
newMaster.UserName, newMaster.Password, newMaster.Port)
Expand Down
66 changes: 43 additions & 23 deletions dbm-services/common/dbha/ha-module/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import (

// SwitchMonitor switch monitor information
type SwitchMonitor struct {
ServerIp string
ServerPort int
Bzid string
MachineType string
Role string
Status string
Cluster string
IDC string
ServerIp string
ServerPort int
Bzid string
MachineType string
Role string
Status string
Cluster string
IDC string
BinlogFile string
BinlogPosition uint64
}

// DetectMonitor detect monitor information
Expand Down Expand Up @@ -107,6 +109,12 @@ func MonitorSend(content string, info MonitorInfo) error {
addDimension["cluster"] = info.Switch.Cluster
addDimension["machine_type"] = info.Switch.MachineType
addDimension["idc"] = info.Switch.IDC
if info.EventName == constvar.DBHAEventMysqlSwitchSucc &&
(info.Switch.Role == constvar.TenDBStorageMaster ||
info.Switch.Role == constvar.TenDBClusterStorageMaster) {
addDimension["binlog_file"] = info.Switch.BinlogFile
addDimension["binlog_pos"] = info.Switch.BinlogPosition
}
} else if info.MonitorInfoType == constvar.MonitorInfoDetect {
// detect monitor information dimension add
addDimension["appid"] = info.Detect.Bzid
Expand All @@ -132,6 +140,22 @@ func MonitorSend(content string, info MonitorInfo) error {
// GetMonitorInfoBySwitch get MonitorInfo by switch instance
func GetMonitorInfoBySwitch(ins dbutil.DataBaseSwitch, succ bool) MonitorInfo {
var eventName string
addr, port := ins.GetAddress()
monInfo := MonitorInfo{
EventName: eventName,
MonitorInfoType: constvar.MonitorInfoSwitch,
Switch: SwitchMonitor{
ServerIp: addr,
ServerPort: port,
Bzid: ins.GetApp(),
MachineType: ins.GetMetaType(),
Role: ins.GetRole(),
Status: ins.GetStatus(),
Cluster: ins.GetCluster(),
IDC: strconv.Itoa(ins.GetIdcID()),
},
}

switch ins.GetMetaType() {
case constvar.RedisMetaType, constvar.TwemproxyMetaType,
constvar.TendisSSDMetaType:
Expand All @@ -150,6 +174,15 @@ func GetMonitorInfoBySwitch(ins dbutil.DataBaseSwitch, succ bool) MonitorInfo {
constvar.TenDBClusterStorageType, constvar.TenDBClusterProxyType:
if succ {
eventName = constvar.DBHAEventMysqlSwitchSucc
if ins.GetRole() == constvar.TenDBStorageMaster ||
ins.GetRole() == constvar.TenDBClusterStorageMaster {
if ok, file := ins.GetInfo(constvar.BinlogFile); ok {
monInfo.Switch.BinlogFile = file.(string)
}
if ok, pos := ins.GetInfo(constvar.BinlogPos); ok {
monInfo.Switch.BinlogPosition = pos.(uint64)
}
}
} else {
eventName = constvar.DBHAEventMysqlSwitchErr
}
Expand All @@ -166,22 +199,9 @@ func GetMonitorInfoBySwitch(ins dbutil.DataBaseSwitch, succ bool) MonitorInfo {
eventName = constvar.DBHAEventMysqlSwitchErr
}
}
monInfo.EventName = eventName

addr, port := ins.GetAddress()
return MonitorInfo{
EventName: eventName,
MonitorInfoType: constvar.MonitorInfoSwitch,
Switch: SwitchMonitor{
ServerIp: addr,
ServerPort: port,
Bzid: ins.GetApp(),
MachineType: ins.GetMetaType(),
Role: ins.GetRole(),
Status: ins.GetStatus(),
Cluster: ins.GetCluster(),
IDC: strconv.Itoa(ins.GetIdcID()),
},
}
return monInfo
}

// GetMonitorInfoByDetect get MonitorInfo by detect instance
Expand Down

0 comments on commit 4e41839

Please sign in to comment.