diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 3e6057995..39c815bc8 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -51,6 +51,7 @@ func main() { 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.Float64Var(&migrationContext.InspectorConnectionConfig.WaitTimeout, "mysql-wait-timeout", 0.0, "wait_timeout for MySQL sessions") 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") diff --git a/go/mysql/connection.go b/go/mysql/connection.go index 33bde2b62..7db51afe4 100644 --- a/go/mysql/connection.go +++ b/go/mysql/connection.go @@ -31,6 +31,7 @@ type ConnectionConfig struct { Timeout float64 TransactionIsolation string Charset string + WaitTimeout float64 } func NewConnectionConfig() *ConnectionConfig { @@ -51,6 +52,7 @@ func (this *ConnectionConfig) DuplicateCredentials(key InstanceKey) *ConnectionC Timeout: this.Timeout, TransactionIsolation: this.TransactionIsolation, Charset: this.Charset, + WaitTimeout: this.WaitTimeout, } config.ImpliedKey = &config.Key return config @@ -139,6 +141,9 @@ func (this *ConnectionConfig) GetDBUri(databaseName string) string { fmt.Sprintf("readTimeout=%fs", this.Timeout), fmt.Sprintf("writeTimeout=%fs", this.Timeout), } + if this.WaitTimeout > 0 { + connectionParams = append(connectionParams, fmt.Sprintf("wait_timeout=%fs", this.WaitTimeout)) + } return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s", this.User, this.Password, hostname, this.Key.Port, databaseName, strings.Join(connectionParams, "&")) } diff --git a/go/mysql/connection_test.go b/go/mysql/connection_test.go index cc2271f1d..6398e0169 100644 --- a/go/mysql/connection_test.go +++ b/go/mysql/connection_test.go @@ -82,6 +82,7 @@ func TestGetDBUri(t *testing.T) { c.User = "gromit" c.Password = "penguin" c.Timeout = 1.2345 + c.WaitTimeout = 0 // should be ignored c.TransactionIsolation = transactionIsolation c.Charset = "utf8mb4,utf8,latin1" @@ -95,10 +96,11 @@ func TestGetDBUriWithTLSSetup(t *testing.T) { c.User = "gromit" c.Password = "penguin" c.Timeout = 1.2345 + c.WaitTimeout = 60 c.tlsConfig = &tls.Config{} c.TransactionIsolation = transactionIsolation c.Charset = "utf8mb4_general_ci,utf8_general_ci,latin1" uri := c.GetDBUri("test") - test.S(t).ExpectEquals(uri, `gromit:penguin@tcp(myhost:3306)/test?autocommit=true&interpolateParams=true&charset=utf8mb4_general_ci,utf8_general_ci,latin1&tls=ghost&transaction_isolation="REPEATABLE-READ"&timeout=1.234500s&readTimeout=1.234500s&writeTimeout=1.234500s`) + test.S(t).ExpectEquals(uri, `gromit:penguin@tcp(myhost:3306)/test?autocommit=true&interpolateParams=true&charset=utf8mb4_general_ci,utf8_general_ci,latin1&tls=ghost&transaction_isolation="REPEATABLE-READ"&timeout=1.234500s&readTimeout=1.234500s&writeTimeout=1.234500s&wait_timeout=60.000000s`) }