From 17e6297aeecf264c8c75c89d9824e8be3f025812 Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Thu, 24 Nov 2022 17:30:42 +0800 Subject: [PATCH] test --- executor/adapter.go | 4 ++-- sessionctx/stmtctx/stmtctx.go | 9 +++++++++ sessionctx/variable/session.go | 6 ++++++ util/expensivequery/expensivequery.go | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index 3dd0e0ce0877e..8157c74bacfc7 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -1453,7 +1453,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { tikvExecDetail = *(tikvExecDetailRaw.(*util.ExecDetails)) } execDetail := stmtCtx.GetExecDetails() - copTaskInfo := stmtCtx.CopTasksDetails() + copTaskInfo := &stmtctx.CopTasksDetails{} statsInfos := plannercore.GetStatsInfoFromFlatPlan(flat) memMax := sessVars.MemTracker.MaxConsumed() diskMax := sessVars.DiskTracker.MaxConsumed() @@ -1730,7 +1730,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) { } execDetail := stmtCtx.GetExecDetails() - copTaskInfo := stmtCtx.CopTasksDetails() + copTaskInfo := &stmtctx.CopTasksDetails{} memMax := sessVars.MemTracker.MaxConsumed() diskMax := sessVars.DiskTracker.MaxConsumed() sql := a.GetTextToLog() diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index a9720062f4b4a..303a297aab38c 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -17,6 +17,7 @@ package stmtctx import ( "bytes" "encoding/json" + "github.com/pingcap/tidb/util/logutil" "math" "strconv" "sync" @@ -988,8 +989,16 @@ func (sc *StatementContext) PushDownFlags() uint64 { // CopTasksDetails returns some useful information of cop-tasks during execution. func (sc *StatementContext) CopTasksDetails() *CopTasksDetails { + if !sc.InRestrictedSQL { + logutil.BgLogger().Error("coptasks details sleep 1111111111") + time.Sleep(5 * time.Second) + } sc.mu.Lock() defer sc.mu.Unlock() + if !sc.InRestrictedSQL { + logutil.BgLogger().Error("coptasks details sleep 22222222") + time.Sleep(10 * time.Second) + } n := len(sc.mu.allExecDetails) d := &CopTasksDetails{ NumCopTasks: n, diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 9c34e40154e43..11d70697367ca 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -20,6 +20,7 @@ import ( "crypto/tls" "encoding/binary" "fmt" + "github.com/pingcap/tidb/util/logutil" "math" "math/rand" "net" @@ -1388,12 +1389,17 @@ func (s *SessionVars) InitStatementContext() *stmtctx.StatementContext { if sc == s.StmtCtx { sc = &s.cachedStmtCtx[1] } + isFirst := sc == &s.cachedStmtCtx[0] if s.RefCountOfStmtCtx.TryFreeze() { *sc = stmtctx.StatementContext{} s.RefCountOfStmtCtx.UnFreeze() } else { sc = &stmtctx.StatementContext{} } + if isFirst && !sc.InRestrictedSQL && s.ConnectionID != 0 { + logutil.BgLogger().Error("InitStatementContext[0] sleep") + time.Sleep(15 * time.Second) + } return sc } diff --git a/util/expensivequery/expensivequery.go b/util/expensivequery/expensivequery.go index aff2f3be7829d..9668c7466ad04 100644 --- a/util/expensivequery/expensivequery.go +++ b/util/expensivequery/expensivequery.go @@ -62,6 +62,7 @@ func (eqh *Handle) Run() { } costTime := time.Since(info.Time) + threshold = uint64(2) if !info.ExceedExpensiveTimeThresh && costTime >= time.Second*time.Duration(threshold) && log.GetLevel() <= zapcore.WarnLevel { logExpensiveQuery(costTime, info, "expensive_query") info.ExceedExpensiveTimeThresh = true