Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed May 7, 2024
1 parent 42d1df3 commit 07d18cd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
24 changes: 24 additions & 0 deletions pkg/cluster/operation/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ func Upgrade(
logger.Debugf("Deferred upgrading of PD leader %s", instance.ID())
continue
}
case spec.ComponentTSO:
// defer TSO primary to be upgraded after others
isPrimary, err := instance.(*spec.TSOInstance).IsPrimary(ctx, topo, tlsCfg)
if err != nil {
logger.Warnf("cannot found TSO primary, ignore: %s", err)
return err
}
if isPrimary {
deferInstances = append(deferInstances, instance)
logger.Debugf("Deferred upgrading of TSO primary %s", instance.ID())
continue
}
case spec.ComponentScheduling:
// defer Scheduling primary to be upgraded after others
isPrimary, err := instance.(*spec.SchedulingInstance).IsPrimary(ctx, topo, tlsCfg)
if err != nil {
logger.Warnf("cannot found Scheduling primary, ignore: %s", err)
return err
}
if isPrimary {
deferInstances = append(deferInstances, instance)
logger.Debugf("Deferred upgrading of Scheduling primary %s", instance.ID())
continue
}
case spec.ComponentCDC:
ins := instance.(*spec.CDCInstance)
address := ins.GetAddr()
Expand Down
28 changes: 27 additions & 1 deletion pkg/cluster/spec/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (
"strings"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/cluster/ctxt"
"github.com/pingcap/tiup/pkg/cluster/template/scripts"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/utils"
)

var schedulingService = "scheduling"

// SchedulingSpec represents the scheduling topology specification in topology.yaml
type SchedulingSpec struct {
Host string `yaml:"host"`
Expand Down Expand Up @@ -63,7 +66,7 @@ func (s *SchedulingSpec) Status(ctx context.Context, timeout time.Duration, tlsC
return "Down"
}

primary, err := pc.GetServicePrimary("scheduling")
primary, err := pc.GetServicePrimary(schedulingService)
if err != nil {
return "ERR"
}
Expand Down Expand Up @@ -303,6 +306,29 @@ func (i *SchedulingInstance) setTLSConfig(ctx context.Context, enableTLS bool, c
return configs, nil
}

// IsPrimary checks if the instance is primary
func (i *SchedulingInstance) IsPrimary(ctx context.Context, topo Topology, tlsCfg *tls.Config) (bool, error) {
tidbTopo, ok := topo.(*Specification)
if !ok {
panic("topo should be type of tidb topology")
}
pdClient := api.NewPDClient(ctx, tidbTopo.GetPDListWithManageHost(), time.Second*5, tlsCfg)
primary, err := pdClient.GetServicePrimary(schedulingService)
if err != nil {
if err != nil {
return false, errors.Annotatef(err, "failed to get Scheduling primary %s", i.GetHost())
}
}

spec := i.InstanceSpec.(*SchedulingSpec)
enableTLS := false
if tlsCfg != nil {
enableTLS = true
}

return primary == spec.GetAdvertiseListenURL(enableTLS), nil
}

// ScaleConfig deploy temporary config on scaling
func (i *SchedulingInstance) ScaleConfig(
ctx context.Context,
Expand Down
28 changes: 27 additions & 1 deletion pkg/cluster/spec/tso.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (
"strings"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/cluster/ctxt"
"github.com/pingcap/tiup/pkg/cluster/template/scripts"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/utils"
)

var tsoService = "tso"

// TSOSpec represents the TSO topology specification in topology.yaml
type TSOSpec struct {
Host string `yaml:"host"`
Expand Down Expand Up @@ -63,7 +66,7 @@ func (s *TSOSpec) Status(ctx context.Context, timeout time.Duration, tlsCfg *tls
return "Down"
}

primary, err := pc.GetServicePrimary("tso")
primary, err := pc.GetServicePrimary(tsoService)
if err != nil {
return "ERR"
}
Expand Down Expand Up @@ -303,6 +306,29 @@ func (i *TSOInstance) setTLSConfig(ctx context.Context, enableTLS bool, configs
return configs, nil
}

// IsPrimary checks if the instance is primary
func (i *TSOInstance) IsPrimary(ctx context.Context, topo Topology, tlsCfg *tls.Config) (bool, error) {
tidbTopo, ok := topo.(*Specification)
if !ok {
panic("topo should be type of tidb topology")
}
pdClient := api.NewPDClient(ctx, tidbTopo.GetPDListWithManageHost(), time.Second*5, tlsCfg)
primary, err := pdClient.GetServicePrimary(tsoService)
if err != nil {
if err != nil {
return false, errors.Annotatef(err, "failed to get TSO primary %s", i.GetHost())
}
}

spec := i.InstanceSpec.(*TSOSpec)
enableTLS := false
if tlsCfg != nil {
enableTLS = true
}

return primary == spec.GetAdvertiseListenURL(enableTLS), nil
}

// ScaleConfig deploy temporary config on scaling
func (i *TSOInstance) ScaleConfig(
ctx context.Context,
Expand Down

0 comments on commit 07d18cd

Please sign in to comment.