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

statistics: fix a data race in auto-analyze #55501

Merged
merged 8 commits into from
Aug 22, 2024

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Aug 19, 2024

What problem does this PR solve?

Issue Number: ref #53460

Problem Summary:

I found some issues in the previous implementation.

  1. There is a typo.
  2. There is a data race when we handle the error.
  3. The name is outdated.
  4. There are no tests for the concurrent analysis.
  5. The variable cannot be displayed correctly.

What changed and how does it work?

  1. Fixed the typo.
  2. Fixed the data race.
  3. Added a unit test for it.
  4. Renamed the function.
  5. Added a validation for it.
  6. Fixed the display issue.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/planner SIG: Planner labels Aug 19, 2024
Copy link
Member Author

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

The current implementation does not satisfy our new priority queue because it is not aware of the currently running table, and in the future we will need to skip updates to the running table. So we need to maintain at least the running tables ID.
Also the efficiency of this current implementation is determined by the slowest table every time, we should make the refresher ensure that there are always n tasks going on concurrently without creating unnecessary blocking of each other.
I will improve this when I implement the new priority queue.

🔢 Self-check (PR reviewed by myself and ready for feedback.)

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 19, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 19, 2024
Copy link

ti-chi-bot bot commented Aug 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-19 09:33:20.480049386 +0000 UTC m=+171595.614499500: ☑️ agreed by hawkingrei.
  • 2024-08-19 09:39:41.259576081 +0000 UTC m=+171976.394026201: ☑️ agreed by AilinKid.

Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 6 lines in your changes missing coverage. Please review.

Project coverage is 75.0103%. Comparing base (7342d1d) to head (6a26c7e).
Report is 43 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55501        +/-   ##
================================================
+ Coverage   72.8872%   75.0103%   +2.1231%     
================================================
  Files          1576       1581         +5     
  Lines        440796     455813     +15017     
================================================
+ Hits         321284     341907     +20623     
+ Misses        99789      93281      -6508     
- Partials      19723      20625       +902     
Flag Coverage Δ
integration 49.0052% <47.2222%> (?)
unit 71.9328% <83.3333%> (-0.0161%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 51.8032% <ø> (+5.8127%) ⬆️

@Rustin170506
Copy link
Member Author

Rustin170506 commented Aug 22, 2024

For the validation, I tested it locally again:

mysql> select @@tidb_auto_analyze_concurrency;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id:    2803892230
Current database: *** NONE ***

+---------------------------------+
| @@tidb_auto_analyze_concurrency |
+---------------------------------+
|                                |
+---------------------------------+
1 row in set (0.08 sec)

mysql> select @@tidb_auto_analyze_concurrency;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id:    2657091590
Current database: *** NONE ***

+---------------------------------+
| @@tidb_auto_analyze_concurrency |
+---------------------------------+
| 2                               |
+---------------------------------+
1 row in set (0.03 sec)

mysql> set global tidb_enable_auto_analyze_priority_queue = OFF;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> select @@tidb_enable_auto_analyze_priority_queue;
+-------------------------------------------+
| @@tidb_enable_auto_analyze_priority_queue |
+-------------------------------------------+
|                                         0 |
+-------------------------------------------+
1 row in set (0.00 sec)

mysql> set global tidb_auto_analyze_concurrency = 10;
ERROR 1105 (HY000): cannot set tidb_auto_analyze_concurrency: requires both tidb_enable_auto_analyze and tidb_enable_auto_analyze_priority_queue to be true. Current values: tidb_enable_auto_analyze=true, tidb_enable_auto_analyze_priority_queue=false

mysql> set global tidb_enable_auto_analyze_priority_queue = true;
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> set global tidb_auto_analyze_concurrency = 10;
Query OK, 0 rows affected (0.03 sec)

mysql> select @@tidb_auto_analyze_concurrency;
+---------------------------------+
| @@tidb_auto_analyze_concurrency |
+---------------------------------+
| 10                              |
+---------------------------------+
1 row in set (0.00 sec)

Copy link
Member Author

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback.)

@easonn7
Copy link

easonn7 commented Aug 22, 2024

/approve

Copy link

ti-chi-bot bot commented Aug 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, easonn7, hawkingrei

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Aug 22, 2024
@ti-chi-bot ti-chi-bot bot merged commit e72089d into pingcap:master Aug 22, 2024
23 checks passed
@Rustin170506 Rustin170506 deleted the rustin-patch-analyze-variable branch August 22, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants