Skip to content

resourcecontrol: settle batched cop tasks' execution details#2032

Draft
0xTars wants to merge 3 commits into
tikv:masterfrom
0xTars:copper/analyze-batch-merge-v2
Draft

resourcecontrol: settle batched cop tasks' execution details#2032
0xTars wants to merge 3 commits into
tikv:masterfrom
0xTars:copper/analyze-batch-merge-v2

Conversation

@0xTars

@0xTars 0xTars commented Jul 24, 2026

Copy link
Copy Markdown

Problem

MakeResponseInfo reads execution details only from the top-level coprocessor response. A StoreBatchTasks response represents several logical tasks, and each attached batch response carries its own scan detail and process time. Ignoring those children undercounts read bytes and KV CPU during resource-group settlement and RU-based runaway detection.

This replaces #2029 because its source branch cannot be updated.

What changed

Sum every attached batch response's execution details into the response information used for resource-control settlement. When a child has no scan detail, use its data length as the same fallback already used for the top-level response.

The replacement branch is based on TiDB's existing pinned client-go revision, so updating that consumer adds only this patch rather than unrelated newer client changes. Production behavior is identical to #2029; the tests and comments were revised to make the ordinary and NextGen accounting rules explicit.

Compatibility

There is no public API or wire-format change. Non-batched responses retain their existing accounting. Resource usage for batched coprocessor responses can increase to include work that was previously omitted; this is the intended compatibility impact for TiDB resource control. TiCDC, BR, CSE, and other consumers are unaffected unless they use this internal batched-response settlement path.

Tests

  • go test -mod=readonly ./internal/client ./internal/resourcecontrol -count=1
  • go test -mod=readonly -tags nextgen ./internal/client ./internal/resourcecontrol -count=1
  • focused MakeResponseInfo tests with and without the nextgen build tag
  • go generate ./... (clean diff)
  • git diff --check
  • gofmt on the changed files

Related changes

@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has signed the dco. labels Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

[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 imtbkcat 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

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e57f3bc1-380b-4d06-9a8b-1d522ce7e1a3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ 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 added the contribution This PR is from a community contributor. label Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

Hi @0xTars. Thanks for your PR.

I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@ti-chi-bot ti-chi-bot Bot added needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. labels Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

Welcome @0xTars!

It looks like this is your first PR to tikv/client-go 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to tikv/client-go. 😃

0xTars added 3 commits July 24, 2026 13:34
Pin the existing MakeResponseInfo behavior through its public seam before
changing resource accounting. The fixture records that only top-level scan
bytes and KV CPU are currently settled in both legacy and NextGen builds.

Signed-off-by: 0xTars <1196089730@qq.com>
Move the existing legacy and NextGen scan-byte rules into one helper without
changing behavior. The helper lets top-level and nested responses share the
same compatibility policy in the subsequent accounting change.

Signed-off-by: 0xTars <1196089730@qq.com>
Include every nested coprocessor response when settling read bytes and KV CPU.
Use scan-detail bytes when present and response data size otherwise, preserving
the existing legacy and NextGen policies for both top-level and nested work.

Signed-off-by: 0xTars <1196089730@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. 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.

1 participant