Skip to content

Commit

Permalink
sessionctx/variable, ddl: fix sysvar API usage (pingcap#35052)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo authored Jun 6, 2022
1 parent 45a6758 commit 233a733
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
8 changes: 4 additions & 4 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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{}
}

Expand Down Expand Up @@ -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{}
}

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1348,7 +1345,6 @@ func NewSessionVars() *SessionVars {
EnableClusteredIndex: DefTiDBEnableClusteredIndex,
EnableParallelApply: DefTiDBEnableParallelApply,
ShardAllocateStep: DefTiDBShardAllocateStep,
EnableChangeMultiSchema: DefTiDBChangeMultiSchema,
EnablePointGetCache: DefTiDBPointGetCache,
EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn,
PartitionPruneMode: *atomic2.NewString(DefTiDBPartitionPruneMode),
Expand Down
23 changes: 12 additions & 11 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions sessionctx/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 233a733

Please sign in to comment.