Skip to content

Commit

Permalink
Change error information
Browse files Browse the repository at this point in the history
  • Loading branch information
CbcWestwolf committed Jun 20, 2022
1 parent 1015d53 commit 8a0a06d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
27 changes: 5 additions & 22 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 8a0a06d

Please sign in to comment.