This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
*: add version check before start #311
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2945ea
add version check
3pointer 42863df
Update pkg/utils/version.go
3pointer 61e1738
fix test
3pointer b67be9d
add flag to control check
3pointer dc73ae1
address comment
3pointer 1a825f0
fix ci
3pointer ba8b7af
Merge branch 'master' into add_version_check
overvenus 6e053e3
remove DS_Store
3pointer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
"github.com/pingcap/check" | ||
"github.com/pingcap/kvproto/pkg/metapb" | ||
pd "github.com/pingcap/pd/v4/client" | ||
) | ||
|
||
type versionSuite struct{} | ||
|
||
var _ = check.Suite(&versionSuite{}) | ||
|
||
type mockPDClient struct { | ||
pd.Client | ||
getAllStores func() []*metapb.Store | ||
} | ||
|
||
func (m *mockPDClient) GetAllStores(ctx context.Context, opts ...pd.GetStoreOption) ([]*metapb.Store, error) { | ||
if m.getAllStores != nil { | ||
return m.getAllStores(), nil | ||
} | ||
return []*metapb.Store{}, nil | ||
} | ||
|
||
func (s *versionSuite) TestCheckClusterVersion(c *check.C) { | ||
mock := mockPDClient{ | ||
Client: nil, | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v3.1.0-beta.2" | ||
mock.getAllStores = func() []*metapb.Store { | ||
return []*metapb.Store{{Version: minTiKVVersion.String()}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.IsNil) | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v3.1.0-beta.2" | ||
mock.getAllStores = func() []*metapb.Store { | ||
// TiKV is too lower to support BR | ||
return []*metapb.Store{{Version: `v2.1.0`}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.ErrorMatches, "TiKV .* don't support BR, please upgrade cluster .*") | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v3.1.0" | ||
mock.getAllStores = func() []*metapb.Store { | ||
// TiKV v3.1.0-beta.2 is incompatible with BR v3.1.0 | ||
return []*metapb.Store{{Version: minTiKVVersion.String()}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.ErrorMatches, "TiKV .* mismatch, please .*") | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v3.1.0" | ||
mock.getAllStores = func() []*metapb.Store { | ||
// TiKV v4.0.0-rc major version mismatch with BR v3.1.0 | ||
return []*metapb.Store{{Version: "v4.0.0-rc"}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.ErrorMatches, "TiKV .* major version mismatch, please .*") | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v4.0.0-rc.2" | ||
mock.getAllStores = func() []*metapb.Store { | ||
// TiKV v4.0.0-rc.2 is incompatible with BR v4.0.0-beta.1 | ||
return []*metapb.Store{{Version: "v4.0.0-beta.1"}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.ErrorMatches, "TiKV .* mismatch, please .*") | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v4.0.0-rc.2" | ||
mock.getAllStores = func() []*metapb.Store { | ||
// TiKV v4.0.0-rc.1 with BR v4.0.0-rc.2 is ok | ||
return []*metapb.Store{{Version: "v4.0.0-rc.1"}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.IsNil) | ||
} | ||
|
||
{ | ||
BRReleaseVersion = "v4.0.0-rc.1" | ||
mock.getAllStores = func() []*metapb.Store { | ||
// TiKV v4.0.0-rc.2 with BR v4.0.0-rc.1 is ok | ||
return []*metapb.Store{{Version: "v4.0.0-rc.2"}} | ||
} | ||
err := CheckClusterVersion(context.Background(), &mock) | ||
c.Assert(err, check.IsNil) | ||
} | ||
} | ||
|
||
func (s *versionSuite) TestCompareVersion(c *check.C) { | ||
c.Assert(semver.New("4.0.0-rc").Compare(*semver.New("4.0.0-rc.2")), check.Equals, -1) | ||
c.Assert(semver.New("4.0.0-beta.3").Compare(*semver.New("4.0.0-rc.2")), check.Equals, -1) | ||
c.Assert(semver.New("4.0.0-rc.1").Compare(*semver.New("4.0.0")), check.Equals, -1) | ||
c.Assert(semver.New("4.0.0-beta.1").Compare(*semver.New("4.0.0")), check.Equals, -1) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean flags seems must use the form
--some=false
to disable(see here), otherwise when it appears, it would be set totrue
.Maybe
--skip-check-reqirements
here would be better? Since we must use--check-requirements=false
to skip check requirements if we let the default value betrue
on this flag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is fine since we've got
--checksum=false
already.--skip-check-requirements
would be a "negative flag".