diff --git a/pkg/cluster/spec/spec_test.go b/pkg/cluster/spec/spec_test.go index e32ca640cf..6193d13938 100644 --- a/pkg/cluster/spec/spec_test.go +++ b/pkg/cluster/spec/spec_test.go @@ -21,7 +21,6 @@ import ( "github.com/BurntSushi/toml" . "github.com/pingcap/check" "github.com/pingcap/tiup/pkg/cluster/template/scripts" - "golang.org/x/mod/semver" "gopkg.in/yaml.v2" ) @@ -721,28 +720,42 @@ cdc_servers: instances := cdcComp.Instances() c.Assert(len(instances), Equals, 1) + var expected = map[string]struct { + configSupported bool + dataDir bool // data-dir is set + dataDirSupported bool + }{ + "v4.0.12": {false, false, false}, + "v4.0.13": {true, true, false}, + "v4.0.14": {true, true, true}, + + "v5.0.0": {true, true, false}, + "v5.0.1": {true, true, false}, + "v5.0.2": {true, true, false}, + + "v5.0.3": {true, true, true}, + "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}, + } + checkByVersion := func(version string) { ins := instances[0].(*CDCInstance) cfg := scripts.NewCDCScript(ins.GetHost(), "", "", false, 0, ""). PatchByVersion(version, ins.DataDir()) - // DataDir support since v4.0.13 - checker := Equals - if semver.Compare(version, "v4.0.13") >= 0 && version != "v5.0.0-rc" { - checker = Not(checker) - c.Assert(len(cfg.DataDir), checker, 0) + wanted := expected[version] - // TiCDC support --data-dir since v4.0.14 and v5.0.3 - expected := semver.Compare(version, "v4.0.14") >= 0 || semver.Compare(version, "v5.0.3") >= 0 - c.Assert(cfg.DataDirEnabled, Equals, expected) - } + c.Assert(cfg.ConfigFileEnabled, Equals, wanted.configSupported) + c.Assert(cfg.DataDirEnabled, Equals, wanted.dataDirSupported) + c.Assert(len(cfg.DataDir) != 0, Equals, wanted.dataDir) } - checkByVersion("v4.0.12") - checkByVersion("v4.0.13") - checkByVersion("v5.0.0-rc") - checkByVersion("v4.0.14") - checkByVersion("v5.0.3") + for k := range expected { + checkByVersion(k) + } } func (s *metaSuiteTopo) TestTiFlashUsersSettings(c *C) { diff --git a/pkg/cluster/template/scripts/cdc.go b/pkg/cluster/template/scripts/cdc.go index 1453495b7e..77432ff441 100644 --- a/pkg/cluster/template/scripts/cdc.go +++ b/pkg/cluster/template/scripts/cdc.go @@ -124,15 +124,26 @@ func (c *CDCScript) AppendEndpoints(ends ...*PDScript) *CDCScript { // PatchByVersion update fields by cluster version func (c *CDCScript) PatchByVersion(clusterVersion, dataDir string) *CDCScript { + // for those version, cdc does not support --data-dir ignore := map[string]struct{}{ "v5.0.0-rc": {}, "v5.1.0-alpha": {}, + "v5.2.0-alpha": {}, } - if _, ok := ignore[clusterVersion]; !ok && semver.Compare(clusterVersion, "v4.0.13") >= 0 { + // 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" { c = c.WithConfigFileEnabled().WithDataDir(dataDir) + } + + // cdc support --data-dir since v4.0.14 and v5.0.3, but not the ignore above + if semver.Major(clusterVersion) == "v4" && semver.Compare(clusterVersion, "v4.0.14") >= 0 { + c = c.WithDataDirEnabled() + } - if semver.Compare(clusterVersion, "v4.0.14") >= 0 || semver.Compare(clusterVersion, "v5.0.3") >= 0 { + if semver.Major(clusterVersion) == "v5" && semver.Compare(clusterVersion, "v5.0.3") >= 0 { + if _, ok := ignore[clusterVersion]; !ok { c = c.WithDataDirEnabled() } }