Skip to content

Commit

Permalink
sessionctx/variable: reduce further skip init
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo committed Jul 13, 2022
1 parent d93bc7a commit d7dc4e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,24 @@ var defaultSysVars = []*SysVar{
s.AllowAggPushDown = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBOptDistinctAggPushDown, Value: BoolToOnOff(config.GetGlobalConfig().Performance.DistinctAggPushDown), skipInit: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBOptDistinctAggPushDown, Value: BoolToOnOff(config.GetGlobalConfig().Performance.DistinctAggPushDown), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.AllowDistinctAggPushDown = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBOptWriteRowID, Value: BoolToOnOff(DefOptWriteRowID), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBOptWriteRowID, Value: BoolToOnOff(DefOptWriteRowID), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.AllowWriteRowID = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBChecksumTableConcurrency, Value: strconv.Itoa(DefChecksumTableConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},
{Scope: ScopeSession, Name: TiDBBatchInsert, Value: BoolToOnOff(DefBatchInsert), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBBatchInsert, Value: BoolToOnOff(DefBatchInsert), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.BatchInsert = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBBatchDelete, Value: BoolToOnOff(DefBatchDelete), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBBatchDelete, Value: BoolToOnOff(DefBatchDelete), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.BatchDelete = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBBatchCommit, Value: BoolToOnOff(DefBatchCommit), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBBatchCommit, Value: BoolToOnOff(DefBatchCommit), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.BatchCommit = TiDBOptOn(val)
return nil
}},
Expand Down Expand Up @@ -205,7 +205,7 @@ var defaultSysVars = []*SysVar{
}
return "", false, nil
}},
{Scope: ScopeSession, Name: TiDBOptimizerSelectivityLevel, Value: strconv.Itoa(DefTiDBOptimizerSelectivityLevel), skipInit: true, Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBOptimizerSelectivityLevel, Value: strconv.Itoa(DefTiDBOptimizerSelectivityLevel), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
s.OptimizerSelectivityLevel = tidbOptPositiveInt32(val, DefTiDBOptimizerSelectivityLevel)
return nil
}},
Expand All @@ -229,11 +229,11 @@ var defaultSysVars = []*SysVar{
s.WaitSplitRegionTimeout = uint64(tidbOptPositiveInt32(val, DefWaitSplitRegionTimeout))
return nil
}},
{Scope: ScopeSession, Name: TiDBLowResolutionTSO, Value: Off, Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBLowResolutionTSO, Value: Off, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.LowResolutionTSO = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBAllowRemoveAutoInc, Value: BoolToOnOff(DefTiDBAllowRemoveAutoInc), skipInit: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBAllowRemoveAutoInc, Value: BoolToOnOff(DefTiDBAllowRemoveAutoInc), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.AllowRemoveAutoInc = TiDBOptOn(val)
return nil
}},
Expand Down Expand Up @@ -1383,7 +1383,7 @@ var defaultSysVars = []*SysVar{
s.PlacementMode = val
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), skipInit: true, Type: TypeUnsigned, MinValue: 0, MaxValue: 63, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63, SetSession: func(s *SessionVars, val string) error {
s.TiDBOptJoinReorderThreshold = tidbOptPositiveInt32(val, DefTiDBOptJoinReorderThreshold)
return nil
}},
Expand Down Expand Up @@ -1571,7 +1571,7 @@ var defaultSysVars = []*SysVar{
s.EnableLegacyInstanceScope = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBStatsLoadSyncWait, Value: strconv.Itoa(DefTiDBStatsLoadSyncWait), skipInit: true, Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32,
{Scope: ScopeGlobal | ScopeSession, Name: TiDBStatsLoadSyncWait, Value: strconv.Itoa(DefTiDBStatsLoadSyncWait), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32,
SetSession: func(s *SessionVars, val string) error {
s.StatsLoadSyncWait = TidbOptInt64(val, DefTiDBStatsLoadSyncWait)
return nil
Expand Down
22 changes: 11 additions & 11 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,28 +708,30 @@ func TestSkipInitIsUsed(t *testing.T) {
// Skipinit has no use on noop funcs, since noop funcs always skipinit.
require.False(t, sv.IsNoop, fmt.Sprintf("skipInit has no effect on noop variables: %s", sv.Name))

// Test for variables that have a default of "0" or "OFF"
// If it is session-only scoped there is likely no bug now.
// If it is also global-scoped, then there is a bug as soon as the global changes.
if !(sv.Name == RandSeed1 || sv.Name == RandSeed2) {
// The bug is because the tests might not realize the SetSession func was not called on init,
// because it would initialize some session field to the empty value anyway.
require.NotEqual(t, "0", sv.Value, fmt.Sprintf("default value is zero: %s", sv.Name))
require.NotEqual(t, "OFF", sv.Value, fmt.Sprintf("default value is OFF: %s", sv.Name))
}

// Many of these variables might allow skipInit to be removed,
// they need to be checked first. The purpose of this test is to make
// sure we don't introduce any new variables with skipInit, which seems
// to be a problem.
switch sv.Name {
case TiDBTxnScope,
TiDBSnapshot,
TiDBOptDistinctAggPushDown,
TiDBOptWriteRowID,
TiDBBatchInsert,
TiDBBatchDelete,
TiDBBatchCommit,
TiDBEnableChunkRPC,
TxnIsolationOneShot,
TiDBOptimizerSelectivityLevel,
TiDBOptimizerEnableOuterJoinReorder,
TiDBDDLReorgPriority,
TiDBSlowQueryFile,
TiDBWaitSplitRegionFinish,
TiDBWaitSplitRegionTimeout,
TiDBLowResolutionTSO,
TiDBAllowRemoveAutoInc,
TiDBMetricSchemaStep,
TiDBMetricSchemaRangeDuration,
RandSeed1,
Expand All @@ -740,9 +742,7 @@ func TestSkipInitIsUsed(t *testing.T) {
CharacterSetConnection,
CharacterSetServer,
TiDBOptTiFlashConcurrencyFactor,
TiDBOptSeekFactor,
TiDBOptJoinReorderThreshold,
TiDBStatsLoadSyncWait:
TiDBOptSeekFactor:
continue
}
require.Equal(t, false, sv.skipInit, fmt.Sprintf("skipInit should not be set on new system variables. variable %s is in violation", sv.Name))
Expand Down

0 comments on commit d7dc4e1

Please sign in to comment.