Skip to content

Commit

Permalink
ddl: fix unexpected delete ETCD value (#52504)
Browse files Browse the repository at this point in the history
close #47060, close #52335
  • Loading branch information
wjhuang2016 authored Apr 16, 2024
1 parent e5863e1 commit 5bb8ed7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func (w *worker) registerMDLInfo(job *model.Job, ver int64) error {
}

// cleanMDLInfo cleans metadata lock info.
func cleanMDLInfo(pool *sess.Pool, jobID int64, ec *clientv3.Client) {
func cleanMDLInfo(pool *sess.Pool, jobID int64, ec *clientv3.Client, cleanETCD bool) {
if !variable.EnableMDL.Load() {
return
}
Expand All @@ -614,7 +614,7 @@ func cleanMDLInfo(pool *sess.Pool, jobID int64, ec *clientv3.Client) {
logutil.BgLogger().Warn("unexpected error when clean mdl info", zap.Int64("job ID", jobID), zap.Error(err))
return
}
if ec != nil {
if cleanETCD && ec != nil {
path := fmt.Sprintf("%s/%d/", util.DDLAllSchemaVersionsByJob, jobID)
_, err = ec.Delete(context.Background(), path, clientv3.WithPrefix())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (d *ddl) delivery2Worker(wk *worker, pool *workerPool, job *model.Job) {
return
}
d.setAlreadyRunOnce(job.ID)
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli)
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli, job.State == model.JobStateSynced)
// Don't have a worker now.
return
}
Expand Down Expand Up @@ -479,7 +479,7 @@ func (d *ddl) delivery2Worker(wk *worker, pool *workerPool, job *model.Job) {
if err != nil {
return
}
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli)
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli, job.State == model.JobStateSynced)
d.synced(job)

if RunInGoTest {
Expand Down

0 comments on commit 5bb8ed7

Please sign in to comment.