Skip to content

Commit

Permalink
add lock check for OceanBase
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Nov 22, 2024
1 parent 70cd24f commit 06ac30d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions go/base/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
gosql "database/sql"

"github.com/github/gh-ost/go/mysql"
"github.com/openark/golib/sqlutils"
)

var (
Expand Down Expand Up @@ -129,5 +130,15 @@ func validateOceanBaseConnection(db *gosql.DB, migrationContext *MigrationContex
if !enableLockPriority {
return errors.New("system parameter 'enable_lock_priority' should be true to support cut-over")
}

// try lock and unlock table
lockQuery := fmt.Sprintf(`lock /* gh-ost */ tables %s.%s write`, migrationContext.DatabaseName, migrationContext.OriginalTableName)
if _, err := sqlutils.ExecNoPrepare(db, lockQuery); err != nil {
return err
}
unlockQuery := `unlock /* gh-ost */ tables`
if _, err := sqlutils.ExecNoPrepare(db, unlockQuery); err != nil {
return err
}
return nil
}

0 comments on commit 06ac30d

Please sign in to comment.