Skip to content

infoschema: fix information_schema.tikv_region_status for nextgen (#67444)#67509

Open
ti-chi-bot wants to merge 5 commits intopingcap:release-nextgen-20251011from
ti-chi-bot:cherry-pick-67444-to-release-nextgen-20251011
Open

infoschema: fix information_schema.tikv_region_status for nextgen (#67444)#67509
ti-chi-bot wants to merge 5 commits intopingcap:release-nextgen-20251011from
ti-chi-bot:cherry-pick-67444-to-release-nextgen-20251011

Conversation

@ti-chi-bot
Copy link
Copy Markdown
Member

@ti-chi-bot ti-chi-bot commented Apr 2, 2026

This is an automated cherry-pick of #67444

What problem does this PR solve?

Issue Number: close #67442, close #67441

Problem Summary:

  1. The information_schema.tikv_region_status usually includes all regions in all keyspaces.
  2. The WHERE table_id = xxx condition doesn't include indexes.

What changed and how does it work?

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

Release Notes

  • Tests

    • Enhanced information_schema.tikv_region_status test coverage for region splitting and index regions.
    • Added keyspace isolation verification tests to prevent cross-keyspace region data contamination.
  • Chores

    • Refactored region retrieval implementation for improved efficiency.
    • Updated build dependencies.

@ti-chi-bot ti-chi-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. type/cherry-pick-for-release-nextgen-20251011 labels Apr 2, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 2, 2026

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

This PR addresses two bugs in information_schema.tikv_region_status: expanding key-range queries to include index regions when filtering by table ID, and isolating region data to the current keyspace to prevent information leakage. A new helper method retrieves all regions for the store with full key-range coverage, and region-filtering logic is refactored to use this method while enforcing keyspace boundaries.

Changes

Cohort / File(s) Summary
Build Configuration
pkg/executor/BUILD.bazel, tests/realtikvtest/sessiontest/BUILD.bazel
Added Bazel dependency //pkg/ddl/placement to executor targets; increased sessiontest shard count from 16 to 17 and added //pkg/config/kerneltype and //pkg/keyspace dependencies.
Helper Infrastructure
pkg/store/helper/helper.go
Added new exported method GetRegions(ctx context.Context) that retrieves all regions for the current store by querying PD with a full-store key-range, encapsulating PD client acquisition and key-range encoding logic.
Region Query Logic
pkg/executor/infoschema_reader.go, pkg/executor/memtable_reader.go
Refactored callers to use the new helper GetRegions() method instead of directly accessing PD HTTP client; expanded key-range query in getRegionsInfoForSingleTable from table handle ranges to full table prefix ranges to include both record and index regions.
Test Infrastructure & Coverage
pkg/executor/infoschema_cluster_table_test.go, tests/realtikvtest/sessiontest/infoschema_test.go
Extended mocked PD server with region-key lookup, placement rule group, and config endpoints; refactored region mock responses to be parameterized by key ranges; updated TestNextGenTiKVRegionStatus to verify region counts match across table and index splits; added TestNextGenTiKVRegionStatusDoesNotMixOtherKeyspaces to verify keyspace isolation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • pingcap/tidb#67444 — Implements identical core changes (Helper.GetRegions, executor refactoring, PD mock updates) addressing the same region-status filtering issues.
  • pingcap/tidb#66194 — Modifies helper and executor region key-range handling and PD client interactions.

Suggested labels

cherry-pick-approved, ok-to-test

Suggested reviewers

  • tangenta
  • tiancaiamao

Poem

🐰 A helper so clever, it gathers them all,
Index and record, no regions fall through,
Keyspaces stay pure, no cross-table sprawl,
The info schema view now speaks truth so true! 📊✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: addressing issues with information_schema.tikv_region_status for nextgen, directly matching the PR's core objective.
Description check ✅ Passed The description includes issue numbers (#67442, #67441), problem summary addressing both index region inclusion and keyspace isolation, checked test boxes (unit and integration), and follows the required template structure.
Linked Issues check ✅ Passed Code changes comprehensively address both linked issues: #67441 (keyspace isolation via GetRegions and boundary detection) and #67442 (index region inclusion via expanded key-range queries).
Out of Scope Changes check ✅ Passed All changes are directly related to fixing information_schema.tikv_region_status: PD HTTP client refactoring, region key-range expansion for index coverage, helper method additions, test enhancements, and associated Bazel build configuration updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/executor/memtable_reader.go (1)

919-924: ⚠️ Potential issue | 🟠 Major

Keep filtered peer lookups on the same keyspace boundary.

The no-filter path is now keyspace-scoped, but the StoreIDs / RegionIDs branches below still use global PD lookups and never re-check the returned key range. In nextgen, WHERE store_id = ... or WHERE region_id = ... can still expose peer rows from other keyspaces, so visibility becomes filter-dependent. Filter those PD results against tikvStore.GetCodec().EncodeRegionRange(nil, nil) before packing rows.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/executor/memtable_reader.go` around lines 919 - 924, The StoreIDs and
RegionIDs branches (code paths checking e.extractor.StoreIDs and
e.extractor.RegionIDs and calling tikvHelper.GetStores/GetRegions) perform
global PD lookups and must be filtered to the current keyspace before calling
e.packTiKVRegionPeersRows; update those branches to filter the returned
stores/regions by checking each entry’s region key range against the current
keyspace bounds produced by tikvStore.GetCodec().EncodeRegionRange(nil, nil)
(i.e., compute the encoded start/end for the keyspace and drop any store/region
whose region range falls outside those bounds) so that packTiKVRegionPeersRows
only receives peers within the same keyspace.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/executor/memtable_reader.go`:
- Around line 919-924: The StoreIDs and RegionIDs branches (code paths checking
e.extractor.StoreIDs and e.extractor.RegionIDs and calling
tikvHelper.GetStores/GetRegions) perform global PD lookups and must be filtered
to the current keyspace before calling e.packTiKVRegionPeersRows; update those
branches to filter the returned stores/regions by checking each entry’s region
key range against the current keyspace bounds produced by
tikvStore.GetCodec().EncodeRegionRange(nil, nil) (i.e., compute the encoded
start/end for the keyspace and drop any store/region whose region range falls
outside those bounds) so that packTiKVRegionPeersRows only receives peers within
the same keyspace.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d893763f-aa4c-41a1-a865-8f562333595c

📥 Commits

Reviewing files that changed from the base of the PR and between 5ec8168 and 717cd73.

📒 Files selected for processing (7)
  • pkg/executor/BUILD.bazel
  • pkg/executor/infoschema_cluster_table_test.go
  • pkg/executor/infoschema_reader.go
  • pkg/executor/memtable_reader.go
  • pkg/store/helper/helper.go
  • tests/realtikvtest/sessiontest/BUILD.bazel
  • tests/realtikvtest/sessiontest/infoschema_test.go

@YangKeao
Copy link
Copy Markdown
Member

YangKeao commented Apr 2, 2026

The test will pass after #67505 is merged.

@YangKeao
Copy link
Copy Markdown
Member

YangKeao commented Apr 2, 2026

/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 Apr 2, 2026
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 2, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tangenta, tiancaiamao

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:
  • OWNERS [tangenta,tiancaiamao]

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 Apr 2, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 2, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-02 08:09:11.548292899 +0000 UTC m=+425356.753652956: ☑️ agreed by tiancaiamao.
  • 2026-04-02 08:11:12.62184537 +0000 UTC m=+425477.827205427: ☑️ agreed by tangenta.

@YangKeao
Copy link
Copy Markdown
Member

YangKeao commented Apr 3, 2026

/retest

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 56.25000% with 7 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-nextgen-20251011@5ec8168). Learn more about missing BASE report.

Additional details and impacted files
@@                      Coverage Diff                      @@
##             release-nextgen-20251011     #67509   +/-   ##
=============================================================
  Coverage                            ?   71.8513%           
=============================================================
  Files                               ?       1833           
  Lines                               ?     492923           
  Branches                            ?          0           
=============================================================
  Hits                                ?     354172           
  Misses                              ?     115415           
  Partials                            ?      23336           
Flag Coverage Δ
unit 71.8513% <56.2500%> (?)

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

Components Coverage Δ
dumpling 56.3493% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 46.5808% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@YangKeao
Copy link
Copy Markdown
Member

YangKeao commented Apr 3, 2026

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved do-not-merge/cherry-pick-not-approved lgtm 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. type/cherry-pick-for-release-nextgen-20251011

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants