Skip to content

Commit

Permalink
Merge 09f09ad into bdac542
Browse files Browse the repository at this point in the history
  • Loading branch information
srstack authored May 19, 2022
2 parents bdac542 + 09f09ad commit ddee7dd
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 @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit ddee7dd

Please sign in to comment.