Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

util: record more information before OOM #37987

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a9bf1e0
record more information before OOM
mengxin9014 Sep 20, 2022
0d135f5
change variable name
mengxin9014 Sep 20, 2022
4a8330d
modify tests
mengxin9014 Sep 20, 2022
6342b71
modify tests
mengxin9014 Sep 20, 2022
c707455
auto update viriable
mengxin9014 Sep 20, 2022
c997191
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Sep 20, 2022
13d7fe5
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Sep 21, 2022
4da2738
refactor memory usage alarm
mengxin9014 Sep 21, 2022
d750a08
Merge branch 'mx/recordMoreInformationBeforeOOM' of github.com:mengxi…
mengxin9014 Sep 21, 2022
5284722
add tests
mengxin9014 Sep 21, 2022
4895b06
fmt
mengxin9014 Sep 21, 2022
526e1bc
fmt
mengxin9014 Sep 21, 2022
76bf701
add license header
mengxin9014 Sep 21, 2022
de38768
fmt
mengxin9014 Sep 21, 2022
e390229
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
hawkingrei Sep 21, 2022
d0cf8ca
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Sep 22, 2022
e5d46f8
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Sep 26, 2022
5fc5865
Merge branch 'mx/recordMoreInformationBeforeOOM' of github.com:mengxi…
mengxin9014 Sep 26, 2022
64afd47
fmt
mengxin9014 Sep 27, 2022
0f64465
modify according comments
mengxin9014 Sep 28, 2022
012e99e
modify according comments
mengxin9014 Sep 28, 2022
6ebe722
fmt
mengxin9014 Sep 28, 2022
5928f68
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Oct 9, 2022
e98b261
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Oct 9, 2022
22d7f9f
change interval time
mengxin9014 Oct 9, 2022
7d0260a
Merge branch 'mx/recordMoreInformationBeforeOOM' of github.com:mengxi…
mengxin9014 Oct 9, 2022
aaa77a8
modify according comments
mengxin9014 Oct 9, 2022
62427a0
deprecate instance tidb memory use ratio
mengxin9014 Oct 9, 2022
92f9d10
modify according comments
mengxin9014 Oct 9, 2022
a2ebbb3
modify according comments
mengxin9014 Oct 9, 2022
2c09f15
change struct name
mengxin9014 Oct 9, 2022
78e5cfd
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Oct 9, 2022
98fa4f3
add tests
mengxin9014 Oct 9, 2022
2d6d81c
Merge branch 'mx/recordMoreInformationBeforeOOM' of github.com:mengxi…
mengxin9014 Oct 9, 2022
491ab76
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Oct 10, 2022
dc32dc6
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Oct 10, 2022
fdc6d37
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
mengxin9014 Oct 11, 2022
3d34222
fix tests
mengxin9014 Oct 11, 2022
2618c09
Merge branch 'mx/recordMoreInformationBeforeOOM' of github.com:mengxi…
mengxin9014 Oct 11, 2022
3141a1e
Merge branch 'master' into mx/recordMoreInformationBeforeOOM
ti-chi-bot Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ var removedConfig = map[string]struct{}{
"oom-use-tmp-storage": {}, // use tidb_enable_tmp_storage_on_oom
"max-server-connections": {}, // use sysvar max_connections
"run-ddl": {}, // use sysvar tidb_enable_ddl
"instance.tidb_memory_usage_alarm_ratio": {}, // use sysvar tidb_memory_usage_alarm_ratio
}

// isAllRemovedConfigItems returns true if all the items that couldn't validate
Expand Down
8 changes: 0 additions & 8 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,6 @@ tidb_expensive_query_time_threshold = 60
# The value could be "NO_PRIORITY", "LOW_PRIORITY", "HIGH_PRIORITY" or "DELAYED".
tidb_force_priority = "NO_PRIORITY"

# The alarm threshold when memory usage of the tidb-server exceeds. The valid value range is greater than or equal to 0
# and less than or equal to 1. The default value is 0.8.
# If this configuration is set to 0 or 1, it'll disable the alarm.
# Otherwise, related information will be recorded in the directory `tmp-storage-path/record`.
# Note: If the configuration `server-memory-quota` is set and larger than 0, the alarm threshold will be
# `tidb_memory_usage_alarm_ratio * server-memory-quota`; otherwise, it'll be `tidb_memory_usage_alarm_ratio * system memory size`.
tidb_memory_usage_alarm_ratio = 0.8

# check mb4 value in utf8 is used to control whether to check the mb4 characters when the charset is utf8.
tidb_check_mb4_value_in_utf8 = true

Expand Down
5 changes: 3 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ max-procs = 0
server-memory-quota = 0

# The alarm threshold when memory usage of the tidb-server exceeds. The valid value range is greater than or equal to 0
# and less than or equal to 1. The default value is 0.8.
# and less than or equal to 1. The default value is 0.7.
# If this configuration is set to 0 or 1, it'll disable the alarm.
# <snip>
memory-usage-alarm-ratio = 0.8
memory-usage-alarm-ratio = 0.7
Comment on lines 424 to +428
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this block


# StmtCountLimit limits the max count of statement inside a transaction.
stmt-count-limit = 5000
Expand Down Expand Up @@ -767,6 +767,7 @@ grpc-initial-window-size = 10240
grpc-max-send-msg-size = 40960
[instance]
max_connections = 200
tidb_memory_usage_alarm_ratio = 0.7
`)

require.NoError(t, err)
Expand Down
8 changes: 8 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
"github.com/pingcap/tidb/util/engine"
"github.com/pingcap/tidb/util/expensivequery"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/memoryusagealarm"
"github.com/pingcap/tidb/util/servermemorylimit"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/tikv/client-go/v2/txnkv/transaction"
Expand Down Expand Up @@ -105,6 +106,7 @@ type Domain struct {
sysVarCache sysVarCache // replaces GlobalVariableCache
slowQuery *topNSlowQueries
expensiveQueryHandle *expensivequery.Handle
memoryUsageAlarmHandle *memoryusagealarm.Handle
serverMemoryLimitHandle *servermemorylimit.Handle
wg util.WaitGroupWrapper
statsUpdating atomicutil.Int32
Expand Down Expand Up @@ -887,6 +889,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio

do.SchemaValidator = NewSchemaValidator(ddlLease, do)
do.expensiveQueryHandle = expensivequery.NewExpensiveQueryHandle(do.exit)
do.memoryUsageAlarmHandle = memoryusagealarm.NewMemoryUsageAlarmHandle(do.exit)
do.serverMemoryLimitHandle = servermemorylimit.NewServerMemoryLimitHandle(do.exit)
do.sysProcesses = SysProcesses{mu: &sync.RWMutex{}, procMap: make(map[uint64]sessionctx.Context)}
variable.SetStatsCacheCapacity.Store(do.SetStatsCacheCapacity)
Expand Down Expand Up @@ -1825,6 +1828,11 @@ func (do *Domain) ExpensiveQueryHandle() *expensivequery.Handle {
return do.expensiveQueryHandle
}

// MemoryUsageAlarmHandle returns the memory usage alarm handle.
func (do *Domain) MemoryUsageAlarmHandle() *memoryusagealarm.Handle {
return do.memoryUsageAlarmHandle
}

// ServerMemoryLimitHandle returns the expensive query handle.
func (do *Domain) ServerMemoryLimitHandle() *servermemorylimit.Handle {
return do.serverMemoryLimitHandle
Expand Down
11 changes: 11 additions & 0 deletions planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ func GetExplainRowsForPlan(plan Plan) (rows [][]string) {
return explain.Rows
}

// GetExplainAnalyzeRowsForPlan get explain rows for plan.
func GetExplainAnalyzeRowsForPlan(plan *Explain) (rows [][]string) {
mengxin9014 marked this conversation as resolved.
Show resolved Hide resolved
if err := plan.prepareSchema(); err != nil {
return rows
}
if err := plan.RenderResult(); err != nil {
return rows
}
return plan.Rows
}

// prepareSchema prepares explain's result schema.
func (e *Explain) prepareSchema() error {
var fieldNames []string
Expand Down
5 changes: 5 additions & 0 deletions planner/core/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,11 @@ func (p *basePlan) SCtx() sessionctx.Context {
return p.ctx
}

// SetSCtx Context implements Plan Set Context interface.
func (p *basePlan) SetSCtx(ctx sessionctx.Context) {
p.ctx = ctx
}

// buildPlanTrace implements Plan
func (p *basePhysicalPlan) buildPlanTrace() *tracing.PlanTrace {
planTrace := &tracing.PlanTrace{ID: p.ID(), TP: p.self.TP(), ExplainInfo: p.self.ExplainInfo()}
Expand Down
51 changes: 36 additions & 15 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import (
"github.com/pingcap/tidb/table/temptable"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/telemetry"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
Expand Down Expand Up @@ -1489,21 +1490,23 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte, maxExecu
p = explain.TargetPlan
}
pi := util.ProcessInfo{
ID: s.sessionVars.ConnectionID,
Port: s.sessionVars.Port,
DB: s.sessionVars.CurrentDB,
Command: command,
Plan: p,
PlanExplainRows: plannercore.GetExplainRowsForPlan(p),
RuntimeStatsColl: s.sessionVars.StmtCtx.RuntimeStatsColl,
Time: t,
State: s.Status(),
Info: sql,
CurTxnStartTS: curTxnStartTS,
StmtCtx: s.sessionVars.StmtCtx,
StatsInfo: plannercore.GetStatsInfo,
MaxExecutionTime: maxExecutionTime,
RedactSQL: s.sessionVars.EnableRedactLog,
ID: s.sessionVars.ConnectionID,
Port: s.sessionVars.Port,
DB: s.sessionVars.CurrentDB,
Command: command,
Plan: p,
PlanExplainRows: plannercore.GetExplainRowsForPlan(p),
CurrentAnalyzeRows: s.getCurrentAnalyzePlan,
RuntimeStatsColl: s.sessionVars.StmtCtx.RuntimeStatsColl,
Time: t,
State: s.Status(),
Info: sql,
CurTxnStartTS: curTxnStartTS,
StmtCtx: s.sessionVars.StmtCtx,
OOMAlarmVariablesInfo: s.getOomAlarmVariablesInfo(),
StatsInfo: plannercore.GetStatsInfo,
MaxExecutionTime: maxExecutionTime,
RedactSQL: s.sessionVars.EnableRedactLog,
}
oldPi := s.ShowProcess()
if p == nil {
Expand Down Expand Up @@ -1533,6 +1536,24 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte, maxExecu
s.processInfo.Store(&pi)
}

func (s *session) getOomAlarmVariablesInfo() util.OOMAlarmVariablesInfo {
return util.OOMAlarmVariablesInfo{
SessionAnalyzeVersion: s.sessionVars.AnalyzeVersion,
SessionEnabledRateLimitAction: s.sessionVars.EnabledRateLimitAction,
}
}

func (s *session) getCurrentAnalyzePlan(p interface{}, runtimeStatsColl *execdetails.RuntimeStatsColl) [][]string {
explain := &plannercore.Explain{
TargetPlan: p.(plannercore.Plan),
Format: types.ExplainFormatROW,
Analyze: false,
RuntimeStatsColl: runtimeStatsColl,
}
explain.SetSCtx(s)
return plannercore.GetExplainAnalyzeRowsForPlan(explain)
}

func (s *session) SetDiskFullOpt(level kvrpcpb.DiskFullOpt) {
s.diskFullOpt = level
}
Expand Down
13 changes: 9 additions & 4 deletions session/session_test/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2039,13 +2039,18 @@ func TestMemoryUsageAlarmVariable(t *testing.T) {
tk.MustExec("set @@global.tidb_memory_usage_alarm_ratio=1.1")
tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_memory_usage_alarm_ratio value: '1.1'"))
tk.MustQuery("select @@global.tidb_memory_usage_alarm_ratio").Check(testkit.Rows("1"))

tk.MustExec("set @@global.tidb_memory_usage_alarm_ratio=-1")
tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_memory_usage_alarm_ratio value: '-1'"))
tk.MustQuery("select @@global.tidb_memory_usage_alarm_ratio").Check(testkit.Rows("0"))

tk.MustExec("set @@session.tidb_memory_usage_alarm_ratio=0.8")
tk.MustQuery(`show warnings`).Check(testkit.Rows(fmt.Sprintf("Warning %d modifying tidb_memory_usage_alarm_ratio will require SET GLOBAL in a future version of TiDB", errno.ErrInstanceScope)))
require.Error(t, tk.ExecToErr("set @@session.tidb_memory_usage_alarm_ratio=0.8"))

tk.MustExec("set @@global.tidb_memory_usage_alarm_keep_record_num=1")
tk.MustQuery("select @@global.tidb_memory_usage_alarm_keep_record_num").Check(testkit.Rows("1"))
tk.MustExec("set @@global.tidb_memory_usage_alarm_keep_record_num=100")
tk.MustQuery("select @@global.tidb_memory_usage_alarm_keep_record_num").Check(testkit.Rows("100"))
tk.MustExec("set @@global.tidb_memory_usage_alarm_keep_record_num=0")
tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_memory_usage_alarm_keep_record_num value: '0'"))
tk.MustQuery("select @@global.tidb_memory_usage_alarm_keep_record_num").Check(testkit.Rows("1"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for the MAXVALUE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for the MAXVALUE

done.

}

func TestSelectLockInShare(t *testing.T) {
Expand Down
18 changes: 12 additions & 6 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,6 @@ var defaultSysVars = []*SysVar{
}, GetGlobal: func(s *SessionVars) (string, error) {
return strconv.FormatUint(atomic.LoadUint64(&ExpensiveQueryTimeThreshold), 10), nil
}},
{Scope: ScopeInstance, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(config.GetGlobalConfig().Instance.MemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, SetGlobal: func(s *SessionVars, val string) error {
MemoryUsageAlarmRatio.Store(tidbOptFloat64(val, 0.8))
return nil
}, GetGlobal: func(s *SessionVars) (string, error) {
return fmt.Sprintf("%g", MemoryUsageAlarmRatio.Load()), nil
}},
{Scope: ScopeInstance, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error {
oldConfig := config.GetGlobalConfig()
newValue := TiDBOptOn(val)
Expand Down Expand Up @@ -963,6 +957,18 @@ var defaultSysVars = []*SysVar{
}, GetGlobal: func(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 {
MemoryUsageAlarmRatio.Store(tidbOptFloat64(val, DefMemoryUsageAlarmRatio))
return nil
}, GetGlobal: func(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 {
MemoryUsageAlarmKeepRecordNum.Store(TidbOptInt64(val, DefMemoryUsageAlarmKeepRecordNum))
return nil
}, GetGlobal: func(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 {
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ func TestInstanceScopedVars(t *testing.T) {
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%g", MemoryUsageAlarmRatio.Load()), val)

val, err = vars.GetSessionOrGlobalSystemVar(TiDBMemoryUsageAlarmKeepRecordNum)
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%d", MemoryUsageAlarmKeepRecordNum.Load()), val)

val, err = vars.GetSessionOrGlobalSystemVar(TiDBForcePriority)
require.NoError(t, err)
require.Equal(t, mysql.Priority2Str[mysql.PriorityEnum(atomic.LoadInt32(&ForcePriority))], val)
Expand Down
46 changes: 26 additions & 20 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ const (
// TiDBMemoryUsageAlarmRatio indicates the alarm threshold when memory usage of the tidb-server exceeds.
TiDBMemoryUsageAlarmRatio = "tidb_memory_usage_alarm_ratio"

// TiDBMemoryUsageAlarmKeepRecordNum indicates the number of saved alarm files.
TiDBMemoryUsageAlarmKeepRecordNum = "tidb_memory_usage_alarm_keep_record_num"

// TiDBEnableRateLimitAction indicates whether enabled ratelimit action
TiDBEnableRateLimitAction = "tidb_enable_rate_limit_action"

Expand Down Expand Up @@ -1032,6 +1035,8 @@ const (
DefTiDBEnableTmpStorageOnOOM = true
DefTiDBEnableMDL = false
DefTiFlashFastScan = false
DefMemoryUsageAlarmRatio = 0.7
DefMemoryUsageAlarmKeepRecordNum = 5
DefTiDBEnableFastReorg = false
DefTiDBDDLDiskQuota = 100 * 1024 * 1024 * 1024 // 100GB
DefExecutorConcurrency = 5
Expand Down Expand Up @@ -1066,26 +1071,27 @@ var (
ddlReorgRowFormat int64 = DefTiDBRowFormatV2
maxDeltaSchemaCount int64 = DefTiDBMaxDeltaSchemaCount
// DDLSlowOprThreshold is the threshold for ddl slow operations, uint is millisecond.
DDLSlowOprThreshold = config.GetGlobalConfig().Instance.DDLSlowOprThreshold
ForcePriority = int32(DefTiDBForcePriority)
MaxOfMaxAllowedPacket uint64 = 1073741824
ExpensiveQueryTimeThreshold uint64 = DefTiDBExpensiveQueryTimeThreshold
MemoryUsageAlarmRatio = atomic.NewFloat64(config.GetGlobalConfig().Instance.MemoryUsageAlarmRatio)
EnableLocalTxn = atomic.NewBool(DefTiDBEnableLocalTxn)
MaxTSOBatchWaitInterval = atomic.NewFloat64(DefTiDBTSOClientBatchMaxWaitTime)
EnableTSOFollowerProxy = atomic.NewBool(DefTiDBEnableTSOFollowerProxy)
RestrictedReadOnly = atomic.NewBool(DefTiDBRestrictedReadOnly)
VarTiDBSuperReadOnly = atomic.NewBool(DefTiDBSuperReadOnly)
PersistAnalyzeOptions = atomic.NewBool(DefTiDBPersistAnalyzeOptions)
TableCacheLease = atomic.NewInt64(DefTiDBTableCacheLease)
EnableColumnTracking = atomic.NewBool(DefTiDBEnableColumnTracking)
StatsLoadSyncWait = atomic.NewInt64(DefTiDBStatsLoadSyncWait)
StatsLoadPseudoTimeout = atomic.NewBool(DefTiDBStatsLoadPseudoTimeout)
MemQuotaBindingCache = atomic.NewInt64(DefTiDBMemQuotaBindingCache)
GCMaxWaitTime = atomic.NewInt64(DefTiDBGCMaxWaitTime)
StatsCacheMemQuota = atomic.NewInt64(DefTiDBStatsCacheMemQuota)
OOMAction = atomic.NewString(DefTiDBMemOOMAction)
MaxAutoAnalyzeTime = atomic.NewInt64(DefTiDBMaxAutoAnalyzeTime)
DDLSlowOprThreshold = config.GetGlobalConfig().Instance.DDLSlowOprThreshold
ForcePriority = int32(DefTiDBForcePriority)
MaxOfMaxAllowedPacket uint64 = 1073741824
ExpensiveQueryTimeThreshold uint64 = DefTiDBExpensiveQueryTimeThreshold
MemoryUsageAlarmRatio = atomic.NewFloat64(DefMemoryUsageAlarmRatio)
MemoryUsageAlarmKeepRecordNum = atomic.NewInt64(DefMemoryUsageAlarmKeepRecordNum)
EnableLocalTxn = atomic.NewBool(DefTiDBEnableLocalTxn)
MaxTSOBatchWaitInterval = atomic.NewFloat64(DefTiDBTSOClientBatchMaxWaitTime)
EnableTSOFollowerProxy = atomic.NewBool(DefTiDBEnableTSOFollowerProxy)
RestrictedReadOnly = atomic.NewBool(DefTiDBRestrictedReadOnly)
VarTiDBSuperReadOnly = atomic.NewBool(DefTiDBSuperReadOnly)
PersistAnalyzeOptions = atomic.NewBool(DefTiDBPersistAnalyzeOptions)
TableCacheLease = atomic.NewInt64(DefTiDBTableCacheLease)
EnableColumnTracking = atomic.NewBool(DefTiDBEnableColumnTracking)
StatsLoadSyncWait = atomic.NewInt64(DefTiDBStatsLoadSyncWait)
StatsLoadPseudoTimeout = atomic.NewBool(DefTiDBStatsLoadPseudoTimeout)
MemQuotaBindingCache = atomic.NewInt64(DefTiDBMemQuotaBindingCache)
GCMaxWaitTime = atomic.NewInt64(DefTiDBGCMaxWaitTime)
StatsCacheMemQuota = atomic.NewInt64(DefTiDBStatsCacheMemQuota)
OOMAction = atomic.NewString(DefTiDBMemOOMAction)
MaxAutoAnalyzeTime = atomic.NewInt64(DefTiDBMaxAutoAnalyzeTime)
// variables for plan cache
PreparedPlanCacheMemoryGuardRatio = atomic.NewFloat64(DefTiDBPrepPlanCacheMemoryGuardRatio)
EnableConcurrentDDL = atomic.NewBool(DefTiDBEnableConcurrentDDL)
Expand Down
3 changes: 1 addition & 2 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,6 @@ func setGlobalVars() {
switch oldName {
case "force-priority":
cfg.Instance.ForcePriority = cfg.Performance.ForcePriority
case "memory-usage-alarm-ratio":
cfg.Instance.MemoryUsageAlarmRatio = cfg.Performance.MemoryUsageAlarmRatio
}
case "plugin":
switch oldName {
Expand Down Expand Up @@ -746,6 +744,7 @@ func createServer(storage kv.Storage, dom *domain.Domain) *server.Server {
svr.SetDomain(dom)
svr.InitGlobalConnID(dom.ServerID)
go dom.ExpensiveQueryHandle().SetSessionManager(svr).Run()
go dom.MemoryUsageAlarmHandle().SetSessionManager(svr).Run()
go dom.ServerMemoryLimitHandle().SetSessionManager(svr).Run()
dom.InfoSyncer().SetSessionManager(svr)
return svr
Expand Down
47 changes: 0 additions & 47 deletions util/expensivequery/expensivequerey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ package expensivequery

import (
"testing"
"time"

"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/testkit/testsetup"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/memory"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)

Expand All @@ -34,45 +29,3 @@ func TestMain(m *testing.M) {
}
goleak.VerifyTestMain(m, opts...)
}

func TestLogFormat(t *testing.T) {
mem := memory.NewTracker(-1, -1)
mem.Consume(1<<30 + 1<<29 + 1<<28 + 1<<27)
info := &util.ProcessInfo{
ID: 233,
User: "PingCAP",
Host: "127.0.0.1",
DB: "Database",
Info: "select * from table where a > 1",
CurTxnStartTS: 23333,
StatsInfo: func(interface{}) map[string]uint64 {
return nil
},
StmtCtx: &stmtctx.StatementContext{
MemTracker: mem,
},
RedactSQL: false,
}
costTime := time.Second * 233
logFields := genLogFields(costTime, info)

assert.Len(t, logFields, 7)
assert.Equal(t, "cost_time", logFields[0].Key)
assert.Equal(t, "233s", logFields[0].String)
assert.Equal(t, "conn_id", logFields[1].Key)
assert.Equal(t, int64(233), logFields[1].Integer)
assert.Equal(t, "user", logFields[2].Key)
assert.Equal(t, "PingCAP", logFields[2].String)
assert.Equal(t, "database", logFields[3].Key)
assert.Equal(t, "Database", logFields[3].String)
assert.Equal(t, "txn_start_ts", logFields[4].Key)
assert.Equal(t, int64(23333), logFields[4].Integer)
assert.Equal(t, "mem_max", logFields[5].Key)
assert.Equal(t, "2013265920 Bytes (1.88 GB)", logFields[5].String)
assert.Equal(t, "sql", logFields[6].Key)
assert.Equal(t, "select * from table where a > 1", logFields[6].String)

info.RedactSQL = true
logFields = genLogFields(costTime, info)
assert.Equal(t, "select * from table where `a` > ?", logFields[6].String)
}