Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server, tidb-server: kill auto analyze when gracefully shutting down (#40284) #40302

Merged
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