Skip to content

keyspace: add update keyspace config#69020

Merged
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
ystaticy:update_ks_config
Jun 15, 2026
Merged

keyspace: add update keyspace config#69020
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
ystaticy:update_ks_config

Conversation

@ystaticy

@ystaticy ystaticy commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #67765

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a programmatic way to patch/update keyspace configuration via the platform configuration API.
  • Tests

    • Expanded unit tests to cover successful keyspace updates, missing PD HTTP client handling, and propagation of backend errors.
  • Stability

    • Improved test execution reliability by increasing test sharding.

Signed-off-by: ystaticy <y_static_y@sina.com>
@pantheon-ai

pantheon-ai Bot commented Jun 8, 2026

Copy link
Copy Markdown

@ystaticy I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details.

⏳ This process typically takes 10-30 minutes depending on the complexity of the changes.

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds exported SetKeyspaceConfig to send keyspace config updates through the PD HTTP client, comprehensive unit tests covering success and error propagation cases, and increases infosync_test shard_count from 4 to 7.

Changes

Keyspace Configuration Feature

Layer / File(s) Summary
SetKeyspaceConfig core implementation
pkg/domain/infosync/info.go
Adds exported SetKeyspaceConfig that retrieves global InfoSyncer, validates pdHTTPCli is non-nil (otherwise returns PD leader error), and calls pdHTTPCli.UpdateKeyspaceConfig with provided params. Imports PD errs package.
SetKeyspaceConfig unit tests
pkg/domain/infosync/info_test.go
Adds errors and keyspacepb imports, introduces mockKeyspaceConfigPDHTTPClient test double, and adds three tests: TestSetKeyspaceConfig (success path), TestSetKeyspaceConfigWithoutPDHTTPClient (nil client error), and TestSetKeyspaceConfigPropagatesPDHTTPError (error propagation).
Test shard scaling
pkg/domain/infosync/BUILD.bazel
Increases infosync_test shard_count from 4 to 7.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant InfoSyncer
  participant pdHTTPCli
  participant PD
  Caller->>InfoSyncer: SetKeyspaceConfig(ctx, keyspaceName, config)
  InfoSyncer->>pdHTTPCli: UpdateKeyspaceConfig(params)
  pdHTTPCli->>PD: HTTP PATCH /keyspace/{name} with params
  PD-->>pdHTTPCli: response (KeyspaceMeta or error)
  pdHTTPCli-->>InfoSyncer: result / error
  InfoSyncer-->>Caller: return error or nil
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops to patch the keyspace bright,
With configs marshaled by moonlit byte,
PD listens as tests all pass with glee,
Shards increased for runners roaming free,
A nimble hop into the stable night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'keyspace: add update keyspace config' clearly summarizes the main change—adding functionality to update keyspace configuration. It is concise, specific, and directly reflects the primary purpose of the changeset across all three modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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 and usage tips.

@tiprow

tiprow Bot commented Jun 8, 2026

Copy link
Copy Markdown

Hi @ystaticy. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

@ystaticy ystaticy changed the title add update keyspace config keyspace: add update keyspace config Jun 8, 2026

@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: 2

🤖 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/domain/infosync/info_test.go`:
- Around line 279-343: Add a regression test in TestSetKeyspaceConfig that calls
SetKeyspaceConfig with a typed-nil params pointer to ensure the function
validates and returns a local error: after the existing happy-path case, invoke
SetKeyspaceConfig(context.Background(), "test-keyspace",
(*pdhttp.UpdateKeyspaceConfigParams)(nil)), assert require.Error(t, err) and
assert the error indicates invalid/nil params (e.g., require.Contains(t,
err.Error(), "params" or "nil")). This pins the conversion guard in
SetKeyspaceConfig and prevents regressions; reference SetKeyspaceConfig and
pdhttp.UpdateKeyspaceConfigParams when adding the assertion.

In `@pkg/domain/infosync/info.go`:
- Around line 359-365: The toUpdateKeyspaceConfigParams function currently
treats a typed nil *pdhttp.UpdateKeyspaceConfigParams as valid and returns (nil,
nil), allowing nil payloads to reach UpdateKeyspaceConfig; modify
toUpdateKeyspaceConfigParams to explicitly guard against typed-nil pointers:
when the config asserts to (*pdhttp.UpdateKeyspaceConfigParams) check if params
== nil and return a descriptive error (e.g., "nil UpdateKeyspaceConfigParams")
instead of (nil, nil); keep the existing handling for the non-pointer value case
(pdhttp.UpdateKeyspaceConfigParams) unchanged.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fec23760-9c38-4df1-b263-702655a0a48f

📥 Commits

Reviewing files that changed from the base of the PR and between b399d61 and 31aba0c.

📒 Files selected for processing (3)
  • pkg/domain/infosync/BUILD.bazel
  • pkg/domain/infosync/info.go
  • pkg/domain/infosync/info_test.go

Comment thread pkg/domain/infosync/info_test.go
Comment thread pkg/domain/infosync/info.go Outdated
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.3385%. Comparing base (d568a85) to head (7aa43cc).
⚠️ Report is 33 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69020        +/-   ##
================================================
+ Coverage   76.3213%   76.3385%   +0.0171%     
================================================
  Files          2041       2059        +18     
  Lines        562689     582171     +19482     
================================================
+ Hits         429452     444421     +14969     
- Misses       132324     135148      +2824     
- Partials        913       2602      +1689     
Flag Coverage Δ
integration 46.0480% <0.0000%> (+6.3193%) ⬆️

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

Components Coverage Δ
dumpling 60.4610% <ø> (ø)
parser ∅ <ø> (∅)
br 64.9190% <ø> (+2.1285%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: ystaticy <y_static_y@sina.com>
Comment thread pkg/domain/infosync/info.go Outdated
Comment thread pkg/domain/infosync/info.go Outdated
@ChangRui-Ryan

Copy link
Copy Markdown
Contributor

One concern about SetKeyspaceConfig: after converting config any through JSON into pdhttp.UpdateKeyspaceConfigParams, invalid inputs such as an untyped nil, struct{}{}, or a wrong-shaped struct can become a zero-value params object (Config == nil). The PD side will turn that into empty mutations, so the request may return success for an existing keyspace while no config is actually updated.

Could we reject this locally, e.g. return an error when config == nil or when the converted params has an empty/nil Config map, and add regression tests for these cases? Otherwise a future caller may think a keyspace flag was updated successfully even though the payload was malformed and no update happened.

Signed-off-by: ystaticy <y_static_y@sina.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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/domain/infosync/info.go (1)

342-353: ⚠️ Potential issue | 🟠 Major | ⚖️ Poor tradeoff

Validate that config.Config is non-nil and non-empty before issuing the PD request.

The function accepts pdhttp.UpdateKeyspaceConfigParams by value, which can be a zero-value struct where Config is nil. According to the PR objectives, when the PD backend receives a request with Config == nil or an empty map, it interprets the payload as empty mutations and returns success without performing any configuration update. This creates a silent failure where callers may believe a keyspace configuration was successfully updated when the operation actually did nothing.

Add local validation to reject:

  1. Cases where config.Config is nil
  2. Cases where config.Config is an empty map
🛡️ Proposed validation guard
 func SetKeyspaceConfig(ctx context.Context, keyspaceName string, config pdhttp.UpdateKeyspaceConfigParams) error {
 	is, err := getGlobalInfoSyncer()
 	if err != nil {
 		return errors.Trace(err)
 	}
 	if is.pdHTTPCli == nil {
 		return errs.ErrClientGetLeader.FastGenByArgs("pd http cli is nil")
 	}
+	if config.Config == nil || len(config.Config) == 0 {
+		return errors.New("keyspace config cannot be nil or empty")
+	}
 
 	_, err = is.pdHTTPCli.UpdateKeyspaceConfig(ctx, keyspaceName, &config)
 	return errors.Trace(err)
 }
🤖 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/domain/infosync/info.go` around lines 342 - 353, The SetKeyspaceConfig
function accepts a potentially zero-value UpdateKeyspaceConfigParams struct
where the Config field can be nil or empty, and the PD backend will silently
accept such requests without performing any actual configuration updates. Add
validation in SetKeyspaceConfig before calling is.pdHTTPCli.UpdateKeyspaceConfig
to check that config.Config is neither nil nor an empty map, returning an
appropriate error if either condition is true. Place this validation after the
pdHTTPCli nil check and before the UpdateKeyspaceConfig call to prevent silent
failures where callers believe the configuration was updated when it was not.
pkg/domain/infosync/info_test.go (1)

279-340: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add regression tests for nil and empty Config map validation.

The test suite does not cover the validation gap where config.Config is nil or empty. According to the PR objectives, these cases should be rejected locally with an explicit error rather than allowing the request to proceed to PD (which would silently succeed without updating anything).

Please add test cases that:

  1. Pass pdhttp.UpdateKeyspaceConfigParams{} (zero-value with Config == nil) with a valid PD HTTP client and assert that SetKeyspaceConfig returns an error indicating invalid/nil config
  2. Pass pdhttp.UpdateKeyspaceConfigParams{Config: map[string]*string{}} (empty map) with a valid PD HTTP client and assert an error

These tests will prevent future regressions and provide clear feedback to developers integrating this function.

📝 Example test structure
func TestSetKeyspaceConfigRejectsNilConfig(t *testing.T) {
	_, err := GlobalInfoSyncerInit(context.TODO(), "test", func() uint64 { return 1 }, nil, nil, nil, nil, keyspace.CodecV1, false, nil)
	require.NoError(t, err)

	restore := SetPDHttpCliForTest(&mockKeyspaceConfigPDHTTPClient{
		t:              t,
		expectedName:   "test-keyspace",
		expectedParams: nil, // should not be called
	})
	defer restore()

	// Test nil Config map
	err = SetKeyspaceConfig(context.Background(), "test-keyspace", pdhttp.UpdateKeyspaceConfigParams{})
	require.Error(t, err)
	require.Contains(t, err.Error(), "config")

	// Test empty Config map
	err = SetKeyspaceConfig(context.Background(), "test-keyspace", pdhttp.UpdateKeyspaceConfigParams{
		Config: map[string]*string{},
	})
	require.Error(t, err)
	require.Contains(t, err.Error(), "empty")
}
🤖 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/domain/infosync/info_test.go` around lines 279 - 340, Add two new
regression test functions to validate that SetKeyspaceConfig rejects invalid
Config maps. Following the same pattern as the existing test functions
(TestSetKeyspaceConfig, TestSetKeyspaceConfigWithoutPDHTTPClient,
TestSetKeyspaceConfigPropagatesPDHTTPError), create a test that initializes
GlobalInfoSyncerInit with a valid mock PD HTTP client via SetPDHttpCliForTest,
then calls SetKeyspaceConfig twice: once with a zero-value
UpdateKeyspaceConfigParams (nil Config) and once with an empty Config map
(map[string]*string{}). Both calls should return errors with appropriate
messages indicating invalid or nil/empty config. This validates that
SetKeyspaceConfig performs local validation before attempting to contact PD.
🤖 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.

Outside diff comments:
In `@pkg/domain/infosync/info_test.go`:
- Around line 279-340: Add two new regression test functions to validate that
SetKeyspaceConfig rejects invalid Config maps. Following the same pattern as the
existing test functions (TestSetKeyspaceConfig,
TestSetKeyspaceConfigWithoutPDHTTPClient,
TestSetKeyspaceConfigPropagatesPDHTTPError), create a test that initializes
GlobalInfoSyncerInit with a valid mock PD HTTP client via SetPDHttpCliForTest,
then calls SetKeyspaceConfig twice: once with a zero-value
UpdateKeyspaceConfigParams (nil Config) and once with an empty Config map
(map[string]*string{}). Both calls should return errors with appropriate
messages indicating invalid or nil/empty config. This validates that
SetKeyspaceConfig performs local validation before attempting to contact PD.

In `@pkg/domain/infosync/info.go`:
- Around line 342-353: The SetKeyspaceConfig function accepts a potentially
zero-value UpdateKeyspaceConfigParams struct where the Config field can be nil
or empty, and the PD backend will silently accept such requests without
performing any actual configuration updates. Add validation in SetKeyspaceConfig
before calling is.pdHTTPCli.UpdateKeyspaceConfig to check that config.Config is
neither nil nor an empty map, returning an appropriate error if either condition
is true. Place this validation after the pdHTTPCli nil check and before the
UpdateKeyspaceConfig call to prevent silent failures where callers believe the
configuration was updated when it was not.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7b1572c8-fb76-4bba-83c8-c0a1b98719b6

📥 Commits

Reviewing files that changed from the base of the PR and between 168f478 and 7aa43cc.

📒 Files selected for processing (2)
  • pkg/domain/infosync/info.go
  • pkg/domain/infosync/info_test.go

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 15, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, YangKeao

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 15, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-06-15 03:55:42.325602251 +0000 UTC m=+1364243.395919641: ☑️ agreed by YangKeao.
  • 2026-06-15 03:57:20.434322989 +0000 UTC m=+1364341.504640389: ☑️ agreed by D3Hunter.

@ti-chi-bot ti-chi-bot Bot merged commit 720c2f6 into pingcap:master Jun 15, 2026
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants