-
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
sessionctx/stmtctx: do not use copy-on-read for GetWarnings function #39742
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. |
warns := make([]SQLWarn, len(sc.mu.warnings)) | ||
copy(warns, sc.mu.warnings) | ||
return warns | ||
return sc.mu.warnings |
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.
Will return warnings directly cause conflict?
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 code date back to very early commit:
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 407) // GetWarnings gets warnings.
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 408) func (sc *StatementContext) GetWarnings() []error {
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 409) sc.mu.Lock()
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 410) warns := make([]error, len(sc.mu.warnings))
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 411) copy(warns, sc.mu.warnings)
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 412) sc.mu.Unlock()
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 413) return warns
5230f5eabd7 (Ewan Chou 2016-11-29 14:25:38 +0800 414) }
The commit is sooooooo old that it's hard to figure out why it's written like that.
The change should work, if not, at least we can see where the data race happen and try to fix again.
@Defined2014
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.
without copy, does the lock necessary here?
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.
without copy, does the lock necessary here?
I think so ... GetWarnings / SetWarnings
may be visited by many different component, maybe concurrently.
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.
Got it. The value of sc.mu.warnings
will be changed by SetWarnings.
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 1688e68
|
/run-mysql-test |
TiDB MergeCI notify🔴 Bad News! New failing [1] after this pr merged.
|
What problem does this PR solve?
Issue Number: close #39702
Problem Summary:
What is changed and how it works?
7 min 53s => 9.32s
(B.T.W, if we don't add error stack on decimal truncate error, the execution time can furthur reduce to 5s)
Before the change:
After:
Check List
Tests
See #39702 reproduce process.
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.