Skip to content

Commit

Permalink
ddl: gc mdl etcd key after cleaning the mdl table (#39454)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Nov 30, 2022
1 parent 8b06ef2 commit 30a8414
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 8 additions & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func (w *worker) registerMDLInfo(job *model.Job, ver int64) error {
}

// cleanMDLInfo cleans metadata lock info.
func cleanMDLInfo(pool *sessionPool, jobID int64) {
func cleanMDLInfo(pool *sessionPool, jobID int64, ec *clientv3.Client) {
if !variable.EnableMDL.Load() {
return
}
Expand All @@ -525,6 +525,13 @@ func cleanMDLInfo(pool *sessionPool, jobID int64) {
if err != nil {
logutil.BgLogger().Warn("unexpected error when clean mdl info", zap.Error(err))
}
if ec != nil {
path := fmt.Sprintf("%s/%d/", util.DDLAllSchemaVersionsByJob, jobID)
_, err = ec.Delete(context.Background(), path, clientv3.WithPrefix())
if err != nil {
logutil.BgLogger().Warn("[ddl] delete versions failed", zap.Any("job id", jobID), zap.Error(err))
}
}
}

// checkMDLInfo checks if metadata lock info exists. It means the schema is locked by some TiDBs if exists.
Expand Down
4 changes: 2 additions & 2 deletions ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (d *ddl) delivery2worker(wk *worker, pool *workerPool, job *model.Job) {
return
}
d.once.Store(false)
cleanMDLInfo(d.sessPool, job.ID)
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli)
// Don't have a worker now.
return
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (d *ddl) delivery2worker(wk *worker, pool *workerPool, job *model.Job) {
// If the job is done or still running or rolling back, we will wait 2 * lease time to guarantee other servers to update
// the newest schema.
waitSchemaChanged(context.Background(), d.ddlCtx, d.lease*2, schemaVer, job)
cleanMDLInfo(d.sessPool, job.ID)
cleanMDLInfo(d.sessPool, job.ID, d.etcdCli)
d.synced(job)

if RunInGoTest {
Expand Down
6 changes: 0 additions & 6 deletions ddl/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,6 @@ func (s *schemaVersionSyncer) OwnerCheckAllVersions(ctx context.Context, jobID i
}

if succ {
if variable.EnableMDL.Load() {
_, err = s.etcdCli.Delete(ctx, path, clientv3.WithPrefix())
if err != nil {
logutil.BgLogger().Warn("[ddl] syncer delete versions failed", zap.Any("job id", jobID), zap.Error(err))
}
}
return nil
}
time.Sleep(checkVersInterval)
Expand Down

0 comments on commit 30a8414

Please sign in to comment.