Skip to content

Commit

Permalink
add cluster version check
Browse files Browse the repository at this point in the history
Signed-off-by: pingyu <[email protected]>
  • Loading branch information
pingyu committed Sep 14, 2022
1 parent 2a4f063 commit 5304c07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/cluster/spec/tikv_cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import (
"path/filepath"
"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"
logprinter "github.com/pingcap/tiup/pkg/logger/printer"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/tidbver"
)

// TiKVCDCSpec represents the TiKVCDC topology specification in topology.yaml
Expand Down Expand Up @@ -121,7 +123,7 @@ func (c *TiKVCDCComponent) Instances() []Instance {
return ins
}

// TiKVCDCInstance represent the CDC instance.
// TiKVCDCInstance represent the TiKV-CDC instance.
type TiKVCDCInstance struct {
BaseInstance
topo Topology
Expand Down Expand Up @@ -155,6 +157,10 @@ func (i *TiKVCDCInstance) InitConfig(
deployUser string,
paths meta.DirPaths,
) error {
if !tidbver.TiKVCDCSupportDeploy(clusterVersion) {
return errors.New("tikv-cdc only supports cluster version v6.2.0 or later")
}

topo := i.topo.(*Specification)
if err := i.BaseInstance.InitConfig(ctx, e, topo.GlobalOptions, deployUser, paths); err != nil {
return err
Expand Down Expand Up @@ -203,7 +209,7 @@ func (i *TiKVCDCInstance) setTLSConfig(ctx context.Context, enableTLS bool, conf

var _ RollingUpdateInstance = &TiKVCDCInstance{}

// GetAddr return the address of this TiCDC instance
// GetAddr return the address of this TiKV-CDC instance
func (i *TiKVCDCInstance) GetAddr() string {
return fmt.Sprintf("%s:%d", i.GetHost(), i.GetPort())
}
Expand All @@ -224,7 +230,7 @@ func (i *TiKVCDCInstance) PreRestart(ctx context.Context, topo Topology, apiTime
address := i.GetAddr()
// cdc rolling upgrade strategy only works if there are more than 2 captures
if len(tidbTopo.TiKVCDCServers) <= 1 {
logger.Debugf("TiKV-CDC pre-restart skipped, only one capture in the topology, addr: %s", address)
logger.Debugf("tikv-cdc pre-restart skipped, only one capture in the topology, addr: %s", address)
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/tidbver/tidbver.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ func DMSupportDeploy(version string) bool {
// tiup-dm only support version not less than v2.0
return semver.Compare(version, "v2.0.0") >= 0 || strings.Contains(version, "nightly")
}

// TiKVCDCSupportDeploy return if given version of TiDB/TiKV cluster is supported
func TiKVCDCSupportDeploy(version string) bool {
// TiKV-CDC only support TiKV version not less than v6.2.0
return semver.Compare(version, "v6.2.0") >= 0 || strings.Contains(version, "nightly")
}
5 changes: 5 additions & 0 deletions tests/tiup-cluster/script/tikv_cdc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function tikv_cdc_test() {
ssh-add /root/.ssh/id_rsa

tiup-cluster check $topo --apply

# Test check version. Cluster version >= v6.2.0 is required.
# Error message: "Error: init config failed: n3:8600: tikv-cdc only supports cluster version v6.2.0 or later"
! tiup-cluster --yes deploy $name 6.1.0 $topo

tiup-cluster --yes deploy $name $version $topo

# check the local config
Expand Down

0 comments on commit 5304c07

Please sign in to comment.