From 9debac7f2e6658c537d9d61482631047a2bb961f Mon Sep 17 00:00:00 2001 From: reafans Date: Thu, 2 Apr 2020 13:47:29 +0800 Subject: [PATCH 01/14] fix tidb version --- executor/infoschema_reader_test.go | 2 +- go.mod | 2 +- go.sum | 5 ++--- infoschema/tables.go | 10 +++++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index 254d61c56d1a4..f4d333d6ef854 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -696,7 +696,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", "127.0.0.1:20160", mockAddr, "4.0.0-alpha", "mock-tikv-githash"), )) diff --git a/go.mod b/go.mod index 4c0fa122de3be..3bcbb29fa696b 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd github.com/pingcap/parser v0.0.0-20200317021010-cd90cc2a7d87 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 diff --git a/go.sum b/go.sum index 79473a8cb3cd0..8e280608dac2d 100644 --- a/go.sum +++ b/go.sum @@ -272,10 +272,9 @@ github.com/pingcap/parser v0.0.0-20200317021010-cd90cc2a7d87/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= diff --git a/infoschema/tables.go b/infoschema/tables.go index 0fea9c074dbbb..bc8c9390d385f 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1206,12 +1206,20 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { } var servers []ServerInfo + var version string for _, node := range tidbNodes { + nodeVersion := node.Version[strings.LastIndex(node.Version,"TiDB-") + len("TiDB-"):] + 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]) + } 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: version, GitHash: node.GitHash, StartTimestamp: node.StartTimestamp, }) From 5ecb2fd62879673a17c10c90f456938602af8194 Mon Sep 17 00:00:00 2001 From: reafans Date: Thu, 2 Apr 2020 13:57:59 +0800 Subject: [PATCH 02/14] fmt --- infoschema/tables.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index bc8c9390d385f..3a5cd93a21107 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1208,12 +1208,12 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { var servers []ServerInfo var version string for _, node := range tidbNodes { - nodeVersion := node.Version[strings.LastIndex(node.Version,"TiDB-") + len("TiDB-"):] - nodeVersions := strings.Split(nodeVersion,"-") + nodeVersion := node.Version[strings.LastIndex(node.Version, "TiDB-")+len("TiDB-"):] + 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]) + version = fmt.Sprintf("%s-%s", nodeVersions[0], nodeVersions[1]) } servers = append(servers, ServerInfo{ ServerType: "tidb", From 2ad26aae83e7ca42a261f74c9d705fc1a2090234 Mon Sep 17 00:00:00 2001 From: reafans Date: Thu, 2 Apr 2020 14:18:30 +0800 Subject: [PATCH 03/14] add UT --- infoschema/tables.go | 26 +++++++++++++++++--------- infoschema/tables_test.go | 9 +++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index 3a5cd93a21107..f983fac295db2 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1206,20 +1206,12 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { } var servers []ServerInfo - var version string for _, node := range tidbNodes { - nodeVersion := node.Version[strings.LastIndex(node.Version, "TiDB-")+len("TiDB-"):] - 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]) - } 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: version, + Version: FormatVersion(node.Version), GitHash: node.GitHash, StartTimestamp: node.StartTimestamp, }) @@ -1227,6 +1219,22 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { return servers, nil } +// FormatVersion make TiDBVersion consistent to TiKV and PD. +func FormatVersion(TiDBVersion string) string { + var version string + nodeVersion := TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):] + 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]) + } + return version +} + // GetPDServerInfo returns all PD nodes information of cluster func GetPDServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { // Get PD servers info. diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 3a03a52cefd7e..7435b3186dfe1 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -867,3 +867,12 @@ 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) { + versions := []string{"5.7.25-TiDB-v4.0.0-beta-446-g5268094af", "5.7.25-TiDB-None", "5.7.25-TiDB-v4.0.1"} + res := []string{"4.0.0-beta", "None", "4.0.1"} + for i, v := range versions { + version := infoschema.FormatVersion(v) + c.Assert(version, Equals, res[i]) + } +} From a7410b4ff90246e44f8220ce5e11be2abadb73cd Mon Sep 17 00:00:00 2001 From: reafans Date: Thu, 2 Apr 2020 16:04:17 +0800 Subject: [PATCH 04/14] refine --- infoschema/tables.go | 1 + 1 file changed, 1 insertion(+) diff --git a/infoschema/tables.go b/infoschema/tables.go index 2f7aa724e3cac..5e23dcc3e6664 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1125,6 +1125,7 @@ func FormatVersion(TiDBVersion string) string { if nodeVersion[0] == 'v' { nodeVersion = nodeVersion[1:] } + nodeVersions := strings.Split(nodeVersion, "-") if len(nodeVersions) == 1 { version = nodeVersions[0] From 7e079993152c88ad055efdb8061933527681b239 Mon Sep 17 00:00:00 2001 From: reafans Date: Tue, 7 Apr 2020 19:27:25 +0800 Subject: [PATCH 05/14] address comment --- config/{config.toml.example => config.toml} | 0 infoschema/tables.go | 27 +++++++++++++-------- infoschema/tables_test.go | 6 +++-- 3 files changed, 21 insertions(+), 12 deletions(-) rename config/{config.toml.example => config.toml} (100%) diff --git a/config/config.toml.example b/config/config.toml similarity index 100% rename from config/config.toml.example rename to config/config.toml diff --git a/infoschema/tables.go b/infoschema/tables.go index 5e23dcc3e6664..5a495616d554e 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1119,19 +1119,26 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { } // FormatVersion make TiDBVersion consistent to TiKV and PD. +// The default TiDBVersion is 5.7.25-TiDB-${TiDBReleaseVersion}. func FormatVersion(TiDBVersion string) string { - var version string - nodeVersion := TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):] - if nodeVersion[0] == 'v' { - nodeVersion = nodeVersion[1:] - } + var version,nodeVersion string - 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]) + // The user hasn't set the config 'ServerVersion',so the TiDBVersion would like "5.7.25-TiDB-TiDBReleaseVersion". + if TiDBVersion == fmt.Sprintf("5.7.25-TiDB-%s",mysql.TiDBReleaseVersion) { + nodeVersion = TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):] + 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 } diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 08e1499b8770c..e80975eaa8758 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -854,8 +854,10 @@ func (s *testTableSuite) TestSelectHiddenColumn(c *C) { } func (s *testTableSuite) TestFormatVersion(c *C) { - versions := []string{"5.7.25-TiDB-v4.0.0-beta-446-g5268094af", "5.7.25-TiDB-None", "5.7.25-TiDB-v4.0.1"} - res := []string{"4.0.0-beta", "None", "4.0.1"} + tk := testkit.NewTestKit(c, s.store) + TiDBReleaseVersion := tk.Se.GetSessionVars().ConnectionInfo.ServerVersion + versions := []string{fmt.Sprintf("5.7.25-TiDB-%s",TiDBReleaseVersion), "TiDB-4.0.1", "8.0.18", "5.7.27", ""} + res := []string{"None", "TiDB-4.0.1", "8.0.18", "5.7.27",""} for i, v := range versions { version := infoschema.FormatVersion(v) c.Assert(version, Equals, res[i]) From d6ec54fd889ed6d7f9bffdb8ef5413ffdf13e1c7 Mon Sep 17 00:00:00 2001 From: reafans Date: Tue, 7 Apr 2020 20:21:09 +0800 Subject: [PATCH 06/14] fix UT --- config/{config.toml => config.toml.example} | 0 infoschema/tables.go | 4 ++-- infoschema/tables_test.go | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) rename config/{config.toml => config.toml.example} (100%) diff --git a/config/config.toml b/config/config.toml.example similarity index 100% rename from config/config.toml rename to config/config.toml.example diff --git a/infoschema/tables.go b/infoschema/tables.go index 5a495616d554e..0a7c86d4ec832 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1121,10 +1121,10 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { // FormatVersion make TiDBVersion consistent to TiKV and PD. // The default TiDBVersion is 5.7.25-TiDB-${TiDBReleaseVersion}. func FormatVersion(TiDBVersion string) string { - var version,nodeVersion string + var version, nodeVersion string // The user hasn't set the config 'ServerVersion',so the TiDBVersion would like "5.7.25-TiDB-TiDBReleaseVersion". - if TiDBVersion == fmt.Sprintf("5.7.25-TiDB-%s",mysql.TiDBReleaseVersion) { + if TiDBVersion == fmt.Sprintf("5.7.25-TiDB-%s", mysql.TiDBReleaseVersion) { nodeVersion = TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):] if nodeVersion[0] == 'v' { nodeVersion = nodeVersion[1:] diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index e80975eaa8758..b5b34f380a7cb 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -854,10 +854,8 @@ func (s *testTableSuite) TestSelectHiddenColumn(c *C) { } func (s *testTableSuite) TestFormatVersion(c *C) { - tk := testkit.NewTestKit(c, s.store) - TiDBReleaseVersion := tk.Se.GetSessionVars().ConnectionInfo.ServerVersion - versions := []string{fmt.Sprintf("5.7.25-TiDB-%s",TiDBReleaseVersion), "TiDB-4.0.1", "8.0.18", "5.7.27", ""} - res := []string{"None", "TiDB-4.0.1", "8.0.18", "5.7.27",""} + versions := []string{"5.7.25-TiDB-None", "8.0.18", "5.7.27"} + res := []string{"None", "8.0.18", "5.7.27"} for i, v := range versions { version := infoschema.FormatVersion(v) c.Assert(version, Equals, res[i]) From 2755881d1171ccdcee1bc0c0e928309411b5fd64 Mon Sep 17 00:00:00 2001 From: reafans Date: Tue, 7 Apr 2020 20:29:38 +0800 Subject: [PATCH 07/14] refine UT --- infoschema/tables_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index b5b34f380a7cb..787db233cde89 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -854,8 +854,8 @@ func (s *testTableSuite) TestSelectHiddenColumn(c *C) { } func (s *testTableSuite) TestFormatVersion(c *C) { - versions := []string{"5.7.25-TiDB-None", "8.0.18", "5.7.27"} - res := []string{"None", "8.0.18", "5.7.27"} + versions := []string{"5.7.25-TiDB-v4.0.0-beta-446-g5268094af", "5.7.25-TiDB-None", "5.7.25-TiDB-v4.0.1", "8.0.18", "5.7.27-TiDB"} + res := []string{"4.0.0-beta", "None", "4.0.1", "8.0.18", "5.7.27-TiDB"} for i, v := range versions { version := infoschema.FormatVersion(v) c.Assert(version, Equals, res[i]) From 4c6106add373db934bdeb36cc38b4f122c463932 Mon Sep 17 00:00:00 2001 From: reafans Date: Tue, 7 Apr 2020 20:40:05 +0800 Subject: [PATCH 08/14] fix UT --- config/{config.toml.example => config.toml} | 0 infoschema/tables_test.go | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename config/{config.toml.example => config.toml} (100%) diff --git a/config/config.toml.example b/config/config.toml similarity index 100% rename from config/config.toml.example rename to config/config.toml diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 787db233cde89..242918fcee1aa 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -854,8 +854,9 @@ func (s *testTableSuite) TestSelectHiddenColumn(c *C) { } func (s *testTableSuite) TestFormatVersion(c *C) { - versions := []string{"5.7.25-TiDB-v4.0.0-beta-446-g5268094af", "5.7.25-TiDB-None", "5.7.25-TiDB-v4.0.1", "8.0.18", "5.7.27-TiDB"} - res := []string{"4.0.0-beta", "None", "4.0.1", "8.0.18", "5.7.27-TiDB"} + // If not set the serverVersion, it would be "5.7.25-TiDB-None" in UT. + versions := []string{"5.7.25-TiDB-None", "8.0.18", "5.7.27-TiDB"} + res := []string{"None", "8.0.18", "5.7.27-TiDB"} for i, v := range versions { version := infoschema.FormatVersion(v) c.Assert(version, Equals, res[i]) From 91effa93d86cf0bb7545e9d59f6a1767b1bfdce5 Mon Sep 17 00:00:00 2001 From: reafans Date: Tue, 7 Apr 2020 20:41:32 +0800 Subject: [PATCH 09/14] refine --- config/{config.toml => config.toml.example} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename config/{config.toml => config.toml.example} (99%) diff --git a/config/config.toml b/config/config.toml.example similarity index 99% rename from config/config.toml rename to config/config.toml.example index 67017a071f125..aa57940538dfa 100644 --- a/config/config.toml +++ b/config/config.toml.example @@ -86,7 +86,7 @@ alter-primary-key = false # 1. the server version returned by builtin-function `VERSION()`. # 2. the server version filled in handshake packets of MySQL Connection Protocol, see https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake for more details. # if server-version = "", the default value(original TiDB version string) is used. -server-version = "" +server-version = "8.0.1" # repair mode is used to repair the broken table meta in TiKV in extreme cases. repair-mode = false From be730311dcd523f2121a855dc90d53df6faf6a2d Mon Sep 17 00:00:00 2001 From: reafans Date: Tue, 7 Apr 2020 21:37:52 +0800 Subject: [PATCH 10/14] refine --- config/config.toml.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.toml.example b/config/config.toml.example index aa57940538dfa..67017a071f125 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -86,7 +86,7 @@ alter-primary-key = false # 1. the server version returned by builtin-function `VERSION()`. # 2. the server version filled in handshake packets of MySQL Connection Protocol, see https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake for more details. # if server-version = "", the default value(original TiDB version string) is used. -server-version = "8.0.1" +server-version = "" # repair mode is used to repair the broken table meta in TiKV in extreme cases. repair-mode = false From 2c5ac913f0469601a1dc8700db67c4cc1970bfe8 Mon Sep 17 00:00:00 2001 From: reafans Date: Wed, 8 Apr 2020 15:30:22 +0800 Subject: [PATCH 11/14] address comment --- config/config.toml.example | 2 +- infoschema/tables.go | 15 ++++++++++----- infoschema/tables_test.go | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/config/config.toml.example b/config/config.toml.example index 28672c34e21a7..6ec8f35868daf 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -86,7 +86,7 @@ alter-primary-key = false # 1. the server version returned by builtin-function `VERSION()`. # 2. the server version filled in handshake packets of MySQL Connection Protocol, see https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake for more details. # if server-version = "", the default value(original TiDB version string) is used. -server-version = "" +server-version = "123" # repair mode is used to repair the broken table meta in TiKV in extreme cases. repair-mode = false diff --git a/infoschema/tables.go b/infoschema/tables.go index bf3d3b586e70e..9cd80e66b50ed 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -17,6 +17,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/pingcap/tidb/config" "io/ioutil" "net/http" "sort" @@ -1101,14 +1102,17 @@ 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: FormatVersion(node.Version), + Version: FormatVersion(node.Version, isDefaultVersion), GitHash: node.GitHash, StartTimestamp: node.StartTimestamp, }) @@ -1118,11 +1122,12 @@ func GetTiDBServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { // FormatVersion make TiDBVersion consistent to TiKV and PD. // The default TiDBVersion is 5.7.25-TiDB-${TiDBReleaseVersion}. -func FormatVersion(TiDBVersion string) string { +func FormatVersion(TiDBVersion string, isDefaultVersion bool) string { var version, nodeVersion string - // The user hasn't set the config 'ServerVersion',so the TiDBVersion would like "5.7.25-TiDB-TiDBReleaseVersion". - if TiDBVersion == fmt.Sprintf("5.7.25-TiDB-%s", mysql.TiDBReleaseVersion) { + // The user hasn't set the config 'ServerVersion'. + //if TiDBVersion == fmt.Sprintf("5.7.25-TiDB-%s", mysql.TiDBReleaseVersion) { + if isDefaultVersion { nodeVersion = TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):] if nodeVersion[0] == 'v' { nodeVersion = nodeVersion[1:] diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 242918fcee1aa..f5f77c4878808 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -854,11 +854,19 @@ func (s *testTableSuite) TestSelectHiddenColumn(c *C) { } func (s *testTableSuite) TestFormatVersion(c *C) { - // If not set the serverVersion, it would be "5.7.25-TiDB-None" in UT. - versions := []string{"5.7.25-TiDB-None", "8.0.18", "5.7.27-TiDB"} - res := []string{"None", "8.0.18", "5.7.27-TiDB"} + // 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) + version := infoschema.FormatVersion(v, false) c.Assert(version, Equals, res[i]) } } From b62e526fd193c26b05c289fef5b04b6569ab6ff1 Mon Sep 17 00:00:00 2001 From: reafans Date: Wed, 8 Apr 2020 15:36:43 +0800 Subject: [PATCH 12/14] refine --- config/config.toml.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.toml.example b/config/config.toml.example index 6ec8f35868daf..28672c34e21a7 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -86,7 +86,7 @@ alter-primary-key = false # 1. the server version returned by builtin-function `VERSION()`. # 2. the server version filled in handshake packets of MySQL Connection Protocol, see https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake for more details. # if server-version = "", the default value(original TiDB version string) is used. -server-version = "123" +server-version = "" # repair mode is used to repair the broken table meta in TiKV in extreme cases. repair-mode = false From a24d4368a305a4f8064f78a031d65580aee4409a Mon Sep 17 00:00:00 2001 From: reafans Date: Thu, 9 Apr 2020 11:13:02 +0800 Subject: [PATCH 13/14] address comment --- infoschema/tables.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index d9e59f35b050a..51e544d6d5300 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -17,7 +17,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/pingcap/tidb/config" "io/ioutil" "net/http" "sort" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/terror" + "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain/infosync" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" @@ -1127,7 +1127,6 @@ 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) { if isDefaultVersion { nodeVersion = TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):] if nodeVersion[0] == 'v' { From af483dd06914e67807c5ba5db94b176f68a3e1a5 Mon Sep 17 00:00:00 2001 From: reafans Date: Thu, 9 Apr 2020 11:25:05 +0800 Subject: [PATCH 14/14] remove mod --- go.mod | 2 +- go.sum | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ab9930c54e9ea..ad693571f02ae 100644 --- a/go.mod +++ b/go.mod @@ -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-20200402033507-c59b39dd9c7b + github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb 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 diff --git a/go.sum b/go.sum index 6d40e040eedae..7eb399ac04511 100644 --- a/go.sum +++ b/go.sum @@ -274,9 +274,10 @@ 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-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/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/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=