Skip to content

Commit

Permalink
fix(dbm-services): 处理语法分析并发问题 TencentBlueKing#8675
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Dec 17, 2024
1 parent 9760896 commit 81455e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ func (tf *TmysqlParseFile) DoParseRelationDbs(version string) (createDbs, relati
}
// 最后删除临时目录,不会返回错误
defer tf.delTempDir()

errChan := make(chan error, 1)
logger.Info("all sqlfiles download ok ~")
alreadExecutedSqlfileChan := make(chan string, len(tf.Param.FileNames))

go func() {
if err = tf.Execute(alreadExecutedSqlfileChan, version); err != nil {
logger.Error("failed to execute tmysqlparse: %s", err.Error())
errChan <- err
}
close(alreadExecutedSqlfileChan)
}()
Expand All @@ -79,7 +77,7 @@ func (t *TmysqlParse) doParseInchan(alreadExecutedSqlfileCh chan string,
mysqlVersion string) (createDbs []string, relationDbs []string, dumpAll bool, err error) {
var errs []error
c := make(chan struct{}, 10)
errChan := make(chan error, 5)
errChan := make(chan error)
wg := &sync.WaitGroup{}
stopChan := make(chan struct{})

Expand Down Expand Up @@ -132,7 +130,6 @@ func (t *TmysqlParse) analyzeRelationDbs(inputfileName, mysqlVersion string) (
logger.Error("panic error:%v,stack:%s", r, string(debug.Stack()))
}
}()
t.result[inputfileName] = &CheckInfo{}
f, err := os.Open(t.getAbsoutputfilePath(inputfileName, mysqlVersion))
if err != nil {
logger.Error("open file failed %s", err.Error())
Expand Down
8 changes: 4 additions & 4 deletions dbm-services/mysql/db-simulation/app/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ const DdlMapFileSubffix = ".tbl.map"

// Do 运行语法检查 For SQL 文件
func (tf *TmysqlParseFile) Do(dbtype string, versions []string) (result map[string]*CheckInfo, err error) {
logger.Info("doing....")
tf.mu = sync.Mutex{}
tf.mu.Lock()
tf.result = make(map[string]*CheckInfo)
tf.tmpWorkdir = tf.BaseWorkdir
tf.mu = sync.Mutex{}

tf.mu.Unlock()
if !tf.IsLocalFile {
if err = tf.Init(); err != nil {
logger.Error("Do init failed %s", err.Error())
Expand All @@ -142,7 +142,7 @@ func (tf *TmysqlParseFile) Do(dbtype string, versions []string) (result map[stri
}

func (tf *TmysqlParseFile) doSingleVersion(dbtype string, mysqlVersion string) (err error) {
errChan := make(chan error, 1)
errChan := make(chan error, len(tf.Param.FileNames))
alreadExecutedSqlfileChan := make(chan string, len(tf.Param.FileNames))
signalChan := make(chan struct{})

Expand Down

0 comments on commit 81455e3

Please sign in to comment.