Skip to content

Commit 62ce678

Browse files
Merge pull request #515 from akshaychhajed/improve-conn-log
Improved connection type logging
2 parents c681c54 + 048d583 commit 62ce678

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

go/base/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
gosql "database/sql"
16+
1617
"github.com/github/gh-ost/go/mysql"
1718
)
1819

@@ -62,7 +63,7 @@ func StringContainsAll(s string, substrings ...string) bool {
6263
return nonEmptyStringsFound
6364
}
6465

65-
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext) (string, error) {
66+
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string) (string, error) {
6667
versionQuery := `select @@global.version`
6768
var port, extraPort int
6869
var version string
@@ -86,7 +87,7 @@ func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig,
8687
}
8788

8889
if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) {
89-
migrationContext.Log.Infof("connection validated on %+v", connectionConfig.Key)
90+
migrationContext.Log.Infof("%s connection validated on %+v", name, connectionConfig.Key)
9091
return version, nil
9192
} else if extraPort == 0 {
9293
return "", fmt.Errorf("Unexpected database port reported: %+v", port)

go/logic/applier.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ type Applier struct {
5757
singletonDB *gosql.DB
5858
migrationContext *base.MigrationContext
5959
finishedMigrating int64
60+
name string
6061
}
6162

6263
func NewApplier(migrationContext *base.MigrationContext) *Applier {
6364
return &Applier{
6465
connectionConfig: migrationContext.ApplierConnectionConfig,
6566
migrationContext: migrationContext,
6667
finishedMigrating: 0,
68+
name: "applier",
6769
}
6870
}
6971

@@ -78,11 +80,11 @@ func (this *Applier) InitDBConnections() (err error) {
7880
return err
7981
}
8082
this.singletonDB.SetMaxOpenConns(1)
81-
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext)
83+
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext, this.name)
8284
if err != nil {
8385
return err
8486
}
85-
if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig, this.migrationContext); err != nil {
87+
if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig, this.migrationContext, this.name); err != nil {
8688
return err
8789
}
8890
this.migrationContext.ApplierMySQLVersion = version

go/logic/inspect.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ type Inspector struct {
2929
db *gosql.DB
3030
informationSchemaDb *gosql.DB
3131
migrationContext *base.MigrationContext
32+
name string
3233
}
3334

3435
func NewInspector(migrationContext *base.MigrationContext) *Inspector {
3536
return &Inspector{
3637
connectionConfig: migrationContext.InspectorConnectionConfig,
3738
migrationContext: migrationContext,
39+
name: "inspector",
3840
}
3941
}
4042

@@ -198,7 +200,7 @@ func (this *Inspector) validateConnection() error {
198200
return fmt.Errorf("MySQL replication length limited to 32 characters. See https://dev.mysql.com/doc/refman/5.7/en/assigning-passwords.html")
199201
}
200202

201-
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext)
203+
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext, this.name)
202204
this.migrationContext.InspectorMySQLVersion = version
203205
return err
204206
}

go/logic/streamer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type EventsStreamer struct {
4242
listenersMutex *sync.Mutex
4343
eventsChannel chan *binlog.BinlogEntry
4444
binlogReader *binlog.GoMySQLReader
45+
name string
4546
}
4647

4748
func NewEventsStreamer(migrationContext *base.MigrationContext) *EventsStreamer {
@@ -51,6 +52,7 @@ func NewEventsStreamer(migrationContext *base.MigrationContext) *EventsStreamer
5152
listeners: [](*BinlogEventListener){},
5253
listenersMutex: &sync.Mutex{},
5354
eventsChannel: make(chan *binlog.BinlogEntry, EventsChannelBufferSize),
55+
name: "streamer",
5456
}
5557
}
5658

@@ -106,7 +108,7 @@ func (this *EventsStreamer) InitDBConnections() (err error) {
106108
if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, EventsStreamerUri); err != nil {
107109
return err
108110
}
109-
if _, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext); err != nil {
111+
if _, err := base.ValidateConnection(this.db, this.connectionConfig, this.migrationContext, this.name); err != nil {
110112
return err
111113
}
112114
if err := this.readCurrentBinlogCoordinates(); err != nil {

0 commit comments

Comments
 (0)