diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 14d054419b501..ea16612e3a450 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2994,7 +2994,7 @@ func isSameTypeMultiSpecs(specs []*ast.AlterTableSpec) bool { } func checkMultiSpecs(sctx sessionctx.Context, specs []*ast.AlterTableSpec) error { - if !sctx.GetSessionVars().EnableChangeMultiSchema { + if !variable.EnableChangeMultiSchema.Load() { if len(specs) > 1 { return dbterror.ErrRunMultiSchemaChanges } @@ -4023,7 +4023,7 @@ func (d *ddl) DropColumn(ctx sessionctx.Context, ti ast.Ident, spec *ast.AlterTa return err } var multiSchemaInfo *model.MultiSchemaInfo - if ctx.GetSessionVars().EnableChangeMultiSchema { + if variable.EnableChangeMultiSchema.Load() { multiSchemaInfo = &model.MultiSchemaInfo{} } @@ -4102,7 +4102,7 @@ func (d *ddl) DropColumns(ctx sessionctx.Context, ti ast.Ident, specs []*ast.Alt return err } var multiSchemaInfo *model.MultiSchemaInfo - if ctx.GetSessionVars().EnableChangeMultiSchema { + if variable.EnableChangeMultiSchema.Load() { multiSchemaInfo = &model.MultiSchemaInfo{} } @@ -4139,7 +4139,7 @@ func checkIsDroppableColumn(ctx sessionctx.Context, t table.Table, spec *ast.Alt return false, err } - if err = isDroppableColumn(ctx.GetSessionVars().EnableChangeMultiSchema, tblInfo, colName); err != nil { + if err = isDroppableColumn(variable.EnableChangeMultiSchema.Load(), tblInfo, colName); err != nil { return false, errors.Trace(err) } // We don't support dropping column with PK handle covered now. diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 57f71b5790a77..2197bf5c8a8fa 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -837,9 +837,6 @@ type SessionVars struct { // DDLReorgPriority is the operation priority of adding indices. DDLReorgPriority int - // EnableChangeMultiSchema is used to control whether to enable the multi schema change. - EnableChangeMultiSchema bool - // EnableAutoIncrementInGenerated is used to control whether to allow auto incremented columns in generated columns. EnableAutoIncrementInGenerated bool @@ -1348,7 +1345,6 @@ func NewSessionVars() *SessionVars { EnableClusteredIndex: DefTiDBEnableClusteredIndex, EnableParallelApply: DefTiDBEnableParallelApply, ShardAllocateStep: DefTiDBShardAllocateStep, - EnableChangeMultiSchema: DefTiDBChangeMultiSchema, EnablePointGetCache: DefTiDBPointGetCache, EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn, PartitionPruneMode: *atomic2.NewString(DefTiDBPartitionPruneMode), diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 9ee43476be4d2..6f5d9dc98da9b 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -465,33 +465,34 @@ var defaultSysVars = []*SysVar{ SetDDLReorgRowFormat(TidbOptInt64(val, DefTiDBRowFormatV2)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLReorgWorkerCount, Value: strconv.Itoa(DefTiDBDDLReorgWorkerCount), Type: TypeUnsigned, MinValue: 1, MaxValue: MaxConfigurableConcurrency, SetSession: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLReorgWorkerCount, Value: strconv.Itoa(DefTiDBDDLReorgWorkerCount), Type: TypeUnsigned, MinValue: 1, MaxValue: MaxConfigurableConcurrency, SetGlobal: func(s *SessionVars, val string) error { SetDDLReorgWorkerCounter(int32(tidbOptPositiveInt32(val, DefTiDBDDLReorgWorkerCount))) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLReorgBatchSize, Value: strconv.Itoa(DefTiDBDDLReorgBatchSize), Type: TypeUnsigned, MinValue: int64(MinDDLReorgBatchSize), MaxValue: uint64(MaxDDLReorgBatchSize), SetSession: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLReorgBatchSize, Value: strconv.Itoa(DefTiDBDDLReorgBatchSize), Type: TypeUnsigned, MinValue: int64(MinDDLReorgBatchSize), MaxValue: uint64(MaxDDLReorgBatchSize), SetGlobal: func(s *SessionVars, val string) error { SetDDLReorgBatchSize(int32(tidbOptPositiveInt32(val, DefTiDBDDLReorgBatchSize))) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLErrorCountLimit, Value: strconv.Itoa(DefTiDBDDLErrorCountLimit), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt64, SetSession: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLErrorCountLimit, Value: strconv.Itoa(DefTiDBDDLErrorCountLimit), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt64, SetGlobal: func(s *SessionVars, val string) error { SetDDLErrorCountLimit(TidbOptInt64(val, DefTiDBDDLErrorCountLimit)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, SetSession: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, SetGlobal: func(s *SessionVars, val string) error { // It's a global variable, but it also wants to be cached in server. SetMaxDeltaSchemaCount(TidbOptInt64(val, DefTiDBMaxDeltaSchemaCount)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBChangeMultiSchema), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error { - s.EnableChangeMultiSchema = TiDBOptOn(val) - return nil - }, SetGlobal: func(s *SessionVars, val string) error { - s.EnableChangeMultiSchema = TiDBOptOn(val) + {Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBChangeMultiSchema), Hidden: true, Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + EnableChangeMultiSchema.Store(TiDBOptOn(val)) return nil + }, GetGlobal: func(s *SessionVars) (string, error) { + return BoolToOnOff(EnableChangeMultiSchema.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBEnablePointGetCache, Value: BoolToOnOff(DefTiDBPointGetCache), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error { - s.EnablePointGetCache = TiDBOptOn(val) + {Scope: ScopeGlobal, Name: TiDBEnablePointGetCache, Value: BoolToOnOff(DefTiDBPointGetCache), Hidden: true, Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + EnablePointGetCache.Store(TiDBOptOn(val)) return nil + }, GetGlobal: func(s *SessionVars) (string, error) { + return BoolToOnOff(EnablePointGetCache.Load()), nil }}, {Scope: ScopeGlobal, Name: TiDBScatterRegion, Value: BoolToOnOff(DefTiDBScatterRegion), Type: TypeBool}, {Scope: ScopeGlobal, Name: TiDBEnableStmtSummary, Value: BoolToOnOff(DefTiDBEnableStmtSummary), Type: TypeBool, AllowEmpty: true, diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index 6c62a697e6d5b..fb821c9f5cf78 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -656,10 +656,7 @@ func TestSettersandGetters(t *testing.T) { // There are some historial exceptions where global variables are loaded into the session. // Please don't add to this list, the behavior is not MySQL compatible. switch sv.Name { - case TiDBEnableChangeMultiSchema, TiDBDDLReorgBatchSize, - TiDBMaxDeltaSchemaCount, InitConnect, MaxPreparedStmtCount, - TiDBDDLReorgWorkerCount, TiDBDDLErrorCountLimit, TiDBRowFormatVersion, - TiDBEnableTelemetry, TiDBEnablePointGetCache: + case TiDBRowFormatVersion: continue } require.Nil(t, sv.SetSession) diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 12916ed13e874..7d621ec5db22a 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -919,6 +919,8 @@ var ( DefExecutorConcurrency = 5 MemoryUsageAlarmRatio = atomic.NewFloat64(config.GetGlobalConfig().Instance.MemoryUsageAlarmRatio) EnableLocalTxn = atomic.NewBool(DefTiDBEnableLocalTxn) + EnablePointGetCache = atomic.NewBool(DefTiDBPointGetCache) + EnableChangeMultiSchema = atomic.NewBool(DefTiDBChangeMultiSchema) MaxTSOBatchWaitInterval = atomic.NewFloat64(DefTiDBTSOClientBatchMaxWaitTime) EnableTSOFollowerProxy = atomic.NewBool(DefTiDBEnableTSOFollowerProxy) RestrictedReadOnly = atomic.NewBool(DefTiDBRestrictedReadOnly) diff --git a/sessionctx/variable/variable.go b/sessionctx/variable/variable.go index ad91470802795..db747819dee42 100644 --- a/sessionctx/variable/variable.go +++ b/sessionctx/variable/variable.go @@ -516,10 +516,7 @@ func (sv *SysVar) SkipInit() bool { // These a special "Global-only" sysvars that for backward compatibility // are currently cached in the session. Please don't add to this list. switch sv.Name { - case TiDBEnableChangeMultiSchema, TiDBDDLReorgBatchSize, - TiDBMaxDeltaSchemaCount, InitConnect, MaxPreparedStmtCount, - TiDBDDLReorgWorkerCount, TiDBDDLErrorCountLimit, TiDBRowFormatVersion, - TiDBEnableTelemetry, TiDBEnablePointGetCache: + case TiDBRowFormatVersion: return false } return !sv.HasSessionScope()