Skip to content

Commit

Permalink
Complete correctness for system variables
Browse files Browse the repository at this point in the history
## 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  ](pingcap#7195)
  • Loading branch information
xiaoronglv committed Sep 23, 2019
1 parent 14df525 commit 07339a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 07339a5

Please sign in to comment.