Skip to content

add API V3 keyspace identity protos - #1458

Merged
ti-chi-bot[bot] merged 25 commits into
masterfrom
apiv3
Jul 24, 2026
Merged

add API V3 keyspace identity protos#1458
ti-chi-bot[bot] merged 25 commits into
masterfrom
apiv3

Conversation

@disksing

@disksing disksing commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Issue: #1506

Summary

  • Add public API V3 KeyspaceIdentity schema and wire it through KV, PD, TSO, keyspace, GC, and related tenant-scoped protobuf APIs.
  • Preserve legacy keyspace_id fields for V1/V2 compatibility while documenting V3 identity semantics.
  • Update generated bindings and proto metadata for downstream API V3 consumers.

Validation

  • make proto-fmt
  • go build ./pkg/...
  • go test ./pkg/...
  • make check reached the expected proto.lock change prompt
  • cargo check is still blocked locally by the known libz/Xcode header issue

Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2026
@ti-chi-bot
ti-chi-bot Bot requested a review from henrybw April 30, 2026 16:25
@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 30, 2026
@disksing disksing changed the title [codex] add API V3 keyspace identity protos add API V3 keyspace identity protos Apr 30, 2026
disksing added 5 commits May 1, 2026 09:54
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
# Conflicts:
#	pkg/kvrpcpb/kvrpcpb.pb.go
#	pkg/pdpb/pdpb.pb.go

Signed-off-by: disksing <i@disksing.com>
Comment thread proto/pdpb.proto Outdated
Comment thread proto/autoid.proto Outdated
Comment thread proto/keyspacepb.proto Outdated
Comment thread proto/pdpb.proto Outdated
Comment thread proto/pdpb.proto Outdated
Comment thread proto/pdpb.proto Outdated
Comment thread proto/tsopb.proto Outdated
Comment thread proto/tsopb.proto Outdated
Comment thread proto/keyspacepb.proto Outdated
disksing and others added 10 commits June 11, 2026 09:19
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
# Conflicts:
#	pkg/keyspacepb/keyspacepb.pb.go
#	proto/keyspacepb.proto
#	scripts/proto.lock
@disksing
disksing marked this pull request as ready for review July 8, 2026 04:27
@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 Jul 8, 2026
@ti-chi-bot
ti-chi-bot Bot requested a review from 0xPoe July 8, 2026 04:27
Comment thread proto/kvrpcpb.proto
// The keyspace that the request is sent to.
// NOTE: This field is only meaningful while the api_version is V2.
uint32 keyspace_id = 32;
oneof keyspace {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changing this existing scalar field into a oneof is source-incompatible for generated Go users even though the wire tag is preserved. Context.KeyspaceId disappears, and downstream PD/TiDB/client-go code constructs or reads this field directly, so upgrading kvproto would break V1/V2 callers that do not use V3. The legacy scalar should stay as a normal field and keyspace_identity should be added alongside it, as was done for AutoIDRequest and KeyspaceMeta.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fair point. I originally kept keyspace_id as a normal field and added keyspace_identity alongside it to minimize downstream Go source changes. Later I changed it to oneof based on review feedback, since semantically it is clearer that only one keyspace identifier should be set.

I think both directions are reasonable: parallel fields are more source-compatible, while oneof is clearer semantically. @sunxiaoguang what do you think? If we prefer minimizing downstream changes for kvrpcpb.Context, I can change this back to the parallel-field style.

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.

Thanks @rleungx @disksing for the insightful discussion.
I lean towards the oneof approach here. Here is my perspective:
Confined Blast Radius: While changing to oneof is indeed source-incompatible, the generated protobuf code is primarily encapsulated within our rich clients (client-go, client-rust, client-c). The blast radius of this incompatible change is limited and well-contained within these repositories, rather than leaking indefinitely downstream.
Compiler-Guaranteed Safety: For strongly-typed languages, breaking the source code during compilation is actually a major benefit in this context. It forces the compiler to help us pinpoint every single callsite that accesses the relevant fields. This completely eliminates the risk of missing any field migrations, which could otherwise lead to silent, hard-to-debug runtime issues.
Semantics vs. Refactoring Cost: Maintaining parallel fields compromises semantic clarity and risks inconsistent states (e.g., both fields being set). The value of absolute correctness and explicit semantics brought by oneof far outweighs the cost of limited code adjustments in the client libraries.
Therefore, I'd prefer to go with oneof to ensure long-term robustness.

Signed-off-by: disksing <i@disksing.com>
Comment thread proto/kvrpcpb.proto
//
// `V3` uses user-key wire semantics for normal KV RPCs. Servers encode an
// 8-byte physical prefix at the serving boundary:
// mode(1) + namespace_id(4 bytes, big endian) + keyspace_id(3 bytes, big endian).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the semantic difference between namespace id and keyspace id?
What are the considerations of encoding namespace id first? Can it be mode(1) + keyspace_id(3 bytes, big endian) + namespace_id(4 bytes, big endian)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

namespace_id represents the higher-level namespace that groups multiple keyspaces. We intentionally encode it before keyspace_id because storage keys are ordered lexicographically. Using mode + namespace_id + keyspace_id ensures that all keyspaces belonging to the same namespace form one contiguous key range after sorting. If keyspace_id were encoded first, keyspaces from the same namespace would be scattered across different ranges. Therefore, we prefer to keep the namespace ID before the keyspace ID.

@coocood

coocood commented Jul 20, 2026

Copy link
Copy Markdown
Member

@disksing
Do we have dev branch of tidb & tikv that compiles with API V3?

Comment thread proto/autoid.proto
disksing added 2 commits July 22, 2026 11:36
Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
Comment thread proto/resource_manager.proto Outdated

@rleungx rleungx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rest LGTM.

Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 23, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-21 05:50:58.855688624 +0000 UTC m=+1297644.891783670: ☑️ agreed by coocood.
  • 2026-07-23 03:00:45.856590652 +0000 UTC m=+1460231.892685708: ☑️ agreed by rleungx.

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

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

@bb7133 bb7133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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

@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, cfzjywxk, coocood, rleungx, windtalker, zhangjinpeng87

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:
  • OWNERS [bb7133,cfzjywxk,coocood,rleungx,windtalker]
  • proto/OWNERS [bb7133,cfzjywxk,rleungx,windtalker,zhangjinpeng87]

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 Jul 24, 2026
Comment thread proto/pdpb.proto
@ti-chi-bot
ti-chi-bot Bot merged commit 7022f46 into master Jul 24, 2026
5 of 6 checks passed
@ti-chi-bot
ti-chi-bot Bot deleted the apiv3 branch July 24, 2026 03:11
Comment thread proto/keyspacepb.proto
@@ -16,7 +17,12 @@ option (rustproto.lite_runtime_all) = true;

// Keyspace provides services to manage keyspaces.
service Keyspace {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Namespace contains keyspace, but we put Namespace in the Keyspace service. Maybe adding a new Namespace service is better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Namespace and keyspace are tightly coupled in API V3, and namespace_id is part of KeyspaceIdentity. Therefore, keeping their management APIs in the same service seems reasonable. We can revisit a separate Namespace service if it gains a more independent lifecycle later.

@yudongusa

Copy link
Copy Markdown

Why didn't any reviewer point out the missing github related issue and design spec?

disksing added a commit to tidbcloud/kvproto that referenced this pull request Jul 27, 2026
Sync the final protocol changes from pingcap/kvproto#1458 at 7022f46937bc35125fb6d65aad5a0eedd59e7cfd onto release-8.5-keyspace.

Preserve the downstream release schema and regenerate Go bindings and proto.lock with the downstream toolchain.

Signed-off-by: disksing <i@disksing.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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