diff --git a/go/base/context.go b/go/base/context.go index 5f63c88..981c386 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -215,8 +215,6 @@ type ContextConfig struct { } } -var Context *MigrationContext - func NewMigrationContext() *MigrationContext { return &MigrationContext{ Uuid: uuid.NewV4().String(), diff --git a/go/base/utils.go b/go/base/utils.go index 8d9e4f0..d6bbf47 100644 --- a/go/base/utils.go +++ b/go/base/utils.go @@ -64,7 +64,7 @@ func StringContainsAll(s string, substrings ...string) bool { return nonEmptyStringsFound } -func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig) (string, error) { +func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext) (string, error) { versionQuery := `select @@global.version` var port, extraPort int var version string @@ -76,7 +76,7 @@ func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig) // swallow this error. not all servers support extra_port } // AliyunRDS set users port to "NULL", replace it by gh-ost param - if Context.AliyunRDS { + if migrationContext.AliyunRDS { port = connectionConfig.Key.Port } else { portQuery := `select @@global.port` diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 335d6cc..70a4e90 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -44,8 +44,6 @@ func acceptSignals(migrationContext *base.MigrationContext) { // main is the application's entry point. It will either spawn a CLI or HTTP interfaces. func main() { migrationContext := base.NewMigrationContext() - base.Context = migrationContext - flag.StringVar(&migrationContext.InspectorConnectionConfig.Key.Hostname, "host", "127.0.0.1", "MySQL hostname (preferably a replica, not the master)") flag.StringVar(&migrationContext.AssumeMasterHostname, "assume-master-host", "", "(optional) explicitly tell gh-ost the identity of the master. Format: some.host.com[:port] This is useful in master-master setups where you wish to pick an explicit master, or in a tungsten-replicator where gh-ost is unable to determine the master") flag.IntVar(&migrationContext.InspectorConnectionConfig.Key.Port, "port", 3306, "MySQL port (preferably a replica, not the master)") diff --git a/go/logic/applier.go b/go/logic/applier.go index 1a3e618..0a2951e 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -78,21 +78,21 @@ 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, this.migrationContext.AliyunRDS); err != nil { - return err - } else { - if this.migrationContext.AliyunRDS != true { + if !this.migrationContext.AliyunRDS { + if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { + return err + } else { this.connectionConfig.ImpliedKey = impliedKey } } diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 1417ffa..bb57447 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -53,10 +53,10 @@ func (this *Inspector) InitDBConnections() (err error) { if err := this.validateConnection(); err != nil { return err } - if impliedKey, err := mysql.GetInstanceKey(this.db, this.migrationContext.AliyunRDS); err != nil { - return err - } else { - if this.migrationContext.AliyunRDS != true { + if !this.migrationContext.AliyunRDS { + if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { + return err + } else { this.connectionConfig.ImpliedKey = impliedKey } } @@ -205,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 37e7195..25d9f53 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 { diff --git a/go/mysql/utils.go b/go/mysql/utils.go index c513ae5..532cbb4 100644 --- a/go/mysql/utils.go +++ b/go/mysql/utils.go @@ -171,11 +171,9 @@ func GetSelfBinlogCoordinates(db *gosql.DB) (selfBinlogCoordinates *BinlogCoordi } // GetInstanceKey reads hostname and port on given DB -func GetInstanceKey(db *gosql.DB, isAliyunRDS bool) (instanceKey *InstanceKey, err error) { +func GetInstanceKey(db *gosql.DB) (instanceKey *InstanceKey, err error) { instanceKey = &InstanceKey{} - if isAliyunRDS != true { - err = db.QueryRow(`select @@global.hostname, @@global.port`).Scan(&instanceKey.Hostname, &instanceKey.Port) - } + err = db.QueryRow(`select @@global.hostname, @@global.port`).Scan(&instanceKey.Hostname, &instanceKey.Port) return instanceKey, err }