diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index b1b30f07d7f4d..5ecd4bbf1f83c 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -294,7 +294,8 @@ func (d *ddl) limitDDLJobs() { func (d *ddl) addBatchDDLJobs(tasks []*limitJobTask) { startTime := time.Now() var err error - if variable.EnableConcurrentDDL.Load() { + // DDLForce2Queue is a flag to tell DDL worker to always push the job to the DDL queue. + if variable.EnableConcurrentDDL.Load() && !variable.DDLForce2Queue.Load() { err = d.addBatchDDLJobs2Table(tasks) } else { err = d.addBatchDDLJobs2Queue(tasks) diff --git a/session/bootstrap.go b/session/bootstrap.go index a9ad49a2c5b5b..9dd2f545c03e6 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -789,16 +789,17 @@ func upgrade(s Session) { } // Only upgrade from under version92 and this TiDB is not owner set. // The owner in older tidb does not support concurrent DDL, we should add the internal DDL to job queue. - original := variable.EnableConcurrentDDL.Load() if ver < version92 && !domain.GetDomain(s).DDL().OwnerManager().IsOwner() { - variable.EnableConcurrentDDL.Store(false) + // use another variable DDLForce2Queue but not EnableConcurrentDDL since in upgrade it may set global variable, the initial step will + // overwrite variable EnableConcurrentDDL. + variable.DDLForce2Queue.Store(true) } // Do upgrade works then update bootstrap version. for _, upgrade := range bootstrapVersion { upgrade(s, ver) } - variable.EnableConcurrentDDL.Store(original) + variable.DDLForce2Queue.Store(false) updateBootstrapVer(s) ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap) _, err = s.ExecuteInternal(ctx, "COMMIT") diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index ffa18e380c375..6d029f97c5669 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -1043,6 +1043,7 @@ var ( PreparedPlanCacheSize = atomic.NewUint64(DefTiDBPrepPlanCacheSize) PreparedPlanCacheMemoryGuardRatio = atomic.NewFloat64(DefTiDBPrepPlanCacheMemoryGuardRatio) EnableConcurrentDDL = atomic.NewBool(DefTiDBEnableConcurrentDDL) + DDLForce2Queue = atomic.NewBool(false) EnableNoopVariables = atomic.NewBool(DefTiDBEnableNoopVariables) )