From 46724b04f14648d54409234ecc7c36c3e02dc3ed Mon Sep 17 00:00:00 2001 From: Yifan Xu <30385241+xuyifangreeneyes@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:02:19 +0800 Subject: [PATCH] This is an automated cherry-pick of #40284 Signed-off-by: ti-chi-bot --- server/server.go | 16 ++++++++++++++++ tidb-server/main.go | 3 +++ 2 files changed, 19 insertions(+) diff --git a/server/server.go b/server/server.go index 43a479fbd5efa..e9916d6e376b1 100644 --- a/server/server.go +++ b/server/server.go @@ -701,6 +701,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.") @@ -714,6 +725,11 @@ func (s *Server) KillAllConnections() { } killConn(conn) } +<<<<<<< HEAD +======= + + s.KillSysProcesses() +>>>>>>> 62a713394f (server, tidb-server: kill auto analyze when gracefully shutting down (#40284)) } var gracefulCloseConnectionsTimeout = 15 * time.Second diff --git a/tidb-server/main.go b/tidb-server/main.go index 9e0989b564269..723747b801d90 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -720,6 +720,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() }