Skip to content

Commit

Permalink
fix(mysql): 中控清档漏掉了设置drop不转发 #8816
Browse files Browse the repository at this point in the history
  • Loading branch information
xfwduke committed Dec 25, 2024
1 parent 73f7af7 commit 1998372
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
"context"
"dbm-services/common/go-pubpkg/logger"
"dbm-services/mysql/db-tools/dbactuator/pkg/components/rename_dbs/pkg"
"fmt"
"time"
Expand All @@ -22,6 +23,7 @@ func SafeDropSourceTables(conn *sqlx.Conn, dbName, stageDBName string, tables []
func safeDropSourceTable(conn *sqlx.Conn, dbName, stageDBName, tableName string) error {
ok, err := pkg.IsTableExistsIn(conn, tableName, stageDBName)
if err != nil {
logger.Error("error checking if table exists in database %s.%s: %s", stageDBName, tableName, err)
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ func (c *ViaCtlComponent) CreateStageTables() error {

// Truncate truncate table 不需要任何处理
func (c *ViaCtlComponent) Truncate() error {
/*
v1 版本中, 这一步操作是直接 drop db, 而且写法是 drop db if exists
所以可以不用关心 remote 上这个 db 在不在
v2 版本优化了 dropSourceDBs, 会先定向删除 db 中表, 能减少超时
但是当 remote 的 db 不存在时 (实际确实没了), 会报错
所以需要在这里单独把 tcadmin 设置为 0, 不转发 drop 命令
只能在这个函数内设置, 因为这个函数只在最后的 中控清档 步骤执行
如果在前面设置会影响其他步骤
*/
_, err := c.dbConn.ExecContext(context.Background(), `SET TC_ADMIN=0`)
if err != nil {
logger.Error("truncate on ctl set tc admin failed: ", err.Error())
return err
}

if c.Param.TruncateDataType == "drop_database" {
err := c.dropSourceDBs()
if err != nil {
Expand Down

0 comments on commit 1998372

Please sign in to comment.