Skip to content

resource_group client: prevent NaN in zero-duration calcAvg (#11023)#11029

Open
JmPotato wants to merge 1 commit into
tikv:release-nextgen-202603from
JmPotato:codex/cherry-pick-11023-nextgen
Open

resource_group client: prevent NaN in zero-duration calcAvg (#11023)#11029
JmPotato wants to merge 1 commit into
tikv:release-nextgen-202603from
JmPotato:codex/cherry-pick-11023-nextgen

Conversation

@JmPotato

Copy link
Copy Markdown
Member

This is a cherry-pick of #11023 to release-nextgen-202603.

What problem does this PR solve?

Issue Number: ref #11022, ref #9455

What is changed and how does it work?

The target branch already contains the non-positive duration guard from #10866.
This cherry-pick preserves that shared implementation and applies the remaining
source behavior plus regression coverage.

Update the burstable state before sampling so a zero-duration sample does not
delay it. Add a regression test covering the creation race, finite
moving-average values, resumed sampling, and the burstable state update.

Check List

Tests

  • Unit test

Release note

Fix the issue that the resource group client might permanently send `NaN` token requests when a newly created resource group controller races with the periodic state update.

…s zero

A freshly created groupCostController can be published between the
updateRunState and updateAvgRequestResourcePerSec passes of the same tick,
in which case gc.run.now still equals the avgLastTime set by initRunState
and calcAvg computes (0-0)/0 = NaN, permanently poisoning avgRUPerSec and
making every subsequent token-bucket request carry required-token=NaN
until the idle cleanup deletes the controller.

Skip the sample when the elapsed duration is non-positive, and update the
burstable flag before sampling so a skipped sample does not delay it.
Add a regression test covering the exact scenario.

Signed-off-by: JmPotato <github@ipotato.me>
(cherry picked from commit f2bcfc2)
Signed-off-by: JmPotato <github@ipotato.me>
@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. dco-signoff: yes Indicates the PR's author has signed the dco. labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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

Run ID: e1f06262-a2b0-4c57-826f-43bb5f8b16a3

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

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.14%. Comparing base (0543310) to head (d743c2d).

Additional details and impacted files
@@                    Coverage Diff                     @@
##           release-nextgen-202603   #11029      +/-   ##
==========================================================
- Coverage                   79.19%   79.14%   -0.05%     
==========================================================
  Files                         532      532              
  Lines                       72818    72818              
==========================================================
- Hits                        57665    57632      -33     
- Misses                      11118    11140      +22     
- Partials                     4035     4046      +11     
Flag Coverage Δ
unittests 79.14% <100.00%> (-0.05%) ⬇️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 21, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

[LGTM Timeline notifier]

Timeline:

  • 2026-07-21 02:44:54.037371335 +0000 UTC m=+1286480.073466381: ☑️ agreed by lhy1024.

@ti-chi-bot

ti-chi-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lhy1024

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 the approved label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

2 participants