Skip to content

Commit

Permalink
server, tidb-server: kill auto analyze when gracefully shutting down (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jan 18, 2023
1 parent 0180126 commit 52c603b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 12 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,17 @@ func killConn(conn *clientConn) {
}
}

// KillSysProcesses kill sys processes such as auto analyze.
func (s *Server) KillSysProcesses() {
if s.dom == nil {
return
}
sysProcTracker := s.dom.SysProcTracker()
for connID := range sysProcTracker.GetSysProcessList() {
sysProcTracker.KillSysProcess(connID)
}
}

// KillAllConnections kills all connections when server is not gracefully shutdown.
func (s *Server) KillAllConnections() {
logutil.BgLogger().Info("[server] kill all connections.")
Expand All @@ -735,12 +746,7 @@ func (s *Server) KillAllConnections() {
killConn(conn)
}

if s.dom != nil {
sysProcTracker := s.dom.SysProcTracker()
for connID := range sysProcTracker.GetSysProcessList() {
sysProcTracker.KillSysProcess(connID)
}
}
s.KillSysProcesses()
}

var gracefulCloseConnectionsTimeout = 15 * time.Second
Expand Down
3 changes: 3 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ func cleanup(svr *server.Server, storage kv.Storage, dom *domain.Domain, gracefu
if graceful {
done := make(chan struct{})
svr.GracefulDown(context.Background(), done)
// Kill sys processes such as auto analyze. Otherwise, tidb-server cannot exit until auto analyze is finished.
// See https://github.com/pingcap/tidb/issues/40038 for details.
svr.KillSysProcesses()
} else {
svr.TryGracefulDown()
}
Expand Down

0 comments on commit 52c603b

Please sign in to comment.