-
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 ctrl+c can not kill tidb during statistics init #54594
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. 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. |
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.
rest lgtm
pkg/statistics/handle/bootstrap.go
Outdated
// Detect the context cancel signal, since it may take a long time for the loop. | ||
// TODO: add context to TableInfoByID and remove this code block? | ||
select { | ||
case <-ctx.Done(): |
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.
if ctx.Err() != nil { return }
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.
done
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 I mean replace the whole select {case <- ctx.Done(): ..., default: ...}.
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 @lance6716 means we can use if ctx.Err() != nil { return }
instead of line63-69.
[LGTM Timeline notifier]Timeline:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #54594 +/- ##
================================================
+ Coverage 72.7895% 73.2545% +0.4649%
================================================
Files 1549 1549
Lines 436285 437999 +1714
================================================
+ Hits 317570 320854 +3284
+ Misses 99067 97478 -1589
- Partials 19648 19667 +19
Flags with carried forward coverage won't be shown. Click here to find out more.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hawkingrei, lance6716, zimulala The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test |
/retest |
What problem does this PR solve?
Issue Number: close #54589
Problem Summary:
When there a a lot of tables, statistics initialize takes a long time.
For example, 1M tables takes 13-14min with infoschema v2 currently.
When TiDB start up and initialize statistics, it does not handle any interrupt signal.
So if I start tidb and then Ctrl+C, domain.Close will wait the background worker to exit.
But the statistics load worker are handling the statistics initialization, it never response to the exit signal.
So tidb can't exit.
What changed and how does it work?
Add a context.Context to the related statistics code and handle context.Cancel signal.
Check List
Tests
Before this commit, the log is this:
And after the fix, tidb can exit quickly:
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.