diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/rename_dbs/pkg/drop_db.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/rename_dbs/pkg/drop_db.go index 4276cbd6ac..0b73efde26 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/rename_dbs/pkg/drop_db.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/rename_dbs/pkg/drop_db.go @@ -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( diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/pkg/safe_drop_tables.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/pkg/safe_drop_tables.go index a58d91e8de..01d6f36904 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/pkg/safe_drop_tables.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/pkg/safe_drop_tables.go @@ -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 不需要预处理触发器 diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/via_ctl.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/via_ctl.go index 90f5c40b07..49131ccb47 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/via_ctl.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/truncate/via_ctl.go @@ -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(),