From bdc10b9b8d044a1ed0b1e5f4ea6855be4211f01f Mon Sep 17 00:00:00 2001 From: Neil Shen Date: Tue, 12 Apr 2022 13:54:34 +0800 Subject: [PATCH] cluster: enable data-dir for versions above v5.0.3 (#1838) --- pkg/cluster/spec/spec_test.go | 9 ++++++--- pkg/cluster/template/scripts/cdc.go | 18 ++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/cluster/spec/spec_test.go b/pkg/cluster/spec/spec_test.go index ebe915f874..b9fa52ef55 100644 --- a/pkg/cluster/spec/spec_test.go +++ b/pkg/cluster/spec/spec_test.go @@ -742,6 +742,9 @@ cdc_servers: "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}, } checkByVersion := func(version string) { @@ -751,9 +754,9 @@ cdc_servers: wanted := expected[version] - c.Assert(cfg.ConfigFileEnabled, Equals, wanted.configSupported) - c.Assert(cfg.DataDirEnabled, Equals, wanted.dataDirSupported) - c.Assert(len(cfg.DataDir) != 0, Equals, wanted.dataDir) + c.Assert(cfg.ConfigFileEnabled, Equals, wanted.configSupported, Commentf(version)) + c.Assert(cfg.DataDirEnabled, Equals, wanted.dataDirSupported, Commentf(version)) + c.Assert(len(cfg.DataDir) != 0, Equals, wanted.dataDir, Commentf(version)) } for k := range expected { diff --git a/pkg/cluster/template/scripts/cdc.go b/pkg/cluster/template/scripts/cdc.go index 7fe532397b..4b4b6298f4 100644 --- a/pkg/cluster/template/scripts/cdc.go +++ b/pkg/cluster/template/scripts/cdc.go @@ -124,26 +124,24 @@ 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": {}, - } - // 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 + // cdc support --data-dir since v4.0.14 and v5.0.3 if semver.Major(clusterVersion) == "v4" && semver.Compare(clusterVersion, "v4.0.14") >= 0 { c = c.WithDataDirEnabled() } - if semver.Major(clusterVersion) == "v5" && semver.Compare(clusterVersion, "v5.0.3") >= 0 { - if _, ok := ignore[clusterVersion]; !ok { + // 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() } }