Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschema: fix tidb version showed in cluster_info table and update the go.mod for new sysutil #16003

Merged
merged 27 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9debac7
fix tidb version
reafans Apr 2, 2020
5ecb2fd
fmt
reafans Apr 2, 2020
2ad26aa
add UT
reafans Apr 2, 2020
a67f4ca
Merge branch 'master' into fix_tidb_version
reafans Apr 2, 2020
fa0baa3
Merge branch 'master' of https://github.com/pingcap/tidb into fix_tid…
reafans Apr 2, 2020
a6484f2
Merge branch 'master' into fix_tidb_version
reafans Apr 2, 2020
6507aff
Merge branch 'fix_tidb_version' of https://github.com/reafans/tidb in…
reafans Apr 2, 2020
a7410b4
refine
reafans Apr 2, 2020
5f7d091
Merge branch 'master' into fix_tidb_version
crazycs520 Apr 2, 2020
7e07999
address comment
reafans Apr 7, 2020
88a502c
Merge branch 'fix_tidb_version' of https://github.com/reafans/tidb in…
reafans Apr 7, 2020
d6ec54f
fix UT
reafans Apr 7, 2020
2755881
refine UT
reafans Apr 7, 2020
4c6106a
fix UT
reafans Apr 7, 2020
91effa9
refine
reafans Apr 7, 2020
756a142
Merge branch 'master' into fix_tidb_version
reafans Apr 7, 2020
be73031
refine
reafans Apr 7, 2020
92c24f7
Merge branch 'fix_tidb_version' of https://github.com/reafans/tidb in…
reafans Apr 7, 2020
2c5ac91
address comment
reafans Apr 8, 2020
b62e526
refine
reafans Apr 8, 2020
e8124fc
Merge branch 'master' into fix_tidb_version
reafans Apr 8, 2020
a24d436
address comment
reafans Apr 9, 2020
2e19fb0
Merge branch 'master' into fix_tidb_version
reafans Apr 9, 2020
af483dd
remove mod
reafans Apr 9, 2020
033e83b
Merge branch 'fix_tidb_version' of https://github.com/reafans/tidb in…
reafans Apr 9, 2020
07e1a23
Merge branch 'master' into fix_tidb_version
sre-bot Apr 9, 2020
0f26d48
Merge branch 'master' into fix_tidb_version
reafans Apr 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (s *testInfoschemaClusterTableSuite) TestTiDBClusterInfo(c *C) {
tidbStatusAddr := fmt.Sprintf(":%d", config.GetGlobalConfig().Status.StatusPort)
row := func(cols ...string) string { return strings.Join(cols, " ") }
tk.MustQuery("select type, instance, status_address, version, git_hash from information_schema.cluster_info").Check(testkit.Rows(
row("tidb", ":4000", tidbStatusAddr, "5.7.25-TiDB-None", "None"),
row("tidb", ":4000", tidbStatusAddr, "None", "None"),
row("pd", mockAddr, mockAddr, "4.0.0-alpha", "mock-pd-githash"),
row("tikv", "store1", "", "", ""),
))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd
github.com/pingcap/parser v0.0.0-20200407074807-436f1c8c4cff
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3
github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb
github.com/pingcap/sysutil v0.0.0-20200402033507-c59b39dd9c7b
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible
github.com/pingcap/tipb v0.0.0-20200212061130-c4d518eb1d60
github.com/prometheus/client_golang v1.0.0
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,9 @@ github.com/pingcap/parser v0.0.0-20200407074807-436f1c8c4cff/go.mod h1:9v0Edh8Ib
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3 h1:Yrp99FnjHAEuDrSBql2l0IqCtJX7KwJbTsD5hIArkvk=
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3/go.mod h1:25GfNw6+Jcr9kca5rtmTb4gKCJ4jOpow2zV2S9Dgafs=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20200302022240-21c8c70d0ab1 h1:YUnUZ914SHFMsOSe/xgH5DKK/thtRma8X8hcszRo3CA=
github.com/pingcap/sysutil v0.0.0-20200302022240-21c8c70d0ab1/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb h1:bDbgLaNTRNK6Qw7KjvEqqfCQstY8WMEcXyXTU7yzYKg=
github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20200402033507-c59b39dd9c7b h1:YQvq94uXDFG59FL+d7slpBsyU6ZCrlLlXdzVBauK9h8=
github.com/pingcap/sysutil v0.0.0-20200402033507-c59b39dd9c7b/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible h1:84F7MFMfdAYObrznvRslmVu43aoihrlL+7mMyMlOi0o=
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
Expand Down
33 changes: 31 additions & 2 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/pingcap/tidb/config"
reafans marked this conversation as resolved.
Show resolved Hide resolved
"io/ioutil"
"net/http"
"sort"
Expand Down Expand Up @@ -1102,21 +1103,49 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
if err != nil {
return nil, errors.Trace(err)
}

var servers []ServerInfo
var isDefaultVersion bool
if len(config.GetGlobalConfig().ServerVersion) == 0 {
isDefaultVersion = true
}
for _, node := range tidbNodes {
servers = append(servers, ServerInfo{
ServerType: "tidb",
Address: fmt.Sprintf("%s:%d", node.IP, node.Port),
StatusAddr: fmt.Sprintf("%s:%d", node.IP, node.StatusPort),
Version: node.Version,
Version: FormatVersion(node.Version, isDefaultVersion),
GitHash: node.GitHash,
StartTimestamp: node.StartTimestamp,
})
}
return servers, nil
}

// FormatVersion make TiDBVersion consistent to TiKV and PD.
// The default TiDBVersion is 5.7.25-TiDB-${TiDBReleaseVersion}.
func FormatVersion(TiDBVersion string, isDefaultVersion bool) string {
var version, nodeVersion string

// The user hasn't set the config 'ServerVersion'.
//if TiDBVersion == fmt.Sprintf("5.7.25-TiDB-%s", mysql.TiDBReleaseVersion) {
reafans marked this conversation as resolved.
Show resolved Hide resolved
if isDefaultVersion {
nodeVersion = TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a scenario where "TiDBVersion" is not the default format, but "isDefaultVersion" is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No,this would be never happened,because the "TiDBVersion" also comes from mysql.ServerVersion, and when the user not set the serverVersion,the mysql.ServerVersion would be the default version which make isDefaultVersion become true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I see node.Version is come from ServerInfo so ask this question.

if nodeVersion[0] == 'v' {
nodeVersion = nodeVersion[1:]
}
nodeVersions := strings.Split(nodeVersion, "-")
if len(nodeVersions) == 1 {
version = nodeVersions[0]
} else if len(nodeVersions) >= 2 {
version = fmt.Sprintf("%s-%s", nodeVersions[0], nodeVersions[1])
}
} else { // The user has already set the config 'ServerVersion',it would be a complex scene, so just use the 'ServerVersion' as version.
version = TiDBVersion
}

return version
}

// GetPDServerInfo returns all PD nodes information of cluster
func GetPDServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
// Get PD servers info.
Expand Down
18 changes: 18 additions & 0 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,21 @@ func (s *testTableSuite) TestSelectHiddenColumn(c *C) {
colInfo[2].Hidden = true
tk.MustQuery("select count(*) from INFORMATION_SCHEMA.COLUMNS where table_name = 'hidden'").Check(testkit.Rows("0"))
}

func (s *testTableSuite) TestFormatVersion(c *C) {
// Test for defaultVersions.
defaultVersions := []string{"5.7.25-TiDB-None", "5.7.25-TiDB-8.0.18", "5.7.25-TiDB-8.0.18-beta.1", "5.7.25-TiDB-v4.0.0-beta-446-g5268094af"}
defaultRes := []string{"None", "8.0.18", "8.0.18-beta.1", "4.0.0-beta"}
for i, v := range defaultVersions {
version := infoschema.FormatVersion(v, true)
c.Assert(version, Equals, defaultRes[i])
}

// Test for versions user set.
versions := []string{"8.0.18", "5.7.25-TiDB", "8.0.18-TiDB-4.0.0-beta.1"}
res := []string{"8.0.18", "5.7.25-TiDB", "8.0.18-TiDB-4.0.0-beta.1"}
for i, v := range versions {
version := infoschema.FormatVersion(v, false)
c.Assert(version, Equals, res[i])
}
}