From d35d3a5820b0db4c7d69a4fcd8c0191e75c0829c Mon Sep 17 00:00:00 2001 From: Keyi Xie Date: Thu, 7 Mar 2019 16:36:11 +0800 Subject: [PATCH] variable: change "ddl_slow_threshold" (#9043) --- executor/set_test.go | 7 +++++++ sessionctx/variable/session.go | 2 ++ sessionctx/variable/sysvar.go | 1 + sessionctx/variable/tidb_vars.go | 14 +++++++++----- sessionctx/variable/varsutil.go | 2 ++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/executor/set_test.go b/executor/set_test.go index afface4eb3908..6fdb59fef08ab 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -138,6 +138,13 @@ func (s *testSuite2) TestSetVar(c *C) { tk.MustExec("set character_set_results = NULL") tk.MustQuery("select @@character_set_results").Check(testkit.Rows("")) + tk.MustExec("set @@session.ddl_slow_threshold=12345") + tk.MustQuery("select @@session.ddl_slow_threshold").Check(testkit.Rows("12345")) + c.Assert(variable.DDLSlowOprThreshold, Equals, uint32(12345)) + tk.MustExec("set session ddl_slow_threshold=\"54321\"") + tk.MustQuery("show variables like 'ddl_slow_threshold'").Check(testkit.Rows("ddl_slow_threshold 54321")) + c.Assert(variable.DDLSlowOprThreshold, Equals, uint32(54321)) + // Test set transaction isolation level, which is equivalent to setting variable "tx_isolation". tk.MustExec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED") tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED")) diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 15f350d2160b6..816b3e327694b 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -667,6 +667,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { atomic.StoreUint32(&ProcessGeneralLog, uint32(tidbOptPositiveInt32(val, DefTiDBGeneralLog))) case TiDBSlowLogThreshold: atomic.StoreUint64(&config.GetGlobalConfig().Log.SlowThreshold, uint64(tidbOptInt64(val, logutil.DefaultSlowThreshold))) + case TiDBDDLSlowOprThreshold: + atomic.StoreUint32(&DDLSlowOprThreshold, uint32(tidbOptPositiveInt32(val, DefTiDBDDLSlowOprThreshold))) case TiDBQueryLogMaxLen: atomic.StoreUint64(&config.GetGlobalConfig().Log.QueryLogMaxLen, uint64(tidbOptInt64(val, logutil.DefaultQueryLogMaxLen))) case TiDBRetryLimit: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index fd454c1b52334..ecbad582c5014 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -675,6 +675,7 @@ var defaultSysVars = []*SysVar{ /* The following variable is defined as session scope but is actually server scope. */ {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, {ScopeSession, TiDBSlowLogThreshold, strconv.Itoa(logutil.DefaultSlowThreshold)}, + {ScopeSession, TiDBDDLSlowOprThreshold, strconv.Itoa(DefTiDBDDLSlowOprThreshold)}, {ScopeSession, TiDBQueryLogMaxLen, strconv.Itoa(logutil.DefaultQueryLogMaxLen)}, {ScopeSession, TiDBConfig, ""}, {ScopeGlobal, TiDBDDLReorgWorkerCount, strconv.Itoa(DefTiDBDDLReorgWorkerCount)}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index e0eeb79a3a5d4..b6d98ea282c6c 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -34,6 +34,8 @@ import ( // TiDB system variable names that only in session scope. const ( + TiDBDDLSlowOprThreshold = "ddl_slow_threshold" + // tidb_snapshot is used for reading history data, the default value is empty string. // The value can be a datetime string like '2017-11-11 20:20:20' or a tso string. When this variable is set, the session reads history data of that time. TiDBSnapshot = "tidb_snapshot" @@ -285,6 +287,7 @@ const ( DefTiDBForcePriority = mysql.NoPriority DefTiDBUseRadixJoin = false DefEnableWindowFunction = false + DefTiDBDDLSlowOprThreshold = 300 ) // Process global variables. @@ -295,9 +298,10 @@ var ( ddlReorgBatchSize int32 = DefTiDBDDLReorgBatchSize ddlErrorCountlimit int64 = DefTiDBDDLErrorCountLimit // Export for testing. - MaxDDLReorgBatchSize int32 = 10240 - MinDDLReorgBatchSize int32 = 32 - DDLSlowOprThreshold uint32 = 300 // DDLSlowOprThreshold is the threshold for ddl slow operations, uint is millisecond. - ForcePriority = int32(DefTiDBForcePriority) - ServerHostname, _ = os.Hostname() + MaxDDLReorgBatchSize int32 = 10240 + MinDDLReorgBatchSize int32 = 32 + // DDLSlowOprThreshold is the threshold for ddl slow operations, uint is millisecond. + DDLSlowOprThreshold uint32 = DefTiDBDDLSlowOprThreshold + ForcePriority = int32(DefTiDBForcePriority) + ServerHostname, _ = os.Hostname() ) diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 563681749f54d..db8cce5ba7ed9 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -114,6 +114,8 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) { return mysql.Priority2Str[mysql.PriorityEnum(atomic.LoadInt32(&ForcePriority))], true, nil case TiDBSlowLogThreshold: return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Log.SlowThreshold), 10), true, nil + case TiDBDDLSlowOprThreshold: + return strconv.FormatUint(uint64(atomic.LoadUint32(&DDLSlowOprThreshold)), 10), true, nil case TiDBQueryLogMaxLen: return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Log.QueryLogMaxLen), 10), true, nil case PluginDir: