Skip to content

store/copr: add RC byte-budget paging framework#67504

Open
JmPotato wants to merge 6 commits intopingcap:masterfrom
JmPotato:demo/ru-paging-size
Open

store/copr: add RC byte-budget paging framework#67504
JmPotato wants to merge 6 commits intopingcap:masterfrom
JmPotato:demo/ru-paging-size

Conversation

@JmPotato
Copy link
Copy Markdown
Member

@JmPotato JmPotato commented Apr 2, 2026

What problem does this PR solve?

Issue Number: ref pingcap/kvproto#1448

Problem Summary:

In concurrent coprocessor workloads under Resource Control, row-count-based paging alone cannot prevent "token cliff" effects where multiple workers exhaust RU budgets simultaneously. This PR introduces byte-budget paging to bound per-page resource consumption by byte size (4 MB), enabling PD's resource controller to pre-charge RU more accurately in Phase 1.

What changed and how does it work?

RC Paging Eligibility (rcPagingEligible):

  • Checks 4 conditions: RC enabled, resource group set, TiKV store, DAG request type
  • TiFlash and non-DAG requests are excluded

Paging Injection (BuildCopIterator):

  • When eligible, force-enables paging with row-count limits (128–50K) and sets rcPagingSizeBytes = 4MB
  • Byte budget propagates through copTaskhandleTaskOnce → coprocessor RPC (PagingSizeBytes field)
  • Retry handling preserves pagingSizeBytes across region/lock errors

New Constants (paging.go):

  • MinPagingSizeBytes = 256 KB, MaxPagingSizeBytes = 4 MB

Dependency Updates (go.mod):

  • kvproto → JmPotato/kvproto (adds paging_size_bytes proto field)
  • client-go → JmPotato/client-go (extracts PagingSizeBytes from RequestInfo)
  • pd/client → JmPotato/pd (two-phase RU pre-charge/settlement)

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test

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

Related PRs

Release note

None

Summary by CodeRabbit

  • New Features

    • Resource-control byte-budget paging for TiKV DAG requests when resource groups are enabled.
    • New system variable tidb_rc_paging_size_bytes (GLOBAL|SESSION) to set per-page byte budget (0 disables; default = max paging size).
  • Tests

    • Added tests for paging eligibility and byte-budget assignment/clearing behavior.
  • Chores

    • Updated dependency pins, module replacements, and test sharding/build config.

JmPotato added 3 commits April 2, 2026 10:20
When Resource Control is enabled, force-enable paging for eligible
coprocessor requests and set a byte budget (paging_size_bytes) per
page. This limits the scanned bytes of each page so that RU cost
is bounded and pre-charged in Phase 1, preventing concurrent
workers from all hitting Phase 2 simultaneously.

Signed-off-by: JmPotato <github@ipotato.me>
Signed-off-by: JmPotato <github@ipotato.me>
…ation

Test rcPagingEligible conditions (RC enabled, resource group, TiKV, DAG)
and verify pagingSizeBytes is correctly propagated to copTasks and cleared
when small limit disables paging.

Signed-off-by: JmPotato <github@ipotato.me>
@pantheon-ai
Copy link
Copy Markdown

pantheon-ai bot commented Apr 2, 2026

Review Complete

Findings: 0 issues
Posted: 0
Duplicates/Skipped: 0

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Resource-Control (RC) byte-budget paging for TiKV DAG coprocessor requests, propagates a per-page byte budget through DistSQL/session/sysvar plumbing and cop task construction, introduces paging-size constants (256 KB–4 MB), updates go module pins and Bazel deps, adds tests and adjusts test sharding/deps.

Changes

Cohort / File(s) Summary
Module & Bazel deps
go.mod, DEPS.bzl
Bumped modules, added replace directives routing some tikv/pingcap modules to forked github.com/JmPotato/* paths; expanded and re-pinned many Bazel go_repository entries.
RC Paging Core
pkg/store/copr/coprocessor.go
Added rcPagingEligible; compute rcPagingSizeBytes when eligible; enable/set paging sizes and thread budget via buildCopTaskOptcopTask → outbound coprocessor.Request; clear budget for small LimitSize; propagate to “remains” tasks.
RC Paging Tests
pkg/store/copr/coprocessor_test.go
Added TestRCPagingEligible and TestBuildCopTasksWithRCPagingSizeBytes verifying eligibility rules and propagation/clearing of pagingSizeBytes.
Paging Constants
pkg/util/paging/paging.go
Added exported MinPagingSizeBytes = 256 * 1024 and MaxPagingSizeBytes = 4 * 1024 * 1024.
DistSQL & Request plumbing
pkg/distsql/context/context.go, pkg/distsql/request_builder.go, pkg/kv/kv.go
Added DistSQLContext.RCPagingSizeBytes; added Request.Paging.RCPagingSizeBytes and propagate RCPagingSizeBytes into outgoing requests.
Session & Sysvar
pkg/session/session.go, pkg/sessionctx/vardef/tidb_vars.go, pkg/sessionctx/variable/session.go, pkg/sessionctx/variable/sysvar.go
Added SessionVars.RCPagingSizeBytes, new sysvar tidb_rc_paging_size_bytes (default from DefRCPagingSizeBytes), initialized in NewSessionVars and wired into sysvar setter.
Build / Test config
pkg/store/copr/BUILD.bazel
Increased copr_test shard_count from 40 to 42 and added //pkg/sessionctx/vardef to test deps.

Sequence Diagram(s)

sequenceDiagram
  participant Planner as "BuildCopIterator\n(Planner)"
  participant Builder as "buildCopTaskOpt\n/ copTask"
  participant TiKV as "TiKV\n(Coprocessor)"
  participant ResourceCtrl as "Resource Control\n(config)"
  rect rgba(200,230,201,0.5)
    Planner->>ResourceCtrl: check RC enabled & resource group
    ResourceCtrl-->>Planner: RC enabled? (yes/no)
    Planner->>Planner: rcPagingEligible(req)?
    alt eligible
      Planner->>Builder: set paging=true,\nrcPagingSizeBytes, min/max
      Builder->>TiKV: send Request(Paging=true,\nPagingSizeBytes=rcPagingSizeBytes)
      TiKV-->>Builder: paged response chunk
      Builder-->>Planner: assemble remains task\n(propagate pagingSizeBytes)
    else not eligible
      Planner->>Builder: normal request (no RC paging)
      Builder->>TiKV: send Request(Paging=false)
      TiKV-->>Builder: full/non-paged response
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

ok-to-test, approved, lgtm

Suggested reviewers

  • wjhuang2016
  • XuHuaiyu
  • nolouch
  • yudongusa

Poem

🐰 I nibble bytes in careful hops,
RC pages split the data crops,
From 256K to four meg's delight,
TiKV parcels through the night,
Small limits clear — I stash the bits. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: introducing a byte-budget paging framework for Resource Control in the coprocessor store module.
Description check ✅ Passed The PR description provides comprehensive information including problem statement, technical details, scope of changes, dependency updates, and test coverage. All required template sections are addressed.

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

@JmPotato JmPotato force-pushed the demo/ru-paging-size branch from 1550f30 to a2c0781 Compare April 2, 2026 02:53
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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
go.mod (1)

371-374: Document the temporary nature and release plan for forked dependencies.

Since this PR implements a coordinated multi-repository feature (RC byte-budget paging), consider adding comments in go.mod to:

  1. Explain why these forks are necessary (awaiting upstream releases with paging_size_bytes support)
  2. Reference the corresponding upstream PRs/issues
  3. Document the plan for transitioning to official releases

This will help future maintainers understand the dependency strategy and track when these can be replaced.

📝 Proposed documentation addition
 replace (
 	// Downgrade grpc to v1.63.2, as well as other related modules.
 	github.com/apache/arrow-go/v18 => github.com/joechenrh/arrow-go/v18 v18.0.0-20250911101656-62c34c9a3b82
 	github.com/go-ldap/ldap/v3 => github.com/YangKeao/ldap/v3 v3.4.5-0.20230421065457-369a3bab1117
+	// TODO: RC byte-budget paging feature - replace with official releases once available
+	// Tracking: pingcap/kvproto#1448 and related upstream changes in PD, client-go, TiKV
 	github.com/pingcap/kvproto => github.com/JmPotato/kvproto v0.0.0-20260401045836-48e3f28d9c74
 	github.com/pingcap/tidb/pkg/parser => ./pkg/parser
 	github.com/tikv/client-go/v2 => github.com/JmPotato/client-go/v2 v2.0.0-20260402023154-0eedbbb67070
 	github.com/tikv/pd/client => github.com/JmPotato/pd/client v0.0.0-20260402021839-b98ff48814c2
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go.mod` around lines 371 - 374, Add explanatory comments in go.mod next to
the replaced module lines (the github.com/pingcap/kvproto,
github.com/tikv/client-go/v2, and github.com/tikv/pd/client replacements)
stating these are temporary forks to obtain paging_size_bytes support, reference
the upstream PRs or issue URLs that add paging_size_bytes, and include a brief
transition plan (e.g., watch upstream PRs, replace forks once upstream releases
include the feature and update require/replace lines). Ensure comments mention
the intended owner/reviewer and a target to remove the forks once official
releases are available.
pkg/store/copr/coprocessor_test.go (1)

733-778: Exercise the RC wiring through BuildCopIterator.

This test seeds rcPagingSizeBytes directly into buildCopTasks, so it won't catch regressions in the actual feature wiring inside BuildCopIterator—especially the paging-vs-store-batch interaction. Please add a targeted case with RC enabled and StoreBatchSize > 0 that asserts batching is shut off while pagingSizeBytes still propagates.

Based on learnings: Applies to pkg/store/|pkg/kv/ : For storage behavior changes, perform targeted unit tests; use realtikv tests if behavior depends on real TiKV.

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

In `@pkg/store/copr/coprocessor_test.go` around lines 733 - 778, Add a test that
exercises the RC wiring via BuildCopIterator instead of seeding
rcPagingSizeBytes into buildCopTasks: create a BuildCopIterator (or call
BuildCopIterator through the same code-path used by production) with RC enabled,
set req.Paging as in the existing test, set StoreBatchSize > 0 on the iterator
options, and set rcPagingSizeBytes to paging.MaxPagingSizeBytes; assert that the
resulting iterator disables store batching (StoreBatchSize behavior or
equivalent flag is off) while the iterator or its underlying cop-task still has
paging == true and pagingSizeBytes == paging.MaxPagingSizeBytes; use the same
helpers (e.g., buildCopRanges, NewRegionCache/pd client bootstrapping) and
mirror assertions from TestBuildCopTasksWithRCPagingSizeBytes so regressions in
the BuildCopIterator wiring are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@go.mod`:
- Around line 371-374: go.mod currently redirects core modules
(github.com/pingcap/kvproto, github.com/tikv/client-go/v2,
github.com/tikv/pd/client) to a personal JmPotato fork which mismatches versions
in DEPS.bzl; to fix, restore these replace directives to the official upstream
module versions (or remove them), then regenerate DEPS.bzl by running make
bazel_prepare so Bazel and Go use the same versions; if the fork was
intentionally used for testing, document that fact in the PR and ensure you
coordinate upstream releases before merging so the temporary forked replaces are
removed prior to production.

In `@pkg/store/copr/coprocessor.go`:
- Around line 142-156: The code checks checkStoreBatchCopr(req) before
rcPagingEligible(req) can flip req.Paging.Enable, allowing RC-eligible DAG
requests to incorrectly keep StoreBatchSize > 0; after rcPagingEligible(req)
forces paging on, re-run the store-batch gate and clear batching when paging was
enabled (i.e., call checkStoreBatchCopr(req) or explicitly set
req.StoreBatchSize = 0 if req.Paging.Enable was turned on by rcPagingEligible)
so newBatchTaskBuilder never receives a request that has both paging forced by
RC and a positive StoreBatchSize; update the logic around checkStoreBatchCopr,
rcPagingEligible, req.Paging.Enable, and StoreBatchSize accordingly.

---

Nitpick comments:
In `@go.mod`:
- Around line 371-374: Add explanatory comments in go.mod next to the replaced
module lines (the github.com/pingcap/kvproto, github.com/tikv/client-go/v2, and
github.com/tikv/pd/client replacements) stating these are temporary forks to
obtain paging_size_bytes support, reference the upstream PRs or issue URLs that
add paging_size_bytes, and include a brief transition plan (e.g., watch upstream
PRs, replace forks once upstream releases include the feature and update
require/replace lines). Ensure comments mention the intended owner/reviewer and
a target to remove the forks once official releases are available.

In `@pkg/store/copr/coprocessor_test.go`:
- Around line 733-778: Add a test that exercises the RC wiring via
BuildCopIterator instead of seeding rcPagingSizeBytes into buildCopTasks: create
a BuildCopIterator (or call BuildCopIterator through the same code-path used by
production) with RC enabled, set req.Paging as in the existing test, set
StoreBatchSize > 0 on the iterator options, and set rcPagingSizeBytes to
paging.MaxPagingSizeBytes; assert that the resulting iterator disables store
batching (StoreBatchSize behavior or equivalent flag is off) while the iterator
or its underlying cop-task still has paging == true and pagingSizeBytes ==
paging.MaxPagingSizeBytes; use the same helpers (e.g., buildCopRanges,
NewRegionCache/pd client bootstrapping) and mirror assertions from
TestBuildCopTasksWithRCPagingSizeBytes so regressions in the BuildCopIterator
wiring are caught.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 99dd612b-2680-493e-8272-6b0fb21125db

📥 Commits

Reviewing files that changed from the base of the PR and between 8412422 and 1550f30.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • go.mod
  • pkg/store/copr/coprocessor.go
  • pkg/store/copr/coprocessor_test.go
  • pkg/util/paging/paging.go

Comment on lines 142 to +156
if !checkStoreBatchCopr(req) {
req.StoreBatchSize = 0
}
// RC Paging: if Resource Control is enabled and the request targets a
// resource group on TiKV with a DAG type, force-enable paging and set
// a default byte budget so each page's scanned bytes are bounded.
rcPagingSizeBytes := uint64(0)
if rcPagingEligible(req) {
if !req.Paging.Enable {
req.Paging.Enable = true
req.Paging.MinPagingSize = paging.MinPagingSize
req.Paging.MaxPagingSize = paging.MinAllowedMaxPagingSize
}
rcPagingSizeBytes = paging.MaxPagingSizeBytes
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Re-run the store-batch gate after RC forces paging.

Line 142 decides whether store batching stays enabled before Line 149 can flip req.Paging.Enable for RC. That lets an RC-eligible DAG request with StoreBatchSize > 0 still enter newBatchTaskBuilder, even though checkStoreBatchCopr explicitly treats paging and batching as mutually exclusive. The first build can then take the batching path while still carrying the new RC paging budget, which undermines the RU precharge behavior this change is trying to enforce.

💡 Suggested fix
-	if !checkStoreBatchCopr(req) {
-		req.StoreBatchSize = 0
-	}
 	// RC Paging: if Resource Control is enabled and the request targets a
 	// resource group on TiKV with a DAG type, force-enable paging and set
 	// a default byte budget so each page's scanned bytes are bounded.
 	rcPagingSizeBytes := uint64(0)
 	if rcPagingEligible(req) {
 		if !req.Paging.Enable {
 			req.Paging.Enable = true
 			req.Paging.MinPagingSize = paging.MinPagingSize
 			req.Paging.MaxPagingSize = paging.MinAllowedMaxPagingSize
 		}
 		rcPagingSizeBytes = paging.MaxPagingSizeBytes
 	}
+	// Paging and store-batch are mutually exclusive. Re-evaluate after RC may
+	// have force-enabled paging.
+	if !checkStoreBatchCopr(req) {
+		req.StoreBatchSize = 0
+	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/store/copr/coprocessor.go` around lines 142 - 156, The code checks
checkStoreBatchCopr(req) before rcPagingEligible(req) can flip
req.Paging.Enable, allowing RC-eligible DAG requests to incorrectly keep
StoreBatchSize > 0; after rcPagingEligible(req) forces paging on, re-run the
store-batch gate and clear batching when paging was enabled (i.e., call
checkStoreBatchCopr(req) or explicitly set req.StoreBatchSize = 0 if
req.Paging.Enable was turned on by rcPagingEligible) so newBatchTaskBuilder
never receives a request that has both paging forced by RC and a positive
StoreBatchSize; update the logic around checkStoreBatchCopr, rcPagingEligible,
req.Paging.Enable, and StoreBatchSize accordingly.

Copy link
Copy Markdown

@pantheon-ai pantheon-ai bot left a comment

Choose a reason for hiding this comment

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

✅ Code looks good. No issues found.

@JmPotato JmPotato force-pushed the demo/ru-paging-size branch from a2c0781 to 7a480de Compare April 2, 2026 03:07
Add a new session variable `tidb_rc_paging_size_bytes` to allow
dynamically controlling the byte budget per page for RC paging via SQL.

- Default: 4MB (paging.MaxPagingSizeBytes)
- Set to 0 to disable byte-budget paging
- Supports both GLOBAL and SESSION scope

Usage:
  SET @@tidb_rc_paging_size_bytes = 4194304;  -- 4MB (default)
  SET @@tidb_rc_paging_size_bytes = 1048576;  -- 1MB
  SET @@tidb_rc_paging_size_bytes = 0;        -- disable
Signed-off-by: JmPotato <github@ipotato.me>
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 2, 2026

[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 cfzjywxk, terry1purcell 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

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/sessionctx/variable/sysvar.go (1)

2973-2974: Use tidbOptPositiveInt32 to align with the pattern for MinPagingSize and MaxPagingSize.

Line 2974 uses TidbOptInt64 with an explicit int() cast, while the similar paging-size sysvars on lines 2966 and 2970 use tidbOptPositiveInt32 with strconv.Atoi. For consistency and clarity, apply the same safe helper:

Suggested fix
 {Scope: vardef.ScopeGlobal | vardef.ScopeSession, Name: vardef.TiDBRCPagingSizeBytes, Value: strconv.Itoa(vardef.DefRCPagingSizeBytes), Type: vardef.TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt64, SetSession: func(s *SessionVars, val string) error {
-	s.RCPagingSizeBytes = int(TidbOptInt64(val, int64(vardef.DefRCPagingSizeBytes)))
+	s.RCPagingSizeBytes = tidbOptPositiveInt32(val, vardef.DefRCPagingSizeBytes)
 	return nil
 }},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/sessionctx/variable/sysvar.go` around lines 2973 - 2974, The
TiDBRCPagingSizeBytes sysvar SetSession currently uses TidbOptInt64 with an
int(...) cast; replace that with the same pattern used for
MinPagingSize/MaxPagingSize by using tidbOptPositiveInt32 together with
strconv.Atoi to parse/validate the value and assign to s.RCPagingSizeBytes,
ensuring the helper enforces positivity and 32-bit range; update the SetSession
closure for the TiDBRCPagingSizeBytes entry accordingly (referencing
TiDBRCPagingSizeBytes, SetSession, s.RCPagingSizeBytes, tidbOptPositiveInt32,
and strconv.Atoi).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/session/session.go`:
- Line 3378: Add SQL integration tests that exercise the session variable
tidb_rc_paging_size_bytes end-to-end: write tests that SET and SET GLOBAL the
variable, verify scoping (session vs global), and assert that setting it to 0
disables byte-budget paging in actual queries; mirror the structure and
assertions used in tests/integrationtest/t/sessionctx/setvar.test and cover the
behavior covered by TestBuildCopTasksWithRCPagingSizeBytes so DistSQL requests
pick up RCPagingSizeBytes from the session (the code path that reads
RCPagingSizeBytes in session.go should be exercised by these integration tests).

---

Nitpick comments:
In `@pkg/sessionctx/variable/sysvar.go`:
- Around line 2973-2974: The TiDBRCPagingSizeBytes sysvar SetSession currently
uses TidbOptInt64 with an int(...) cast; replace that with the same pattern used
for MinPagingSize/MaxPagingSize by using tidbOptPositiveInt32 together with
strconv.Atoi to parse/validate the value and assign to s.RCPagingSizeBytes,
ensuring the helper enforces positivity and 32-bit range; update the SetSession
closure for the TiDBRCPagingSizeBytes entry accordingly (referencing
TiDBRCPagingSizeBytes, SetSession, s.RCPagingSizeBytes, tidbOptPositiveInt32,
and strconv.Atoi).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 63954ddf-f0ee-4cee-b1a7-41c3f9ead908

📥 Commits

Reviewing files that changed from the base of the PR and between 7a480de and 991201f.

📒 Files selected for processing (8)
  • pkg/distsql/context/context.go
  • pkg/distsql/request_builder.go
  • pkg/kv/kv.go
  • pkg/session/session.go
  • pkg/sessionctx/vardef/tidb_vars.go
  • pkg/sessionctx/variable/session.go
  • pkg/sessionctx/variable/sysvar.go
  • pkg/store/copr/coprocessor.go

EnablePaging: vars.EnablePaging,
MinPagingSize: vars.MinPagingSize,
MaxPagingSize: vars.MaxPagingSize,
RCPagingSizeBytes: vars.RCPagingSizeBytes,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify existing test coverage for the new RC paging byte-budget variable/path.
rg -n --glob '*_test.go' 'tidb_rc_paging_size_bytes|RCPagingSizeBytes|paging_size_bytes'

# Check for integration-style SQL test coverage references (if present in repo).
rg -n --glob '*.test' --glob '*.result' 'tidb_rc_paging_size_bytes|paging_size_bytes'

Repository: pingcap/tidb

Length of output: 154


🏁 Script executed:

# Inspect the existing test to see what it covers
head -50 pkg/store/copr/coprocessor_test.go | tail -30
sed -n '733,800p' pkg/store/copr/coprocessor_test.go

# Search for RCPagingSizeBytes in session-related test files
rg -l 'RCPagingSizeBytes' pkg/session --glob '*_test.go'

# Check for integration test patterns (testdata, sqllogictests, etc.)
fd -type f -path '*/testdata*' -name '*paging*' -o -path '*/testdata*' -name '*rc*' | head -20

# Broader search for integration/SQL tests mentioning this variable
rg 'tidb_rc_paging' --glob '*.test' --glob '*.sql' --glob '*.result' --glob '*integration*'

Repository: pingcap/tidb

Length of output: 3376


🏁 Script executed:

# Find the variable definition for tidb_rc_paging_size_bytes
rg -n 'tidb_rc_paging_size_bytes|RCPagingSizeBytes' pkg/sessionctx/variable pkg/sessionctx/vardef -A 3 -B 1

# Check the session.go GetDistSQLCtx function context
sed -n '3350,3400p' pkg/session/session.go

# Search for existing integration/SQL tests in testdata
fd 'testdata' -type d | head -5
ls -la testdata/ 2>/dev/null | head -20 || echo "No testdata in root"

# Look for other RC (request-scoped) variables to see their test patterns
rg -n 'RCMaxOpenConnections|RCWriteLatencyBase' pkg/session -A 2 -B 1 | head -40

Repository: pingcap/tidb

Length of output: 5924


🏁 Script executed:

# List integration test directories
find . -type d -name testdata 2>/dev/null | head -5

# Search for .test files that might cover RC features
find . -name '*.test' -o -name '*.sql' 2>/dev/null | grep -i 'rc\|paging\|resource' | head -10

# Check if session variable tests exist for similar variables
rg -l 'SET tidb_' tests/ testdata/ --glob '*.test' 2>/dev/null | head -5

# Simpler: look for any test file mentioning variable changes
rg 'SET tidb_rc_paging_size_bytes|SET tidb_max_paging' -type f --max-count 5

# Check nearby session variables to understand test patterns
rg 'TiFlashMaxBytesBeforeExternalJoin|TiFlashMaxQueryMemoryPerNode' pkg/session/session.go -B 2 -A 2

Repository: pingcap/tidb

Length of output: 1464


🏁 Script executed:

# Check if RC paging tests exist in integration tests
rg 'rc_paging_size_bytes|RCPagingSizeBytes' tests/integrationtest/t/executor/set.test tests/integrationtest/t/sessionctx/setvar.test

# Check what's in setvar.test to understand test pattern
head -50 tests/integrationtest/t/sessionctx/setvar.test

# Search broader for any RC variable testing
rg 'tidb_rc' tests/integrationtest/ --glob '*.test' | head -20

Repository: pingcap/tidb

Length of output: 2292


Add SQL integration tests for the new session variable behavior.

Line 3378 wires tidb_rc_paging_size_bytes (a user-facing SESSION/GLOBAL variable) into DistSQL request behavior. While unit test coverage exists at the coprocessor level (TestBuildCopTasksWithRCPagingSizeBytes), SQL integration tests should validate the end-to-end variable behavior, including SET scoping and 0 disabling byte-budget paging (similar to the pattern in tests/integrationtest/t/sessionctx/setvar.test).

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

In `@pkg/session/session.go` at line 3378, Add SQL integration tests that exercise
the session variable tidb_rc_paging_size_bytes end-to-end: write tests that SET
and SET GLOBAL the variable, verify scoping (session vs global), and assert that
setting it to 0 disables byte-budget paging in actual queries; mirror the
structure and assertions used in tests/integrationtest/t/sessionctx/setvar.test
and cover the behavior covered by TestBuildCopTasksWithRCPagingSizeBytes so
DistSQL requests pick up RCPagingSizeBytes from the session (the code path that
reads RCPagingSizeBytes in session.go should be exercised by these integration
tests).

Signed-off-by: JmPotato <github@ipotato.me>
@JmPotato JmPotato force-pushed the demo/ru-paging-size branch from 2dfee7a to 2cc25e2 Compare April 2, 2026 05:41
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 2, 2026

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-linked-issue label, please provide the linked issue number on one line in the PR body, for example: Issue Number: close #123 or Issue Number: ref #456.

📖 For more info, you can check the "Contribute Code" section in the development guide.

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.

🧹 Nitpick comments (1)
DEPS.bzl (1)

8221-8246: Ensure fork references in go.mod are reverted once upstream PRs merge.

Both github.com/tikv/client-go/v2 and github.com/tikv/pd/client are currently aliased to JmPotato's forks via go.mod replace directives (lines 373-374) to support the two-phase RU pre-charge/settlement feature. When the corresponding upstream PRs are merged (client-go tikv#1936, PD tikv#10548), remove these replace directives from go.mod. DEPS.bzl will be automatically regenerated on the next make bazel_prepare run.

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

In `@DEPS.bzl` around lines 8221 - 8246, Remove the temporary go.mod replace
directives that point github.com/tikv/client-go/v2 and github.com/tikv/pd/client
to the JmPotato forks once the upstream PRs (tikv#1936 and tikv#10548) are
merged: delete the replace entries for those module paths in go.mod and then run
make bazel_prepare so DEPS.bzl (which currently contains the forked
strip_prefix/urls for com_github_jmpotato_client_go_v2 and
com_github_jmpotato_pd_client) is regenerated to reference upstream modules.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@DEPS.bzl`:
- Around line 8221-8246: Remove the temporary go.mod replace directives that
point github.com/tikv/client-go/v2 and github.com/tikv/pd/client to the JmPotato
forks once the upstream PRs (tikv#1936 and tikv#10548) are merged: delete the
replace entries for those module paths in go.mod and then run make bazel_prepare
so DEPS.bzl (which currently contains the forked strip_prefix/urls for
com_github_jmpotato_client_go_v2 and com_github_jmpotato_pd_client) is
regenerated to reference upstream modules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a5b90f6f-6068-472f-9441-002aaa7e9cbb

📥 Commits

Reviewing files that changed from the base of the PR and between 2dfee7a and 2cc25e2.

📒 Files selected for processing (2)
  • DEPS.bzl
  • pkg/store/copr/BUILD.bazel
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/store/copr/BUILD.bazel

@tiprow
Copy link
Copy Markdown

tiprow bot commented Apr 2, 2026

@JmPotato: 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
fast_test_tiprow 2cc25e2 link true /test fast_test_tiprow

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.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 2, 2026

@JmPotato: The following tests 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 2cc25e2 link true /test pull-unit-test-next-gen
idc-jenkins-ci-tidb/build 2cc25e2 link true /test build
idc-jenkins-ci-tidb/unit-test 2cc25e2 link true /test unit-test
pull-build-next-gen 2cc25e2 link true /test pull-build-next-gen
idc-jenkins-ci-tidb/check_dev 2cc25e2 link true /test check-dev
pull-integration-e2e-test 2cc25e2 link true /test pull-integration-e2e-test
idc-jenkins-ci-tidb/check_dev_2 2cc25e2 link true /test check-dev2
pull-integration-realcluster-test-next-gen 2cc25e2 link true /test pull-integration-realcluster-test-next-gen

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.

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

Labels

do-not-merge/needs-linked-issue do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant