Skip to content

Commit ccb7654

Browse files
committed
Improved connection type logging
1 parent ca2340a commit ccb7654

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
"github.com/outbrain/golib/log"
1819
)
@@ -64,7 +65,7 @@ func StringContainsAll(s string, substrings ...string) bool {
6465
return nonEmptyStringsFound
6566
}
6667

67-
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig) (string, error) {
68+
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, name string) (string, error) {
6869
query := `select @@global.port, @@global.version`
6970
var port, extraPort int
7071
var version string
@@ -77,7 +78,7 @@ func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig)
7778
}
7879

7980
if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) {
80-
log.Infof("connection validated on %+v", connectionConfig.Key)
81+
log.Infof("%s connection validated on %+v", name, connectionConfig.Key)
8182
return version, nil
8283
} else if extraPort == 0 {
8384
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
@@ -34,12 +34,14 @@ type Applier struct {
3434
db *gosql.DB
3535
singletonDB *gosql.DB
3636
migrationContext *base.MigrationContext
37+
name string
3738
}
3839

3940
func NewApplier() *Applier {
4041
return &Applier{
4142
connectionConfig: base.GetMigrationContext().ApplierConnectionConfig,
4243
migrationContext: base.GetMigrationContext(),
44+
name: "applier",
4345
}
4446
}
4547

@@ -53,11 +55,11 @@ func (this *Applier) InitDBConnections() (err error) {
5355
return err
5456
}
5557
this.singletonDB.SetMaxOpenConns(1)
56-
version, err := base.ValidateConnection(this.db, this.connectionConfig)
58+
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.name)
5759
if err != nil {
5860
return err
5961
}
60-
if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig); err != nil {
62+
if _, err := base.ValidateConnection(this.singletonDB, this.connectionConfig, this.name); err != nil {
6163
return err
6264
}
6365
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
connectionConfig *mysql.ConnectionConfig
3030
db *gosql.DB
3131
migrationContext *base.MigrationContext
32+
name string
3233
}
3334

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

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

199-
version, err := base.ValidateConnection(this.db, this.connectionConfig)
201+
version, err := base.ValidateConnection(this.db, this.connectionConfig, this.name)
200202
this.migrationContext.InspectorMySQLVersion = version
201203
return err
202204
}

go/logic/streamer.go

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

4849
func NewEventsStreamer() *EventsStreamer {
@@ -52,6 +53,7 @@ func NewEventsStreamer() *EventsStreamer {
5253
listeners: [](*BinlogEventListener){},
5354
listenersMutex: &sync.Mutex{},
5455
eventsChannel: make(chan *binlog.BinlogEntry, EventsChannelBufferSize),
56+
name: "streamer",
5557
}
5658
}
5759

@@ -107,7 +109,7 @@ func (this *EventsStreamer) InitDBConnections() (err error) {
107109
if this.db, _, err = sqlutils.GetDB(EventsStreamerUri); err != nil {
108110
return err
109111
}
110-
if _, err := base.ValidateConnection(this.db, this.connectionConfig); err != nil {
112+
if _, err := base.ValidateConnection(this.db, this.connectionConfig, this.name); err != nil {
111113
return err
112114
}
113115
if err := this.readCurrentBinlogCoordinates(); err != nil {

0 commit comments

Comments
 (0)