Skip to content

Commit

Permalink
Simplified the cleanup to only start a new txn and not a new session
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed Jan 11, 2023
1 parent 51bacd3 commit 389ad4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (w *worker) HandleJobDone(d *ddlCtx, job *model.Job, t *meta.Meta) error {
if err != nil {
return err
}
CleanupDDLReorgHandles(job, w.sessPool)
CleanupDDLReorgHandles(job, w.sess)
asyncNotify(d.ddlJobDoneCh)
return nil
}
Expand Down
7 changes: 1 addition & 6 deletions ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,7 @@ func removeReorgElement(s *session, job *model.Job) error {

// cleanDDLReorgHandles removes handles that are no longer needed.
func cleanDDLReorgHandles(s *session, job *model.Job) error {
var sql string
if job != nil {
sql = "delete from mysql.tidb_ddl_reorg where job_id = " + strconv.FormatInt(job.ID, 10)
} else {
sql = "delete from mysql.tidb_ddl_reorg where job_id not in (select job_id from mysql.tidb_ddl_job)"
}
sql := "delete from mysql.tidb_ddl_reorg where job_id = " + strconv.FormatInt(job.ID, 10)
return s.runInTxn(func(se *session) error {
_, err := se.execute(context.Background(), sql, "clean_handle")
return err
Expand Down
16 changes: 4 additions & 12 deletions ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/tidb/ddl/ingest"
"github.com/pingcap/tidb/distsql"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -789,23 +788,16 @@ func (r *reorgHandler) RemoveDDLReorgHandle(job *model.Job, elements []*meta.Ele
}

// CleanupDDLReorgHandles removes the job reorganization related handles.
func CleanupDDLReorgHandles(job *model.Job, pool *sessionPool) {
func CleanupDDLReorgHandles(job *model.Job, s *session) {
if job != nil && !job.IsFinished() && !job.IsSynced() {
// Job is given, but it is neither finished nor synced; do nothing
return
}
sctx, err := pool.get()
if err != nil {
logutil.BgLogger().Info("CleanupDDLReorgHandles get sessionctx failed", zap.Error(err))
return
}
defer pool.put(sctx)

// Should there be any other options?
sctx.SetDiskFullOpt(kvrpcpb.DiskFullOpt_AllowedOnAlmostFull)
err = cleanDDLReorgHandles(newSession(sctx), job)
err := cleanDDLReorgHandles(s, job)
if err != nil {
logutil.BgLogger().Info("cleanDDLReorgHandles failed", zap.Error(err))
// ignore error, cleanup is not that critical
logutil.BgLogger().Warn("Failed removing the DDL reorg entry in tidb_ddl_reorg", zap.String("job", job.String()), zap.Error(err))
}
}

Expand Down

0 comments on commit 389ad4d

Please sign in to comment.