Skip to content

tools: isolate keyspace according to the given label (#10121)#10172

Merged
ti-chi-bot[bot] merged 3 commits intotikv:release-nextgen-20251011from
ti-chi-bot:cherry-pick-10121-to-release-nextgen-20251011
Jan 22, 2026
Merged

tools: isolate keyspace according to the given label (#10121)#10172
ti-chi-bot[bot] merged 3 commits intotikv:release-nextgen-20251011from
ti-chi-bot:cherry-pick-10121-to-release-nextgen-20251011

Conversation

@ti-chi-bot
Copy link
Member

@ti-chi-bot ti-chi-bot commented Jan 20, 2026

This is an automated cherry-pick of #10121

What problem does this PR solve?

Issue Number: ref #10122

What is changed and how does it work?

Check List

Tests

  • Unit test

Release note

None.

Summary by CodeRabbit

  • New Features
    • Added keyspace range viewing functionality supporting both raw and transactional key bounds.
    • Added placement rule management for keyspaces with set and revert operations.
    • Added support for multiple label constraints (zone, disk) on placement rules.
    • Added TiFlash compatibility for keyspace placement configurations.

✏️ Tip: You can customize this high-level summary in your review settings.

ref tikv#10122

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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. type/cherry-pick-for-release-nextgen-20251011 labels Jan 20, 2026
@ti-chi-bot
Copy link
Member Author

@rleungx This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2026

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

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 ti-community-infra/tichi repository.

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

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.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes introduce a new HTTP API method for deleting placement rule bundles by group in the client library, add CLI subcommands for managing keyspace placement rules and viewing key ranges in pd-ctl, and provide comprehensive test coverage for keyspace placement functionality.

Changes

Cohort / File(s) Summary
HTTP Client API
client/http/interface.go, client/http/request_info.go
Added new public method DeletePlacementRuleBundleByGroup to Client interface and corresponding constant for the named operation to support deletion of placement rule bundles by group.
CLI Keyspace Placement Management
tools/pd-ctl/pdctl/command/keyspace_command.go
Introduced new range subcommand with options to display key ranges (raw/transactional) in JSON format, and set-placement/revert-placement subcommands to manage placement rules. Added internal helpers for label constraint parsing, key range generation, placement rule bundle construction, and PD client invocation.
CLI Keyspace Command Tests
tools/pd-ctl/pdctl/command/keyspace_command_test.go
New unit test TestMakeKeyRanges validating that keyspace.MakeKeyRanges generates correct raw and transactional key range pairs with proper encoding for given keyspace IDs.
Server-Side Keyspace Tests
tests/server/keyspace/keyspace_test.go
Refactored test to replace manual keyspace bound computation with keyspace.MakeRegionBound helper and updated assertions to validate hex-encoded bound fields.
Integration Keyspace Placement Tests
tools/pd-ctl/tests/keyspace/keyspace_test.go
Comprehensive new test suite covering placement rule workflows: set-placement with single/multiple label constraints, revert-placement verification, and TiFlash coexistence scenarios. Tests validate rule bundle creation, group management, region key ranges, and proper rule application.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • JmPotato
  • lhy1024

Poem

🐰 Placement rules now dance in the CLI's embrace,
With bundles to delete and key ranges to trace,
Labels constrain, TiFlash learns to coexist,
Keyspace placement workflows—none should be missed!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% 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 describes the main objective of the PR: adding keyspace isolation functionality based on labels through new CLI commands and placement rules.
Description check ✅ Passed The description follows the required template with Issue Number, Check List, and Release note sections completed. However, the 'What is changed and how does it work?' section lacks detail about the implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@rleungx
Copy link
Member

rleungx commented Jan 21, 2026

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

✅ Actions performed

Full review triggered.

@rleungx
Copy link
Member

rleungx commented Jan 21, 2026

/hold cancel

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 21, 2026
Copy link

@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

🤖 Fix all issues with AI agents
In `@tools/pd-ctl/pdctl/command/keyspace_command.go`:
- Around line 472-486: Replace the current fmt.Sscanf parsing of keyspaceIDStr
with strconv.ParseUint(keyspaceIDStr, 10, 32) in both setPlacementCommandFunc
and revertPlacementCommandFunc so parsing enforces 32-bit width (preventing
wraparound); on error, print the parse error via cmd.PrintErrf and return, then
safely cast the parsed uint64 result to uint32 (e.g., uint32(parsed)) and
continue to perform the existing bounds check against
constants.DefaultKeyspaceID and constants.MaxKeyspaceID.
🧹 Nitpick comments (1)
tools/pd-ctl/pdctl/command/keyspace_command.go (1)

523-534: Consider surfacing replica count as a flag.
There’s a TODO to make Count configurable; adding a CLI flag (or documenting a follow‑up) would close the loop.

If you want, I can draft a flag-based implementation and tests.

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@rleungx
Copy link
Member

rleungx commented Jan 21, 2026

/retest

@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 49.73822% with 96 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.61%. Comparing base (14fe15c) to head (cd10b3c).
⚠️ Report is 2 commits behind head on release-nextgen-20251011.

❌ Your patch status has failed because the patch coverage (49.73%) is below the target coverage (74.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           release-nextgen-20251011   #10172      +/-   ##
============================================================
- Coverage                     78.73%   78.61%   -0.12%     
============================================================
  Files                           491      491              
  Lines                         66124    66320     +196     
============================================================
+ Hits                          52060    52136      +76     
- Misses                        10308    10417     +109     
- Partials                       3756     3767      +11     
Flag Coverage Δ
unittests 78.61% <49.73%> (-0.12%) ⬇️

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 needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 22, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 22, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-22 02:46:20.822046149 +0000 UTC m=+634808.436003015: ☑️ agreed by bufferflies.
  • 2026-01-22 03:10:55.183485569 +0000 UTC m=+636282.797442435: ☑️ agreed by lhy1024.

@ti-chi-bot ti-chi-bot bot added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Jan 22, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bufferflies, lhy1024, rleungx

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:
  • OWNERS [bufferflies,lhy1024,rleungx]

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 merged commit 17478bb into tikv:release-nextgen-20251011 Jan 22, 2026
33 of 37 checks passed
@ti-chi-bot ti-chi-bot bot deleted the cherry-pick-10121-to-release-nextgen-20251011 branch January 22, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. dco-signoff: yes Indicates the PR's author has signed the dco. lgtm 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. type/cherry-pick-for-release-nextgen-20251011

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants