diff --git a/go/base/context.go b/go/base/context.go index cc5844e..b68bf7b 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -288,7 +288,7 @@ func NewMigrationContext() *MigrationContext { } } -func (this *MigrationContext) SetConnectionConfig(storageEngine string) error { +func (this *MigrationContext) SetConnectionConfig(storageEngine string, host string, port int, timeout float64) error { transactionIsolation := "REPEATABLE-READ" switch storageEngine { case "rocksdb": @@ -299,6 +299,9 @@ func (this *MigrationContext) SetConnectionConfig(storageEngine string) error { transactionIsolation = "REPEATABLE-READ" } this.InspectorConnectionConfig = mysql.NewConnectionConfig(transactionIsolation) + this.InspectorConnectionConfig.Key.Hostname = host + this.InspectorConnectionConfig.Key.Port = port + this.InspectorConnectionConfig.Timeout = timeout this.ApplierConnectionConfig = mysql.NewConnectionConfig(transactionIsolation) return nil } diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 54083c3..145ef65 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -47,10 +47,10 @@ 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() - flag.StringVar(&migrationContext.InspectorConnectionConfig.Key.Hostname, "host", "127.0.0.1", "MySQL hostname (preferably a replica, not the master)") + host := flag.String("host", "127.0.0.1", "MySQL hostname (preferably a replica, not the master)") + port := flag.Int("port", 3306, "MySQL port (preferably a replica, not the master)") + timeout := flag.Float64("mysql-timeout", 0.0, "Connect, read and write timeout for MySQL") 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)") - flag.Float64Var(&migrationContext.InspectorConnectionConfig.Timeout, "mysql-timeout", 0.0, "Connect, read and write timeout for MySQL") flag.StringVar(&migrationContext.CliUser, "user", "", "MySQL user") flag.StringVar(&migrationContext.CliPassword, "password", "", "MySQL password") flag.StringVar(&migrationContext.CliMasterUser, "master-user", "", "MySQL user on master, if different from that on replica. Requires --assume-master-host") @@ -183,6 +183,10 @@ func main() { migrationContext.Log.SetLevel(log.ERROR) } + if err := migrationContext.SetConnectionConfig(*storageEngine, *host, *port, *timeout); err != nil { + migrationContext.Log.Fatale(err) + } + if migrationContext.AlterStatement == "" { log.Fatal("--alter must be provided and statement must not be empty") } @@ -249,10 +253,6 @@ func main() { migrationContext.Log.Warning("--replication-lag-query is deprecated") } - if err := migrationContext.SetConnectionConfig(*storageEngine); err != nil { - migrationContext.Log.Fatale(err) - } - switch *cutOver { case "atomic", "default", "": migrationContext.CutOverType = base.CutOverAtomic diff --git a/go/mysql/connection.go b/go/mysql/connection.go index dcf33ad..15d7cb0 100644 --- a/go/mysql/connection.go +++ b/go/mysql/connection.go @@ -18,23 +18,23 @@ import ( ) const ( - TLS_CONFIG_KEY = "ghost" + TLS_CONFIG_KEY = "ghost" ) // ConnectionConfig is the minimal configuration required to connect to a MySQL server type ConnectionConfig struct { - Key InstanceKey - User string - Password string - ImpliedKey *InstanceKey - tlsConfig *tls.Config - Timeout float64 + Key InstanceKey + User string + Password string + ImpliedKey *InstanceKey + tlsConfig *tls.Config + Timeout float64 transactionIsolation string } func NewConnectionConfig(transactionIsolation string) *ConnectionConfig { config := &ConnectionConfig{ - Key: InstanceKey{}, + Key: InstanceKey{}, transactionIsolation: transactionIsolation, } config.ImpliedKey = &config.Key diff --git a/go/mysql/connection_test.go b/go/mysql/connection_test.go index 2f39c4f..e8cdc27 100644 --- a/go/mysql/connection_test.go +++ b/go/mysql/connection_test.go @@ -17,7 +17,6 @@ const ( transactionIsolation = "REPEATABLE-READ" ) - func init() { log.SetLevel(log.ERROR) }