From 07339a53b0db026cf2313217fb41ced9f73f8f19 Mon Sep 17 00:00:00 2001 From: Ryan Lv Date: Mon, 23 Sep 2019 15:40:07 +0800 Subject: [PATCH] Complete correctness for system variables ## What Add restriction for system variable `thread_pool_size`. ## Reference 1. [MySQL global variable: thread_pool_size](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_version_compile_os) 2. [TiDB guide to cover more restrictions on system variable ](https://github.com/pingcap/tidb/issues/7195) --- executor/set_test.go | 13 +++++++++++++ sessionctx/variable/sysvar.go | 3 +++ sessionctx/variable/varsutil.go | 2 ++ 3 files changed, 18 insertions(+) diff --git a/executor/set_test.go b/executor/set_test.go index 6fefbdadc10b0..3ec8226f59c98 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -502,6 +502,19 @@ func (s *testSuite2) TestValidateSetVar(c *C) { _, err = tk.Exec("set @@global.max_connections='hello'") c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) + tk.MustExec("set @@global.thread_pool_size=65") + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect thread_pool_size value: '65'")) + result = tk.MustQuery("select @@global.thread_pool_size;") + result.Check(testkit.Rows("64")) + + tk.MustExec("set @@global.thread_pool_size=-1") + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect thread_pool_size value: '-1'")) + result = tk.MustQuery("select @@global.thread_pool_size;") + result.Check(testkit.Rows("1")) + + _, err = tk.Exec("set @@global.thread_pool_size='hello'") + c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) + tk.MustExec("set @@global.max_allowed_packet=-1") tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '-1'")) result = tk.MustQuery("select @@global.max_allowed_packet;") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 5b97fa5e7d168..ef64c6e0ebe4c 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -638,6 +638,7 @@ var defaultSysVars = []*SysVar{ {ScopeSession, WarningCount, "0"}, {ScopeSession, ErrorCount, "0"}, {ScopeGlobal | ScopeSession, "information_schema_stats_expiry", "86400"}, + {ScopeGlobal, "thread_pool_size", "16"}, /* TiDB specific variables */ {ScopeSession, TiDBSnapshot, ""}, {ScopeSession, TiDBOptAggPushDown, BoolToIntStr(DefOptAggPushDown)}, @@ -971,6 +972,8 @@ const ( CollationServer = "collation_server" // NetWriteTimeout is the name of 'net_write_timeout' variable. NetWriteTimeout = "net_write_timeout" + // ThreadPoolSize is the name of 'thread_pool_size' variable. + ThreadPoolSize = "thread_pool_size" ) // GlobalVarAccessor is the interface for accessing global scope system and status variables. diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index e02efe3ed51d5..800c4449f94e0 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -425,6 +425,8 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) case MaxExecutionTime: return checkUInt64SystemVar(name, value, 0, math.MaxUint64, vars) + case ThreadPoolSize: + return checkUInt64SystemVar(name, value, 1, 64, vars) case TiDBEnableTablePartition: switch { case strings.EqualFold(value, "ON") || value == "1":