Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: make CompleteDeleteRange atomic by explicit transaction #33721

Merged
merged 3 commits into from Apr 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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