Skip to content

Commit

Permalink
kill auto analyze when gracefully shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyifangreeneyes authored and ti-chi-bot committed Jan 4, 2023
1 parent 706c3fa commit a13454e
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 @@ -790,6 +790,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 @@ -804,12 +815,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 @@ -822,6 +822,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 a13454e

Please sign in to comment.