Skip to content

[DNM] test rate-limited Leader return to a restarted TiKV store - #11160

Draft
exit-code-1 wants to merge 2 commits into
tikv:masterfrom
exit-code-1:zhy/test-5774-target-leader-return-rate-limit
Draft

[DNM] test rate-limited Leader return to a restarted TiKV store#11160
exit-code-1 wants to merge 2 commits into
tikv:masterfrom
exit-code-1:zhy/test-5774-target-leader-return-rate-limit

Conversation

@exit-code-1

@exit-code-1 exit-code-1 commented Aug 19, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Warning

DNM / test-only / do not merge. This branch exists only for staging experiments for tidbcloud/cloud-storage-engine#5774.

Issue Number: N/A (DNM test PR)

After a TiKV restart and removal of evict-leader, automatic leader balancing can return many Leaders to the restarted target Store in a short interval. This makes it hard to separate delayed admission from paced admission when measuring cold working-set/runtime I/O, Prewrite latency, business tail latency, and QPS.

What is changed and how does it work?

Add an opt-in leaders-per-second token bucket to balance-leader-scheduler, keyed by target store ID.

Keep the default unlimited, persist and hot-reload the per-target settings, expose exact readback, and add pd-ctl set/delete commands. Fix burst at one Leader so a configured target cannot receive a scheduler batch at once.

Configuration example:

pd-ctl scheduler config balance-leader-scheduler \
  set-inbound-leader-transfer-rate 42 2

pd-ctl scheduler config balance-leader-scheduler show

pd-ctl scheduler config balance-leader-scheduler \
  delete-inbound-leader-transfer-rate 42

Readback for the example:

{
  "inbound-leader-transfer-rate-limits": {
    "42": {
      "leaders-per-second": 2,
      "burst": 1
    }
  }
}

Semantics and scope:

  • Unit: successfully constructed automatic balance-leader transfer operators per second, aggregated by target store_id.
  • Burst is fixed at 1. A newly configured target starts with one token; updates preserve bucket state; deletion restores unlimited behavior immediately.
  • The default is fully disabled: an absent target Store entry follows existing behavior.
  • Only balance-leader-scheduler automatic transfers are limited. Manual admin-transfer-leader, scatter/balance-range, hot-region, label/rule-checker, evict/grant/shuffle, and witness transfer paths bypass this test limiter.
  • Both PD monolith and scheduling service/MCS use the same scheduler implementation. Scheduler config persists through the existing PD scheduler-config storage, and the MCS watcher reload path is covered by unit tests.
  • Normal scheduling consumes target tokens even when diagnostic plan collection is enabled. Only an explicit diagnostic dry run bypasses token consumption.
  • Failed/duplicate candidate construction does not consume tokens. A unique operator is charged when returned by the scheduler; later waiting-queue rejection or cancellation is not refunded, and normal token refill continues.
  • No TiKV Raft message is dropped and no existing Leader, Region, or peer state is mutated by limiter rejection.

Staging comparison:

  1. Delayed return: keep evict-leader until the readiness/I/O gate, then remove it with no per-target rate entry.
  2. Delayed bulk return: same gate, then allow the current balance-leader scheduler speed without the limiter.
  3. Delayed paced return: set the target Store rate before removing evict-leader, then verify readback and observe Leader count, runtime I/O, Prewrite/tail latency, and QPS.

This PR does not start or submit any staging/TCMS execution.

Check List

Tests

  • Unit test
    • default unlimited and per-target isolation
    • dynamic set/update/delete and persisted readback
    • token refill and fixed burst
    • diagnostic-enabled executable scheduling versus explicit dry-run behavior
    • persistence-failure rollback for set/update/delete
    • failed candidate and cancellation behavior
    • scheduler-level same-window target limiting
    • scheduling-service watcher ReloadConfig path
  • Manual test
    • make pd-ctl
    • pd-ctl command help/readback shape

Code changes

  • Has the configuration change
  • Has HTTP APIs changed
  • Has persistent data change

Side effects

  • Increased code complexity

Validation

  • make gotest GOTEST_ARGS=\"./pkg/schedule/schedulers -count=1\"
  • make gotest GOTEST_ARGS=\"./pkg/schedule/schedulers -run TestInboundLeaderTransferRateLimit -count=1\"
  • make gotest GOTEST_ARGS="./pkg/schedule/schedulers -run TestBalanceLeaderInboundTargetRateLimit -count=1"
  • GOTOOLCHAIN=go1.25.12 go test -race ./pkg/schedule/schedulers -run TestBalanceLeaderInboundTargetRateLimit -count=1
  • root scheduler-package golangci-lint: 0 issues
  • tools-module make static GO_EFFECTIVE_TOOLCHAIN=go1.25.12: 0 issues
  • GOTOOLCHAIN=go1.25.12 go test ./pd-ctl/pdctl/command -count=1
  • make pd-ctl
  • git diff --check

Release note

None.

Add a disabled-by-default per-target token bucket to the balance-leader
scheduler for staging experiments. Expose persistent runtime configuration
and pd-ctl commands with a fixed burst of one leader.

Signed-off-by: Zhang Haoyuan <20194550@qq.com>
@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Aug 19, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

[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 zhouqiang-cl 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 dco-signoff: yes Indicates the PR's author has signed the dco. 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 Aug 19, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Hi @exit-code-1. 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.

@coderabbitai

coderabbitai Bot commented Aug 19, 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: a37e55ce-8cff-47d8-9b70-78855415aaaf

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

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 19, 2026
Keep diagnostic plan collection separate from a true dry run so normal scheduling always consumes target-store tokens. Roll back runtime configuration and return an error when persistence fails.

Signed-off-by: Zhang Haoyuan <20194550@qq.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 19, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

[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, multiple issues should use full syntax for each issue and be separated by a comma, like: Issue Number: close #123, ref #456.

📖 For more info, you can check the "Linking issues" section in the CONTRIBUTING.md.

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/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. 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