Skip to content

Conversation

@shubhamdhama
Copy link
Contributor

@shubhamdhama shubhamdhama commented Jun 18, 2025

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:

TenantSettings(ctx context.Context, in *TenantSettingsRequest) (RPCTenantService_TenantSettingsClient, error)

But NewGRPCInternalClientAdapter returns RPCInternalClient, which defines:

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.

func (a *grpcInternalToTenantServiceClientAdapter) TenantSettings(
	ctx context.Context, in *TenantSettingsRequest,
) (RPCTenantService_TenantSettingsClient, error) {
	return (*internalClient)(a).TenantSettings(ctx, in)
}

Informs: #148726
Release note: none
Epic: CRDB-48923

@blathers-crl
Copy link

blathers-crl bot commented Jun 18, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

}

func (c *connector) tryForgetClient(ctx context.Context, client kvpb.InternalClient) {
func (c *connector) tryForgetClient(ctx context.Context, client any) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chandra: change this from any to *client

@shubhamdhama shubhamdhama force-pushed the tenant-connector-replace-internal-client branch from 2828ef1 to f9f4a21 Compare June 20, 2025 10:15
@shubhamdhama shubhamdhama marked this pull request as ready for review June 20, 2025 10:15
@shubhamdhama shubhamdhama requested a review from a team as a code owner June 20, 2025 10:15
…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
@shubhamdhama shubhamdhama force-pushed the tenant-connector-replace-internal-client branch from f9f4a21 to bcd8dd3 Compare June 24, 2025 08:41
Copy link
Contributor

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

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

lgtm!

@shubhamdhama
Copy link
Contributor Author

TFTR!

bors r=cthumuluru-crdb

@craig
Copy link
Contributor

craig bot commented Jun 25, 2025

@craig craig bot merged commit a53b28b into cockroachdb:master Jun 25, 2025
22 checks passed
@shubhamdhama shubhamdhama linked an issue Jun 25, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drpc: split and register Internal service with DRPC server

3 participants