Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
pkg/lightning: checkVersion checks major version for requiredMaxVersi…
Browse files Browse the repository at this point in the history
…on (#806)

Signed-off-by: Neil Shen <[email protected]>
  • Loading branch information
overvenus authored Mar 11, 2021
1 parent 9348911 commit 3833d43
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions pkg/lightning/backend/checkreq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (s *checkReqSuite) TestCheckVersion(c *C) {

err = checkVersion("TiNB", *semver.New("3.1.0"), *semver.New("2.3.5"), *semver.New("3.0.0"))
c.Assert(err, ErrorMatches, "TiNB version too new.*")

err = checkVersion("TiNB", *semver.New("3.0.0-beta"), *semver.New("2.3.5"), *semver.New("3.0.0"))
c.Assert(err, ErrorMatches, "TiNB version too new.*")
}

func (s *checkReqSuite) TestCheckTiDBVersion(c *C) {
Expand All @@ -66,6 +69,9 @@ func (s *checkReqSuite) TestCheckTiDBVersion(c *C) {
version = "5.7.25-TiDB-v6.0.0"
c.Assert(checkTiDBVersionByTLS(ctx, tls, requiredMinTiDBVersion, requiredMaxTiDBVersion), ErrorMatches, "TiDB version too new.*")

version = "5.7.25-TiDB-v6.0.0-beta"
c.Assert(checkTiDBVersionByTLS(ctx, tls, requiredMinTiDBVersion, requiredMaxTiDBVersion), ErrorMatches, "TiDB version too new.*")

version = "5.7.25-TiDB-v1.0.0"
c.Assert(checkTiDBVersionByTLS(ctx, tls, requiredMinTiDBVersion, requiredMaxTiDBVersion), ErrorMatches, "TiDB version too old.*")
}
Expand Down Expand Up @@ -105,6 +111,11 @@ func (s *checkReqSuite) TestCheckPDVersion(c *C) {
}`
c.Assert(checkPDVersion(ctx, tls, mockURL.Host, requiredMinPDVersion, requiredMaxPDVersion), ErrorMatches, "PD version too new.*")

version = `{
"version": "v6.0.0-beta"
}`
c.Assert(checkPDVersion(ctx, tls, mockURL.Host, requiredMinPDVersion, requiredMaxPDVersion), ErrorMatches, "PD version too new.*")

version = `{
"version": "v1.0.0"
}`
Expand Down Expand Up @@ -150,4 +161,7 @@ func (s *checkReqSuite) TestCheckTiKVVersion(c *C) {

versions = []string{"6.0.0"}
c.Assert(checkTiKVVersion(ctx, tls, mockURL.Host, requiredMinTiKVVersion, requiredMaxTiKVVersion), ErrorMatches, `TiKV \(at tikv0\.test:20160\) version too new.*`)

versions = []string{"6.0.0-beta"}
c.Assert(checkTiKVVersion(ctx, tls, mockURL.Host, requiredMinTiKVVersion, requiredMaxTiKVVersion), ErrorMatches, `TiKV \(at tikv0\.test:20160\) version too new.*`)
}
9 changes: 6 additions & 3 deletions pkg/lightning/backend/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,15 @@ func checkVersion(component string, actual, requiredMinVersion, requiredMaxVersi
actual,
)
}
if actual.Compare(requiredMaxVersion) >= 0 {
// Compare the major version number to make sure beta version does not pass
// the check. This is because beta version may contains incompatible
// changes.
if actual.Major >= requiredMaxVersion.Major {
return errors.Errorf(
"%s version too new, expected to be within [%s, %s), found '%s'",
"%s version too new, major version expected to be within [%s, %d.0.0), found '%s'",
component,
requiredMinVersion,
requiredMaxVersion,
requiredMaxVersion.Major,
actual,
)
}
Expand Down

0 comments on commit 3833d43

Please sign in to comment.