SetConnectionConfig
This commit is contained in:
parent
3ee667a40e
commit
9c7857bd46
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -17,7 +17,6 @@ const (
|
||||
transactionIsolation = "REPEATABLE-READ"
|
||||
)
|
||||
|
||||
|
||||
func init() {
|
||||
log.SetLevel(log.ERROR)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user