Skip to content

tikvrpc: add default request origin - #1975

Merged
ti-chi-bot[bot] merged 5 commits into
tikv:masterfrom
ekexium:codex/max-ts-request-origin-client-go
Jun 1, 2026
Merged

tikvrpc: add default request origin#1975
ti-chi-bot[bot] merged 5 commits into
tikv:masterfrom
ekexium:codex/max-ts-request-origin-client-go

Conversation

@ekexium

@ekexium ekexium commented May 29, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Add a process-wide default request origin in tikvrpc.
  • Fill kvrpcpb.Context.request_origin from that default when creating or attaching request context.
  • Keep the default as unspecified so non-TiDB client-go users do not get TiDB trust by accident.

Dependency stack

Tests

  • gotestsum --format short-verbose -- ./tikvrpc
  • go test ./tikvrpc -run '^TestDefaultRequestOrigin$' -race
  • cd integration_tests && go list -mod=readonly ./...
  • for mod in $(find examples -name go.mod -print | sort); do (cd "${mod%/go.mod}" && go list -mod=readonly ./...); done
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Configurable default request origin for RPCs, ensuring consistent request identification and tracking across operations.
  • Chores

    • Bumped an indirect dependency used by examples and integration tests to a newer commit across multiple modules.
  • Tests

    • Added unit tests to verify default request origin behavior and that explicit origins are preserved across RPC creation and attachment.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has signed the dco. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ekexium, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 4 minutes and 30 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93c5238d-7274-4231-b61a-94512ae26a9d

📥 Commits

Reviewing files that changed from the base of the PR and between f8a9f95 and 6ffa8ae.

📒 Files selected for processing (1)
  • tikvrpc/tikvrpc_test.go
📝 Walkthrough

Walkthrough

This PR bumps the github.com/pingcap/kvproto dependency across the main module and example modules, and adds a process-wide default RequestOrigin (with Set/Get APIs and fill logic) applied in NewRequest and AttachContext, plus unit tests validating the behavior.

Changes

Dependency and RequestOrigin Updates

Layer / File(s) Summary
kvproto dependency updates
go.mod, examples/gcworker/go.mod, examples/rawkv/go.mod, examples/txnkv/go.mod, examples/txnkv/1pc_txn/go.mod, examples/txnkv/async_commit/go.mod, examples/txnkv/delete_range/go.mod, examples/txnkv/pessimistic_txn/go.mod, examples/txnkv/unsafedestoryrange/go.mod, integration_tests/go.mod
Updates github.com/pingcap/kvproto from v0.0.0-20260514102340-daa7c864b473 to v0.0.0-20260601035955-b2b3bb492278 across module declarations.
RequestOrigin defaulting implementation
tikvrpc/tikvrpc.go, tikvrpc/tikvrpc_test.go
Adds process-wide atomic defaultRequestOrigin with SetDefaultRequestOrigin() and GetDefaultRequestOrigin(), fillDefaultRequestOrigin() helper, applies defaulting in NewRequest() and AttachContext(), and adds TestDefaultRequestOrigin validating default and override behaviors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • tikv/client-go#1935: Related dependency pin updates for github.com/pingcap/kvproto across modules.

Suggested labels

lgtm, approved

Suggested reviewers

  • zyguan
  • bufferflies
  • lhy1024

Poem

🐰 I hop through modules, tidy and spry,
Bumped kvproto so builds fly high,
A default origin now quietly lives,
Filled where the empty context gives,
Tests nod, and the RPCs reply.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'tikvrpc: add default request origin' directly and accurately summarizes the main change: adding a default request origin feature to the tikvrpc package.
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.

@ekexium
ekexium force-pushed the codex/max-ts-request-origin-client-go branch 3 times, most recently from aba2414 to d3276f1 Compare May 30, 2026 02:36
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium
ekexium force-pushed the codex/max-ts-request-origin-client-go branch from d3276f1 to 94a0a90 Compare June 1, 2026 04:01
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 1, 2026
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium
ekexium marked this pull request as ready for review June 1, 2026 04:40
Copilot AI review requested due to automatic review settings June 1, 2026 04:40
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 1, 2026

Copilot AI 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.

Pull request overview

Adds a process-wide default request_origin in tikvrpc and ensures it is filled into kvrpcpb.Context when requests are created or when contexts are attached, alongside bumping kvproto to a revision that includes the new enum/field.

Changes:

  • Introduce global default request origin setters/getters and apply the default when Context.request_origin is unknown.
  • Extend NewRequest and AttachContext to auto-fill request_origin.
  • Bump github.com/pingcap/kvproto pseudo-version across the root module, integration tests, and examples.

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tikvrpc/tikvrpc.go Adds global default request origin and fills it into request contexts during creation/attachment.
tikvrpc/tikvrpc_test.go Adds tests to validate default request origin propagation.
go.mod Bumps github.com/pingcap/kvproto version for the main module.
go.sum Updates checksums for the bumped kvproto version.
integration_tests/go.mod Bumps github.com/pingcap/kvproto for integration test module.
integration_tests/go.sum Updates checksums for the bumped kvproto version in integration tests.
examples/txnkv/go.mod Bumps github.com/pingcap/kvproto for the txnkv examples module.
examples/txnkv/async_commit/go.mod Bumps indirect github.com/pingcap/kvproto for async_commit example.
examples/txnkv/1pc_txn/go.mod Bumps indirect github.com/pingcap/kvproto for 1pc_txn example.
examples/txnkv/delete_range/go.mod Bumps indirect github.com/pingcap/kvproto for delete_range example.
examples/txnkv/pessimistic_txn/go.mod Bumps indirect github.com/pingcap/kvproto for pessimistic_txn example.
examples/txnkv/unsafedestoryrange/go.mod Bumps indirect github.com/pingcap/kvproto for unsafedestoryrange example.
examples/rawkv/go.mod Bumps indirect github.com/pingcap/kvproto for rawkv example.
examples/gcworker/go.mod Bumps indirect github.com/pingcap/kvproto for gcworker example.

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

Comment thread tikvrpc/tikvrpc.go Outdated
Comment thread tikvrpc/tikvrpc_test.go
Comment thread tikvrpc/tikvrpc_test.go
Comment thread go.mod

@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: 1

🧹 Nitpick comments (1)
tikvrpc/tikvrpc_test.go (1)

115-119: ⚡ Quick win

Make the explicit-origin case observable.

This assertion uses the same value as the configured default, so it still passes if explicit origins start getting overwritten by the default. Flip the default before this case so the preservation contract is actually exercised.

Suggested test tweak
+	SetDefaultRequestOrigin(kvrpcpb.RequestOrigin_RequestOriginUnknown)
 	req = NewRequest(CmdGet, &kvrpcpb.GetRequest{}, kvrpcpb.Context{
 		RequestOrigin: kvrpcpb.RequestOrigin_RequestOriginTiDB,
 	})
 	require.Equal(t, kvrpcpb.RequestOrigin_RequestOriginTiDB, req.GetRequestOrigin())
🤖 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 `@tikvrpc/tikvrpc_test.go` around lines 115 - 119, Test currently verifies an
explicit origin using the same value as the configured default, so change the
configured default request origin to a different enum value before constructing
the explicit-origin request to ensure preservation is exercised; specifically,
set the package's configured default request origin to a different
kvrpcpb.RequestOrigin (e.g., RequestOrigin_RequestOriginTiKV), call
NewRequest(CmdGet, &kvrpcpb.GetRequest{}, kvrpcpb.Context{RequestOrigin:
kvrpcpb.RequestOrigin_RequestOriginTiDB}), assert req.GetRequestOrigin() is
RequestOrigin_RequestOriginTiDB, and then restore the original default.
🤖 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 `@tikvrpc/tikvrpc.go`:
- Around line 873-875: AttachContext is only mutating the local rpcCtx copy via
fillDefaultRequestOrigin, so the normalized origin isn't persisted onto
req.Context; modify AttachContext to copy the updated rpcCtx back into
req.Context (e.g., req.Context = rpcCtx or equivalent assignment) immediately
after fillDefaultRequestOrigin(&rpcCtx) and before the code that patches the
protobuf request so that subsequent retries see the filled RequestOrigin;
reference function AttachContext, variables req.Context and rpcCtx, and helper
fillDefaultRequestOrigin when making the change.

---

Nitpick comments:
In `@tikvrpc/tikvrpc_test.go`:
- Around line 115-119: Test currently verifies an explicit origin using the same
value as the configured default, so change the configured default request origin
to a different enum value before constructing the explicit-origin request to
ensure preservation is exercised; specifically, set the package's configured
default request origin to a different kvrpcpb.RequestOrigin (e.g.,
RequestOrigin_RequestOriginTiKV), call NewRequest(CmdGet, &kvrpcpb.GetRequest{},
kvrpcpb.Context{RequestOrigin: kvrpcpb.RequestOrigin_RequestOriginTiDB}), assert
req.GetRequestOrigin() is RequestOrigin_RequestOriginTiDB, and then restore the
original default.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffb0a60a-f50f-4412-9b48-14e542fe01b1

📥 Commits

Reviewing files that changed from the base of the PR and between 636b5f2 and e01c519.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • integration_tests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (12)
  • examples/gcworker/go.mod
  • examples/rawkv/go.mod
  • examples/txnkv/1pc_txn/go.mod
  • examples/txnkv/async_commit/go.mod
  • examples/txnkv/delete_range/go.mod
  • examples/txnkv/go.mod
  • examples/txnkv/pessimistic_txn/go.mod
  • examples/txnkv/unsafedestoryrange/go.mod
  • go.mod
  • integration_tests/go.mod
  • tikvrpc/tikvrpc.go
  • tikvrpc/tikvrpc_test.go

Comment thread tikvrpc/tikvrpc.go
ekexium added 2 commits June 1, 2026 12:52
Signed-off-by: Ziqian Qin <eke@fastmail.com>
Signed-off-by: Ziqian Qin <eke@fastmail.com>
@ekexium
ekexium requested review from MyonKeminta and cfzjywxk June 1, 2026 05:17
@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 1, 2026
@cfzjywxk
cfzjywxk requested a review from zyguan June 1, 2026 06:55
@ti-chi-bot ti-chi-bot Bot added the lgtm label Jun 1, 2026
@ti-chi-bot ti-chi-bot Bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 1, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MyonKeminta, 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 commented Jun 1, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-06-01 05:48:03.850938131 +0000 UTC m=+161384.921255521: ☑️ agreed by MyonKeminta.
  • 2026-06-01 08:46:25.075739287 +0000 UTC m=+172086.146056677: ☑️ agreed by zyguan.

@ti-chi-bot
ti-chi-bot Bot merged commit f2ffb0f into tikv:master Jun 1, 2026
13 checks passed
@ekexium

ekexium commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-nextgen-202603

@ekexium

ekexium commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

/cherry-pick tidb-8.5

@ti-chi-bot

Copy link
Copy Markdown
Member

@ekexium: new pull request created to branch release-nextgen-202603: #1977.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-nextgen-202603

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

Copy link
Copy Markdown
Member

@ekexium: new pull request created to branch tidb-8.5: #1978.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick tidb-8.5

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.

ekexium added a commit to ti-chi-bot/client-go that referenced this pull request Jun 8, 2026
ref pingcap/tidb#68799

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ekexium added a commit to ti-chi-bot/client-go that referenced this pull request Jun 8, 2026
ref pingcap/tidb#68799

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: Ziqian Qin <eke@fastmail.com>
ti-chi-bot Bot pushed a commit that referenced this pull request Jun 8, 2026
ref pingcap/tidb#68799\n\nSigned-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>\nSigned-off-by: Ziqian Qin <eke@fastmail.com>\n\nCo-authored-by: Ziqian Qin <eke@fastmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm 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.

5 participants