From ef04fa49f5ba4e5a1f46a4f6ea6779e6d6cf77f6 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 6 Oct 2016 12:00:34 +0200 Subject: [PATCH 1/3] assume-master-host now applied ImpliedKey --- go/logic/migrator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 2ac4c37..32466d2 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -624,6 +624,7 @@ func (this *Migrator) initiateInspector() (err error) { return err } else { this.migrationContext.ApplierConnectionConfig.Key = *key + this.migrationContext.ApplierConnectionConfig.ImpliedKey = key } } if this.migrationContext.TestOnReplica || this.migrationContext.MigrateOnReplica { From c1a6773c029b8eab6a493633ab8c12850bdfd872 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 11 Oct 2016 16:42:19 +0200 Subject: [PATCH 2/3] better handling of --assume-master-host separated logic and not even attempting to crawl topology --- go/logic/migrator.go | 24 +++++++++------- go/mysql/connection.go | 12 ++++---- go/mysql/connection_test.go | 57 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 go/mysql/connection_test.go diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 32466d2..7c96871 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -616,17 +616,22 @@ func (this *Migrator) initiateInspector() (err error) { } // So far so good, table is accessible and valid. // Let's get master connection config - if this.migrationContext.ApplierConnectionConfig, err = this.inspector.getMasterConnectionConfig(); err != nil { - return err - } - if this.migrationContext.AssumeMasterHostname != "" { - if key, err := mysql.ParseRawInstanceKeyLoose(this.migrationContext.AssumeMasterHostname); err != nil { + if this.migrationContext.AssumeMasterHostname == "" { + // No forced master host; detect master + if this.migrationContext.ApplierConnectionConfig, err = this.inspector.getMasterConnectionConfig(); err != nil { return err - } else { - this.migrationContext.ApplierConnectionConfig.Key = *key - this.migrationContext.ApplierConnectionConfig.ImpliedKey = key } + log.Infof("Master found to be %+v", *this.migrationContext.ApplierConnectionConfig.ImpliedKey) + } else { + // 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.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") @@ -639,13 +644,12 @@ func (this *Migrator) initiateInspector() (err error) { this.migrationContext.AddThrottleControlReplicaKey(this.migrationContext.InspectorConnectionConfig.Key) } } 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 { return err } - log.Infof("Master found to be %+v", *this.migrationContext.ApplierConnectionConfig.ImpliedKey) return nil } diff --git a/go/mysql/connection.go b/go/mysql/connection.go index 649da93..daae75e 100644 --- a/go/mysql/connection.go +++ b/go/mysql/connection.go @@ -26,12 +26,10 @@ func NewConnectionConfig() *ConnectionConfig { 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{ - Key: InstanceKey{ - Hostname: this.Key.Hostname, - Port: this.Key.Port, - }, + Key: key, User: this.User, Password: this.Password, } @@ -39,6 +37,10 @@ func (this *ConnectionConfig) Duplicate() *ConnectionConfig { return config } +func (this *ConnectionConfig) Duplicate() *ConnectionConfig { + return this.DuplicateCredentials(this.Key) +} + func (this *ConnectionConfig) String() string { return fmt.Sprintf("%s, user=%s", this.Key.DisplayString(), this.User) } diff --git a/go/mysql/connection_test.go b/go/mysql/connection_test.go new file mode 100644 index 0000000..657feb0 --- /dev/null +++ b/go/mysql/connection_test.go @@ -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") +} From c2801978219a4d9b44ac6835701b36221f5503ed Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 11 Oct 2016 20:29:56 +0200 Subject: [PATCH 3/3] updated version --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 8b09426..3b8dc4b 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ # # -RELEASE_VERSION="1.0.20" +RELEASE_VERSION="1.0.21" function build { osname=$1