Simplify GoMySQLReader

This commit is contained in:
Nikhil Mathew 2017-08-08 13:41:46 -07:00
parent 982b8eede9
commit b399533d4f
2 changed files with 8 additions and 10 deletions

View File

@ -26,28 +26,26 @@ type GoMySQLReader struct {
currentCoordinates mysql.BinlogCoordinates currentCoordinates mysql.BinlogCoordinates
currentCoordinatesMutex *sync.Mutex currentCoordinatesMutex *sync.Mutex
LastAppliedRowsEventHint mysql.BinlogCoordinates LastAppliedRowsEventHint mysql.BinlogCoordinates
MigrationContext *base.MigrationContext
} }
func NewGoMySQLReader(migrationContext *base.MigrationContext, connectionConfig *mysql.ConnectionConfig) (binlogReader *GoMySQLReader, err error) { func NewGoMySQLReader(migrationContext *base.MigrationContext) (binlogReader *GoMySQLReader, err error) {
binlogReader = &GoMySQLReader{ binlogReader = &GoMySQLReader{
connectionConfig: connectionConfig, connectionConfig: migrationContext.InspectorConnectionConfig,
currentCoordinates: mysql.BinlogCoordinates{}, currentCoordinates: mysql.BinlogCoordinates{},
currentCoordinatesMutex: &sync.Mutex{}, currentCoordinatesMutex: &sync.Mutex{},
binlogSyncer: nil, binlogSyncer: nil,
binlogStreamer: nil, binlogStreamer: nil,
MigrationContext: migrationContext,
} }
serverId := uint32(binlogReader.MigrationContext.ReplicaServerId) serverId := uint32(migrationContext.ReplicaServerId)
binlogSyncerConfig := &replication.BinlogSyncerConfig{ binlogSyncerConfig := &replication.BinlogSyncerConfig{
ServerID: serverId, ServerID: serverId,
Flavor: "mysql", Flavor: "mysql",
Host: connectionConfig.Key.Hostname, Host: binlogReader.connectionConfig.Key.Hostname,
Port: uint16(connectionConfig.Key.Port), Port: uint16(binlogReader.connectionConfig.Key.Port),
User: connectionConfig.User, User: binlogReader.connectionConfig.User,
Password: connectionConfig.Password, Password: binlogReader.connectionConfig.Password,
} }
binlogReader.binlogSyncer = replication.NewBinlogSyncer(binlogSyncerConfig) binlogReader.binlogSyncer = replication.NewBinlogSyncer(binlogSyncerConfig)

View File

@ -122,7 +122,7 @@ func (this *EventsStreamer) InitDBConnections() (err error) {
// initBinlogReader creates and connects the reader: we hook up to a MySQL server as a replica // initBinlogReader creates and connects the reader: we hook up to a MySQL server as a replica
func (this *EventsStreamer) initBinlogReader(binlogCoordinates *mysql.BinlogCoordinates) error { func (this *EventsStreamer) initBinlogReader(binlogCoordinates *mysql.BinlogCoordinates) error {
goMySQLReader, err := binlog.NewGoMySQLReader(this.migrationContext, this.migrationContext.InspectorConnectionConfig) goMySQLReader, err := binlog.NewGoMySQLReader(this.migrationContext)
if err != nil { if err != nil {
return err return err
} }