-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: fix memory leak after dom.Close #28027
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/cc @wjhuang2016 @gozssky @glorv |
domain/domain.go
Outdated
@@ -605,6 +605,9 @@ func (do *Domain) isClose() bool { | |||
return false | |||
} | |||
|
|||
// DomainMapDelete is used to avoid cycle import with `session` package. | |||
var DomainMapDelete func (kv.Storage) |
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.
How about adding a `callback' to Domain instead of another global variable?
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.
how can we pass the callback? domain package can't access session package
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.
like this
type Domain struct {
callback func()
}
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.
On the other hand, domain
is created by domap.Get()
, so is domap's
responsibility to call domain.Close
?
session/tidb.go
Outdated
@@ -42,6 +42,12 @@ import ( | |||
"go.uber.org/zap" | |||
) | |||
|
|||
func init() { | |||
domain.DomainMapDelete = func(store kv.Storage) { | |||
domap.Delete(store) |
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.
There is another global map storeBootstrapped
which hold a storeUUID -> bool
. ResetStoreForWithTiKVTest
is a similar function to clean the two maps.
sessionctx/variable/statusvar.go
Outdated
var RegisterStatistics = registerStatistics | ||
|
||
// registerStatistics registers statistics. | ||
func registerStatistics(s Statistics) { |
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 should add a function like UnregisterStatistics
and call it when domain or ddl is closed. It seems memory leak also happen in TiDB server, because BootstrapSession
opens domain
twice.
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.
there's no id for Statistics
, we can't find the one we appended (maybe by memory address?)
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.
Directly comparing interface?
Lines 106 to 122 in c26038b
|
its assigned to Domain and unregistered in |
I missed it 😂 |
|
I can't reproduce it in my local |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 3e9e3c9
|
@lance6716: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #18048
Problem Summary: memory leak after dom.Close
What is changed and how it works?
How it Works:
domap
when dom.CloseCheck List
Tests
Side effects
Documentation
Release note