Skip to content

Commit

Permalink
disttask: batch insert subtasks (#47207)
Browse files Browse the repository at this point in the history
ref #46258, close #47178
  • Loading branch information
ywqzzy authored Sep 25, 2023
1 parent 34438f8 commit 5f8be45
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions disttask/framework/storage/task_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,16 +668,26 @@ func (stm *TaskManager) UpdateGlobalTaskAndAddSubTasks(gTask *proto.Task, subtas
subtaskState = proto.TaskStateRevertPending
}

for _, subtask := range subtasks {
// TODO: insert subtasks in batch
_, err = ExecSQL(stm.ctx, se, `insert into mysql.tidb_background_subtask
(step, task_key, exec_id, meta, state, type, checkpoint, summary)
values (%?, %?, %?, %?, %?, %?, %?, %?)`,
subtask.Step, gTask.ID, subtask.SchedulerID, subtask.Meta, subtaskState, proto.Type2Int(subtask.Type), []byte{}, "{}")
if err != nil {
sql := new(strings.Builder)
if err := sqlexec.FormatSQL(sql, "insert into mysql.tidb_background_subtask \n"+
"(step, task_key, exec_id, meta, state, type, checkpoint, summary) values "); err != nil {
return err
}
for i, subtask := range subtasks {
if i != 0 {
if err := sqlexec.FormatSQL(sql, ","); err != nil {
return err
}
}
if err := sqlexec.FormatSQL(sql, "(%?, %?, %?, %?, %?, %?, %?, %?)",
subtask.Step, gTask.ID, subtask.SchedulerID, subtask.Meta, subtaskState, proto.Type2Int(subtask.Type), []byte{}, "{}"); err != nil {
return err
}
}
_, err := ExecSQL(stm.ctx, se, sql.String())
if err != nil {
return nil
}
}
return nil
})
Expand Down

0 comments on commit 5f8be45

Please sign in to comment.