Skip to content

vars: validate some vars for tidb x#68196

Open
ekexium wants to merge 2 commits into
pingcap:masterfrom
ekexium:validate-tidbx-vars
Open

vars: validate some vars for tidb x#68196
ekexium wants to merge 2 commits into
pingcap:masterfrom
ekexium:validate-tidbx-vars

Conversation

@ekexium
Copy link
Copy Markdown
Member

@ekexium ekexium commented May 7, 2026

What problem does this PR solve?

Issue Number: close #60697

Problem Summary:

  • Disable pipelined dml and follower read in TiDB X

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.

Disallow non-leader tidb_replica_read. Disallow pipelined dml.

Summary by CodeRabbit

  • New Features

    • NextGen kernel mode now rejects non‑leader replica‑read modes and the "bulk" DML type with validation errors.
  • Dependencies

    • TiKV client-go v2 dependency updated to a newer pseudo‑version.
  • Tests

    • Tests added/adjusted to cover NextGen validation and to skip or gate scenarios unsupported in NextGen.

Review Change Stack

Signed-off-by: Ziqian Qin <eke@fastmail.com>
Copilot AI review requested due to automatic review settings May 7, 2026 07:47
@ti-chi-bot ti-chi-bot Bot added the release-note-none Denotes a PR that doesn't merit a release note. label May 7, 2026
@pantheon-ai
Copy link
Copy Markdown

pantheon-ai Bot commented May 7, 2026

@ekexium 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 May 7, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 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: fd9daef6-4d21-4803-9f42-512f4d9c8000

📥 Commits

Reviewing files that changed from the base of the PR and between f005b8d and 86bfa7b.

📒 Files selected for processing (9)
  • pkg/executor/distsql_test.go
  • pkg/executor/executor_failpoint_test.go
  • pkg/executor/test/distsqltest/BUILD.bazel
  • pkg/executor/test/distsqltest/distsql_test.go
  • pkg/session/test/variable/BUILD.bazel
  • pkg/session/test/variable/variable_test.go
  • pkg/sessiontxn/isolation/main_test.go
  • pkg/sessiontxn/staleread/BUILD.bazel
  • pkg/sessiontxn/staleread/provider_test.go
✅ Files skipped from review due to trivial changes (2)
  • pkg/sessiontxn/staleread/BUILD.bazel
  • pkg/session/test/variable/BUILD.bazel
🚧 Files skipped from review as they are similar to previous changes (6)
  • pkg/executor/distsql_test.go
  • pkg/session/test/variable/variable_test.go
  • pkg/sessiontxn/isolation/main_test.go
  • pkg/executor/test/distsqltest/distsql_test.go
  • pkg/executor/executor_failpoint_test.go
  • pkg/sessiontxn/staleread/provider_test.go

📝 Walkthrough

Walkthrough

This PR bumps the tikv client-go/v2 dependency, adds Validation hooks to disallow non-leader TiDBReplicaRead modes and the bulk TiDBDMLType under the NextGen kernel, and updates tests and BUILD deps to gate or assert those restrictions.

Changes

NextGen Feature Restrictions

Layer / File(s) Summary
Dependency Update
DEPS.bzl, go.mod
Updated github.com/tikv/client-go/v2 pseudo-version and checksum (bump to ...-839228f8c022).
System Variable Validation
pkg/sessionctx/variable/sysvar.go
Added Validation hooks: disallow non-leader for TiDBReplicaRead and disallow bulk for TiDBDMLType when kerneltype.IsNextGen() is true.
NextGen Test Cases
pkg/sessionctx/variable/nextgen_test.go
Added TestTiDBDMLTypeInNextGen and TestTiDBReplicaReadInNextGen to assert acceptance/rejection and effective mappings in NextGen.
System Variable Tests
pkg/sessionctx/variable/sysvar_test.go
Updated TestTiDBReplicaRead to branch expectations on kerneltype.IsNextGen(): expect ErrNotSupportedInNextGen in NextGen, otherwise previous behavior.
Utility Tests
pkg/sessionctx/variable/varsutil_test.go
Updated TestVarsutil to conditionally assert NextGen rejection or validate internal v.replicaRead mappings in non-NextGen mode.
DistSQL Test Updates
pkg/executor/test/distsqltest/*, pkg/executor/distsql_test.go
Added //pkg/config/kerneltype dep and adjusted replicaReadModes / skipped TestAdaptiveClosestRead when in NextGen mode.
Executor Failpoint Tests
pkg/executor/executor_failpoint_test.go
Guarded stale-read explain/analyze assertions to run only when !kerneltype.IsNextGen().
Session & StaleRead Test Skips
pkg/session/test/variable/*, pkg/sessiontxn/*, pkg/sessiontxn/staleread/*
Added kerneltype imports/BUILD deps and t.Skip or gating to avoid running follower/closest replica-read scenarios in NextGen mode.

Sequence Diagram(s)

sequenceDiagram
  participant User as Client/API
  participant Sysvar as sysvar.TiDBReplicaRead/TiDBDMLType
  participant Kernel as kerneltype.IsNextGen
  User->>Sysvar: SET replica_read / SET dml_type
  Sysvar->>Kernel: IsNextGen()
  Kernel-->>Sysvar: true/false
  Sysvar-->>User: accept or ErrNotSupportedInNextGen
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • joechenrh
  • terry1purcell
  • hawkingrei

🐰 I hopped through code with nimble cheer,
Leaders only now, no followers near,
Bulk DML tucked away, skipped by the test,
Builds and deps updated — we did our best,
A rabbit claps for rules kept clear.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'vars: validate some vars for tidb x' is vague and uses generic language that doesn't clearly convey what specific variables are being validated or why. Use a more descriptive title like 'sessionctx/variable: validate tidb_replica_read and tidb_dml_type in TiDB X' to clearly indicate which variables are affected and the purpose of the changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required issue number (#60697), a problem summary explaining the feature disabling, acknowledgment of unit tests being added, and a relevant release note.
Linked Issues check ✅ Passed The PR successfully implements two of the three main objectives from #60697: disallowing non-leader tidb_replica_read and disallowing pipelined DML via validation hooks in TiDB X. The code changes with validation checks and test coverage align with the linked issue requirements.
Out of Scope Changes check ✅ Passed All changes are scoped to validating tidb_replica_read and tidb_dml_type variables in TiDB X mode and updating related tests. The dependency update (DEPS.bzl/go.mod) is a supporting change. No unrelated modifications were introduced.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds NextGen (TiDB X) restrictions to session/system variables so that features incompatible with the NextGen kernel cannot be enabled via sysvars, aligning runtime behavior with the NextGen feature set.

Changes:

  • Add NextGen-only validation for tidb_replica_read to reject any mode other than leader.
  • Add NextGen-only validation for tidb_dml_type to reject bulk mode.
  • Update and add unit tests (including //go:build nextgen coverage) to assert the new validation behavior.
  • Bump github.com/tikv/client-go/v2 dependency and Bazel DEPS.bzl metadata accordingly.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/sessionctx/variable/sysvar.go Adds NextGen validation hooks for tidb_replica_read and tidb_dml_type.
pkg/sessionctx/variable/varsutil_test.go Updates session var tests to expect NextGen validation failures for replica read follower/mixed modes.
pkg/sessionctx/variable/sysvar_test.go Updates sysvar validation test to branch on NextGen vs Classic behavior for tidb_replica_read.
pkg/sessionctx/variable/nextgen_test.go Adds NextGen-only tests verifying tidb_dml_type and tidb_replica_read are constrained as intended.
go.mod Bumps github.com/tikv/client-go/v2 pseudo-version.
go.sum Updates checksums for the bumped client-go version.
DEPS.bzl Updates Bazel go_repository strip_prefix/sha256/urls for the new client-go version.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.8860%. Comparing base (84d8269) to head (86bfa7b).
⚠️ Report is 23 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #68196        +/-   ##
================================================
- Coverage   77.7288%   76.8860%   -0.8429%     
================================================
  Files          1990       1973        -17     
  Lines        551970     554613      +2643     
================================================
- Hits         429040     426420      -2620     
- Misses       122010     128096      +6086     
+ Partials        920         97       -823     
Flag Coverage Δ
integration 41.3352% <77.7777%> (+1.5334%) ⬆️

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

Components Coverage Δ
dumpling 60.4888% <ø> (ø)
parser ∅ <ø> (∅)
br 50.0597% <ø> (-13.0338%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ekexium ekexium requested a review from cfzjywxk May 7, 2026 08:15
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 7, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cfzjywxk
Once this PR has been reviewed and has the lgtm label, please assign terry1purcell 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 May 7, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 7, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-05-07 08:21:46.934461058 +0000 UTC m=+342379.807811050: ☑️ agreed by cfzjywxk.

@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 May 7, 2026
@ekexium
Copy link
Copy Markdown
Member Author

ekexium commented May 11, 2026

/retest

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)
pkg/executor/test/distsqltest/distsql_test.go (1)

133-140: ⚡ Quick win

Consider adding a comment explaining the next-gen restriction.

The conditional logic correctly restricts replica read modes when running on next-gen kernels, aligning with the PR objective. However, future maintainers would benefit from a brief comment explaining why non-leader modes are excluded for next-gen (e.g., "Next-gen TiKV does not support non-leader replica reads").

📝 Suggested comment
 	replicaReadModes := []string{
 		"leader",
 	}
+	// Next-gen kernel does not support non-leader replica read modes.
 	if !kerneltype.IsNextGen() {
 		replicaReadModes = append(replicaReadModes,
🤖 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/test/distsqltest/distsql_test.go` around lines 133 - 140, Add a
brief explanatory comment above the kerneltype.IsNextGen() conditional to
clarify why non-leader replica read modes are omitted for next-gen kernels
(e.g., that Next-gen TiKV does not support non-leader replica reads or that
replica reads are handled differently), so future maintainers understand the
restriction; locate the check using kerneltype.IsNextGen() and the
replicaReadModes slice to add the comment.
🤖 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.

Nitpick comments:
In `@pkg/executor/test/distsqltest/distsql_test.go`:
- Around line 133-140: Add a brief explanatory comment above the
kerneltype.IsNextGen() conditional to clarify why non-leader replica read modes
are omitted for next-gen kernels (e.g., that Next-gen TiKV does not support
non-leader replica reads or that replica reads are handled differently), so
future maintainers understand the restriction; locate the check using
kerneltype.IsNextGen() and the replicaReadModes slice to add the comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fcb2f961-7d58-431a-8039-1ff36edc755a

📥 Commits

Reviewing files that changed from the base of the PR and between 3310e2e and 4cbed3c.

📒 Files selected for processing (1)
  • pkg/executor/test/distsqltest/distsql_test.go

@ekexium ekexium force-pushed the validate-tidbx-vars branch from 4cbed3c to f005b8d Compare May 11, 2026 11:38
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)
pkg/executor/executor_failpoint_test.go (1)

810-818: 💤 Low value

Correct conditional gating for NextGen replica-read restrictions.

The stale-read test is correctly skipped on NextGen kernels where non-leader tidb_replica_read modes (like 'closest-replicas') are disabled per the PR objectives.

Consider adding a brief comment above line 810 explaining why this test is skipped on NextGen for future maintainability:

// Skip stale read with replica read test on NextGen where non-leader replica reads are disabled.
if !kerneltype.IsNextGen() {
🤖 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/executor_failpoint_test.go` around lines 810 - 818, Add a
one-line comment explaining why the stale-read replica test is skipped when
NextGen is enabled: place it immediately above the existing if
!kerneltype.IsNextGen() check in executor_failpoint_test.go, referencing that
NextGen disables non-leader replica reads (so modes like 'closest-replicas' are
not applicable). Keep the comment short and specific (e.g., "Skip stale read
with replica read test on NextGen where non-leader replica reads are
disabled."), leaving the surrounding code calling waitUntilReadTSSafe and the
explain/require assertions unchanged.
🤖 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.

Nitpick comments:
In `@pkg/executor/executor_failpoint_test.go`:
- Around line 810-818: Add a one-line comment explaining why the stale-read
replica test is skipped when NextGen is enabled: place it immediately above the
existing if !kerneltype.IsNextGen() check in executor_failpoint_test.go,
referencing that NextGen disables non-leader replica reads (so modes like
'closest-replicas' are not applicable). Keep the comment short and specific
(e.g., "Skip stale read with replica read test on NextGen where non-leader
replica reads are disabled."), leaving the surrounding code calling
waitUntilReadTSSafe and the explain/require assertions unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7e2adce6-3c60-4473-badf-d3318f23a554

📥 Commits

Reviewing files that changed from the base of the PR and between 4cbed3c and f005b8d.

📒 Files selected for processing (6)
  • pkg/executor/distsql_test.go
  • pkg/executor/executor_failpoint_test.go
  • pkg/executor/test/distsqltest/distsql_test.go
  • pkg/session/test/variable/variable_test.go
  • pkg/sessiontxn/isolation/main_test.go
  • pkg/sessiontxn/staleread/provider_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/executor/test/distsqltest/distsql_test.go

Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium ekexium force-pushed the validate-tidbx-vars branch from f005b8d to 86bfa7b Compare May 11, 2026 14:14
@ekexium
Copy link
Copy Markdown
Member Author

ekexium commented May 12, 2026

/retest

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 12, 2026

@ekexium: 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-next-gen 86bfa7b link true /test pull-integration-realcluster-test-next-gen

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

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.

Disable features that are not compatible with next-gen

3 participants