Skip to content

Commit

Permalink
ddl: make CompleteDeleteRange atomic by explicit transaction (#33721)
Browse files Browse the repository at this point in the history
close #33720
  • Loading branch information
wjhuang2016 committed Apr 6, 2022
1 parent bd8c710 commit 94b7069
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ddl/util/util.go
Expand Up @@ -104,14 +104,23 @@ func loadDeleteRangesFromTable(ctx sessionctx.Context, table string, safePoint u
}

// CompleteDeleteRange moves a record from gc_delete_range table to gc_delete_range_done table.
// NOTE: This function WILL NOT start and run in a new transaction internally.
func CompleteDeleteRange(ctx sessionctx.Context, dr DelRangeTask) error {
_, err := ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), recordDoneDeletedRangeSQL, dr.JobID, dr.ElementID)
_, err := ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), "BEGIN")
if err != nil {
return errors.Trace(err)
}

return RemoveFromGCDeleteRange(ctx, dr.JobID, dr.ElementID)
_, err = ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), recordDoneDeletedRangeSQL, dr.JobID, dr.ElementID)
if err != nil {
return errors.Trace(err)
}

err = RemoveFromGCDeleteRange(ctx, dr.JobID, dr.ElementID)
if err != nil {
return errors.Trace(err)
}
_, err = ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), "COMMIT")
return errors.Trace(err)
}

// RemoveFromGCDeleteRange is exported for ddl pkg to use.
Expand Down

0 comments on commit 94b7069

Please sign in to comment.