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

planner: a new thread-safe lock-free plan cache #54089

Merged
merged 16 commits into from
Jun 25, 2024

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Jun 18, 2024

What problem does this PR solve?

Issue Number: close #54057

Problem Summary: planner: a new thread-safe lock-free plan cache

What changed and how does it work?

I'll add more test cases in the next few PRs.

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 do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/planner SIG: Planner labels Jun 18, 2024
Copy link

tiprow bot commented Jun 18, 2024

Hi @qw4990. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 87.12121% with 17 lines in your changes missing coverage. Please review.

Project coverage is 56.1599%. Comparing base (dfa6b7c) to head (1621eb0).
Report is 52 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54089         +/-   ##
=================================================
- Coverage   74.8567%   56.1599%   -18.6968%     
=================================================
  Files          1516       1642        +126     
  Lines        360852     615583     +254731     
=================================================
+ Hits         270122     345711      +75589     
- Misses        71179     246554     +175375     
- Partials      19551      23318       +3767     
Flag Coverage Δ
integration 36.2468% <0.0000%> (?)

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

Components Coverage Δ
dumpling 52.9656% <ø> (-2.2339%) ⬇️
parser ∅ <ø> (∅)
br 52.1240% <ø> (+4.1456%) ⬆️

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 18, 2024
Copy link
Member

@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.

thanks!

pkg/planner/core/plan_cache_instance.go Show resolved Hide resolved
pkg/planner/core/plan_cache_instance.go Show resolved Hide resolved
pkg/planner/core/plan_cache_instance.go Outdated Show resolved Hide resolved
pkg/planner/core/plan_cache_instance.go Outdated Show resolved Hide resolved
qw4990 and others added 2 commits June 21, 2024 13:51
pkg/planner/core/plan_cache_instance.go Outdated Show resolved Hide resolved
pkg/planner/core/plan_cache_instance_test.go Outdated Show resolved Hide resolved
pkg/planner/core/plan_cache_instance.go Show resolved Hide resolved
pkg/planner/core/plan_cache_instance.go Outdated Show resolved Hide resolved
pkg/planner/core/plan_cache_instance.go Outdated Show resolved Hide resolved
Comment on lines 182 to 183
if len(lastUsedTimes) < int(numToEvict) {
return
Copy link
Member

Choose a reason for hiding this comment

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

How could this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for safety, to avoid index-out-of-range panic below.

@qw4990
Copy link
Contributor Author

qw4990 commented Jun 25, 2024

Thanks, all comments have been addressed @time-and-fate

Copy link
Member

@time-and-fate time-and-fate left a comment

Choose a reason for hiding this comment

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

Others LGTM.

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package core
Copy link
Member

Choose a reason for hiding this comment

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

Need an empty line here to pass CI.

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package core
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

Comment on lines 32 to 34
Evict(sctx sessionctx.Context) (evicted bool)
// MemUsage returns the total memory usage of this plan cache.
MemUsage(sctx sessionctx.Context) int64
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we don't need sctx parameter for these two methods.

Copy link
Member

@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.

Approve in advance.

Please address @time-and-fate's comment.

// Get gets the cached value from the cache according to key and opts.
Get(sctx sessionctx.Context, key string, opts any) (value any, ok bool)
// Put puts the key and value into the cache.
Put(sctx sessionctx.Context, key string, value, opts any) (succ bool)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should add a comment to explain why we need to use them here. But I am fine if you prefer not to add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, Thanks!

@ti-chi-bot ti-chi-bot bot added the approved label Jun 25, 2024
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 25, 2024
Copy link

ti-chi-bot bot commented Jun 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hi-rustin, time-and-fate

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 25, 2024
Copy link

ti-chi-bot bot commented Jun 25, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-25 09:45:19.993634557 +0000 UTC m=+712846.479123384: ☑️ agreed by hi-rustin.
  • 2024-06-25 11:31:25.661662869 +0000 UTC m=+719212.147151699: ☑️ agreed by time-and-fate.

@ti-chi-bot ti-chi-bot bot merged commit 4869956 into pingcap:master Jun 25, 2024
20 of 23 checks passed
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner: instance/node level plan cache - phase 1
4 participants