Skip to content

Commit

Permalink
config: add configuration entry make TiDB version string configurable (
Browse files Browse the repository at this point in the history
  • Loading branch information
reafans authored and bb7133 committed Dec 5, 2019
1 parent 83919ba commit 8d279ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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"
)
Expand Down Expand Up @@ -67,8 +68,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"`
Expand Down Expand Up @@ -308,6 +309,7 @@ var defaultConf = Config{
Capacity: 10240000,
},
LowerCaseTableNames: 2,
ServerVersion: "",
Log: Log{
Level: "info",
Format: "text",
Expand Down Expand Up @@ -389,6 +391,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.
Expand Down
6 changes: 6 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ treat-old-version-utf8-as-utf8mb4 = true
# Maximum number of the splitting region, which is used by the split region statement.
split-region-max-num = 1000

# 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"
Expand Down
4 changes: 4 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/parser/mysql"
)

var _ = Suite(&testConfigSuite{})
Expand Down Expand Up @@ -62,6 +63,7 @@ unrecognized-option-test = true
_, err = f.WriteString(`
token-limit = 0
split-region-max-num=10000
server-version = "test_version"
[performance]
txn-entry-count-limit=2000
txn-total-size-limit=2000
Expand All @@ -74,6 +76,8 @@ commit-timeout="41s"

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.BinlogSocket, Equals, "/tmp/socket")
Expand Down

0 comments on commit 8d279ad

Please sign in to comment.