Skip to content

Commit

Permalink
sysvar: bypass validation for noop variables (#31566)
Browse files Browse the repository at this point in the history
close #31538
  • Loading branch information
xhebox authored Jan 11, 2022
1 parent 706abd6 commit 1ffd6c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions expression/integration_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3851,8 +3851,8 @@ func TestSetVariables(t *testing.T) {
tk.MustExec("set global tidb_enable_noop_functions=1")

_, err = tk.Exec("set @@global.max_user_connections='';")
require.Error(t, err)
require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error())
require.NoError(t, err)
//require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error())
_, err = tk.Exec("set @@global.max_prepared_stmt_count='';")
require.Error(t, err)
require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error())
Expand Down
13 changes: 13 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,16 @@ func TestIndexMergeSwitcher(t *testing.T) {
require.Equal(t, DefTiDBEnableIndexMerge, true)
require.Equal(t, BoolToOnOff(DefTiDBEnableIndexMerge), val)
}

func TestNoValidateForNoop(t *testing.T) {
vars := NewSessionVars()

// for noop variables, no error
val, err := GetSysVar("rpl_semi_sync_slave_enabled").ValidateFromType(vars, "", ScopeGlobal)
require.NoError(t, err)
require.Equal(t, val, "")

// for other variables, error
_, err = GetSysVar(TiDBAllowBatchCop).ValidateFromType(vars, "", ScopeGlobal)
require.Error(t, err)
}
4 changes: 4 additions & 0 deletions sessionctx/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ func (sv *SysVar) Validate(vars *SessionVars, value string, scope ScopeFlag) (st

// ValidateFromType provides automatic validation based on the SysVar's type
func (sv *SysVar) ValidateFromType(vars *SessionVars, value string, scope ScopeFlag) (string, error) {
// TODO: this is a temporary solution for issue: https://github.com/pingcap/tidb/issues/31538, an elegant solution is needed.
if value == "" && sv.IsNoop {
return value, nil
}
// Some sysvars in TiDB have a special behavior where the empty string means
// "use the config file value". This needs to be cleaned up once the behavior
// for instance variables is determined.
Expand Down

0 comments on commit 1ffd6c0

Please sign in to comment.