Skip to content

Commit

Permalink
server: stop the server when writing binlog failed (pingcap#15324) (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp committed Mar 12, 2020
1 parent 340d8e2 commit 5a4cde0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
4 changes: 1 addition & 3 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ var (
EventStart = "start"
EventGracefulDown = "graceful_shutdown"
// Eventkill occurs when the server.Kill() function is called.
EventKill = "kill"
// EventHang occurs when server meet some critical error. It will close the listening port and hang for ever.
EventHang = "hang"
EventKill = "kill"
EventClose = "close"
ServerEventCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Expand Down
7 changes: 1 addition & 6 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,8 @@ func (cc *clientConn) Run(ctx context.Context) {
logutil.Logger(ctx).Error("result undetermined, close this connection", zap.Error(err))
return
} else if terror.ErrCritical.Equal(err) {
logutil.Logger(ctx).Error("critical error, stop the server listener", zap.Error(err))
metrics.CriticalErrorCounter.Add(1)
select {
case cc.server.stopListenerCh <- struct{}{}:
default:
}
return
logutil.Logger(ctx).Fatal("critical error, stop the server", zap.Error(err))
}
logutil.Logger(ctx).Warn("dispatch error",
zap.String("connInfo", cc.String()),
Expand Down
30 changes: 1 addition & 29 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ type Server struct {
concurrentLimiter *TokenLimiter
clients map[uint32]*clientConn
capability uint32

// stopListenerCh is used when a critical error occurred, we don't want to exit the process, because there may be
// a supervisor automatically restart it, then new client connection will be created, but we can't server it.
// So we just stop the listener and store to force clients to chose other TiDB servers.
stopListenerCh chan struct{}
statusServer *http.Server
statusServer *http.Server
}

// ConnectionCount gets current connection count.
Expand Down Expand Up @@ -201,7 +196,6 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
driver: driver,
concurrentLimiter: NewTokenLimiter(cfg.TokenLimit),
clients: make(map[uint32]*clientConn),
stopListenerCh: make(chan struct{}, 1),
}
s.loadTLSCertificates()
setSystemTimeZoneVariable()
Expand Down Expand Up @@ -326,11 +320,6 @@ func (s *Server) Run() error {
logutil.Logger(context.Background()).Error("accept failed", zap.Error(err))
return errors.Trace(err)
}
if s.shouldStopListener() {
err = conn.Close()
terror.Log(errors.Trace(err))
break
}

clientConn := s.newConn(conn)

Expand Down Expand Up @@ -358,23 +347,6 @@ func (s *Server) Run() error {

go s.onConn(clientConn)
}
err := s.listener.Close()
terror.Log(errors.Trace(err))
s.listener = nil
for {
metrics.ServerEventCounter.WithLabelValues(metrics.EventHang).Inc()
logutil.Logger(context.Background()).Error("listener stopped, waiting for manual kill.")
time.Sleep(time.Minute)
}
}

func (s *Server) shouldStopListener() bool {
select {
case <-s.stopListenerCh:
return true
default:
return false
}
}

// Close closes the server.
Expand Down

0 comments on commit 5a4cde0

Please sign in to comment.