Skip to content

Commit

Permalink
*: support variable log_bin (#9634)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXiangUSTC authored and jackysp committed Mar 11, 2019
1 parent 449ade9 commit e21d15e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package executor_test
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/variable"
"github.com/pingcap/tidb/util/testkit"
Expand Down Expand Up @@ -219,6 +220,9 @@ func (s *testSuite) 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)))
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")

Expand Down
25 changes: 14 additions & 11 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ 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"
}
Expand Down Expand Up @@ -378,7 +379,7 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal, "log_syslog_include_pid", ""},
{ScopeSession, "last_insert_id", ""},
{ScopeNone, "innodb_ft_cache_size", "8000000"},
{ScopeNone, "log_bin", "OFF"},
{ScopeNone, LogBin, "0"},
{ScopeGlobal, "innodb_disable_sort_file_cache", "OFF"},
{ScopeGlobal, "log_error_verbosity", ""},
{ScopeNone, "performance_schema_hosts_size", "100"},
Expand Down Expand Up @@ -620,23 +621,23 @@ 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, TiDBOptInSubqUnFolding, boolToIntStr(DefOptInSubqUnfolding)},
{ScopeGlobal | ScopeSession, TiDBOptInSubqUnFolding, BoolToIntStr(DefOptInSubqUnfolding)},
{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)},
{ScopeGlobal | ScopeSession, TiDBSkipUTF8Check, BoolToIntStr(DefSkipUTF8Check)},
{ScopeSession, TiDBBatchInsert, BoolToIntStr(DefBatchInsert)},
{ScopeSession, TiDBBatchDelete, BoolToIntStr(DefBatchDelete)},
{ScopeSession, TiDBDMLBatchSize, strconv.Itoa(DefDMLBatchSize)},
{ScopeSession, TiDBCurrentTS, strconv.Itoa(DefCurretTS)},
{ScopeGlobal | ScopeSession, TiDBMaxChunkSize, strconv.Itoa(DefMaxChunkSize)},
Expand All @@ -657,8 +658,8 @@ 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)},
/* The following variable is defined as session scope but is actually server scope. */
{ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)},
Expand All @@ -669,7 +670,7 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal, TiDBDDLReorgBatchSize, strconv.Itoa(DefTiDBDDLReorgBatchSize)},
{ScopeSession, TiDBDDLReorgPriority, "PRIORITY_LOW"},
{ScopeSession, TiDBForcePriority, mysql.Priority2Str[DefTiDBForcePriority]},
{ScopeSession, TiDBCheckMb4ValueInUtf8, boolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUtf8)},
{ScopeSession, TiDBCheckMb4ValueInUtf8, BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUtf8)},
}

// SynonymsSysVariables is synonyms of system variables.
Expand Down Expand Up @@ -728,6 +729,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.
Expand Down
5 changes: 3 additions & 2 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) {
case TiDBQueryLogMaxLen:
return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Log.QueryLogMaxLen), 10), 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 {
Expand Down Expand Up @@ -310,7 +310,8 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
return value, err
case WarningCount, ErrorCount:
return value, ErrReadOnly.GenWithStackByArgs(name)
case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode,

case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode,
PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBConstraintCheckInPlace:
if strings.EqualFold(value, "ON") || value == "1" {
return "1", nil
Expand Down
1 change: 1 addition & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable)

// For CI environment we default enable prepare-plan-cache.
plannercore.SetPreparedPlanCache(config.CheckTableBeforeDrop || cfg.PreparedPlanCache.Enabled)
Expand Down

0 comments on commit e21d15e

Please sign in to comment.