Skip to content

Commit

Permalink
Compatible with the old version of tidb client that does not have the…
Browse files Browse the repository at this point in the history
… prefix 'v' on version info (pingcap#185)

Signed-off-by: Cuixiaotian [email protected]
  • Loading branch information
cxt90730 authored Nov 12, 2020
1 parent e1ed4ff commit 05f1c5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion v4/export/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ var ServerInfoUnknown = ServerInfo{
}

var versionRegex = regexp.MustCompile(`^\d+\.\d+\.\d+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?`)
var tidbVersionRegex = regexp.MustCompile(`v\d+\.\d+\.\d+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?`)
var tidbVersionRegex = regexp.MustCompile(`-[v]?\d+\.\d+\.\d+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?`)

func ParseServerInfo(src string) ServerInfo {
log.Debug("parse server info", zap.String("server info string", src))
Expand All @@ -532,6 +532,7 @@ func ParseServerInfo(src string) ServerInfo {
var versionStr string
if serverInfo.ServerType == ServerTypeTiDB {
versionStr = tidbVersionRegex.FindString(src)[1:]
versionStr = strings.TrimPrefix(versionStr, "v")
} else {
versionStr = versionRegex.FindString(src)
}
Expand Down
3 changes: 2 additions & 1 deletion v4/export/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (s *testDumpSuite) TestDetectServerInfo(c *C) {
{2, "10.4.10-MariaDB-1:10.4.10+maria~bionic", ServerTypeMariaDB, mkVer(10, 4, 10, "MariaDB-1")},
{3, "5.7.25-TiDB-v4.0.0-alpha-1263-g635f2e1af", ServerTypeTiDB, mkVer(4, 0, 0, "alpha-1263-g635f2e1af")},
{4, "5.7.25-TiDB-v3.0.7-58-g6adce2367", ServerTypeTiDB, mkVer(3, 0, 7, "58-g6adce2367")},
{5, "invalid version", ServerTypeUnknown, (*semver.Version)(nil)},
{5, "5.7.25-TiDB-3.0.6", ServerTypeTiDB, mkVer(3, 0, 6, "")},
{6, "invalid version", ServerTypeUnknown, (*semver.Version)(nil)},
}
dec := func(d []interface{}) (tag int, verStr string, tp ServerType, v *semver.Version) {
return d[0].(int), d[1].(string), ServerType(d[2].(int)), d[3].(*semver.Version)
Expand Down

0 comments on commit 05f1c5d

Please sign in to comment.