Skip to content

meta-service-group: add status#10904

Open
bufferflies wants to merge 3 commits into
tikv:masterfrom
bufferflies:pr-cp-10889-meta-service-group-status
Open

meta-service-group: add status#10904
bufferflies wants to merge 3 commits into
tikv:masterfrom
bufferflies:pr-cp-10889-meta-service-group-status

Conversation

@bufferflies

@bufferflies bufferflies commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: Close #10889

CP from 5be7eae (original PR #392).

Original author: @AmoebaProtozoa.

What is changed and how does it work?

meta-service-group: add status

Add persisted meta-service group status with assignment count and enabled state. Only enabled meta-service groups are eligible for keyspace assignment, the HTTP v2 API returns the full status, and pd-ctl can patch enabled state or assignment count through the status endpoint.

Check List

Tests

  • Unit test

Code changes

Related changes

  • Need to cherry-pick to the release branch

Validation:

  • GOFLAGS=-buildvcs=false go test ./pkg/keyspace ./pkg/storage ./server/apiv2/handlers -run 'TestMetaServiceGroup|TestNonExistent' -count=1 -timeout=5m
  • GOFLAGS=-buildvcs=false go test ./tests/server/apiv2/handlers -run TestMetaServiceGroupTestSuite -count=1 -timeout=5m
  • cd tools/pd-ctl && GOFLAGS=-buildvcs=false go test ./pdctl/command -run TestNonExistent -count=0 -timeout=5m
  • git diff --check
  • GOFLAGS=-buildvcs=false make check

Release note

None.

Summary by CodeRabbit

  • New Features
    • Added persistent meta-service group status management (enabled + assignment count) and updated group status listing.
    • Added PATCH /meta-service-groups/:id/status to update group status.
    • Added pd-ctl meta-service-group subcommands: set-enabled and set-assignment-count.
  • Changes
    • API responses now include a per-group status object (enabled + assignment count); assignment selection respects enabled/assignment count.
    • Improved validation/error behavior for unknown groups and invalid assignment counts.
  • Tests
    • Updated API, storage, and CLI tests to cover the new status model and enablement semantics.

* add enable status

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>

* Update pkg/keyspace/meta_service_group.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update pkg/keyspace/meta_service_group.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update tests/server/apiv2/handlers/testutil.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix typo

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>

* fix linter issue

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>

* Update tools/pd-ctl/pdctl/command/meta_service_group_command.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix copilot suggestion

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>

* fix ut

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>

---------

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit 5be7eae)
Signed-off-by: bufferflies <1045931706@qq.com>

# Conflicts:
#	pkg/keyspace/keyspace_test.go
#	pkg/keyspace/meta_service_group.go
#	pkg/keyspace/meta_service_group_test.go
#	pkg/storage/meta_service_group_test.go
#	pkg/utils/keypath/key_path.go
#	server/apiv2/handlers/meta_service_group.go
#	tests/server/apiv2/handlers/meta_service_group_test.go
#	tests/server/apiv2/handlers/testutil.go
#	tools/pd-ctl/pdctl/command/meta_service_group_command.go
@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. labels Jun 16, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 16, 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 bufferflies 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

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Replaces meta-service-group assignment-count storage with persisted status records containing AssignmentCount and Enabled, and updates manager, HTTP API, CLI, and tests to read and mutate the new status shape.

Changes

Meta-service group status migration

Layer / File(s) Summary
Storage contract and status key path
pkg/storage/endpoint/meta_service_group.go, pkg/utils/keypath/absolute_key_path.go, pkg/storage/meta_service_group_test.go
Introduces the exported status struct and status load/save methods, switches key paths to status records, and updates storage tests to persist and load full status values.
Manager status reads and group selection
pkg/keyspace/meta_service_group.go, pkg/keyspace/meta_service_group_test.go
Adds transactional status reads, derives assignment counts from loaded statuses, and selects enabled groups from the status map.
Manager status patching and assignment updates
pkg/keyspace/meta_service_group.go, pkg/keyspace/util.go, pkg/keyspace/keyspace.go
Validates status patches, updates assignment mutations through status records, and exports the unknown-group and invalid-assignment-count errors used by callers.
HTTP API status endpoint and response shape
server/apiv2/handlers/meta_service_group.go, tests/server/apiv2/handlers/meta_service_group_test.go, tests/server/apiv2/handlers/testutil.go
Adds the /status PATCH route, changes list/get/patch responses to include status objects, and updates handler tests and helpers for the new payloads.
CLI status subcommands
tools/pd-ctl/pdctl/command/meta_service_group_command.go, tools/pd-ctl/tests/metaservicegroup/meta_service_group_test.go
Adds set-enabled and set-assignment-count commands and covers their success and validation flows in CLI integration tests.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MetaServiceGroupHTTP
  participant MetaServiceGroupManager
  participant StorageEndpoint
  Client->>MetaServiceGroupHTTP: PATCH /meta-service-groups/:id/status
  MetaServiceGroupHTTP->>MetaServiceGroupManager: PatchStatus(ctx, id, patch)
  MetaServiceGroupManager->>StorageEndpoint: RunInTxn
  MetaServiceGroupManager->>StorageEndpoint: LoadMetaServiceGroupStatus(txn, ids)
  StorageEndpoint-->>MetaServiceGroupManager: status map
  MetaServiceGroupManager->>StorageEndpoint: SaveMetaServiceGroupStatus(txn, id, status)
  MetaServiceGroupHTTP->>MetaServiceGroupManager: buildMetaServiceGroupStatus(ctx)
  MetaServiceGroupManager->>StorageEndpoint: GetGroups() and LoadMetaServiceGroupStatus()
  StorageEndpoint-->>MetaServiceGroupHTTP: groups and statuses
  MetaServiceGroupHTTP-->>Client: status response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • tikv/pd#10597: Introduced the original meta-service-group manager, storage, API, and CLI flow that this PR updates from assignment-count storage to persisted status records.

Suggested labels

lgtm, approved

Suggested reviewers

  • lhy1024
  • JmPotato
  • rleungx

Poem

🐇 I hopped through status paths today,
With counts and flags that dance and sway.
A patch went by, the groups replied,
And JSON bunnies stayed neatly tied.
Hop hop! The status grove is bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding meta-service-group status.
Description check ✅ Passed The PR description follows the template well, includes the issue number, change summary, tests, and release note.
Linked Issues check ✅ Passed The changes match issue #10889 by persisting status, adding enabled-state handling, updating APIs, and supporting pd-ctl patches.
Out of Scope Changes check ✅ Passed The modified files and tests all appear directly related to the meta-service-group status feature with no clear unrelated additions.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
server/apiv2/handlers/meta_service_group.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.13][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

pkg/keyspace/meta_service_group.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.13][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


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 Jun 16, 2026
@bufferflies

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

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

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@pkg/keyspace/meta_service_group.go`:
- Around line 75-79: The MetaServiceGroupStatusPatch struct uses the JSON field
name assigned_count for the AssignedCount field, but the MetaServiceGroupStatus
exposes this field as assignment_count. This mismatch prevents API clients from
updating the count using the status shape. Change the JSON tag on the
AssignedCount field in MetaServiceGroupStatusPatch to assignment_count to align
with the status struct. Additionally, add validation logic to reject negative
values before persisting the patch, since negative counts corrupt the balancing
logic. Be aware that callers constructing MetaServiceGroupStatusPatch instances
may need updating to use the corrected field name.

In `@pkg/storage/endpoint/meta_service_group.go`:
- Around line 62-70: In the loadMetaServiceGroupStatus function, when statusVal
is empty (indicating the /status key is missing), add a fallback mechanism
before returning the zero-value status. Before the return statement in the
statusVal == "" condition, attempt to load the legacy assignment-count key using
the transaction (txn). If the legacy key exists, migrate its integer value to
populate the assignment_count field of the status object and set enabled to
true. Only return the zero-value status with assignment_count:0 and
enabled:false if the legacy key is also not found, ensuring existing persisted
counts from the old storage model are preserved during the upgrade.

In `@server/apiv2/handlers/meta_service_group.go`:
- Around line 187-195: The PatchMetaServiceGroupStatus handler needs to validate
the patch payload before persisting it and properly classify errors. After the
ShouldBindJSON check succeeds, add validation logic to ensure the patch data is
valid (such as checking that assigned_count is not negative), and return a 400
Bad Request if validation fails. Additionally, when the manager.PatchStatus call
fails, distinguish between client errors (invalid patch data) and server errors
instead of treating all failures as 500 Internal Server Error. Return 400 for
validation or client-side errors and 500 only for actual server-side failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4f09485-f513-4fe7-917b-6ff801605390

📥 Commits

Reviewing files that changed from the base of the PR and between 5eb3dab and c5c65b5.

📒 Files selected for processing (9)
  • pkg/keyspace/meta_service_group.go
  • pkg/keyspace/meta_service_group_test.go
  • pkg/storage/endpoint/meta_service_group.go
  • pkg/storage/meta_service_group_test.go
  • pkg/utils/keypath/absolute_key_path.go
  • server/apiv2/handlers/meta_service_group.go
  • tests/server/apiv2/handlers/meta_service_group_test.go
  • tests/server/apiv2/handlers/testutil.go
  • tools/pd-ctl/pdctl/command/meta_service_group_command.go

Comment thread pkg/keyspace/meta_service_group.go Outdated
Comment thread pkg/storage/endpoint/meta_service_group.go
Comment thread server/apiv2/handlers/meta_service_group.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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
tests/server/apiv2/handlers/meta_service_group_test.go (1)

78-100: 💤 Low value

Potential logic discrepancy in collectStatus setting Enabled=true.

The collectStatus helper function at line 89 sets Enabled: true for all collected statuses. However, this represents the expected state after keyspaces have been created and assigned to enabled groups. This is correct in the context of the test since groups are enabled at lines 108-112 before keyspaces are created at line 114.

The logic is correct but could be clearer. Consider adding a comment explaining that this helper assumes all collected groups have been enabled before assignment, to avoid confusion.

🤖 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 `@tests/server/apiv2/handlers/meta_service_group_test.go` around lines 78 -
100, Add a clarifying comment in the collectStatus function above or near the
line where Enabled is set to true (within the initialization of the
handlers.MetaServiceGroupStatus struct) to explicitly document the assumption
that this helper function expects all collected meta service groups to have been
enabled before keyspaces are assigned to them. This will make the intent clearer
to future readers and prevent confusion about why Enabled is always set to true.
tools/pd-ctl/pdctl/command/meta_service_group_command.go (1)

166-172: 💤 Low value

Consider validating non-negative assignment count client-side.

strconv.Atoi accepts negative integers. While the server should also validate this, adding a client-side check provides better UX by catching errors early with a clear message.

Proposed fix
 func newSetMetaServiceGroupAssignmentCountFunc(cmd *cobra.Command, args []string) {
 	groupID := strings.TrimSpace(args[0])
 	assignmentCount, err := strconv.Atoi(args[1])
 	if err != nil {
 		cmd.PrintErrln("Invalid value for assignment count, must be an integer:", err)
 		return
 	}
+	if assignmentCount < 0 {
+		cmd.PrintErrln("Invalid value for assignment count, must be non-negative")
+		return
+	}
 	patch := &keyspace.MetaServiceGroupStatusPatch{
🤖 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 `@tools/pd-ctl/pdctl/command/meta_service_group_command.go` around lines 166 -
172, After successfully parsing the assignment count with strconv.Atoi in the
newSetMetaServiceGroupAssignmentCountFunc function, add a validation check to
ensure assignmentCount is not negative. If assignmentCount is less than zero,
use cmd.PrintErrln to display an error message indicating that the assignment
count must be a non-negative integer, then return early. This provides better
user experience by catching invalid input on the client side before sending it
to the server.
pkg/keyspace/meta_service_group.go (1)

149-161: ⚡ Quick win

Redundant status load within the same transaction.

findMinMetaGroup (called at line 151) already loads the entire status map via LoadMetaServiceGroupStatus. Lines 155-158 load the same data again within the same transaction. Consider refactoring findMinMetaGroup to return both the selected group and the status map, allowing reuse here.

♻️ Suggested refactor
-func (m *MetaServiceGroupManager) findMinMetaGroup(txn kv.Txn) (string, error) {
+func (m *MetaServiceGroupManager) findMinMetaGroup(txn kv.Txn) (string, map[string]*endpoint.MetaServiceGroupStatus, error) {
 	statusMap, err := m.store.LoadMetaServiceGroupStatus(txn, m.metaServiceGroups)
 	if err != nil {
-		return "", err
+		return "", nil, err
 	}
 	minCount := math.MaxInt
 	var assignedGroup string
 	for currentGroup, status := range statusMap {
 		if status.Enabled && status.AssignmentCount < minCount {
 			minCount = status.AssignmentCount
 			assignedGroup = currentGroup
 		}
 	}
 	if assignedGroup == "" {
-		return "", errNoAvailableMetaServiceGroups
+		return "", nil, errNoAvailableMetaServiceGroups
 	}
-	return assignedGroup, nil
+	return assignedGroup, statusMap, nil
 }

Then in AssignToGroup:

-		assignedGroup, err = m.findMinMetaGroup(txn)
+		var statusMap map[string]*endpoint.MetaServiceGroupStatus
+		assignedGroup, statusMap, err = m.findMinMetaGroup(txn)
 		if err != nil {
 			return err
 		}
-		statusMap, err := m.store.LoadMetaServiceGroupStatus(txn, m.metaServiceGroups)
-		if err != nil {
-			return err
-		}
 		status := statusMap[assignedGroup]
🤖 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/keyspace/meta_service_group.go` around lines 149 - 161, The code is
redundantly loading the status map twice within the same transaction: once
inside findMinMetaGroup and again at lines 155-158. Refactor the
findMinMetaGroup method to return both the assigned group and the status map it
already loads internally. Then update the call to findMinMetaGroup in the
transaction to receive both return values, and remove the redundant
m.store.LoadMetaServiceGroupStatus call. Finally, use the status map returned
from findMinMetaGroup instead of loading it again.
🤖 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.

Inline comments:
In `@pkg/keyspace/meta_service_group.go`:
- Around line 173-178: The assignment count decrement for the old group ID in
the statusMap has no validation to prevent it from going negative. Before
decrementing status.AssignmentCount for the oldGroupID in the statusMap, add a
check to ensure the count is greater than 0 to prevent it from becoming
negative, which would corrupt load balancing behavior in findMinMetaGroup. Only
perform the decrement and subsequent SaveMetaServiceGroupStatus call if the
count is positive.

---

Nitpick comments:
In `@pkg/keyspace/meta_service_group.go`:
- Around line 149-161: The code is redundantly loading the status map twice
within the same transaction: once inside findMinMetaGroup and again at lines
155-158. Refactor the findMinMetaGroup method to return both the assigned group
and the status map it already loads internally. Then update the call to
findMinMetaGroup in the transaction to receive both return values, and remove
the redundant m.store.LoadMetaServiceGroupStatus call. Finally, use the status
map returned from findMinMetaGroup instead of loading it again.

In `@tests/server/apiv2/handlers/meta_service_group_test.go`:
- Around line 78-100: Add a clarifying comment in the collectStatus function
above or near the line where Enabled is set to true (within the initialization
of the handlers.MetaServiceGroupStatus struct) to explicitly document the
assumption that this helper function expects all collected meta service groups
to have been enabled before keyspaces are assigned to them. This will make the
intent clearer to future readers and prevent confusion about why Enabled is
always set to true.

In `@tools/pd-ctl/pdctl/command/meta_service_group_command.go`:
- Around line 166-172: After successfully parsing the assignment count with
strconv.Atoi in the newSetMetaServiceGroupAssignmentCountFunc function, add a
validation check to ensure assignmentCount is not negative. If assignmentCount
is less than zero, use cmd.PrintErrln to display an error message indicating
that the assignment count must be a non-negative integer, then return early.
This provides better user experience by catching invalid input on the client
side before sending it to the server.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: beec8daa-b422-480f-885e-71d385de0445

📥 Commits

Reviewing files that changed from the base of the PR and between 5eb3dab and c5c65b5.

📒 Files selected for processing (9)
  • pkg/keyspace/meta_service_group.go
  • pkg/keyspace/meta_service_group_test.go
  • pkg/storage/endpoint/meta_service_group.go
  • pkg/storage/meta_service_group_test.go
  • pkg/utils/keypath/absolute_key_path.go
  • server/apiv2/handlers/meta_service_group.go
  • tests/server/apiv2/handlers/meta_service_group_test.go
  • tests/server/apiv2/handlers/testutil.go
  • tools/pd-ctl/pdctl/command/meta_service_group_command.go

Comment thread pkg/keyspace/meta_service_group.go
AssignedKeyspaces int `json:"assigned_keyspaces"`
ID string `json:"id"`
Addresses string `json:"addresses"`
Status *endpoint.MetaServiceGroupStatus `json:"status,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This changes the existing v2 response shape by removing assigned_keyspaces. Existing clients of GET/POST /meta-service-groups may break; please keep the old field while adding status, or version the API change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Restored the assigned_keyspaces field on the response in 10f7107 — it now mirrors status.assignment_count, so existing GET/POST /meta-service-groups clients keep working, while the new status object additionally exposes the enabled state. Happy to instead version the endpoint if you'd prefer a cleaner break.

Return 404 for an unknown meta-service group and 400 for a negative
assignment count instead of 500, by exporting sentinel errors and
mapping them in the HTTP handler. Rename the patch field AssignedCount
to AssignmentCount for consistency with the persisted status. Fix the
swagger annotations to describe the list/add/patch responses as
{array} MetaServiceGroupStatus. Add a pd-ctl integration test covering
list/add/set-enabled/set-assignment-count and the new error paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: tongjian <1045931706@qq.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/needs-triage-completed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 25, 2026
…ount

Restore the assigned_keyspaces field on the meta-service group HTTP
response for backward compatibility with existing v2 clients; it mirrors
status.assignment_count. Guard updateAssignmentTxn against decrementing
the assignment count below zero, which would otherwise be preferred by
findMinMetaGroup and skew load balancing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: tongjian <1045931706@qq.com>

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@server/apiv2/handlers/meta_service_group.go`:
- Around line 161-169: The status assembly in MetaServiceGroupStatus is
returning a partial object when statuses[id] is missing, which can hide the
enabled state while still emitting AssignedKeyspaces as 0. Update the GetStatus
response handling in meta_service_group.go so it does not append a group unless
a matching endpoint.MetaServiceGroupStatus exists, or else build a full default
status consistently before appending. Keep the behavior aligned with the
MetaServiceGroupStatus struct fields and the statuses[id] lookup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a34b952-41f3-4062-ba82-a462f7dd119a

📥 Commits

Reviewing files that changed from the base of the PR and between b0d53fd and 10f7107.

📒 Files selected for processing (2)
  • pkg/keyspace/meta_service_group.go
  • server/apiv2/handlers/meta_service_group.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/keyspace/meta_service_group.go

Comment on lines +161 to +169
var assignedKeyspaces int
if status := statuses[id]; status != nil {
assignedKeyspaces = status.AssignmentCount
}
response = append(response, MetaServiceGroupStatus{
ID: id,
Addresses: addresses,
AssignedKeyspaces: assignmentCounts[id],
Status: statuses[id],
AssignedKeyspaces: assignedKeyspaces,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Avoid returning partial status objects when a group status is missing.

Line 168 omits status because the field has omitempty, while Line 169 still returns assigned_keyspaces: 0. If GetStatus lacks an entry for any group, clients lose the new enabled state and may see a misleading assignment count. Prefer failing the response or synthesizing a default endpoint.MetaServiceGroupStatus consistently.

Suggested fix
 	for id, addresses := range groups {
-		var assignedKeyspaces int
-		if status := statuses[id]; status != nil {
-			assignedKeyspaces = status.AssignmentCount
+		status := statuses[id]
+		if status == nil {
+			return nil, errors.Errorf("meta-service group %s status not found", id)
 		}
 		response = append(response, MetaServiceGroupStatus{
 			ID:                id,
 			Addresses:         addresses,
-			Status:            statuses[id],
-			AssignedKeyspaces: assignedKeyspaces,
+			Status:            status,
+			AssignedKeyspaces: status.AssignmentCount,
 		})
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var assignedKeyspaces int
if status := statuses[id]; status != nil {
assignedKeyspaces = status.AssignmentCount
}
response = append(response, MetaServiceGroupStatus{
ID: id,
Addresses: addresses,
AssignedKeyspaces: assignmentCounts[id],
Status: statuses[id],
AssignedKeyspaces: assignedKeyspaces,
for id, addresses := range groups {
status := statuses[id]
if status == nil {
return nil, errors.Errorf("meta-service group %s status not found", id)
}
response = append(response, MetaServiceGroupStatus{
ID: id,
Addresses: addresses,
Status: status,
AssignedKeyspaces: status.AssignmentCount,
🤖 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 `@server/apiv2/handlers/meta_service_group.go` around lines 161 - 169, The
status assembly in MetaServiceGroupStatus is returning a partial object when
statuses[id] is missing, which can hide the enabled state while still emitting
AssignedKeyspaces as 0. Update the GetStatus response handling in
meta_service_group.go so it does not append a group unless a matching
endpoint.MetaServiceGroupStatus exists, or else build a full default status
consistently before appending. Keep the behavior aligned with the
MetaServiceGroupStatus struct fields and the statuses[id] lookup.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.48780% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.18%. Comparing base (5eb3dab) to head (10f7107).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10904      +/-   ##
==========================================
+ Coverage   79.06%   79.18%   +0.12%     
==========================================
  Files         540      541       +1     
  Lines       74535    75150     +615     
==========================================
+ Hits        58929    59506     +577     
- Misses      11423    11434      +11     
- Partials     4183     4210      +27     
Flag Coverage Δ
unittests 79.18% <80.48%> (+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.

c.AbortWithStatusJSON(http.StatusBadRequest, err.Error())
return
}
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please map errs.ErrEtcdTxnConflict to 409 here. Concurrent status patches or assignments can hit the etcd txn compare failure, and that is a retryable conflict rather than an internal server error.

Comment thread pkg/keyspace/keyspace.go
if manager.mgm != nil && oldMetaServiceGroup != newMetaServiceGroup {
if newMetaServiceGroup != "" && manager.mgm.GetGroups()[newMetaServiceGroup] == "" {
return errUnknownMetaServiceGroup
return ErrUnknownMetaServiceGroup

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This only checks that the target group exists. Since disabled groups are skipped by automatic assignment, config updates should also reject moving a keyspace into a disabled meta-service group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. 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.

5be7eae7 add meta-service-group status

3 participants