Skip to content

Commit

Permalink
feat(mysql): mysql清档重命名增加flush tables TencentBlueKing#8718
Browse files Browse the repository at this point in the history
  • Loading branch information
xfwduke committed Dec 19, 2024
1 parent 0352875 commit b04c17d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"strings"
"time"

"dbm-services/common/go-pubpkg/logger"
"dbm-services/mysql/db-tools/dbactuator/pkg/components"
Expand Down Expand Up @@ -62,6 +63,10 @@ func (c *OnMySQLComponent) Do() error {
}

func (c *OnMySQLComponent) oneInstance(port int) error {
defer func() {
c.instanceFlushTable()
}()

err := c.instanceInit(port)
if err != nil {
return err
Expand Down Expand Up @@ -279,6 +284,21 @@ func (c *OnMySQLComponent) instanceDropFromDBs(port int) error {
return nil
}

func (c *OnMySQLComponent) instanceFlushTable() {
if c.dbConn != nil {
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Second)
defer cancel()

_, err := c.dbConn.ExecContext(
ctx,
`FLUSH TABLES`,
)
if err != nil {
logger.Error("flush table failed: %v", err)
}
}
}

func (c *OnMySQLComponent) Example() interface{} {
f := false
return OnMySQLComponent{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,26 @@ func (c *OnMySQLComponent) Truncate() error {
return nil
}

func (c *OnMySQLComponent) instanceFlushTable() {
if c.dbConn != nil {
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Second)
defer cancel()

_, err := c.dbConn.ExecContext(
ctx,
`FLUSH TABLES`,
)
if err != nil {
logger.Error("flush table failed: %v", err)
}
}
}

func (c *OnMySQLComponent) oneInstance(port int) error {
defer func() {
c.instanceFlushTable()
}()

err := c.instanceInit(port)
if err != nil {
logger.Error("init instance %d truncate failed: %s", port, err.Error())
Expand Down

0 comments on commit b04c17d

Please sign in to comment.