Skip to content

*: update kvproto to apiv3 - #2024

Merged
ti-chi-bot[bot] merged 16 commits into
masterfrom
apiv3-update-proto
Aug 7, 2026
Merged

*: update kvproto to apiv3#2024
ti-chi-bot[bot] merged 16 commits into
masterfrom
apiv3-update-proto

Conversation

@disksing

@disksing disksing commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

The kvproto APIV3 branch moves keyspace-related protobuf fields into oneofs, so the current client code no longer compiles against the latest definitions.

Issue: pingcap/kvproto#1506 (introduce namespace-scoped keyspace identity for API V3); the protos are added by pingcap/kvproto#1458.

What changed?

  • Update kvproto to fd32127adca58438f6b05c869951182bbdd6041c in the root, integration-test, and example modules.
  • Update the PD client dependency to the latest master revision ba23e721a (2026-08-04) in the root, integration-test, and example modules.
  • Adapt API codec, region location, TiKV RPC, and tests to generated oneof getters and wrappers.
  • Cache the keyspace oneof wrapper in the codec: the keyspace ID never changes per codec, so reuse one *Context_KeyspaceId instead of allocating a new wrapper on every encoded V1/V2 request. The isolated setAPICtx path goes back to 0 B/0 allocs per call (was 4 B/1 alloc).
  • Make the lifecycle-hook tests non-flaky: Test2PCLifecycleHooks, Test2PCCleanupLifecycleHooks and TestAsyncCommitLifecycleHooks asserted reachedPost == false immediately after Commit returned, assuming the background (secondary commit / cleanup) goroutine had not finished yet. With the mock store that goroutine can finish before Commit returns, so the assertion is racy and integration-local-race failed intermittently. The fragile assertion is removed; the tests still verify that Pre runs and that Post eventually runs.

Tests

  • go test -tags=intest ./...
  • go test -race ./... in integration_tests/

Summary by CodeRabbit

  • Compatibility
    • Updated keyspace-aware request and response handling for newer protocol formats across MPP, compaction, transaction, and RPC flows.
    • Improved consistency when reading keyspace identifiers in garbage collection and related operations.
  • Maintenance
    • Refreshed example and integration components to align with newer protocol and client revisions.
    • Updated supporting test coverage to reflect the latest keyspace metadata structures.

Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 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

Updates keyspace protobuf handling to use wrapper fields and generated accessors. Refreshes kvproto, PD client, TiDB, and client-go revisions in the root, integration-test, and example Go modules.

Changes

Keyspace compatibility and module updates

Layer / File(s) Summary
Protobuf keyspace request handling
internal/apicodec/codec.go, internal/apicodec/codec_v2_test.go, tikvrpc/tikvrpc_test.go
API context, compact, and MPP request construction and tests use wrapper-based keyspace fields and generated getters.
Keyspace accessor propagation
internal/apicodec/codec_v2.go, internal/locate/pd_codec.go, tikv/*, integration_tests/gc_test.go
Keyspace ID retrieval uses GetId() in codecs, PD handling, safe-point loading, integration tests, and test utilities.
Dependency revision refresh
go.mod, integration_tests/go.mod, examples/**/go.mod
Pinned revisions for kvproto, PD client, TiDB, and client-go are updated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • tikv/tikv#19856: Updates kvproto revisions for protobuf and API compatibility.

Possibly related PRs

Suggested reviewers: ekexium, wfxr, zyguan

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: updating kvproto for APIV3 compatibility.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch apiv3-update-proto

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.

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

🧹 Nitpick comments (1)
internal/apicodec/codec_v2_test.go (1)

887-887: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Swap arguments to match testify's expected vs. actual convention.

In testify/suite, the Equal method expects arguments in the order (expected, actual). Swapping them ensures that any failure messages will report the expected and actual values correctly instead of inversely.

♻️ Proposed refactor
-	suite.Equal(task.Meta.GetKeyspaceId(), testKeyspaceID)
+	suite.Equal(testKeyspaceID, task.Meta.GetKeyspaceId())
🤖 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 `@internal/apicodec/codec_v2_test.go` at line 887, Update the Equal assertion
in the relevant test to pass testKeyspaceID as the expected value and
task.Meta.GetKeyspaceId() as the actual value, preserving the existing
comparison.
🤖 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 `@internal/apicodec/codec_v2_test.go`:
- Line 887: Update the Equal assertion in the relevant test to pass
testKeyspaceID as the expected value and task.Meta.GetKeyspaceId() as the actual
value, preserving the existing comparison.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 028004a3-d722-4842-84e1-09af2e9ec1ee

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4b3ea and 1abe0db.

⛔ 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 (17)
  • 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
  • internal/apicodec/codec.go
  • internal/apicodec/codec_v2.go
  • internal/apicodec/codec_v2_test.go
  • internal/locate/pd_codec.go
  • tikv/compatible_txn_safe_point_loader.go
  • tikv/test_util.go
  • tikvrpc/tikvrpc_test.go

Signed-off-by: disksing <i@disksing.com>
@disksing

Copy link
Copy Markdown
Collaborator Author

Addressed the CodeRabbit nit in 901d142 by using the expected/actual argument order. This update also moves integration_tests to the APIV3-compatible TiDB revision and fixes the remaining KeyspaceMeta getter; the full integration test module now compiles.

disksing added 4 commits July 22, 2026 22:32
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
# Conflicts:
#	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
#	go.sum
#	integration_tests/go.mod
#	integration_tests/go.sum
Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 24, 2026
Signed-off-by: disksing <i@disksing.com>
- Update github.com/tikv/pd/client to the latest master revision
  (ba23e721a) in the root, integration-test, and example modules.
- Remove the fragile assertion that the background goroutine has not
  finished right after Commit returns, in Test2PCLifecycleHooks,
  Test2PCCleanupLifecycleHooks and TestAsyncCommitLifecycleHooks.
  With the mock store's fast commit path the Post hook may run before
  Commit returns, so the assertion is racy and fails intermittently
  under -race on CI.

Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 4, 2026
@disksing

disksing commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI follow-up:

  • integration-local-race was failing on TestCommitter/Test2PCLifecycleHooks (and the same pattern in Test2PCCleanupLifecycleHooks and TestAsyncCommitLifecycleHooks). The assertion s.Equal(reachedPost.Load(), false) right after Commit returns is racy: with the mock store the background (secondary commit / cleanup) goroutine can finish before Commit returns, so the Post hook may already have run. Removed the fragile assertion and kept the checks that Pre ran and that Post eventually runs.

  • Updated github.com/tikv/pd/client to the latest master revision ba23e721a (2026-08-04) in the root, integration-test, and example modules.

  • The pull-integration-test-nextgen prow job still fails because the pinned base image ships Go 1.25.10 while go.mod requires 1.25.12 (and GOTOOLCHAIN=local is set). Fixed in chore(prow-jobs): update client-go nextgen base image to go 1.25.12 PingCAP-QE/ci#4857 (bump base image to v2026.7.12-6-gc8582dde-go1.25, Go 1.25.12); once that is merged the job should be re-run.

@disksing

disksing commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

/test pull-integration-test-nextgen

Comment thread internal/apicodec/codec.go Outdated
…ation

Since kvproto moved Context.keyspace into a oneof, setAPICtx built a new
*Context_KeyspaceId wrapper for every encoded V1/V2 request, which
escapes to the heap and adds 4 B/1 alloc on the default RPC hot path
(0 B/0 allocs before).

The keyspace ID of a codec never changes, so cache the wrapper in the
codec and reuse it for all encoded requests. setAPICtx now reports
0 B/0 allocs again.

Signed-off-by: disksing <i@disksing.com>
Comment thread internal/apicodec/codec.go Outdated
@disksing

disksing commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@cfzjywxk Done - the PR description now references the design issue: pingcap/kvproto#1506 (introduce namespace-scoped keyspace identity for API V3). The protos themselves were added in pingcap/kvproto#1458.

KeyspaceMeta.GetId() returns 0 when the keyspace oneof holds a
KeyspaceIdentity (API V3), and a zero numeric ID is invalid under API V3
semantics. NewCodecV2 is exported as tikv.NewCodecV2, so passing a V3
meta previously succeeded silently as a default-keyspace codec and
encoded keys and request context for keyspace 0.

Reject the identity arm explicitly since codec V2 only supports the
numeric keyspace ID.

Signed-off-by: disksing <i@disksing.com>
Comment thread internal/apicodec/codec_v2.go
Comment thread internal/locate/pd_codec.go

@ekexium ekexium left a comment

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.

LGTM after fixing existing comments

NewCodecV2 used to read keyspaceMeta.Id directly, so a nil meta failed
immediately; the nil-safe generated getters now silently produced a
default-keyspace (ID 0) codec. Restore the loud failure for nil meta.

GetKeyspaceID reports the numeric keyspace ID from PD metadata. When the
keyspace oneof holds an API V3 KeyspaceIdentity, GetId() returns 0, so
the helper silently routed an identity-scoped keyspace as keyspace 0.
Reject the identity arm explicitly, matching NewCodecV2.

Add tests for both cases.

Signed-off-by: disksing <i@disksing.com>
@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 Aug 5, 2026
Update github.com/tikv/pd/client to the latest master revision
afa43111d (client: recognize v2 keyspace-level GC, #11100) in the
root, integration-test, and example modules.

Signed-off-by: disksing <i@disksing.com>
@disksing
disksing force-pushed the apiv3-update-proto branch from de95a8c to 0989abf Compare August 5, 2026 14:48
@disksing

disksing commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Updated github.com/tikv/pd/client to afa43111d (client: recognize v2 keyspace-level GC, tikv/pd#11100) in the root, integration-test, and example modules.

@disksing

disksing commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@ekexium All of rleungx's review comments have been addressed and replied to in the threads:

  • oneof wrapper allocation (codec.go) → fixed in 0a7a5ac (0 B/0 allocs, public interface unchanged via unexported keyspaceOneofProvider)
  • V3 keyspace identity rejected in NewCodecV2 → fixed in afe0924
  • nil meta rejected in NewCodecV2 → fixed in 86c6e6e
  • V3 keyspace identity rejected in GetKeyspaceID → fixed in 86c6e6e

CI is green (all GitHub Actions jobs + prow nextgen). Could you take another look / approve?

…-proto-fix

Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 6, 2026
@ti-chi-bot ti-chi-bot Bot added lgtm approved and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 7, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-08-06 03:56:25.556059268 +0000 UTC m=+2673171.592154334: ☑️ agreed by rleungx.
  • 2026-08-07 08:00:45.04466086 +0000 UTC m=+2774231.080755906: ☑️ agreed by pingyu.

@pingyu

pingyu commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

/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 Aug 7, 2026
@disksing

disksing commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

@pingyu Thanks for the approval. The PR now has the required approvals and lgtm, but the /hold is keeping Tide blocked. Is there anything remaining to address? If not, please run /hold cancel when ready so Tide can proceed.

@ti-chi-bot

ti-chi-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, pingyu, rleungx

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

@pingyu

pingyu commented Aug 7, 2026

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 Aug 7, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit b75f6ef into master Aug 7, 2026
13 checks passed
@ti-chi-bot
ti-chi-bot Bot deleted the apiv3-update-proto branch August 7, 2026 10:34
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants