Skip to content

Commit

Permalink
ddl: do not reference owner_id for all system DDLs (#53355)
Browse files Browse the repository at this point in the history
close #53327
  • Loading branch information
tangenta authored May 17, 2024
1 parent 68db9c0 commit 2037a2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 0 additions & 2 deletions pkg/ddl/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const (
ReorgTable = "tidb_ddl_reorg"
// HistoryTable stores the history DDL jobs.
HistoryTable = "tidb_ddl_history"
// MDLInfoTable stores lock info used by metadata lock.
MDLInfoTable = "tidb_mdl_info"

// JobTableID is the table ID of `tidb_ddl_job`.
JobTableID = meta.MaxInt48 - 1
Expand Down
18 changes: 6 additions & 12 deletions pkg/ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/binloginfo"
Expand Down Expand Up @@ -595,11 +594,6 @@ func (w *worker) updateDDLJob(job *model.Job, meetErr bool) error {
return errors.Trace(updateDDLJob2Table(w.sess, job, updateRawArgs))
}

func matchMDLInfoTable(schemaName, tblName string) bool {
return strings.ToLower(schemaName) == mysql.SystemDB &&
strings.ToLower(tblName) == MDLInfoTable
}

// registerMDLInfo registers metadata lock info.
func (w *worker) registerMDLInfo(job *model.Job, ver int64) error {
if !variable.EnableMDL.Load() {
Expand All @@ -618,9 +612,9 @@ func (w *worker) registerMDLInfo(job *model.Job, ver int64) error {
ownerID := w.ownerManager.ID()
ids := rows[0].GetString(0)
var sql string
if matchMDLInfoTable(job.SchemaName, job.TableName) {
// DDLs that modify system table `tidb_mdl_info` could only happen in upgrade process,
// we should not reference 'owner_id'. Otherwise, there is a circular problem.
if tidbutil.IsSysDB(strings.ToLower(job.SchemaName)) {
// DDLs that modify system tables could only happen in upgrade process,
// we should not reference 'owner_id'. Otherwise, there is a circular blocking problem.
sql = fmt.Sprintf("replace into mysql.tidb_mdl_info (job_id, version, table_ids) values (%d, %d, '%s')", job.ID, ver, ids)
} else {
sql = fmt.Sprintf("replace into mysql.tidb_mdl_info (job_id, version, table_ids, owner_id) values (%d, %d, '%s', '%s')", job.ID, ver, ids, ownerID)
Expand All @@ -635,9 +629,9 @@ func cleanMDLInfo(pool *sess.Pool, job *model.Job, ec *clientv3.Client, ownerID
return
}
var sql string
if matchMDLInfoTable(job.SchemaName, job.TableName) {
// DDLs that modify system table `tidb_mdl_info` could only happen in upgrade process,
// we should not reference 'owner_id'. Otherwise, there is a circular problem.
if tidbutil.IsSysDB(strings.ToLower(job.SchemaName)) {
// DDLs that modify system tables could only happen in upgrade process,
// we should not reference 'owner_id'. Otherwise, there is a circular blocking problem.
sql = fmt.Sprintf("delete from mysql.tidb_mdl_info where job_id = %d", job.ID)
} else {
sql = fmt.Sprintf("delete from mysql.tidb_mdl_info where job_id = %d and owner_id = '%s'", job.ID, ownerID)
Expand Down

0 comments on commit 2037a2f

Please sign in to comment.