Skip to content

Commit

Permalink
fix bug : concurrency error is modified by other goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
fengve authored Nov 11, 2019
1 parent c5621ba commit a9d69c4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions go/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
isMaxScale := false
isMaxScale110 := false
slaveStatusFound := false
errorChan := make(chan error, 32)
var resolveErr error

if !instanceKey.IsValid() {
Expand Down Expand Up @@ -361,7 +362,7 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
defer waitGroup.Done()
var dummy string
// show global status works just as well with 5.6 & 5.7 (5.7 moves variables to performance_schema)
err = db.QueryRow("show global status like 'Uptime'").Scan(&dummy, &instance.Uptime)
err := db.QueryRow("show global status like 'Uptime'").Scan(&dummy, &instance.Uptime)

if err != nil {
logReadTopologyInstanceError(instanceKey, "show global status like 'Uptime'", err)
Expand All @@ -373,6 +374,7 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
// so as to completely fail reading a 5.7 instance.
// This is supposed to be fixed in 5.7.9
}
errorChan <- err
}()
}

Expand Down Expand Up @@ -402,27 +404,29 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
err = sqlutils.QueryRowsMap(db, "show master status", func(m sqlutils.RowMap) error {
err := sqlutils.QueryRowsMap(db, "show master status", func(m sqlutils.RowMap) error {
var err error
instance.SelfBinlogCoordinates.LogFile = m.GetString("File")
instance.SelfBinlogCoordinates.LogPos = m.GetInt64("Position")
return err
})
errorChan <- err
}()
}

{
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
err = sqlutils.QueryRowsMap(db, "show global status like 'rpl_semi_sync_%_status'", func(m sqlutils.RowMap) error {
err := sqlutils.QueryRowsMap(db, "show global status like 'rpl_semi_sync_%_status'", func(m sqlutils.RowMap) error {
if m.GetString("Variable_name") == "Rpl_semi_sync_master_status" {
instance.SemiSyncMasterEnabled = (m.GetString("Value") == "ON")
} else if m.GetString("Variable_name") == "Rpl_semi_sync_slave_status" {
instance.SemiSyncReplicaEnabled = (m.GetString("Value") == "ON")
}
return nil
})
errorChan <- err
}()
}
if (instance.IsOracleMySQL() || instance.IsPercona()) && !instance.IsSmallerMajorVersionByString("5.6") {
Expand Down Expand Up @@ -806,6 +810,19 @@ func ReadTopologyInstanceBufferable(instanceKey *InstanceKey, bufferWrites bool,

Cleanup:
waitGroup.Wait()
close(errorChan)
err = func() error {
if err != nil {
return err
}

for err := range errorChan {
if err != nil {
return err
}
}
return nil
}()

if instanceFound {
if instance.IsCoMaster {
Expand Down

0 comments on commit a9d69c4

Please sign in to comment.