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

binlog: update config for backward compatibility #9688

Merged
merged 12 commits into from
Mar 14, 2019
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ type TiKVClient struct {

// Binlog is the config for binlog.
type Binlog struct {
Enable string `toml:"enable" json:"enable"`
Enable bool `toml:"enable" json:"enable"`
Mode string `toml:"mode" json:"mode"`
WriteTimeout string `toml:"write-timeout" json:"write-timeout"`
// If IgnoreError is true, when writing binlog meets error, TiDB would
// ignore the error.
Expand Down Expand Up @@ -343,7 +344,6 @@ var defaultConf = Config{
BatchWaitSize: 8,
},
Binlog: Binlog{
Enable: "auto",
WriteTimeout: "15s",
},
}
Expand Down
8 changes: 5 additions & 3 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ enabled = true
capacity = 2048000

[binlog]
# Enable to write binlog. Values can be "on", "off" or "auto".
# If value is "auto", will enable binlog according to the system variables 'tidb_log_bin'.
enable = "auto"
# Enable to write binlog. This config will be disabled if mode is "auto".
enable = false

# If mode is "auto", will enable binlog according to the system variables 'tidb_log_bin'.
mode = ""

# WriteTimeout specifies how long it will wait for writing binlog to pump.
write-timeout = "15s"
Expand Down
6 changes: 4 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func TestT(t *testing.T) {

func (s *testConfigSuite) TestConfig(c *C) {
conf := new(Config)
conf.Binlog.Enable = "auto"
conf.Binlog.Enable = true
conf.Binlog.Mode = "auto"
conf.Binlog.IgnoreError = true
conf.TiKVClient.CommitTimeout = "10s"
conf.CheckMb4ValueInUtf8 = true
Expand All @@ -54,7 +55,8 @@ max-batch-size=128
c.Assert(conf.Load(configFile), IsNil)

// 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, "auto")
c.Assert(conf.Binlog.Enable, Equals, true)
c.Assert(conf.Binlog.Mode, Equals, "auto")

c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s")
c.Assert(conf.TiKVClient.MaxBatchSize, Equals, uint(128))
Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) {
return nil, errors.Trace(err)
}

// get global system tidb_log_bin from mysql.GLOBAL_VARIABLES
// get global system variable tidb_log_bin from mysql.GLOBAL_VARIABLES
tidbLogBin, err := se1.GetGlobalSysVar(variable.TiDBLogBin)
if err != nil {
return nil, errors.Trace(err)
Expand Down
8 changes: 6 additions & 2 deletions sessionctx/binloginfo/binloginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ func SetIgnoreError(on bool) {
}
}

// ShouldEnableBinlog returns true if binlog.enable is "on", or binlog.enable is "auto" and tidb_log_bin's value is "1"
// ShouldEnableBinlog returns true if binlog.mode is not "auto" and binlog.enable is true, or binlog.mode is "auto" and tidb_log_bin's value is "1"
func ShouldEnableBinlog() bool {
return config.GetGlobalConfig().Binlog.Enable == "on" || (config.GetGlobalConfig().Binlog.Enable == "auto" && variable.SysVars[variable.TiDBLogBin].Value == "1")
if config.GetGlobalConfig().Binlog.Mode == "auto" {
return variable.SysVars[variable.TiDBLogBin].Value == "1"
}

return config.GetGlobalConfig().Binlog.Enable
}

// WriteBinlog writes a binlog to Pump.
Expand Down
2 changes: 1 addition & 1 deletion tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var (
port = flag.String(nmPort, "4000", "tidb server port")
cors = flag.String(nmCors, "", "tidb server allow cors origin")
socket = flag.String(nmSocket, "", "The socket file to use for connection.")
enableBinlog = flag.String(nmEnableBinlog, "auto", "enable generate binlog")
enableBinlog = flagBoolean(nmEnableBinlog, false, "enable generate binlog")
runDDL = flagBoolean(nmRunDDL, true, "run ddl worker on this tidb-server")
ddlLease = flag.String(nmDdlLease, "45s", "schema lease duration, very dangerous to change only if you know what you do")
tokenLimit = flag.Int(nmTokenLimit, 1000, "the limit of concurrent executed sessions")
Expand Down