Skip to content

Commit

Permalink
binlog: update config for backward compatibility (pingcap#9688)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXiangUSTC authored Mar 14, 2019
1 parent c5c3091 commit 792429d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
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"`
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.
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 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"
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.AutoMode = true
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.AutoMode, Equals, true)

c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s")
c.Assert(conf.TiKVClient.MaxBatchSize, Equals, uint(128))
Expand Down
6 changes: 3 additions & 3 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
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.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.
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

0 comments on commit 792429d

Please sign in to comment.