-
Notifications
You must be signed in to change notification settings - Fork 6.1k
stmtsummary: fix a memory leak caused by stmt summary referencing packet data #65977
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
Conversation
|
Hi @tiancaiamao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions 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 kubernetes-sigs/prow repository. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #65977 +/- ##
================================================
- Coverage 77.7795% 77.5191% -0.2605%
================================================
Files 2001 1923 -78
Lines 545624 536043 -9581
================================================
- Hits 424384 415536 -8848
- Misses 119578 120496 +918
+ Partials 1662 11 -1651
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
|
@tiancaiamao: PRs from untrusted users cannot be marked as trusted with DetailsIn response to this:
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 kubernetes-sigs/prow repository. |
YangKeao
left a comment
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 😆
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: xhebox, YangKeao The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What problem does this PR solve?
Issue Number: ref #64256
Problem Summary:
Maybe they are the same leak, but maybe not.
From the Go heap profile, I can see the packet data memory is leak
And using goref https://github.com/cloudwego/goref, stmtsummary is the root refercing data:
What changed and how does it work?
Key path (from packet allocation to being held by stmt summary):
data := make([]byte, length) allocates the full packet payload.
dataStr := string(hack.String(data)) uses unsafe zero-copy to convert []byte to string.
stmtText() takes a substring of the original SQL: text := s.r.s[s.stmtStartPos:endPos], without copying.
The AST node stores text (still referencing the original underlying array).
sc.OriginalSQL = s.Text() puts the AST text into StmtCtx.OriginalSQL.
sampleSQL: formatSQL(sei.LazyInfo.GetOriginalSQL())
formatSQL returns the original string directly when length <= tidb_stmt_summary_max_sql_length.
Result:
stmt summary keeps the original SQL string, and that string actually points to the packet’s underlying buffer.
For multi-statement or large SQL, even if a single statement is short, the substring still keeps the entire packet alive.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.