From fe017458f986835bc3523d4ddb5c56272006d07c Mon Sep 17 00:00:00 2001 From: aliiohs Date: Tue, 19 Feb 2019 20:19:12 +0800 Subject: [PATCH] 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)