Skip to content

[release-8.5-keyspace] add option to skip rawkv region bound#10535

Open
bufferflies wants to merge 5 commits intotikv:masterfrom
bufferflies:pr-merge/0c88ce89-skip-rawkv-region-bound
Open

[release-8.5-keyspace] add option to skip rawkv region bound#10535
bufferflies wants to merge 5 commits intotikv:masterfrom
bufferflies:pr-merge/0c88ce89-skip-rawkv-region-bound

Conversation

@bufferflies
Copy link
Copy Markdown
Contributor

@bufferflies bufferflies commented Apr 1, 2026

What problem does this PR solve?

Issue Number: ref #10516,close #10534

author: @zeminzhou

cp 0c88ce89

What is changed and how does it work?

Cherry-pick 0c88ce8921caabfa532e4a2a259bf39f7a49bdd4 onto master and adapt the region-split wait path to the current master structure so keyspace creation can optionally skip rawkv region bounds.

Check List

Tests

  • Unit test

Release note

Add a new configuration `disable-raw-kv-region-split` to skip raw KV split. It will ignore the existing keyspace, only affect the new keyspace 

Summary by CodeRabbit

  • New Features
    • Added a new configuration option disable-raw-kv-region-split to control region split behavior for keyspaces. When enabled, region bound evaluation and label rule construction will conditionally exclude raw KV bounds.

… (tikv#358)

* [release 8.1] cp disable-raw-kv-region-split (tikv#292)

* Add option to skip split rawkv regions (tikv#217)

* add option to skip rawkv region bound

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

---------

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

* make check

Signed-off-by: zeminzhou <zhouzemin@pingcap.com>

---------

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>
Signed-off-by: zeminzhou <zhouzemin@pingcap.com>
Co-authored-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
(cherry picked from commit 0c88ce8)
@ti-chi-bot ti-chi-bot bot added 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. labels Apr 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new configuration option DisableRawKVRegionSplit that allows conditional omission of raw KV bounds during keyspace region splitting and label rule construction. The option is threaded through the keyspace manager, configuration layer, and utility functions with corresponding test updates.

Changes

Cohort / File(s) Summary
Keyspace Manager
pkg/keyspace/keyspace.go
Added GetDisableRawKVRegionSplit() to the Config interface; refactored waitKeyspaceRegionSplit to accept skipRaw parameter; introduced hasKeyspaceRegionBound helper with conditional bound-checking logic; delegated CheckKeyspaceRegionBound to use the new helper with the config value.
Keyspace Manager Tests
pkg/keyspace/keyspace_test.go
Extended mockConfig struct with DisableRawKVRegionSplit field and added corresponding getter method to satisfy the updated Config interface.
Keyspace Utilities
pkg/keyspace/util.go
Added buildKeyRanges and buildLabelRule internal helpers with skipRaw parameter to conditionally exclude raw bounds from key ranges and label rules; public APIs remain unchanged, delegating with skipRaw=false.
Keyspace Utility Tests
pkg/keyspace/util_test.go
Updated TestMakeLabelRule to test both skipRaw=false (multi-entry data) and skipRaw=true (single txn-only entry) cases; adjusted TestParseKeyspaceIDFromLabelRule fixture to use new helper invocations.
Scheduling Rule Watcher Tests
pkg/mcs/scheduling/server/rule/watcher_test.go
Changed label-rule Data construction to use explicit per-region bound encodings via MakeRegionBound and hex encoding instead of MakeKeyRanges.
Server Configuration
server/config/config.go
Added DisableRawKVRegionSplit boolean field to KeyspaceConfig with TOML/JSON mappings, default constant, config adjustment logic, and exported getter method.
Server Configuration Tests
server/config/config_test.go
Added TestKeyspaceConfigJSONBoolEncoding to verify JSON marshaling/unmarshaling of the new disable-raw-kv-region-split and wait-region-split boolean fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

lgtm, approved

Suggested reviewers

  • rleungx
  • lhy1024

Poem

🐰 A toggle so fine, to skip what's raw and keen,
When region bounds split, choose which range is seen—
Config threads gently through manager and test,
Keyspace grows flexible, put your bounds to rest! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 '[release-8.5-keyspace] add option to skip rawkv region bound' clearly summarizes the main feature being added—a configuration option to skip RawKV region bounds during keyspace creation.
Linked Issues check ✅ Passed The PR implements the feature to skip RawKV region bounds by adding a DisableRawKVRegionSplit configuration option, extending the Config interface, and adjusting bound-checking logic accordingly, aligning with issue #10534.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the skip RawKV region bound feature: configuration fields, interface extensions, bound-checking refactors, and supporting test updates. No unrelated changes detected.
Description check ✅ Passed The PR description covers required sections: problem statement (issue references), explanation of changes with context, checklist with unit tests, and release note.

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

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

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.

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 1, 2026
@bufferflies
Copy link
Copy Markdown
Contributor Author

Review note:

The new DisableRawKVRegionSplit field is tagged as json:"disable-raw-kv-region-split,string" in server/config/config.go. KeyspaceConfig is exported via the config HTTP API, so this makes the field serialize as a JSON string ("true" / "false") instead of a JSON boolean, unlike the sibling wait-region-split field. That changes the API shape for config consumers and is likely to break scripts or clients that expect a boolean.

Please change the tag to json:"disable-raw-kv-region-split" unless there is a specific compatibility requirement for string-encoded booleans here.

@bufferflies
Copy link
Copy Markdown
Contributor Author

Re-review update:

I rechecked the latest delta and the previous finding is resolved.

  • DisableRawKVRegionSplit now uses json:"disable-raw-kv-region-split", so the config HTTP API keeps this field as a JSON boolean instead of a string.
  • The new regression test in server/config/config_test.go exercises the JSON encoding path and verifies that keyspace.disable-raw-kv-region-split is emitted as a bool.

I do not have additional findings on this update. The remaining merge gate is the required make check pass mentioned in the task thread.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
pkg/keyspace/keyspace_test.go (1)

66-92: Add one manager-level test that actually sets DisableRawKVRegionSplit=true.

This mock wiring keeps the suite compiling, but nothing in this file exercises the new waitKeyspaceRegionSplit / CheckKeyspaceRegionBound branch with raw bounds absent. A txn-only-ready case here would catch the behavior this PR is changing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/keyspace/keyspace_test.go` around lines 66 - 92, The test suite never
sets DisableRawKVRegionSplit on the mockConfig so the new branches in
waitKeyspaceRegionSplit and CheckKeyspaceRegionBound are not exercised; add a
manager-level test that creates/uses mockConfig with
DisableRawKVRegionSplit=true (via GetDisableRawKVRegionSplit) and drives the
manager code paths that call waitKeyspaceRegionSplit and
CheckKeyspaceRegionBound (simulate/prepare a txn-only-ready keyspace with raw
bounds missing) so the branch that handles raw-bounds-absent behavior executes
and asserts expected outcome.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/keyspace/util.go`:
- Around line 129-130: The rename of makeKeyRanges to an unexported identifier
breaks external callers; either restore an exported wrapper MakeKeyRanges(id
uint32, skipRaw bool) that calls the new makeKeyRanges, or update all external
call sites to use the unexported symbol (preferred if migrating within the same
package). Add an exported function named MakeKeyRanges that forwards its
arguments to makeKeyRanges (preserving signature and behavior) so tools/pd-ctl
callers (e.g., keyspace.MakeKeyRanges) keep building, or alternatively change
those callers to call the new unexported implementation and remove the wrapper.

---

Nitpick comments:
In `@pkg/keyspace/keyspace_test.go`:
- Around line 66-92: The test suite never sets DisableRawKVRegionSplit on the
mockConfig so the new branches in waitKeyspaceRegionSplit and
CheckKeyspaceRegionBound are not exercised; add a manager-level test that
creates/uses mockConfig with DisableRawKVRegionSplit=true (via
GetDisableRawKVRegionSplit) and drives the manager code paths that call
waitKeyspaceRegionSplit and CheckKeyspaceRegionBound (simulate/prepare a
txn-only-ready keyspace with raw bounds missing) so the branch that handles
raw-bounds-absent behavior executes and asserts expected outcome.
🪄 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: db1a2dcf-698f-41aa-b67d-e062dea57b9f

📥 Commits

Reviewing files that changed from the base of the PR and between 5e71b3a and 0ef292c.

📒 Files selected for processing (6)
  • pkg/keyspace/keyspace.go
  • pkg/keyspace/keyspace_test.go
  • pkg/keyspace/util.go
  • pkg/keyspace/util_test.go
  • pkg/mcs/scheduling/server/rule/watcher_test.go
  • server/config/config.go

Signed-off-by: bufferflies <1045931706@qq.com>
@bufferflies bufferflies force-pushed the pr-merge/0c88ce89-skip-rawkv-region-bound branch from cea718f to 4473520 Compare April 1, 2026 03:21
@bufferflies
Copy link
Copy Markdown
Contributor Author

Review note:

makeKeyRanges should stay public and keep returning []any. In the current patch it was changed from MakeKeyRanges(id uint32) []any to makeKeyRanges(id uint32, skipRaw bool) any, which unnecessarily regresses both API visibility and type precision.

Even if current call sites are internal, this helper was previously exported and had a concrete return type. Please keep the exported helper and preserve the []any return type, then layer the new skipRaw behavior without widening the signature to any.

Signed-off-by: bufferflies <1045931706@qq.com>
@bufferflies
Copy link
Copy Markdown
Contributor Author

Review note:

This is only a partial compatibility fix. MakeKeyRanges is public again and the return type is back to []any, but its exported signature still changed from MakeKeyRanges(id uint32) []any to MakeKeyRanges(id uint32, skipRaw bool) []any.

That is still a breaking API change for any existing caller that uses the old one-argument form. If compatibility is the goal, the old exported signature should remain available. A safer shape would be to keep MakeKeyRanges(id uint32) []any with the original behavior and add a new helper for the skip-raw variant (or keep the skip-raw helper internal).

Signed-off-by: bufferflies <1045931706@qq.com>
Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
tools/pd-ctl/pdctl/command/keyspace_command_test.go (1)

41-74: Consider adding test coverage for skipRaw=true.

The test correctly validates the skipRaw=false behavior. However, the new skipRaw=true path is not covered in this test file. Adding a test case that verifies MakeKeyRanges(keyspaceID, true) returns only 1 range (txn-only) would improve coverage of the new functionality.

💡 Example test case for skipRaw=true
func TestMakeKeyRangesSkipRaw(t *testing.T) {
	re := require.New(t)

	keyspaceID := uint32(1)
	ranges := keyspace.MakeKeyRanges(keyspaceID, true)
	re.Len(ranges, 1, "should have 1 range (txn only) when skipRaw=true")

	// Verify txn key range
	txnRange := ranges[0].(map[string]any)
	txnStart := txnRange["start_key"].(string)
	txnEnd := txnRange["end_key"].(string)
	re.NotEmpty(txnStart)
	re.NotEmpty(txnEnd)

	// Verify the encoding matches the expected txn format
	keyspaceIDBytes := make([]byte, 4)
	nextKeyspaceIDBytes := make([]byte, 4)
	binary.BigEndian.PutUint32(keyspaceIDBytes, keyspaceID)
	binary.BigEndian.PutUint32(nextKeyspaceIDBytes, keyspaceID+1)

	expectedTxnLeft := codec.EncodeBytes(append([]byte{'x'}, keyspaceIDBytes[1:]...))
	expectedTxnRight := codec.EncodeBytes(append([]byte{'x'}, nextKeyspaceIDBytes[1:]...))

	re.Equal(hex.EncodeToString(expectedTxnLeft), txnStart)
	re.Equal(hex.EncodeToString(expectedTxnRight), txnEnd)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/pd-ctl/pdctl/command/keyspace_command_test.go` around lines 41 - 74,
Add a unit test covering the new skipRaw=true path: call
keyspace.MakeKeyRanges(keyspaceID, true) in keyspace_command_test.go (similar
structure to existing loop test) and assert it returns exactly 1 range
(txn-only); verify the returned map uses keys "start_key"/"end_key" and that
encoded txn boundaries equal codec.EncodeBytes(append([]byte{'x'}, ...)) for
keyspaceID and keyspaceID+1 as done in the existing assertions for the txn
range.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tools/pd-ctl/pdctl/command/keyspace_command_test.go`:
- Around line 41-74: Add a unit test covering the new skipRaw=true path: call
keyspace.MakeKeyRanges(keyspaceID, true) in keyspace_command_test.go (similar
structure to existing loop test) and assert it returns exactly 1 range
(txn-only); verify the returned map uses keys "start_key"/"end_key" and that
encoded txn boundaries equal codec.EncodeBytes(append([]byte{'x'}, ...)) for
keyspaceID and keyspaceID+1 as done in the existing assertions for the txn
range.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0f0db76-96c4-42eb-b36e-91f8e6678652

📥 Commits

Reviewing files that changed from the base of the PR and between 4473520 and 4a19d98.

📒 Files selected for processing (4)
  • pkg/keyspace/keyspace.go
  • pkg/keyspace/util.go
  • tools/pd-ctl/pdctl/command/keyspace_command.go
  • tools/pd-ctl/pdctl/command/keyspace_command_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/keyspace/keyspace.go

@bufferflies
Copy link
Copy Markdown
Contributor Author

Review note:

There is still another compatibility regression in the same area: MakeLabelRule was also changed from an exported helper to the private makeLabelRule.

Even though the current discussion focused on MakeKeyRanges, this has the same compatibility risk pattern: a previously exported helper became private as part of the refactor. If compatibility is the goal, MakeLabelRule should also keep its exported surface, or there needs to be a very explicit decision that this API break is acceptable.

Signed-off-by: bufferflies <1045931706@qq.com>
@bufferflies
Copy link
Copy Markdown
Contributor Author

/check-issue-triage-complete

@bufferflies
Copy link
Copy Markdown
Contributor Author

Re-review update:

I rechecked the latest delta and the MakeLabelRule compatibility issue is resolved.

  • MakeLabelRule(id uint32) is exported again.
  • The skip-raw behavior stays behind internal helpers instead of changing the exported helper signature.
  • This is aligned with the compatibility expectation discussed in the thread.

I do not have an additional compatibility finding on this specific follow-up change.

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Apr 1, 2026

@bufferflies: 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-integration-realcluster-test bff1863 link true /test pull-integration-realcluster-test

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.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 78.12500% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.96%. Comparing base (3eb99ae) to head (bff1863).
⚠️ Report is 16 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10535      +/-   ##
==========================================
+ Coverage   78.88%   78.96%   +0.08%     
==========================================
  Files         530      531       +1     
  Lines       71548    71655     +107     
==========================================
+ Hits        56439    56584     +145     
+ Misses      11092    11057      -35     
+ Partials     4017     4014       -3     
Flag Coverage Δ
unittests 78.96% <78.12%> (+0.08%) ⬆️

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.

@bufferflies
Copy link
Copy Markdown
Contributor Author

/ping @AmoebaProtozoa @rleungx

@bufferflies bufferflies requested a review from rleungx April 2, 2026 02:10
@@ -576,7 +577,15 @@ func (manager *Manager) waitKeyspaceRegionSplit(id uint32) error {

// CheckKeyspaceRegionBound checks whether the keyspace region has been split.
func (manager *Manager) CheckKeyspaceRegionBound(id uint32) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If a keyspace created with disable-raw-kv-region-split=true only has txn bounds. If the config is later changed to false, it may never pass CheckKeyspaceRegionBound again and can become effectively invisible to LoadKeyspace.

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.

Yes, the existing keyspace isn't affected by the configuration by design, and later add notes on the user docs.

Copy link
Copy Markdown
Contributor

@lhy1024 lhy1024 Apr 3, 2026

Choose a reason for hiding this comment

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

If this is intended to be immutable after keyspace creation, can we enforce that in code (for example, reject dynamic updates for this field)?

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 catch, I will create new issue to follow it #10572

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to add TODO here?

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Apr 3, 2026

@AmoebaProtozoa: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

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.

@bufferflies bufferflies requested a review from lhy1024 April 3, 2026 03:16
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Apr 3, 2026
Copy link
Copy Markdown
Contributor

@lhy1024 lhy1024 left a comment

Choose a reason for hiding this comment

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

the rest LGTM

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Apr 8, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AmoebaProtozoa, lhy1024
Once this PR has been reviewed and has the lgtm label, please assign yudongusa 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 the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 8, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Apr 8, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-08 03:22:38.945045323 +0000 UTC m=+926564.150405370: ☑️ agreed by lhy1024.

defaultGCTunerThreshold = 0.6
minGCTunerThreshold = 0
maxGCTunerThreshold = 0.9
defaultDisableRawKVRegionSplit = false
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.

Should we change to enablexxx?

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.

It may introduce configuration compatibility issues.

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.

But usually we use enablexxx for a switch.

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. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

0c88ce89 add option to skip rawkv region bound

5 participants