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 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add version check * Update pkg/utils/version.go Co-authored-by: kennytm <kennytm@gmail.com> * fix test * add flag to control check * address comment * fix ci * remove DS_Store Co-authored-by: luancheng <luancheng@pingcap.com> Co-authored-by: kennytm <kennytm@gmail.com>
- Loading branch information
1 parent
aa5e231
commit a1c1d5d
Showing
10 changed files
with
204 additions
and
13 deletions.
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) | ||
} |