diff --git a/components/dm/command/deploy.go b/components/dm/command/deploy.go index 4e7a165c38..2343419b94 100644 --- a/components/dm/command/deploy.go +++ b/components/dm/command/deploy.go @@ -22,10 +22,10 @@ import ( operator "github.com/pingcap/tiup/pkg/cluster/operation" "github.com/pingcap/tiup/pkg/cluster/spec" "github.com/pingcap/tiup/pkg/cluster/task" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/tui" "github.com/pingcap/tiup/pkg/utils" "github.com/spf13/cobra" - "golang.org/x/mod/semver" ) func newDeployCmd() *cobra.Command { @@ -69,12 +69,7 @@ func newDeployCmd() *cobra.Command { } func supportVersion(vs string) error { - if !semver.IsValid(vs) { - return nil - } - - majorMinor := semver.MajorMinor(vs) - if semver.Compare(majorMinor, "v2.0") < 0 { + if !tidbver.DMSupportDeploy(vs) { return errors.Errorf("Only support version not less than v2.0") } diff --git a/components/dm/command/deploy_test.go b/components/dm/command/deploy_test.go index 82399c9fab..502bdd4621 100644 --- a/components/dm/command/deploy_test.go +++ b/components/dm/command/deploy_test.go @@ -10,12 +10,10 @@ func TestSupportVersion(t *testing.T) { assert := require.New(t) tests := map[string]bool{ // version to support or not - "v2.0.0": true, - "v3.0.0": true, - "v2.0.0-beta.1": true, - "v2.0.0-alpha": true, - "v1.0.1": false, - "v1.1.1": false, + "v2.0.0": true, + "v6.0.0": true, + "v1.0.1": false, + "v1.1.1": false, } for v, support := range tests { diff --git a/components/playground/instance/ticdc.go b/components/playground/instance/ticdc.go index 562d42d504..da2d683913 100644 --- a/components/playground/instance/ticdc.go +++ b/components/playground/instance/ticdc.go @@ -20,8 +20,8 @@ import ( "strings" tiupexec "github.com/pingcap/tiup/pkg/exec" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" - "golang.org/x/mod/semver" ) // TiCDC represent a ticdc instance. @@ -62,9 +62,8 @@ func (c *TiCDC) Start(ctx context.Context, version utils.Version) error { fmt.Sprintf("--log-file=%s", c.LogFile()), } clusterVersion := string(version) - if semver.Compare(clusterVersion, "v4.0.13") >= 0 { - if (semver.Major(clusterVersion) == "v4" && semver.Compare(clusterVersion, "v4.0.14") >= 0) || - (semver.Major(clusterVersion) == "v5" && semver.Compare(clusterVersion, "v5.0.3") >= 0) { + if tidbver.TiCDCSupportConfigFile(clusterVersion) { + if tidbver.TiCDCSupportDataDir(clusterVersion) { args = append(args, fmt.Sprintf("--data-dir=%s", filepath.Join(c.Dir, "data"))) } else { args = append(args, fmt.Sprintf("--sort-dir=%s/tmp/sorter", filepath.Join(c.Dir, "data"))) diff --git a/components/playground/instance/tiflash_config.go b/components/playground/instance/tiflash_config.go index 02a4b92ec4..ddf825c5ef 100644 --- a/components/playground/instance/tiflash_config.go +++ b/components/playground/instance/tiflash_config.go @@ -18,8 +18,8 @@ import ( "io" "strings" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" - "golang.org/x/mod/semver" ) const tiflashDaemonConfig = ` @@ -104,7 +104,7 @@ func writeTiFlashConfig(w io.Writer, version utils.Version, tcpPort, httpPort, s logDir := fmt.Sprintf("%s/log", deployDir) ip := AdvertiseHost(host) var conf string - if semver.Compare(version.String(), "v5.4.0") >= 0 || version.IsNightly() { + if tidbver.TiFlashNotNeedSomeConfig(version.String()) { conf = fmt.Sprintf(tiflashConfig, pdAddrs, httpPort, tcpPort, deployDir, dataDir, tmpDir, logDir, servicePort, metricsPort, ip, strings.Join(tidbStatusAddrs, ","), clusterManagerPath, "") diff --git a/components/playground/instance/tiflash_proxy_config.go b/components/playground/instance/tiflash_proxy_config.go index 29bef476ad..868974711e 100644 --- a/components/playground/instance/tiflash_proxy_config.go +++ b/components/playground/instance/tiflash_proxy_config.go @@ -17,8 +17,8 @@ import ( "fmt" "io" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" - "golang.org/x/mod/semver" ) const tiflashProxyConfig = ` @@ -52,7 +52,7 @@ func writeTiFlashProxyConfig(w io.Writer, version utils.Version, host, deployDir logDir := fmt.Sprintf("%s/log", deployDir) ip := AdvertiseHost(host) var statusAddr string - if semver.Compare(version.String(), "v4.0.5") >= 0 || version.IsNightly() { + if tidbver.TiFlashSupportAdvertiseStatusAddr(version.String()) { statusAddr = fmt.Sprintf(`status-addr = "0.0.0.0:%[2]d" advertise-status-addr = "%[1]s:%[2]d"`, ip, proxyStatusPort) } else { diff --git a/pkg/cluster/manager/basic.go b/pkg/cluster/manager/basic.go index 0096d775df..8647d3a8da 100644 --- a/pkg/cluster/manager/basic.go +++ b/pkg/cluster/manager/basic.go @@ -31,9 +31,9 @@ import ( "github.com/pingcap/tiup/pkg/cluster/task" "github.com/pingcap/tiup/pkg/meta" "github.com/pingcap/tiup/pkg/set" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/tui" "github.com/pingcap/tiup/pkg/utils" - "golang.org/x/mod/semver" ) // EnableCluster enable/disable the service in a cluster @@ -296,7 +296,7 @@ func getMonitorHosts(topo spec.Topology) (map[string]hostInfo, set.StringSet) { func checkTiFlashWithTLS(topo spec.Topology, version string) error { if clusterSpec, ok := topo.(*spec.Specification); ok { if clusterSpec.GlobalOptions.TLSEnabled { - if (semver.Compare(version, "v4.0.5") < 0 && + if (!tidbver.TiFlashSupportTLS(version) && len(clusterSpec.TiFlashServers) > 0) && version != utils.NightlyVersionAlias { return fmt.Errorf("TiFlash %s is not supported in TLS enabled cluster", version) diff --git a/pkg/cluster/spec/cdc.go b/pkg/cluster/spec/cdc.go index a4a52fd70d..82d5f79552 100644 --- a/pkg/cluster/spec/cdc.go +++ b/pkg/cluster/spec/cdc.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/tiup/pkg/cluster/ctxt" "github.com/pingcap/tiup/pkg/cluster/template/scripts" "github.com/pingcap/tiup/pkg/meta" - "golang.org/x/mod/semver" + "github.com/pingcap/tiup/pkg/tidbver" ) // CDCSpec represents the Drainer topology specification in topology.yaml @@ -163,7 +163,7 @@ func (i *CDCInstance) InitConfig( globalConfig := topo.ServerConfigs.CDC instanceConfig := spec.Config - if semver.Compare(clusterVersion, "v4.0.13") == -1 { + if !tidbver.TiCDCSupportConfigFile(clusterVersion) { if len(globalConfig)+len(instanceConfig) > 0 { return perrs.New("server_config is only supported with TiCDC version v4.0.13 or later") } diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index e13ddcd024..19c62cf0f5 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -31,11 +31,10 @@ import ( "github.com/pingcap/tiup/pkg/cluster/template/scripts" "github.com/pingcap/tiup/pkg/meta" "github.com/pingcap/tiup/pkg/proxy" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/tui" - "github.com/pingcap/tiup/pkg/utils" clientv3 "go.etcd.io/etcd/client/v3" "go.uber.org/zap" - "golang.org/x/mod/semver" ) const ( @@ -413,12 +412,12 @@ func (s *Specification) GetPDList() []string { // AdjustByVersion modify the spec by cluster version. func (s *Specification) AdjustByVersion(clusterVersion string) { // CDC does not support data dir for version below v4.0.13, and also v5.0.0-rc, set it to empty. - if semver.Compare(clusterVersion, "v4.0.13") == -1 || clusterVersion == "v5.0.0-rc" { + if !tidbver.TiCDCSupportConfigFile(clusterVersion) { for _, server := range s.CDCServers { server.DataDir = "" } } - if semver.Compare(clusterVersion, "v5.4.0") >= 0 || strings.Contains(clusterVersion, utils.NightlyVersionAlias) { + if tidbver.NgMonitorDeployByDefault(clusterVersion) { for _, m := range s.Monitors { if m.NgPort == 0 { m.NgPort = 12020 diff --git a/pkg/cluster/spec/spec_test.go b/pkg/cluster/spec/spec_test.go index b9fa52ef55..2c63e49426 100644 --- a/pkg/cluster/spec/spec_test.go +++ b/pkg/cluster/spec/spec_test.go @@ -740,8 +740,6 @@ cdc_servers: "v5.1.0": {true, true, true}, "v5.0.0-rc": {false, false, false}, - "v5.1.0-alpha": {true, true, false}, - "v5.2.0-alpha": {true, true, false}, "v6.0.0-alpha": {true, true, true}, "v6.1.0": {true, true, true}, "v99.0.0": {true, true, true}, diff --git a/pkg/cluster/spec/tidb.go b/pkg/cluster/spec/tidb.go index 6a9bd0cd48..469dc22104 100644 --- a/pkg/cluster/spec/tidb.go +++ b/pkg/cluster/spec/tidb.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/tiup/pkg/cluster/ctxt" "github.com/pingcap/tiup/pkg/cluster/template/scripts" "github.com/pingcap/tiup/pkg/meta" - "golang.org/x/mod/semver" + "github.com/pingcap/tiup/pkg/tidbver" ) // TiDBSpec represents the TiDB topology specification in topology.yaml @@ -146,7 +146,7 @@ func (i *TiDBInstance) InitConfig( AppendEndpoints(topo.Endpoints(deployUser)...). WithListenHost(i.GetListenHost()). WithAdvertiseAddr(spec.Host). - SupportSecureBootstrap(semver.Compare(clusterVersion, "v5.3.0") >= 0) + SupportSecureBootstrap(tidbver.TiDBSupportSecureBoot(clusterVersion)) fp := filepath.Join(paths.Cache, fmt.Sprintf("run_tidb_%s_%d.sh", i.GetHost(), i.GetPort())) if err := cfg.ConfigToFile(fp); err != nil { return err diff --git a/pkg/cluster/spec/tiflash.go b/pkg/cluster/spec/tiflash.go index 2e1f954a1c..771edb8f23 100644 --- a/pkg/cluster/spec/tiflash.go +++ b/pkg/cluster/spec/tiflash.go @@ -34,8 +34,8 @@ import ( "github.com/pingcap/tiup/pkg/cluster/template/scripts" "github.com/pingcap/tiup/pkg/meta" "github.com/pingcap/tiup/pkg/set" + "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" - "golang.org/x/mod/semver" "gopkg.in/yaml.v2" ) @@ -363,7 +363,7 @@ func (i *TiFlashInstance) CheckIncorrectConfigs() error { // need to check the configuration after clusterVersion >= v4.0.9. func checkTiFlashStorageConfigWithVersion(clusterVersion string, config map[string]interface{}) (bool, error) { - if semver.Compare(clusterVersion, "v4.0.9") >= 0 || utils.Version(clusterVersion).IsNightly() { + if tidbver.TiFlashSupportMultiDisksDeployment(clusterVersion) { return checkTiFlashStorageConfig(config) } return false, nil @@ -388,7 +388,7 @@ func (i *TiFlashInstance) initTiFlashConfig(ctx context.Context, cfg *scripts.Ti pathConfig = fmt.Sprintf(`path: "%s"`, cfg.DataDir) } - if (semver.Compare(clusterVersion, "v4.0.12") >= 0 && semver.Compare(clusterVersion, "v5.0.0-rc") != 0) || utils.Version(clusterVersion).IsNightly() { + if tidbver.TiFlashDeprecatedUsersConfig(clusterVersion) { // For v4.0.12 or later, 5.0.0 or later, TiFlash can ignore these `user.*`, `quotas.*` settings deprecatedUsersConfig = "#" } else { @@ -429,7 +429,7 @@ func (i *TiFlashInstance) initTiFlashConfig(ctx context.Context, cfg *scripts.Ti topo := Specification{} - if semver.Compare(clusterVersion, "v5.4.0") >= 0 || utils.Version(clusterVersion).IsNightly() { + if tidbver.TiFlashNotNeedSomeConfig(clusterVersion) { // For 5.4.0 or later, TiFlash can ignore application.runAsDaemon setting daemonConfig = "#" } else { @@ -499,7 +499,7 @@ func (i *TiFlashInstance) InitTiFlashLearnerConfig(ctx context.Context, cfg *scr firstDataDir := strings.Split(cfg.DataDir, ",")[0] - if semver.Compare(clusterVersion, "v4.0.5") >= 0 || utils.Version(clusterVersion).IsNightly() { + if tidbver.TiFlashSupportAdvertiseStatusAddr(clusterVersion) { statusAddr = fmt.Sprintf(`server.status-addr: "0.0.0.0:%[2]d" server.advertise-status-addr: "%[1]s:%[2]d"`, cfg.IP, cfg.FlashProxyStatusPort) } else { diff --git a/pkg/cluster/template/config/prometheus.go b/pkg/cluster/template/config/prometheus.go index b21cb2846f..69ef056d2b 100644 --- a/pkg/cluster/template/config/prometheus.go +++ b/pkg/cluster/template/config/prometheus.go @@ -21,7 +21,7 @@ import ( "text/template" "github.com/pingcap/tiup/embed" - "golang.org/x/mod/semver" + "github.com/pingcap/tiup/pkg/tidbver" ) // PrometheusConfig represent the data to generate Prometheus config @@ -57,14 +57,11 @@ type PrometheusConfig struct { // NewPrometheusConfig returns a PrometheusConfig func NewPrometheusConfig(clusterName, clusterVersion string, enableTLS bool) *PrometheusConfig { cfg := &PrometheusConfig{ - ClusterName: clusterName, - TLSEnabled: enableTLS, + ClusterName: clusterName, + TLSEnabled: enableTLS, + HasTiKVAccelerateRules: tidbver.PrometheusHasTiKVAccelerateRules(clusterVersion), } - // tikv.accelerate.rules.yml was first introduced in v4.0.0 - if semver.Compare(clusterVersion, "v4.0.0") >= 0 { - cfg.HasTiKVAccelerateRules = true - } return cfg } diff --git a/pkg/cluster/template/scripts/cdc.go b/pkg/cluster/template/scripts/cdc.go index 4b4b6298f4..9775323544 100644 --- a/pkg/cluster/template/scripts/cdc.go +++ b/pkg/cluster/template/scripts/cdc.go @@ -20,7 +20,7 @@ import ( "text/template" "github.com/pingcap/tiup/embed" - "golang.org/x/mod/semver" + "github.com/pingcap/tiup/pkg/tidbver" ) // CDCScript represent the data to generate cdc config @@ -126,25 +126,14 @@ func (c *CDCScript) AppendEndpoints(ends ...*PDScript) *CDCScript { func (c *CDCScript) PatchByVersion(clusterVersion, dataDir string) *CDCScript { // config support since v4.0.13, ignore v5.0.0-rc // the same to data-dir, but we treat it as --sort-dir - if semver.Compare(clusterVersion, "v4.0.13") >= 0 && clusterVersion != "v5.0.0-rc" { + if tidbver.TiCDCSupportConfigFile(clusterVersion) { c = c.WithConfigFileEnabled().WithDataDir(dataDir) } // cdc support --data-dir since v4.0.14 and v5.0.3 - if semver.Major(clusterVersion) == "v4" && semver.Compare(clusterVersion, "v4.0.14") >= 0 { + if tidbver.TiCDCSupportDataDir(clusterVersion) { c = c.WithDataDirEnabled() } - // for those version above v5.0.3, cdc does not support --data-dir - ignoreVersion := map[string]struct{}{ - "v5.1.0-alpha": {}, - "v5.2.0-alpha": {}, - } - if semver.Compare(clusterVersion, "v5.0.3") >= 0 { - if _, ok := ignoreVersion[clusterVersion]; !ok { - c = c.WithDataDirEnabled() - } - } - return c } diff --git a/pkg/cluster/template/scripts/tikv.go b/pkg/cluster/template/scripts/tikv.go index 33222da0e2..d5ba933f83 100644 --- a/pkg/cluster/template/scripts/tikv.go +++ b/pkg/cluster/template/scripts/tikv.go @@ -21,11 +21,7 @@ import ( "text/template" "github.com/pingcap/tiup/embed" - "golang.org/x/mod/semver" -) - -const ( - advertiseStatusAddrSupportedFrom = "v4.0.1" + "github.com/pingcap/tiup/pkg/tidbver" ) // TiKVScript represent the data to generate TiKV config @@ -55,7 +51,7 @@ func NewTiKVScript(version, ip string, port, statusPort int, deployDir, dataDir, DeployDir: deployDir, DataDir: dataDir, LogDir: logDir, - SupportAdvertiseStatusAddr: semver.Compare(version, advertiseStatusAddrSupportedFrom) >= 0, + SupportAdvertiseStatusAddr: tidbver.TiKVSupportAdvertiseStatusAddr(version), } } diff --git a/pkg/tidbver/tidbver.go b/pkg/tidbver/tidbver.go new file mode 100644 index 0000000000..8f3b53d1a2 --- /dev/null +++ b/pkg/tidbver/tidbver.go @@ -0,0 +1,94 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package tidbver + +import ( + "strings" + + "golang.org/x/mod/semver" +) + +// warning: invalid semantic version string is considered less than a valid one when using semver.Compare + +// TiDBSupportSecureBoot return if given version of TiDB support secure boot +func TiDBSupportSecureBoot(version string) bool { + return semver.Compare(version, "v5.3.0") >= 0 || strings.Contains(version, "nightly") +} + +// TiKVSupportAdvertiseStatusAddr return if given version of TiKV support --advertise-status-addr +func TiKVSupportAdvertiseStatusAddr(version string) bool { + // TiKV support --advertise-status-addr since v4.0.1 + return semver.Compare(version, "v4.0.1") >= 0 || strings.Contains(version, "nightly") +} + +// TiFlashSupportTLS return if given version of TiFlash support TLS +func TiFlashSupportTLS(version string) bool { + return semver.Compare(version, "v4.0.5") >= 0 || strings.Contains(version, "nightly") +} + +// TiFlashSupportAdvertiseStatusAddr return if given version of TiFlash support --advertise-status-addr +func TiFlashSupportAdvertiseStatusAddr(version string) bool { + // TiFlash support --advertise-status-addr since v4.0.5 + return semver.Compare(version, "v4.0.5") >= 0 || strings.Contains(version, "nightly") +} + +// TiFlashSupportMultiDisksDeployment return if given version of TiFlash support multi-disks deployment +func TiFlashSupportMultiDisksDeployment(version string) bool { + // https://github.com/pingcap/tiup/pull/931 + return semver.Compare(version, "v4.0.9") >= 0 || strings.Contains(version, "nightly") +} + +// TiFlashDeprecatedUsersConfig return if given version of TiFlash deprecated users.* config +func TiFlashDeprecatedUsersConfig(version string) bool { + // https://github.com/pingcap/tiup/pull/1211 + return semver.Compare(version, "v4.0.12") >= 0 && version != "v5.0.0-rc" || strings.Contains(version, "nightly") +} + +// TiFlashNotNeedSomeConfig return if given version of TiFlash do not need some config like runAsDaemon +func TiFlashNotNeedSomeConfig(version string) bool { + // https://github.com/pingcap/tiup/pull/1673 + return semver.Compare(version, "v5.4.0") >= 0 || strings.Contains(version, "nightly") +} + +// TiCDCSupportConfigFile return if given version of TiCDC support config file +func TiCDCSupportConfigFile(version string) bool { + // config support since v4.0.13, ignore v5.0.0-rc + return semver.Compare(version, "v4.0.13") >= 0 && version != "v5.0.0-rc" || strings.Contains(version, "nightly") +} + +// TiCDCSupportDataDir return if given version of TiCDC support --data-dir +func TiCDCSupportDataDir(version string) bool { + // TiCDC support --data-dir since v4.0.14 and v5.0.3 + if semver.Compare(version, "v5.0.3") >= 0 || strings.Contains(version, "nightly") { + return true + } + return semver.Major(version) == "v4" && semver.Compare(version, "v4.0.14") >= 0 +} + +// NgMonitorDeployByDefault return if given version of TiDB cluster should contain ng-monitoring +func NgMonitorDeployByDefault(version string) bool { + return semver.Compare(version, "v5.4.0") >= 0 || strings.Contains(version, "nightly") +} + +// PrometheusHasTiKVAccelerateRules return if given version of Prometheus has TiKV accelerateRules +func PrometheusHasTiKVAccelerateRules(version string) bool { + // tikv.accelerate.rules.yml was first introduced in v4.0.0 + return semver.Compare(version, "v4.0.0") >= 0 || strings.Contains(version, "nightly") +} + +// DMSupportDeploy return if given version of DM is supported bu tiup-dm +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") +}