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: replace StatsLoad mutex with a dedicated mutex for statsCache protection #59778

Merged
merged 4 commits into from
Mar 3, 2025

Conversation

Rustin170506
Copy link
Member

What problem does this PR solve?

Issue Number: ref #55043

Problem Summary:

What changed and how does it work?

I moved the lock to the correct position because placing it near the two channels was too confusing.

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. sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 26, 2025
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.5684%. Comparing base (8b30027) to head (ddb315b).
Report is 23 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #59778        +/-   ##
================================================
+ Coverage   72.9531%   73.5684%   +0.6152%     
================================================
  Files          1699       1729        +30     
  Lines        469241     480686     +11445     
================================================
+ Hits         342326     353633     +11307     
+ Misses       105828     105087       -741     
- Partials      21087      21966       +879     
Flag Coverage Δ
integration 45.5950% <0.0000%> (?)
unit 72.1485% <100.0000%> (-0.0185%) ⬇️

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

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 44.3144% <ø> (-0.7391%) ⬇️

@Rustin170506 Rustin170506 requested a review from Copilot February 27, 2025 01:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR refactors mutex usage in the stats sync load logic by replacing the previously embedded mutex within StatsLoad with a dedicated mutex in statsSyncLoad to better protect the statsCache during concurrent updates.

  • Introduces a dedicated mutex (mu) in statsSyncLoad.
  • Updates updateCachedItem to use the new mutex.
  • Removes the embedded mutex from the StatsLoad struct in types/interfaces.go.

Reviewed Changes

File Description
pkg/statistics/handle/syncload/stats_syncload.go Adds a dedicated mutex for protecting statsCache and updates lock usage
pkg/statistics/handle/types/interfaces.go Removes the now-unneeded embedded sync.Mutex from the StatsLoad struct

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@Rustin170506 Rustin170506 requested a review from Copilot March 3, 2025 05:33

Choose a reason for hiding this comment

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

PR Overview

This PR refactors mutex usage for protecting the statistics cache by introducing a dedicated mutex in the statsSyncLoad struct and removing the embedded mutex from the StatsLoad type.

  • Introduced a dedicated mutex "mu" in statsSyncLoad for better clarity on protecting statsCache.
  • Replaced locking on StatsLoad with locking on the dedicated mutex in updateCachedItem.
  • Removed the unused embedded mutex from the StatsLoad type in interfaces.

Reviewed Changes

File Description
pkg/statistics/handle/syncload/stats_syncload.go Added a dedicated mutex for statsCache protection and updated locking
pkg/statistics/handle/types/interfaces.go Removed an unnecessary embedded mutex from the StatsLoad type

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

pkg/statistics/handle/syncload/stats_syncload.go:70

  • [nitpick] Consider renaming 'mu' to 'statsCacheMu' for enhanced clarity regarding its purpose.
mu sync.Mutex
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.)

Copy link
Contributor

@elsa0520 elsa0520 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 3, 2025
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 3, 2025
Copy link

ti-chi-bot bot commented Mar 3, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-03 05:43:36.20076835 +0000 UTC m=+247529.329688089: ☑️ agreed by elsa0520.
  • 2025-03-03 05:53:30.05014607 +0000 UTC m=+248123.179065811: ☑️ agreed by AilinKid.

Copy link

ti-chi-bot bot commented Mar 3, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, elsa0520, qw4990

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 merged commit 448649e into pingcap:master Mar 3, 2025
25 checks passed
@Rustin170506 Rustin170506 deleted the rustin-patch-sync-load-lock branch March 3, 2025 06:39
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants