Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: cleanup sysvar API usage #36640

Merged
merged 18 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func (d *ddl) CreateSchema(ctx sessionctx.Context, stmt *ast.CreateDatabaseStmt)
// If no charset and/or collation is specified use collation_server and character_set_server
charsetOpt := ast.CharsetOpt{}
if sessionVars.GlobalVarsAccessor != nil {
charsetOpt.Col, err = variable.GetSessionOrGlobalSystemVar(sessionVars, variable.CollationServer)
charsetOpt.Col, err = sessionVars.GetSessionOrGlobalSystemVar(variable.CollationServer)
if err != nil {
return err
}
charsetOpt.Chs, err = variable.GetSessionOrGlobalSystemVar(sessionVars, variable.CharacterSetServer)
charsetOpt.Chs, err = sessionVars.GetSessionOrGlobalSystemVar(variable.CharacterSetServer)
if err != nil {
return err
}
Expand Down Expand Up @@ -2568,7 +2568,7 @@ func (d *ddl) preSplitAndScatter(ctx sessionctx.Context, tbInfo *model.TableInfo
preSplit func()
scatterRegion bool
)
val, err := variable.GetGlobalSystemVar(ctx.GetSessionVars(), variable.TiDBScatterRegion)
val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBScatterRegion)
if err != nil {
logutil.BgLogger().Warn("[ddl] won't scatter region", zap.Error(err))
} else {
Expand Down
2 changes: 1 addition & 1 deletion ddl/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func LoadGlobalVars(ctx context.Context, sctx sessionctx.Context, varNames []str
for _, row := range rows {
varName := row.GetString(0)
varValue := row.GetString(1)
if err = sctx.GetSessionVars().SetSystemVar(varName, varValue); err != nil {
if err = sctx.GetSessionVars().SetSystemVarWithoutValidation(varName, varValue); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func buildGroupConcat(ctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDe
panic(fmt.Sprintf("Error happened when buildGroupConcat: %s", err.Error()))
}
var s string
s, err = variable.GetSessionOrGlobalSystemVar(ctx.GetSessionVars(), variable.GroupConcatMaxLen)
s, err = ctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.GroupConcatMaxLen)
if err != nil {
panic(fmt.Sprintf("Error happened when buildGroupConcat: no system variable named '%s'", variable.GroupConcatMaxLen))
}
Expand Down
4 changes: 2 additions & 2 deletions executor/aggfuncs/func_group_concat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func TestGroupConcat(t *testing.T) {
testMultiArgsAggFunc(t, ctx, test2)

defer func() {
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.GroupConcatMaxLen, "1024")
err := ctx.GetSessionVars().SetSystemVar(variable.GroupConcatMaxLen, "1024")
require.NoError(t, err)
}()
// minimum GroupConcatMaxLen is 4
for i := 4; i <= 7; i++ {
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.GroupConcatMaxLen, fmt.Sprint(i))
err := ctx.GetSessionVars().SetSystemVar(variable.GroupConcatMaxLen, fmt.Sprint(i))
require.NoError(t, err)
test2 = buildMultiArgsAggTester(ast.AggFuncGroupConcat, []byte{mysql.TypeString, mysql.TypeString}, mysql.TypeString, 5, nil, "44 33 22 11 00"[:i])
test2.orderBy = true
Expand Down
2 changes: 1 addition & 1 deletion executor/analyze_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

func getBuildStatsConcurrency(ctx sessionctx.Context) (int, error) {
sessionVars := ctx.GetSessionVars()
concurrency, err := variable.GetSessionOrGlobalSystemVar(sessionVars, variable.TiDBBuildStatsConcurrency)
concurrency, err := sessionVars.GetSessionOrGlobalSystemVar(variable.TiDBBuildStatsConcurrency)
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion executor/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (c *checksumContext) HandleResponse(update *tipb.ChecksumResponse) {

func getChecksumTableConcurrency(ctx sessionctx.Context) (int, error) {
sessionVars := ctx.GetSessionVars()
concurrency, err := variable.GetSessionOrGlobalSystemVar(sessionVars, variable.TiDBChecksumTableConcurrency)
concurrency, err := sessionVars.GetSessionOrGlobalSystemVar(variable.TiDBChecksumTableConcurrency)
if err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ func (e *DDLExec) executeDropDatabase(s *ast.DropDatabaseStmt) error {
sessionVars := e.ctx.GetSessionVars()
if err == nil && strings.ToLower(sessionVars.CurrentDB) == dbName.L {
sessionVars.CurrentDB = ""
err = variable.SetSessionSystemVar(sessionVars, variable.CharsetDatabase, mysql.DefaultCharset)
err = sessionVars.SetSystemVar(variable.CharsetDatabase, mysql.DefaultCharset)
if err != nil {
return err
}
err = variable.SetSessionSystemVar(sessionVars, variable.CollationDatabase, mysql.DefaultCollationName)
err = sessionVars.SetSystemVar(variable.CollationDatabase, mysql.DefaultCollationName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (e *memtableRetriever) setDataForVariablesInfo(ctx sessionctx.Context) erro
sysVars := variable.GetSysVars()
rows := make([][]types.Datum, 0, len(sysVars))
for _, sv := range sysVars {
currentVal, err := variable.GetSessionOrGlobalSystemVar(ctx.GetSessionVars(), sv.Name)
currentVal, err := ctx.GetSessionVars().GetSessionOrGlobalSystemVar(sv.Name)
if err != nil {
currentVal = ""
}
Expand Down
14 changes: 7 additions & 7 deletions executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres
return errors.Trace(ErrCantChangeTxCharacteristics)
}
}
err = variable.SetSessionSystemVar(sessionVars, name, valStr)
err = sessionVars.SetSystemVar(name, valStr)
if err != nil {
return err
}
Expand Down Expand Up @@ -274,15 +274,15 @@ func (e *SetExecutor) setCharset(cs, co string, isSetName bool) error {
}
if isSetName {
for _, v := range variable.SetNamesVariables {
if err = variable.SetSessionSystemVar(sessionVars, v, cs); err != nil {
if err = sessionVars.SetSystemVar(v, cs); err != nil {
return errors.Trace(err)
}
}
return errors.Trace(variable.SetSessionSystemVar(sessionVars, variable.CollationConnection, co))
return errors.Trace(sessionVars.SetSystemVar(variable.CollationConnection, co))
}
// Set charset statement, see also https://dev.mysql.com/doc/refman/8.0/en/set-character-set.html.
for _, v := range variable.SetCharsetVariables {
if err = variable.SetSessionSystemVar(sessionVars, v, cs); err != nil {
if err = sessionVars.SetSystemVar(v, cs); err != nil {
return errors.Trace(err)
}
}
Expand All @@ -294,11 +294,11 @@ func (e *SetExecutor) setCharset(cs, co string, isSetName bool) error {
if err != nil {
return err
}
err = variable.SetSessionSystemVar(sessionVars, variable.CharacterSetConnection, csDb)
err = sessionVars.SetSystemVar(variable.CharacterSetConnection, csDb)
if err != nil {
return errors.Trace(err)
}
return errors.Trace(variable.SetSessionSystemVar(sessionVars, variable.CollationConnection, coDb))
return errors.Trace(sessionVars.SetSystemVar(variable.CollationConnection, coDb))
}

func (e *SetExecutor) getVarValue(v *expression.VarAssignment, sysVar *variable.SysVar) (value string, err error) {
Expand All @@ -309,7 +309,7 @@ func (e *SetExecutor) getVarValue(v *expression.VarAssignment, sysVar *variable.
if sysVar != nil {
return sysVar.Value, nil
}
return variable.GetGlobalSystemVar(e.ctx.GetSessionVars(), v.Name)
return e.ctx.GetSessionVars().GetGlobalSystemVar(v.Name)
}
nativeVal, err := v.Expr.Eval(chunk.Row{})
if err != nil || nativeVal.IsNull() {
Expand Down
2 changes: 1 addition & 1 deletion executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ func TestSetCharset(t *testing.T) {

check := func(args ...string) {
for i, v := range characterSetVariables {
sVar, err := variable.GetSessionOrGlobalSystemVar(sessionVars, v)
sVar, err := sessionVars.GetSessionOrGlobalSystemVar(v)
require.NoError(t, err)
require.Equal(t, args[i], sVar, fmt.Sprintf("%d: %s", i, characterSetVariables[i]))
}
Expand Down
4 changes: 2 additions & 2 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func (e *ShowExec) fetchShowVariables() (err error) {
if e.sysVarHiddenForSem(v.Name) {
continue
}
value, err = variable.GetGlobalSystemVar(sessionVars, v.Name)
value, err = sessionVars.GetGlobalSystemVar(v.Name)
if err != nil {
return errors.Trace(err)
}
Expand All @@ -868,7 +868,7 @@ func (e *ShowExec) fetchShowVariables() (err error) {
if e.sysVarHiddenForSem(v.Name) {
continue
}
value, err = variable.GetSessionOrGlobalSystemVar(sessionVars, v.Name)
value, err = sessionVars.GetSessionOrGlobalSystemVar(v.Name)
if err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func (e *SimpleExec) executeUse(s *ast.UseStmt) error {
// collation if this one is not supported.
// The SetSystemVar will also update the CharsetDatabase
dbCollate = collate.SubstituteMissingCollationToDefault(dbCollate)
return sessionVars.SetSystemVar(variable.CollationDatabase, dbCollate)
return sessionVars.SetSystemVarWithoutValidation(variable.CollationDatabase, dbCollate)
}

func (e *SimpleExec) executeBegin(ctx context.Context, s *ast.BeginStmt) error {
Expand Down
2 changes: 1 addition & 1 deletion expression/aggregation/agg_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func AggFuncToPBExpr(sctx sessionctx.Context, client kv.Client, aggFunc *AggFunc
orderBy = append(orderBy, pbArg)
}
// encode GroupConcatMaxLen
GCMaxLen, err := variable.GetSessionOrGlobalSystemVar(sctx.GetSessionVars(), variable.GroupConcatMaxLen)
GCMaxLen, err := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.GroupConcatMaxLen)
if err != nil {
return nil, errors.Errorf("Error happened when buildGroupConcat: no system variable named '%s'", variable.GroupConcatMaxLen)
}
Expand Down
2 changes: 1 addition & 1 deletion expression/aggregation/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (a *AggFuncDesc) GetAggFunc(ctx sessionctx.Context) Aggregation {
var s string
var err error
var maxLen uint64
s, err = variable.GetSessionOrGlobalSystemVar(ctx.GetSessionVars(), variable.GroupConcatMaxLen)
s, err = ctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.GroupConcatMaxLen)
if err != nil {
panic(fmt.Sprintf("Error happened when GetAggFunc: no system variable named '%s'", variable.GroupConcatMaxLen))
}
Expand Down
2 changes: 1 addition & 1 deletion expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ func testVectorizedBuiltinFunc(t *testing.T, vecExprCases vecExprBenchCases) {
for funcName, testCases := range vecExprCases {
for _, testCase := range testCases {
ctx := mock.NewContext()
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, testCase.aesModes)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.BlockEncryptionMode, testCase.aesModes)
require.NoError(t, err)
if funcName == ast.CurrentUser || funcName == ast.User {
ctx.GetSessionVars().User = &auth.UserIdentity{
Expand Down
36 changes: 18 additions & 18 deletions expression/builtin_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ var cryptTests = []struct {
func TestSQLDecode(t *testing.T) {
ctx := createContext(t)
for _, tt := range cryptTests {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, tt.chs)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, tt.chs)
require.NoError(t, err)
err = ctx.GetSessionVars().SetSystemVar(variable.CollationConnection, tt.chs)
err = ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CollationConnection, tt.chs)
require.NoError(t, err)
f, err := newFunctionForTest(ctx, ast.Decode, primitiveValsToConstants(ctx, []interface{}{tt.origin, tt.password})...)
require.NoError(t, err)
Expand All @@ -77,9 +77,9 @@ func TestSQLDecode(t *testing.T) {
func TestSQLEncode(t *testing.T) {
ctx := createContext(t)
for _, test := range cryptTests {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, test.chs)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, test.chs)
require.NoError(t, err)
err = ctx.GetSessionVars().SetSystemVar(variable.CollationConnection, test.chs)
err = ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CollationConnection, test.chs)
require.NoError(t, err)
var h []byte
if test.crypt != nil {
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestAESEncrypt(t *testing.T) {

fc := funcs[ast.AesEncrypt]
for _, tt := range aesTests {
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, tt.mode)
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, tt.mode)
require.NoError(t, err)
args := []types.Datum{types.NewDatum(tt.origin)}
for _, param := range tt.params {
Expand All @@ -159,7 +159,7 @@ func TestAESEncrypt(t *testing.T) {
require.NoError(t, err)
require.Equal(t, types.NewDatum(tt.crypt), toHex(crypt))
}
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, "aes-128-ecb")
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, "aes-128-ecb")
require.NoError(t, err)
testNullInput(t, ctx, ast.AesEncrypt)
testAmbiguousInput(t, ctx, ast.AesEncrypt)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestAESEncrypt(t *testing.T) {
msg := fmt.Sprintf("%v", tt)
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, tt.chs)
require.NoError(t, err, msg)
err = variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, tt.mode)
err = ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, tt.mode)
require.NoError(t, err, msg)

args := primitiveValsToConstants(ctx, []interface{}{tt.origin})
Expand All @@ -214,7 +214,7 @@ func TestAESDecrypt(t *testing.T) {
fc := funcs[ast.AesDecrypt]
for _, tt := range aesTests {
msg := fmt.Sprintf("%v", tt)
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, tt.mode)
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, tt.mode)
require.NoError(t, err, msg)
args := []types.Datum{fromHex(tt.crypt)}
for _, param := range tt.params {
Expand All @@ -230,7 +230,7 @@ func TestAESDecrypt(t *testing.T) {
}
require.Equal(t, types.NewCollationStringDatum(tt.origin.(string), charset.CollationBin), str, msg)
}
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, "aes-128-ecb")
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, "aes-128-ecb")
require.NoError(t, err)
testNullInput(t, ctx, ast.AesDecrypt)
testAmbiguousInput(t, ctx, ast.AesDecrypt)
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestAESDecrypt(t *testing.T) {
msg := fmt.Sprintf("%v", tt)
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, tt.chs)
require.NoError(t, err, msg)
err = variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, tt.mode)
err = ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, tt.mode)
require.NoError(t, err, msg)
// Set charset and collate except first argument
args := datumsToConstants([]types.Datum{fromHex(tt.crypt)})
Expand All @@ -280,7 +280,7 @@ func TestAESDecrypt(t *testing.T) {
}

func testNullInput(t *testing.T, ctx sessionctx.Context, fnName string) {
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, "aes-128-ecb")
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, "aes-128-ecb")
require.NoError(t, err)
fc := funcs[fnName]
arg := types.NewStringDatum("str")
Expand All @@ -302,7 +302,7 @@ func testAmbiguousInput(t *testing.T, ctx sessionctx.Context, fnName string) {
fc := funcs[fnName]
arg := types.NewStringDatum("str")
// test for modes that require init_vector
err := variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, "aes-128-cbc")
err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, "aes-128-cbc")
require.NoError(t, err)
_, err = fc.getFunction(ctx, datumsToConstants([]types.Datum{arg, arg}))
require.Error(t, err)
Expand All @@ -312,7 +312,7 @@ func testAmbiguousInput(t *testing.T, ctx sessionctx.Context, fnName string) {
require.Error(t, err)

// test for modes that do not require init_vector
err = variable.SetSessionSystemVar(ctx.GetSessionVars(), variable.BlockEncryptionMode, "aes-128-ecb")
err = ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, "aes-128-ecb")
require.NoError(t, err)
f, err = fc.getFunction(ctx, datumsToConstants([]types.Datum{arg, arg, arg}))
require.NoError(t, err)
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestSha1Hash(t *testing.T) {

fc := funcs[ast.SHA]
for _, tt := range sha1Tests {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, tt.chs)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, tt.chs)
require.NoError(t, err)
f, _ := fc.getFunction(ctx, primitiveValsToConstants(ctx, []interface{}{tt.origin}))
crypt, err := evalBuiltinFunc(f, chunk.Row{})
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestSha2Hash(t *testing.T) {

fc := funcs[ast.SHA2]
for _, tt := range sha2Tests {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, tt.chs)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, tt.chs)
require.NoError(t, err)
f, err := fc.getFunction(ctx, primitiveValsToConstants(ctx, []interface{}{tt.origin, tt.hashLength}))
require.NoError(t, err)
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestMD5Hash(t *testing.T) {
{nil, "", "", true, false},
}
for _, c := range cases {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, c.charset)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, c.charset)
require.NoError(t, err)
f, err := newFunctionForTest(ctx, ast.MD5, primitiveValsToConstants(ctx, []interface{}{c.args})...)
require.NoError(t, err)
Expand Down Expand Up @@ -552,7 +552,7 @@ func TestCompress(t *testing.T) {
{"gbk", "你好", string(decodeHex("04000000789C3AF278D76140000000FFFF07F40325"))},
}
for _, test := range tests {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, test.chs)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, test.chs)
require.NoErrorf(t, err, "%v", test)
arg := primitiveValsToConstants(ctx, []interface{}{test.in})
f, err := fc.getFunction(ctx, arg)
Expand Down Expand Up @@ -656,7 +656,7 @@ func TestPassword(t *testing.T) {

warnCount := len(ctx.GetSessionVars().StmtCtx.GetWarnings())
for _, c := range cases {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, c.charset)
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, c.charset)
require.NoError(t, err)
f, err := newFunctionForTest(ctx, ast.PasswordFunc, primitiveValsToConstants(ctx, []interface{}{c.args})...)
require.NoError(t, err)
Expand Down
Loading