Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: fix cdc data dir version issue #1421

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions pkg/cluster/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 13 additions & 2 deletions pkg/cluster/template/scripts/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down