Skip to content

*: make table attribute labels keyspace-aware#68410

Open
ChangRui-Ryan wants to merge 2 commits into
pingcap:masterfrom
ChangRui-Ryan:changrui_cse_1968
Open

*: make table attribute labels keyspace-aware#68410
ChangRui-Ryan wants to merge 2 commits into
pingcap:masterfrom
ChangRui-Ryan:changrui_cse_1968

Conversation

@ChangRui-Ryan
Copy link
Copy Markdown
Contributor

@ChangRui-Ryan ChangRui-Ryan commented May 15, 2026

What problem does this PR solve?

Issue Number: ref #67765

Problem Summary:
In NextGen deployments, TiDB can run with a keyspace-aware TiKV codec. Table attributes are persisted as PD region label rules, but the existing rule IDs are generated only from database/table/partition names, for example schema/db/table or schema/db/table/partition.

This is not sufficient in keyspace-aware deployments. Different keyspaces may contain tables with the same database, table, and partition names. Without keyspace information in the table attribute label rule ID, label rules from different keyspaces can collide or be read back together. In addition, the rule key ranges must be encoded with the keyspace-aware TiKV codec so that PD applies the rule to the correct keyspace range.

As a result, table attribute label rules need to be keyspace-aware whenever TiDB is running in NextGen with keyspace metadata.

What changed and how does it work?

This PR makes table attribute label rules keyspace-aware in NextGen deployments when the TiKV codec contains keyspace metadata.

The core change is to centralize table attribute label rule ID generation in pkg/ddl/label:

  • Added label.UseKeyspaceAwareRules(codec).
    • It returns true when TiDB is running in NextGen and the TiKV codec has keyspace metadata.
  • Added label.NewRuleID(codec, dbName, tableName, partName).
    • In classic mode, or when the codec does not carry keyspace metadata, it keeps the existing rule ID format:
      • schema/db/table
      • schema/db/table/partition
    • In NextGen with a keyspace-aware codec, it generates:
      • keyspace/<keyspace-id>/schema/db/table
      • keyspace/<keyspace-id>/schema/db/table/partition

label.Rule.Reset now takes the TiKV codec and uses the centralized rule ID helper. When keyspace-aware rules are enabled, it also adds or updates an internal keyspace=<id> label and encodes rule ranges with codec.EncodeRegionRange(...), so the PD rule points to the correct keyspace range. When keyspace-aware rules are not enabled, it keeps the old rule ID format and the old table prefix range encoding.

All DDL table attribute lifecycle paths now pass the store codec and use the centralized rule ID helper, including:

  • ALTER TABLE ... ATTRIBUTES
  • ALTER TABLE ... PARTITION ... ATTRIBUTES
  • add/drop/truncate/reorganize/exchange partition
  • drop schema/table
  • rename table
  • truncate table
  • recover table

The information schema path is updated accordingly:

  • infosync.GetAllLabelRules now passes the current TiKV codec to the label rule manager.
  • When keyspace-aware rules are enabled, GetAllLabelRules filters PD label rules by the current keyspace prefix, so information_schema.attributes only shows table attribute rules for the current keyspace.
  • When keyspace-aware rules are not enabled, no filtering is applied, preserving the existing behavior.
  • checkRule can parse keyspace-prefixed rule IDs in NextGen.

BR backup/restore merge-option logic now also uses the same centralized rule ID helper, so DDL, backup, and restore use consistent table attribute label rule IDs in both classic and keyspace-aware modes.

For restored user-visible attributes, the internal keyspace label is hidden in NextGen, while classic mode preserves the existing behavior.

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

  • New Features

    • Keyspace-aware label rules for correct label scoping in NextGen deployments.
  • Improvements

    • More reliable label and region handling across table/partition workflows via codec-aware rule IDs.
    • Backup/restore schema merge-option handling refined for partitioned tables.
    • Conditional label restoration and listing behavior when NextGen kernel mode is enabled.
  • Tests

    • Added and updated tests covering keyspace-aware behaviors and codec-driven rule ID handling.

Review Change Stack

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. labels May 15, 2026
@pantheon-ai
Copy link
Copy Markdown

pantheon-ai Bot commented May 15, 2026

@ChangRui-Ryan 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 15, 2026
@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 15, 2026

Hi @ChangRui-Ryan. 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2a3694f6-f21f-4723-95fc-78af07d94a1d

📥 Commits

Reviewing files that changed from the base of the PR and between 8d52045 and 4da1a79.

📒 Files selected for processing (1)
  • pkg/executor/infoschema_reader.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/executor/infoschema_reader.go

📝 Walkthrough

Walkthrough

Threads a tikv.Codec into label rule ID generation and Rule.Reset, enabling optional keyspace-prefixed rule IDs and codec-driven region boundary encoding; updates DDL partition/table flows, backup/restore, infosync filtering, executor info-schema parsing, tests, and BUILD files accordingly.

Changes

Keyspace-Aware Label Rule Support

Layer / File(s) Summary
Core label rule API & tests
pkg/ddl/label/rule.go, pkg/ddl/label/rule_test.go, pkg/ddl/label/BUILD.bazel
Add KeyspacePrefix, UseKeyspaceAwareRules, NewRuleID; change Rule.Reset to accept tikv.Codec and use codec to set ID and encode region range; update tests and label BUILD deps.
DDL: table/partition flows, attributes, and tests
pkg/ddl/partition.go, pkg/ddl/table.go, pkg/ddl/schema.go, pkg/ddl/attributes.go, pkg/ddl/attributes_test.go, pkg/ddl/attributes_sql_test.go, pkg/ddl/executor.go
Thread tikv.Codec through label-rule helpers and Reset calls, replace formatted ID strings with label.NewRuleID(codec, ...), adjust rename/truncate/exchange/reorganize/partition flows and attribute serialization, and extend tests.
Infosync label manager & tests
pkg/domain/infosync/label_manager.go, pkg/domain/infosync/info.go, pkg/domain/infosync/BUILD.bazel, pkg/domain/infosync/label_manager_test.go
Add codec parameter to GetAllLabelRules, implement filterRulesByKeyspace that uses label.UseKeyspaceAwareRules(codec), update BUILD/test wiring and add test coverage.
Backup/Restore codec threading and tests
br/pkg/backup/schema.go, br/pkg/backup/schema_merge_option_test.go, br/pkg/backup/BUILD.bazel, br/pkg/restore/snap_client/client.go
Pass store codec into merge-option checks and Rule.Reset calls, use label.NewRuleID(codec, ...) for rule ID generation, update tests and backup BUILD deps.
Executor infoschema reader & tests
pkg/executor/infoschema_reader.go, pkg/executor/infoschema_reader_keyspace_test.go, pkg/executor/BUILD.bazel
Detect and parse keyspace-prefixed rule IDs in checkRule, use label.RestoreRuleID for display, add tests and update BUILD deps for keyspace handling.

Estimated code review effort:
🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels:
size/L, ok-to-test

Suggested reviewers:

  • yudongusa
  • tangenta
  • tiancaiamao
  • Leavrth

"A rabbit hopped through source and tests,
Spun codecs into tidy nests,
NewRuleID stitched keys with care,
Region bounds hex-encoded there,
Hooray — labels now know which keyspace rests!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.59% 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 clearly describes the main change: making table attribute labels keyspace-aware. It concisely summarizes the primary modification without noise.
Description check ✅ Passed The PR description comprehensively addresses the template. It includes issue reference (ref #67765), detailed problem summary, thorough explanation of changes, test coverage checkboxes (unit tests marked), and release notes section.
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

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.

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

Caution

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

⚠️ Outside diff range comments (3)
pkg/ddl/label/attributes.go (1)

102-123: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Comma logic bug when first label is skipped.

The comma is inserted based on the loop index i, not the count of actually written labels. If the first label in the slice is skipped (e.g., a keyspace label at index 0 in NextGen mode, or a db/table/partition label), the next non-skipped label at index 1 will have i > 0 true and insert a leading comma, producing output like ,"attr=val" instead of "attr=val".

In practice, Reset appends internal labels (db, table, partition, keyspace) after user-defined attributes, so this bug is unlikely to manifest. However, if labels are manually constructed in a different order (as the test in attributes_test.go lines 237-243 does), the bug could surface.

🐛 Proposed fix

Track the number of written labels instead of using the loop index:

 func RestoreRegionLabels(labels *[]pd.RegionLabel) string {
 	var sb strings.Builder
+	written := 0
 	for i, label := range *labels {
 		switch label.Key {
 		case dbKey, tableKey, partitionKey:
 			continue
 		case keyspaceKey:
 			if kerneltype.IsNextGen() {
 				continue
 			}
 		default:
 		}
 
-		if i > 0 {
+		if written > 0 {
 			sb.WriteByte(',')
 		}
 		sb.WriteByte('"')
 		sb.WriteString(RestoreRegionLabel(&label))
 		sb.WriteByte('"')
+		written++
 	}
 	return sb.String()
}
🤖 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/ddl/label/attributes.go` around lines 102 - 123, RestoreRegionLabels
incorrectly uses the loop index `i` to decide when to write commas, causing a
leading comma if early labels are skipped; change it to track the number of
actually written labels (e.g., a `written` counter) and use `written > 0` to
decide when to write a comma, incrementing `written` only when you append a
label (still honoring the existing skip logic for dbKey/tableKey/partitionKey
and keyspaceKey with kerneltype.IsNextGen) and continue to call
RestoreRegionLabel(&label) for the appended entries.
pkg/ddl/table.go (1)

1633-1653: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Pass the destination schema into updateLabelRules.

This helper rebuilds rule IDs from job.SchemaName, but checkAndRenameTables is also used by RENAME TABLES, where each entry carries its own destination schema. In a multi-table rename that targets different schemas, later iterations can recreate PD label rules under the wrong schema name. Thread the new schema name through this helper instead of reading it from the shared job object.

🤖 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/ddl/table.go` around lines 1633 - 1653, The updateLabelRules helper
currently reads job.SchemaName when rebuilding PD label rules, which breaks
multi-table RENAMEs where each table may have a different destination schema;
change updateLabelRules to accept a destination schema parameter (e.g.
destSchema string) and use that instead of job.SchemaName in calls to
label.Rule.Clone().Reset(...); update all callers (notably checkAndRenameTables
and any other places that call updateLabelRules) to pass the correct per-table
destination schema from the rename entry rather than the shared job.SchemaName
so rules are created under the intended schema.
pkg/ddl/partition.go (1)

3003-3028: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep the two schema names distinct during EXCHANGE PARTITION label updates.

This function already fetches ntDbInfo and ptDbInfo, so the two tables are not guaranteed to live in the same schema. The rule lookup/reset still uses job.SchemaName for both sides, which will miss the partition rule or recreate it under the wrong schema when the exchange crosses schemas. Build/reset ntr with ntDbInfo.Name.L and ptr with ptDbInfo.Name.L.

🤖 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/ddl/partition.go` around lines 3003 - 3028, The code builds and resets
label rule IDs and rules using job.SchemaName for both tables, which fails when
nt and pt live in different schemas; change the code that creates ntrID and
ptrID (label.NewRuleID) to use ntDbInfo.Name.L for the nt rule and
ptDbInfo.Name.L for the pt rule, and likewise update the ntr.Clone().Reset(...)
and ptr.Clone().Reset(...) calls to pass the matching schema name
(ntDbInfo.Name.L for ntr resets, ptDbInfo.Name.L for ptr resets) so lookups and
resets target the correct schemas.
🧹 Nitpick comments (3)
pkg/executor/infoschema_reader_keyspace_test.go (1)

46-81: ⚡ Quick win

Add negative ID-format cases to prevent parser regressions.

Please add invalid IDs (e.g. wrong root prefix, malformed keyspace prefix) to ensure checkRule fails fast when the ID shape is not table-attribute-compatible.

✅ Suggested test extension
 tests := []struct {
 	name          string
 	ruleID        string
 	wantDB        string
 	wantTable     string
 	wantPartition string
+	wantErr       bool
 }{
+	{
+		name:    "invalid non-keyspace prefix",
+		ruleID:  "foo/test/t1",
+		wantErr: true,
+	},
 	{
 		name:      "non-keyspace table",
 		ruleID:    fmt.Sprintf("%s/test/t1", label.IDPrefix),
 		wantDB:    "test",
 		wantTable: "t1",
 	},
+	{
+		name:    "invalid keyspace inner prefix",
+		ruleID:  fmt.Sprintf("%s/42/foo/test/t2", label.KeyspacePrefix),
+		wantErr: true,
+	},
 	// ...
 }

 for _, tc := range tests {
 	t.Run(tc.name, func(t *testing.T) {
 		dbName, tableName, partitionName, err := checkRule(newRule(tc.ruleID))
+		if tc.wantErr {
+			require.Error(t, err)
+			return
+		}
 		require.NoError(t, err)
 		require.Equal(t, tc.wantDB, dbName)
 		require.Equal(t, tc.wantTable, tableName)
 		require.Equal(t, tc.wantPartition, partitionName)
 	})
 }
🤖 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/executor/infoschema_reader_keyspace_test.go` around lines 46 - 81, Add
negative test cases to pkg/executor/infoschema_reader_keyspace_test.go to assert
checkRule returns an error for malformed IDs: extend the tests slice (near the
existing entries that use newRule and checkRule) with cases like wrong root
prefix, malformed keyspace prefix, missing ID parts, and non-table shapes (e.g.,
malformed "%s/test" or "%s/42/%s/test" variants) and in the t.Run for those
cases call checkRule(newRule(tc.ruleID)) and require.Error(t, err) (and
optionally require.Empty for db/table/partition) so the parser fails fast on
invalid ID shapes.
pkg/ddl/label/attributes_test.go (1)

237-243: ⚡ Quick win

Missing test coverage for reversed label ordering.

The test only validates the case where merge_option=allow precedes keyspace=42. Consider adding a test case with reversed ordering (keyspace=42, then merge_option=allow) to verify the comma logic handles skipped-first-label scenarios correctly. This would catch the comma insertion bug flagged in RestoreRegionLabels.

📋 Suggested additional test case
// Test reversed ordering to verify comma logic
if kerneltype.IsNextGen() {
	output := RestoreRegionLabels(&[]pd.RegionLabel{input6, input1})
	require.Equal(t, `"merge_option=allow"`, output)
} else {
	output := RestoreRegionLabels(&[]pd.RegionLabel{input6, input1})
	require.Equal(t, `"keyspace=42","merge_option=allow"`, output)
}
🤖 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/ddl/label/attributes_test.go` around lines 237 - 243, Add a test that
covers reversed label ordering to ensure RestoreRegionLabels handles commas when
the first label is skipped: call RestoreRegionLabels with the slice order
swapped (use the existing pd.RegionLabel fixtures input6 then input1) and assert
the expected strings—when kerneltype.IsNextGen() expect `"merge_option=allow"`
and otherwise expect `"keyspace=42","merge_option=allow"`; place this alongside
the existing test so it exercises RestoreRegionLabels with the reversed input
order.
pkg/ddl/label/rule.go (1)

173-179: 💤 Low value

Minor inefficiency: Classic-mode keys are computed then discarded in keyspace mode.

Lines 173-174 unconditionally compute startKey/endKey using classic encoding, then lines 175-179 immediately overwrite them when useKeyspace is true. Consider restructuring with an if-else to avoid the wasted computation.

♻️ Optional refactor to eliminate redundant encoding
-		startKey := codec.EncodeBytes(nil, tablecodec.GenTablePrefix(ids[i]))
-		endKey := codec.EncodeBytes(nil, tablecodec.GenTablePrefix(ids[i]+1))
+		var startKey, endKey []byte
 		if useKeyspace {
-			// Label rules are consumed as region boundary keys, so V2 must encode
-			// the whole outer key instead of prefixing a mem-encoded table key.
 			startKey, endKey = tikvCodec.EncodeRegionRange(tablecodec.GenTablePrefix(ids[i]), tablecodec.GenTablePrefix(ids[i]+1))
+		} else {
+			startKey = codec.EncodeBytes(nil, tablecodec.GenTablePrefix(ids[i]))
+			endKey = codec.EncodeBytes(nil, tablecodec.GenTablePrefix(ids[i]+1))
 		}
🤖 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/ddl/label/rule.go` around lines 173 - 179, The current code
unconditionally computes classic-mode keys with codec.EncodeBytes into
startKey/endKey and then overwrites them when useKeyspace is true; change to an
if-else so you only compute the classic keys when useKeyspace is false and only
call tikvCodec.EncodeRegionRange(tablecodec.GenTablePrefix(ids[i]),
tablecodec.GenTablePrefix(ids[i]+1)) when useKeyspace is true, referencing the
same symbols (startKey, endKey, codec.EncodeBytes, tikvCodec.EncodeRegionRange,
tablecodec.GenTablePrefix, ids[i]) to avoid wasted encoding work.
🤖 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/executor/infoschema_reader.go`:
- Around line 4166-4172: The validation in checkRule incorrectly gates the
label.IDPrefix check behind idOffset > 0, allowing IDs like "foo/db/t" to be
parsed as table rules; change the guard so the prefix and minimum length are
validated regardless of idOffset (i.e., ensure s[idOffset] == label.IDPrefix and
len(s) >= idOffset+3 for table rules), and keep setting dbName = s[idOffset+1]
and tableName = s[idOffset+2] only after this stricter check; reference
checkRule, idOffset, s, label.IDPrefix, rule.ID, dbName and tableName when
making the fix.

---

Outside diff comments:
In `@pkg/ddl/label/attributes.go`:
- Around line 102-123: RestoreRegionLabels incorrectly uses the loop index `i`
to decide when to write commas, causing a leading comma if early labels are
skipped; change it to track the number of actually written labels (e.g., a
`written` counter) and use `written > 0` to decide when to write a comma,
incrementing `written` only when you append a label (still honoring the existing
skip logic for dbKey/tableKey/partitionKey and keyspaceKey with
kerneltype.IsNextGen) and continue to call RestoreRegionLabel(&label) for the
appended entries.

In `@pkg/ddl/partition.go`:
- Around line 3003-3028: The code builds and resets label rule IDs and rules
using job.SchemaName for both tables, which fails when nt and pt live in
different schemas; change the code that creates ntrID and ptrID
(label.NewRuleID) to use ntDbInfo.Name.L for the nt rule and ptDbInfo.Name.L for
the pt rule, and likewise update the ntr.Clone().Reset(...) and
ptr.Clone().Reset(...) calls to pass the matching schema name (ntDbInfo.Name.L
for ntr resets, ptDbInfo.Name.L for ptr resets) so lookups and resets target the
correct schemas.

In `@pkg/ddl/table.go`:
- Around line 1633-1653: The updateLabelRules helper currently reads
job.SchemaName when rebuilding PD label rules, which breaks multi-table RENAMEs
where each table may have a different destination schema; change
updateLabelRules to accept a destination schema parameter (e.g. destSchema
string) and use that instead of job.SchemaName in calls to
label.Rule.Clone().Reset(...); update all callers (notably checkAndRenameTables
and any other places that call updateLabelRules) to pass the correct per-table
destination schema from the rename entry rather than the shared job.SchemaName
so rules are created under the intended schema.

---

Nitpick comments:
In `@pkg/ddl/label/attributes_test.go`:
- Around line 237-243: Add a test that covers reversed label ordering to ensure
RestoreRegionLabels handles commas when the first label is skipped: call
RestoreRegionLabels with the slice order swapped (use the existing
pd.RegionLabel fixtures input6 then input1) and assert the expected strings—when
kerneltype.IsNextGen() expect `"merge_option=allow"` and otherwise expect
`"keyspace=42","merge_option=allow"`; place this alongside the existing test so
it exercises RestoreRegionLabels with the reversed input order.

In `@pkg/ddl/label/rule.go`:
- Around line 173-179: The current code unconditionally computes classic-mode
keys with codec.EncodeBytes into startKey/endKey and then overwrites them when
useKeyspace is true; change to an if-else so you only compute the classic keys
when useKeyspace is false and only call
tikvCodec.EncodeRegionRange(tablecodec.GenTablePrefix(ids[i]),
tablecodec.GenTablePrefix(ids[i]+1)) when useKeyspace is true, referencing the
same symbols (startKey, endKey, codec.EncodeBytes, tikvCodec.EncodeRegionRange,
tablecodec.GenTablePrefix, ids[i]) to avoid wasted encoding work.

In `@pkg/executor/infoschema_reader_keyspace_test.go`:
- Around line 46-81: Add negative test cases to
pkg/executor/infoschema_reader_keyspace_test.go to assert checkRule returns an
error for malformed IDs: extend the tests slice (near the existing entries that
use newRule and checkRule) with cases like wrong root prefix, malformed keyspace
prefix, missing ID parts, and non-table shapes (e.g., malformed "%s/test" or
"%s/42/%s/test" variants) and in the t.Run for those cases call
checkRule(newRule(tc.ruleID)) and require.Error(t, err) (and optionally
require.Empty for db/table/partition) so the parser fails fast on invalid ID
shapes.
🪄 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: 45c66364-70b3-4a37-97dc-f557507c3cb6

📥 Commits

Reviewing files that changed from the base of the PR and between e5ca0bb and b81e920.

📒 Files selected for processing (20)
  • br/pkg/backup/BUILD.bazel
  • br/pkg/backup/schema.go
  • br/pkg/backup/schema_merge_option_test.go
  • br/pkg/restore/snap_client/client.go
  • pkg/ddl/executor.go
  • pkg/ddl/label/BUILD.bazel
  • pkg/ddl/label/attributes.go
  • pkg/ddl/label/attributes_test.go
  • pkg/ddl/label/rule.go
  • pkg/ddl/label/rule_test.go
  • pkg/ddl/partition.go
  • pkg/ddl/schema.go
  • pkg/ddl/table.go
  • pkg/domain/infosync/BUILD.bazel
  • pkg/domain/infosync/info.go
  • pkg/domain/infosync/label_manager.go
  • pkg/domain/infosync/label_manager_test.go
  • pkg/executor/BUILD.bazel
  • pkg/executor/infoschema_reader.go
  • pkg/executor/infoschema_reader_keyspace_test.go

Comment thread pkg/executor/infoschema_reader.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 56.92308% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.7175%. Comparing base (5ffa989) to head (4da1a79).
⚠️ Report is 26 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #68410        +/-   ##
================================================
- Coverage   77.2803%   76.7175%   -0.5628%     
================================================
  Files          2010       2046        +36     
  Lines        555624     575910     +20286     
================================================
+ Hits         429388     441824     +12436     
- Misses       125316     131440      +6124     
- Partials        920       2646      +1726     
Flag Coverage Δ
integration 46.3220% <56.9230%> (+6.5280%) ⬆️

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

Components Coverage Δ
dumpling 60.4888% <ø> (ø)
parser ∅ <ø> (∅)
br 65.7421% <100.0000%> (+2.7342%) ⬆️
🚀 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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 18, 2026
case dbKey, tableKey, partitionKey:
continue
case keyspaceKey:
if kerneltype.IsNextGen() {
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.

why skipped in nextgen

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.

keyspace is an internal label injected by TiDB for keyspace-aware table attribute label rules. It is not part of the user-specified table attributes, so information_schema.attributes should hide it in NextGen, similar to how we already hide the internal db/table/partition labels.

r = append(r, (*label.Rule)(labelRule))
}
return r, nil
return filterRulesByKeyspace(r, codec), nil
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.

this feature would be better be implemented at PD side where we make those rules keyspace scoped, instead of difference them by prefix, and encoding/filtering at client side

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.

Agree this would be cleaner in PD long term.

For this PR, the current PD label-rule API is still global and has no keyspace context. Since TiDB already generates rule IDs and encoded region ranges with the store codec, keyspace/<id>/ prefixing plus client-side filtering is the minimal compatible fix. Native PD-side scoping can be a follow-up.

Comment thread pkg/executor/infoschema_reader.go Outdated

dbName = s[idOffset+1]
tableName = s[idOffset+2]
if len(s) > idOffset+3 {
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.

Suggested change
if len(s) > idOffset+3 {
if idOffset+3 < len(s) {

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. I will take the suggestion.

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 19, 2026
@D3Hunter
Copy link
Copy Markdown
Contributor

/hold

please fix existing comments

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 19, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

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

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 19, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 19, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-05-19 06:17:27.87721984 +0000 UTC m=+244977.381350506: ☑️ agreed by D3Hunter.
  • 2026-05-19 07:49:04.655858377 +0000 UTC m=+250474.159989043: ☑️ agreed by YuJuncen.

@D3Hunter
Copy link
Copy Markdown
Contributor

/unhold

@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 May 19, 2026
@ChangRui-Ryan
Copy link
Copy Markdown
Contributor Author

/retest

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 19, 2026

@ChangRui-Ryan: 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.

Details

In response to this:

/retest

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.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 19, 2026

@ChangRui-Ryan: 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
idc-jenkins-ci-tidb/check_dev_2 4da1a79 link unknown /test check-dev2

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.

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants