forked from storj/drpc
-
Notifications
You must be signed in to change notification settings - Fork 3
codegen: create RPC service interface with gRPC & DRPC adapters #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shubhamdhama
merged 1 commit into
cockroachdb:main
from
shubhamdhama:add-grpc-drpc-adapters
Jun 3, 2025
Merged
codegen: create RPC service interface with gRPC & DRPC adapters #4
shubhamdhama
merged 1 commit into
cockroachdb:main
from
shubhamdhama:add-grpc-drpc-adapters
Jun 3, 2025
+104
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shubhamdhama
added a commit
to shubhamdhama/cockroach
that referenced
this pull request
May 18, 2025
Enable MultiRaft service on the DRPC server in addition to gRPC. Controlled by `rpc.experimental_drpc.enabled` (off by default). It uses the adapters introduced by: cockroachdb/drpc#4
This was referenced May 19, 2025
2168317
to
23a74f1
Compare
shubhamdhama
added a commit
to shubhamdhama/cockroach
that referenced
this pull request
May 30, 2025
Enable MultiRaft service on the DRPC server in addition to gRPC. Controlled by `rpc.experimental_drpc.enabled` (off by default). It uses the adapters introduced by: cockroachdb/drpc#4
Example code generated by this: // MultiRaft gRPC -> RPC adapter
type grpcMultiRaftClientAdapter multiRaftClient
func NewGRPCMultiRaftClientAdapter(conn *grpc.ClientConn) RPCMultiRaftClient {
return (*grpcMultiRaftClientAdapter)(&multiRaftClient{conn})
}
func (a *grpcMultiRaftClientAdapter) RaftMessageBatch(ctx context.Context) (RPCMultiRaft_RaftMessageBatchClient, error) {
return (*multiRaftClient)(a).RaftMessageBatch(ctx)
}
func (a *grpcMultiRaftClientAdapter) RaftSnapshot(ctx context.Context) (RPCMultiRaft_RaftSnapshotClient, error) {
return (*multiRaftClient)(a).RaftSnapshot(ctx)
}
func (a *grpcMultiRaftClientAdapter) DelegateRaftSnapshot(ctx context.Context) (RPCMultiRaft_DelegateRaftSnapshotClient, error) {
return (*multiRaftClient)(a).DelegateRaftSnapshot(ctx)
}
// compile-time assertion
var _ RPCMultiRaftClient = (*grpcMultiRaftClientAdapter)(nil)
// MultiRaft DRPC -> RPC adapter
type drpcMultiRaftClientAdapter drpcMultiRaftClient
func NewDRPCMultiRaftClientAdapter(conn drpc.Conn) RPCMultiRaftClient {
return (*drpcMultiRaftClientAdapter)(&drpcMultiRaftClient{conn})
}
func (a *drpcMultiRaftClientAdapter) RaftMessageBatch(ctx context.Context) (RPCMultiRaft_RaftMessageBatchClient, error) {
return (*drpcMultiRaftClient)(a).RaftMessageBatch(ctx)
}
func (a *drpcMultiRaftClientAdapter) RaftSnapshot(ctx context.Context) (RPCMultiRaft_RaftSnapshotClient, error) {
return (*drpcMultiRaftClient)(a).RaftSnapshot(ctx)
}
func (a *drpcMultiRaftClientAdapter) DelegateRaftSnapshot(ctx context.Context) (RPCMultiRaft_DelegateRaftSnapshotClient, error) {
return (*drpcMultiRaftClient)(a).DelegateRaftSnapshot(ctx)
}
// compile-time assertion
var _ RPCMultiRaftClient = (*drpcMultiRaftClientAdapter)(nil) |
Define a shared `RPC<Service>Client` interface to wrap both gRPC's `<Service>Client` and DRPC's `DRPC<Service>Client`. Streaming methods will also return the common `RPC<Service>_<Method>Client`. Adds two simple adapters: - `NewGRPC<Service>ClientAdapter` - `NewDRPC<Service>ClientAdapter` They implement `RPC<Service>Client`, so we can swap clients at runtime via the cluster setting.
23a74f1
to
c5c11ef
Compare
Same as #2 (comment) here for why tests are missing for these changes. |
cthumuluru-crdb
approved these changes
Jun 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
shubhamdhama
added a commit
to shubhamdhama/cockroach
that referenced
this pull request
Jun 3, 2025
This will pickup the following changes: 1. cockroachdb/drpc#3 2. cockroachdb/drpc#2 3. cockroachdb/drpc#4 4. cockroachdb/drpc#6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
stacked on #2
Define a shared
RPC<Service>Client
interface to wrap both gRPC's<Service>Client
and DRPC'sDRPC<Service>Client
. Streaming methods willalso return the common
RPC<Service>_<Method>Client
.Adds two simple adapters:
NewGRPC<Service>ClientAdapter
NewDRPC<Service>ClientAdapter
They implement
RPC<Service>Client
, so we can swap clients at runtime viathe cluster setting.