-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: print an expensive query log when a query is out of memQuota #10799
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10799 +/- ##
================================================
+ Coverage 80.8285% 80.8473% +0.0187%
================================================
Files 419 419
Lines 88611 88635 +24
================================================
+ Hits 71623 71659 +36
+ Misses 11760 11750 -10
+ Partials 5228 5226 -2 |
ddl/ddl_test.go
Outdated
SetHook(h Callback) | ||
// SetInterceptoror sets the interceptor. | ||
SetInterceptoror(h Interceptor) | ||
} | ||
|
||
// SetHook implements DDL.SetHook interface. | ||
// SetLogHook implements DDL.SetLogHook interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment and Function name is not consistent...
I think it can't pass this check #10787
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
default: | ||
sc.MemTracker.SetActionOnExceed(&memory.LogOnExceed{}) | ||
action := &memory.LogOnExceed{ConnID: ctx.GetSessionVars().ConnectionID} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we return an unsupported oom action
error?
@@ -490,8 +490,9 @@ func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo { | |||
if atomic.LoadInt32(&client.status) == connStatusWaitShutdown { | |||
continue | |||
} | |||
pi := client.ctx.ShowProcess() | |||
rs[pi.ID] = pi | |||
if pi := client.ctx.ShowProcess(); pi != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bugfix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, #10740
But I'm not sure how to add a test case for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do release 2.1 and 3.0 have this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only master branch has this issue now.
Before refactoring the expensive log, this function will only be called when we use show processlist
, the pi
can be promised to be not null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this PR needs to be cherry-picked to release-3.0, so we'd better use another PR to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an UT about it?
And we should backport this UT to old releases.
@@ -490,8 +490,9 @@ func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo { | |||
if atomic.LoadInt32(&client.status) == connStatusWaitShutdown { | |||
continue | |||
} | |||
pi := client.ctx.ShowProcess() | |||
rs[pi.ID] = pi | |||
if pi := client.ctx.ShowProcess(); pi != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do release 2.1 and 3.0 have this issue?
@@ -1303,11 +1303,15 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { | |||
} | |||
switch config.GetGlobalConfig().OOMAction { | |||
case config.OOMActionCancel: | |||
sc.MemTracker.SetActionOnExceed(&memory.PanicOnExceed{}) | |||
action := &memory.PanicOnExceed{ConnID: ctx.GetSessionVars().ConnectionID} | |||
action.SetLogHook(domain.GetDomain(ctx).ExpensiveQueryHandle().LogOnQueryExceedMemQuota) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to add this log. When the query runs out of memory quota, it panics. The upper layer will recover that goroutine and log the panic reason and sql, which is "out of memory quota".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they are two different logs.
Expensive query log can provide us more info about the query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change the panic message to the content we want to log?
ddl/ddl_test.go
Outdated
@@ -46,7 +46,7 @@ type DDLForTest interface { | |||
SetInterceptoror(h Interceptor) | |||
} | |||
|
|||
// SetHook implements DDL.SetHook interface. | |||
// SetHook implements DDL.SetLogHook interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should not be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
util/memory/action.go
Outdated
@@ -17,6 +17,7 @@ import ( | |||
"context" | |||
"sync" | |||
|
|||
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this upward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
Print an expensive query log when a query is out of memory quota.
What is changed and how it works?
Action
, and this hook will be triggered when a sql's memory usage is out of quota.Check List
Tests
MemQuotaQuery
to 1<<15 (32KB), and runselect * from t
, then we get:OOMAction
tocancel
andMemQuotaQuery
to 1<<15(32KB), and runselect * from t
, then we get:Code changes
Side effects
N/A
Related changes