Skip to content

Commit 5009883

Browse files
authored
ddl: fix unexpected delete ETCD value (pingcap#52504) (pingcap#52651)
close pingcap#47060, close pingcap#52335
1 parent 43222f7 commit 5009883

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ddl/ddl_worker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ func (w *worker) registerMDLInfo(job *model.Job, ver int64) error {
470470
}
471471

472472
// cleanMDLInfo cleans metadata lock info.
473-
func cleanMDLInfo(pool *sess.Pool, jobID int64, ec *clientv3.Client) {
473+
func cleanMDLInfo(pool *sess.Pool, jobID int64, ec *clientv3.Client, cleanETCD bool) {
474474
if !variable.EnableMDL.Load() {
475475
return
476476
}
@@ -484,7 +484,7 @@ func cleanMDLInfo(pool *sess.Pool, jobID int64, ec *clientv3.Client) {
484484
logutil.BgLogger().Warn("unexpected error when clean mdl info", zap.Int64("job ID", jobID), zap.Error(err))
485485
return
486486
}
487-
if ec != nil {
487+
if cleanETCD && ec != nil {
488488
path := fmt.Sprintf("%s/%d/", util.DDLAllSchemaVersionsByJob, jobID)
489489
_, err = ec.Delete(context.Background(), path, clientv3.WithPrefix())
490490
if err != nil {

ddl/job_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (d *ddl) delivery2worker(wk *worker, pool *workerPool, job *model.Job) {
379379
return
380380
}
381381
d.setAlreadyRunOnce(job.ID)
382-
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli)
382+
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli, job.State == model.JobStateSynced)
383383
// Don't have a worker now.
384384
return
385385
}
@@ -419,7 +419,7 @@ func (d *ddl) delivery2worker(wk *worker, pool *workerPool, job *model.Job) {
419419
logutil.BgLogger().Info("wait latest schema version error", zap.String("category", "ddl"), zap.Error(err))
420420
return
421421
}
422-
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli)
422+
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli, job.State == model.JobStateSynced)
423423
d.synced(job)
424424

425425
if RunInGoTest {

0 commit comments

Comments
 (0)