Skip to content

Commit a85ff7c

Browse files
committed
chore: update .gitignore and fix MHA replica validation
- Add comprehensive .gitignore patterns to prevent non-essential files - Fix MHA deployment validation to check each replica individually - Add validateMHAReplica helper for per-host replication status check
1 parent e49dd63 commit a85ff7c

2 files changed

Lines changed: 61 additions & 7 deletions

File tree

.gitignore

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ agent/bin/
3030
platform-backend/platform-backend
3131
platform-backend/agent
3232
agent/agent
33+
agent/agent_linux
34+
agent/mysql-ops-agent
3335
# 测试覆盖率
3436
*.out
3537
coverage.out
@@ -101,15 +103,19 @@ Thumbs.db
101103
*.db
102104

103105
# ---------- 项目特定 ----------
104-
# 平台后端配置
106+
# 平台后端配置(含密钥的本地配置)
107+
platform-backend/config/config.yaml
105108
platform-backend/config/config.local.yaml
106-
# Agent 配置
109+
# Agent 配置(含密钥的本地配置)
110+
agent/config/config.yaml
107111
agent/config/config.local.yaml
108112
# 备份目录
109113
backups/
110114
data/
111-
.omo/
115+
omo/
112116
.cache/
117+
.codeartsdoer/
118+
.sisyphus/
113119

114120
# ---------- 敏感信息 ----------
115121
login.json
@@ -129,3 +135,18 @@ secrets.yml
129135
docs/
130136
# 临时文件
131137
*.tmp
138+
139+
# ---------- Python ----------
140+
__pycache__/
141+
*.pyc
142+
*.pyo
143+
*.egg-info/
144+
dist/
145+
build/
146+
147+
# ---------- 临时工具/脚本 ----------
148+
bfg-1.15.0.jar
149+
.gitcleanup-paths*
150+
151+
# ---------- 备份目录 ----------
152+
.git.backup/

agent/internal/executor/mha_executor.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,16 @@ func (e *MHAExecutor) validateMHADeployment(ctx context.Context, config MHAConfi
579579
}
580580
}
581581

582-
replCmd := mhaShellCommand(ctx, config.ManagerHost, config.SSHUser, config.SSHPrivateKey, "perl -X $(command -v masterha_check_repl) --conf=/etc/mha/app1.cnf")
583-
if out, err := replCmd.CombinedOutput(); err != nil {
584-
if !mhaOutputContains(string(out), "MySQL Replication Health is OK") {
582+
for i, host := range config.SlaveHosts {
583+
port := config.MasterPort
584+
if i < len(config.SlavePorts) && config.SlavePorts[i] != 0 {
585+
port = config.SlavePorts[i]
586+
}
587+
if err := validateMHAReplica(ctx, host, port, config); err != nil {
585588
return &TaskResult{
586589
Status: "failed",
587590
Progress: 85,
588-
Message: fmt.Sprintf("MHA replication check failed: %v, output: %s", err, strings.TrimSpace(string(out))),
591+
Message: fmt.Sprintf("MHA replication check failed on %s:%d: %v", host, port, err),
589592
Timestamp: time.Now(),
590593
}
591594
}
@@ -600,6 +603,36 @@ func (e *MHAExecutor) validateMHADeployment(ctx context.Context, config MHAConfi
600603
}
601604
}
602605

606+
func validateMHAReplica(ctx context.Context, host string, port int, config MHAConfig) error {
607+
output, err := mysqlExecCommand(ctx, host, port, config.ManagerUser, config.ManagerPass, "SHOW REPLICA STATUS\\G").CombinedOutput()
608+
if err != nil {
609+
legacyOutput, legacyErr := mysqlExecCommand(ctx, host, port, config.ManagerUser, config.ManagerPass, "SHOW SLAVE STATUS\\G").CombinedOutput()
610+
if legacyErr != nil {
611+
return fmt.Errorf("%v, output: %s; fallback: %v, output: %s", err, strings.TrimSpace(string(output)), legacyErr, strings.TrimSpace(string(legacyOutput)))
612+
}
613+
output = legacyOutput
614+
}
615+
616+
status := string(output)
617+
if strings.TrimSpace(status) == "" {
618+
return fmt.Errorf("replica status is empty")
619+
}
620+
if !mhaReplicaStatusContainsRunning(status, "Replica_IO_Running", "Slave_IO_Running") {
621+
return fmt.Errorf("replica IO thread is not running: %s", strings.TrimSpace(status))
622+
}
623+
if !mhaReplicaStatusContainsRunning(status, "Replica_SQL_Running", "Slave_SQL_Running") {
624+
return fmt.Errorf("replica SQL thread is not running: %s", strings.TrimSpace(status))
625+
}
626+
if !strings.Contains(status, "Source_Host: "+config.MasterHost) && !strings.Contains(status, "Master_Host: "+config.MasterHost) {
627+
return fmt.Errorf("replica source does not match master %s: %s", config.MasterHost, strings.TrimSpace(status))
628+
}
629+
return nil
630+
}
631+
632+
func mhaReplicaStatusContainsRunning(status string, modernKey string, legacyKey string) bool {
633+
return strings.Contains(status, modernKey+": Yes") || strings.Contains(status, legacyKey+": Yes")
634+
}
635+
603636
func mhaOutputContains(output, marker string) bool {
604637
return strings.Contains(output, marker)
605638
}

0 commit comments

Comments
 (0)