Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
restore: use a more robust version parsing strategy for TiDB
Browse files Browse the repository at this point in the history
In semver, '2.0.4-1 < 2.0.4', so we need to properly skip the unrelated
portions of the version.
  • Loading branch information
kennytm committed Sep 6, 2018
1 parent 47029f3 commit e01819d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,17 @@ func (rc *RestoreController) checkTiDBVersion(client *http.Client) error {
}

// version format: "5.7.10-TiDB-v2.1.0-rc.1-7-g38c939f"
versions := strings.SplitN(status.Version, "-TiDB-v", 2)
if len(versions) != 2 {
// ^~~~~~~~~^ we only want this part
// version format: "5.7.10-TiDB-v2.0.4-1-g06a0bf5"
// ^~~~^
versions := strings.Split(status.Version, "-")
if len(versions) < 5 {
return errors.Errorf("not a valid TiDB version: %s", status.Version)
}
rawVersion := strings.Join(versions[2:len(versions)-2], "-")
rawVersion = strings.TrimPrefix(rawVersion, "v")

version, err := semver.NewVersion(versions[1])
version, err := semver.NewVersion(rawVersion)
if err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit e01819d

Please sign in to comment.