From 808eab19115d81a2940bca87e287dd7e58218c75 Mon Sep 17 00:00:00 2001 From: H Date: Fri, 14 Dec 2018 22:22:25 +0800 Subject: [PATCH] session: support system variable interactive_timeout (#8487) (#8573) --- server/server.go | 2 +- session/session.go | 9 +++++++++ sessionctx/variable/sysvar.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index 5e516493673bb..45a1c3b6e9fad 100644 --- a/server/server.go +++ b/server/server.go @@ -72,7 +72,7 @@ const defaultCapability = mysql.ClientLongPassword | mysql.ClientLongFlag | mysql.ClientConnectWithDB | mysql.ClientProtocol41 | mysql.ClientTransactions | mysql.ClientSecureConnection | mysql.ClientFoundRows | mysql.ClientMultiStatements | mysql.ClientMultiResults | mysql.ClientLocalFiles | - mysql.ClientConnectAtts | mysql.ClientPluginAuth + mysql.ClientConnectAtts | mysql.ClientPluginAuth | mysql.ClientInteractive // Server is the MySQL protocol server type Server struct { diff --git a/session/session.go b/session/session.go index 6a2e3817e1aa5..ccabb386e554a 100644 --- a/session/session.go +++ b/session/session.go @@ -1389,6 +1389,7 @@ const loadCommonGlobalVarsSQL = "select HIGH_PRIORITY * from mysql.global_variab variable.TimeZone + quoteCommaQuote + variable.BlockEncryptionMode + quoteCommaQuote + variable.WaitTimeout + quoteCommaQuote + + variable.InteractiveTimeout + quoteCommaQuote + variable.MaxPreparedStmtCount + quoteCommaQuote + /* TiDB specific global variables: */ variable.TiDBSkipUTF8Check + quoteCommaQuote + @@ -1451,6 +1452,14 @@ func (s *session) loadCommonGlobalVariablesIfNeeded() error { } } } + + // when client set Capability Flags CLIENT_INTERACTIVE, init wait_timeout with interactive_timeout + if vars.ClientCapability&mysql.ClientInteractive > 0 { + if varVal, ok := vars.GetSystemVar(variable.InteractiveTimeout); ok { + vars.SetSystemVar(variable.WaitTimeout, varVal) + } + } + vars.CommonGlobalLoaded = true return nil } diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index eae4fe4b8f284..1e7437931ae78 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -254,7 +254,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, BlockEncryptionMode, "aes-128-ecb"}, {ScopeGlobal | ScopeSession, "max_length_for_sort_data", "1024"}, {ScopeNone, "character_set_system", "utf8"}, - {ScopeGlobal | ScopeSession, "interactive_timeout", "28800"}, + {ScopeGlobal | ScopeSession, InteractiveTimeout, "28800"}, {ScopeGlobal, "innodb_optimize_fulltext_only", "OFF"}, {ScopeNone, "character_sets_dir", "/usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/"}, {ScopeGlobal | ScopeSession, "query_cache_type", "OFF"},