From 62606d643f3c94d10276561259c9530ec610b3a3 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 15:51:16 +0800 Subject: [PATCH 01/17] Support variable `log_bin` --- executor/set_test.go | 10 ++++++++++ sessionctx/variable/sysvar.go | 11 ++++++++++- sessionctx/variable/varsutil.go | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/executor/set_test.go b/executor/set_test.go index 8b78a8f72823b..41e38f047c18b 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -220,6 +220,16 @@ func (s *testSuite2) TestSetVar(c *C) { tk.MustExec("COMMIT") tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED")) + tk.MustExec("set session log_bin = off;") + tk.MustQuery(`select @@session.log_bin;`).Check(testkit.Rows("OFF")) + tk.MustExec("set session log_bin = on;") + tk.MustQuery(`select @@session.log_bin;`).Check(testkit.Rows("ON")) + tk.MustExec("set session log_bin = off;") + tk.MustExec("set global log_bin = OFF;") + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("OFF")) + tk.MustExec("set global log_bin = on;") + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("ON")) + tk.MustExec("set global avoid_temporal_upgrade = on") tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Rows("1")) tk.MustExec("set @@global.avoid_temporal_upgrade = off") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 9befa39267a1c..18128f44c545a 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -115,6 +115,13 @@ func boolToIntStr(b bool) string { return "0" } +func boolToStatusStr(b bool) string { + if b { + return "ON" + } + return "OFF" +} + // we only support MySQL now var defaultSysVars = []*SysVar{ {ScopeGlobal, "gtid_mode", "OFF"}, @@ -386,7 +393,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "log_syslog_include_pid", ""}, {ScopeSession, "last_insert_id", ""}, {ScopeNone, "innodb_ft_cache_size", "8000000"}, - {ScopeNone, "log_bin", "OFF"}, + {ScopeSession, LogBin, boolToStatusStr(config.GetGlobalConfig().Binlog.Enable)}, {ScopeGlobal, "innodb_disable_sort_file_cache", "OFF"}, {ScopeGlobal, "log_error_verbosity", ""}, {ScopeNone, "performance_schema_hosts_size", "100"}, @@ -741,6 +748,8 @@ const ( InnodbLockWaitTimeout = "innodb_lock_wait_timeout" // SQLLogBin is the name for 'sql_log_bin' system variable. SQLLogBin = "sql_log_bin" + //LogBin is the name for 'log_bin' system variable. + LogBin = "log_bin" // MaxSortLength is the name for 'max_sort_length' system variable. MaxSortLength = "max_sort_length" // MaxSpRecursionDepth is the name for 'max_sp_recursion_depth' system variable. diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 89d498c5e1128..0fa545aaffbac 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -340,6 +340,15 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return "0", nil } return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) + case LogBin: + if strings.EqualFold(value, "ON") || value == "1" { + return "ON", nil + } + if strings.EqualFold(value, "OFF") || value == "0" { + return "OFF", nil + } + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) + case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown, TiDBOptInSubqToJoinAndAgg, TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming, From 3eb96d3bf7573974ddeff5f35cdcb6c5b6610a4c Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 16:10:00 +0800 Subject: [PATCH 02/17] =?UTF-8?q?Support=20variable=20`log=5Fbin`,Because?= =?UTF-8?q?=20the=20scope=20is=20not=20determined=EF=BC=8Cso=20the=20test?= =?UTF-8?q?=20only=20contains=20session=20level?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- executor/set_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index 41e38f047c18b..0c8279f520bda 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -225,11 +225,11 @@ func (s *testSuite2) TestSetVar(c *C) { tk.MustExec("set session log_bin = on;") tk.MustQuery(`select @@session.log_bin;`).Check(testkit.Rows("ON")) tk.MustExec("set session log_bin = off;") - tk.MustExec("set global log_bin = OFF;") - tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("OFF")) - tk.MustExec("set global log_bin = on;") - tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("ON")) - + /* tk.MustExec("set global log_bin = OFF;") + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("OFF")) + tk.MustExec("set global log_bin = on;") + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("ON")) + */ tk.MustExec("set global avoid_temporal_upgrade = on") tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Rows("1")) tk.MustExec("set @@global.avoid_temporal_upgrade = off") From b3af7746fb9647eb88fd4aacf54575af3b06e2e2 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 16:18:38 +0800 Subject: [PATCH 03/17] set ScopeNone as the scope of `log_bin` --- executor/set_test.go | 10 ---------- sessionctx/variable/sysvar.go | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index 0c8279f520bda..8b78a8f72823b 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -220,16 +220,6 @@ func (s *testSuite2) TestSetVar(c *C) { tk.MustExec("COMMIT") tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED")) - tk.MustExec("set session log_bin = off;") - tk.MustQuery(`select @@session.log_bin;`).Check(testkit.Rows("OFF")) - tk.MustExec("set session log_bin = on;") - tk.MustQuery(`select @@session.log_bin;`).Check(testkit.Rows("ON")) - tk.MustExec("set session log_bin = off;") - /* tk.MustExec("set global log_bin = OFF;") - tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("OFF")) - tk.MustExec("set global log_bin = on;") - tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows("ON")) - */ tk.MustExec("set global avoid_temporal_upgrade = on") tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Rows("1")) tk.MustExec("set @@global.avoid_temporal_upgrade = off") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 18128f44c545a..6d0a329ff0596 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -393,7 +393,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "log_syslog_include_pid", ""}, {ScopeSession, "last_insert_id", ""}, {ScopeNone, "innodb_ft_cache_size", "8000000"}, - {ScopeSession, LogBin, boolToStatusStr(config.GetGlobalConfig().Binlog.Enable)}, + {ScopeNone, LogBin, boolToStatusStr(config.GetGlobalConfig().Binlog.Enable)}, {ScopeGlobal, "innodb_disable_sort_file_cache", "OFF"}, {ScopeGlobal, "log_error_verbosity", ""}, {ScopeNone, "performance_schema_hosts_size", "100"}, From 195eaa88faf27d45d618c325d3e151804bf370fb Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 17:30:14 +0800 Subject: [PATCH 04/17] set `log_bin in setGlobalVars method --- executor/set_test.go | 3 +++ sessionctx/variable/sysvar.go | 4 ++-- tidb-server/main.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index 8b78a8f72823b..b9ec3ab5e7b7b 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -15,6 +15,7 @@ package executor_test import ( "context" + "github.com/pingcap/tidb/config" . "github.com/pingcap/check" "github.com/pingcap/parser/terror" @@ -231,6 +232,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.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) + tk.MustExec("set @@tidb_general_log = 1") tk.MustExec("set @@tidb_general_log = 0") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 6d0a329ff0596..186c19eda970f 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -115,7 +115,7 @@ func boolToIntStr(b bool) string { return "0" } -func boolToStatusStr(b bool) string { +func BoolToStatusStr(b bool) string { if b { return "ON" } @@ -393,7 +393,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "log_syslog_include_pid", ""}, {ScopeSession, "last_insert_id", ""}, {ScopeNone, "innodb_ft_cache_size", "8000000"}, - {ScopeNone, LogBin, boolToStatusStr(config.GetGlobalConfig().Binlog.Enable)}, + {ScopeNone, LogBin, "OFF"}, {ScopeGlobal, "innodb_disable_sort_file_cache", "OFF"}, {ScopeGlobal, "log_error_verbosity", ""}, {ScopeNone, "performance_schema_hosts_size", "100"}, diff --git a/tidb-server/main.go b/tidb-server/main.go index 1150a9258cf6a..4137a8037b5fe 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -439,6 +439,7 @@ func setGlobalVars() { variable.SysVars[variable.TIDBMemQuotaQuery].Value = strconv.FormatInt(cfg.MemQuotaQuery, 10) variable.SysVars["lower_case_table_names"].Value = strconv.Itoa(cfg.LowerCaseTableNames) + variable.SysVars["log_bin"].Value = variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable) // For CI environment we default enable prepare-plan-cache. plannercore.SetPreparedPlanCache(config.CheckTableBeforeDrop || cfg.PreparedPlanCache.Enabled) From af5997398e48e23a30ba6265aa223e11723a55a5 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 17:54:49 +0800 Subject: [PATCH 05/17] Support variable `log_bin` --- executor/set_test.go | 8 +++++++- sessionctx/variable/sysvar.go | 7 ------- tidb-server/main.go | 8 +++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index b9ec3ab5e7b7b..5082b02e0fa24 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -232,7 +232,7 @@ 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.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows(boolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) tk.MustExec("set @@tidb_general_log = 1") tk.MustExec("set @@tidb_general_log = 0") @@ -599,3 +599,9 @@ func (s *testSuite2) TestSelectGlobalVar(c *C) { _, err = tk.Exec("select @@global.invalid") c.Assert(terror.ErrorEqual(err, variable.UnknownSystemVar), IsTrue, Commentf("err %v", err)) } +func boolToStatusStr(b bool) string { + if b { + return "ON" + } + return "OFF" +} diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 186c19eda970f..1e1ea9fd46cc7 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -115,13 +115,6 @@ func boolToIntStr(b bool) string { return "0" } -func BoolToStatusStr(b bool) string { - if b { - return "ON" - } - return "OFF" -} - // we only support MySQL now var defaultSysVars = []*SysVar{ {ScopeGlobal, "gtid_mode", "OFF"}, diff --git a/tidb-server/main.go b/tidb-server/main.go index 4137a8037b5fe..05684dd7c781d 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -418,6 +418,12 @@ func validateConfig() { os.Exit(-1) } } +func boolToStatusStr(b bool) string { + if b { + return "ON" + } + return "OFF" +} func setGlobalVars() { ddlLeaseDuration := parseDuration(cfg.Lease) @@ -439,7 +445,7 @@ func setGlobalVars() { variable.SysVars[variable.TIDBMemQuotaQuery].Value = strconv.FormatInt(cfg.MemQuotaQuery, 10) variable.SysVars["lower_case_table_names"].Value = strconv.Itoa(cfg.LowerCaseTableNames) - variable.SysVars["log_bin"].Value = variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable) + variable.SysVars["log_bin"].Value = boolToStatusStr(config.GetGlobalConfig().Binlog.Enable) // For CI environment we default enable prepare-plan-cache. plannercore.SetPreparedPlanCache(config.CheckTableBeforeDrop || cfg.PreparedPlanCache.Enabled) From b682f9377eb6e8c719bc1b6149972e18239516f6 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 18:17:23 +0800 Subject: [PATCH 06/17] add a Blank in Comment of variable 'LogBin' --- sessionctx/variable/sysvar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 1e1ea9fd46cc7..889e6ad23b1f0 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -741,7 +741,7 @@ const ( InnodbLockWaitTimeout = "innodb_lock_wait_timeout" // SQLLogBin is the name for 'sql_log_bin' system variable. SQLLogBin = "sql_log_bin" - //LogBin is the name for 'log_bin' system variable. + // LogBin is the name for 'log_bin' system variable. LogBin = "log_bin" // MaxSortLength is the name for 'max_sort_length' system variable. MaxSortLength = "max_sort_length" From 6b8a50441562e7c5db0fd08d8a12f1b06e78dc80 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 18:31:48 +0800 Subject: [PATCH 07/17] abstract a method transfer bool to status str ,like "ON" or "OFF" --- executor/set_test.go | 8 +------- sessionctx/variable/sysvar.go | 6 ++++++ tidb-server/main.go | 12 +++--------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index 5082b02e0fa24..b9ec3ab5e7b7b 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -232,7 +232,7 @@ 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(boolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows(variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) tk.MustExec("set @@tidb_general_log = 1") tk.MustExec("set @@tidb_general_log = 0") @@ -599,9 +599,3 @@ func (s *testSuite2) TestSelectGlobalVar(c *C) { _, err = tk.Exec("select @@global.invalid") c.Assert(terror.ErrorEqual(err, variable.UnknownSystemVar), IsTrue, Commentf("err %v", err)) } -func boolToStatusStr(b bool) string { - if b { - return "ON" - } - return "OFF" -} diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 889e6ad23b1f0..3dbf191580f34 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -114,6 +114,12 @@ func boolToIntStr(b bool) string { } return "0" } +func BoolToStatusStr(b bool) string { + if b { + return "ON" + } + return "OFF" +} // we only support MySQL now var defaultSysVars = []*SysVar{ diff --git a/tidb-server/main.go b/tidb-server/main.go index 05684dd7c781d..595fd6f526984 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -24,11 +24,11 @@ import ( "sync/atomic" "time" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/terror" - pd "github.com/pingcap/pd/client" + "github.com/pingcap/pd/client" pumpcli "github.com/pingcap/tidb-tools/tidb-binlog/pump_client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" @@ -418,12 +418,6 @@ func validateConfig() { os.Exit(-1) } } -func boolToStatusStr(b bool) string { - if b { - return "ON" - } - return "OFF" -} func setGlobalVars() { ddlLeaseDuration := parseDuration(cfg.Lease) @@ -445,7 +439,7 @@ func setGlobalVars() { variable.SysVars[variable.TIDBMemQuotaQuery].Value = strconv.FormatInt(cfg.MemQuotaQuery, 10) variable.SysVars["lower_case_table_names"].Value = strconv.Itoa(cfg.LowerCaseTableNames) - variable.SysVars["log_bin"].Value = boolToStatusStr(config.GetGlobalConfig().Binlog.Enable) + variable.SysVars[variable.LogBin].Value = variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable) // For CI environment we default enable prepare-plan-cache. plannercore.SetPreparedPlanCache(config.CheckTableBeforeDrop || cfg.PreparedPlanCache.Enabled) From 13d63e943dce37ba717c7ef50d888b6a9253f97b Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 18:38:45 +0800 Subject: [PATCH 08/17] add Comment for BoolToStatusStr --- sessionctx/variable/sysvar.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 3dbf191580f34..b57ce89f15a95 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -108,6 +108,7 @@ func init() { terror.ErrClassToMySQLCodes[terror.ClassVariable] = mySQLErrCodes } +// BoolToStatusStr converts bool to string,for example "ON" or "OFF" func boolToIntStr(b bool) string { if b { return "1" From 8d8d596c0af4f0b2f4a1e670475e69061342661c Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 18:44:41 +0800 Subject: [PATCH 09/17] add Comment for BoolToStatusStr --- sessionctx/variable/sysvar.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index b57ce89f15a95..4b4bb29ac3948 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -108,13 +108,14 @@ func init() { terror.ErrClassToMySQLCodes[terror.ClassVariable] = mySQLErrCodes } -// BoolToStatusStr converts bool to string,for example "ON" or "OFF" func boolToIntStr(b bool) string { if b { return "1" } return "0" } + +// BoolToStatusStr converts bool to string,for example "ON" or "OFF". func BoolToStatusStr(b bool) string { if b { return "ON" From 4566842bcf74a68021a08cd03e2c165c76217e83 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 18:55:37 +0800 Subject: [PATCH 10/17] import Alias --- tidb-server/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tidb-server/main.go b/tidb-server/main.go index 595fd6f526984..a2eeed002e9c4 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -24,11 +24,11 @@ import ( "sync/atomic" "time" - "github.com/opentracing/opentracing-go" + opentracing "github.com/opentracing/opentracing-go" "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/terror" - "github.com/pingcap/pd/client" + pd "github.com/pingcap/pd/client" pumpcli "github.com/pingcap/tidb-tools/tidb-binlog/pump_client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" From 054cb187109aa678b4f8d074e113238d7aee6860 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Mon, 18 Feb 2019 19:03:20 +0800 Subject: [PATCH 11/17] please add a blank after , --- sessionctx/variable/sysvar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 4b4bb29ac3948..077f68bc3b473 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -115,7 +115,7 @@ func boolToIntStr(b bool) string { return "0" } -// BoolToStatusStr converts bool to string,for example "ON" or "OFF". +// BoolToStatusStr converts bool to string, for example "ON" or "OFF". func BoolToStatusStr(b bool) string { if b { return "ON" From feea00ecb1081816bb5a4e656f992a5f05d64581 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Tue, 19 Feb 2019 10:27:26 +0800 Subject: [PATCH 12/17] add a test case for 'log_bin' --- executor/set_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/executor/set_test.go b/executor/set_test.go index b9ec3ab5e7b7b..c158b36e0df08 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -233,6 +233,7 @@ func (s *testSuite2) TestSetVar(c *C) { tk.MustQuery(`select @@session.sql_log_bin;`).Check(testkit.Rows("1")) tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows(variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) + tk.MustQuery(`select @@log_bin;`).Check(testkit.Rows(variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) tk.MustExec("set @@tidb_general_log = 1") tk.MustExec("set @@tidb_general_log = 0") From f862b4c16460d2db9ef5497007f4cd092ce1f4b9 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Tue, 19 Feb 2019 11:49:14 +0800 Subject: [PATCH 13/17] move merge case 'LogBin' to case 'TiDBEnableTablePartition' --- sessionctx/variable/varsutil.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 0fa545aaffbac..1f8ea7d4bdd08 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -340,15 +340,6 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return "0", nil } return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) - case LogBin: - if strings.EqualFold(value, "ON") || value == "1" { - return "ON", nil - } - if strings.EqualFold(value, "OFF") || value == "0" { - return "OFF", nil - } - return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) - case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown, TiDBOptInSubqToJoinAndAgg, TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming, @@ -357,7 +348,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return value, nil } return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) - case TiDBEnableTablePartition: + case TiDBEnableTablePartition, LogBin: switch { case strings.EqualFold(value, "ON") || value == "1": return "on", nil From 82e7be3f13654c119d82394a55de8c62954e0762 Mon Sep 17 00:00:00 2001 From: aliiohs Date: Tue, 19 Feb 2019 15:40:09 +0800 Subject: [PATCH 14/17] 'LogBin' still keep an independent case --- sessionctx/variable/varsutil.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 1f8ea7d4bdd08..0fa545aaffbac 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -340,6 +340,15 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return "0", nil } return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) + case LogBin: + if strings.EqualFold(value, "ON") || value == "1" { + return "ON", nil + } + if strings.EqualFold(value, "OFF") || value == "0" { + return "OFF", nil + } + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) + case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown, TiDBOptInSubqToJoinAndAgg, TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming, @@ -348,7 +357,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return value, nil } return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) - case TiDBEnableTablePartition, LogBin: + case TiDBEnableTablePartition: switch { case strings.EqualFold(value, "ON") || value == "1": return "on", nil From fe017458f986835bc3523d4ddb5c56272006d07c Mon Sep 17 00:00:00 2001 From: aliiohs Date: Tue, 19 Feb 2019 20:19:12 +0800 Subject: [PATCH 15/17] change LogBin Status from "ON" or "OFF" to "0" or "1". --- executor/set_test.go | 4 ++-- sessionctx/variable/sysvar.go | 35 +++++++++++++-------------------- sessionctx/variable/varsutil.go | 14 +++---------- tidb-server/main.go | 2 +- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index c158b36e0df08..ecc125a9ad818 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -232,8 +232,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.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) - tk.MustQuery(`select @@log_bin;`).Check(testkit.Rows(variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable))) + tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Rows(variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable))) + tk.MustQuery(`select @@log_bin;`).Check(testkit.Rows(variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable))) tk.MustExec("set @@tidb_general_log = 1") tk.MustExec("set @@tidb_general_log = 0") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 077f68bc3b473..0207251c5a438 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -108,21 +108,14 @@ func init() { terror.ErrClassToMySQLCodes[terror.ClassVariable] = mySQLErrCodes } -func boolToIntStr(b bool) string { +// BoolToIntStr converts bool to int string, for example "0" or "1". +func BoolToIntStr(b bool) string { if b { return "1" } return "0" } -// BoolToStatusStr converts bool to string, for example "ON" or "OFF". -func BoolToStatusStr(b bool) string { - if b { - return "ON" - } - return "OFF" -} - // we only support MySQL now var defaultSysVars = []*SysVar{ {ScopeGlobal, "gtid_mode", "OFF"}, @@ -394,7 +387,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "log_syslog_include_pid", ""}, {ScopeSession, "last_insert_id", ""}, {ScopeNone, "innodb_ft_cache_size", "8000000"}, - {ScopeNone, LogBin, "OFF"}, + {ScopeNone, LogBin, "0"}, {ScopeGlobal, "innodb_disable_sort_file_cache", "OFF"}, {ScopeGlobal, "log_error_verbosity", ""}, {ScopeNone, "performance_schema_hosts_size", "100"}, @@ -635,24 +628,24 @@ var defaultSysVars = []*SysVar{ {ScopeSession, ErrorCount, "0"}, /* TiDB specific variables */ {ScopeSession, TiDBSnapshot, ""}, - {ScopeSession, TiDBOptAggPushDown, boolToIntStr(DefOptAggPushDown)}, - {ScopeSession, TiDBOptWriteRowID, boolToIntStr(DefOptWriteRowID)}, + {ScopeSession, TiDBOptAggPushDown, BoolToIntStr(DefOptAggPushDown)}, + {ScopeSession, TiDBOptWriteRowID, BoolToIntStr(DefOptWriteRowID)}, {ScopeGlobal | ScopeSession, TiDBBuildStatsConcurrency, strconv.Itoa(DefBuildStatsConcurrency)}, {ScopeGlobal, TiDBAutoAnalyzeRatio, strconv.FormatFloat(DefAutoAnalyzeRatio, 'f', -1, 64)}, {ScopeGlobal, TiDBAutoAnalyzeStartTime, DefAutoAnalyzeStartTime}, {ScopeGlobal, TiDBAutoAnalyzeEndTime, DefAutoAnalyzeEndTime}, {ScopeSession, TiDBChecksumTableConcurrency, strconv.Itoa(DefChecksumTableConcurrency)}, {ScopeGlobal | ScopeSession, TiDBDistSQLScanConcurrency, strconv.Itoa(DefDistSQLScanConcurrency)}, - {ScopeGlobal | ScopeSession, TiDBOptInSubqToJoinAndAgg, boolToIntStr(DefOptInSubqToJoinAndAgg)}, + {ScopeGlobal | ScopeSession, TiDBOptInSubqToJoinAndAgg, BoolToIntStr(DefOptInSubqToJoinAndAgg)}, {ScopeGlobal | ScopeSession, TiDBIndexJoinBatchSize, strconv.Itoa(DefIndexJoinBatchSize)}, {ScopeGlobal | ScopeSession, TiDBIndexLookupSize, strconv.Itoa(DefIndexLookupSize)}, {ScopeGlobal | ScopeSession, TiDBIndexLookupConcurrency, strconv.Itoa(DefIndexLookupConcurrency)}, {ScopeGlobal | ScopeSession, TiDBIndexLookupJoinConcurrency, strconv.Itoa(DefIndexLookupJoinConcurrency)}, {ScopeGlobal | ScopeSession, TiDBIndexSerialScanConcurrency, strconv.Itoa(DefIndexSerialScanConcurrency)}, - {ScopeGlobal | ScopeSession, TiDBSkipUTF8Check, boolToIntStr(DefSkipUTF8Check)}, - {ScopeSession, TiDBBatchInsert, boolToIntStr(DefBatchInsert)}, - {ScopeSession, TiDBBatchDelete, boolToIntStr(DefBatchDelete)}, - {ScopeSession, TiDBBatchCommit, boolToIntStr(DefBatchCommit)}, + {ScopeGlobal | ScopeSession, TiDBSkipUTF8Check, BoolToIntStr(DefSkipUTF8Check)}, + {ScopeSession, TiDBBatchInsert, BoolToIntStr(DefBatchInsert)}, + {ScopeSession, TiDBBatchDelete, BoolToIntStr(DefBatchDelete)}, + {ScopeSession, TiDBBatchCommit, BoolToIntStr(DefBatchCommit)}, {ScopeSession, TiDBDMLBatchSize, strconv.Itoa(DefDMLBatchSize)}, {ScopeSession, TiDBCurrentTS, strconv.Itoa(DefCurretTS)}, {ScopeGlobal | ScopeSession, TiDBMaxChunkSize, strconv.Itoa(DefMaxChunkSize)}, @@ -675,10 +668,10 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, TiDBHashAggFinalConcurrency, strconv.Itoa(DefTiDBHashAggFinalConcurrency)}, {ScopeGlobal | ScopeSession, TiDBBackoffLockFast, strconv.Itoa(kv.DefBackoffLockFast)}, {ScopeGlobal | ScopeSession, TiDBRetryLimit, strconv.Itoa(DefTiDBRetryLimit)}, - {ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, boolToIntStr(DefTiDBDisableTxnAutoRetry)}, - {ScopeGlobal | ScopeSession, TiDBConstraintCheckInPlace, boolToIntStr(DefTiDBConstraintCheckInPlace)}, + {ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, BoolToIntStr(DefTiDBDisableTxnAutoRetry)}, + {ScopeGlobal | ScopeSession, TiDBConstraintCheckInPlace, BoolToIntStr(DefTiDBConstraintCheckInPlace)}, {ScopeSession, TiDBOptimizerSelectivityLevel, strconv.Itoa(DefTiDBOptimizerSelectivityLevel)}, - {ScopeGlobal | ScopeSession, TiDBEnableWindowFunction, boolToIntStr(DefEnableWindowFunction)}, + {ScopeGlobal | ScopeSession, TiDBEnableWindowFunction, BoolToIntStr(DefEnableWindowFunction)}, /* The following variable is defined as session scope but is actually server scope. */ {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, {ScopeSession, TiDBSlowLogThreshold, strconv.Itoa(logutil.DefaultSlowThreshold)}, @@ -688,7 +681,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, TiDBDDLReorgBatchSize, strconv.Itoa(DefTiDBDDLReorgBatchSize)}, {ScopeSession, TiDBDDLReorgPriority, "PRIORITY_LOW"}, {ScopeSession, TiDBForcePriority, mysql.Priority2Str[DefTiDBForcePriority]}, - {ScopeSession, TiDBEnableRadixJoin, boolToIntStr(DefTiDBUseRadixJoin)}, + {ScopeSession, TiDBEnableRadixJoin, BoolToIntStr(DefTiDBUseRadixJoin)}, } // SynonymsSysVariables is synonyms of system variables. diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 0fa545aaffbac..5431d126b5df8 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -332,23 +332,15 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return checkUInt64SystemVar(name, value, 0, math.MaxUint64, vars) case WarningCount, ErrorCount: return value, ErrReadOnly.GenWithStackByArgs(name) - case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, - PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, SQLSafeUpdates, TiDBConstraintCheckInPlace: + case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin, + CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, PseudoSlaveMode, LowPriorityUpdates, + SkipNameResolve, SQLSafeUpdates, TiDBConstraintCheckInPlace: if strings.EqualFold(value, "ON") || value == "1" { return "1", nil } else if strings.EqualFold(value, "OFF") || value == "0" { return "0", nil } return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) - case LogBin: - if strings.EqualFold(value, "ON") || value == "1" { - return "ON", nil - } - if strings.EqualFold(value, "OFF") || value == "0" { - return "OFF", nil - } - return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) - case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown, TiDBOptInSubqToJoinAndAgg, TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming, diff --git a/tidb-server/main.go b/tidb-server/main.go index a2eeed002e9c4..9528f3f553653 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -439,7 +439,7 @@ func setGlobalVars() { variable.SysVars[variable.TIDBMemQuotaQuery].Value = strconv.FormatInt(cfg.MemQuotaQuery, 10) variable.SysVars["lower_case_table_names"].Value = strconv.Itoa(cfg.LowerCaseTableNames) - variable.SysVars[variable.LogBin].Value = variable.BoolToStatusStr(config.GetGlobalConfig().Binlog.Enable) + variable.SysVars[variable.LogBin].Value = variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable) // For CI environment we default enable prepare-plan-cache. plannercore.SetPreparedPlanCache(config.CheckTableBeforeDrop || cfg.PreparedPlanCache.Enabled) From 65943a98e4a3958576af256b0e5051658e17f03e Mon Sep 17 00:00:00 2001 From: aliiohs Date: Tue, 19 Feb 2019 20:51:59 +0800 Subject: [PATCH 16/17] change status of'LogBin' from 'on/off' to '0/1'. --- sessionctx/variable/varsutil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 8166af7740d8f..63b6cd29e04cf 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -111,7 +111,7 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) { case PluginLoad: return config.GetGlobalConfig().Plugin.Load, true, nil case TiDBCheckMb4ValueInUtf8: - return boolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUtf8), true, nil + return BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUtf8), true, nil } sVal, ok := s.systems[key] if ok { From 4f7b4b0ad7623c6f3bfeb0a26611d5b9f44adf3b Mon Sep 17 00:00:00 2001 From: aliiohs Date: Wed, 20 Feb 2019 11:02:09 +0800 Subject: [PATCH 17/17] eep the sys libs seperate with the 3rd libs. --- executor/set_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/set_test.go b/executor/set_test.go index ecc125a9ad818..afface4eb3908 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -15,10 +15,10 @@ package executor_test import ( "context" - "github.com/pingcap/tidb/config" . "github.com/pingcap/check" "github.com/pingcap/parser/terror" + "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/testkit"