forked from pingcap/br
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: add version check before start (pingcap#311)
* add version check * Update pkg/utils/version.go Co-authored-by: kennytm <[email protected]> * fix test * add flag to control check * address comment * fix ci * remove DS_Store Co-authored-by: kennytm <[email protected]> Co-authored-by: Neil Shen <[email protected]>
- Loading branch information
1 parent
abb9f88
commit 7c5c187
Showing
12 changed files
with
279 additions
and
47 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/v3/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) | ||
} |
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