Skip to content

Commit

Permalink
revise
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer committed Dec 30, 2022
1 parent c00c36b commit bfd25ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
22 changes: 19 additions & 3 deletions domain/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -99,7 +100,7 @@ func (p *dumpFileGcChecker) gcDumpFilesByPath(path string, t time.Duration) {
logutil.BgLogger().Error("[dumpFileGcChecker] parseTime failed", zap.Error(err), zap.String("filename", fileName))
continue
}
isPlanReplayer := parseType(fileName) == "replayer"
isPlanReplayer := strings.Contains(fileName, "replayer")
if !createTime.After(gcTime) {
err := os.Remove(filepath.Join(path, f.Name()))
if err != nil {
Expand Down Expand Up @@ -419,6 +420,19 @@ func (w *planReplayerTaskDumpWorker) HandleTask(task *PlanReplayerDumpTask) (suc
task.Zf = file
task.FileName = fileName
task.EncodedPlan, _ = task.EncodePlan(task.SessionVars.StmtCtx, false)
if task.InExecute && len(task.NormalizedSQL) > 0 {
p := parser.New()
stmts, _, err := p.ParseSQL(task.NormalizedSQL)
if err != nil {
logutil.BgLogger().Warn("[plan-replayer-capture] parse normalized sql failed",
zap.String("sql", task.NormalizedSQL),
zap.String("sqlDigest", taskKey.SQLDigest),
zap.String("planDigest", taskKey.PlanDigest),
zap.Error(err))
return false
}
task.ExecStmts = stmts
}
err = DumpPlanReplayerInfo(w.ctx, w.sctx, task)
if err != nil {
logutil.BgLogger().Warn("[plan-replayer-capture] dump task result failed",
Expand Down Expand Up @@ -512,8 +526,10 @@ type PlanReplayerDumpTask struct {
replayer.PlanReplayerTaskKey

// tmp variables stored during the query
EncodePlan func(*stmtctx.StatementContext, bool) (string, string)
TblStats map[int64]interface{}
EncodePlan func(*stmtctx.StatementContext, bool) (string, string)
TblStats map[int64]interface{}
InExecute bool
NormalizedSQL string

// variables used to dump the plan
StartTS uint64
Expand Down
5 changes: 5 additions & 0 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,5 +2043,10 @@ func sendPlanReplayerDumpTask(key replayer.PlanReplayerTaskKey, sctx sessionctx.
IsCapture: true,
IsContinuesCapture: isContinuesCapture,
}
if _, ok := stmtNode.(*ast.ExecuteStmt); ok {
nsql, _ := sctx.GetSessionVars().StmtCtx.SQLDigest()
dumpTask.InExecute = true
dumpTask.NormalizedSQL = nsql
}
domain.GetDomain(sctx).GetPlanReplayerHandle().SendTask(dumpTask)
}
2 changes: 1 addition & 1 deletion server/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func dumpJSONStatsIntoZip(tbls map[int64]*tblInfo, content []byte, path string)
if err != nil {
return "", err
}
newPath := fmt.Sprintf("copy_%v.zip", path[0:len(path)-4])
newPath := strings.Replace(path, "capture_replayer", "copy_capture_replayer", 1)
zf, err := os.Create(newPath)
if err != nil {
return "", err
Expand Down

0 comments on commit bfd25ac

Please sign in to comment.