@@ -9,110 +9,62 @@ import (
9
9
context "context"
10
10
11
11
roachpb "github.com/cockroachdb/cockroach/pkg/roachpb"
12
+ "github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
12
13
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
14
+ "github.com/cockroachdb/cockroach/pkg/settings/cluster"
13
15
)
14
16
15
17
// DialMigrationClient establishes a DRPC connection if enabled; otherwise,
16
18
// it falls back to gRPC. The established connection is used to create a
17
19
// RPCMigrationClient.
18
20
func DialMigrationClient (
19
- nd rpcbase.NodeDialer , ctx context.Context , nodeID roachpb.NodeID , class rpcbase.ConnectionClass ,
21
+ nd rpcbase.NodeDialer ,
22
+ ctx context.Context ,
23
+ nodeID roachpb.NodeID ,
24
+ class rpcbase.ConnectionClass ,
25
+ cs * cluster.Settings ,
20
26
) (RPCMigrationClient , error ) {
21
- if ! rpcbase .TODODRPC {
22
- conn , err := nd .Dial (ctx , nodeID , class )
23
- if err != nil {
24
- return nil , err
25
- }
26
- return NewGRPCMigrationClientAdapter (conn ), nil
27
- }
28
- conn , err := nd .DRPCDial (ctx , nodeID , class )
29
- if err != nil {
30
- return nil , err
31
- }
32
- return NewDRPCMigrationClientAdapter (conn ), nil
27
+ return rpcbase .DialRPCClient (nd , ctx , nodeID , class , NewGRPCMigrationClientAdapter , NewDRPCMigrationClientAdapter , cs )
33
28
}
34
29
35
30
// DialStatusClientNoBreaker establishes a DRPC connection if enabled;
36
31
// otherwise, it falls back to gRPC. The established connection is used
37
32
// to create a StatusClient. This method is same as DialStatusClient, but it
38
33
// does not check the breaker before dialing the connection.
39
34
func DialStatusClientNoBreaker (
40
- nd rpcbase.NodeDialerNoBreaker ,
41
- ctx context.Context ,
42
- nodeID roachpb.NodeID ,
43
- class rpcbase.ConnectionClass ,
35
+ nd * nodedialer.Dialer , ctx context.Context , nodeID roachpb.NodeID , class rpcbase.ConnectionClass ,
44
36
) (RPCStatusClient , error ) {
45
- if ! rpcbase .TODODRPC {
46
- conn , err := nd .DialNoBreaker (ctx , nodeID , class )
47
- if err != nil {
48
- return nil , err
49
- }
50
- return NewGRPCStatusClientAdapter (conn ), nil
51
- }
52
- conn , err := nd .DRPCDialNoBreaker (ctx , nodeID , class )
53
- if err != nil {
54
- return nil , err
55
- }
56
- return NewDRPCStatusClientAdapter (conn ), nil
37
+ return nodedialer .DialRPCClientNoBreaker (nd , ctx , nodeID , class ,
38
+ NewGRPCStatusClientAdapter , NewDRPCStatusClientAdapter )
57
39
}
58
40
59
41
// DialStatusClient establishes a DRPC connection if enabled; otherwise, it
60
42
// falls back to gRPC. The established connection is used to create a
61
43
// RPCStatusClient.
62
44
func DialStatusClient (
63
- nd rpcbase.NodeDialer , ctx context.Context , nodeID roachpb.NodeID ,
45
+ nd rpcbase.NodeDialer , ctx context.Context , nodeID roachpb.NodeID , cs * cluster. Settings ,
64
46
) (RPCStatusClient , error ) {
65
- if ! rpcbase .TODODRPC {
66
- conn , err := nd .Dial (ctx , nodeID , rpcbase .DefaultClass )
67
- if err != nil {
68
- return nil , err
69
- }
70
- return NewGRPCStatusClientAdapter (conn ), nil
71
- }
72
- conn , err := nd .DRPCDial (ctx , nodeID , rpcbase .DefaultClass )
73
- if err != nil {
74
- return nil , err
75
- }
76
- return NewDRPCStatusClientAdapter (conn ), nil
47
+ return rpcbase .DialRPCClient (nd , ctx , nodeID , rpcbase .DefaultClass ,
48
+ NewGRPCStatusClientAdapter , NewDRPCStatusClientAdapter , cs )
77
49
}
78
50
79
51
// DialAdminClient establishes a DRPC connection if enabled; otherwise, it
80
52
// falls back to gRPC. The established connection is used to create a
81
53
// RPCAdminClient.
82
54
func DialAdminClient (
83
- nd rpcbase.NodeDialer , ctx context.Context , nodeID roachpb.NodeID ,
55
+ nd rpcbase.NodeDialer , ctx context.Context , nodeID roachpb.NodeID , cs * cluster. Settings ,
84
56
) (RPCAdminClient , error ) {
85
- if ! rpcbase .TODODRPC {
86
- conn , err := nd .Dial (ctx , nodeID , rpcbase .DefaultClass )
87
- if err != nil {
88
- return nil , err
89
- }
90
- return NewGRPCAdminClientAdapter (conn ), nil
91
- }
92
- conn , err := nd .DRPCDial (ctx , nodeID , rpcbase .DefaultClass )
93
- if err != nil {
94
- return nil , err
95
- }
96
- return NewDRPCAdminClientAdapter (conn ), nil
57
+ return rpcbase .DialRPCClient (nd , ctx , nodeID , rpcbase .DefaultClass ,
58
+ NewGRPCAdminClientAdapter , NewDRPCAdminClientAdapter , cs )
97
59
}
98
60
99
61
// DialAdminClientNoBreaker establishes a DRPC connection if enabled;
100
62
// otherwise, it falls back to gRPC. The established connection is used to
101
63
// create a AdminClient. This method is same as DialAdminClient, but it
102
64
// does not check the breaker before dialing the connection.
103
65
func DialAdminClientNoBreaker (
104
- nd rpcbase. NodeDialerNoBreaker , ctx context.Context , nodeID roachpb.NodeID ,
66
+ nd * nodedialer. Dialer , ctx context.Context , nodeID roachpb.NodeID ,
105
67
) (RPCAdminClient , error ) {
106
- if ! rpcbase .TODODRPC {
107
- conn , err := nd .DialNoBreaker (ctx , nodeID , rpcbase .DefaultClass )
108
- if err != nil {
109
- return nil , err
110
- }
111
- return NewGRPCAdminClientAdapter (conn ), nil
112
- }
113
- conn , err := nd .DRPCDialNoBreaker (ctx , nodeID , rpcbase .DefaultClass )
114
- if err != nil {
115
- return nil , err
116
- }
117
- return NewDRPCAdminClientAdapter (conn ), nil
68
+ return nodedialer .DialRPCClientNoBreaker (nd , ctx , nodeID , rpcbase .DefaultClass ,
69
+ NewGRPCAdminClientAdapter , NewDRPCAdminClientAdapter )
118
70
}
0 commit comments