SetConnectionConfig

This commit is contained in:
lukelewang 2022-11-25 18:48:48 +08:00
parent 3ee667a40e
commit 9c7857bd46
4 changed files with 19 additions and 17 deletions

View File

@ -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" transactionIsolation := "REPEATABLE-READ"
switch storageEngine { switch storageEngine {
case "rocksdb": case "rocksdb":
@ -299,6 +299,9 @@ func (this *MigrationContext) SetConnectionConfig(storageEngine string) error {
transactionIsolation = "REPEATABLE-READ" transactionIsolation = "REPEATABLE-READ"
} }
this.InspectorConnectionConfig = mysql.NewConnectionConfig(transactionIsolation) this.InspectorConnectionConfig = mysql.NewConnectionConfig(transactionIsolation)
this.InspectorConnectionConfig.Key.Hostname = host
this.InspectorConnectionConfig.Key.Port = port
this.InspectorConnectionConfig.Timeout = timeout
this.ApplierConnectionConfig = mysql.NewConnectionConfig(transactionIsolation) this.ApplierConnectionConfig = mysql.NewConnectionConfig(transactionIsolation)
return nil return nil
} }

View File

@ -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. // main is the application's entry point. It will either spawn a CLI or HTTP interfaces.
func main() { func main() {
migrationContext := base.NewMigrationContext() 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.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.CliUser, "user", "", "MySQL user")
flag.StringVar(&migrationContext.CliPassword, "password", "", "MySQL password") 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") 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) migrationContext.Log.SetLevel(log.ERROR)
} }
if err := migrationContext.SetConnectionConfig(*storageEngine, *host, *port, *timeout); err != nil {
migrationContext.Log.Fatale(err)
}
if migrationContext.AlterStatement == "" { if migrationContext.AlterStatement == "" {
log.Fatal("--alter must be provided and statement must not be empty") 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") migrationContext.Log.Warning("--replication-lag-query is deprecated")
} }
if err := migrationContext.SetConnectionConfig(*storageEngine); err != nil {
migrationContext.Log.Fatale(err)
}
switch *cutOver { switch *cutOver {
case "atomic", "default", "": case "atomic", "default", "":
migrationContext.CutOverType = base.CutOverAtomic migrationContext.CutOverType = base.CutOverAtomic

View File

@ -18,23 +18,23 @@ import (
) )
const ( const (
TLS_CONFIG_KEY = "ghost" TLS_CONFIG_KEY = "ghost"
) )
// ConnectionConfig is the minimal configuration required to connect to a MySQL server // ConnectionConfig is the minimal configuration required to connect to a MySQL server
type ConnectionConfig struct { type ConnectionConfig struct {
Key InstanceKey Key InstanceKey
User string User string
Password string Password string
ImpliedKey *InstanceKey ImpliedKey *InstanceKey
tlsConfig *tls.Config tlsConfig *tls.Config
Timeout float64 Timeout float64
transactionIsolation string transactionIsolation string
} }
func NewConnectionConfig(transactionIsolation string) *ConnectionConfig { func NewConnectionConfig(transactionIsolation string) *ConnectionConfig {
config := &ConnectionConfig{ config := &ConnectionConfig{
Key: InstanceKey{}, Key: InstanceKey{},
transactionIsolation: transactionIsolation, transactionIsolation: transactionIsolation,
} }
config.ImpliedKey = &config.Key config.ImpliedKey = &config.Key

View File

@ -17,7 +17,6 @@ const (
transactionIsolation = "REPEATABLE-READ" transactionIsolation = "REPEATABLE-READ"
) )
func init() { func init() {
log.SetLevel(log.ERROR) log.SetLevel(log.ERROR)
} }