Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu committed Nov 24, 2022
1 parent 68e46cb commit 17e6297
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package stmtctx
import (
"bytes"
"encoding/json"
"github.com/pingcap/tidb/util/logutil"
"math"
"strconv"
"sync"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"encoding/binary"
"fmt"
"github.com/pingcap/tidb/util/logutil"
"math"
"math/rand"
"net"
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions util/expensivequery/expensivequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17e6297

Please sign in to comment.