Skip to content

server: keep unsynced region stats leader-only - #11065

Open
okJiang wants to merge 1 commit into
tikv:masterfrom
okJiang:codex/issue-10719-leader-only-region-stats
Open

server: keep unsynced region stats leader-only#11065
okJiang wants to merge 1 commit into
tikv:masterfrom
okJiang:codex/issue-10719-leader-only-region-stats

Conversation

@okJiang

@okJiang okJiang commented Jul 29, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #10719

Follower handling allowed several Region statistics APIs to execute against the follower-local Region cache.

RegionSyncer does not synchronize query statistics, approximate size and key counts, or CPU usage. A follower could therefore return stale, missing, or zero statistics for these APIs.

What is changed and how does it work?

Keep Region query, size, key, CPU, and histogram statistics APIs on the leader.

Continue allowing follower-local handling for Region metadata and flow APIs whose required fields are synchronized.

Add an integration test that verifies direct follower handling is rejected while normal forwarding to the leader succeeds.

Check List

Tests

  • Integration test
  • Manual test

Manual test:

  • Verified direct follower handling is rejected for all seven affected statistics APIs.
  • Verified the same requests succeed after forwarding to the leader.
  • Verified safe Region metadata and flow APIs continue to execute on followers.

Code changes

  • Has HTTP APIs changed

Release note

Keep Region query, size, key, CPU, and histogram statistics APIs on the PD leader when follower handling is enabled.

Summary by CodeRabbit

  • Bug Fixes
    • Updated access handling for region query, sizing, key, CPU, and histogram endpoints.
    • Requests to leader-only region APIs from follower nodes now return a clear error when the cluster is not bootstrapped.
  • Tests
    • Added coverage for follower behavior across additional region-related endpoints.

Signed-off-by: okjiang <819421878@qq.com>
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has signed the dco. labels Jul 29, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cabinfeverb for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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

@ti-chi-bot ti-chi-bot Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6dc2e1dd-87f9-4970-a07f-2ab82d116c6c

📥 Commits

Reviewing files that changed from the base of the PR and between fad3ff9 and aafd682.

📒 Files selected for processing (2)
  • server/api/router.go
  • tests/server/api/api_test.go

📝 Walkthrough

Walkthrough

Region ranking and histogram APIs are reassigned from region read routing to cluster routing. Follower API coverage now verifies leader-only region endpoints return cluster-not-bootstrapped errors without forwarding.

Changes

Region API routing

Layer / File(s) Summary
Cluster middleware routing and follower validation
server/api/router.go, tests/server/api/api_test.go
Region ranking and histogram endpoints move to clusterRouter, while readflow, confver, and version remain on regionReadRouter. Follower requests to leader-only paths are expected to return HTTP 500 with the cluster-not-bootstrapped message.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • tikv/pd#10682: Updates related region endpoint routing and follower no-forward behavior.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: keeping affected region statistics APIs leader-only.
Description check ✅ Passed The description follows the template and includes the issue, change summary, tests, code changes, and release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@ti-chi-bot

ti-chi-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@okJiang: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen-3 aafd682 link true /test pull-unit-test-next-gen-3

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.36%. Comparing base (070828c) to head (aafd682).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11065      +/-   ##
==========================================
+ Coverage   79.23%   79.36%   +0.12%     
==========================================
  Files         540      541       +1     
  Lines       76010    76354     +344     
==========================================
+ Hits        60226    60597     +371     
+ Misses      11533    11497      -36     
- Partials     4251     4260       +9     
Flag Coverage Δ
unittests 79.36% <100.00%> (+0.12%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant