Skip to content

Commit

Permalink
ddl: fix unexpected delete ETCD value (#52504) (#53022)
Browse files Browse the repository at this point in the history
close #47060, close #52335
  • Loading branch information
ti-chi-bot authored May 21, 2024
1 parent 3b4de20 commit 7af62de
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 @@ -487,7 +487,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 @@ -501,7 +501,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 @@ -386,7 +386,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 @@ -426,7 +426,7 @@ func (d *ddl) delivery2worker(wk *worker, pool *workerPool, job *model.Job) {
logutil.BgLogger().Info("wait latest schema version error", zap.String("category", "ddl"), zap.Error(err))
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 7af62de

Please sign in to comment.