sessionctx: Fix SET GLOBAL tidb_skip_isolation_level_check=1 (#27898)

This commit is contained in:
Xiaoguang Sun
2021-09-14 12:32:41 +08:00
committed by GitHub
parent 282357e6b7
commit b52f3efbe9
3 changed files with 20 additions and 2 deletions

View File

@ -15,6 +15,7 @@
package variable_test
import (
"sync"
"testing"
"time"
@ -34,6 +35,7 @@ func TestSetSystemVariable(t *testing.T) {
v := variable.NewSessionVars()
v.GlobalVarsAccessor = variable.NewMockGlobalAccessor()
v.TimeZone = time.UTC
mtx := new(sync.Mutex)
testCases := []struct {
key string
@ -57,7 +59,10 @@ func TestSetSystemVariable(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.key, func(t *testing.T) {
t.Parallel()
mtx.Lock()
err := variable.SetSessionSystemVar(v, tc.key, tc.value)
mtx.Unlock()
if tc.err {
require.Error(t, err)
} else {

View File

@ -1269,7 +1269,7 @@ var defaultSysVars = []*SysVar{
s.EnableFastAnalyze = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBSkipIsolationLevelCheck, skipInit: true, Value: BoolToOnOff(DefTiDBSkipIsolationLevelCheck), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBSkipIsolationLevelCheck, Value: BoolToOnOff(DefTiDBSkipIsolationLevelCheck), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableRateLimitAction, Value: BoolToOnOff(DefTiDBEnableRateLimitAction), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnabledRateLimitAction = TiDBOptOn(val)
return nil

View File

@ -419,8 +419,21 @@ func TestTxnIsolation(t *testing.T) {
_, err = sv.Validate(vars, "read-uncommitted", ScopeSession)
require.Equal(t, "[variable:8048]The isolation level 'READ-UNCOMMITTED' is not supported. Set tidb_skip_isolation_level_check=1 to skip this error", err.Error())
vars.systems[TiDBSkipIsolationLevelCheck] = "ON"
// Enable global skip isolation check doesn't affect current session
require.Nil(t, GetSysVar(TiDBSkipIsolationLevelCheck).SetGlobalFromHook(vars, "ON", true))
_, err = sv.Validate(vars, "Serializable", ScopeSession)
require.Equal(t, "[variable:8048]The isolation level 'SERIALIZABLE' is not supported. Set tidb_skip_isolation_level_check=1 to skip this error", err.Error())
// Enable session skip isolation check
require.Nil(t, GetSysVar(TiDBSkipIsolationLevelCheck).SetSessionFromHook(vars, "ON"))
val, err = sv.Validate(vars, "Serializable", ScopeSession)
require.NoError(t, err)
require.Equal(t, "SERIALIZABLE", val)
// Init TiDBSkipIsolationLevelCheck like what loadCommonGlobalVariables does
vars = NewSessionVars()
require.NoError(t, vars.SetSystemVarWithRelaxedValidation(TiDBSkipIsolationLevelCheck, "1"))
val, err = sv.Validate(vars, "Serializable", ScopeSession)
require.NoError(t, err)
require.Equal(t, "SERIALIZABLE", val)