Skip to content

Commit

Permalink
variable: revise TiDBStatsCacheMemQuota settting code (#34762)
Browse files Browse the repository at this point in the history
ref #34052
  • Loading branch information
Yisaer authored May 18, 2022
1 parent d40b5e1 commit 95e359f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
do.SchemaValidator = NewSchemaValidator(ddlLease, do)
do.expensiveQueryHandle = expensivequery.NewExpensiveQueryHandle(do.exit)
do.sysProcesses = SysProcesses{mu: &sync.RWMutex{}, procMap: make(map[uint64]sessionctx.Context)}
variable.SetStatsCacheCapacity = do.SetStatsCacheCapacity
return do
}

Expand Down
7 changes: 0 additions & 7 deletions domain/sysvar_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ func (do *Domain) rebuildSysVarCache(ctx sessionctx.Context) error {
if sv.HasGlobalScope() {
newGlobalCache[sv.Name] = sVal

oldStatsCacheMemQuota := variable.StatsCacheMemQuota.Load()

// Call the SetGlobal func for this sysvar if it exists.
// SET GLOBAL only calls the SetGlobal func on the calling instances.
// This ensures it is run on all tidb servers.
Expand All @@ -151,11 +149,6 @@ func (do *Domain) rebuildSysVarCache(ctx sessionctx.Context) error {
if err != nil {
logutil.BgLogger().Error(fmt.Sprintf("load global variable %s error", sv.Name), zap.Error(err))
}

newStatsCacheMemQuota := variable.StatsCacheMemQuota.Load()
if sv.Name == variable.TiDBStatsCacheMemQuota && oldStatsCacheMemQuota != newStatsCacheMemQuota {
do.SetStatsCacheCapacity(newStatsCacheMemQuota)
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,11 @@ var defaultSysVars = []*SysVar{
return strconv.FormatInt(StatsCacheMemQuota.Load(), 10), nil
}, SetGlobal: func(vars *SessionVars, s string) error {
v := TidbOptInt64(s, DefTiDBStatsCacheMemQuota)
StatsCacheMemQuota.Store(v)
oldv := StatsCacheMemQuota.Load()
if v != oldv {
StatsCacheMemQuota.Store(v)
SetStatsCacheCapacity(v)
}
return nil
},
},
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,6 @@ var (
SetMemQuotaAnalyze func(quota int64) = nil
// GetMemQuotaAnalyze is the func registered by global/subglobal tracker to get memory quota.
GetMemQuotaAnalyze func() int64 = nil
// SetStatsCacheCapacity is the func registered by domain to set statsCache memory quota.
SetStatsCacheCapacity func(c int64) = nil
)

0 comments on commit 95e359f

Please sign in to comment.