@@ -15,7 +15,6 @@ import (
15
15
"github.com/cockroachdb/cockroach/pkg/util/stop"
16
16
"github.com/cockroachdb/errors"
17
17
"google.golang.org/grpc"
18
- "storj.io/drpc"
19
18
)
20
19
21
20
// rpcConn defines a lightweight interface that both grpc.ClientConn and drpc.Conn
@@ -91,9 +90,6 @@ type Connection[Conn rpcConn] struct {
91
90
//
92
91
// The pool is only initialized once the rpc connection is resolved.
93
92
batchStreamPool streamPool [* kvpb.BatchRequest , * kvpb.BatchResponse , Conn ]
94
- // TODO(server): remove this once the code is consolidated to use generic
95
- // Connection and Pool for drpc.Conn.
96
- drpcBatchStreamPool DRPCBatchStreamPool
97
93
}
98
94
99
95
// newConnectionToNodeID makes a Connection for the given node, class, and nontrivial Signal
@@ -104,15 +100,13 @@ func newConnectionToNodeID[Conn rpcConn](
104
100
breakerSignal func () circuit.Signal ,
105
101
connOptions * ConnectionOptions [Conn ],
106
102
) * Connection [Conn ] {
107
- drpcConnEquals := func (a , b drpc.Conn ) bool { return a == b }
108
103
c := & Connection [Conn ]{
109
104
breakerSignalFn : breakerSignal ,
110
105
k : k ,
111
106
connFuture : connFuture [Conn ]{
112
107
ready : make (chan struct {}),
113
108
},
114
- batchStreamPool : makeStreamPool (opts .Stopper , connOptions .newBatchStreamClient , connOptions .connEquals ),
115
- drpcBatchStreamPool : makeStreamPool (opts .Stopper , newDRPCBatchStream , drpcConnEquals ),
109
+ batchStreamPool : makeStreamPool (opts .Stopper , connOptions .newBatchStreamClient , connOptions .connEquals ),
116
110
}
117
111
return c
118
112
}
@@ -124,15 +118,15 @@ func newConnectionToNodeID[Conn rpcConn](
124
118
// block but fall back to defErr in this case.
125
119
func (c * Connection [Conn ]) waitOrDefault (
126
120
ctx context.Context , defErr error , sig circuit.Signal ,
127
- ) (Conn , drpc. Conn , error ) {
121
+ ) (Conn , error ) {
128
122
// Check the circuit breaker first. If it is already tripped now, we
129
123
// want it to take precedence over connFuture below (which is closed in
130
124
// the common case of a connection going bad after having been healthy
131
125
// for a while).
132
126
var nilConn Conn
133
127
select {
134
128
case <- sig .C ():
135
- return nilConn , nil , sig .Err ()
129
+ return nilConn , sig .Err ()
136
130
default :
137
131
}
138
132
@@ -143,26 +137,26 @@ func (c *Connection[Conn]) waitOrDefault(
143
137
select {
144
138
case <- c .connFuture .C ():
145
139
case <- sig .C ():
146
- return nilConn , nil , sig .Err ()
140
+ return nilConn , sig .Err ()
147
141
case <- ctx .Done ():
148
- return nilConn , nil , errors .Wrapf (ctx .Err (), "while connecting to n%d at %s" , c .k .NodeID , c .k .TargetAddr )
142
+ return nilConn , errors .Wrapf (ctx .Err (), "while connecting to n%d at %s" , c .k .NodeID , c .k .TargetAddr )
149
143
}
150
144
} else {
151
145
select {
152
146
case <- c .connFuture .C ():
153
147
case <- sig .C ():
154
- return nilConn , nil , sig .Err ()
148
+ return nilConn , sig .Err ()
155
149
case <- ctx .Done ():
156
- return nilConn , nil , errors .Wrapf (ctx .Err (), "while connecting to n%d at %s" , c .k .NodeID , c .k .TargetAddr )
150
+ return nilConn , errors .Wrapf (ctx .Err (), "while connecting to n%d at %s" , c .k .NodeID , c .k .TargetAddr )
157
151
default :
158
- return nilConn , nil , defErr
152
+ return nilConn , defErr
159
153
}
160
154
}
161
155
162
156
// Done waiting, c.connFuture has resolved, return the result. Note that this
163
157
// conn could be unhealthy (or there may not even be a conn, i.e. Err() !=
164
158
// nil), if that's what the caller wanted (ConnectNoBreaker).
165
- return c .connFuture .Conn (), c .connFuture .DRPCConn (), c . connFuture . Err ()
159
+ return c .connFuture .Conn (), c .connFuture .Err ()
166
160
}
167
161
168
162
// Connect returns the underlying rpc connection after it has been validated,
@@ -172,18 +166,10 @@ func (c *Connection[Conn]) waitOrDefault(
172
166
// an error. In rare cases, this behavior is undesired and ConnectNoBreaker may
173
167
// be used instead.
174
168
func (c * Connection [Conn ]) Connect (ctx context.Context ) (Conn , error ) {
175
- cc , _ , err := c .waitOrDefault (ctx , nil /* defErr */ , c .breakerSignalFn ())
169
+ cc , err := c .waitOrDefault (ctx , nil /* defErr */ , c .breakerSignalFn ())
176
170
return cc , err
177
171
}
178
172
179
- // ConnectEx is similar to Connect but it addition to gRPC connection, it also
180
- // returns underlying drpc connection after it has been validated.
181
- // TODO(server): remove this once the code is consolidated to use generic
182
- // Connection and Pool for drpc.Conn.
183
- func (c * Connection [Conn ]) ConnectEx (ctx context.Context ) (Conn , drpc.Conn , error ) {
184
- return c .waitOrDefault (ctx , nil /* defErr */ , c .breakerSignalFn ())
185
- }
186
-
187
173
type neverTripSignal struct {}
188
174
189
175
func (s * neverTripSignal ) Err () error {
@@ -202,7 +188,7 @@ func (s *neverTripSignal) IsTripped() bool {
202
188
// that it will latch onto (or start) an existing connection attempt even if
203
189
// previous attempts have not succeeded. This may be preferable to Connect
204
190
// if the caller is already certain that a peer is available.
205
- func (c * Connection [Conn ]) ConnectNoBreaker (ctx context.Context ) (Conn , drpc. Conn , error ) {
191
+ func (c * Connection [Conn ]) ConnectNoBreaker (ctx context.Context ) (Conn , error ) {
206
192
// For ConnectNoBreaker we don't use the default Signal but pass a dummy one
207
193
// that never trips. (The probe tears down the Conn on quiesce so we don't rely
208
194
// on the Signal for that).
@@ -226,7 +212,7 @@ func (c *Connection[Conn]) ConnectNoBreaker(ctx context.Context) (Conn, drpc.Con
226
212
// latest heartbeat. Returns ErrNotHeartbeated if the peer was just contacted for
227
213
// the first time and the first heartbeat has not occurred yet.
228
214
func (c * Connection [Conn ]) Health () error {
229
- _ , _ , err := c .waitOrDefault (context .Background (), ErrNotHeartbeated , c .breakerSignalFn ())
215
+ _ , err := c .waitOrDefault (context .Background (), ErrNotHeartbeated , c .breakerSignalFn ())
230
216
return err
231
217
}
232
218
@@ -241,17 +227,9 @@ func (c *Connection[Conn]) BatchStreamPool() *streamPool[*kvpb.BatchRequest, *kv
241
227
return & c .batchStreamPool
242
228
}
243
229
244
- func (c * Connection [Conn ]) DRPCBatchStreamPool () * DRPCBatchStreamPool {
245
- if ! c .connFuture .Resolved () {
246
- panic ("DRPCBatchStreamPool called on unresolved connection" )
247
- }
248
- return & c .drpcBatchStreamPool
249
- }
250
-
251
230
type connFuture [Conn rpcConn ] struct {
252
231
ready chan struct {}
253
232
cc Conn
254
- dc drpc.Conn
255
233
err error
256
234
}
257
235
@@ -279,14 +257,6 @@ func (s *connFuture[Conn]) Conn() Conn {
279
257
return s .cc
280
258
}
281
259
282
- // DRPCConn must only be called after C() has been closed.
283
- func (s * connFuture [Conn ]) DRPCConn () drpc.Conn {
284
- if s .err != nil {
285
- return nil
286
- }
287
- return s .dc
288
- }
289
-
290
260
func (s * connFuture [Conn ]) Resolved () bool {
291
261
select {
292
262
case <- s .ready :
@@ -298,12 +268,12 @@ func (s *connFuture[Conn]) Resolved() bool {
298
268
299
269
// Resolve is idempotent. Only the first call has any effect.
300
270
// Not thread safe.
301
- func (s * connFuture [Conn ]) Resolve (cc Conn , dc drpc. Conn , err error ) {
271
+ func (s * connFuture [Conn ]) Resolve (cc Conn , err error ) {
302
272
select {
303
273
case <- s .ready :
304
274
// Already resolved, noop.
305
275
default :
306
- s .cc , s .dc , s . err = cc , dc , err
276
+ s .cc , s .err = cc , err
307
277
close (s .ready )
308
278
}
309
279
}
0 commit comments