Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: fix display exception #1889

Merged
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
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