Skip to content

Commit

Permalink
cluster: fix display exception (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
srstack authored and AstroProfundis committed May 20, 2022
1 parent 2971b46 commit 4759c7f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/cluster/manager/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -342,12 +343,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)
Expand Down Expand Up @@ -462,6 +467,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
Expand All @@ -470,7 +476,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)
Expand Down Expand Up @@ -544,6 +552,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,
Expand All @@ -557,6 +566,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
Expand Down

0 comments on commit 4759c7f

Please sign in to comment.