@@ -13,13 +13,13 @@ import (
1313 "github.com/github/gh-ost/go/mysql"
1414 "github.com/github/gh-ost/go/sql"
1515
16- "github.com/outbrain/golib/log"
1716 gomysql "github.com/siddontang/go-mysql/mysql"
1817 "github.com/siddontang/go-mysql/replication"
1918 "golang.org/x/net/context"
2019)
2120
2221type GoMySQLReader struct {
22+ migrationContext * base.MigrationContext
2323 connectionConfig * mysql.ConnectionConfig
2424 binlogSyncer * replication.BinlogSyncer
2525 binlogStreamer * replication.BinlogStreamer
@@ -30,6 +30,7 @@ type GoMySQLReader struct {
3030
3131func NewGoMySQLReader (migrationContext * base.MigrationContext ) (binlogReader * GoMySQLReader , err error ) {
3232 binlogReader = & GoMySQLReader {
33+ migrationContext : migrationContext ,
3334 connectionConfig : migrationContext .InspectorConnectionConfig ,
3435 currentCoordinates : mysql.BinlogCoordinates {},
3536 currentCoordinatesMutex : & sync.Mutex {},
@@ -57,11 +58,11 @@ func NewGoMySQLReader(migrationContext *base.MigrationContext) (binlogReader *Go
5758// ConnectBinlogStreamer
5859func (this * GoMySQLReader ) ConnectBinlogStreamer (coordinates mysql.BinlogCoordinates ) (err error ) {
5960 if coordinates .IsEmpty () {
60- return log .Errorf ("Empty coordinates at ConnectBinlogStreamer()" )
61+ return this . migrationContext . Log .Errorf ("Empty coordinates at ConnectBinlogStreamer()" )
6162 }
6263
6364 this .currentCoordinates = coordinates
64- log .Infof ("Connecting binlog streamer at %+v" , this .currentCoordinates )
65+ this . migrationContext . Log .Infof ("Connecting binlog streamer at %+v" , this .currentCoordinates )
6566 // Start sync with specified binlog file and position
6667 this .binlogStreamer , err = this .binlogSyncer .StartSync (gomysql.Position {this .currentCoordinates .LogFile , uint32 (this .currentCoordinates .LogPos )})
6768
@@ -78,7 +79,7 @@ func (this *GoMySQLReader) GetCurrentBinlogCoordinates() *mysql.BinlogCoordinate
7879// StreamEvents
7980func (this * GoMySQLReader ) handleRowsEvent (ev * replication.BinlogEvent , rowsEvent * replication.RowsEvent , entriesChannel chan <- * BinlogEntry ) error {
8081 if this .currentCoordinates .SmallerThanOrEquals (& this .LastAppliedRowsEventHint ) {
81- log .Debugf ("Skipping handled query at %+v" , this .currentCoordinates )
82+ this . migrationContext . Log .Debugf ("Skipping handled query at %+v" , this .currentCoordinates )
8283 return nil
8384 }
8485
@@ -147,14 +148,14 @@ func (this *GoMySQLReader) StreamEvents(canStopStreaming func() bool, entriesCha
147148 defer this .currentCoordinatesMutex .Unlock ()
148149 this .currentCoordinates .LogFile = string (rotateEvent .NextLogName )
149150 }()
150- log .Infof ("rotate to next log from %s:%d to %s" , this .currentCoordinates .LogFile , int64 (ev .Header .LogPos ), rotateEvent .NextLogName )
151+ this . migrationContext . Log .Infof ("rotate to next log from %s:%d to %s" , this .currentCoordinates .LogFile , int64 (ev .Header .LogPos ), rotateEvent .NextLogName )
151152 } else if rowsEvent , ok := ev .Event .(* replication.RowsEvent ); ok {
152153 if err := this .handleRowsEvent (ev , rowsEvent , entriesChannel ); err != nil {
153154 return err
154155 }
155156 }
156157 }
157- log .Debugf ("done streaming events" )
158+ this . migrationContext . Log .Debugf ("done streaming events" )
158159
159160 return nil
160161}
0 commit comments