From 09f09add583d346d2bba0a672d3f11cf1fd8924e Mon Sep 17 00:00:00 2001 From: srstack Date: Thu, 19 May 2022 14:35:49 +0800 Subject: [PATCH] fix display --- pkg/cluster/manager/display.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/cluster/manager/display.go b/pkg/cluster/manager/display.go index e8b72d3b48..0d29b95022 100644 --- a/pkg/cluster/manager/display.go +++ b/pkg/cluster/manager/display.go @@ -24,6 +24,7 @@ import ( "sort" "strconv" "strings" + "sync" "time" "github.com/fatih/color" @@ -362,12 +363,16 @@ func (m *Manager) DisplayTiKVLabels(name string, opt operator.Options) error { if err != nil { return err } + + var mu sync.Mutex topo.IterInstance(func(ins spec.Instance) { if ins.ComponentName() == spec.ComponentPD { status := ins.Status(ctx, statusTimeout, tlsCfg, masterList...) if strings.HasPrefix(status, "Up") || strings.HasPrefix(status, "Healthy") { instAddr := fmt.Sprintf("%s:%d", ins.GetHost(), ins.GetPort()) + mu.Lock() masterActive = append(masterActive, instAddr) + mu.Unlock() } } }, opt.Concurrency) @@ -482,6 +487,7 @@ func (m *Manager) GetClusterTopology(name string, opt operator.Options) ([]InstI masterActive := make([]string, 0) masterStatus := make(map[string]string) + var mu sync.Mutex topo.IterInstance(func(ins spec.Instance) { if ins.ComponentName() != spec.ComponentPD && ins.ComponentName() != spec.ComponentDMMaster { return @@ -490,7 +496,9 @@ func (m *Manager) GetClusterTopology(name string, opt operator.Options) ([]InstI status := ins.Status(ctx, statusTimeout, tlsCfg, masterList...) if strings.HasPrefix(status, "Up") || strings.HasPrefix(status, "Healthy") { instAddr := fmt.Sprintf("%s:%d", ins.GetHost(), ins.GetPort()) + mu.Lock() masterActive = append(masterActive, instAddr) + mu.Unlock() } masterStatus[ins.ID()] = status }, opt.Concurrency) @@ -564,6 +572,7 @@ func (m *Manager) GetClusterTopology(name string, opt operator.Options) ([]InstI if ins.IsPatched() { roleName += " (patched)" } + mu.Lock() clusterInstInfos = append(clusterInstInfos, InstInfo{ ID: ins.ID(), Role: roleName, @@ -577,6 +586,7 @@ func (m *Manager) GetClusterTopology(name string, opt operator.Options) ([]InstI Port: ins.GetPort(), Since: since, }) + mu.Unlock() }, opt.Concurrency) // Sort by role,host,ports