Skip to content

Commit fe3f346

Browse files
craig[bot]cthumuluru-crdb
andcommitted
Merge #153031
153031: *: use generic dialers to create RPC clients r=cthumuluru-crdb a=cthumuluru-crdb Changes in this PR are followup to #152948. Epic: CRDB-48935 Informs: None Release note: None Co-authored-by: Chandra Thumuluru <[email protected]>
2 parents 9996bf4 + 3467330 commit fe3f346

File tree

9 files changed

+23
-91
lines changed

9 files changed

+23
-91
lines changed

pkg/blobs/blobspb/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ go_library(
2828
visibility = ["//visibility:public"],
2929
deps = [
3030
"//pkg/roachpb",
31+
"//pkg/rpc/nodedialer",
3132
"//pkg/rpc/rpcbase",
3233
],
3334
)

pkg/blobs/blobspb/rpc_clients.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ import (
99
context "context"
1010

1111
"github.com/cockroachdb/cockroach/pkg/roachpb"
12+
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
1213
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
1314
)
1415

1516
// DialBlobClient establishes a DRPC connection if enabled; otherwise,
1617
// it falls back to gRPC. The established connection is used to create a
1718
// RPCBlobClient.
1819
func DialBlobClient(
19-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
20+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
2021
) (RPCBlobClient, error) {
21-
if !rpcbase.TODODRPC {
22-
conn, err := nd.Dial(ctx, nodeID, class)
23-
if err != nil {
24-
return nil, err
25-
}
26-
return NewGRPCBlobClientAdapter(conn), nil
27-
}
28-
conn, err := nd.DRPCDial(ctx, nodeID, class)
29-
if err != nil {
30-
return nil, err
31-
}
32-
return NewDRPCBlobClientAdapter(conn), nil
22+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCBlobClientAdapter, NewDRPCBlobClientAdapter)
3323
}

pkg/keyvisualizer/keyvispb/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ go_library(
3737
visibility = ["//visibility:public"],
3838
deps = [
3939
"//pkg/roachpb",
40+
"//pkg/rpc/nodedialer",
4041
"//pkg/rpc/rpcbase",
4142
],
4243
)

pkg/keyvisualizer/keyvispb/rpc_clients.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ import (
99
context "context"
1010

1111
roachpb "github.com/cockroachdb/cockroach/pkg/roachpb"
12+
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
1213
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
1314
)
1415

1516
// DialKeyVisualizerClient establishes a DRPC connection if enabled; otherwise,
1617
// it falls back to gRPC. The established connection is used to create a
1718
// RPCKeyVisualizerClient.
1819
func DialKeyVisualizerClient(
19-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
20+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
2021
) (RPCKeyVisualizerClient, error) {
21-
if !rpcbase.TODODRPC {
22-
conn, err := nd.Dial(ctx, nodeID, class)
23-
if err != nil {
24-
return nil, err
25-
}
26-
return NewGRPCKeyVisualizerClientAdapter(conn), nil
27-
}
28-
conn, err := nd.DRPCDial(ctx, nodeID, class)
29-
if err != nil {
30-
return nil, err
31-
}
32-
return NewDRPCKeyVisualizerClientAdapter(conn), nil
22+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCKeyVisualizerClientAdapter, NewDRPCKeyVisualizerClientAdapter)
3323
}

pkg/kv/kvserver/rpc_clients.go

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,33 @@ import (
99
context "context"
1010

1111
"github.com/cockroachdb/cockroach/pkg/roachpb"
12+
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
1213
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
1314
)
1415

1516
// DialMultiRaftClient establishes a DRPC connection if enabled; otherwise,
1617
// it falls back to gRPC. The established connection is used to create a
1718
// RPCMultiRaftClient.
1819
func DialMultiRaftClient(
19-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
20+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
2021
) (RPCMultiRaftClient, error) {
21-
if !rpcbase.TODODRPC {
22-
conn, err := nd.Dial(ctx, nodeID, class)
23-
if err != nil {
24-
return nil, err
25-
}
26-
return NewGRPCMultiRaftClientAdapter(conn), nil
27-
}
28-
conn, err := nd.DRPCDial(ctx, nodeID, class)
29-
if err != nil {
30-
return nil, err
31-
}
32-
return NewDRPCMultiRaftClientAdapter(conn), nil
22+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCMultiRaftClientAdapter, NewDRPCMultiRaftClientAdapter)
3323
}
3424

3525
// DialPerReplicaClient establishes a DRPC connection if enabled; otherwise,
3626
// it falls back to gRPC. The established connection is used to create a
3727
// RPCPerReplicaClient.
3828
func DialPerReplicaClient(
39-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
29+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
4030
) (RPCPerReplicaClient, error) {
41-
if !rpcbase.TODODRPC {
42-
conn, err := nd.Dial(ctx, nodeID, class)
43-
if err != nil {
44-
return nil, err
45-
}
46-
return NewGRPCPerReplicaClientAdapter(conn), nil
47-
}
48-
conn, err := nd.DRPCDial(ctx, nodeID, class)
49-
if err != nil {
50-
return nil, err
51-
}
52-
return NewDRPCPerReplicaClientAdapter(conn), nil
31+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCPerReplicaClientAdapter, NewDRPCPerReplicaClientAdapter)
5332
}
5433

5534
// DialPerStoreClient establishes a DRPC connection if enabled; otherwise,
5635
// it falls back to gRPC. The established connection is used to create a
5736
// RPCPerStoreClient.
5837
func DialPerStoreClient(
59-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
38+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
6039
) (RPCPerStoreClient, error) {
61-
if !rpcbase.TODODRPC {
62-
conn, err := nd.Dial(ctx, nodeID, class)
63-
if err != nil {
64-
return nil, err
65-
}
66-
return NewGRPCPerStoreClientAdapter(conn), nil
67-
}
68-
conn, err := nd.DRPCDial(ctx, nodeID, class)
69-
if err != nil {
70-
return nil, err
71-
}
72-
return NewDRPCPerStoreClientAdapter(conn), nil
40+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCPerStoreClientAdapter, NewDRPCPerStoreClientAdapter)
7341
}

pkg/kv/kvserver/storeliveness/storelivenesspb/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ go_library(
4040
visibility = ["//visibility:public"],
4141
deps = [
4242
"//pkg/roachpb",
43+
"//pkg/rpc/nodedialer",
4344
"//pkg/rpc/rpcbase",
4445
],
4546
)

pkg/kv/kvserver/storeliveness/storelivenesspb/rpc_clients.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ import (
99
context "context"
1010

1111
"github.com/cockroachdb/cockroach/pkg/roachpb"
12+
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
1213
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
1314
)
1415

1516
// DialStoreLivenessClient establishes a DRPC connection if enabled; otherwise,
1617
// it falls back to gRPC. The established connection is used to create a
1718
// RPCStoreLivenessClient.
1819
func DialStoreLivenessClient(
19-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
20+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
2021
) (RPCStoreLivenessClient, error) {
21-
if !rpcbase.TODODRPC {
22-
conn, err := nd.Dial(ctx, nodeID, class)
23-
if err != nil {
24-
return nil, err
25-
}
26-
return NewGRPCStoreLivenessClientAdapter(conn), nil
27-
}
28-
conn, err := nd.DRPCDial(ctx, nodeID, class)
29-
if err != nil {
30-
return nil, err
31-
}
32-
return NewDRPCStoreLivenessClientAdapter(conn), nil
22+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCStoreLivenessClientAdapter, NewDRPCStoreLivenessClientAdapter)
3323
}

pkg/util/tracing/tracingservicepb/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ go_library(
3636
visibility = ["//visibility:public"],
3737
deps = [
3838
"//pkg/roachpb",
39+
"//pkg/rpc/nodedialer",
3940
"//pkg/rpc/rpcbase",
4041
],
4142
)

pkg/util/tracing/tracingservicepb/rpc_clients.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ import (
99
context "context"
1010

1111
"github.com/cockroachdb/cockroach/pkg/roachpb"
12+
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
1213
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
1314
)
1415

1516
// DialTracingClient establishes a DRPC connection if enabled; otherwise,
1617
// it falls back to gRPC. The established connection is used to create a
1718
// RPCTracingClient.
1819
func DialTracingClient(
19-
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
20+
nd *nodedialer.Dialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
2021
) (RPCTracingClient, error) {
21-
if !rpcbase.TODODRPC {
22-
conn, err := nd.Dial(ctx, nodeID, class)
23-
if err != nil {
24-
return nil, err
25-
}
26-
return NewGRPCTracingClientAdapter(conn), nil
27-
}
28-
conn, err := nd.DRPCDial(ctx, nodeID, class)
29-
if err != nil {
30-
return nil, err
31-
}
32-
return NewDRPCTracingClientAdapter(conn), nil
22+
return nodedialer.DialRPCClient(nd, ctx, nodeID, class, NewGRPCTracingClientAdapter, NewDRPCTracingClientAdapter)
3323
}

0 commit comments

Comments
 (0)