Skip to content

vars: validate some vars for tidb x (#68196)#68458

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:release-nextgen-202603from
ti-chi-bot:cherry-pick-68196-to-release-nextgen-202603
May 25, 2026
Merged

vars: validate some vars for tidb x (#68196)#68458
ti-chi-bot[bot] merged 2 commits into
pingcap:release-nextgen-202603from
ti-chi-bot:cherry-pick-68196-to-release-nextgen-202603

Conversation

@ti-chi-bot
Copy link
Copy Markdown
Member

@ti-chi-bot ti-chi-bot commented May 18, 2026

This is an automated cherry-pick of #68196

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

    • Added support for a next-generation kernel mode.
  • Bug Fixes

    • Enforced session variable restrictions in next-gen: replica read limited to "leader"; bulk DML rejected and coerced to standard.
  • Chores

    • Updated TiKV client dependency to a newer pinned revision.

Review Change Stack

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202603 labels May 18, 2026
@ti-chi-bot
Copy link
Copy Markdown
Member Author

@ekexium This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 18, 2026

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

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 ti-community-infra/tichi repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

This PR enforces next-gen kernel restrictions: updates TiKV client pins, adds validation to TiDBReplicaRead and TiDBDMLType to reject unsupported values on next-gen, and updates many tests to skip or gate replica-read and stale-read assertions when kerneltype.IsNextGen().

Changes

NextGen Feature Gating: Replica Read and DML Type Restrictions

Layer / File(s) Summary
Dependency Updates
DEPS.bzl, go.mod
Pinned github.com/tikv/client-go/v2 updated (sha256/strip_prefix/urls in DEPS.bzl, pseudo-version in go.mod).
NextGen Sysvar Validation Implementation
pkg/sessionctx/variable/sysvar.go
Adds Validation hooks: TiDBReplicaRead now rejects non-"leader" values on next-gen; TiDBDMLType now rejects "bulk" on next-gen, returning ErrNotSupportedInNextGen and coercing to defaults.
NextGen Sysvar Validation Tests
pkg/sessionctx/variable/nextgen_test.go, pkg/sessionctx/variable/sysvar_test.go, pkg/sessionctx/variable/varsutil_test.go
New tests TestTiDBDMLTypeInNextGen and TestTiDBReplicaReadInNextGen; existing sysvar tests branch expectations based on kerneltype.IsNextGen().
Executor & Unit Test Gating
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, related BUILD files
Adds kerneltype imports; TestAdaptiveClosestRead skips on next-gen; stale-read assertions in executor tests are gated by !kerneltype.IsNextGen(); replica-read mode lists are conditionally extended only on non-next-gen.
StaleRead & Integration Test Gating
pkg/sessiontxn/staleread/provider_test.go, pkg/sessiontxn/isolation/main_test.go, tests/realtikvtest/*, related BUILD files
Adds kerneltype imports; multiple real-TiKV and stale-read tests either skip entirely on next-gen or wrap replica-read assertions behind !kerneltype.IsNextGen().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • pingcap/tidb#68388: Overlapping sysvar validation and test condition updates for next-gen replica-read/DML restrictions.
  • pingcap/tidb#67811: Similar dependency bumps for github.com/tikv/client-go/v2 in DEPS.bzl/go.mod.
  • pingcap/tidb#68196: Implements next-gen validation for TiDBReplicaRead/TiDBDMLType with corresponding test changes.

Suggested labels

cherry-pick-approved, ok-to-test, approved, lgtm

Suggested reviewers

  • zyguan
  • cfzjywxk

Poem

🐰 I hopped through tests and pinned a new commit,
Kept leader reads simple, let followers sit.
Bulk DML tucked away,
Tests skip what can't play—
A tidy next-gen hop, nimble and lit!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately identifies the main change of adding variable validations for TiDB X, though it is somewhat abbreviated.
Linked Issues check ✅ Passed PR successfully disables non-leader replica read [#60697] and pipelined DML, matching primary objectives; follower read modes are conditionally skipped and TiDBDMLType bulk setting is rejected in next-gen mode.
Out of Scope Changes check ✅ Passed All changes scope to disabling non-leader replica read and pipelined DML for next-gen; tikv dependency update and test gating are necessary supporting changes.
Description check ✅ Passed PR description follows the template with issue reference, problem summary, test selection, and release note. However, the 'What changed and how does it work?' section is empty.

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

🧹 Nitpick comments (1)
pkg/sessionctx/variable/varsutil_test.go (1)

384-393: ⚡ Quick win

Assert post-error replica-read state in next-gen branches.

These branches validate the error, but they don’t verify that session state remains "leader" after rejected assignments. Adding that check prevents false positives where an error is returned but state is still mutated.

Proposed test hardening
 err = v.SetSystemVar(vardef.TiDBReplicaRead, "follower")
 if kerneltype.IsNextGen() {
 	require.Error(t, err)
 	require.True(t, ErrNotSupportedInNextGen.Equal(err))
+	val, err = v.GetSessionOrGlobalSystemVar(context.Background(), vardef.TiDBReplicaRead)
+	require.NoError(t, err)
+	require.Equal(t, "leader", val)
+	require.Equal(t, kv.ReplicaReadLeader, v.replicaRead)
 } else {
 	require.NoError(t, err)
 	val, err = v.GetSessionOrGlobalSystemVar(context.Background(), vardef.TiDBReplicaRead)
 	require.NoError(t, err)
 	require.Equal(t, "follower", val)
 	require.Equal(t, kv.ReplicaReadFollower, v.replicaRead)
 }
@@
 err = v.SetSystemVar(vardef.TiDBReplicaRead, "leader-and-follower")
 if kerneltype.IsNextGen() {
 	require.Error(t, err)
 	require.True(t, ErrNotSupportedInNextGen.Equal(err))
+	val, err = v.GetSessionOrGlobalSystemVar(context.Background(), vardef.TiDBReplicaRead)
+	require.NoError(t, err)
+	require.Equal(t, "leader", val)
+	require.Equal(t, kv.ReplicaReadLeader, v.replicaRead)
 } else {
 	require.NoError(t, err)
 	val, err = v.GetSessionOrGlobalSystemVar(context.Background(), vardef.TiDBReplicaRead)
 	require.NoError(t, err)
 	require.Equal(t, "leader-and-follower", val)
 	require.Equal(t, kv.ReplicaReadMixed, v.replicaRead)
 }

Also applies to: 401-410

🤖 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/sessionctx/variable/varsutil_test.go` around lines 384 - 393, The test
currently only asserts an error in the kerneltype.IsNextGen() branch but does
not verify that the session state was not mutated; update the failing-branch
assertions to also read back the TiDBReplicaRead state and assert it is still
"leader" and that v.replicaRead == kv.ReplicaReadLeader (use
v.GetSessionOrGlobalSystemVar(ctx, vardef.TiDBReplicaRead) and check
v.replicaRead) so both the error and unchanged session state are verified; make
the same addition in the other similar branch around lines 401-410 to harden
that assertion too.
🤖 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 `@DEPS.bzl`:
- Around line 7808-7824: Remove the leftover merge-conflict markers in DEPS.bzl
and leave a single valid dependency block for github.com/tikv/client-go/v2:
delete the lines starting with <<<<<<<, =======, and >>>>>>> and ensure only one
set of sha256, strip_prefix, and urls remains (pick the correct/expected values
for sha256, strip_prefix, and urls for the chosen revision) so the file parses
cleanly for Bazel.

In `@go.mod`:
- Around line 127-133: go.mod contains leftover git conflict markers (<<<<<<<,
=======, >>>>>>>) that break parsing; open the go.mod and remove the conflict
markers and duplicate entries, pick the correct version for
github.com/tikv/client-go/v2 and github.com/tikv/pd/client (or reconcile to the
desired versions used elsewhere), leaving only one line per module (e.g., a
single chosen version for github.com/tikv/client-go/v2 and for
github.com/tikv/pd/client) and run go mod tidy to verify the file is valid.

---

Nitpick comments:
In `@pkg/sessionctx/variable/varsutil_test.go`:
- Around line 384-393: The test currently only asserts an error in the
kerneltype.IsNextGen() branch but does not verify that the session state was not
mutated; update the failing-branch assertions to also read back the
TiDBReplicaRead state and assert it is still "leader" and that v.replicaRead ==
kv.ReplicaReadLeader (use v.GetSessionOrGlobalSystemVar(ctx,
vardef.TiDBReplicaRead) and check v.replicaRead) so both the error and unchanged
session state are verified; make the same addition in the other similar branch
around lines 401-410 to harden that assertion too.
🪄 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: 2fe53fe6-5492-4864-9d4e-3d3c3157d764

📥 Commits

Reviewing files that changed from the base of the PR and between 56ea7a2 and 045566e.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (18)
  • DEPS.bzl
  • go.mod
  • 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/sessionctx/variable/nextgen_test.go
  • pkg/sessionctx/variable/sysvar.go
  • pkg/sessionctx/variable/sysvar_test.go
  • pkg/sessionctx/variable/varsutil_test.go
  • pkg/sessiontxn/isolation/main_test.go
  • pkg/sessiontxn/staleread/BUILD.bazel
  • pkg/sessiontxn/staleread/provider_test.go
  • tests/realtikvtest/sessiontest/session_fail_test.go
  • tests/realtikvtest/txntest/replica_read_test.go
  • tests/realtikvtest/txntest/stale_read_test.go

Comment thread DEPS.bzl Outdated
Comment thread go.mod Outdated
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium
Copy link
Copy Markdown
Member

ekexium commented May 21, 2026

/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 21, 2026
@ekexium ekexium requested review from cfzjywxk and zyguan May 21, 2026 14:13
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 55.55556% with 12 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-nextgen-202603@56ea7a2). Learn more about missing BASE report.

Additional details and impacted files
@@                     Coverage Diff                     @@
##             release-nextgen-202603     #68458   +/-   ##
===========================================================
  Coverage                          ?   77.0918%           
===========================================================
  Files                             ?       1966           
  Lines                             ?     548272           
  Branches                          ?          0           
===========================================================
  Hits                              ?     422673           
  Misses                            ?     124747           
  Partials                          ?        852           
Flag Coverage Δ
unit 76.2112% <55.5555%> (?)

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

Components Coverage Δ
dumpling 61.5065% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 61.0132% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ekexium
Copy link
Copy Markdown
Member

ekexium commented May 21, 2026

/retest

2 similar comments
@ekexium
Copy link
Copy Markdown
Member

ekexium commented May 22, 2026

/retest

@ekexium
Copy link
Copy Markdown
Member

ekexium commented May 22, 2026

/retest

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 22, 2026
@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 25, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 25, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-05-22 06:16:28.479580828 +0000 UTC m=+104119.120437631: ☑️ agreed by zyguan.
  • 2026-05-25 06:22:38.380179776 +0000 UTC m=+246828.350344856: ☑️ agreed by cfzjywxk.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 25, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, yudongusa, zyguan

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 the approved label May 25, 2026
@ekexium
Copy link
Copy Markdown
Member

ekexium commented May 25, 2026

/retest

@wuhuizuo
Copy link
Copy Markdown
Contributor

/test pull-integration-realcluster-test-next-gen

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 25, 2026

@wuhuizuo: No presubmit jobs available for pingcap/tidb@release-nextgen-202603

Details

In response to this:

/test pull-integration-realcluster-test-next-gen

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 ti-chi-bot Bot merged commit 6e625df into pingcap:release-nextgen-202603 May 25, 2026
18 checks passed
@ti-chi-bot ti-chi-bot Bot deleted the cherry-pick-68196-to-release-nextgen-202603 branch May 25, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202603

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants