Skip to content

Commit bcd8dd3

Browse files
committed
kvtenant: replace InternalClient with more specific services' client adapters
Since we have broken down the `Internal` service into smaller services, this PR uses them in the tenant connector. This means the `client.InternalClient` will be replaced by `RPCTenantServiceClient`, `RPCTenantUsageClient`, and `RPCTenantSpanConfigClient`, as they are used by the tenant connector. For gRPC, they can be initialized with the gRPC adapter of `InternalClient` returned by `NewGRPCInternalClientAdapter`, as these smaller services are a subset of the `Internal` service. However, a complication arises with `RPCTenantSpanConfigClient`. We can't simply use the generic `InternalClient` adapter because its streaming methods generate request/response types that embed the service name. For example: Let's take an example here: `RPCTenantServiceClient` has this method: ```go TenantSettings(ctx context.Context, in *TenantSettingsRequest) (RPCTenantService_TenantSettingsClient, error) ``` But `NewGRPCInternalClientAdapter` returns `RPCInternalClient`, which defines: ```go TenantSettings(ctx context.Context, in *TenantSettingsRequest) (RPCInternal_TenantSettingsClient, error) ``` So they are not compatible, even though `RPCInternal_TenantSettingsClient` and `RPCTenantService_TenantSettingsClient` are equivalent. The solution here is to create an adapter that adapts the `InternalClient` to `RPCTenantServiceClient`. ```go func (a *grpcInternalToTenantServiceClientAdapter) TenantSettings( ctx context.Context, in *TenantSettingsRequest, ) (RPCTenantService_TenantSettingsClient, error) { return (*internalClient)(a).TenantSettings(ctx, in) } ``` Release note: none Epic: CRDB-48923
1 parent add581c commit bcd8dd3

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

pkg/kv/kvclient/kvtenant/connector.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ type connector struct {
222222

223223
// client represents an RPC client that proxies to a KV instance.
224224
type client struct {
225-
kvpb.RPCInternalClient
225+
kvpb.RPCTenantServiceClient
226+
kvpb.RPCTenantUsageClient
227+
kvpb.RPCTenantSpanConfigClient
226228
serverpb.RPCStatusClient
227229
serverpb.RPCAdminClient
228230
tspb.RPCTimeSeriesClient
@@ -983,10 +985,12 @@ func (c *connector) dialAddrs(ctx context.Context) (*client, error) {
983985
continue
984986
}
985987
return &client{
986-
RPCInternalClient: kvpb.NewGRPCInternalClientAdapter(conn),
987-
RPCStatusClient: serverpb.NewGRPCStatusClientAdapter(conn),
988-
RPCAdminClient: serverpb.NewGRPCAdminClientAdapter(conn),
989-
RPCTimeSeriesClient: tspb.NewGRPCTimeSeriesClientAdapter(conn),
988+
RPCTenantServiceClient: kvpb.NewGRPCInternalToTenantServiceClientAdapter(conn),
989+
RPCTenantSpanConfigClient: kvpb.NewGRPCInternalClientAdapter(conn),
990+
RPCTenantUsageClient: kvpb.NewGRPCInternalClientAdapter(conn),
991+
RPCStatusClient: serverpb.NewGRPCStatusClientAdapter(conn),
992+
RPCAdminClient: serverpb.NewGRPCAdminClientAdapter(conn),
993+
RPCTimeSeriesClient: tspb.NewGRPCTimeSeriesClientAdapter(conn),
990994
}, nil
991995
}
992996
}

pkg/kv/kvpb/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
srcs = [
1111
"ambiguous_result_error.go",
1212
"api.go",
13+
"api_adapter.go",
1314
"batch.go",
1415
"data.go",
1516
"errors.go",
@@ -48,6 +49,7 @@ go_library(
4849
"@com_github_gogo_protobuf//types",
4950
"@com_github_gogo_status//:status",
5051
"@com_github_golang_mock//gomock", # keep
52+
"@org_golang_google_grpc//:grpc",
5153
"@org_golang_google_grpc//codes",
5254
"@org_golang_google_grpc//metadata", # keep
5355
],

pkg/kv/kvpb/api_adapter.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package kvpb
7+
8+
import (
9+
"context"
10+
11+
grpc "google.golang.org/grpc"
12+
)
13+
14+
type grpcInternalToTenantServiceClientAdapter internalClient
15+
16+
// NewGRPCInternalToTenantServiceClientAdapter creates a new
17+
// RPCTenantServiceClient that adapts an InternalClient. This is necessary
18+
// because the response types for streaming methods like TenantSettings are not
19+
// compatible between RPCInternal_TenantSettingsClient (of adapter returned by
20+
// NewGRPCInternalClientAdapter) and RPCTenantService_TenantSettingsClient (of
21+
// RPCTenantServiceClient), even though they are otherwise equivalent.
22+
func NewGRPCInternalToTenantServiceClientAdapter(conn *grpc.ClientConn) RPCTenantServiceClient {
23+
return (*grpcInternalToTenantServiceClientAdapter)(&internalClient{conn})
24+
}
25+
26+
func (a *grpcInternalToTenantServiceClientAdapter) TenantSettings(
27+
ctx context.Context, in *TenantSettingsRequest,
28+
) (RPCTenantService_TenantSettingsClient, error) {
29+
return (*internalClient)(a).TenantSettings(ctx, in)
30+
}
31+
32+
func (a *grpcInternalToTenantServiceClientAdapter) RangeLookup(
33+
ctx context.Context, in *RangeLookupRequest,
34+
) (*RangeLookupResponse, error) {
35+
return (*internalClient)(a).RangeLookup(ctx, in)
36+
}
37+
38+
func (a *grpcInternalToTenantServiceClientAdapter) GossipSubscription(
39+
ctx context.Context, in *GossipSubscriptionRequest,
40+
) (RPCTenantService_GossipSubscriptionClient, error) {
41+
return (*internalClient)(a).GossipSubscription(ctx, in)
42+
}
43+
44+
func (a *grpcInternalToTenantServiceClientAdapter) GetRangeDescriptors(
45+
ctx context.Context, in *GetRangeDescriptorsRequest,
46+
) (RPCTenantService_GetRangeDescriptorsClient, error) {
47+
return (*internalClient)(a).GetRangeDescriptors(ctx, in)
48+
}

0 commit comments

Comments
 (0)