Skip to content

Commit

Permalink
determine and verify OceanBase connection
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Nov 22, 2024
1 parent 6c080b4 commit 5a141ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 28 additions & 0 deletions go/base/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package base

import (
"errors"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -62,6 +63,10 @@ func StringContainsAll(s string, substrings ...string) bool {
}

func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string) (string, error) {
if err := validateOceanBaseConnection(db, migrationContext); err != nil {
return "", err
}

versionQuery := `select @@global.version`

var version string
Expand Down Expand Up @@ -102,3 +107,26 @@ func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig,
return "", fmt.Errorf("Unexpected database port reported: %+v / extra_port: %+v", port, extraPort)
}
}

func validateOceanBaseConnection(db *gosql.DB, migrationContext *MigrationContext) error {
versionCommentQuery := `select @@global.version_comment`
var versionComment string
if err := db.QueryRow(versionCommentQuery).Scan(&versionComment); err != nil {
return nil
}
if !strings.Contains(versionComment, "OceanBase") {
return nil
}

migrationContext.OceanBase = true

enableLockPriorityQuery := `select value from oceanbase.GV$OB_PARAMETERS where name='enable_lock_priority'`
var enableLockPriority bool
if err := db.QueryRow(enableLockPriorityQuery).Scan(&enableLockPriority); err != nil {
return err
}
if !enableLockPriority {
return errors.New("system parameter 'enable_lock_priority' should be true to support cut-over")
}
return nil
}
1 change: 0 additions & 1 deletion go/cmd/gh-ost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func main() {
flag.BoolVar(&migrationContext.AliyunRDS, "aliyun-rds", false, "set to 'true' when you execute on Aliyun RDS.")
flag.BoolVar(&migrationContext.GoogleCloudPlatform, "gcp", false, "set to 'true' when you execute on a 1st generation Google Cloud Platform (GCP).")
flag.BoolVar(&migrationContext.AzureMySQL, "azure", false, "set to 'true' when you execute on Azure Database on MySQL.")
flag.BoolVar(&migrationContext.OceanBase, "oceanbase", false, "set to 'true' when you execute on OceanBase")

executeFlag := flag.Bool("execute", false, "actually execute the alter & migrate the table. Default is noop: do some tests and exit")
flag.BoolVar(&migrationContext.TestOnReplica, "test-on-replica", false, "Have the migration run on a replica, not on the master. At the end of migration replication is stopped, and tables are swapped and immediately swap-revert. Replication remains stopped and you can compare the two tables for building trust")
Expand Down

0 comments on commit 5a141ae

Please sign in to comment.