Skip to content

Conversation

@lhy1024
Copy link
Contributor

@lhy1024 lhy1024 commented Dec 10, 2025

What problem does this PR solve?

Issue Number: Ref #9764

What is changed and how does it work?

Check List

Tests

  • Unit test

Release note

None.

@ti-chi-bot ti-chi-bot bot added 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 Dec 10, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 10, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 10, 2025
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 79.08847% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.49%. Comparing base (27c2705) to head (6653ab5).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10041      +/-   ##
==========================================
+ Coverage   78.40%   78.49%   +0.09%     
==========================================
  Files         511      513       +2     
  Lines       68415    68893     +478     
==========================================
+ Hits        53644    54081     +437     
- Misses      10876    10899      +23     
- Partials     3895     3913      +18     
Flag Coverage Δ
unittests 78.49% <79.08%> (+0.09%) ⬆️

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.

Signed-off-by: lhy1024 <admin@liudos.us>
@lhy1024 lhy1024 marked this pull request as ready for review December 11, 2025 10:05
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 11, 2025
Signed-off-by: lhy1024 <admin@liudos.us>
@lhy1024
Copy link
Contributor Author

lhy1024 commented Dec 11, 2025

/retest

1 similar comment
@lhy1024
Copy link
Contributor Author

lhy1024 commented Dec 12, 2025

/retest


// IsStable indicates that the Group has completed the required scheduling and is currently in a stable state.
func (s *AffinityGroupState) IsStable() bool {
return s.Phase == "stable"
Copy link
Member

Choose a reason for hiding this comment

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

The phase name is strange, but we can rename it later.

Copy link
Member

Choose a reason for hiding this comment

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

It is public. Can we rename it in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so

Copy link
Member

Choose a reason for hiding this comment

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

I means "Can" we update it?

router.PATCH("", BatchModifyAffinityGroups)
router.PUT("/:group_id", UpdateAffinityGroupPeers)
router.DELETE("/:group_id", DeleteAffinityGroup)
router.POST("/batch-delete", BatchDeleteAffinityGroups)
Copy link
Member

Choose a reason for hiding this comment

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

not meet the RESTful requirement

Copy link
Contributor Author

@lhy1024 lhy1024 Dec 12, 2025

Choose a reason for hiding this comment

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

The primary reason is that we want to perform batch deletions within a single transaction, but the DELETE does not support carrying a body.

And I found that there is also "/config/rules/batch" and "/regions/accelerate-schedule/batch", so I chose a similar path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lhy1024 lhy1024 requested a review from rleungx December 12, 2025 06:05
Signed-off-by: lhy1024 <admin@liudos.us>

// IsStable indicates that the Group has completed the required scheduling and is currently in a stable state.
func (s *AffinityGroupState) IsStable() bool {
return s.Phase == "stable"
Copy link
Member

Choose a reason for hiding this comment

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

I means "Can" we update it?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive API and client support for affinity groups, which allow managing key ranges with specific peer placement requirements for region scheduling. The feature enables users to group key ranges together and control their leader and voter store placement through a RESTful API.

Key Changes

  • Adds complete REST API endpoints for affinity group management (create, get, update, delete, batch operations)
  • Implements HTTP client methods for all affinity group operations
  • Adds middleware to check if affinity scheduling is enabled before processing requests
  • Includes comprehensive test coverage for API handlers and client integration

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
server/apiv2/router.go Registers affinity group API handlers with the v2 router
server/apiv2/middlewares/affinity_enabled_checker.go New middleware to block requests when affinity scheduling is disabled
server/apiv2/handlers/affinity.go Complete handler implementation for all affinity group API endpoints including create, get, update, delete, and batch modify operations
client/http/types.go Defines client-side types for affinity group operations and responses
client/http/interface.go Adds affinity group methods to the HTTP client interface and implements all operations
client/http/api.go Adds API endpoint path constants for affinity groups
pkg/utils/apiutil/apiutil.go Adds PutJSON utility function for PUT requests
pkg/utils/testutil/api_check.go Adds CheckPutJSON helper for testing PUT endpoints
tests/server/apiv2/handlers/affinity_test.go Comprehensive test suite covering all affinity group operations, error cases, and edge cases
tests/integrations/client/http_client_test.go Integration tests for the HTTP client affinity group methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: lhy1024 <admin@liudos.us>
Signed-off-by: lhy1024 <admin@liudos.us>

// Convert internal manager output to API output.
resp := AffinityGroupsResponse{
AffinityGroups: make(map[string]*affinity.GroupState, len(req.AffinityGroups)),
Copy link
Member

Choose a reason for hiding this comment

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

Just a question. Is it necessary to return complete Group information?

Copy link
Member

Choose a reason for hiding this comment

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

Will we use it?

Copy link
Member

Choose a reason for hiding this comment

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

In the future, we will be able to include the correct StoreIDs in the return value of Create, which will help tidb update the cache faster.

Signed-off-by: lhy1024 <admin@liudos.us>
@lhy1024
Copy link
Contributor Author

lhy1024 commented Dec 12, 2025

@okJiang @rleungx PTAL

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 12, 2025
@ti-chi-bot ti-chi-bot bot added the lgtm label Dec 12, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: okJiang, 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:

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

ti-chi-bot bot commented Dec 12, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-12-12 11:33:11.489830316 +0000 UTC m=+1213536.303607889: ☑️ agreed by okJiang.
  • 2025-12-12 11:39:26.396730655 +0000 UTC m=+1213911.210508217: ☑️ agreed by rleungx.

@ti-chi-bot ti-chi-bot bot merged commit 09f1b5d into tikv:master Dec 12, 2025
31 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Dec 12, 2025
ref tikv#9764

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #10058.
But this PR has conflicts, please resolve them!

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 12, 2025

@lhy1024: 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
pull-unit-test-next-gen-2 6653ab5 link unknown /test pull-unit-test-next-gen-2

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.

lhy1024 added a commit to lhy1024/pd that referenced this pull request Dec 13, 2025
ref tikv#9764

Signed-off-by: lhy1024 <admin@liudos.us>
HunDunDM pushed a commit to HunDunDM/pd that referenced this pull request Dec 13, 2025
lhy1024 added a commit to lhy1024/pd that referenced this pull request Dec 14, 2025
ref tikv#9764

Signed-off-by: lhy1024 <admin@liudos.us>
lhy1024 added a commit to lhy1024/pd that referenced this pull request Dec 14, 2025
ref tikv#9764

Signed-off-by: lhy1024 <admin@liudos.us>
lhy1024 added a commit to lhy1024/pd that referenced this pull request Dec 16, 2025
ref tikv#9764

Signed-off-by: lhy1024 <admin@liudos.us>
lhy1024 added a commit to lhy1024/pd that referenced this pull request Dec 16, 2025
ref tikv#9764

Signed-off-by: lhy1024 <admin@liudos.us>
lhy1024 added a commit to lhy1024/pd that referenced this pull request Dec 16, 2025
ref tikv#9764

Signed-off-by: lhy1024 <admin@liudos.us>
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. lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. 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.

5 participants