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

*: global memory controller should not kill session whose mem less than limit_sess_min_size #42803

Merged
merged 6 commits into from
Apr 7, 2023

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Apr 4, 2023

What problem does this PR solve?

Issue Number:
close #42662
close #42664

Problem Summary:
As the description mentioned here:
#42662 (comment)

What is changed and how it works?

  1. Reset NeekKill flag even error is thrown during the planner phase or executor.Open phase
  2. Do not kill the session whose memory usage is less than tidb_server_memory_limit_sess_min_size

Check List

Tests

  • Unit test
  • Integration test

If we run the same test on master branch, the following error will be thrown:

    testkit.go:157: 
        	Error Trace:	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/testkit/testkit.go:157
        	            				/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/testkit/testkit.go:150
        	            				/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/executor_test.go:6521
        	Error:      	Received unexpected error:
        	            	Out Of Memory Quota![conn=12345]
        	            	github.com/pingcap/tidb/executor.(*ExecStmt).openExecutor.func1
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/adapter.go:1188
        	            	runtime.gopanic
        	            		/Users/xuhuaiyu/.gvm/gos/go1.20/src/runtime/panic.go:884
        	            	github.com/pingcap/tidb/util/memory.(*PanicOnExceed).Action
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/util/memory/action.go:149
        	            	github.com/pingcap/tidb/util/memory.(*Tracker).Consume.func2
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/util/memory/tracker.go:450
        	            	github.com/pingcap/tidb/util/memory.(*Tracker).Consume
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/util/memory/tracker.go:462
        	            	github.com/pingcap/tidb/executor.(*HashAggExec).initForParallelExec
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/aggregate.go:395
        	            	github.com/pingcap/tidb/executor.(*HashAggExec).Open
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/aggregate.go:321
        	            	github.com/pingcap/tidb/executor.(*ExecStmt).openExecutor
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/adapter.go:1192
        	            	github.com/pingcap/tidb/executor.(*ExecStmt).Exec
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/adapter.go:527
        	            	github.com/pingcap/tidb/session.runStmt
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/session/session.go:2343
        	            	github.com/pingcap/tidb/session.(*session).ExecuteStmt
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/session/session.go:2200
        	            	github.com/pingcap/tidb/testkit.(*TestKit).ExecWithContext
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/testkit/testkit.go:325
        	            	github.com/pingcap/tidb/testkit.(*TestKit).MustQueryWithContext
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/testkit/testkit.go:156
        	            	github.com/pingcap/tidb/testkit.(*TestKit).MustQuery
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/testkit/testkit.go:150
        	            	github.com/pingcap/tidb/executor_test.TestIssue42662
        	            		/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/executor_test.go:6521
        	            	testing.tRunner
        	            		/Users/xuhuaiyu/.gvm/gos/go1.20/src/testing/testing.go:1576
        	            	runtime.goexit
        	            		/Users/xuhuaiyu/.gvm/gos/go1.20/src/runtime/asm_amd64.s:1598
        	Test:       	TestIssue42662
        	Messages:   	sql:select count(*) from t1, args:[]

  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix the problem that global memory controller kill the sqls whose memory usage are less than tidb_server_memory_limit_sess_min_size defined.

@XuHuaiyu XuHuaiyu added type/bugfix This PR fixes a bug. sig/execution SIG execution needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. labels Apr 4, 2023
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 4, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • chrysan
  • hawkingrei

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 4, 2023
@XuHuaiyu XuHuaiyu changed the title *: global memory controller should not kill session whose mem less th… *: global memory controller should not kill session whose mem less than limit_sess_min_size Apr 4, 2023
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 4, 2023
memUsage := t.BytesConsumed()
// If the memory usage of the top1 session is less than tidb_server_memory_limit_sess_min_size, we do not need to kill it.
if uint64(memUsage) < limitSessMinSize {
memory.MemUsageTop1Tracker.CompareAndSwap(t, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

If CompareAndSwap fails, it means the Top1Tracker is another tracker now, but we will skip the check and kill in this round, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks OK, I see the interval is 100 ms.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 4, 2023
@@ -6481,3 +6481,46 @@ from ssci right join csci on (ssci.customer_sk=csci.customer_sk
and ssci.item_sk = csci.item_sk)
limit 100;`)
}

func TestIssue42662(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Because too many test cases are in the executor. Please move it into executor/issuetest.

on the other hand, TestIssuexxxx makes people wonder what exactly has been repaired.

@hawkingrei
Copy link
Member

/retest

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Apr 6, 2023

/retest

1 similar comment
@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Apr 6, 2023

/retest

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 6, 2023
@hawkingrei hawkingrei requested a review from wshwsh12 April 6, 2023 06:37
@hawkingrei
Copy link
Member

/retest

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Apr 7, 2023

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: ff2bef0

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 7, 2023
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #42852.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Apr 7, 2023
ti-chi-bot added a commit that referenced this pull request Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/execution SIG execution size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

query with memory usage 0 be killed query killed by global memory controller unexpectedly
4 participants