diff --git a/config/config.go b/config/config.go index 959e400648ac1..2a3361ff90a70 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` + AutoMode bool `toml:"auto-mode" json:"auto-mode"` WriteTimeout string `toml:"write-timeout" json:"write-timeout"` // If IgnoreError is true, when writing binlog meets error, TiDB would // ignore the error. @@ -343,7 +344,6 @@ var defaultConf = Config{ BatchWaitSize: 8, }, Binlog: Binlog{ - Enable: "auto", WriteTimeout: "15s", }, } diff --git a/config/config.toml.example b/config/config.toml.example index 73b3894e39a22..74b91f7f02ef4 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -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 auto-mode is true. +enable = false + +# If auto-mode is true, will enable binlog according to the system variables 'tidb_log_bin'. +auto-mode = false # WriteTimeout specifies how long it will wait for writing binlog to pump. write-timeout = "15s" diff --git a/config/config_test.go b/config/config_test.go index 9981886f32511..137c07572053f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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.AutoMode = true conf.Binlog.IgnoreError = true conf.TiKVClient.CommitTimeout = "10s" conf.CheckMb4ValueInUtf8 = true @@ -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.AutoMode, Equals, true) c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s") c.Assert(conf.TiKVClient.MaxBatchSize, Equals, uint(128)) diff --git a/executor/set_test.go b/executor/set_test.go index c7bb09db41a4c..54a6c347627b7 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -18,8 +18,8 @@ import ( . "github.com/pingcap/check" "github.com/pingcap/parser/terror" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/sessionctx" + "github.com/pingcap/tidb/sessionctx/binloginfo" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" @@ -239,8 +239,8 @@ func (s *testSuite2) TestSetVar(c *C) { tk.MustExec("set @@sql_log_bin = on") tk.MustQuery(`select @@session.sql_log_bin;`).Check(testkit.Rows("1")) - tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows(variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable == "on"))) - tk.MustQuery(`select @@log_bin;`).Check(testkit.Rows(variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable == "on"))) + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows(variable.BoolToIntStr(binloginfo.ShouldEnableBinlog()))) + tk.MustQuery(`select @@log_bin;`).Check(testkit.Rows(variable.BoolToIntStr(binloginfo.ShouldEnableBinlog()))) tk.MustExec("set global tidb_log_bin = on") tk.MustQuery(`select @@global.tidb_log_bin;`).Check(testkit.Rows("1")) diff --git a/session/session.go b/session/session.go index 422d10530ccf9..e897c41b41875 100644 --- a/session/session.go +++ b/session/session.go @@ -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) diff --git a/sessionctx/binloginfo/binloginfo.go b/sessionctx/binloginfo/binloginfo.go index 996902a48ece8..0976fb8801ab3 100644 --- a/sessionctx/binloginfo/binloginfo.go +++ b/sessionctx/binloginfo/binloginfo.go @@ -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.AutoMode is false and Binlog.Enable is true, or Binlog.AutoMode is true 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.AutoMode { + return variable.SysVars[variable.TiDBLogBin].Value == "1" + } + + return config.GetGlobalConfig().Binlog.Enable } // WriteBinlog writes a binlog to Pump. diff --git a/tidb-server/main.go b/tidb-server/main.go index d6c73e7a2ca34..c12814fabe10c 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -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")