From 2c432ea9e39bd256e902dd60d685f605dc62b511 Mon Sep 17 00:00:00 2001 From: YangKeao Date: Mon, 10 Oct 2022 19:40:24 +0800 Subject: [PATCH] add context for variable Signed-off-by: YangKeao --- ddl/cluster.go | 2 +- ddl/ddl_api.go | 6 +- domain/sysvar_cache.go | 2 +- executor/aggfuncs/builder.go | 3 +- executor/analyze_utils.go | 3 +- executor/checksum.go | 2 +- executor/executor.go | 4 +- executor/infoschema_reader.go | 4 +- executor/set.go | 10 +- executor/set_test.go | 2 +- executor/show.go | 8 +- expression/aggregation/agg_to_pb.go | 3 +- expression/aggregation/descriptor.go | 3 +- expression/builtin_time.go | 3 +- expression/builtin_time_test.go | 3 +- expression/helper.go | 3 +- infoschema/perfschema/tables.go | 24 +- infoschema/tables.go | 11 +- planner/core/expression_rewriter.go | 4 +- plugin/conn_ip_example/conn_ip_example.go | 2 +- server/conn.go | 6 +- server/http_handler.go | 12 +- server/http_handler_serial_test.go | 9 +- session/session.go | 10 +- session/session_test/session_test.go | 8 +- sessionctx/variable/mock_globalaccessor.go | 8 +- .../variable/mock_globalaccessor_test.go | 11 +- sessionctx/variable/session.go | 10 +- sessionctx/variable/sysvar.go | 273 +++++++++--------- sessionctx/variable/sysvar_test.go | 111 +++---- sessionctx/variable/variable.go | 19 +- sessionctx/variable/variable_test.go | 9 +- sessionctx/variable/varsutil_test.go | 57 ++-- telemetry/data_feature_usage.go | 14 +- util/gcutil/gcutil.go | 4 +- 35 files changed, 339 insertions(+), 324 deletions(-) diff --git a/ddl/cluster.go b/ddl/cluster.go index a6f80991ca0c9..c874d677827be 100644 --- a/ddl/cluster.go +++ b/ddl/cluster.go @@ -118,7 +118,7 @@ func ValidateFlashbackTS(ctx context.Context, sctx sessionctx.Context, flashBack } func setTiDBSuperReadOnly(sess sessionctx.Context, value string) error { - return sess.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBSuperReadOnly, value) + return sess.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBSuperReadOnly, value) } func getTiDBSuperReadOnly(sess sessionctx.Context) (string, error) { diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 092ac77782f63..45471ebe5d7b8 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -94,11 +94,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 = sessionVars.GetSessionOrGlobalSystemVar(variable.CollationServer) + charsetOpt.Col, err = sessionVars.GetSessionOrGlobalSystemVar(context.Background(), variable.CollationServer) if err != nil { return err } - charsetOpt.Chs, err = sessionVars.GetSessionOrGlobalSystemVar(variable.CharacterSetServer) + charsetOpt.Chs, err = sessionVars.GetSessionOrGlobalSystemVar(context.Background(), variable.CharacterSetServer) if err != nil { return err } @@ -2636,7 +2636,7 @@ func (d *ddl) preSplitAndScatter(ctx sessionctx.Context, tbInfo *model.TableInfo preSplit func() scatterRegion bool ) - val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBScatterRegion) + val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBScatterRegion) if err != nil { logutil.BgLogger().Warn("[ddl] won't scatter region", zap.Error(err)) } else { diff --git a/domain/sysvar_cache.go b/domain/sysvar_cache.go index 238f8f867257c..370260a67c02a 100644 --- a/domain/sysvar_cache.go +++ b/domain/sysvar_cache.go @@ -144,7 +144,7 @@ func (do *Domain) rebuildSysVarCache(ctx sessionctx.Context) error { // This does not apply to INSTANCE scoped vars (HasGlobalScope() is false) if sv.SetGlobal != nil && !sv.SkipSysvarCache() { sVal = sv.ValidateWithRelaxedValidation(ctx.GetSessionVars(), sVal, variable.ScopeGlobal) - err = sv.SetGlobal(ctx.GetSessionVars(), sVal) + err = sv.SetGlobal(context.Background(), ctx.GetSessionVars(), sVal) if err != nil { logutil.BgLogger().Error(fmt.Sprintf("load global variable %s error", sv.Name), zap.Error(err)) } diff --git a/executor/aggfuncs/builder.go b/executor/aggfuncs/builder.go index 51b72ebfc242b..f215983d3c7e4 100644 --- a/executor/aggfuncs/builder.go +++ b/executor/aggfuncs/builder.go @@ -15,6 +15,7 @@ package aggfuncs import ( + "context" "fmt" "strconv" @@ -462,7 +463,7 @@ func buildGroupConcat(ctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDe panic(fmt.Sprintf("Error happened when buildGroupConcat: %s", err.Error())) } var s string - s, err = ctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.GroupConcatMaxLen) + s, err = ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.GroupConcatMaxLen) if err != nil { panic(fmt.Sprintf("Error happened when buildGroupConcat: no system variable named '%s'", variable.GroupConcatMaxLen)) } diff --git a/executor/analyze_utils.go b/executor/analyze_utils.go index b4ec10a104ac5..c6d4886d79b7c 100644 --- a/executor/analyze_utils.go +++ b/executor/analyze_utils.go @@ -15,6 +15,7 @@ package executor import ( + "context" "strconv" "sync" @@ -28,7 +29,7 @@ import ( func getBuildStatsConcurrency(ctx sessionctx.Context) (int, error) { sessionVars := ctx.GetSessionVars() - concurrency, err := sessionVars.GetSessionOrGlobalSystemVar(variable.TiDBBuildStatsConcurrency) + concurrency, err := sessionVars.GetSessionOrGlobalSystemVar(context.Background(), variable.TiDBBuildStatsConcurrency) if err != nil { return 0, err } diff --git a/executor/checksum.go b/executor/checksum.go index a23ec0b577b48..fa2d02338ec3f 100644 --- a/executor/checksum.go +++ b/executor/checksum.go @@ -272,7 +272,7 @@ func (c *checksumContext) HandleResponse(update *tipb.ChecksumResponse) { func getChecksumTableConcurrency(ctx sessionctx.Context) (int, error) { sessionVars := ctx.GetSessionVars() - concurrency, err := sessionVars.GetSessionOrGlobalSystemVar(variable.TiDBChecksumTableConcurrency) + concurrency, err := sessionVars.GetSessionOrGlobalSystemVar(context.Background(), variable.TiDBChecksumTableConcurrency) if err != nil { return 0, err } diff --git a/executor/executor.go b/executor/executor.go index d14f8a55a7de3..6f2126c63f4a9 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1630,9 +1630,9 @@ func (e *TableScanExec) nextChunk4InfoSchema(ctx context.Context, chk *chunk.Chu } mutableRow := chunk.MutRowFromTypes(retTypes(e)) type tableIter interface { - IterRecords(sessionctx.Context, []*table.Column, table.RecordIterFunc) error + IterRecords(ctx context.Context, sctx sessionctx.Context, cols []*table.Column, fn table.RecordIterFunc) error } - err := (e.t.(tableIter)).IterRecords(e.ctx, columns, func(_ kv.Handle, rec []types.Datum, cols []*table.Column) (bool, error) { + err := (e.t.(tableIter)).IterRecords(ctx, e.ctx, columns, func(_ kv.Handle, rec []types.Datum, cols []*table.Column) (bool, error) { mutableRow.SetDatums(rec...) e.virtualTableChunkList.AppendRow(mutableRow.ToRow()) return true, nil diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 66ddbc2271afc..0f33a34e269e9 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -148,7 +148,7 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex case infoschema.TableConstraints: e.setDataFromTableConstraints(sctx, dbs) case infoschema.TableSessionVar: - e.rows, err = infoschema.GetDataFromSessionVariables(sctx) + e.rows, err = infoschema.GetDataFromSessionVariables(ctx, sctx) case infoschema.TableTiDBServersInfo: err = e.setDataForServersInfo(sctx) case infoschema.TableTiFlashReplica: @@ -402,7 +402,7 @@ func (e *memtableRetriever) setDataForVariablesInfo(ctx sessionctx.Context) erro if infoschema.SysVarHiddenForSem(ctx, sv.Name) { continue } - currentVal, err := ctx.GetSessionVars().GetSessionOrGlobalSystemVar(sv.Name) + currentVal, err := ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), sv.Name) if err != nil { currentVal = "" } diff --git a/executor/set.go b/executor/set.go index 90ec6d750299c..b3b8c00c1d316 100644 --- a/executor/set.go +++ b/executor/set.go @@ -123,11 +123,11 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres } if v.IsGlobal { - valStr, err := e.getVarValue(v, sysVar) + valStr, err := e.getVarValue(ctx, v, sysVar) if err != nil { return err } - err = sessionVars.GlobalVarsAccessor.SetGlobalSysVar(name, valStr) + err = sessionVars.GlobalVarsAccessor.SetGlobalSysVar(ctx, name, valStr) if err != nil { return err } @@ -142,7 +142,7 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres return err } // Set session variable - valStr, err := e.getVarValue(v, nil) + valStr, err := e.getVarValue(ctx, v, nil) if err != nil { return err } @@ -251,7 +251,7 @@ func (e *SetExecutor) setCharset(cs, co string, isSetName bool) error { return errors.Trace(sessionVars.SetSystemVar(variable.CollationConnection, coDb)) } -func (e *SetExecutor) getVarValue(v *expression.VarAssignment, sysVar *variable.SysVar) (value string, err error) { +func (e *SetExecutor) getVarValue(ctx context.Context, v *expression.VarAssignment, sysVar *variable.SysVar) (value string, err error) { if v.IsDefault { // To set a SESSION variable to the GLOBAL value or a GLOBAL value // to the compiled-in MySQL default value, use the DEFAULT keyword. @@ -259,7 +259,7 @@ func (e *SetExecutor) getVarValue(v *expression.VarAssignment, sysVar *variable. if sysVar != nil { return sysVar.Value, nil } - return e.ctx.GetSessionVars().GetGlobalSystemVar(v.Name) + return e.ctx.GetSessionVars().GetGlobalSystemVar(ctx, v.Name) } nativeVal, err := v.Expr.Eval(chunk.Row{}) if err != nil || nativeVal.IsNull() { diff --git a/executor/set_test.go b/executor/set_test.go index 0f099e8182e44..0816dfb74df97 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -922,7 +922,7 @@ func TestSetCharset(t *testing.T) { check := func(args ...string) { for i, v := range characterSetVariables { - sVar, err := sessionVars.GetSessionOrGlobalSystemVar(v) + sVar, err := sessionVars.GetSessionOrGlobalSystemVar(context.Background(), v) require.NoError(t, err) require.Equal(t, args[i], sVar, fmt.Sprintf("%d: %s", i, characterSetVariables[i])) } diff --git a/executor/show.go b/executor/show.go index 9f5a1ba0d2194..bd0f779f488ee 100644 --- a/executor/show.go +++ b/executor/show.go @@ -204,7 +204,7 @@ func (e *ShowExec) fetchAll(ctx context.Context) error { case ast.ShowTriggers: return e.fetchShowTriggers() case ast.ShowVariables: - return e.fetchShowVariables() + return e.fetchShowVariables(ctx) case ast.ShowWarnings: return e.fetchShowWarnings(false) case ast.ShowErrors: @@ -817,7 +817,7 @@ func (e *ShowExec) fetchShowMasterStatus() error { return nil } -func (e *ShowExec) fetchShowVariables() (err error) { +func (e *ShowExec) fetchShowVariables(ctx context.Context) (err error) { var ( value string sessionVars = e.ctx.GetSessionVars() @@ -849,7 +849,7 @@ func (e *ShowExec) fetchShowVariables() (err error) { if infoschema.SysVarHiddenForSem(e.ctx, v.Name) { continue } - value, err = sessionVars.GetGlobalSystemVar(v.Name) + value, err = sessionVars.GetGlobalSystemVar(ctx, v.Name) if err != nil { return errors.Trace(err) } @@ -874,7 +874,7 @@ func (e *ShowExec) fetchShowVariables() (err error) { if infoschema.SysVarHiddenForSem(e.ctx, v.Name) { continue } - value, err = sessionVars.GetSessionOrGlobalSystemVar(v.Name) + value, err = sessionVars.GetSessionOrGlobalSystemVar(context.Background(), v.Name) if err != nil { return errors.Trace(err) } diff --git a/expression/aggregation/agg_to_pb.go b/expression/aggregation/agg_to_pb.go index 54fbce47df23a..1d90ab02fb253 100644 --- a/expression/aggregation/agg_to_pb.go +++ b/expression/aggregation/agg_to_pb.go @@ -15,6 +15,7 @@ package aggregation import ( + "context" "strconv" "github.com/pingcap/errors" @@ -130,7 +131,7 @@ func AggFuncToPBExpr(sctx sessionctx.Context, client kv.Client, aggFunc *AggFunc orderBy = append(orderBy, pbArg) } // encode GroupConcatMaxLen - GCMaxLen, err := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.GroupConcatMaxLen) + GCMaxLen, err := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.GroupConcatMaxLen) if err != nil { return nil, errors.Errorf("Error happened when buildGroupConcat: no system variable named '%s'", variable.GroupConcatMaxLen) } diff --git a/expression/aggregation/descriptor.go b/expression/aggregation/descriptor.go index e174108cbd9b4..2af7d4d49f348 100644 --- a/expression/aggregation/descriptor.go +++ b/expression/aggregation/descriptor.go @@ -16,6 +16,7 @@ package aggregation import ( "bytes" + "context" "fmt" "math" "strconv" @@ -229,7 +230,7 @@ func (a *AggFuncDesc) GetAggFunc(ctx sessionctx.Context) Aggregation { var s string var err error var maxLen uint64 - s, err = ctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.GroupConcatMaxLen) + s, err = ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.GroupConcatMaxLen) if err != nil { panic(fmt.Sprintf("Error happened when GetAggFunc: no system variable named '%s'", variable.GroupConcatMaxLen)) } diff --git a/expression/builtin_time.go b/expression/builtin_time.go index e6bc7fe57371b..83f18d1c1653a 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -19,6 +19,7 @@ package expression import ( + "context" "fmt" "math" "regexp" @@ -6643,7 +6644,7 @@ func (b *builtinTiDBCurrentTsoSig) Clone() builtinFunc { // evalInt evals currentTSO(). func (b *builtinTiDBCurrentTsoSig) evalInt(row chunk.Row) (d int64, isNull bool, err error) { - tso, _ := b.ctx.GetSessionVars().GetSessionOrGlobalSystemVar("tidb_current_ts") + tso, _ := b.ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), "tidb_current_ts") itso, _ := strconv.ParseInt(tso, 10, 64) return itso, false, nil } diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index fe33a92e2a99a..55973f9dab5f8 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -15,6 +15,7 @@ package expression import ( + "context" "fmt" "math" "strconv" @@ -3112,7 +3113,7 @@ func TestCurrentTso(t *testing.T) { v, err := evalBuiltinFunc(f, chunk.Row{}) require.NoError(t, err) n := v.GetInt64() - tso, _ := ctx.GetSessionVars().GetSessionOrGlobalSystemVar("tidb_current_ts") + tso, _ := ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), "tidb_current_ts") itso, _ := strconv.ParseInt(tso, 10, 64) require.Equal(t, itso, n, v.Kind()) } diff --git a/expression/helper.go b/expression/helper.go index 6e235d1abcc96..c9534be9493ff 100644 --- a/expression/helper.go +++ b/expression/helper.go @@ -15,6 +15,7 @@ package expression import ( + "context" "math" "strings" "time" @@ -164,7 +165,7 @@ func getStmtTimestamp(ctx sessionctx.Context) (time.Time, error) { } sessionVars := ctx.GetSessionVars() - timestampStr, err := sessionVars.GetSessionOrGlobalSystemVar("timestamp") + timestampStr, err := sessionVars.GetSessionOrGlobalSystemVar(context.Background(), "timestamp") if err != nil { return now, err } diff --git a/infoschema/perfschema/tables.go b/infoschema/perfschema/tables.go index 5046dd318ec19..9a5a36235cfa4 100644 --- a/infoschema/perfschema/tables.go +++ b/infoschema/perfschema/tables.go @@ -15,6 +15,7 @@ package perfschema import ( + "context" "fmt" "net/http" "strings" @@ -219,7 +220,7 @@ func initTableIndices(t *perfSchemaTable) error { return nil } -func (vt *perfSchemaTable) getRows(ctx sessionctx.Context, cols []*table.Column) (fullRows [][]types.Datum, err error) { +func (vt *perfSchemaTable) getRows(ctx context.Context, sctx sessionctx.Context, cols []*table.Column) (fullRows [][]types.Datum, err error) { switch vt.meta.Name.O { case tableNameTiDBProfileCPU: fullRows, err = (&profile.Collector{}).ProfileGraph("cpu") @@ -235,22 +236,22 @@ func (vt *perfSchemaTable) getRows(ctx sessionctx.Context, cols []*table.Column) fullRows, err = (&profile.Collector{}).ProfileGraph("goroutine") case tableNameTiKVProfileCPU: interval := fmt.Sprintf("%d", profile.CPUProfileInterval/time.Second) - fullRows, err = dataForRemoteProfile(ctx, "tikv", "/debug/pprof/profile?seconds="+interval, false) + fullRows, err = dataForRemoteProfile(sctx, "tikv", "/debug/pprof/profile?seconds="+interval, false) case tableNamePDProfileCPU: interval := fmt.Sprintf("%d", profile.CPUProfileInterval/time.Second) - fullRows, err = dataForRemoteProfile(ctx, "pd", "/pd/api/v1/debug/pprof/profile?seconds="+interval, false) + fullRows, err = dataForRemoteProfile(sctx, "pd", "/pd/api/v1/debug/pprof/profile?seconds="+interval, false) case tableNamePDProfileMemory: - fullRows, err = dataForRemoteProfile(ctx, "pd", "/pd/api/v1/debug/pprof/heap", false) + fullRows, err = dataForRemoteProfile(sctx, "pd", "/pd/api/v1/debug/pprof/heap", false) case tableNamePDProfileMutex: - fullRows, err = dataForRemoteProfile(ctx, "pd", "/pd/api/v1/debug/pprof/mutex", false) + fullRows, err = dataForRemoteProfile(sctx, "pd", "/pd/api/v1/debug/pprof/mutex", false) case tableNamePDProfileAllocs: - fullRows, err = dataForRemoteProfile(ctx, "pd", "/pd/api/v1/debug/pprof/allocs", false) + fullRows, err = dataForRemoteProfile(sctx, "pd", "/pd/api/v1/debug/pprof/allocs", false) case tableNamePDProfileBlock: - fullRows, err = dataForRemoteProfile(ctx, "pd", "/pd/api/v1/debug/pprof/block", false) + fullRows, err = dataForRemoteProfile(sctx, "pd", "/pd/api/v1/debug/pprof/block", false) case tableNamePDProfileGoroutines: - fullRows, err = dataForRemoteProfile(ctx, "pd", "/pd/api/v1/debug/pprof/goroutine?debug=2", true) + fullRows, err = dataForRemoteProfile(sctx, "pd", "/pd/api/v1/debug/pprof/goroutine?debug=2", true) case tableNameSessionVariables: - fullRows, err = infoschema.GetDataFromSessionVariables(ctx) + fullRows, err = infoschema.GetDataFromSessionVariables(ctx, sctx) } if err != nil { return @@ -270,9 +271,8 @@ func (vt *perfSchemaTable) getRows(ctx sessionctx.Context, cols []*table.Column) } // IterRecords implements table.Table IterRecords interface. -func (vt *perfSchemaTable) IterRecords(ctx sessionctx.Context, cols []*table.Column, - fn table.RecordIterFunc) error { - rows, err := vt.getRows(ctx, cols) +func (vt *perfSchemaTable) IterRecords(ctx context.Context, sctx sessionctx.Context, cols []*table.Column, fn table.RecordIterFunc) error { + rows, err := vt.getRows(ctx, sctx, cols) if err != nil { return err } diff --git a/infoschema/tables.go b/infoschema/tables.go index 74d064b55759a..9d03518425c11 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1903,16 +1903,16 @@ func SysVarHiddenForSem(ctx sessionctx.Context, sysVarNameInLower string) bool { } // GetDataFromSessionVariables return the [name, value] of all session variables -func GetDataFromSessionVariables(ctx sessionctx.Context) ([][]types.Datum, error) { - sessionVars := ctx.GetSessionVars() +func GetDataFromSessionVariables(ctx context.Context, sctx sessionctx.Context) ([][]types.Datum, error) { + sessionVars := sctx.GetSessionVars() sysVars := variable.GetSysVars() rows := make([][]types.Datum, 0, len(sysVars)) for _, v := range sysVars { - if SysVarHiddenForSem(ctx, v.Name) { + if SysVarHiddenForSem(sctx, v.Name) { continue } var value string - value, err := sessionVars.GetSessionOrGlobalSystemVar(v.Name) + value, err := sessionVars.GetSessionOrGlobalSystemVar(ctx, v.Name) if err != nil { return nil, err } @@ -2016,8 +2016,7 @@ type infoschemaTable struct { } // IterRecords implements table.Table IterRecords interface. -func (*infoschemaTable) IterRecords(_ sessionctx.Context, _ []*table.Column, - _ table.RecordIterFunc) error { +func (*infoschemaTable) IterRecords(ctx context.Context, sctx sessionctx.Context, cols []*table.Column, fn table.RecordIterFunc) error { return nil } diff --git a/planner/core/expression_rewriter.go b/planner/core/expression_rewriter.go index 73a998197cc0f..2e22a752df310 100644 --- a/planner/core/expression_rewriter.go +++ b/planner/core/expression_rewriter.go @@ -1391,9 +1391,9 @@ func (er *expressionRewriter) rewriteVariable(v *ast.VariableExpr) { if sysVar.HasNoneScope() { val = sysVar.Value } else if v.IsGlobal { - val, err = sessionVars.GetGlobalSystemVar(name) + val, err = sessionVars.GetGlobalSystemVar(er.ctx, name) } else { - val, err = sessionVars.GetSessionOrGlobalSystemVar(name) + val, err = sessionVars.GetSessionOrGlobalSystemVar(er.ctx, name) } if err != nil { er.err = err diff --git a/plugin/conn_ip_example/conn_ip_example.go b/plugin/conn_ip_example/conn_ip_example.go index f6d09ffc5c612..082a7b4cdc04b 100644 --- a/plugin/conn_ip_example/conn_ip_example.go +++ b/plugin/conn_ip_example/conn_ip_example.go @@ -66,7 +66,7 @@ func OnInit(ctx context.Context, manifest *plugin.Manifest) error { // (Optional) the SetGlobal function is called when a global variable is changed. // This will only be called on the TiDB server that the change is made on, // and not on the tidb-server peers which will also update their global variable eventually. - SetGlobal: func(vars *variable.SessionVars, value string) error { + SetGlobal: func(_ context.Context, vars *variable.SessionVars, value string) error { fmt.Println("The set global function was called") return nil }, diff --git a/server/conn.go b/server/conn.go index 478f86a821860..49a7f97a1df24 100644 --- a/server/conn.go +++ b/server/conn.go @@ -402,7 +402,7 @@ func (cc *clientConn) writeInitialHandshake(ctx context.Context) error { return err } } - defAuthPlugin, err := cc.ctx.GetSessionVars().GetGlobalSystemVar(variable.DefaultAuthPlugin) + defAuthPlugin, err := cc.ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.DefaultAuthPlugin) if err != nil { return err } @@ -971,7 +971,7 @@ func (cc *clientConn) skipInitConnect() bool { // initResultEncoder initialize the result encoder for current connection. func (cc *clientConn) initResultEncoder(ctx context.Context) { - chs, err := cc.ctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.CharacterSetResults) + chs, err := cc.ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.CharacterSetResults) if err != nil { chs = "" logutil.Logger(ctx).Warn("get character_set_results system variable failed", zap.Error(err)) @@ -980,7 +980,7 @@ func (cc *clientConn) initResultEncoder(ctx context.Context) { } func (cc *clientConn) initInputEncoder(ctx context.Context) { - chs, err := cc.ctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.CharacterSetClient) + chs, err := cc.ctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.CharacterSetClient) if err != nil { chs = "" logutil.Logger(ctx).Warn("get character_set_client system variable failed", zap.Error(err)) diff --git a/server/http_handler.go b/server/http_handler.go index 82d9ec051c722..1338ed072c1d0 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -658,9 +658,9 @@ func (h settingsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { switch asyncCommit { case "0": - err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnableAsyncCommit, variable.Off) + err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBEnableAsyncCommit, variable.Off) case "1": - err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnableAsyncCommit, variable.On) + err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBEnableAsyncCommit, variable.On) default: writeError(w, errors.New("illegal argument")) return @@ -680,9 +680,9 @@ func (h settingsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { switch onePC { case "0": - err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnable1PC, variable.Off) + err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBEnable1PC, variable.Off) case "1": - err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnable1PC, variable.On) + err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBEnable1PC, variable.On) default: writeError(w, errors.New("illegal argument")) return @@ -747,9 +747,9 @@ func (h settingsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { switch mutationChecker { case "0": - err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnableMutationChecker, variable.Off) + err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBEnableMutationChecker, variable.Off) case "1": - err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnableMutationChecker, variable.On) + err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBEnableMutationChecker, variable.On) default: writeError(w, errors.New("illegal argument")) return diff --git a/server/http_handler_serial_test.go b/server/http_handler_serial_test.go index c6a07c90760a1..b0b3903eeb201 100644 --- a/server/http_handler_serial_test.go +++ b/server/http_handler_serial_test.go @@ -16,6 +16,7 @@ package server import ( "bytes" + "context" "database/sql" "encoding/json" "fmt" @@ -65,10 +66,10 @@ func TestPostSettings(t *testing.T) { require.Equal(t, zap.ErrorLevel, log.GetLevel()) require.Equal(t, "error", config.GetGlobalConfig().Log.Level) require.True(t, variable.ProcessGeneralLog.Load()) - val, err := se.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnableAsyncCommit) + val, err := se.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnableAsyncCommit) require.NoError(t, err) require.Equal(t, variable.On, val) - val, err = se.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnable1PC) + val, err = se.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnable1PC) require.NoError(t, err) require.Equal(t, variable.On, val) @@ -84,10 +85,10 @@ func TestPostSettings(t *testing.T) { require.False(t, variable.ProcessGeneralLog.Load()) require.Equal(t, zap.FatalLevel, log.GetLevel()) require.Equal(t, "fatal", config.GetGlobalConfig().Log.Level) - val, err = se.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnableAsyncCommit) + val, err = se.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnableAsyncCommit) require.NoError(t, err) require.Equal(t, variable.Off, val) - val, err = se.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnable1PC) + val, err = se.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnable1PC) require.NoError(t, err) require.Equal(t, variable.Off, val) form.Set("log_level", os.Getenv("log_level")) diff --git a/session/session.go b/session/session.go index ec98b21b41012..684c0fb1b6967 100644 --- a/session/session.go +++ b/session/session.go @@ -1465,7 +1465,7 @@ func (s *session) GetGlobalSysVar(name string) (string, error) { // SetGlobalSysVar implements GlobalVarAccessor.SetGlobalSysVar interface. // it is called (but skipped) when setting instance scope -func (s *session) SetGlobalSysVar(name, value string) (err error) { +func (s *session) SetGlobalSysVar(ctx context.Context, name string, value string) (err error) { sv := variable.GetSysVar(name) if sv == nil { return variable.ErrUnknownSystemVar.GenWithStackByArgs(name) @@ -1473,7 +1473,7 @@ func (s *session) SetGlobalSysVar(name, value string) (err error) { if value, err = sv.Validate(s.sessionVars, value, variable.ScopeGlobal); err != nil { return err } - if err = sv.SetGlobalFromHook(s.sessionVars, value, false); err != nil { + if err = sv.SetGlobalFromHook(ctx, s.sessionVars, value, false); err != nil { return err } if sv.HasInstanceScope() { // skip for INSTANCE scope @@ -1487,18 +1487,18 @@ func (s *session) SetGlobalSysVar(name, value string) (err error) { // SetGlobalSysVarOnly updates the sysvar, but does not call the validation function or update aliases. // This is helpful to prevent duplicate warnings being appended from aliases, or recursion. -func (s *session) SetGlobalSysVarOnly(name, value string) (err error) { +func (s *session) SetGlobalSysVarOnly(ctx context.Context, name string, value string) (err error) { sv := variable.GetSysVar(name) if sv == nil { return variable.ErrUnknownSystemVar.GenWithStackByArgs(name) } - if err = sv.SetGlobalFromHook(s.sessionVars, value, true); err != nil { + if err = sv.SetGlobalFromHook(ctx, s.sessionVars, value, true); err != nil { return err } if sv.HasInstanceScope() { // skip for INSTANCE scope return nil } - return s.replaceGlobalVariablesTableValue(context.TODO(), sv.Name, value) + return s.replaceGlobalVariablesTableValue(ctx, sv.Name, value) } // SetTiDBTableValue implements GlobalVarAccessor.SetTiDBTableValue interface. diff --git a/session/session_test/session_test.go b/session/session_test/session_test.go index b58e78ede9c23..40bbdfcefe2f3 100644 --- a/session/session_test/session_test.go +++ b/session/session_test/session_test.go @@ -3700,7 +3700,7 @@ func TestGlobalVarAccessor(t *testing.T) { require.NoError(t, err) require.Equal(t, varValue, v) // Set global var to another value - err = se.SetGlobalSysVar(varName, varValue1) + err = se.SetGlobalSysVar(context.Background(), varName, varValue1) require.NoError(t, err) v, err = se.GetGlobalSysVar(varName) require.NoError(t, err) @@ -3713,7 +3713,7 @@ func TestGlobalVarAccessor(t *testing.T) { v, err = se1.GetGlobalSysVar(varName) require.NoError(t, err) require.Equal(t, varValue0, v) - err = se1.SetGlobalSysVar(varName, varValue2) + err = se1.SetGlobalSysVar(context.Background(), varName, varValue2) require.NoError(t, err) v, err = se1.GetGlobalSysVar(varName) require.NoError(t, err) @@ -3835,7 +3835,7 @@ func TestSetInstanceSysvarBySetGlobalSysVar(t *testing.T) { // but GetGlobalSysVar could not access TiDBGeneralLog's GetGlobal. // set to "1" - err = se.SetGlobalSysVar(varName, "ON") + err = se.SetGlobalSysVar(context.Background(), varName, "ON") require.NoError(t, err) v, err = se.GetGlobalSysVar(varName) tk.MustQuery("select @@global.tidb_general_log").Check(testkit.Rows("1")) @@ -3843,7 +3843,7 @@ func TestSetInstanceSysvarBySetGlobalSysVar(t *testing.T) { require.Equal(t, defaultValue, v) // set back to "0" - err = se.SetGlobalSysVar(varName, defaultValue) + err = se.SetGlobalSysVar(context.Background(), varName, defaultValue) require.NoError(t, err) v, err = se.GetGlobalSysVar(varName) tk.MustQuery("select @@global.tidb_general_log").Check(testkit.Rows("0")) diff --git a/sessionctx/variable/mock_globalaccessor.go b/sessionctx/variable/mock_globalaccessor.go index c4bb86748e9fd..e452c398da424 100644 --- a/sessionctx/variable/mock_globalaccessor.go +++ b/sessionctx/variable/mock_globalaccessor.go @@ -14,6 +14,8 @@ package variable +import "context" + // MockGlobalAccessor implements GlobalVarAccessor interface. it's used in tests type MockGlobalAccessor struct { SessionVars *SessionVars // can be overwritten if needed for correctness. @@ -69,7 +71,7 @@ func (m *MockGlobalAccessor) GetGlobalSysVar(name string) (string, error) { } // SetGlobalSysVar implements GlobalVarAccessor.SetGlobalSysVar interface. -func (m *MockGlobalAccessor) SetGlobalSysVar(name string, value string) (err error) { +func (m *MockGlobalAccessor) SetGlobalSysVar(ctx context.Context, name string, value string) (err error) { sv := GetSysVar(name) if sv == nil { return ErrUnknownSystemVar.GenWithStackByArgs(name) @@ -77,7 +79,7 @@ func (m *MockGlobalAccessor) SetGlobalSysVar(name string, value string) (err err if value, err = sv.Validate(m.SessionVars, value, ScopeGlobal); err != nil { return err } - if err = sv.SetGlobalFromHook(m.SessionVars, value, false); err != nil { + if err = sv.SetGlobalFromHook(ctx, m.SessionVars, value, false); err != nil { return err } m.vals[name] = value @@ -85,7 +87,7 @@ func (m *MockGlobalAccessor) SetGlobalSysVar(name string, value string) (err err } // SetGlobalSysVarOnly implements GlobalVarAccessor.SetGlobalSysVarOnly interface. -func (m *MockGlobalAccessor) SetGlobalSysVarOnly(name string, value string) error { +func (m *MockGlobalAccessor) SetGlobalSysVarOnly(ctx context.Context, name string, value string) error { sv := GetSysVar(name) if sv == nil { return ErrUnknownSystemVar.GenWithStackByArgs(name) diff --git a/sessionctx/variable/mock_globalaccessor_test.go b/sessionctx/variable/mock_globalaccessor_test.go index 57ed4931a342d..3372a92790275 100644 --- a/sessionctx/variable/mock_globalaccessor_test.go +++ b/sessionctx/variable/mock_globalaccessor_test.go @@ -15,6 +15,7 @@ package variable import ( + "context" "testing" "github.com/stretchr/testify/require" @@ -33,19 +34,19 @@ func TestMockAPI(t *testing.T) { require.Error(t, err) // invalid option name - err = mock.SetGlobalSysVar("illegalopt", "val") + err = mock.SetGlobalSysVar(context.Background(), "illegalopt", "val") require.Error(t, err) - err = mock.SetGlobalSysVarOnly("illegalopt", "val") + err = mock.SetGlobalSysVarOnly(context.Background(), "illegalopt", "val") require.Error(t, err) // valid option, invalid value - err = mock.SetGlobalSysVar(DefaultAuthPlugin, "invalidvalue") + err = mock.SetGlobalSysVar(context.Background(), DefaultAuthPlugin, "invalidvalue") require.Error(t, err) // valid option, valid value - err = mock.SetGlobalSysVar(DefaultAuthPlugin, "mysql_native_password") + err = mock.SetGlobalSysVar(context.Background(), DefaultAuthPlugin, "mysql_native_password") require.NoError(t, err) - err = mock.SetGlobalSysVarOnly(DefaultAuthPlugin, "mysql_native_password") + err = mock.SetGlobalSysVarOnly(context.Background(), DefaultAuthPlugin, "mysql_native_password") require.NoError(t, err) // Test GetTiDBTableValue diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index fef6154567c8b..c0b71b4e10af8 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -1740,7 +1740,7 @@ func (s *SessionVars) GetCharsetInfo() (charset, collation string) { // GetParseParams gets the parse parameters from session variables. func (s *SessionVars) GetParseParams() []parser.ParseParam { chs, coll := s.GetCharsetInfo() - cli, err := s.GetSessionOrGlobalSystemVar(CharacterSetClient) + cli, err := s.GetSessionOrGlobalSystemVar(context.Background(), CharacterSetClient) if err != nil { cli = "" } @@ -1988,7 +1988,7 @@ func (s *SessionVars) ClearStmtVars() { // GetSessionOrGlobalSystemVar gets a system variable. // If it is a session only variable, use the default value defined in code. // Returns error if there is no such variable. -func (s *SessionVars) GetSessionOrGlobalSystemVar(name string) (string, error) { +func (s *SessionVars) GetSessionOrGlobalSystemVar(ctx context.Context, name string) (string, error) { sv := GetSysVar(name) if sv == nil { return "", ErrUnknownSystemVar.GenWithStackByArgs(name) @@ -2014,7 +2014,7 @@ func (s *SessionVars) GetSessionOrGlobalSystemVar(name string) (string, error) { } return sv.GetSessionFromHook(s) } - return sv.GetGlobalFromHook(s) + return sv.GetGlobalFromHook(ctx, s) } // GetSessionStatesSystemVar gets the session variable value for session states. @@ -2041,12 +2041,12 @@ func (s *SessionVars) GetSessionStatesSystemVar(name string) (string, bool, erro } // GetGlobalSystemVar gets a global system variable. -func (s *SessionVars) GetGlobalSystemVar(name string) (string, error) { +func (s *SessionVars) GetGlobalSystemVar(ctx context.Context, name string) (string, error) { sv := GetSysVar(name) if sv == nil { return "", ErrUnknownSystemVar.GenWithStackByArgs(name) } - return sv.GetGlobalFromHook(s) + return sv.GetGlobalFromHook(ctx, s) } // SetStmtVar sets system variable and updates SessionVars states. diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 42690602b32cf..c350d71db5599 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -15,6 +15,7 @@ package variable import ( + "context" "encoding/json" "fmt" "math" @@ -348,7 +349,7 @@ var defaultSysVars = []*SysVar{ }, }, /* The system variables below have INSTANCE scope */ - {Scope: ScopeInstance, Name: TiDBLogFileMaxDays, Value: strconv.Itoa(config.GetGlobalConfig().Log.File.MaxDays), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBLogFileMaxDays, Value: strconv.Itoa(config.GetGlobalConfig().Log.File.MaxDays), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { maxAge, err := strconv.ParseInt(val, 10, 32) if err != nil { return err @@ -361,72 +362,72 @@ var defaultSysVars = []*SysVar{ return err } return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(int64(GlobalLogMaxDays.Load()), 10), nil }}, - {Scope: ScopeInstance, Name: TiDBConfig, Value: "", ReadOnly: true, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeInstance, Name: TiDBConfig, Value: "", ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return config.GetJSONConfig() }}, - {Scope: ScopeInstance, Name: TiDBGeneralLog, Value: BoolToOnOff(DefTiDBGeneralLog), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBGeneralLog, Value: BoolToOnOff(DefTiDBGeneralLog), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { ProcessGeneralLog.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(ProcessGeneralLog.Load()), nil }}, - {Scope: ScopeInstance, Name: TiDBSlowLogThreshold, Value: strconv.Itoa(logutil.DefaultSlowThreshold), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBSlowLogThreshold, Value: strconv.Itoa(logutil.DefaultSlowThreshold), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { atomic.StoreUint64(&config.GetGlobalConfig().Instance.SlowThreshold, uint64(TidbOptInt64(val, logutil.DefaultSlowThreshold))) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Instance.SlowThreshold), 10), nil }}, - {Scope: ScopeInstance, Name: TiDBRecordPlanInSlowLog, Value: int32ToBoolStr(logutil.DefaultRecordPlanInSlowLog), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBRecordPlanInSlowLog, Value: int32ToBoolStr(logutil.DefaultRecordPlanInSlowLog), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { atomic.StoreUint32(&config.GetGlobalConfig().Instance.RecordPlanInSlowLog, uint32(TidbOptInt64(val, logutil.DefaultRecordPlanInSlowLog))) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { enabled := atomic.LoadUint32(&config.GetGlobalConfig().Instance.RecordPlanInSlowLog) == 1 return BoolToOnOff(enabled), nil }}, - {Scope: ScopeInstance, Name: TiDBEnableSlowLog, Value: BoolToOnOff(logutil.DefaultTiDBEnableSlowLog), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBEnableSlowLog, Value: BoolToOnOff(logutil.DefaultTiDBEnableSlowLog), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { config.GetGlobalConfig().Instance.EnableSlowLog.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(config.GetGlobalConfig().Instance.EnableSlowLog.Load()), nil }}, - {Scope: ScopeInstance, Name: TiDBCheckMb4ValueInUTF8, Value: BoolToOnOff(config.GetGlobalConfig().Instance.CheckMb4ValueInUTF8.Load()), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBCheckMb4ValueInUTF8, Value: BoolToOnOff(config.GetGlobalConfig().Instance.CheckMb4ValueInUTF8.Load()), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { config.GetGlobalConfig().Instance.CheckMb4ValueInUTF8.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(config.GetGlobalConfig().Instance.CheckMb4ValueInUTF8.Load()), nil }}, - {Scope: ScopeInstance, Name: TiDBPProfSQLCPU, Value: strconv.Itoa(DefTiDBPProfSQLCPU), Type: TypeInt, MinValue: 0, MaxValue: 1, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBPProfSQLCPU, Value: strconv.Itoa(DefTiDBPProfSQLCPU), Type: TypeInt, MinValue: 0, MaxValue: 1, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnablePProfSQLCPU.Store(uint32(tidbOptPositiveInt32(val, DefTiDBPProfSQLCPU)) > 0) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { val := "0" if EnablePProfSQLCPU.Load() { val = "1" } return val, nil }}, - {Scope: ScopeInstance, Name: TiDBDDLSlowOprThreshold, Value: strconv.Itoa(DefTiDBDDLSlowOprThreshold), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBDDLSlowOprThreshold, Value: strconv.Itoa(DefTiDBDDLSlowOprThreshold), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { atomic.StoreUint32(&DDLSlowOprThreshold, uint32(tidbOptPositiveInt32(val, DefTiDBDDLSlowOprThreshold))) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatUint(uint64(atomic.LoadUint32(&DDLSlowOprThreshold)), 10), nil }}, - {Scope: ScopeInstance, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority], Type: TypeEnum, PossibleValues: []string{"NO_PRIORITY", "LOW_PRIORITY", "HIGH_PRIORITY", "DELAYED"}, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority], Type: TypeEnum, PossibleValues: []string{"NO_PRIORITY", "LOW_PRIORITY", "HIGH_PRIORITY", "DELAYED"}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { atomic.StoreInt32(&ForcePriority, int32(mysql.Str2Priority(val))) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return mysql.Priority2Str[mysql.PriorityEnum(atomic.LoadInt32(&ForcePriority))], nil }}, - {Scope: ScopeInstance, Name: TiDBExpensiveQueryTimeThreshold, Value: strconv.Itoa(DefTiDBExpensiveQueryTimeThreshold), Type: TypeUnsigned, MinValue: int64(MinExpensiveQueryTimeThreshold), MaxValue: math.MaxInt32, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBExpensiveQueryTimeThreshold, Value: strconv.Itoa(DefTiDBExpensiveQueryTimeThreshold), Type: TypeUnsigned, MinValue: int64(MinExpensiveQueryTimeThreshold), MaxValue: math.MaxInt32, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { atomic.StoreUint64(&ExpensiveQueryTimeThreshold, uint64(tidbOptPositiveInt32(val, DefTiDBExpensiveQueryTimeThreshold))) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatUint(atomic.LoadUint64(&ExpensiveQueryTimeThreshold), 10), nil }}, - {Scope: ScopeInstance, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { oldConfig := config.GetGlobalConfig() newValue := TiDBOptOn(val) if oldConfig.Instance.EnableCollectExecutionInfo.Load() != newValue { @@ -435,23 +436,23 @@ var defaultSysVars = []*SysVar{ config.StoreGlobalConfig(&newConfig) } return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(config.GetGlobalConfig().Instance.EnableCollectExecutionInfo.Load()), nil }}, - {Scope: ScopeInstance, Name: PluginLoad, Value: "", ReadOnly: true, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeInstance, Name: PluginLoad, Value: "", ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return config.GetGlobalConfig().Instance.PluginLoad, nil }}, - {Scope: ScopeInstance, Name: PluginDir, Value: "/data/deploy/plugin", ReadOnly: true, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeInstance, Name: PluginDir, Value: "/data/deploy/plugin", ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return config.GetGlobalConfig().Instance.PluginDir, nil }}, - {Scope: ScopeInstance, Name: MaxConnections, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().Instance.MaxConnections), 10), Type: TypeUnsigned, MinValue: 0, MaxValue: 100000, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: MaxConnections, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().Instance.MaxConnections), 10), Type: TypeUnsigned, MinValue: 0, MaxValue: 100000, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { config.GetGlobalConfig().Instance.MaxConnections = uint32(TidbOptInt64(val, 0)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatUint(uint64(config.GetGlobalConfig().Instance.MaxConnections), 10), nil }}, {Scope: ScopeInstance, Name: TiDBEnableDDL, Value: BoolToOnOff(config.GetGlobalConfig().Instance.TiDBEnableDDL.Load()), Type: TypeBool, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { oldVal, newVal := config.GetGlobalConfig().Instance.TiDBEnableDDL.Load(), TiDBOptOn(val) if oldVal != newVal { err := switchDDL(newVal) @@ -460,14 +461,14 @@ var defaultSysVars = []*SysVar{ } return nil }, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(config.GetGlobalConfig().Instance.TiDBEnableDDL.Load()), nil }, }, - {Scope: ScopeInstance, Name: TiDBRCReadCheckTS, Value: BoolToOnOff(DefRCReadCheckTS), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeInstance, Name: TiDBRCReadCheckTS, Value: BoolToOnOff(DefRCReadCheckTS), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableRCReadCheckTS.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableRCReadCheckTS.Load()), nil }}, @@ -486,22 +487,22 @@ var defaultSysVars = []*SysVar{ /* TiDB specific variables */ {Scope: ScopeGlobal, Name: TiDBTSOClientBatchMaxWaitTime, Value: strconv.FormatFloat(DefTiDBTSOClientBatchMaxWaitTime, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: 10, - GetGlobal: func(sv *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return strconv.FormatFloat(MaxTSOBatchWaitInterval.Load(), 'f', -1, 64), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { (*SetPDClientDynamicOption.Load())(TiDBTSOClientBatchMaxWaitTime, val) return nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableTSOFollowerProxy, Value: BoolToOnOff(DefTiDBEnableTSOFollowerProxy), Type: TypeBool, GetGlobal: func(sv *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBEnableTSOFollowerProxy, Value: BoolToOnOff(DefTiDBEnableTSOFollowerProxy), Type: TypeBool, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return BoolToOnOff(EnableTSOFollowerProxy.Load()), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { (*SetPDClientDynamicOption.Load())(TiDBEnableTSOFollowerProxy, val) return nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableLocalTxn, Value: BoolToOnOff(DefTiDBEnableLocalTxn), Hidden: true, Type: TypeBool, GetGlobal: func(sv *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBEnableLocalTxn, Value: BoolToOnOff(DefTiDBEnableLocalTxn), Hidden: true, Type: TypeBool, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return BoolToOnOff(EnableLocalTxn.Load()), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { oldVal := EnableLocalTxn.Load() newVal := TiDBOptOn(val) // Make sure the TxnScope is always Global when disable the Local Txn. @@ -515,82 +516,82 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal, Name: TiDBAutoAnalyzeRatio, Value: strconv.FormatFloat(DefAutoAnalyzeRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64}, {Scope: ScopeGlobal, Name: TiDBAutoAnalyzeStartTime, Value: DefAutoAnalyzeStartTime, Type: TypeTime}, {Scope: ScopeGlobal, Name: TiDBAutoAnalyzeEndTime, Value: DefAutoAnalyzeEndTime, Type: TypeTime}, - {Scope: ScopeGlobal, Name: TiDBMemQuotaBindingCache, Value: strconv.FormatInt(DefTiDBMemQuotaBindingCache, 10), Type: TypeUnsigned, MaxValue: math.MaxInt32, GetGlobal: func(sv *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBMemQuotaBindingCache, Value: strconv.FormatInt(DefTiDBMemQuotaBindingCache, 10), Type: TypeUnsigned, MaxValue: math.MaxInt32, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return strconv.FormatInt(MemQuotaBindingCache.Load(), 10), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { MemQuotaBindingCache.Store(TidbOptInt64(val, DefTiDBMemQuotaBindingCache)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLFlashbackConcurrency, Value: strconv.Itoa(DefTiDBDDLFlashbackConcurrency), Type: TypeUnsigned, MinValue: 1, MaxValue: MaxConfigurableConcurrency, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLFlashbackConcurrency, Value: strconv.Itoa(DefTiDBDDLFlashbackConcurrency), Type: TypeUnsigned, MinValue: 1, MaxValue: MaxConfigurableConcurrency, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { SetDDLFlashbackConcurrency(int32(tidbOptPositiveInt32(val, DefTiDBDDLFlashbackConcurrency))) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLReorgWorkerCount, Value: strconv.Itoa(DefTiDBDDLReorgWorkerCount), Type: TypeUnsigned, MinValue: 1, MaxValue: MaxConfigurableConcurrency, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLReorgWorkerCount, Value: strconv.Itoa(DefTiDBDDLReorgWorkerCount), Type: TypeUnsigned, MinValue: 1, MaxValue: MaxConfigurableConcurrency, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { SetDDLReorgWorkerCounter(int32(tidbOptPositiveInt32(val, DefTiDBDDLReorgWorkerCount))) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLReorgBatchSize, Value: strconv.Itoa(DefTiDBDDLReorgBatchSize), Type: TypeUnsigned, MinValue: int64(MinDDLReorgBatchSize), MaxValue: uint64(MaxDDLReorgBatchSize), SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLReorgBatchSize, Value: strconv.Itoa(DefTiDBDDLReorgBatchSize), Type: TypeUnsigned, MinValue: int64(MinDDLReorgBatchSize), MaxValue: uint64(MaxDDLReorgBatchSize), SetGlobal: func(_ context.Context, s *SessionVars, val string) error { SetDDLReorgBatchSize(int32(tidbOptPositiveInt32(val, DefTiDBDDLReorgBatchSize))) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLErrorCountLimit, Value: strconv.Itoa(DefTiDBDDLErrorCountLimit), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt64, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBDDLErrorCountLimit, Value: strconv.Itoa(DefTiDBDDLErrorCountLimit), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt64, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { SetDDLErrorCountLimit(TidbOptInt64(val, DefTiDBDDLErrorCountLimit)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { // It's a global variable, but it also wants to be cached in server. SetMaxDeltaSchemaCount(TidbOptInt64(val, DefTiDBMaxDeltaSchemaCount)) return nil }}, {Scope: ScopeGlobal, Name: TiDBScatterRegion, Value: BoolToOnOff(DefTiDBScatterRegion), Type: TypeBool}, {Scope: ScopeGlobal, Name: TiDBEnableStmtSummary, Value: BoolToOnOff(DefTiDBEnableStmtSummary), Type: TypeBool, AllowEmpty: true, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return stmtsummary.StmtSummaryByDigestMap.SetEnabled(TiDBOptOn(val)) }}, {Scope: ScopeGlobal, Name: TiDBStmtSummaryInternalQuery, Value: BoolToOnOff(DefTiDBStmtSummaryInternalQuery), Type: TypeBool, AllowEmpty: true, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return stmtsummary.StmtSummaryByDigestMap.SetEnabledInternalQuery(TiDBOptOn(val)) }}, {Scope: ScopeGlobal, Name: TiDBStmtSummaryRefreshInterval, Value: strconv.Itoa(DefTiDBStmtSummaryRefreshInterval), Type: TypeInt, MinValue: 1, MaxValue: math.MaxInt32, AllowEmpty: true, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { // convert val to int64 return stmtsummary.StmtSummaryByDigestMap.SetRefreshInterval(TidbOptInt64(val, DefTiDBStmtSummaryRefreshInterval)) }}, {Scope: ScopeGlobal, Name: TiDBStmtSummaryHistorySize, Value: strconv.Itoa(DefTiDBStmtSummaryHistorySize), Type: TypeInt, MinValue: 0, MaxValue: math.MaxUint8, AllowEmpty: true, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return stmtsummary.StmtSummaryByDigestMap.SetHistorySize(TidbOptInt(val, DefTiDBStmtSummaryHistorySize)) }}, {Scope: ScopeGlobal, Name: TiDBStmtSummaryMaxStmtCount, Value: strconv.Itoa(DefTiDBStmtSummaryMaxStmtCount), Type: TypeInt, MinValue: 1, MaxValue: math.MaxInt16, AllowEmpty: true, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return stmtsummary.StmtSummaryByDigestMap.SetMaxStmtCount(uint(TidbOptInt(val, DefTiDBStmtSummaryMaxStmtCount))) }}, {Scope: ScopeGlobal, Name: TiDBStmtSummaryMaxSQLLength, Value: strconv.Itoa(DefTiDBStmtSummaryMaxSQLLength), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, AllowEmpty: true, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return stmtsummary.StmtSummaryByDigestMap.SetMaxSQLLength(TidbOptInt(val, DefTiDBStmtSummaryMaxSQLLength)) }}, {Scope: ScopeGlobal, Name: TiDBCapturePlanBaseline, Value: DefTiDBCapturePlanBaseline, Type: TypeBool, AllowEmptyAll: true}, {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskMaxTime, Value: strconv.Itoa(DefTiDBEvolvePlanTaskMaxTime), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskStartTime, Value: DefTiDBEvolvePlanTaskStartTime, Type: TypeTime}, {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskEndTime, Value: DefTiDBEvolvePlanTaskEndTime, Type: TypeTime}, - {Scope: ScopeGlobal, Name: TiDBStoreLimit, Value: strconv.FormatInt(atomic.LoadInt64(&config.GetGlobalConfig().TiKVClient.StoreLimit), 10), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt64, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBStoreLimit, Value: strconv.FormatInt(atomic.LoadInt64(&config.GetGlobalConfig().TiKVClient.StoreLimit), 10), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt64, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(tikvstore.StoreLimit.Load(), 10), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { tikvstore.StoreLimit.Store(TidbOptInt64(val, DefTiDBStoreLimit)) return nil }}, {Scope: ScopeGlobal, Name: TiDBTxnCommitBatchSize, Value: strconv.FormatUint(tikvstore.DefTxnCommitBatchSize, 10), Type: TypeUnsigned, MinValue: 1, MaxValue: 1 << 30, - GetGlobal: func(sv *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return strconv.FormatUint(tikvstore.TxnCommitBatchSize.Load(), 10), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { tikvstore.TxnCommitBatchSize.Store(uint64(TidbOptInt64(val, int64(tikvstore.DefTxnCommitBatchSize)))) return nil }}, - {Scope: ScopeGlobal, Name: TiDBRestrictedReadOnly, Value: BoolToOnOff(DefTiDBRestrictedReadOnly), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBRestrictedReadOnly, Value: BoolToOnOff(DefTiDBRestrictedReadOnly), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { on := TiDBOptOn(val) // For user initiated SET GLOBAL, also change the value of TiDBSuperReadOnly if on && s.StmtCtx.StmtType == "Set" { - err := s.GlobalVarsAccessor.SetGlobalSysVar(TiDBSuperReadOnly, "ON") + err := s.GlobalVarsAccessor.SetGlobalSysVar(context.Background(), TiDBSuperReadOnly, "ON") if err != nil { return err } @@ -610,11 +611,11 @@ var defaultSysVars = []*SysVar{ } } return normalizedValue, nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { VarTiDBSuperReadOnly.Store(TiDBOptOn(val)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableGOGCTuner, Value: BoolToOnOff(DefTiDBEnableGOGCTuner), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableGOGCTuner, Value: BoolToOnOff(DefTiDBEnableGOGCTuner), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { on := TiDBOptOn(val) gctuner.EnableGOGCTuner.Store(on) if !on { @@ -626,28 +627,28 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal, Name: TiDBEnableTelemetry, Value: BoolToOnOff(DefTiDBEnableTelemetry), Type: TypeBool}, {Scope: ScopeGlobal, Name: TiDBEnableHistoricalStats, Value: Off, Type: TypeBool}, /* tikv gc metrics */ - {Scope: ScopeGlobal, Name: TiDBGCEnable, Value: On, Type: TypeBool, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBGCEnable, Value: On, Type: TypeBool, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return getTiDBTableValue(s, "tikv_gc_enable", On) - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return setTiDBTableValue(s, "tikv_gc_enable", val, "Current GC enable status") }}, - {Scope: ScopeGlobal, Name: TiDBGCRunInterval, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: uint64(time.Hour * 24 * 365), GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBGCRunInterval, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: uint64(time.Hour * 24 * 365), GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return getTiDBTableValue(s, "tikv_gc_run_interval", "10m0s") - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return setTiDBTableValue(s, "tikv_gc_run_interval", val, "GC run interval, at least 10m, in Go format.") }}, - {Scope: ScopeGlobal, Name: TiDBGCLifetime, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: uint64(time.Hour * 24 * 365), GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBGCLifetime, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: uint64(time.Hour * 24 * 365), GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return getTiDBTableValue(s, "tikv_gc_life_time", "10m0s") - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return setTiDBTableValue(s, "tikv_gc_life_time", val, "All versions within life time will not be collected by GC, at least 10m, in Go format.") }}, - {Scope: ScopeGlobal, Name: TiDBGCConcurrency, Value: "-1", Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency, AllowAutoValue: true, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBGCConcurrency, Value: "-1", Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency, AllowAutoValue: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { autoConcurrencyVal, err := getTiDBTableValue(s, "tikv_gc_auto_concurrency", On) if err == nil && autoConcurrencyVal == On { return "-1", nil // convention for "AUTO" } return getTiDBTableValue(s, "tikv_gc_concurrency", "-1") - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { autoConcurrency := Off if val == "-1" { autoConcurrency = On @@ -658,16 +659,16 @@ var defaultSysVars = []*SysVar{ } return setTiDBTableValue(s, "tikv_gc_concurrency", val, "How many goroutines used to do GC parallel, [1, 256], default 2") }}, - {Scope: ScopeGlobal, Name: TiDBGCScanLockMode, Value: "LEGACY", Type: TypeEnum, PossibleValues: []string{"PHYSICAL", "LEGACY"}, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBGCScanLockMode, Value: "LEGACY", Type: TypeEnum, PossibleValues: []string{"PHYSICAL", "LEGACY"}, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return getTiDBTableValue(s, "tikv_gc_scan_lock_mode", "LEGACY") - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return setTiDBTableValue(s, "tikv_gc_scan_lock_mode", val, "Mode of scanning locks, \"physical\" or \"legacy\"") }}, - {Scope: ScopeGlobal, Name: TiDBGCMaxWaitTime, Value: strconv.Itoa(DefTiDBGCMaxWaitTime), Type: TypeInt, MinValue: 600, MaxValue: 31536000, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBGCMaxWaitTime, Value: strconv.Itoa(DefTiDBGCMaxWaitTime), Type: TypeInt, MinValue: 600, MaxValue: 31536000, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { GCMaxWaitTime.Store(TidbOptInt64(val, DefTiDBGCMaxWaitTime)) return nil }}, - {Scope: ScopeGlobal, Name: TiDBTableCacheLease, Value: strconv.Itoa(DefTiDBTableCacheLease), Type: TypeUnsigned, MinValue: 1, MaxValue: 10, SetGlobal: func(s *SessionVars, sVal string) error { + {Scope: ScopeGlobal, Name: TiDBTableCacheLease, Value: strconv.Itoa(DefTiDBTableCacheLease), Type: TypeUnsigned, MinValue: 1, MaxValue: 10, SetGlobal: func(_ context.Context, s *SessionVars, sVal string) error { var val int64 val, err := strconv.ParseInt(sVal, 10, 64) if err != nil { @@ -679,7 +680,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal, Name: TiDBAutoAnalyzePartitionBatchSize, Value: strconv.Itoa(DefTiDBAutoAnalyzePartitionBatchSize), Type: TypeUnsigned, MinValue: 1, MaxValue: 1024, - SetGlobal: func(vars *SessionVars, s string) error { + SetGlobal: func(_ context.Context, vars *SessionVars, s string) error { var val int64 val, err := strconv.ParseInt(s, 10, 64) if err != nil { @@ -693,9 +694,9 @@ var defaultSysVars = []*SysVar{ // TopSQL enable only be controlled by TopSQL pub/sub sinker. // This global variable only uses to update the global config which store in PD(ETCD). {Scope: ScopeGlobal, Name: TiDBEnableTopSQL, Value: BoolToOnOff(topsqlstate.DefTiDBTopSQLEnable), Type: TypeBool, AllowEmpty: true, GlobalConfigName: GlobalConfigEnableTopSQL}, - {Scope: ScopeGlobal, Name: TiDBTopSQLMaxTimeSeriesCount, Value: strconv.Itoa(topsqlstate.DefTiDBTopSQLMaxTimeSeriesCount), Type: TypeInt, MinValue: 1, MaxValue: 5000, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBTopSQLMaxTimeSeriesCount, Value: strconv.Itoa(topsqlstate.DefTiDBTopSQLMaxTimeSeriesCount), Type: TypeInt, MinValue: 1, MaxValue: 5000, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(topsqlstate.GlobalState.MaxStatementCount.Load(), 10), nil - }, SetGlobal: func(vars *SessionVars, s string) error { + }, SetGlobal: func(_ context.Context, vars *SessionVars, s string) error { val, err := strconv.ParseInt(s, 10, 64) if err != nil { return err @@ -703,9 +704,9 @@ var defaultSysVars = []*SysVar{ topsqlstate.GlobalState.MaxStatementCount.Store(val) return nil }}, - {Scope: ScopeGlobal, Name: TiDBTopSQLMaxMetaCount, Value: strconv.Itoa(topsqlstate.DefTiDBTopSQLMaxMetaCount), Type: TypeInt, MinValue: 1, MaxValue: 10000, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBTopSQLMaxMetaCount, Value: strconv.Itoa(topsqlstate.DefTiDBTopSQLMaxMetaCount), Type: TypeInt, MinValue: 1, MaxValue: 10000, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(topsqlstate.GlobalState.MaxCollect.Load(), 10), nil - }, SetGlobal: func(vars *SessionVars, s string) error { + }, SetGlobal: func(_ context.Context, vars *SessionVars, s string) error { val, err := strconv.ParseInt(s, 10, 64) if err != nil { return err @@ -716,25 +717,25 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal, Name: SkipNameResolve, Value: Off, Type: TypeBool}, {Scope: ScopeGlobal, Name: DefaultAuthPlugin, Value: mysql.AuthNativePassword, Type: TypeEnum, PossibleValues: []string{mysql.AuthNativePassword, mysql.AuthCachingSha2Password, mysql.AuthTiDBSM3Password}}, {Scope: ScopeGlobal, Name: TiDBPersistAnalyzeOptions, Value: BoolToOnOff(DefTiDBPersistAnalyzeOptions), Type: TypeBool, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(PersistAnalyzeOptions.Load()), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { PersistAnalyzeOptions.Store(TiDBOptOn(val)) return nil }, }, {Scope: ScopeGlobal, Name: TiDBEnableAutoAnalyze, Value: BoolToOnOff(DefTiDBEnableAutoAnalyze), Type: TypeBool, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(RunAutoAnalyze.Load()), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { RunAutoAnalyze.Store(TiDBOptOn(val)) return nil }, }, {Scope: ScopeGlobal, Name: TiDBServerMemoryLimit, Value: strconv.FormatUint(DefTiDBServerMemoryLimit, 10), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxUint64, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return memory.ServerMemoryLimit.String(), nil }, Validation: func(s *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { @@ -748,7 +749,7 @@ var defaultSysVars = []*SysVar{ } return strconv.FormatUint(intVal, 10), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { intVal, err := strconv.ParseUint(val, 10, 64) if err != nil { return err @@ -759,7 +760,7 @@ var defaultSysVars = []*SysVar{ }, }, {Scope: ScopeGlobal, Name: TiDBServerMemoryLimitSessMinSize, Value: strconv.FormatUint(DefTiDBServerMemoryLimitSessMinSize, 10), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxUint64, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return memory.ServerMemoryLimitSessMinSize.String(), nil }, Validation: func(s *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { @@ -773,7 +774,7 @@ var defaultSysVars = []*SysVar{ } return strconv.FormatUint(intVal, 10), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { intVal, err := strconv.ParseUint(val, 10, 64) if err != nil { return err @@ -783,7 +784,7 @@ var defaultSysVars = []*SysVar{ }, }, {Scope: ScopeGlobal, Name: TiDBServerMemoryLimitGCTrigger, Value: strconv.FormatFloat(DefTiDBServerMemoryLimitGCTrigger, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatFloat(gctuner.GlobalMemoryLimitTuner.GetPercentage(), 'f', -1, 64), nil }, Validation: func(s *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { @@ -797,7 +798,7 @@ var defaultSysVars = []*SysVar{ } return strconv.FormatFloat(floatValue, 'f', -1, 64), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { floatValue, err := strconv.ParseFloat(val, 64) if err != nil { return err @@ -807,9 +808,9 @@ var defaultSysVars = []*SysVar{ return nil }, }, - {Scope: ScopeGlobal, Name: TiDBEnableColumnTracking, Value: BoolToOnOff(DefTiDBEnableColumnTracking), Type: TypeBool, GetGlobal: func(s *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBEnableColumnTracking, Value: BoolToOnOff(DefTiDBEnableColumnTracking), Type: TypeBool, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableColumnTracking.Load()), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { v := TiDBOptOn(val) // If this is a user initiated statement, // we log that column tracking is disabled. @@ -824,10 +825,10 @@ var defaultSysVars = []*SysVar{ return nil }}, {Scope: ScopeGlobal, Name: RequireSecureTransport, Value: BoolToOnOff(DefRequireSecureTransport), Type: TypeBool, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(tls.RequireSecureTransport.Load()), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { tls.RequireSecureTransport.Store(TiDBOptOn(val)) return nil }, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { @@ -842,25 +843,25 @@ var defaultSysVars = []*SysVar{ }, }, {Scope: ScopeGlobal, Name: TiDBStatsLoadPseudoTimeout, Value: BoolToOnOff(DefTiDBStatsLoadPseudoTimeout), Type: TypeBool, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(StatsLoadPseudoTimeout.Load()), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { StatsLoadPseudoTimeout.Store(TiDBOptOn(val)) return nil }, }, - {Scope: ScopeGlobal, Name: TiDBEnableBatchDML, Value: BoolToOnOff(DefTiDBEnableBatchDML), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableBatchDML, Value: BoolToOnOff(DefTiDBEnableBatchDML), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableBatchDML.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableBatchDML.Load()), nil }}, {Scope: ScopeGlobal, Name: TiDBStatsCacheMemQuota, Value: strconv.Itoa(DefTiDBStatsCacheMemQuota), MinValue: 0, MaxValue: MaxTiDBStatsCacheMemQuota, Type: TypeInt, - GetGlobal: func(vars *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, vars *SessionVars) (string, error) { return strconv.FormatInt(StatsCacheMemQuota.Load(), 10), nil - }, SetGlobal: func(vars *SessionVars, s string) error { + }, SetGlobal: func(_ context.Context, vars *SessionVars, s string) error { v := TidbOptInt64(s, DefTiDBStatsCacheMemQuota) oldv := StatsCacheMemQuota.Load() if v != oldv { @@ -870,25 +871,25 @@ var defaultSysVars = []*SysVar{ return nil }, }, - {Scope: ScopeGlobal, Name: TiDBQueryLogMaxLen, Value: strconv.Itoa(DefTiDBQueryLogMaxLen), Type: TypeInt, MinValue: 0, MaxValue: 1073741824, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBQueryLogMaxLen, Value: strconv.Itoa(DefTiDBQueryLogMaxLen), Type: TypeInt, MinValue: 0, MaxValue: 1073741824, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { QueryLogMaxLen.Store(int32(TidbOptInt64(val, DefTiDBQueryLogMaxLen))) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return fmt.Sprint(QueryLogMaxLen.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBCommitterConcurrency, Value: strconv.Itoa(DefTiDBCommitterConcurrency), Type: TypeInt, MinValue: 1, MaxValue: 10000, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBCommitterConcurrency, Value: strconv.Itoa(DefTiDBCommitterConcurrency), Type: TypeInt, MinValue: 1, MaxValue: 10000, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { tikvutil.CommitterConcurrency.Store(int32(TidbOptInt64(val, DefTiDBCommitterConcurrency))) cfg := config.GetGlobalConfig().GetTiKVConfig() tikvcfg.StoreGlobalConfig(cfg) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return fmt.Sprint(tikvutil.CommitterConcurrency.Load()), nil }}, {Scope: ScopeGlobal, Name: TiDBMemQuotaAnalyze, Value: strconv.Itoa(DefTiDBMemQuotaAnalyze), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(GetMemQuotaAnalyze(), 10), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { SetMemQuotaAnalyze(TidbOptInt64(val, DefTiDBMemQuotaAnalyze)) return nil }, @@ -904,13 +905,13 @@ var defaultSysVars = []*SysVar{ } return err }}, - {Scope: ScopeGlobal, Name: TiDBPrepPlanCacheMemoryGuardRatio, Value: strconv.FormatFloat(DefTiDBPrepPlanCacheMemoryGuardRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBPrepPlanCacheMemoryGuardRatio, Value: strconv.FormatFloat(DefTiDBPrepPlanCacheMemoryGuardRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { f, err := strconv.ParseFloat(val, 64) if err == nil { PreparedPlanCacheMemoryGuardRatio.Store(f) } return err - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatFloat(PreparedPlanCacheMemoryGuardRatio.Load(), 'f', -1, 64), nil }}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableGeneralPlanCache, Value: BoolToOnOff(DefTiDBEnableGeneralPlanCache), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { @@ -925,18 +926,18 @@ var defaultSysVars = []*SysVar{ return err }}, {Scope: ScopeGlobal, Name: TiDBMemOOMAction, Value: DefTiDBMemOOMAction, PossibleValues: []string{"CANCEL", "LOG"}, Type: TypeEnum, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return OOMAction.Load(), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { OOMAction.Store(val) return nil }}, {Scope: ScopeGlobal, Name: TiDBMaxAutoAnalyzeTime, Value: strconv.Itoa(DefTiDBMaxAutoAnalyzeTime), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(MaxAutoAnalyzeTime.Load(), 10), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { num, err := strconv.ParseInt(val, 10, 64) if err == nil { MaxAutoAnalyzeTime.Store(num) @@ -944,7 +945,7 @@ var defaultSysVars = []*SysVar{ return err }, }, - {Scope: ScopeGlobal, Name: TiDBEnableConcurrentDDL, Value: BoolToOnOff(DefTiDBEnableConcurrentDDL), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableConcurrentDDL, Value: BoolToOnOff(DefTiDBEnableConcurrentDDL), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { if EnableConcurrentDDL.Load() != TiDBOptOn(val) { err := SwitchConcurrentDDL(TiDBOptOn(val)) if err != nil { @@ -953,10 +954,10 @@ var defaultSysVars = []*SysVar{ EnableConcurrentDDL.Store(TiDBOptOn(val)) } return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableConcurrentDDL.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableMDL, Value: BoolToOnOff(DefTiDBEnableMDL), Type: TypeBool, SetGlobal: func(vars *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableMDL, Value: BoolToOnOff(DefTiDBEnableMDL), Type: TypeBool, SetGlobal: func(_ context.Context, vars *SessionVars, val string) error { if EnableMDL.Load() != TiDBOptOn(val) { err := SwitchMDL(TiDBOptOn(val)) if err != nil { @@ -964,50 +965,50 @@ var defaultSysVars = []*SysVar{ } } return nil - }, GetGlobal: func(vars *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, vars *SessionVars) (string, error) { return BoolToOnOff(EnableMDL.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableNoopVariables, Value: BoolToOnOff(DefTiDBEnableNoopVariables), Type: TypeEnum, PossibleValues: []string{Off, On}, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableNoopVariables, Value: BoolToOnOff(DefTiDBEnableNoopVariables), Type: TypeEnum, PossibleValues: []string{Off, On}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableNoopVariables.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableNoopVariables.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBAuthSigningCert, Value: "", Type: TypeStr, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBAuthSigningCert, Value: "", Type: TypeStr, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { sessionstates.SetCertPath(val) return nil }}, - {Scope: ScopeGlobal, Name: TiDBAuthSigningKey, Value: "", Type: TypeStr, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBAuthSigningKey, Value: "", Type: TypeStr, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { sessionstates.SetKeyPath(val) return nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableGCAwareMemoryTrack, Value: BoolToOnOff(DefEnableTiDBGCAwareMemoryTrack), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableGCAwareMemoryTrack, Value: BoolToOnOff(DefEnableTiDBGCAwareMemoryTrack), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { memory.EnableGCAwareMemoryTrack.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(memory.EnableGCAwareMemoryTrack.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBEnableTmpStorageOnOOM, Value: BoolToOnOff(DefTiDBEnableTmpStorageOnOOM), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableTmpStorageOnOOM, Value: BoolToOnOff(DefTiDBEnableTmpStorageOnOOM), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableTmpStorageOnOOM.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableTmpStorageOnOOM.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(DefMemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(DefMemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { MemoryUsageAlarmRatio.Store(tidbOptFloat64(val, DefMemoryUsageAlarmRatio)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return fmt.Sprintf("%g", MemoryUsageAlarmRatio.Load()), nil }}, - {Scope: ScopeGlobal, Name: TiDBMemoryUsageAlarmKeepRecordNum, Value: strconv.Itoa(DefMemoryUsageAlarmKeepRecordNum), Type: TypeInt, MinValue: 1, MaxValue: 10000, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBMemoryUsageAlarmKeepRecordNum, Value: strconv.Itoa(DefMemoryUsageAlarmKeepRecordNum), Type: TypeInt, MinValue: 1, MaxValue: 10000, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { MemoryUsageAlarmKeepRecordNum.Store(TidbOptInt64(val, DefMemoryUsageAlarmKeepRecordNum)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return fmt.Sprintf("%d", MemoryUsageAlarmKeepRecordNum.Load()), nil }}, /* The system variables below have GLOBAL and SESSION scope */ - {Scope: ScopeGlobal | ScopeSession, Name: TiDBRowFormatVersion, Value: strconv.Itoa(DefTiDBRowFormatV1), Type: TypeUnsigned, MinValue: 1, MaxValue: 2, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal | ScopeSession, Name: TiDBRowFormatVersion, Value: strconv.Itoa(DefTiDBRowFormatV1), Type: TypeUnsigned, MinValue: 1, MaxValue: 2, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { SetDDLReorgRowFormat(TidbOptInt64(val, DefTiDBRowFormatV2)) return nil }, SetSession: func(s *SessionVars, val string) error { @@ -1085,10 +1086,10 @@ var defaultSysVars = []*SysVar{ } return normalizedValue, ErrWrongValueForVar.GenWithStackByArgs(ForeignKeyChecks, originalValue) }}, - {Scope: ScopeGlobal, Name: TiDBEnableForeignKey, Value: BoolToOnOff(false), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBEnableForeignKey, Value: BoolToOnOff(false), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableForeignKey.Store(TiDBOptOn(val)) return nil - }, GetGlobal: func(s *SessionVars) (string, error) { + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return BoolToOnOff(EnableForeignKey.Load()), nil }}, {Scope: ScopeGlobal | ScopeSession, Name: CollationDatabase, Value: mysql.DefaultCollationName, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { @@ -1647,7 +1648,7 @@ var defaultSysVars = []*SysVar{ } s.PartitionPruneMode.Store(newMode) return nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { newMode := strings.ToLower(strings.TrimSpace(val)) if PartitionPruneMode(newMode) == Dynamic { s.StmtCtx.AppendWarning(errors.New("Please analyze all partition tables again for consistency between partition and global stats")) @@ -1740,7 +1741,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnablePaging, Value: BoolToOnOff(DefTiDBEnablePaging), Type: TypeBool, Hidden: true, SetSession: func(s *SessionVars, val string) error { s.EnablePaging = TiDBOptOn(val) return nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { s.EnablePaging = TiDBOptOn(val) return nil }}, @@ -1753,10 +1754,10 @@ var defaultSysVars = []*SysVar{ s.StatsLoadSyncWait = TidbOptInt64(val, DefTiDBStatsLoadSyncWait) return nil }, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return strconv.FormatInt(StatsLoadSyncWait.Load(), 10), nil }, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { StatsLoadSyncWait.Store(TidbOptInt64(val, DefTiDBStatsLoadSyncWait)) return nil }, @@ -1846,7 +1847,7 @@ var defaultSysVars = []*SysVar{ return nil }}, {Scope: ScopeGlobal, Name: TiDBSimplifiedMetrics, Value: BoolToOnOff(DefTiDBSimplifiedMetrics), Type: TypeBool, - SetGlobal: func(vars *SessionVars, s string) error { + SetGlobal: func(_ context.Context, vars *SessionVars, s string) error { metrics.ToggleSimplifiedMode(TiDBOptOn(s)) return nil }}, @@ -1874,7 +1875,7 @@ var defaultSysVars = []*SysVar{ s.EnableAnalyzeSnapshot = TiDBOptOn(val) return nil }}, - {Scope: ScopeGlobal, Name: TiDBGenerateBinaryPlan, Value: BoolToOnOff(DefTiDBGenerateBinaryPlan), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal, Name: TiDBGenerateBinaryPlan, Value: BoolToOnOff(DefTiDBGenerateBinaryPlan), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { GenerateBinaryPlan.Store(TiDBOptOn(val)) return nil }}, @@ -1883,16 +1884,16 @@ var defaultSysVars = []*SysVar{ s.DefaultStrMatchSelectivity = tidbOptFloat64(val, DefTiDBDefaultStrMatchSelectivity) return nil }}, - {Scope: ScopeGlobal, Name: TiDBDDLEnableFastReorg, Value: BoolToOnOff(DefTiDBEnableFastReorg), Type: TypeBool, GetGlobal: func(sv *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBDDLEnableFastReorg, Value: BoolToOnOff(DefTiDBEnableFastReorg), Type: TypeBool, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return BoolToOnOff(EnableFastReorg.Load()), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableFastReorg.Store(TiDBOptOn(val)) return nil }}, // This system var is set disk quota for lightning sort dir, from 100 GB to 1PB. - {Scope: ScopeGlobal, Name: TiDBDDLDiskQuota, Value: strconv.Itoa(DefTiDBDDLDiskQuota), Type: TypeInt, MinValue: DefTiDBDDLDiskQuota, MaxValue: 1024 * 1024 * DefTiDBDDLDiskQuota / 100, GetGlobal: func(sv *SessionVars) (string, error) { + {Scope: ScopeGlobal, Name: TiDBDDLDiskQuota, Value: strconv.Itoa(DefTiDBDDLDiskQuota), Type: TypeInt, MinValue: DefTiDBDDLDiskQuota, MaxValue: 1024 * 1024 * DefTiDBDDLDiskQuota / 100, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) { return strconv.FormatUint(DDLDiskQuota.Load(), 10), nil - }, SetGlobal: func(s *SessionVars, val string) error { + }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { DDLDiskQuota.Store(TidbOptUint64(val, DefTiDBDDLDiskQuota)) return nil }}, diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index a1b996d7468a8..ca8f3219ef974 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -15,6 +15,7 @@ package variable import ( + "context" "encoding/json" "fmt" "math" @@ -160,7 +161,7 @@ func TestTxnIsolation(t *testing.T) { 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()) // Enable global skip isolation check doesn't affect current session - require.Nil(t, GetSysVar(TiDBSkipIsolationLevelCheck).SetGlobalFromHook(vars, "ON", true)) + require.Nil(t, GetSysVar(TiDBSkipIsolationLevelCheck).SetGlobalFromHook(context.Background(), 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()) @@ -232,10 +233,10 @@ func TestReadOnlyNoop(t *testing.T) { require.Equal(t, "[variable:1235]function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions", err.Error()) } require.Equal(t, "OFF", val) - require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(TiDBEnableNoopFuncs, "ON")) + require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(context.Background(), TiDBEnableNoopFuncs, "ON")) _, err = sv.Validate(vars, "on", ScopeGlobal) require.NoError(t, err) - require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(TiDBEnableNoopFuncs, "OFF")) + require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(context.Background(), TiDBEnableNoopFuncs, "OFF")) } } @@ -255,40 +256,40 @@ func TestSkipInit(t *testing.T) { func TestSessionGetterFuncs(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(TiDBCurrentTS) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBCurrentTS) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%d", vars.TxnCtx.StartTS), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBLastTxnInfo) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBLastTxnInfo) require.NoError(t, err) require.Equal(t, vars.LastTxnInfo, val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBLastQueryInfo) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBLastQueryInfo) require.NoError(t, err) info, err := json.Marshal(vars.LastQueryInfo) require.NoError(t, err) require.Equal(t, string(info), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBFoundInPlanCache) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBFoundInPlanCache) require.NoError(t, err) require.Equal(t, BoolToOnOff(vars.PrevFoundInPlanCache), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBFoundInBinding) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBFoundInBinding) require.NoError(t, err) require.Equal(t, BoolToOnOff(vars.PrevFoundInBinding), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBTxnScope) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBTxnScope) require.NoError(t, err) require.Equal(t, vars.TxnScope.GetVarValue(), val) } func TestInstanceScopedVars(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(TiDBGeneralLog) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBGeneralLog) require.NoError(t, err) require.Equal(t, BoolToOnOff(ProcessGeneralLog.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBPProfSQLCPU) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBPProfSQLCPU) require.NoError(t, err) expected := "0" if EnablePProfSQLCPU.Load() { @@ -296,66 +297,66 @@ func TestInstanceScopedVars(t *testing.T) { } require.Equal(t, expected, val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBExpensiveQueryTimeThreshold) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBExpensiveQueryTimeThreshold) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%d", atomic.LoadUint64(&ExpensiveQueryTimeThreshold)), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBMemoryUsageAlarmRatio) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBMemoryUsageAlarmRatio) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%g", MemoryUsageAlarmRatio.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBMemoryUsageAlarmKeepRecordNum) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBMemoryUsageAlarmKeepRecordNum) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%d", MemoryUsageAlarmKeepRecordNum.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBForcePriority) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBForcePriority) require.NoError(t, err) require.Equal(t, mysql.Priority2Str[mysql.PriorityEnum(atomic.LoadInt32(&ForcePriority))], val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBDDLSlowOprThreshold) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBDDLSlowOprThreshold) require.NoError(t, err) require.Equal(t, strconv.FormatUint(uint64(atomic.LoadUint32(&DDLSlowOprThreshold)), 10), val) - val, err = vars.GetSessionOrGlobalSystemVar(PluginDir) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), PluginDir) require.NoError(t, err) require.Equal(t, config.GetGlobalConfig().Instance.PluginDir, val) - val, err = vars.GetSessionOrGlobalSystemVar(PluginLoad) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), PluginLoad) require.NoError(t, err) require.Equal(t, config.GetGlobalConfig().Instance.PluginLoad, val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBSlowLogThreshold) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBSlowLogThreshold) require.NoError(t, err) require.Equal(t, strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Instance.SlowThreshold), 10), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBRecordPlanInSlowLog) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBRecordPlanInSlowLog) require.NoError(t, err) enabled := atomic.LoadUint32(&config.GetGlobalConfig().Instance.RecordPlanInSlowLog) == 1 require.Equal(t, BoolToOnOff(enabled), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBEnableSlowLog) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBEnableSlowLog) require.NoError(t, err) require.Equal(t, BoolToOnOff(config.GetGlobalConfig().Instance.EnableSlowLog.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBCheckMb4ValueInUTF8) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBCheckMb4ValueInUTF8) require.NoError(t, err) require.Equal(t, BoolToOnOff(config.GetGlobalConfig().Instance.CheckMb4ValueInUTF8.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBEnableCollectExecutionInfo) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBEnableCollectExecutionInfo) require.NoError(t, err) require.Equal(t, BoolToOnOff(config.GetGlobalConfig().Instance.EnableCollectExecutionInfo.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBConfig) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBConfig) require.NoError(t, err) expected, err = config.GetJSONConfig() require.NoError(t, err) require.Equal(t, expected, val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBLogFileMaxDays) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBLogFileMaxDays) require.NoError(t, err) require.Equal(t, fmt.Sprint(GlobalLogMaxDays.Load()), val) - val, err = vars.GetSessionOrGlobalSystemVar(TiDBRCReadCheckTS) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBRCReadCheckTS) require.NoError(t, err) require.Equal(t, BoolToOnOff(EnableRCReadCheckTS.Load()), val) } @@ -406,29 +407,29 @@ func TestSQLAutoIsNull(t *testing.T) { func TestLastInsertID(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(LastInsertID) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), LastInsertID) require.NoError(t, err) require.Equal(t, val, "0") vars.StmtCtx.PrevLastInsertID = 21 - val, err = vars.GetSessionOrGlobalSystemVar(LastInsertID) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), LastInsertID) require.NoError(t, err) require.Equal(t, val, "21") } func TestTimestamp(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(Timestamp) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), Timestamp) require.NoError(t, err) require.NotEqual(t, "", val) vars.systems[Timestamp] = "10" - val, err = vars.GetSessionOrGlobalSystemVar(Timestamp) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), Timestamp) require.NoError(t, err) require.Equal(t, "10", val) vars.systems[Timestamp] = "0" // set to default - val, err = vars.GetSessionOrGlobalSystemVar(Timestamp) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), Timestamp) require.NoError(t, err) require.NotEqual(t, "", val) require.NotEqual(t, "10", val) @@ -454,12 +455,12 @@ func TestTimestamp(t *testing.T) { func TestIdentity(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(Identity) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), Identity) require.NoError(t, err) require.Equal(t, val, "0") vars.StmtCtx.PrevLastInsertID = 21 - val, err = vars.GetSessionOrGlobalSystemVar(Identity) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), Identity) require.NoError(t, err) require.Equal(t, val, "21") } @@ -480,7 +481,7 @@ func TestLcMessages(t *testing.T) { require.NoError(t, err) err = sv.SetSessionFromHook(vars, "zh_CN") require.NoError(t, err) - val, err := vars.GetSessionOrGlobalSystemVar("lc_messages") + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), "lc_messages") require.NoError(t, err) require.Equal(t, val, "zh_CN") } @@ -513,10 +514,10 @@ func TestDDLWorkers(t *testing.T) { func TestDefaultCharsetAndCollation(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(CharacterSetConnection) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), CharacterSetConnection) require.NoError(t, err) require.Equal(t, val, mysql.DefaultCharset) - val, err = vars.GetSessionOrGlobalSystemVar(CollationConnection) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), CollationConnection) require.NoError(t, err) require.Equal(t, val, mysql.DefaultCollationName) } @@ -524,7 +525,7 @@ func TestDefaultCharsetAndCollation(t *testing.T) { func TestIndexMergeSwitcher(t *testing.T) { vars := NewSessionVars(nil) vars.GlobalVarsAccessor = NewMockGlobalAccessor4Tests() - val, err := vars.GetSessionOrGlobalSystemVar(TiDBEnableIndexMerge) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBEnableIndexMerge) require.NoError(t, err) require.Equal(t, DefTiDBEnableIndexMerge, true) require.Equal(t, BoolToOnOff(DefTiDBEnableIndexMerge), val) @@ -662,10 +663,10 @@ func TestTiDBDDLFlashbackConcurrency(t *testing.T) { func TestDefaultMemoryDebugModeValue(t *testing.T) { vars := NewSessionVars(nil) - val, err := vars.GetSessionOrGlobalSystemVar(TiDBMemoryDebugModeMinHeapInUse) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBMemoryDebugModeMinHeapInUse) require.NoError(t, err) require.Equal(t, val, "0") - val, err = vars.GetSessionOrGlobalSystemVar(TiDBMemoryDebugModeAlarmRatio) + val, err = vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBMemoryDebugModeAlarmRatio) require.NoError(t, err) require.Equal(t, val, "0") } @@ -675,7 +676,7 @@ func TestDefaultPartitionPruneMode(t *testing.T) { mock := NewMockGlobalAccessor4Tests() mock.SessionVars = vars vars.GlobalVarsAccessor = mock - val, err := vars.GetSessionOrGlobalSystemVar(TiDBPartitionPruneMode) + val, err := vars.GetSessionOrGlobalSystemVar(context.Background(), TiDBPartitionPruneMode) require.NoError(t, err) require.Equal(t, "dynamic", val) require.Equal(t, "dynamic", DefTiDBPartitionPruneMode) @@ -692,14 +693,14 @@ func TestSetTIDBFastDDL(t *testing.T) { require.Equal(t, fastDDL.Value, Off) // Set to On - err := mock.SetGlobalSysVar(TiDBDDLEnableFastReorg, On) + err := mock.SetGlobalSysVar(context.Background(), TiDBDDLEnableFastReorg, On) require.NoError(t, err) val, err1 := mock.GetGlobalSysVar(TiDBDDLEnableFastReorg) require.NoError(t, err1) require.Equal(t, On, val) // Set to off - err = mock.SetGlobalSysVar(TiDBDDLEnableFastReorg, Off) + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLEnableFastReorg, Off) require.NoError(t, err) val, err1 = mock.GetGlobalSysVar(TiDBDDLEnableFastReorg) require.NoError(t, err1) @@ -722,35 +723,35 @@ func TestSetTIDBDiskQuota(t *testing.T) { require.Equal(t, diskQuota.Value, strconv.FormatInt(100*gb, 10)) // MinValue is 100 GB, set to 50 Gb is not allowed - err = mock.SetGlobalSysVar(TiDBDDLDiskQuota, strconv.FormatInt(50*gb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLDiskQuota, strconv.FormatInt(50*gb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBDDLDiskQuota) require.NoError(t, err) require.Equal(t, strconv.FormatInt(100*gb, 10), val) // Set to 100 GB - err = mock.SetGlobalSysVar(TiDBDDLDiskQuota, strconv.FormatInt(100*gb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLDiskQuota, strconv.FormatInt(100*gb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBDDLDiskQuota) require.NoError(t, err) require.Equal(t, strconv.FormatInt(100*gb, 10), val) // Set to 200 GB - err = mock.SetGlobalSysVar(TiDBDDLDiskQuota, strconv.FormatInt(200*gb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLDiskQuota, strconv.FormatInt(200*gb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBDDLDiskQuota) require.NoError(t, err) require.Equal(t, strconv.FormatInt(200*gb, 10), val) // Set to 1 Pb - err = mock.SetGlobalSysVar(TiDBDDLDiskQuota, strconv.FormatInt(pb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLDiskQuota, strconv.FormatInt(pb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBDDLDiskQuota) require.NoError(t, err) require.Equal(t, strconv.FormatInt(pb, 10), val) // MaxValue is 1 PB, set to 2 Pb is not allowed, it will set back to 1 PB max allowed value. - err = mock.SetGlobalSysVar(TiDBDDLDiskQuota, strconv.FormatInt(2*pb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLDiskQuota, strconv.FormatInt(2*pb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBDDLDiskQuota) require.NoError(t, err) @@ -773,28 +774,28 @@ func TestTiDBServerMemoryLimit(t *testing.T) { require.Equal(t, serverMemoryLimit.Value, strconv.FormatUint(DefTiDBServerMemoryLimit, 10)) // MinValue is 512 MB - err = mock.SetGlobalSysVar(TiDBServerMemoryLimit, strconv.FormatUint(100*mb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimit, strconv.FormatUint(100*mb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimit) require.NoError(t, err) require.Equal(t, strconv.FormatUint(512*mb, 10), val) // Test Close - err = mock.SetGlobalSysVar(TiDBServerMemoryLimit, strconv.FormatUint(0, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimit, strconv.FormatUint(0, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimit) require.NoError(t, err) require.Equal(t, strconv.FormatUint(0, 10), val) // Test MaxValue - err = mock.SetGlobalSysVar(TiDBServerMemoryLimit, strconv.FormatUint(math.MaxUint64, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimit, strconv.FormatUint(math.MaxUint64, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimit) require.NoError(t, err) require.Equal(t, strconv.FormatUint(math.MaxUint64, 10), val) // Test Normal Value - err = mock.SetGlobalSysVar(TiDBServerMemoryLimit, strconv.FormatUint(1024*mb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimit, strconv.FormatUint(1024*mb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimit) require.NoError(t, err) @@ -806,28 +807,28 @@ func TestTiDBServerMemoryLimit(t *testing.T) { require.Equal(t, serverMemoryLimitSessMinSize.Value, strconv.FormatUint(DefTiDBServerMemoryLimitSessMinSize, 10)) // MinValue is 128 Bytes - err = mock.SetGlobalSysVar(TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(100, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(100, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimitSessMinSize) require.NoError(t, err) require.Equal(t, strconv.FormatUint(128, 10), val) // Test Close - err = mock.SetGlobalSysVar(TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(0, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(0, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimitSessMinSize) require.NoError(t, err) require.Equal(t, strconv.FormatUint(0, 10), val) // Test MaxValue - err = mock.SetGlobalSysVar(TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(math.MaxUint64, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(math.MaxUint64, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimitSessMinSize) require.NoError(t, err) require.Equal(t, strconv.FormatUint(math.MaxUint64, 10), val) // Test Normal Value - err = mock.SetGlobalSysVar(TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(200*mb, 10)) + err = mock.SetGlobalSysVar(context.Background(), TiDBServerMemoryLimitSessMinSize, strconv.FormatUint(200*mb, 10)) require.NoError(t, err) val, err = mock.GetGlobalSysVar(TiDBServerMemoryLimitSessMinSize) require.NoError(t, err) diff --git a/sessionctx/variable/variable.go b/sessionctx/variable/variable.go index deca51f3e9fa3..fbb3aa79126f1 100644 --- a/sessionctx/variable/variable.go +++ b/sessionctx/variable/variable.go @@ -15,6 +15,7 @@ package variable import ( + "context" "strconv" "strings" "sync" @@ -136,7 +137,7 @@ type SysVar struct { // and will be called on all variables in builtinGlobalVariable, regardless of their scope. SetSession func(*SessionVars, string) error // SetGlobal is called after validation - SetGlobal func(*SessionVars, string) error + SetGlobal func(context.Context, *SessionVars, string) error // IsHintUpdatable indicate whether it's updatable via SET_VAR() hint (optional) IsHintUpdatable bool // Deprecated: Hidden previously meant that the variable still responds to SET but doesn't show up in SHOW VARIABLES @@ -149,7 +150,7 @@ type SysVar struct { // It can be used by instance-scoped variables to overwrite the previously expected value. GetSession func(*SessionVars) (string, error) // GetGlobal is a getter function for global scope. - GetGlobal func(*SessionVars) (string, error) + GetGlobal func(context.Context, *SessionVars) (string, error) // GetStateValue gets the value for session states, which is used for migrating sessions. // We need a function to override GetSession sometimes, because GetSession may not return the real value. GetStateValue func(*SessionVars) (string, bool, error) @@ -166,10 +167,10 @@ type SysVar struct { } // GetGlobalFromHook calls the GetSession func if it exists. -func (sv *SysVar) GetGlobalFromHook(s *SessionVars) (string, error) { +func (sv *SysVar) GetGlobalFromHook(ctx context.Context, s *SessionVars) (string, error) { // Call the Getter if there is one defined. if sv.GetGlobal != nil { - val, err := sv.GetGlobal(s) + val, err := sv.GetGlobal(ctx, s) if err != nil { return val, err } @@ -240,9 +241,9 @@ func (sv *SysVar) SetSessionFromHook(s *SessionVars, val string) error { } // SetGlobalFromHook calls the SetGlobal func if it exists. -func (sv *SysVar) SetGlobalFromHook(s *SessionVars, val string, skipAliases bool) error { +func (sv *SysVar) SetGlobalFromHook(ctx context.Context, s *SessionVars, val string, skipAliases bool) error { if sv.SetGlobal != nil { - return sv.SetGlobal(s, val) + return sv.SetGlobal(ctx, s, val) } // Call the SetGlobalSysVarOnly function on all the aliases for this sysVar @@ -252,7 +253,7 @@ func (sv *SysVar) SetGlobalFromHook(s *SessionVars, val string, skipAliases bool if !skipAliases && sv.Aliases != nil { for _, aliasName := range sv.Aliases { - if err := s.GlobalVarsAccessor.SetGlobalSysVarOnly(aliasName, val); err != nil { + if err := s.GlobalVarsAccessor.SetGlobalSysVarOnly(ctx, aliasName, val); err != nil { return err } } @@ -621,9 +622,9 @@ type GlobalVarAccessor interface { // GetGlobalSysVar gets the global system variable value for name. GetGlobalSysVar(name string) (string, error) // SetGlobalSysVar sets the global system variable name to value. - SetGlobalSysVar(name string, value string) error + SetGlobalSysVar(ctx context.Context, name string, value string) error // SetGlobalSysVarOnly sets the global system variable without calling the validation function or updating aliases. - SetGlobalSysVarOnly(name string, value string) error + SetGlobalSysVarOnly(ctx context.Context, name string, value string) error // GetTiDBTableValue gets a value from mysql.tidb for the key 'name' GetTiDBTableValue(name string) (string, error) // SetTiDBTableValue sets a value+comment for the mysql.tidb key 'name' diff --git a/sessionctx/variable/variable_test.go b/sessionctx/variable/variable_test.go index ff7f5f73ecf9e..bcf917413de3d 100644 --- a/sessionctx/variable/variable_test.go +++ b/sessionctx/variable/variable_test.go @@ -15,6 +15,7 @@ package variable import ( + "context" "encoding/json" "fmt" "runtime" @@ -606,10 +607,10 @@ func TestInstanceScope(t *testing.T) { count := len(GetSysVars()) sv := SysVar{Scope: ScopeInstance, Name: "newinstancesysvar", Value: On, Type: TypeBool, - SetGlobal: func(s *SessionVars, val string) error { + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { return fmt.Errorf("set should fail") }, - GetGlobal: func(s *SessionVars) (string, error) { + GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { return "", fmt.Errorf("get should fail") }, } @@ -634,7 +635,7 @@ func TestInstanceScope(t *testing.T) { require.Equal(t, "OFF", normalizedVal) require.NoError(t, err) - err = sysVar.SetGlobalFromHook(vars, "OFF", true) // default is on + err = sysVar.SetGlobalFromHook(context.Background(), vars, "OFF", true) // default is on require.Equal(t, "set should fail", err.Error()) // Test unregistration restores previous count @@ -649,7 +650,7 @@ func TestSetSysVar(t *testing.T) { SetSysVar(SystemTimeZone, "America/New_York") require.Equal(t, "America/New_York", GetSysVar(SystemTimeZone).Value) // Test alternative Get - val, err := GetSysVar(SystemTimeZone).GetGlobalFromHook(vars) + val, err := GetSysVar(SystemTimeZone).GetGlobalFromHook(context.Background(), vars) require.Nil(t, err) require.Equal(t, "America/New_York", val) SetSysVar(SystemTimeZone, originalVal) // restore diff --git a/sessionctx/variable/varsutil_test.go b/sessionctx/variable/varsutil_test.go index 68e55bc33aea8..69c9caf294e5e 100644 --- a/sessionctx/variable/varsutil_test.go +++ b/sessionctx/variable/varsutil_test.go @@ -15,6 +15,7 @@ package variable import ( + "context" "reflect" "strconv" "testing" @@ -108,7 +109,7 @@ func TestVarsutil(t *testing.T) { err := v.SetSystemVar("autocommit", "1") require.NoError(t, err) - val, err := v.GetSessionOrGlobalSystemVar("autocommit") + val, err := v.GetSessionOrGlobalSystemVar(context.Background(), "autocommit") require.NoError(t, err) require.Equal(t, "ON", val) require.NotNil(t, v.SetSystemVar("autocommit", "")) @@ -116,19 +117,19 @@ func TestVarsutil(t *testing.T) { // 0 converts to OFF err = v.SetSystemVar("foreign_key_checks", "0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar("foreign_key_checks") + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), "foreign_key_checks") require.NoError(t, err) require.Equal(t, "OFF", val) err = v.SetSystemVar("foreign_key_checks", "1") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar("foreign_key_checks") + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), "foreign_key_checks") require.NoError(t, err) require.Equal(t, "ON", val) err = v.SetSystemVar("sql_mode", "strict_trans_tables") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar("sql_mode") + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), "sql_mode") require.NoError(t, err) require.Equal(t, "STRICT_TRANS_TABLES", val) require.True(t, v.StrictSQLMode) @@ -225,7 +226,7 @@ func TestVarsutil(t *testing.T) { // Test case for TiDBConfig session variable. err = v.SetSystemVar(TiDBConfig, "abc") require.True(t, terror.ErrorEqual(err, ErrIncorrectScope)) - val, err = v.GetSessionOrGlobalSystemVar(TiDBConfig) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBConfig) require.NoError(t, err) jsonConfig, err := config.GetJSONConfig() require.NoError(t, err) @@ -254,7 +255,7 @@ func TestVarsutil(t *testing.T) { err = v.SetSystemVar(TiDBRetryLimit, "3") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBRetryLimit) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBRetryLimit) require.NoError(t, err) require.Equal(t, "3", val) require.Equal(t, int64(3), v.RetryLimit) @@ -262,7 +263,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, "", v.EnableTablePartition) err = v.SetSystemVar(TiDBEnableTablePartition, "on") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBEnableTablePartition) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBEnableTablePartition) require.NoError(t, err) require.Equal(t, "ON", val) require.Equal(t, "ON", v.EnableTablePartition) @@ -270,7 +271,7 @@ func TestVarsutil(t *testing.T) { require.False(t, v.EnableListTablePartition) err = v.SetSystemVar(TiDBEnableListTablePartition, "on") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBEnableListTablePartition) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBEnableListTablePartition) require.NoError(t, err) require.Equal(t, "ON", val) require.True(t, v.EnableListTablePartition) @@ -278,20 +279,20 @@ func TestVarsutil(t *testing.T) { require.Equal(t, DefTiDBOptJoinReorderThreshold, v.TiDBOptJoinReorderThreshold) err = v.SetSystemVar(TiDBOptJoinReorderThreshold, "5") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptJoinReorderThreshold) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptJoinReorderThreshold) require.NoError(t, err) require.Equal(t, "5", val) require.Equal(t, 5, v.TiDBOptJoinReorderThreshold) err = v.SetSystemVar(TiDBLowResolutionTSO, "1") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBLowResolutionTSO) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBLowResolutionTSO) require.NoError(t, err) require.Equal(t, "ON", val) require.True(t, v.LowResolutionTSO) err = v.SetSystemVar(TiDBLowResolutionTSO, "0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBLowResolutionTSO) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBLowResolutionTSO) require.NoError(t, err) require.Equal(t, "OFF", val) require.False(t, v.LowResolutionTSO) @@ -299,7 +300,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 0.9, v.CorrelationThreshold) err = v.SetSystemVar(TiDBOptCorrelationThreshold, "0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptCorrelationThreshold) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptCorrelationThreshold) require.NoError(t, err) require.Equal(t, "0", val) require.Equal(t, float64(0), v.CorrelationThreshold) @@ -307,7 +308,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 3.0, v.GetCPUFactor()) err = v.SetSystemVar(TiDBOptCPUFactor, "5.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptCPUFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptCPUFactor) require.NoError(t, err) require.Equal(t, "5.0", val) require.Equal(t, 5.0, v.GetCPUFactor()) @@ -315,7 +316,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 3.0, v.GetCopCPUFactor()) err = v.SetSystemVar(TiDBOptCopCPUFactor, "5.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptCopCPUFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptCopCPUFactor) require.NoError(t, err) require.Equal(t, "5.0", val) require.Equal(t, 5.0, v.GetCopCPUFactor()) @@ -323,7 +324,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 24.0, v.CopTiFlashConcurrencyFactor) err = v.SetSystemVar(TiDBOptTiFlashConcurrencyFactor, "5.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptTiFlashConcurrencyFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptTiFlashConcurrencyFactor) require.NoError(t, err) require.Equal(t, "5.0", val) require.Equal(t, 5.0, v.GetCopCPUFactor()) @@ -331,7 +332,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 1.0, v.GetNetworkFactor(nil)) err = v.SetSystemVar(TiDBOptNetworkFactor, "3.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptNetworkFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptNetworkFactor) require.NoError(t, err) require.Equal(t, "3.0", val) require.Equal(t, 3.0, v.GetNetworkFactor(nil)) @@ -339,7 +340,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 1.5, v.GetScanFactor(nil)) err = v.SetSystemVar(TiDBOptScanFactor, "3.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptScanFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptScanFactor) require.NoError(t, err) require.Equal(t, "3.0", val) require.Equal(t, 3.0, v.GetScanFactor(nil)) @@ -347,7 +348,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 3.0, v.GetDescScanFactor(nil)) err = v.SetSystemVar(TiDBOptDescScanFactor, "5.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptDescScanFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptDescScanFactor) require.NoError(t, err) require.Equal(t, "5.0", val) require.Equal(t, 5.0, v.GetDescScanFactor(nil)) @@ -355,7 +356,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 20.0, v.GetSeekFactor(nil)) err = v.SetSystemVar(TiDBOptSeekFactor, "50.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptSeekFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptSeekFactor) require.NoError(t, err) require.Equal(t, "50.0", val) require.Equal(t, 50.0, v.GetSeekFactor(nil)) @@ -363,7 +364,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 0.001, v.GetMemoryFactor()) err = v.SetSystemVar(TiDBOptMemoryFactor, "1.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptMemoryFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptMemoryFactor) require.NoError(t, err) require.Equal(t, "1.0", val) require.Equal(t, 1.0, v.GetMemoryFactor()) @@ -371,7 +372,7 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 1.5, v.GetDiskFactor()) err = v.SetSystemVar(TiDBOptDiskFactor, "1.1") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptDiskFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptDiskFactor) require.NoError(t, err) require.Equal(t, "1.1", val) require.Equal(t, 1.1, v.GetDiskFactor()) @@ -379,33 +380,33 @@ func TestVarsutil(t *testing.T) { require.Equal(t, 3.0, v.GetConcurrencyFactor()) err = v.SetSystemVar(TiDBOptConcurrencyFactor, "5.0") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBOptConcurrencyFactor) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBOptConcurrencyFactor) require.NoError(t, err) require.Equal(t, "5.0", val) require.Equal(t, 5.0, v.GetConcurrencyFactor()) err = v.SetSystemVar(TiDBReplicaRead, "follower") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBReplicaRead) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBReplicaRead) require.NoError(t, err) require.Equal(t, "follower", val) require.Equal(t, kv.ReplicaReadFollower, v.GetReplicaRead()) err = v.SetSystemVar(TiDBReplicaRead, "leader") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBReplicaRead) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBReplicaRead) require.NoError(t, err) require.Equal(t, "leader", val) require.Equal(t, kv.ReplicaReadLeader, v.GetReplicaRead()) err = v.SetSystemVar(TiDBReplicaRead, "leader-and-follower") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBReplicaRead) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBReplicaRead) require.NoError(t, err) require.Equal(t, "leader-and-follower", val) require.Equal(t, kv.ReplicaReadMixed, v.GetReplicaRead()) err = v.SetSystemVar(TiDBRedactLog, "ON") require.NoError(t, err) - val, err = v.GetSessionOrGlobalSystemVar(TiDBRedactLog) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBRedactLog) require.NoError(t, err) require.Equal(t, "ON", val) @@ -435,7 +436,7 @@ func TestVarsutil(t *testing.T) { require.Error(t, err) require.Regexp(t, "'tidb_table_cache_lease' is a GLOBAL variable and should be set with SET GLOBAL", err.Error()) - val, err = v.GetSessionOrGlobalSystemVar(TiDBMinPagingSize) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBMinPagingSize) require.NoError(t, err) require.Equal(t, strconv.Itoa(DefMinPagingSize), val) @@ -443,7 +444,7 @@ func TestVarsutil(t *testing.T) { require.NoError(t, err) require.Equal(t, v.MinPagingSize, 123) - val, err = v.GetSessionOrGlobalSystemVar(TiDBMaxPagingSize) + val, err = v.GetSessionOrGlobalSystemVar(context.Background(), TiDBMaxPagingSize) require.NoError(t, err) require.Equal(t, strconv.Itoa(DefMaxPagingSize), val) diff --git a/telemetry/data_feature_usage.go b/telemetry/data_feature_usage.go index f50b5ab02c2bb..5be16b51bed1b 100644 --- a/telemetry/data_feature_usage.go +++ b/telemetry/data_feature_usage.go @@ -240,29 +240,29 @@ var initialDDLUsageCounter m.DDLUsageCounter // getTxnUsageInfo gets the usage info of transaction related features. It's exported for tests. func getTxnUsageInfo(ctx sessionctx.Context) *TxnUsage { asyncCommitUsed := false - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnableAsyncCommit); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnableAsyncCommit); err == nil { asyncCommitUsed = val == variable.On } onePCUsed := false - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnable1PC); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnable1PC); err == nil { onePCUsed = val == variable.On } curr := metrics.GetTxnCommitCounter() diff := curr.Sub(initialTxnCommitCounter) mutationCheckerUsed := false - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBEnableMutationChecker); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBEnableMutationChecker); err == nil { mutationCheckerUsed = val == variable.On } assertionUsed := "" - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBTxnAssertionLevel); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBTxnAssertionLevel); err == nil { assertionUsed = val } rcCheckTSUsed := false - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBRCReadCheckTS); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBRCReadCheckTS); err == nil { rcCheckTSUsed = val == variable.On } rcWriteCheckTSUsed := false - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBRCWriteCheckTs); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBRCWriteCheckTs); err == nil { rcWriteCheckTSUsed = val == variable.On } currSavepointCount := m.GetSavepointStmtCounter() @@ -346,7 +346,7 @@ func getTablePartitionUsageInfo() *m.TablePartitionUsageCounter { // getAutoCaptureUsageInfo gets the 'Auto Capture' usage func getAutoCaptureUsageInfo(ctx sessionctx.Context) bool { - if val, err := ctx.GetSessionVars().GetGlobalSystemVar(variable.TiDBCapturePlanBaseline); err == nil { + if val, err := ctx.GetSessionVars().GetGlobalSystemVar(context.Background(), variable.TiDBCapturePlanBaseline); err == nil { return val == variable.On } return false diff --git a/util/gcutil/gcutil.go b/util/gcutil/gcutil.go index 0d3ae7da53ee2..9474cace52378 100644 --- a/util/gcutil/gcutil.go +++ b/util/gcutil/gcutil.go @@ -42,12 +42,12 @@ func CheckGCEnable(ctx sessionctx.Context) (enable bool, err error) { // DisableGC will disable GC enable variable. func DisableGC(ctx sessionctx.Context) error { - return ctx.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBGCEnable, variable.Off) + return ctx.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBGCEnable, variable.Off) } // EnableGC will enable GC enable variable. func EnableGC(ctx sessionctx.Context) error { - return ctx.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBGCEnable, variable.On) + return ctx.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(context.Background(), variable.TiDBGCEnable, variable.On) } // ValidateSnapshot checks that the newly set snapshot time is after GC safe point time.