Merge pull request #263 from github/implied-key-fix
assume-master-host now applies ImpliedKey
This commit is contained in:
commit
c399119139
@ -616,16 +616,22 @@ func (this *Migrator) initiateInspector() (err error) {
|
|||||||
}
|
}
|
||||||
// So far so good, table is accessible and valid.
|
// So far so good, table is accessible and valid.
|
||||||
// Let's get master connection config
|
// Let's get master connection config
|
||||||
|
if this.migrationContext.AssumeMasterHostname == "" {
|
||||||
|
// No forced master host; detect master
|
||||||
if this.migrationContext.ApplierConnectionConfig, err = this.inspector.getMasterConnectionConfig(); err != nil {
|
if this.migrationContext.ApplierConnectionConfig, err = this.inspector.getMasterConnectionConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if this.migrationContext.AssumeMasterHostname != "" {
|
log.Infof("Master found to be %+v", *this.migrationContext.ApplierConnectionConfig.ImpliedKey)
|
||||||
if key, err := mysql.ParseRawInstanceKeyLoose(this.migrationContext.AssumeMasterHostname); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
} else {
|
||||||
this.migrationContext.ApplierConnectionConfig.Key = *key
|
// Forced master host.
|
||||||
|
key, err := mysql.ParseRawInstanceKeyLoose(this.migrationContext.AssumeMasterHostname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
this.migrationContext.ApplierConnectionConfig = this.migrationContext.InspectorConnectionConfig.DuplicateCredentials(*key)
|
||||||
|
log.Infof("Master forced to be %+v", *this.migrationContext.ApplierConnectionConfig.ImpliedKey)
|
||||||
}
|
}
|
||||||
|
// validate configs
|
||||||
if this.migrationContext.TestOnReplica || this.migrationContext.MigrateOnReplica {
|
if this.migrationContext.TestOnReplica || this.migrationContext.MigrateOnReplica {
|
||||||
if this.migrationContext.InspectorIsAlsoApplier() {
|
if this.migrationContext.InspectorIsAlsoApplier() {
|
||||||
return fmt.Errorf("Instructed to --test-on-replica or --migrate-on-replica, but the server we connect to doesn't seem to be a replica")
|
return fmt.Errorf("Instructed to --test-on-replica or --migrate-on-replica, but the server we connect to doesn't seem to be a replica")
|
||||||
@ -638,13 +644,12 @@ func (this *Migrator) initiateInspector() (err error) {
|
|||||||
this.migrationContext.AddThrottleControlReplicaKey(this.migrationContext.InspectorConnectionConfig.Key)
|
this.migrationContext.AddThrottleControlReplicaKey(this.migrationContext.InspectorConnectionConfig.Key)
|
||||||
}
|
}
|
||||||
} else if this.migrationContext.InspectorIsAlsoApplier() && !this.migrationContext.AllowedRunningOnMaster {
|
} else if this.migrationContext.InspectorIsAlsoApplier() && !this.migrationContext.AllowedRunningOnMaster {
|
||||||
return fmt.Errorf("It seems like this migration attempt to run directly on master. Preferably it would be executed on a replica (and this reduces load from the master). To proceed please provide --allow-on-master")
|
return fmt.Errorf("It seems like this migration attempt to run directly on master. Preferably it would be executed on a replica (and this reduces load from the master). To proceed please provide --allow-on-master. Inspector config=%+v, applier config=%+v", this.migrationContext.InspectorConnectionConfig, this.migrationContext.ApplierConnectionConfig)
|
||||||
}
|
}
|
||||||
if err := this.inspector.validateLogSlaveUpdates(); err != nil {
|
if err := this.inspector.validateLogSlaveUpdates(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Master found to be %+v", *this.migrationContext.ApplierConnectionConfig.ImpliedKey)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +26,10 @@ func NewConnectionConfig() *ConnectionConfig {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ConnectionConfig) Duplicate() *ConnectionConfig {
|
// DuplicateCredentials creates a new connection config with given key and with same credentials as this config
|
||||||
|
func (this *ConnectionConfig) DuplicateCredentials(key InstanceKey) *ConnectionConfig {
|
||||||
config := &ConnectionConfig{
|
config := &ConnectionConfig{
|
||||||
Key: InstanceKey{
|
Key: key,
|
||||||
Hostname: this.Key.Hostname,
|
|
||||||
Port: this.Key.Port,
|
|
||||||
},
|
|
||||||
User: this.User,
|
User: this.User,
|
||||||
Password: this.Password,
|
Password: this.Password,
|
||||||
}
|
}
|
||||||
@ -39,6 +37,10 @@ func (this *ConnectionConfig) Duplicate() *ConnectionConfig {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ConnectionConfig) Duplicate() *ConnectionConfig {
|
||||||
|
return this.DuplicateCredentials(this.Key)
|
||||||
|
}
|
||||||
|
|
||||||
func (this *ConnectionConfig) String() string {
|
func (this *ConnectionConfig) String() string {
|
||||||
return fmt.Sprintf("%s, user=%s", this.Key.DisplayString(), this.User)
|
return fmt.Sprintf("%s, user=%s", this.Key.DisplayString(), this.User)
|
||||||
}
|
}
|
||||||
|
57
go/mysql/connection_test.go
Normal file
57
go/mysql/connection_test.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2016 GitHub Inc.
|
||||||
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mysql
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/outbrain/golib/log"
|
||||||
|
test "github.com/outbrain/golib/tests"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetLevel(log.ERROR)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewConnectionConfig(t *testing.T) {
|
||||||
|
c := NewConnectionConfig()
|
||||||
|
test.S(t).ExpectEquals(c.Key.Hostname, "")
|
||||||
|
test.S(t).ExpectEquals(c.Key.Port, 0)
|
||||||
|
test.S(t).ExpectEquals(c.ImpliedKey.Hostname, "")
|
||||||
|
test.S(t).ExpectEquals(c.ImpliedKey.Port, 0)
|
||||||
|
test.S(t).ExpectEquals(c.User, "")
|
||||||
|
test.S(t).ExpectEquals(c.Password, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDuplicateCredentials(t *testing.T) {
|
||||||
|
c := NewConnectionConfig()
|
||||||
|
c.Key = InstanceKey{Hostname: "myhost", Port: 3306}
|
||||||
|
c.User = "gromit"
|
||||||
|
c.Password = "penguin"
|
||||||
|
|
||||||
|
dup := c.DuplicateCredentials(InstanceKey{Hostname: "otherhost", Port: 3310})
|
||||||
|
test.S(t).ExpectEquals(dup.Key.Hostname, "otherhost")
|
||||||
|
test.S(t).ExpectEquals(dup.Key.Port, 3310)
|
||||||
|
test.S(t).ExpectEquals(dup.ImpliedKey.Hostname, "otherhost")
|
||||||
|
test.S(t).ExpectEquals(dup.ImpliedKey.Port, 3310)
|
||||||
|
test.S(t).ExpectEquals(dup.User, "gromit")
|
||||||
|
test.S(t).ExpectEquals(dup.Password, "penguin")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDuplicate(t *testing.T) {
|
||||||
|
c := NewConnectionConfig()
|
||||||
|
c.Key = InstanceKey{Hostname: "myhost", Port: 3306}
|
||||||
|
c.User = "gromit"
|
||||||
|
c.Password = "penguin"
|
||||||
|
|
||||||
|
dup := c.Duplicate()
|
||||||
|
test.S(t).ExpectEquals(dup.Key.Hostname, "myhost")
|
||||||
|
test.S(t).ExpectEquals(dup.Key.Port, 3306)
|
||||||
|
test.S(t).ExpectEquals(dup.ImpliedKey.Hostname, "myhost")
|
||||||
|
test.S(t).ExpectEquals(dup.ImpliedKey.Port, 3306)
|
||||||
|
test.S(t).ExpectEquals(dup.User, "gromit")
|
||||||
|
test.S(t).ExpectEquals(dup.Password, "penguin")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user