diff --git a/server/server.go b/server/server.go index e4a009f7f1937..aa5a5f744d38b 100644 --- a/server/server.go +++ b/server/server.go @@ -302,7 +302,6 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) { rand.Seed(time.Now().UTC().UnixNano()) variable.RegisterStatistics(s) - variable.SetMaxConnections = s.SetMaxConnections return s, nil } @@ -515,11 +514,14 @@ func (s *Server) onConn(conn *clientConn) { }) terror.Log(err) } - if errors.Cause(err) == io.EOF { + switch errors.Cause(err) { + case io.EOF: // `EOF` means the connection is closed normally, we do not treat it as a noticeable error and log it in 'DEBUG' level. logutil.BgLogger().With(zap.Uint64("conn", conn.connectionID)). Debug("EOF", zap.String("remote addr", conn.bufReadConn.RemoteAddr().String())) - } else { + case errConCount: + _ = conn.writeError(ctx, err) + default: metrics.HandShakeErrorCounter.Inc() logutil.BgLogger().With(zap.Uint64("conn", conn.connectionID)). Warn("Server.onConn handshake", zap.Error(err), @@ -623,25 +625,6 @@ func (s *Server) checkConnectionCount() error { return nil } -// SetMaxConnections checks and updates the value of max_connections. -func (s *Server) SetMaxConnections(newMaxConnections uint32) error { - // When the value of newMaxConnections is 0, the number of connections is unlimited. - if int(newMaxConnections) == 0 { - return nil - } - - s.rwlock.RLock() - conns := len(s.clients) - s.rwlock.RUnlock() - - if conns > int(newMaxConnections) { - logutil.BgLogger().Error("Current connections number exceeds the setting value", - zap.Uint32("max connections", newMaxConnections), zap.Error(errConCount)) - return errConCount - } - return nil -} - // ShowProcessList implements the SessionManager interface. func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo { rs := make(map[uint64]*util.ProcessInfo) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index fd870e912c8d6..01879fde2943c 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -416,13 +416,7 @@ var defaultSysVars = []*SysVar{ return config.GetGlobalConfig().Instance.PluginDir, nil }}, {Scope: ScopeInstance, Name: MaxConnections, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().Instance.MaxConnections), 10), Type: TypeUnsigned, MinValue: 0, MaxValue: 100000, SetGlobal: func(s *SessionVars, val string) error { - newVal := uint32(TidbOptInt64(val, 0)) - if SetMaxConnections != nil { - if err := SetMaxConnections(newVal); err != nil { - return err - } - } - config.GetGlobalConfig().Instance.MaxConnections = newVal + config.GetGlobalConfig().Instance.MaxConnections = uint32(TidbOptInt64(val, 0)) return nil }, GetGlobal: func(s *SessionVars) (string, error) { return strconv.FormatUint(uint64(config.GetGlobalConfig().Instance.MaxConnections), 10), nil diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 657e88d161398..64c1916292c73 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -994,6 +994,4 @@ var ( GetMemQuotaAnalyze func() int64 = nil // SetStatsCacheCapacity is the func registered by domain to set statsCache memory quota. SetStatsCacheCapacity atomic.Value - // SetMaxConnections is the func registered by server to set the value of max_connections. - SetMaxConnections func(newMaxConnections uint32) error = nil )