Skip to content

planner: cache mpp info to avoid frequent grpc calling - #65694

Merged
ti-chi-bot[bot] merged 22 commits into
pingcap:masterfrom
xzhangxian1008:fix-tiflash-9663
Jun 23, 2026
Merged

ti-chi-bot[bot] merged 22 commits into
pingcap:masterfrom
xzhangxian1008:fix-tiflash-9663

Conversation

@xzhangxian1008

@xzhangxian1008 xzhangxian1008 commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #65701

Problem Summary:

What changed and how does it work?

We define a new struct called MPPInfoManager and set a global variable GlobalMPPInfoManager with MPPInfoManager type. mpp info are all cached in this variable. In getTiFlashServerMinLogicalCores, we will check the cache first then call grpc for uncached tiflash stores. When we get a failed tiflash store in filterAliveStoresHelper, we will remove it's cache.

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

Summary by CodeRabbit

  • Refactor

    • TiFlash query paths now use a cached per-node CPU metric to reduce repeated hardware queries and improve planner efficiency.
    • Cluster server info retrieval now aggregates responses into a single result set while skipping failed nodes for more stable diagnostics and fewer partial failures.
  • Tests

    • Added tests covering the node info caching and manager behavior to ensure correct refresh and failure handling.

@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. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 21, 2026
@tiprow

tiprow Bot commented Jan 21, 2026

Copy link
Copy Markdown

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

Details

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.

@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/run-check-issue-triage-complete

@codecov

codecov Bot commented Jan 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 24.67532% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.1720%. Comparing base (3adc8ec) to head (8f7c812).
⚠️ Report is 38 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65694        +/-   ##
================================================
- Coverage   76.3196%   76.1720%   -0.1476%     
================================================
  Files          2041       2067        +26     
  Lines        562141     585393     +23252     
================================================
+ Hits         429024     445906     +16882     
- Misses       132210     136655      +4445     
- Partials        907       2832      +1925     
Flag Coverage Δ
integration 46.6001% <24.6753%> (+6.9422%) ⬆️

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

Components Coverage Δ
dumpling 60.4610% <ø> (ø)
parser ∅ <ø> (∅)
br 65.7853% <ø> (+3.0159%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@solotzg

solotzg commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

/cc @copilot

@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/cc @windtalker @solotzg

@ti-chi-bot
ti-chi-bot Bot requested review from solotzg and windtalker January 21, 2026 09:43
Comment thread pkg/planner/core/optimizer.go Outdated
}

if len(uncachedServersInfo) > 0 {
ch := make(chan [][]types.Datum, len(uncachedServersInfo))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why use chan?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why use chan?

deleted

Comment thread pkg/planner/core/optimizer.go Outdated
waitWg := &sync.WaitGroup{}
waitWg.Add(len(uncachedServersInfo))
for i := range uncachedServersInfo {
go func(info []infoschema.ServerInfo) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider fetching once for the full slice, or pass the single-server slice into the call and use the row’s address only when the fetch is truly per-server.

The extra goroutine layer may be unnecessary since FetchClusterServerInfoWithoutPrivilegeCheck already fans out internally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Consider fetching once for the full slice, or pass the single-server slice into the call and use the row’s address only when the fetch is truly per-server.

The extra goroutine layer may be unnecessary since FetchClusterServerInfoWithoutPrivilegeCheck already fans out internally.

fixed

@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/hold

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 26, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jan 26, 2026

Copy link
Copy Markdown

@solotzg: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

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.

Comment thread pkg/executor/memtable_reader.go Outdated
infos := infoschema.FetchClusterServerInfoWithoutPrivilegeCheck(ctx, sctx.GetSessionVars(), serversInfo, e.serverInfoType, true)
rowCount := 0
for _, info := range infos {
if info.Err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if info.Err == nil { ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if info.Err == nil { ?

fixed

Comment thread pkg/executor/memtable_reader.go Outdated

results := make([][]types.Datum, 0, rowCount)
for _, info := range infos {
if info.Err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ditto

fixed

@windtalker windtalker left a comment

Copy link
Copy Markdown
Contributor

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 the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 22, 2026
@windtalker

Copy link
Copy Markdown
Contributor

/test check-dev

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 22, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-06-22 08:07:01.075315269 +0000 UTC m=+1984122.145632649: ☑️ agreed by windtalker.
  • 2026-06-22 08:51:29.139139037 +0000 UTC m=+1986790.209456417: ☑️ agreed by winoros.

@ti-chi-bot ti-chi-bot Bot added the approved label Jun 22, 2026
@windtalker

Copy link
Copy Markdown
Contributor

/test pull-br-integration-test

@windtalker

Copy link
Copy Markdown
Contributor

/hold cancel

@windtalker windtalker removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 23, 2026
@windtalker

Copy link
Copy Markdown
Contributor

/test check-dev2

@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, solotzg, windtalker, winoros, wjhuang2016

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@windtalker

Copy link
Copy Markdown
Contributor

/test pull-br-integration-test

@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit 84f3ca5 into pingcap:master Jun 23, 2026
36 checks passed
@xzhangxian1008
xzhangxian1008 deleted the fix-tiflash-9663 branch June 23, 2026 12:33
@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/cherrypick release-8.5

@ti-chi-bot

Copy link
Copy Markdown
Member

@xzhangxian1008: new pull request created to branch release-8.5: #69403.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherrypick release-8.5

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 ti-community-infra/tichi repository.

@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/cherrypick release-nextgen-202603

@ti-chi-bot

Copy link
Copy Markdown
Member

@xzhangxian1008: new pull request created to branch release-nextgen-202603: #69404.

Details

In response to this:

/cherrypick release-nextgen-202603

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 ti-community-infra/tichi repository.

@xzhangxian1008

Copy link
Copy Markdown
Contributor Author

/cherrypick release-nextgen-202603

@ti-chi-bot

Copy link
Copy Markdown
Member

@xzhangxian1008: failed to apply #65694 on top of branch "release-nextgen-202603":

failed to git commit: exit status 1
Details

In response to this:

/cherrypick release-nextgen-202603

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 ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ok-to-test Indicates a PR is ready to be tested. 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.

TiFlash panics with Too many open files due to grpc connection socket leak in the cloud GCP env

8 participants