Skip to content

Commit f914b93

Browse files
author
Shlomi Noach
authored
Merge pull request #541 from zhangxiaojian/support-aliyun-rds
Support Aliyun RDS
2 parents 3b7f1a7 + 831566c commit f914b93

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

go/base/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type MigrationContext struct {
9191
SkipRenamedColumns bool
9292
IsTungsten bool
9393
DiscardForeignKeys bool
94+
AliyunRDS bool
9495

9596
config ContextConfig
9697
configMutex *sync.Mutex

go/base/utils.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,26 @@ func StringContainsAll(s string, substrings ...string) bool {
6464
return nonEmptyStringsFound
6565
}
6666

67-
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig) (string, error) {
68-
query := `select @@global.port, @@global.version`
67+
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext) (string, error) {
68+
versionQuery := `select @@global.version`
6969
var port, extraPort int
7070
var version string
71-
if err := db.QueryRow(query).Scan(&port, &version); err != nil {
71+
if err := db.QueryRow(versionQuery).Scan(&version); err != nil {
7272
return "", err
7373
}
7474
extraPortQuery := `select @@global.extra_port`
7575
if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil {
7676
// swallow this error. not all servers support extra_port
7777
}
78+
// AliyunRDS set users port to "NULL", replace it by gh-ost param
79+
if migrationContext.AliyunRDS {
80+
port = connectionConfig.Key.Port
81+
} else {
82+
portQuery := `select @@global.port`
83+
if err := db.QueryRow(portQuery).Scan(&port); err != nil {
84+
return "", err
85+
}
86+
}
7887

7988
if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) {
8089
log.Infof("connection validated on %+v", connectionConfig.Key)

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func main() {
6767
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)")
6868
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")
6969
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")
70+
flag.BoolVar(&migrationContext.AliyunRDS, "aliyun-rds", false, "set to 'true' when you execute on Aliyun RDS.")
7071

7172
executeFlag := flag.Bool("execute", false, "actually execute the alter & migrate the table. Default is noop: do some tests and exit")
7273
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")

go/logic/applier.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,23 @@ func (this *Applier) InitDBConnections() (err error) {
7878
return err
7979
}
8080
this.singletonDB.SetMaxOpenConns(1)
81-
version, err := base.ValidateConnection(this.db, this.connectionConfig)
81+
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext)
8282
if err != nil {
8383
return err
8484
}
85-
if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig); err != nil {
85+
if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig, this.migrationContext); err != nil {
8686
return err
8787
}
8888
this.migrationContext.ApplierMySQLVersion = version
8989
if err := this.validateAndReadTimeZone(); err != nil {
9090
return err
9191
}
92-
if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil {
93-
return err
94-
} else {
95-
this.connectionConfig.ImpliedKey = impliedKey
92+
if !this.migrationContext.AliyunRDS {
93+
if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil {
94+
return err
95+
} else {
96+
this.connectionConfig.ImpliedKey = impliedKey
97+
}
9698
}
9799
if err := this.readTableColumns(); err != nil {
98100
return err

go/logic/inspect.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ func (this *Inspector) InitDBConnections() (err error) {
5353
if err := this.validateConnection(); err != nil {
5454
return err
5555
}
56-
if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil {
57-
return err
58-
} else {
59-
this.connectionConfig.ImpliedKey = impliedKey
56+
if !this.migrationContext.AliyunRDS {
57+
if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil {
58+
return err
59+
} else {
60+
this.connectionConfig.ImpliedKey = impliedKey
61+
}
6062
}
6163
if err := this.validateGrants(); err != nil {
6264
return err
@@ -203,7 +205,7 @@ func (this *Inspector) validateConnection() error {
203205
return fmt.Errorf("MySQL replication length limited to 32 characters. See https://dev.mysql.com/doc/refman/5.7/en/assigning-passwords.html")
204206
}
205207

206-
version, err := base.ValidateConnection(this.db, this.connectionConfig)
208+
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext)
207209
this.migrationContext.InspectorMySQLVersion = version
208210
return err
209211
}

go/logic/streamer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (this *EventsStreamer) InitDBConnections() (err error) {
107107
if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, EventsStreamerUri); err != nil {
108108
return err
109109
}
110-
if _, err := base.ValidateConnection(this.db, this.connectionConfig); err != nil {
110+
if _, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext); err != nil {
111111
return err
112112
}
113113
if err := this.readCurrentBinlogCoordinates(); err != nil {

0 commit comments

Comments
 (0)