Skip to content

Commit

Permalink
fix(mysql): 清档在中控超时 #8545
Browse files Browse the repository at this point in the history
  • Loading branch information
xfwduke committed Dec 11, 2024
1 parent af3f501 commit d4bd823
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func DropDB(conn *sqlx.Conn, dbName, to string, onlyStageTable bool) error {
return fmt.Errorf(`db "%s" is not trans clean`, dbName)
}

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()

_, err = conn.ExecContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func safeDropSourceTable(conn *sqlx.Conn, dbName, stageDBName, tableName string)
return fmt.Errorf("table `%s` does not exist in `%s`", tableName, stageDBName)
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

// 留着这里, drop table 不需要预处理触发器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,22 @@ func (c *ViaCtlComponent) dropSourceTables() error {
return nil
}

// 如果库下面有很多表, 直接 drop database 很容易超时
// 得循环起来先一个一个把表 drop 了
func (c *ViaCtlComponent) dropSourceDBs() error {
for db := range c.dbTablesMap {
stageDBName := generateStageDBName(c.Param.StageDBHeader, c.Param.FlowTimeStr, db)
err := rpkg.DropDB(c.dbConn, db, stageDBName, true)

logger.Info(fmt.Sprintf("drop source dbs %v should drop it's tables", c.dbTablesMap[db]))

err := tpkg.SafeDropSourceTables(c.dbConn, db, stageDBName, c.dbTablesMap[db])
if err != nil {
logger.Error("drop source tables %v failed: ", c.dbTablesMap[db], err.Error())
return err
}
logger.Info("drop source tables %v success", c.dbTablesMap[db])

err = rpkg.DropDB(c.dbConn, db, stageDBName, true)
if err != nil {
logger.Error(
"drop db %s failed: %s", db, err.Error(),
Expand Down

0 comments on commit d4bd823

Please sign in to comment.