Skip to content

Commit

Permalink
varaible: fix the new session can't see the instance-level variable s…
Browse files Browse the repository at this point in the history
…tore-limit (pingcap#26649)
  • Loading branch information
AilinKid authored Aug 2, 2021
1 parent cb65b7a commit 0bcf830
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions domain/sysvar_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/stmtsummary"
storekv "github.com/tikv/client-go/v2/kv"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -201,6 +202,13 @@ func checkEnableServerGlobalVar(name, sVal string) {
variable.TopSQLVariable.ReportIntervalSeconds.Store(val)
case variable.TiDBRestrictedReadOnly:
variable.RestrictedReadOnly.Store(variable.TiDBOptOn(sVal))
case variable.TiDBStoreLimit:
var val int64
val, err = strconv.ParseInt(sVal, 10, 64)
if err != nil {
break
}
storekv.StoreLimit.Store(val)
}
if err != nil {
logutil.BgLogger().Error(fmt.Sprintf("load global variable %s error", name), zap.Error(err))
Expand Down
4 changes: 2 additions & 2 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ func (s *testSerialSuite1) TestSetVar(c *C) {
tk.MustExec("set @@tidb_store_limit = 0")

tk.MustExec("set global tidb_store_limit = 100")
tk.MustQuery("select @@tidb_store_limit;").Check(testkit.Rows("0"))
tk.MustQuery("select @@session.tidb_store_limit;").Check(testkit.Rows("0"))
tk.MustQuery("select @@tidb_store_limit;").Check(testkit.Rows("100"))
tk.MustQuery("select @@session.tidb_store_limit;").Check(testkit.Rows("100"))
tk.MustQuery("select @@global.tidb_store_limit;").Check(testkit.Rows("100"))

tk.MustQuery("select @@session.tidb_metric_query_step;").Check(testkit.Rows("60"))
Expand Down
5 changes: 5 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,11 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeGlobal | ScopeSession, Name: TiDBStoreLimit, Value: strconv.FormatInt(atomic.LoadInt64(&config.GetGlobalConfig().TiKVClient.StoreLimit), 10), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt64, AutoConvertOutOfRange: true, SetSession: func(s *SessionVars, val string) error {
tikvstore.StoreLimit.Store(tidbOptInt64(val, DefTiDBStoreLimit))
return nil
}, GetSession: func(s *SessionVars) (string, error) {
return strconv.FormatInt(tikvstore.StoreLimit.Load(), 10), nil
}, SetGlobal: func(s *SessionVars, val string) error {
tikvstore.StoreLimit.Store(tidbOptInt64(val, DefTiDBStoreLimit))
return nil
}},
{Scope: ScopeSession, Name: TiDBMetricSchemaStep, Value: strconv.Itoa(DefTiDBMetricSchemaStep), Type: TypeUnsigned, skipInit: true, MinValue: 10, MaxValue: 60 * 60 * 60, SetSession: func(s *SessionVars, val string) error {
s.MetricSchemaStep = tidbOptInt64(val, DefTiDBMetricSchemaStep)
Expand Down

0 comments on commit 0bcf830

Please sign in to comment.