Skip to content

Commit

Permalink
add package tidbver (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored May 12, 2022
1 parent 1552408 commit 4f8a44a
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 65 deletions.
9 changes: 2 additions & 7 deletions components/dm/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}

Expand Down
10 changes: 4 additions & 6 deletions components/dm/command/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions components/playground/instance/ticdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")))
Expand Down
4 changes: 2 additions & 2 deletions components/playground/instance/tiflash_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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, "")
Expand Down
4 changes: 2 additions & 2 deletions components/playground/instance/tiflash_proxy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/manager/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/spec/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/cluster/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/spec/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/cluster/spec/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions pkg/cluster/template/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 3 additions & 14 deletions pkg/cluster/template/scripts/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
8 changes: 2 additions & 6 deletions pkg/cluster/template/scripts/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
}

Expand Down
Loading

0 comments on commit 4f8a44a

Please sign in to comment.