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

Commit

Permalink
utils: add errors.Annotate on semver errors (#400) (#408)
Browse files Browse the repository at this point in the history
Co-authored-by: kennytm <[email protected]>
  • Loading branch information
ti-srebot and kennytm authored Jul 10, 2020
1 parent d184933 commit fe6be48
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,27 @@ func removeVAndHash(v string) string {
func CheckClusterVersion(ctx context.Context, client pd.Client) error {
BRVersion, err := semver.NewVersion(removeVAndHash(BRReleaseVersion))
if err != nil {
return err
return errors.Annotate(err, "invalid BR version, please recompile using `git fetch origin --tags && make build`")
}
stores, err := client.GetAllStores(ctx, pd.WithExcludeTombstone())
if err != nil {
return err
return errors.Trace(err)
}
for _, s := range stores {
tikvVersion, err := semver.NewVersion(removeVAndHash(s.Version))
tikvVersionString := removeVAndHash(s.Version)
tikvVersion, err := semver.NewVersion(tikvVersionString)
if err != nil {
return err
return errors.Annotatef(err, "TiKV node %s version %s is invalid", s.Address, tikvVersionString)
}

if tikvVersion.Compare(*minTiKVVersion) < 0 {
return errors.Errorf("TiKV node %s version %s don't support BR, please upgrade cluster to %s",
s.Address, removeVAndHash(s.Version), BRReleaseVersion)
s.Address, tikvVersionString, BRReleaseVersion)
}

if tikvVersion.Major != BRVersion.Major {
return errors.Errorf("TiKV node %s version %s and BR %s major version mismatch, please use the same version of BR",
s.Address, removeVAndHash(s.Version), BRReleaseVersion)
s.Address, tikvVersionString, BRReleaseVersion)
}

// BR(https://github.com/pingcap/br/pull/233) and TiKV(https://github.com/tikv/tikv/pull/7241) have breaking changes
Expand All @@ -93,19 +94,20 @@ func CheckClusterVersion(ctx context.Context, client pd.Client) error {
if tikvVersion.Major == 3 {
if tikvVersion.Compare(*incompatibleTiKVMajor3) < 0 && BRVersion.Compare(*incompatibleTiKVMajor3) >= 0 {
return errors.Errorf("TiKV node %s version %s and BR %s version mismatch, please use the same version of BR",
s.Address, removeVAndHash(s.Version), BRReleaseVersion)
s.Address, tikvVersionString, BRReleaseVersion)
}
}

if tikvVersion.Major == 4 {
if tikvVersion.Compare(*incompatibleTiKVMajor4) < 0 && BRVersion.Compare(*incompatibleTiKVMajor4) >= 0 {
return errors.Errorf("TiKV node %s version %s and BR %s version mismatch, please use the same version of BR",
s.Address, removeVAndHash(s.Version), BRReleaseVersion)
s.Address, tikvVersionString, BRReleaseVersion)
}
}

if tikvVersion.Compare(*BRVersion) > 0 {
log.Warn(fmt.Sprintf("BR version is too old, please consider use version %s of BR", removeVAndHash(s.Version)))
// don't warn if we are the master build, which always have the version v4.0.0-beta.2-*
if BRGitBranch != "master" && tikvVersion.Compare(*BRVersion) > 0 {
log.Warn(fmt.Sprintf("BR version is too old, please consider use version %s of BR", tikvVersionString))
break
}
}
Expand Down

0 comments on commit fe6be48

Please sign in to comment.