From b6a30b832ddb6937c88312f71b4e1d4258778f8a Mon Sep 17 00:00:00 2001 From: reafans <30926443+reafans@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:04:39 +0800 Subject: [PATCH] config: add configuration entry make TiDB version string configurable (#13775) (#13906) --- config/config.go | 9 +++++++-- config/config.toml.example | 6 ++++++ config/config_test.go | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 5be0fa6bfc84d..acfb545dd45d6 100644 --- a/config/config.go +++ b/config/config.go @@ -28,6 +28,7 @@ import ( "github.com/BurntSushi/toml" "github.com/pingcap/errors" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/util/logutil" tracing "github.com/uber/jaeger-client-go/config" "go.uber.org/atomic" @@ -74,8 +75,8 @@ type Config struct { TxnLocalLatches TxnLocalLatches `toml:"txn-local-latches" json:"txn-local-latches"` // Set sys variable lower-case-table-names, ref: https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html. // TODO: We actually only support mode 2, which keeps the original case, but the comparison is case-insensitive. - LowerCaseTableNames int `toml:"lower-case-table-names" json:"lower-case-table-names"` - + LowerCaseTableNames int `toml:"lower-case-table-names" json:"lower-case-table-names"` + ServerVersion string `toml:"server-version" json:"server-version"` Log Log `toml:"log" json:"log"` Security Security `toml:"security" json:"security"` Status Status `toml:"status" json:"status"` @@ -352,6 +353,7 @@ var defaultConf = Config{ Capacity: 2048000, }, LowerCaseTableNames: 2, + ServerVersion: "", Log: Log{ Level: "info", Format: "text", @@ -542,6 +544,9 @@ func (c *Config) Load(confFile string) error { if c.TokenLimit <= 0 { c.TokenLimit = 1000 } + if len(c.ServerVersion) > 0 { + mysql.ServerVersion = c.ServerVersion + } // If any items in confFile file are not mapped into the Config struct, issue // an error and stop the server from starting. diff --git a/config/config.toml.example b/config/config.toml.example index cd10557f27f70..7154ff144570b 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -65,6 +65,12 @@ split-region-max-num = 1000 # In order to support "drop primary key" operation , this flag must be true and the table does not have the pkIsHandle flag. alter-primary-key = false +# server-version is used to change the version string of TiDB in the following scenarios: +# 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 = "" + [log] # Log level: debug, info, warn, error, fatal. level = "info" diff --git a/config/config_test.go b/config/config_test.go index 453e9717bc986..3d6e49d4f2030 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -20,6 +20,7 @@ import ( "testing" . "github.com/pingcap/check" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/util/logutil" tracing "github.com/uber/jaeger-client-go/config" ) @@ -65,6 +66,7 @@ unrecognized-option-test = true token-limit = 0 alter-primary-key = true split-region-max-num=10000 +server-version = "test_version" [performance] txn-entry-count-limit=2000 txn-total-size-limit=2000 @@ -83,6 +85,8 @@ max-sql-length=1024 c.Assert(conf.Load(configFile), IsNil) + c.Assert(conf.ServerVersion, Equals, "test_version") + c.Assert(mysql.ServerVersion, Equals, conf.ServerVersion) // Test that the original value will not be clear by load the config file that does not contain the option. c.Assert(conf.Binlog.Enable, Equals, true) c.Assert(conf.Binlog.Strategy, Equals, "hash")