Skip to content

Commit

Permalink
executor: support plan replayer capture <sql> <*> (#39754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer authored Dec 8, 2022
1 parent 6784bfd commit 631f32d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions domain/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ func (r *planReplayerDumpTaskStatus) GetRunningTaskStatusLen() int {
return len(r.runningTaskMu.runningTasks)
}

// CleanFinishedTaskStatus clean then finished tasks, only used for unit test
func (r *planReplayerDumpTaskStatus) CleanFinishedTaskStatus() {
r.finishedTaskMu.Lock()
defer r.finishedTaskMu.Unlock()
r.finishedTaskMu.finishedTask = map[PlanReplayerTaskKey]struct{}{}
}

// GetFinishedTaskStatusLen used for unit test
func (r *planReplayerDumpTaskStatus) GetFinishedTaskStatusLen() int {
r.finishedTaskMu.RLock()
Expand Down
19 changes: 19 additions & 0 deletions domain/plan_replayer_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ func TestPlanReplayerHandleDumpTask(t *testing.T) {
err = prHandle.CollectPlanReplayerTask()
require.NoError(t, err)
require.Len(t, prHandle.GetTasks(), 0)

// clean the task and register task
prHandle.GetTaskStatus().CleanFinishedTaskStatus()
tk.MustExec("delete from mysql.plan_replayer_task")
tk.MustExec("delete from mysql.plan_replayer_status")
tk.MustExec(fmt.Sprintf("insert into mysql.plan_replayer_task (sql_digest, plan_digest) values ('%v','%v');", sqlDigest, "*"))
err = prHandle.CollectPlanReplayerTask()
require.NoError(t, err)
require.Len(t, prHandle.GetTasks(), 1)
tk.MustQuery("select * from t;")
task = prHandle.DrainTask()
require.NotNil(t, task)
worker = prHandle.GetWorker()
success = worker.HandleTask(task)
require.True(t, success)
require.Equal(t, prHandle.GetTaskStatus().GetRunningTaskStatusLen(), 0)
require.Equal(t, prHandle.GetTaskStatus().GetFinishedTaskStatusLen(), 1)
// assert capture * task still remained
require.Len(t, prHandle.GetTasks(), 1)
}
8 changes: 5 additions & 3 deletions executor/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ func checkPlanReplayerCaptureTask(sctx sessionctx.Context, stmtNode ast.StmtNode
_, sqlDigest := sctx.GetSessionVars().StmtCtx.SQLDigest()
_, planDigest := getPlanDigest(sctx.GetSessionVars().StmtCtx)
for _, task := range tasks {
if task.SQLDigest == sqlDigest.String() && task.PlanDigest == planDigest.String() {
sendPlanReplayerDumpTask(sqlDigest.String(), planDigest.String(), sctx, stmtNode)
return
if task.SQLDigest == sqlDigest.String() {
if task.PlanDigest == "*" || task.PlanDigest == planDigest.String() {
sendPlanReplayerDumpTask(sqlDigest.String(), planDigest.String(), sctx, stmtNode)
return
}
}
}
}
Expand Down

0 comments on commit 631f32d

Please sign in to comment.