Skip to content

Commit

Permalink
sessionctx/variable: make lc_time_names read only (#30084)
Browse files Browse the repository at this point in the history
  • Loading branch information
espresso98 authored Nov 26, 2021
1 parent bccc21b commit f5af99e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sessionctx/variable/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ var noopSysVars = []*SysVar{
{Scope: ScopeNone, Name: "tmpdir", Value: "/var/tmp/"},
{Scope: ScopeGlobal, Name: "innodb_thread_concurrency", Value: "0"},
{Scope: ScopeGlobal, Name: "innodb_buffer_pool_dump_pct", Value: ""},
{Scope: ScopeGlobal | ScopeSession, Name: "lc_time_names", Value: "en_US"},
{Scope: ScopeGlobal | ScopeSession, Name: "lc_time_names", Value: "en_US", ReadOnly: true},
{Scope: ScopeGlobal | ScopeSession, Name: "max_statement_time", Value: ""},
{Scope: ScopeGlobal | ScopeSession, Name: EndMarkersInJSON, Value: Off, Type: TypeBool, IsHintUpdatable: true},
{Scope: ScopeGlobal, Name: AvoidTemporalUpgrade, Value: Off, Type: TypeBool},
Expand Down
14 changes: 11 additions & 3 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func TestSkipInit(t *testing.T) {
require.True(t, sv.SkipInit())
}

// IsNoop is used by the documentation to auto-generate docs for real sysvars.
// TestIsNoop is used by the documentation to auto-generate docs for real sysvars.
func TestIsNoop(t *testing.T) {
sv := GetSysVar(TiDBMultiStatementMode)
require.False(t, sv.IsNoop)
Expand Down Expand Up @@ -639,7 +639,7 @@ func TestInstanceScopedVars(t *testing.T) {
require.Equal(t, vars.TxnScope.GetVarValue(), val)
}

// Test that sysvars defaults are logically valid. i.e.
// TestDefaultValuesAreSettable that sysvars defaults are logically valid. i.e.
// the default itself must validate without error provided the scope and read-only is correct.
// The default values should also be normalized for consistency.
func TestDefaultValuesAreSettable(t *testing.T) {
Expand All @@ -660,7 +660,7 @@ func TestDefaultValuesAreSettable(t *testing.T) {
}
}

// This tests that sysvars are logically correct with getter and setter functions.
// TestSettersandGetters tests that sysvars are logically correct with getter and setter functions.
// i.e. it doesn't make sense to have a SetSession function on a variable that is only globally scoped.
func TestSettersandGetters(t *testing.T) {
for _, sv := range GetSysVars() {
Expand Down Expand Up @@ -782,6 +782,14 @@ func TestIdentity(t *testing.T) {
require.Equal(t, val, "21")
}

func TestLcTimeNamesReadOnly(t *testing.T) {
sv := GetSysVar("lc_time_names")
vars := NewSessionVars()
vars.GlobalVarsAccessor = NewMockGlobalAccessor4Tests()
_, err := sv.Validate(vars, "newvalue", ScopeGlobal)
require.Error(t, err)
}

func TestDDLWorkers(t *testing.T) {
svWorkerCount, svBatchSize := GetSysVar(TiDBDDLReorgWorkerCount), GetSysVar(TiDBDDLReorgBatchSize)
vars := NewSessionVars()
Expand Down

0 comments on commit f5af99e

Please sign in to comment.