Skip to content

Commit

Permalink
opti display tip
Browse files Browse the repository at this point in the history
  • Loading branch information
wentaojin committed Sep 6, 2024
1 parent 638f283 commit 98e481f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion component/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (a *AppDisplay) Display(dOpt *manager.DisplayOption, gOpt *operator.Options
if v.ComponentName != cluster.ComponentDBMSMaster {
continue
}
if strings.HasPrefix(v.Status, "Up") || strings.HasPrefix(v.Status, "Healthy") {
if strings.HasPrefix(v.Status, "NotReady") || strings.HasPrefix(v.Status, "Healthy") {
instAddr := stringutil.JoinHostPort(v.ManageHost, v.Port)
masterActive = append(masterActive, instAddr)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/cluster/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ type BaseInstance struct {
OSVersion string
OSArch string

StatusFn func(ctx context.Context, tlsCfg *tls.Config, pdHosts ...string) (string, error)
StatusFn func(ctx context.Context, tlsCfg *tls.Config, masterAddrs ...string) (string, error)

Config map[string]any
Component Component
Expand Down
14 changes: 7 additions & 7 deletions utils/cluster/manager/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *Controller) GetClusterTopology(dopt *DisplayOption, opt *operator.Optio
}

if len(masterList) == 0 {
return nil, nil, fmt.Errorf("the dbms-matser addr can't be zero, the dbms-cluster topology: [%v]", topo.String())
return nil, nil, fmt.Errorf("the dbms-cluster master instance can't be zero, the dbms-cluster topology: [%v]", topo.String())
}

client, err := etcdutil.CreateClient(context.TODO(), masterList, nil)
Expand Down Expand Up @@ -141,7 +141,7 @@ func (c *Controller) GetClusterTopology(dopt *DisplayOption, opt *operator.Optio

status, err := ins.Status(ctx, nil, masterList...)
if err != nil {
c.Logger.Errorf("get instance %s status failed: %v", ins.InstanceName(), err)
c.Logger.Errorf("the dbms-cluster get master instance %s status failed: %v", ins.InstanceName(), err)
masterStatus[ins.InstanceName()] = status
return
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func (c *Controller) GetClusterTopology(dopt *DisplayOption, opt *operator.Optio
default:
status, err = ins.Status(ctx, nil, masterActive...)
if err != nil {
c.Logger.Errorf("get instance %s status failed: %v", ins.InstanceName(), err)
c.Logger.Errorf("the dbms-cluster get worker instance %s status failed: %v", ins.InstanceName(), err)
}
}

Expand Down Expand Up @@ -332,13 +332,13 @@ func FormatInstanceStatus(status string) string {
}

switch {
case startsWith("up|l", "healthy|l"): // up|l, up|l|ui, healthy|l
case startsWith("healthy|l"):
return color.GreenString(status)
case startsWith("up", "healthy", "free", "bound"):
case startsWith("healthy", "free", "bound"):
return color.GreenString(status)
case startsWith("down", "err", "inactive", "failed"): // down, down|ui
case startsWith("down", "err", "inactive", "failed"):
return color.RedString(status)
case startsWith("tombstone", "disconnected", "n/a", "stopped"), strings.Contains(strings.ToLower(status), "offline"):
case startsWith("notready", "disconnected", "n/a", "stopped"), strings.Contains(strings.ToLower(status), "offline"):
return color.YellowString(status)
default:
return status
Expand Down
24 changes: 12 additions & 12 deletions utils/cluster/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,31 @@ func (s *MasterOptions) InstanceName() string {
// Status queries current status of the instance
func (s *MasterOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error) {
if len(addrs) == 0 {
return "N/A", fmt.Errorf("the cluster master instance cannot be zero, please contact author or reselect")
return "N/A", fmt.Errorf("the dbms-cluster master instance cannot be zero, please contact author or reselect")
}
cli, err := etcdutil.CreateClient(ctx, addrs, tlsCfg)
if err != nil {
return "N/A", err
return "N/A", fmt.Errorf("the dbms-cluster create service client failed: [%v]", err)
}

keyResp, err := etcdutil.GetKey(cli, stringutil.StringBuilder(constant.DefaultInstanceServiceRegisterPrefixKey, fmt.Sprintf("%s:%d", s.Host, s.PeerPort)))
keyResp, err := etcdutil.GetKey(cli, stringutil.StringBuilder(constant.DefaultInstanceServiceRegisterPrefixKey, fmt.Sprintf("%s:%d", s.Host, s.Port)))
if err != nil {
return "N/A", err
return "N/A", fmt.Errorf("the dbms-cluster get master instance service key failed: [%v]", err)
}
if len(keyResp.Kvs) == 0 {
return "DOWN", nil
return "DOWN", fmt.Errorf("the dbms-cluster master instance [%s] service registe failed, please check and wait service normal", fmt.Sprintf("%s:%d", s.Host, s.Port))
} else if len(keyResp.Kvs) > 1 {
return "N/A", fmt.Errorf("the cluster instance member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", s.Host, s.Port))
return "N/A", fmt.Errorf("the dbms-cluster instance member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", s.Host, s.Port))
}

leaderResp, err := etcdutil.GetKey(cli, constant.DefaultMasterLeaderAddressKey)
if err != nil {
return "N/A", err
return "N/A", fmt.Errorf("the dbms-cluster get master leader addr key failed: [%v]", err)
}
if len(leaderResp.Kvs) == 0 {
return "N/A", nil
return "NotReady", fmt.Errorf("the dbms-cluster master leader election has not completed, the service is disabled, please wait server ready")
} else if len(leaderResp.Kvs) > 1 {
return "N/A", fmt.Errorf("the cluster leader are over than one, please contact author or reselect, detail: %v", leaderResp.Kvs)
return "N/A", fmt.Errorf("the dbms-cluster leader are over than one, please contact author or reselect, detail: %v", leaderResp.Kvs)
}

if strings.EqualFold(stringutil.BytesToString(leaderResp.Kvs[0].Value), fmt.Sprintf("%s:%d", s.Host, s.Port)) {
Expand Down Expand Up @@ -165,7 +165,7 @@ func (w *WorkerOptions) InstanceName() string {
// Status queries current status of the instance
func (w *WorkerOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error) {
if len(addrs) == 0 {
return "N/A", fmt.Errorf("the cluster master instance cannot be zero, please contact author or reselect")
return "N/A", fmt.Errorf("the dbms-cluster master instance cannot be zero, please contact author or reselect")
}
cli, err := etcdutil.CreateClient(ctx, addrs, tlsCfg)
if err != nil {
Expand All @@ -179,7 +179,7 @@ func (w *WorkerOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ..
if len(keyResp.Kvs) == 0 {
return "DOWN", nil
} else if len(keyResp.Kvs) > 1 {
return "N/A", fmt.Errorf("the cluster worker member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", w.Host, w.Port))
return "N/A", fmt.Errorf("the dbms-cluster worker member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", w.Host, w.Port))
}

var ws *etcdutil.Instance
Expand Down Expand Up @@ -263,7 +263,7 @@ func (t *Topology) FillHostArchOrOS(hostArch map[string]string, fullType FullHos
return nil
}

// CountDir counts for dir paths used by any instance in the cluster with the same
// CountDir counts for dir paths used by any instance in the dbms-cluster with the same
// prefix, useful to find potential path conflicts
func (t *Topology) CountDir(targetHost, dirPrefix string) int {
dirTypes := []string{
Expand Down

0 comments on commit 98e481f

Please sign in to comment.