Skip to content

session: use resource group runtime state for paging#69633

Merged
ti-chi-bot[bot] merged 1 commit into
pingcap:masterfrom
JmPotato:codex/rc-effective-hard-limit
Jul 15, 2026
Merged

session: use resource group runtime state for paging#69633
ti-chi-bot[bot] merged 1 commit into
pingcap:masterfrom
JmPotato:codex/rc-effective-hard-limit

Conversation

@JmPotato

@JmPotato JmPotato commented Jul 3, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #68085, tikv/pd#10612

Problem Summary:

PD resource control now exposes whether the runtime request-unit token bucket has a limited burst. TiDB's tidb_paging_size_bytes gate still depended only on the static resource-group metadata in InfoSchema, so it could miss limited-burst settings produced by service-limit override logic.

The required PD/client-go versions and TiDB mock compatibility are already present on master through #67941, so this PR now only changes the session-side paging gate.

What changed and how does it work?

  • Makes GetDistSQLCtx prefer ResourceGroupsController.GetResourceGroupRuntimeState().HasLimitedBurst when deciding whether tidb_paging_size_bytes can be forwarded.
  • Falls back to the existing InfoSchema burst-limit check while the runtime state is not available yet.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Unit test and static checks:

./tools/check/failpoint-go-test.sh pkg/session -run TestDistSQLCtxPagingSizeBytesRequiresHardCappedResourceGroup -count=1
make lint
git diff --check upstream/master...HEAD

Real TiKV E2E verification (temporary local regression test):

  1. Started a tiup playground v8.5.4 --mode tikv-slim cluster with a locally built PD and a real TiKV store.
  2. Set PD's keyspace service limit to 100. InfoSchema still reported the default resource group as BURSTABLE = UNLIMITED, while the runtime state converged to HasLimitedBurst = true.
  3. Set tidb_paging_size_bytes = 4194304 and captured the actual outbound coprocessor.Request at onBeforeSendReqCtx.
  4. Ran the same test against master and this PR:
./tools/check/failpoint-go-test.sh tests/realtikvtest/sessiontest -run '^TestPagingSizeBytesUsesRuntimeLimitedBurst$' -count=1
Revision Runtime state Outbound PagingSizeBytes Result
upstream/master (52f7a7a3e6) HasLimitedBurst = true 0 FAIL (expected 4194304)
This PR (f60f3384cd) HasLimitedBurst = true 4194304 PASS

This verifies the complete path from PD's runtime service-limit override through TiDB's resource-group runtime state to the outbound Cop RPC. It does not verify TiKV server-side page truncation/resume behavior because the stock TiKV v8.5.4 binary does not implement this request field.

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

Release note

Fix the tidb_paging_size_bytes gating so Resource Control limited-burst state reported by PD is recognized before falling back to static resource-group metadata.

Summary by CodeRabbit

  • Bug Fixes
    • Improved resource-control paging behavior by consistently applying resource-group burst-limit settings.
    • Prevented paging configuration from being enabled when the associated resource group is unavailable or does not permit it.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 94ecc153-77de-4da6-8f90-39bcc930c391

📥 Commits

Reviewing files that changed from the base of the PR and between 1a72eaa and 2050776.

📒 Files selected for processing (1)
  • pkg/session/session.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/session/session.go

📝 Walkthrough

Walkthrough

GetDistSQLCtx now delegates resource-control paging eligibility to resourceGroupAllowsPagingSizeBytes. The helper rejects missing context, prefers runtime controller state, and falls back to infoschema burst-limit data.

Changes

Resource group paging eligibility

Layer / File(s) Summary
Session resource group paging helper
pkg/session/session.go
GetDistSQLCtx uses resourceGroupAllowsPagingSizeBytes, which checks runtime HasLimitedBurst state before falling back to infoschema burst-limit data.

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

Possibly related PRs

  • pingcap/tidb#68091: Adds paging-size plumbing and resource-control burstability gating related to this session eligibility logic.

Poem

A rabbit checks the bursty gate,
With runtime paws and schemas straight.
Missing paths make paging cease,
Known burst limits grant release.
Hop, hop—DistSQL flows with grace!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: session paging now uses resource group runtime state.
Description check ✅ Passed The description matches the template with issue, problem summary, change details, checklist, and release note, plus test and impact info.
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 added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 3, 2026
@JmPotato JmPotato force-pushed the codex/rc-effective-hard-limit branch from a71b708 to 23f168d Compare July 3, 2026 06:36

@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)
pkg/session/session.go (1)

3552-3563: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add unit test coverage for the new paging helper.

resourceGroupAllowsPagingSizeBytes is a pure function with three distinct branches (nil/empty guard, runtime-state path, infoschema fallback) implementing the exact behavior this PR is meant to fix. A focused unit test exercising each branch would guard against regressions in this hard-limit detection logic.

🤖 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 `@pkg/session/session.go` around lines 3552 - 3563, Add focused unit tests for
resourceGroupAllowsPagingSizeBytes to cover all three branches: the nil/empty
guard, the ResourceGroupsController runtime-state path, and the InfoSchema
fallback. Use the function name resourceGroupAllowsPagingSizeBytes and the
Domain/ResourceGroupsController/GetResourceGroupRuntimeState/InfoSchema.ResourceGroupByName
paths to build table-driven cases that assert the expected boolean result for
each scenario.
🤖 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 `@pkg/session/session.go`:
- Around line 3552-3563: Add focused unit tests for
resourceGroupAllowsPagingSizeBytes to cover all three branches: the nil/empty
guard, the ResourceGroupsController runtime-state path, and the InfoSchema
fallback. Use the function name resourceGroupAllowsPagingSizeBytes and the
Domain/ResourceGroupsController/GetResourceGroupRuntimeState/InfoSchema.ResourceGroupByName
paths to build table-driven cases that assert the expected boolean result for
each scenario.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 45c5e12d-58be-4f33-b7e6-c4df9a4a82d0

📥 Commits

Reviewing files that changed from the base of the PR and between 8be4bd0 and a71b708.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • DEPS.bzl
  • go.mod
  • pkg/domain/infosync/BUILD.bazel
  • pkg/domain/infosync/resource_manager_client.go
  • pkg/executor/adapter_internal_test.go
  • pkg/session/session.go
  • pkg/store/mockstore/unistore/pd.go

@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)
pkg/session/session.go (1)

3552-3563: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a comment explaining the hard-limit/paging rationale.

The logic here is non-obvious: paging is only allowed when the resource group has a limited (hard-capped) burst — state.HasLimitedBurst or GetBurstLimitAdjusted() >= 0 — and disabled when the group is unlimited. Without context, a reader could easily assume the opposite (that an unlimited group would allow larger paging). A short comment on why hard-capped burst is required to safely enable paging (and why runtime state is preferred over InfoSchema) would aid future maintainers.

📝 Proposed comment addition
+// resourceGroupAllowsPagingSizeBytes reports whether paging can be enabled for the given
+// resource group. Paging is only safe when the group has a hard-capped (limited) burst,
+// since an unlimited-burst group may not enforce the same throttling contract that paging
+// relies on. Runtime resource-group state is preferred; InfoSchema's static burst-limit
+// metadata is used as a fallback until runtime state is available (e.g. right after group
+// creation or a service-limit override).
 func resourceGroupAllowsPagingSizeBytes(dom *domain.Domain, resourceGroupName string) bool {

Based on coding guidelines: "Comments SHOULD explain non-obvious intent, constraints, invariants, concurrency guarantees, SQL/compatibility contracts, or important performance trade-offs."

🤖 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 `@pkg/session/session.go` around lines 3552 - 3563, Add a short explanatory
comment in resourceGroupAllowsPagingSizeBytes clarifying that paging is only
enabled for resource groups with a hard-limited burst (state.HasLimitedBurst or
GetBurstLimitAdjusted() >= 0), not for unlimited groups. Mention that the
runtime state from ResourceGroupsController is preferred when available because
it reflects the current effective limit, with InfoSchema used only as a
fallback.

Source: Coding guidelines

🤖 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 `@pkg/session/session.go`:
- Around line 3552-3563: Add a short explanatory comment in
resourceGroupAllowsPagingSizeBytes clarifying that paging is only enabled for
resource groups with a hard-limited burst (state.HasLimitedBurst or
GetBurstLimitAdjusted() >= 0), not for unlimited groups. Mention that the
runtime state from ResourceGroupsController is preferred when available because
it reflects the current effective limit, with InfoSchema used only as a
fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5ea9a75c-7b3f-40a0-be55-9d52fa63001f

📥 Commits

Reviewing files that changed from the base of the PR and between a71b708 and 23f168d.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • DEPS.bzl
  • go.mod
  • pkg/domain/infosync/BUILD.bazel
  • pkg/domain/infosync/resource_manager_client.go
  • pkg/executor/adapter_internal_test.go
  • pkg/session/session.go
  • pkg/store/mockstore/unistore/pd.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • pkg/domain/infosync/BUILD.bazel
  • pkg/executor/adapter_internal_test.go
  • pkg/domain/infosync/resource_manager_client.go
  • go.mod
  • pkg/store/mockstore/unistore/pd.go
  • DEPS.bzl

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.0014%. Comparing base (1750c20) to head (2050776).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69633        +/-   ##
================================================
- Coverage   76.3186%   74.0014%   -2.3172%     
================================================
  Files          2041       2056        +15     
  Lines        560073     578302     +18229     
================================================
+ Hits         427440     427952       +512     
- Misses       131732     150027     +18295     
+ Partials        901        323       -578     
Flag Coverage Δ
integration 40.7549% <50.0000%> (+1.0497%) ⬆️

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

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 47.4060% <ø> (-15.3154%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JmPotato JmPotato force-pushed the codex/rc-effective-hard-limit branch from 23f168d to b9c93dd Compare July 9, 2026 03:42
@JmPotato JmPotato force-pushed the codex/rc-effective-hard-limit branch 2 times, most recently from 1a72eaa to a6a551e Compare July 9, 2026 07:13
@JmPotato

JmPotato commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

/retest

@JmPotato JmPotato force-pushed the codex/rc-effective-hard-limit branch from a6a551e to f60f338 Compare July 10, 2026 03:07
@ti-chi-bot ti-chi-bot Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 10, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

@YuhaoZhang00: 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.

@YuhaoZhang00

Copy link
Copy Markdown
Contributor

/retest

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 10, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, rleungx, YuhaoZhang00

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 14, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-10 06:06:16.085252031 +0000 UTC m=+348162.121347087: ☑️ agreed by rleungx.
  • 2026-07-14 07:35:13.011505986 +0000 UTC m=+699099.047601042: ☑️ agreed by cfzjywxk.

@JmPotato

Copy link
Copy Markdown
Member Author

/test check-dev

Signed-off-by: JmPotato <github@ipotato.me>
@JmPotato JmPotato force-pushed the codex/rc-effective-hard-limit branch from f60f338 to 2050776 Compare July 15, 2026 03:34
@JmPotato

Copy link
Copy Markdown
Member Author

/test check-dev2

@ti-chi-bot ti-chi-bot Bot merged commit 10292a4 into pingcap:master Jul 15, 2026
34 checks passed
@JmPotato JmPotato deleted the codex/rc-effective-hard-limit branch July 15, 2026 07:41
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jul 15, 2026
ref pingcap#68085

(cherry picked from commit 10292a4)
Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jul 15, 2026
ref pingcap#68085

(cherry picked from commit 10292a4)
Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jul 16, 2026
ref pingcap#68085

(cherry picked from commit 10292a4)
Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added a commit to JmPotato/tidb that referenced this pull request Jul 16, 2026
ref pingcap#68085

(cherry picked from commit 10292a4)
Signed-off-by: JmPotato <github@ipotato.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

4 participants