From 1587299c46c1551135e6c19a24f4d8813c9841b0 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Thu, 6 Jun 2024 16:07:48 +0800 Subject: [PATCH] add log --- pkg/util/sqlkiller/sqlkiller.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/pkg/util/sqlkiller/sqlkiller.go b/pkg/util/sqlkiller/sqlkiller.go index 9d346bf3d6ab3..2b894313b959e 100644 --- a/pkg/util/sqlkiller/sqlkiller.go +++ b/pkg/util/sqlkiller/sqlkiller.go @@ -47,7 +47,9 @@ type SQLKiller struct { // SendKillSignal sends a kill signal to the query. func (killer *SQLKiller) SendKillSignal(reason killSignal) { if atomic.CompareAndSwapUint32(&killer.Signal, 0, reason) { - logutil.BgLogger().Warn("kill query start", zap.Uint64("conn", killer.ConnID), zap.Uint32("reason", uint32(reason))) + status := atomic.LoadUint32(&killer.Signal) + err := killer.getKillError(status) + logutil.BgLogger().Warn("kill query started", zap.Uint64("conn", killer.ConnID), zap.String("reason", err.Error())) } } @@ -56,6 +58,21 @@ func (killer *SQLKiller) GetKillSignal() killSignal { return killSignal(atomic.LoadUint32(&killer.Signal)) } +// getKillError gets the error according to the kill signal. +func (killer *SQLKiller) getKillError(status killSignal) error { + switch status { + case QueryInterrupted: + return exeerrors.ErrQueryInterrupted.GenWithStackByArgs() + case MaxExecTimeExceeded: + return exeerrors.ErrMaxExecTimeExceeded.GenWithStackByArgs() + case QueryMemoryExceeded: + return exeerrors.ErrMemoryExceedForQuery.GenWithStackByArgs(killer.ConnID) + case ServerMemoryExceeded: + return exeerrors.ErrMemoryExceedForInstance.GenWithStackByArgs(killer.ConnID) + } + return nil +} + // FinishResultSet is used to finish the result set. // If the cancel signal is received and SQL is waiting for network IO, resource released can be performed first. func (killer *SQLKiller) FinishResultSet() { @@ -77,19 +94,13 @@ func (killer *SQLKiller) HandleSignal() error { } }) status := atomic.LoadUint32(&killer.Signal) + err := killer.getKillError(status) switch status { - case QueryInterrupted: - return exeerrors.ErrQueryInterrupted.GenWithStackByArgs() - case MaxExecTimeExceeded: - return exeerrors.ErrMaxExecTimeExceeded.GenWithStackByArgs() - case QueryMemoryExceeded: - return exeerrors.ErrMemoryExceedForQuery.GenWithStackByArgs(killer.ConnID) case ServerMemoryExceeded: logutil.BgLogger().Warn("global memory controller, NeedKill signal is received successfully", zap.Uint64("conn", killer.ConnID)) - return exeerrors.ErrMemoryExceedForInstance.GenWithStackByArgs(killer.ConnID) } - return nil + return err } // Reset resets the SqlKiller.