Skip to content

locate: skip per-store limits for requests without a store - #2068

Open
wjhuang2016 wants to merge 1 commit into
tikv:masterfrom
wjhuang2016:codex/fix-57829-tidb-store-limit
Open

wjhuang2016 wants to merge 1 commit into
tikv:masterfrom
wjhuang2016:codex/fix-57829-tidb-store-limit

Conversation

@wjhuang2016

@wjhuang2016 wjhuang2016 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref pingcap/tidb#57829

With tidb_store_limit enabled, querying TiDB cluster information-schema tables can panic in getStoreToken. These coprocessor requests use a TiDB endpoint, for which getRPCContext intentionally returns an address without a backing Store. The synchronous send path nevertheless dereferences that missing store to acquire a per-store token.

What changed and how does it work?

Apply the per-store token limit only when the RPC context has a store. Requests to TiDB endpoints continue to the RPC client without acquiring or releasing a store token. TiKV/TiFlash contexts with stores retain the existing limit and release behavior. This matches the existing no-store handling in acquireRequestAttemptToken and does not change public APIs.

Add a regression sending TiDB coprocessor requests with limits 0, 1, and 10, checking that the response is returned and the RPC context has no store. The positive-limit cases panic before the fix; the zero-limit control succeeds.

Tests

  • RED: go test -tags=intest ./internal/locate -run '^TestRegionRequestToSingleStore$/^TestTiDBRequestWithStoreLimit$' -count=1
  • GREEN, including existing TiKV limiter and async request coverage: go test -tags=intest ./internal/locate -run '^TestRegionRequestToSingleStore$/(TestTiDBRequestWithStoreLimit|TestRequestAttemptLimiter|TestSendReqAsync)$' -count=1
  • Race: go test -race -tags=intest ./internal/locate -run '^TestRegionRequestToSingleStore$/(TestTiDBRequestWithStoreLimit|TestRequestAttemptLimiter|TestSendReqAsync)$' -count=1
  • golangci-lint run ./internal/locate: zero issues (local v2.11.3; repository CI uses v2.8).
  • gofmt on both changed files and git diff --check.

Real TiDB/TiKV cluster queries and the full module test suite were not run locally. This PR fixes client-go; TiDB still needs to consume the updated dependency before its reported issue is fully resolved.

Release note

Fix a panic when per-store request limits are enabled for coprocessor requests sent to TiDB endpoints.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Cop requests to TiDB endpoints when store limits are enabled.
    • TiDB endpoint requests now complete without store-token errors while preserving correct routing and responses.
  • Tests

    • Added coverage for TiDB requests under multiple store-limit configurations.

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/needs-triage-completed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 17, 2026
@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b158447f-8da8-4846-ba59-59ee9737e3ef

📥 Commits

Reviewing files that changed from the base of the PR and between f7a805b and 0020efa.

📒 Files selected for processing (2)
  • internal/locate/region_request.go
  • internal/locate/region_request_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The request path now skips per-store token handling for TiDB endpoints without a backing store. A test validates routing and responses across three store-limit values.

Changes

TiDB endpoint request handling

Layer / File(s) Summary
Store-limit guard and TiDB request validation
internal/locate/region_request.go, internal/locate/region_request_test.go
The sender acquires and releases store tokens only when the RPC context has a backing store. The test validates TiDB routing, response handling, and nil store context behavior for limits 0, 1, and 10.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: ekexium

Merge Risk: ⚪ Minimal · up to 0020e

The TiDB request path avoids the prior nil-store failure while retaining limits for backed stores. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: skipping per-store limits when requests have no backing store. This matches the implementation and PR objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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 Sep 17, 2026

Copy link
Copy Markdown

@coderabbitai[bot]: 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.

@ti-chi-bot

ti-chi-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: coderabbitai[bot]
Once this PR has been reviewed and has the lgtm label, please assign kennytm 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

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

1 participant