Skip to content

store: mark TiDB requests for max-ts validation (#68779) - #68960

Merged
ti-chi-bot[bot] merged 16 commits into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-68779-to-release-8.5
Jun 11, 2026
Merged

store: mark TiDB requests for max-ts validation (#68779)#68960
ti-chi-bot[bot] merged 16 commits into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-68779-to-release-8.5

Conversation

@ti-chi-bot

@ti-chi-bot ti-chi-bot commented Jun 4, 2026

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #68779

What problem does this PR solve?

Issue Number: close #68799

Problem Summary:

TiKV needs to distinguish TiDB-originated requests from other client-go users so selected non-TiDB max-ts update paths can be validated without drift tolerance.

What changed and how does it work?

  • Set the client-go process default request origin to REQUEST_ORIGIN_TIDB from cmd/tidb-server.
  • Extend TestRequestSource to verify TiDB requests carry kvrpcpb.Context.request_origin on the wire.
  • Temporarily reference the stacked kvproto/client-go draft PRs through fork replace directives so this draft can compile before upstream dependency PRs merge.

The temporary dependency replaces should be removed after pingcap/kvproto#1479 and tikv/client-go#1975 are merged and TiDB can bump normal upstream module versions.

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.

Commands:

  • make bazel_prepare
  • GOPRIVATE=github.com/ekexium/kvproto,github.com/ekexium/client-go ./tools/check/failpoint-go-test.sh pkg/session/test -run TestRequestSource
  • GOPRIVATE=github.com/ekexium/kvproto,github.com/ekexium/client-go gotestsum --format short-verbose -- ./cmd/tidb-server -run '^$'
  • GOPRIVATE=github.com/ekexium/kvproto,github.com/ekexium/client-go make lint
  • git diff --check

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

  • Chores

    • Updated build and dependency pins, including several toolchain and telemetry libraries.
    • Moved an error-handling library to direct dependencies and tweaked test shard settings for build/test performance.
  • Tests

    • Strengthened KV RPC request validation and startup initialization to enforce request origin tracking (TiDB) during test runs.

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-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Jun 4, 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

ti-chi-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

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

@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Set TiKV client's default RequestOrigin to TiDB (Bazel wiring and imports added), validate RequestOrigin in session tests, update many Bazel and Go dependency pins, adjust go.mod requires, and increase a test shard count.

Changes

Request Origin Wiring

Layer / File(s) Summary
Build deps and server imports
cmd/tidb-server/BUILD.bazel, cmd/tidb-server/main.go
Add @com_github_pingcap_kvproto//pkg/kvrpcpb and @com_github_tikv_client_go_v2//tikvrpc to Bazel deps and import kvrpcpb/tikvrpc in main.go.
Server startup initialization
cmd/tidb-server/main.go
Call tikvrpc.SetDefaultRequestOrigin(kvrpcpb.RequestOrigin_RequestOriginTiDB) before store/metrics initialization.
Test validation for RequestOrigin
pkg/session/test/session_test.go
TestRequestSource sets/resets default RequestOriginTiDB and the RPC interceptor now derives and asserts RequestOrigin alongside RequestSource for multiple KV request types.

Dependency pins and module updates

Layer / File(s) Summary
DEPS pinned go_repository updates
DEPS.bzl
Bulk updates and additions to pinned go_repository(...) entries: Envoy-related pins, OpenTelemetry family bumped to v1.39.0, tikv/client-go pin, golang.org/x/* updates, google genproto/grpc bumps, and several added repositories.
go.mod edits and bumps
go.mod
Promote github.com/cockroachdb/errors v1.11.3 to direct require; bump github.com/stretchr/testify, github.com/tikv/client-go/v2, many golang.org/x/* modules, google.golang.org/grpc, and add go.opentelemetry.io/auto/sdk as indirect.

Test shard adjustment

Layer / File(s) Summary
Test shard count
pkg/planner/core/casetest/rule/BUILD.bazel
Increase rule_test shard_count from 13 to 17.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • pingcap/tidb#68779: Both PRs wire TiDB's TiKV client default RequestOriginTiDB in cmd/tidb-server/main.go and extend TestRequestSource to assert RequestOrigin on KV RPCs.

Suggested labels

cherry-pick-approved, approved, lgtm

Suggested reviewers

  • zyguan
  • MyonKeminta
  • cfzjywxk

🐰 In fields of code I nimbly bound,
I label requests so truth is found.
TiDB hops forth with origin true,
Tests check the trail—no drift sneaks through.
🥕 Hooray for pins and tidy glue.

🚥 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 The title clearly identifies the main change: marking TiDB requests with a request origin indicator for TiKV validation purposes.
Description check ✅ Passed The description includes the required issue number (#68799), problem summary, detailed explanation of changes, test checklist, and release notes section per template requirements.
Linked Issues check ✅ Passed All requirements from #68799 are met: cmd/tidb-server sets REQUEST_ORIGIN_TIDB, test verifies request_origin transmission, and temporary dependency replaces enable compilation.
Out of Scope Changes check ✅ Passed All changes directly support the linked objective of marking TiDB requests with origin information and updating dependencies; no unrelated changes detected.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/tidb-server/main.go`:
- Around line 304-311: Replace the direct deferred call that captures err by
value with a deferred closure so EndStandby sees the final err; change the
current defer standbyController.EndStandby(err) to defer func() {
standbyController.EndStandby(err) }() near the WaitForActivate() call (this
ensures standbyController.EndStandby observes errors from later calls like
registerStores() and prepareKeyspaceObservabilityForStarter()).
- Around line 284-289: The startup config validation currently exits with
os.Exit(0) on invalid configs in the kerneltype.IsNextGen() and
kerneltype.IsClassic() branches; change both exits to a non-zero status (e.g.,
os.Exit(1)) so failures are reported to systemd/Kubernetes/scripts; update the
two occurrences where os.Exit(0) is called in the block that checks
kerneltype.IsNextGen(), kerneltype.IsClassic(), and config.GetGlobalConfig()
(including Standby.StandByMode, KeyspaceName, KeyspaceActivateMode) to use
os.Exit(1).
🪄 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: fa4dc002-a50f-40ff-b327-624b4bb85235

📥 Commits

Reviewing files that changed from the base of the PR and between 87f39ce and 0a02f24.

📒 Files selected for processing (3)
  • cmd/tidb-server/BUILD.bazel
  • cmd/tidb-server/main.go
  • pkg/session/test/session_test.go

Comment thread cmd/tidb-server/main.go Outdated
Comment on lines +284 to +289
if kerneltype.IsNextGen() && len(config.GetGlobalConfig().KeyspaceName) == 0 && !config.GetGlobalConfig().Standby.StandByMode {
fmt.Fprintln(os.Stderr, "invalid config: keyspace name or standby mode is required for nextgen TiDB")
os.Exit(0)
} else if kerneltype.IsClassic() && (len(config.GetGlobalConfig().KeyspaceName) > 0 || config.GetGlobalConfig().Standby.StandByMode || config.GetGlobalConfig().KeyspaceActivateMode) {
fmt.Fprintln(os.Stderr, "invalid config: keyspace name, standby mode or keyspace-activate mode is not supported for classic TiDB")
os.Exit(0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Return a non-zero status for invalid startup config.

Lines 285-289 reject invalid config but exit with os.Exit(0). That reports success to systemd/Kubernetes/scripts, so a misconfigured TiDB can look like a clean startup/shutdown instead of a failed boot.

Suggested fix
 	if kerneltype.IsNextGen() && len(config.GetGlobalConfig().KeyspaceName) == 0 && !config.GetGlobalConfig().Standby.StandByMode {
 		fmt.Fprintln(os.Stderr, "invalid config: keyspace name or standby mode is required for nextgen TiDB")
-		os.Exit(0)
+		os.Exit(1)
 	} else if kerneltype.IsClassic() && (len(config.GetGlobalConfig().KeyspaceName) > 0 || config.GetGlobalConfig().Standby.StandByMode || config.GetGlobalConfig().KeyspaceActivateMode) {
 		fmt.Fprintln(os.Stderr, "invalid config: keyspace name, standby mode or keyspace-activate mode is not supported for classic TiDB")
-		os.Exit(0)
+		os.Exit(1)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if kerneltype.IsNextGen() && len(config.GetGlobalConfig().KeyspaceName) == 0 && !config.GetGlobalConfig().Standby.StandByMode {
fmt.Fprintln(os.Stderr, "invalid config: keyspace name or standby mode is required for nextgen TiDB")
os.Exit(0)
} else if kerneltype.IsClassic() && (len(config.GetGlobalConfig().KeyspaceName) > 0 || config.GetGlobalConfig().Standby.StandByMode || config.GetGlobalConfig().KeyspaceActivateMode) {
fmt.Fprintln(os.Stderr, "invalid config: keyspace name, standby mode or keyspace-activate mode is not supported for classic TiDB")
os.Exit(0)
if kerneltype.IsNextGen() && len(config.GetGlobalConfig().KeyspaceName) == 0 && !config.GetGlobalConfig().Standby.StandByMode {
fmt.Fprintln(os.Stderr, "invalid config: keyspace name or standby mode is required for nextgen TiDB")
os.Exit(1)
} else if kerneltype.IsClassic() && (len(config.GetGlobalConfig().KeyspaceName) > 0 || config.GetGlobalConfig().Standby.StandByMode || config.GetGlobalConfig().KeyspaceActivateMode) {
fmt.Fprintln(os.Stderr, "invalid config: keyspace name, standby mode or keyspace-activate mode is not supported for classic TiDB")
os.Exit(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 `@cmd/tidb-server/main.go` around lines 284 - 289, The startup config
validation currently exits with os.Exit(0) on invalid configs in the
kerneltype.IsNextGen() and kerneltype.IsClassic() branches; change both exits to
a non-zero status (e.g., os.Exit(1)) so failures are reported to
systemd/Kubernetes/scripts; update the two occurrences where os.Exit(0) is
called in the block that checks kerneltype.IsNextGen(), kerneltype.IsClassic(),
and config.GetGlobalConfig() (including Standby.StandByMode, KeyspaceName,
KeyspaceActivateMode) to use os.Exit(1).

Comment thread cmd/tidb-server/main.go Outdated
Comment on lines +304 to +311
// If running standby mode, wait for activate request.
if standbyController != nil {
standbyController.WaitForActivate()
// EndStandby only execute once. If server is created
// successfully, the defer has no effect. If panics
// before server is created, the defer makes sure to
// notify the activate caller.
defer standbyController.EndStandby(err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Defer EndStandby via closure so it sees the final error.

Line 311 passes err to defer by value, so it is captured as nil at defer time. If registerStores() or prepareKeyspaceObservabilityForStarter() fails later, EndStandby still receives nil and the activator can be told startup succeeded even though bootstrap aborted.

Suggested fix
-		defer standbyController.EndStandby(err)
+		defer func() {
+			standbyController.EndStandby(err)
+		}()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// If running standby mode, wait for activate request.
if standbyController != nil {
standbyController.WaitForActivate()
// EndStandby only execute once. If server is created
// successfully, the defer has no effect. If panics
// before server is created, the defer makes sure to
// notify the activate caller.
defer standbyController.EndStandby(err)
// If running standby mode, wait for activate request.
if standbyController != nil {
standbyController.WaitForActivate()
// EndStandby only execute once. If server is created
// successfully, the defer has no effect. If panics
// before server is created, the defer makes sure to
// notify the activate caller.
defer func() {
standbyController.EndStandby(err)
}()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/tidb-server/main.go` around lines 304 - 311, Replace the direct deferred
call that captures err by value with a deferred closure so EndStandby sees the
final err; change the current defer standbyController.EndStandby(err) to defer
func() { standbyController.EndStandby(err) }() near the WaitForActivate() call
(this ensures standbyController.EndStandby observes errors from later calls like
registerStores() and prepareKeyspaceObservabilityForStarter()).

Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium ekexium removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 8, 2026
@ekexium
ekexium requested review from cfzjywxk and zyguan June 8, 2026 11:06
@ekexium

ekexium commented Jun 8, 2026

Copy link
Copy Markdown
Member

/retest

Signed-off-by: Ziqian Qin <eke@fastmail.com>
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-8.5@975089d). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-8.5     #68960   +/-   ##
================================================
  Coverage               ?   55.6168%           
================================================
  Files                  ?       1847           
  Lines                  ?     665365           
  Branches               ?          0           
================================================
  Hits                   ?     370055           
  Misses                 ?     267741           
  Partials               ?      27569           
Flag Coverage Δ
integration 39.1457% <100.0000%> (?)
unit 65.1383% <100.0000%> (?)

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

Components Coverage Δ
dumpling 55.1998% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 62.9934% <0.0000%> (?)
🚀 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 approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 8, 2026
…k-68779-to-release-8.5

Signed-off-by: Ziqian Qin <eke@fastmail.com>

# Conflicts:
#	DEPS.bzl
#	go.mod
#	go.sum
@ti-chi-bot ti-chi-bot Bot added sig/planner SIG: Planner and removed approved labels Jun 10, 2026
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 10, 2026
ekexium added 2 commits June 11, 2026 09:23
…68779-to-release-8.5

Signed-off-by: Ziqian Qin <eke@fastmail.com>

# Conflicts:
#	pkg/planner/core/casetest/rule/BUILD.bazel
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/retest

@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/hold

@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 Jun 11, 2026
@ekexium
ekexium force-pushed the cherry-pick-68779-to-release-8.5 branch from a78dfe8 to 421a41d Compare June 11, 2026 03:03
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/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 Jun 11, 2026
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/retest

close pingcap#65727

(cherry picked from commit 6d55295)
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/retest

1 similar comment
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/retest

ekexium and others added 5 commits June 11, 2026 13:34
close pingcap#67174

(cherry picked from commit 25eacc4)
Signed-off-by: Ziqian Qin <eke@fastmail.com>
…ap#68169)

close pingcap#67174

(cherry picked from commit c6056f8)
Signed-off-by: Ziqian Qin <eke@fastmail.com>
After the dependency update the test binary's live heap after the 810MB
allocation sits a few hundred KB below the runtime's memory-limit heap
goal (1GiB*0.8 = 819.2MiB minus non-heap memory and headroom), so the
runtime fires no further GC during the wait windows. The memory limit
tuner's finalizer hook therefore never gets the second run it needs to
set adjustPercentageInProgress, and the waits time out. This used to
pass only because the heap margin was small enough that the polling
goroutine's own allocations crossed the goal and triggered a GC.

Force runtime.GC() in the polling conditions (the same approach as
PR pingcap#67377) so detection no longer depends on incidental allocations.

ref pingcap#65673

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/retest

1 similar comment
@ekexium

ekexium commented Jun 11, 2026

Copy link
Copy Markdown
Member

/retest

The analyze-after-DDL goroutine reports failures via an unbuffered
doneCh. When analyzeTableInner returns through the cumulative-timeout
branch, nothing ever receives from doneCh; a later analyze failure
blocks the goroutine on the send forever, leaking the ddl session pool
session and deadlocking ddl.Stop()/Domain.Close() in SetCapacity(0).

This is what made //tests/realtikvtest/addindextest4 (TestAnalyzeTimeout)
hang deterministically once testify v1.11 (pulled in by the grpc upgrade)
started evaluating require.Eventually conditions immediately.

Mirror the master fix in a736b2f (pingcap#66870): make doneCh buffered.

ref pingcap#69127

Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium
ekexium requested a review from D3Hunter June 11, 2026 13:31
@tiprow

tiprow Bot commented Jun 11, 2026

Copy link
Copy Markdown

@ti-chi-bot: 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
fast_test_tiprow_for_release 1cb3111 link true /test fast_test_tiprow_for_release

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.

@ti-chi-bot

ti-chi-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, D3Hunter, winoros, wjhuang2016

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 merged commit 8331513 into pingcap:release-8.5 Jun 11, 2026
21 of 22 checks passed
@ti-chi-bot
ti-chi-bot Bot deleted the cherry-pick-68779-to-release-8.5 branch June 11, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants