diff --git a/go/base/context.go b/go/base/context.go index bc81f32a0..69cb7ddda 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -91,6 +91,7 @@ type MigrationContext struct { SkipRenamedColumns bool IsTungsten bool DiscardForeignKeys bool + AliyunRDS bool config ContextConfig configMutex *sync.Mutex diff --git a/go/base/utils.go b/go/base/utils.go index 727bc57e0..d6bbf479c 100644 --- a/go/base/utils.go +++ b/go/base/utils.go @@ -64,17 +64,26 @@ func StringContainsAll(s string, substrings ...string) bool { return nonEmptyStringsFound } -func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig) (string, error) { - query := `select @@global.port, @@global.version` +func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext) (string, error) { + versionQuery := `select @@global.version` var port, extraPort int var version string - if err := db.QueryRow(query).Scan(&port, &version); err != nil { + if err := db.QueryRow(versionQuery).Scan(&version); err != nil { return "", err } extraPortQuery := `select @@global.extra_port` if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil { // swallow this error. not all servers support extra_port } + // AliyunRDS set users port to "NULL", replace it by gh-ost param + if migrationContext.AliyunRDS { + port = connectionConfig.Key.Port + } else { + portQuery := `select @@global.port` + if err := db.QueryRow(portQuery).Scan(&port); err != nil { + return "", err + } + } if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) { log.Infof("connection validated on %+v", connectionConfig.Key) diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 3433fabb2..30ac43618 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -67,6 +67,7 @@ func main() { flag.BoolVar(&migrationContext.IsTungsten, "tungsten", false, "explicitly let gh-ost know that you are running on a tungsten-replication based topology (you are likely to also provide --assume-master-host)") flag.BoolVar(&migrationContext.DiscardForeignKeys, "discard-foreign-keys", false, "DANGER! This flag will migrate a table that has foreign keys and will NOT create foreign keys on the ghost table, thus your altered table will have NO foreign keys. This is useful for intentional dropping of foreign keys") flag.BoolVar(&migrationContext.SkipForeignKeyChecks, "skip-foreign-key-checks", false, "set to 'true' when you know for certain there are no foreign keys on your table, and wish to skip the time it takes for gh-ost to verify that") + flag.BoolVar(&migrationContext.AliyunRDS, "aliyun-rds", false, "set to 'true' when you execute on Aliyun RDS.") 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") diff --git a/go/logic/applier.go b/go/logic/applier.go index 227b59ec4..0a2951ebe 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -78,21 +78,23 @@ func (this *Applier) InitDBConnections() (err error) { return err } this.singletonDB.SetMaxOpenConns(1) - version, err := base.ValidateConnection(this.db, this.connectionConfig) + version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext) if err != nil { return err } - if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig); err != nil { + if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig, this.migrationContext); err != nil { return err } this.migrationContext.ApplierMySQLVersion = version if err := this.validateAndReadTimeZone(); err != nil { return err } - if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { - return err - } else { - this.connectionConfig.ImpliedKey = impliedKey + if !this.migrationContext.AliyunRDS { + if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { + return err + } else { + this.connectionConfig.ImpliedKey = impliedKey + } } if err := this.readTableColumns(); err != nil { return err diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 31c81dce5..bb574479b 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -53,10 +53,12 @@ func (this *Inspector) InitDBConnections() (err error) { if err := this.validateConnection(); err != nil { return err } - if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { - return err - } else { - this.connectionConfig.ImpliedKey = impliedKey + if !this.migrationContext.AliyunRDS { + if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { + return err + } else { + this.connectionConfig.ImpliedKey = impliedKey + } } if err := this.validateGrants(); err != nil { return err @@ -203,7 +205,7 @@ func (this *Inspector) validateConnection() error { return fmt.Errorf("MySQL replication length limited to 32 characters. See https://dev.mysql.com/doc/refman/5.7/en/assigning-passwords.html") } - version, err := base.ValidateConnection(this.db, this.connectionConfig) + version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext) this.migrationContext.InspectorMySQLVersion = version return err } diff --git a/go/logic/streamer.go b/go/logic/streamer.go index 37e719543..25d9f536c 100644 --- a/go/logic/streamer.go +++ b/go/logic/streamer.go @@ -107,7 +107,7 @@ func (this *EventsStreamer) InitDBConnections() (err error) { if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, EventsStreamerUri); err != nil { return err } - if _, err := base.ValidateConnection(this.db, this.connectionConfig); err != nil { + if _, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext); err != nil { return err } if err := this.readCurrentBinlogCoordinates(); err != nil {