[ Agent ] [ App ] - fix mysql init bugs - 2

This commit is contained in:
zeaslity
2023-11-28 11:05:39 +08:00
parent a639b9173c
commit 4217a2fd0d
2 changed files with 20 additions and 4 deletions

View File

@@ -5,7 +5,9 @@ import (
"net"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"
)
@@ -542,7 +544,8 @@ func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []strin
}
}
sort.Strings(jackeyLoveFileList)
// sort for numeric order
sortFileNames(jackeyLoveFileList)
log.InfoF("[loadMysqlInitScript] - all jackey love files are => %v", jackeyLoveFileList)
// dispatch mysql execution command
@@ -553,7 +556,7 @@ func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []strin
"[loadMysqlInitScript]- ip config error ",
}
}
load, result := MysqlSqlFileLoad(jackeyLoveFileList)
load, result := MysqlSqlFileLoad(jackeyLoveIP, jackeyLoveFileList)
if !load {
return false, result
}
@@ -563,6 +566,19 @@ func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []strin
}
}
func sortFileNames(fileNames []string) {
re := regexp.MustCompile(`(\d+)_`)
sort.Slice(fileNames, func(i, j int) bool {
numStr1 := re.FindStringSubmatch(fileNames[i])
numStr2 := re.FindStringSubmatch(fileNames[j])
num1, _ := strconv.Atoi(numStr1[1])
num2, _ := strconv.Atoi(numStr2[1])
return num1 < num2
})
}
func (op *AgentOsOperator) checkMySQL(funcArgs []string) (bool, []string) {
if !K8sCheckPodStatusTimeout("helm-mysql-0", funcArgs[0], 180) {

View File

@@ -7,9 +7,9 @@ import (
"os"
)
func MysqlSqlFileLoad(jackeyLoveFileList []string) (bool, []string) {
func MysqlSqlFileLoad(jackeyLoveIp string, jackeyLoveFileList []string) (bool, []string) {
dsn := "root:QzfXQhd3bQ@tcp(127.0.0.1:33306)"
dsn := "root:QzfXQhd3bQ@tcp(" + jackeyLoveIp + ":33306)"
db, err := sql.Open("mysql", dsn)
if err != nil {
errConnect := fmt.Sprintf("[MysqlSqlFileLoad]- mysql connection error ! please check ! => %s ", dsn)