Skip to content

resourcecontrol: price NextGen remote reads separately#2022

Open
YuhaoZhang00 wants to merge 1 commit into
tikv:masterfrom
YuhaoZhang00:feat/nextgen-remote-read-ru-cost
Open

resourcecontrol: price NextGen remote reads separately#2022
YuhaoZhang00 wants to merge 1 commit into
tikv:masterfrom
YuhaoZhang00:feat/nextgen-remote-read-ru-cost

Conversation

@YuhaoZhang00

@YuhaoZhang00 YuhaoZhang00 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref tikv/pd#11019

Related protocol: pingcap/kvproto#1500
Related RU-v1 pricing model: tikv/pd#11018

NextGen remote coprocessor responses need to keep scan statistics factual while allowing the RU-v1 controller to price the remote byte subset separately. Legacy clients must retain the existing pre-priced compatibility behavior.

What is changed?

  • Advertise client_prices_remote_reads only for NextGen coprocessor requests. Non-NextGen and non-coprocessor requests keep the capability disabled.
  • Keep NextGen ReadBytes() as the factual maximum of total/processed scan bytes and expose the factual remote maximum through RemoteReadBytes() for PD's optional remote-byte provider interface.
  • Ignore remote fields outside NextGen so the legacy resource-control path remains unchanged.
  • Temporarily pin both Go modules to the kvproto PR head; this replace can be removed after kvproto#1500 merges and the normal dependency is bumped.

There is no RU-v2 pricing or accounting change, and client-go does not multiply facts by a discount.

Tests

  • go test --tags=intest ./...
  • go test --tags=intest ./internal/resourcecontrol ./tikvrpc
  • go test --tags='intest nextgen' ./internal/resourcecontrol ./tikvrpc
  • go test -race --tags=intest ./internal/resourcecontrol ./tikvrpc
  • go test -race --tags='intest nextgen' ./internal/resourcecontrol ./tikvrpc
  • go generate ./...

The repository-wide NextGen-tag run has one unrelated baseline failure in internal/locate (TestRegionRequestToThreeStores/TestDoNotTryUnreachableLeader); the same assertion reproduces on a clean detached upstream/master. All changed NextGen packages pass.

Summary by CodeRabbit

  • New Features

    • Improved resource accounting for NextGen coprocessor requests by separately tracking remote read activity.
    • Added support for advertising remote-read pricing capabilities to compatible requests.
  • Bug Fixes

    • Preserved legacy pricing behavior for older clients and non-NextGen requests.
  • Tests

    • Added coverage for remote read calculations and pricing behavior across supported request types.

Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
@ti-chi-bot ti-chi-bot Bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Jul 17, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 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 niedhui 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 contribution This PR is from a community contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Jul 17, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

Hi @YuhaoZhang00. 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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

NextGen coprocessor requests now advertise remote-read pricing, and response accounting derives a separate remote read-byte value from scan details while preserving legacy behavior.

Changes

Remote read pricing

Layer / File(s) Summary
Coprocessor pricing advertisement
go.mod, integration_tests/go.mod, tikvrpc/tikvrpc.go, tikvrpc/tikvrpc_test.go
The kvproto dependency uses a fork, and AttachContext advertises remote-read pricing for NextGen CmdCop and CmdCopStream requests.
Remote response byte accounting
internal/resourcecontrol/resource_control.go, internal/resourcecontrol/resource_control_test.go
ResponseInfo derives and exposes remote read bytes from NextGen scan details, with tests covering NextGen, legacy, and compatibility cases.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AttachContext
  participant TiKV
  participant MakeResponseInfo
  Client->>AttachContext: attach NextGen coprocessor context
  AttachContext->>TiKV: send ClientPricesRemoteReads flag
  TiKV-->>MakeResponseInfo: return scan details
  MakeResponseInfo-->>Client: expose read and remote read bytes
Loading

Possibly related PRs

  • tikv/client-go#1907: Changes MakeResponseInfo scan version-size handling for RU-related ReadBytes calculations.

Suggested reviewers: lcwangchao, ekexium, connor1996

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: separate pricing for NextGen remote reads in resource control.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/resourcecontrol/resource_control_test.go (1)

110-124: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Explicitly test both config.NextGen states.

By branching on the global config.NextGen value, this test execution will only verify one of the behavior paths while silently skipping the other. If config.NextGen is a mutable variable, consider explicitly toggling it so that both legacy and NextGen behaviors are asserted in every test run.

♻️ Proposed refactor to test both states
-	info := MakeResponseInfo(resp)
-	if config.NextGen {
-		assert.Equal(t, uint64(100), info.ReadBytes())
-		assert.Equal(t, uint64(40), info.RemoteReadBytes())
-	} else {
-		assert.Equal(t, uint64(80), info.ReadBytes())
-		assert.Zero(t, info.RemoteReadBytes())
-	}
+	originalNextGen := config.NextGen
+	defer func() { config.NextGen = originalNextGen }()
+
+	// Test NextGen behavior
+	config.NextGen = true
+	infoNext := MakeResponseInfo(resp)
+	assert.Equal(t, uint64(100), infoNext.ReadBytes())
+	assert.Equal(t, uint64(40), infoNext.RemoteReadBytes())
+
+	// Test legacy behavior
+	config.NextGen = false
+	infoLegacy := MakeResponseInfo(resp)
+	assert.Equal(t, uint64(80), infoLegacy.ReadBytes())
+	assert.Zero(t, infoLegacy.RemoteReadBytes())
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/resourcecontrol/resource_control_test.go` around lines 110 - 124,
Update the test around MakeResponseInfo to explicitly run assertions for both
config.NextGen values instead of branching on the current global state. Set
config.NextGen to each state in turn, verify the corresponding ReadBytes and
RemoteReadBytes results, and restore the original value afterward if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/resourcecontrol/resource_control_test.go`:
- Around line 110-124: Update the test around MakeResponseInfo to explicitly run
assertions for both config.NextGen values instead of branching on the current
global state. Set config.NextGen to each state in turn, verify the corresponding
ReadBytes and RemoteReadBytes results, and restore the original value afterward
if needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b75c4d7-12e6-471f-a7df-20fb818a84c8

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4b3ea and 0c69dc5.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • integration_tests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • go.mod
  • integration_tests/go.mod
  • internal/resourcecontrol/resource_control.go
  • internal/resourcecontrol/resource_control_test.go
  • tikvrpc/tikvrpc.go
  • tikvrpc/tikvrpc_test.go

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. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. 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