Skip to content

Commit b100858

Browse files
committed
improve pxc join diagnostics
1 parent 7dafd2f commit b100858

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

agent/internal/executor/pxc_executor.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ func startStandalonePXC(ctx context.Context, config PXCConfig) error {
667667

668668
func waitForPXCMySQL(ctx context.Context, config PXCConfig) error {
669669
socket := filepathJoin(config.DataDir, "mysql.sock")
670-
deadline := time.Now().Add(90 * time.Second)
670+
deadline := time.Now().Add(10 * time.Minute)
671671
for time.Now().Before(deadline) {
672672
for _, pass := range []string{config.MySQLPassword, ""} {
673673
pingCmd := exec.CommandContext(ctx, pxcMysqladminPath(), "--socket", socket, "-u", "root", "ping")
@@ -695,7 +695,25 @@ func waitForPXCMySQL(ctx context.Context, config PXCConfig) error {
695695
case <-time.After(3 * time.Second):
696696
}
697697
}
698-
return fmt.Errorf("timeout waiting for mysqld on port %d", config.MySQLPort)
698+
return fmt.Errorf("timeout waiting for mysqld on port %d: %s", config.MySQLPort, pxcRecentLogs(ctx, config))
699+
}
700+
701+
func pxcRecentLogs(ctx context.Context, config PXCConfig) string {
702+
cmd := exec.CommandContext(ctx, "bash", "-lc", fmt.Sprintf(`for f in %s %s; do
703+
if [ -s "$f" ]; then
704+
echo "== $f =="
705+
tail -80 "$f"
706+
fi
707+
done`, shellQuote(pxcStartupLogPath(config)), shellQuote(pxcErrorLogPath(config))))
708+
out, err := cmd.CombinedOutput()
709+
if err != nil {
710+
return fmt.Sprintf("failed to read PXC logs: %v, output: %s", err, strings.TrimSpace(string(out)))
711+
}
712+
logs := strings.TrimSpace(string(out))
713+
if logs == "" {
714+
return "PXC startup and error logs are empty"
715+
}
716+
return logs
699717
}
700718

701719
func setPXCRootPassword(ctx context.Context, config PXCConfig) error {

platform-backend/internal/services/cluster_deploy_service.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,20 @@ func (s *ClusterDeployService) DeployPXC(ctx context.Context, req DeployPXCReque
690690
"instance_id": "",
691691
"config": joinConfig,
692692
})
693-
if err != nil || isFailedDeployStatus(normalizeDeployStatus(result.Status)) {
694-
s.updateStepStatus(deployment.ID, nodeName, "failed", "节点加入失败")
695-
s.repo.UpdateStatus(ctx, deployment.ID, "partial")
696-
msg := "PXC cluster partially deployed (bootstrap OK, some nodes failed)"
697-
if err != nil {
698-
msg = fmt.Sprintf("%s: %v", msg, err)
699-
}
700-
return &DeployResponse{
693+
if err != nil || isFailedDeployStatus(normalizeDeployStatus(result.Status)) {
694+
nodeMessage := "节点加入失败"
695+
if err != nil {
696+
nodeMessage = fmt.Sprintf("%s: %v", nodeMessage, err)
697+
} else if result.Message != "" {
698+
nodeMessage = fmt.Sprintf("%s: %s", nodeMessage, result.Message)
699+
}
700+
s.updateStepStatus(deployment.ID, nodeName, "failed", nodeMessage)
701+
s.repo.UpdateStatus(ctx, deployment.ID, "partial")
702+
msg := "PXC cluster partially deployed (bootstrap OK, some nodes failed)"
703+
if nodeMessage != "" {
704+
msg = fmt.Sprintf("%s: %s", msg, nodeMessage)
705+
}
706+
return &DeployResponse{
701707
DeploymentID: deployment.ID,
702708
ClusterType: "pxc",
703709
Name: req.Name,

0 commit comments

Comments
 (0)