Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

fix bug : concurrency error is modified by other goroutines #1013

Merged
merged 2 commits into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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