@@ -36,6 +36,7 @@ import (
36
36
"github.com/cockroachdb/cockroach/pkg/util/uuid"
37
37
"github.com/cockroachdb/errors"
38
38
"google.golang.org/grpc"
39
+ drpc "storj.io/drpc"
39
40
)
40
41
41
42
const (
@@ -78,7 +79,7 @@ type RaftMessageResponseStream interface {
78
79
// Send. Note that the default implementation of grpc.Stream for server
79
80
// responses (grpc.serverStream) is not safe for concurrent calls to Send.
80
81
type lockedRaftMessageResponseStream struct {
81
- wrapped MultiRaft_RaftMessageBatchServer
82
+ wrapped RPCMultiRaft_RaftMessageBatchStream
82
83
sendMu syncutil.Mutex
83
84
}
84
85
@@ -235,9 +236,7 @@ func NewDummyRaftTransport(
235
236
resolver := func (roachpb.NodeID ) (net.Addr , roachpb.Locality , error ) {
236
237
return nil , roachpb.Locality {}, errors .New ("dummy resolver" )
237
238
}
238
- return NewRaftTransport (ambient , st , nil , clock , nodedialer .New (nil , resolver ), nil ,
239
- nil , nil , nil ,
240
- )
239
+ return NewRaftTransport (ambient , st , nil , clock , nodedialer .New (nil , resolver ), nil , nil , nil , nil , nil )
241
240
}
242
241
243
242
// NewRaftTransport creates a new RaftTransport.
@@ -248,6 +247,7 @@ func NewRaftTransport(
248
247
clock * hlc.Clock ,
249
248
dialer * nodedialer.Dialer ,
250
249
grpcServer * grpc.Server ,
250
+ drpcMux drpc.Mux ,
251
251
piggybackReader node_rac2.PiggybackMsgReader ,
252
252
piggybackedResponseScheduler PiggybackedAdmittedResponseScheduler ,
253
253
knobs * RaftTransportTestingKnobs ,
@@ -271,6 +271,9 @@ func NewRaftTransport(
271
271
if grpcServer != nil {
272
272
RegisterMultiRaftServer (grpcServer , t )
273
273
}
274
+ if drpcMux != nil {
275
+ _ = DRPCRegisterMultiRaft (drpcMux , t .AsDRPCServer ())
276
+ }
274
277
return t
275
278
}
276
279
@@ -375,8 +378,29 @@ func newRaftMessageResponse(
375
378
return resp
376
379
}
377
380
381
+ type drpcRaftTransport RaftTransport
382
+
383
+ // AsDRPCServer returns the DRPC server implementation for the Raft service.
384
+ func (t * RaftTransport ) AsDRPCServer () DRPCMultiRaftServer {
385
+ return (* drpcRaftTransport )(t )
386
+ }
387
+
388
+ // RaftMessageBatch proxies the incoming requests to the listening server interface.
389
+ func (t * drpcRaftTransport ) RaftMessageBatch (
390
+ stream DRPCMultiRaft_RaftMessageBatchStream ,
391
+ ) (lastErr error ) {
392
+ return (* RaftTransport )(t ).raftMessageBatch (stream )
393
+ }
394
+
378
395
// RaftMessageBatch proxies the incoming requests to the listening server interface.
379
396
func (t * RaftTransport ) RaftMessageBatch (stream MultiRaft_RaftMessageBatchServer ) (lastErr error ) {
397
+ return t .raftMessageBatch (stream )
398
+ }
399
+
400
+ // raftMessageBatch is the shared implementation for RaftMessageBatch for both gRPC and DRPC.
401
+ func (t * RaftTransport ) raftMessageBatch (
402
+ stream RPCMultiRaft_RaftMessageBatchStream ,
403
+ ) (lastErr error ) {
380
404
errCh := make (chan error , 1 )
381
405
382
406
// Node stopping error is caught below in the select.
@@ -445,10 +469,25 @@ func (t *RaftTransport) RaftMessageBatch(stream MultiRaft_RaftMessageBatchServer
445
469
}
446
470
}
447
471
472
+ // DelegateRaftSnapshot handles incoming delegated snapshot requests and passes
473
+ // the request to pass off to the sender store. Errors during the snapshots
474
+ // process are sent back as a response.
475
+ func (t * drpcRaftTransport ) DelegateRaftSnapshot (
476
+ stream DRPCMultiRaft_DelegateRaftSnapshotStream ,
477
+ ) error {
478
+ return (* RaftTransport )(t ).delegateRaftSnapshot (stream )
479
+ }
480
+
448
481
// DelegateRaftSnapshot handles incoming delegated snapshot requests and passes
449
482
// the request to pass off to the sender store. Errors during the snapshots
450
483
// process are sent back as a response.
451
484
func (t * RaftTransport ) DelegateRaftSnapshot (stream MultiRaft_DelegateRaftSnapshotServer ) error {
485
+ return t .delegateRaftSnapshot (stream )
486
+ }
487
+
488
+ // delegateRaftSnapshot is the shared implementation for DelegateRaftSnapshot
489
+ // for both gRPC and DRPC.
490
+ func (t * RaftTransport ) delegateRaftSnapshot (stream RPCMultiRaft_DelegateRaftSnapshotStream ) error {
452
491
ctx , cancel := t .stopper .WithCancelOnQuiesce (stream .Context ())
453
492
defer cancel ()
454
493
req , err := stream .Recv ()
@@ -495,8 +534,18 @@ func (t *RaftTransport) InternalDelegateRaftSnapshot(
495
534
return incomingMessageHandler .HandleDelegatedSnapshot (ctx , req )
496
535
}
497
536
537
+ // RaftSnapshot handles incoming streaming snapshot requests.
538
+ func (t * drpcRaftTransport ) RaftSnapshot (stream DRPCMultiRaft_RaftSnapshotStream ) error {
539
+ return (* RaftTransport )(t ).raftSnapshot (stream )
540
+ }
541
+
498
542
// RaftSnapshot handles incoming streaming snapshot requests.
499
543
func (t * RaftTransport ) RaftSnapshot (stream MultiRaft_RaftSnapshotServer ) error {
544
+ return t .raftSnapshot (stream )
545
+ }
546
+
547
+ // raftSnapshot is the shared implementation for RaftSnapshot for both gRPC and DRPC.
548
+ func (t * RaftTransport ) raftSnapshot (stream RPCMultiRaft_RaftSnapshotStream ) error {
500
549
ctx , cancel := t .stopper .WithCancelOnQuiesce (stream .Context ())
501
550
defer cancel ()
502
551
req , err := stream .Recv ()
@@ -548,7 +597,7 @@ func (t *RaftTransport) StopOutgoingMessage(storeID roachpb.StoreID) {
548
597
// lost and a new instance of processQueue will be started by the next message
549
598
// to be sent.
550
599
func (t * RaftTransport ) processQueue (
551
- q * raftSendQueue , stream MultiRaft_RaftMessageBatchClient , _ rpcbase.ConnectionClass ,
600
+ q * raftSendQueue , stream RPCMultiRaft_RaftMessageBatchClient , _ rpcbase.ConnectionClass ,
552
601
) error {
553
602
errCh := make (chan error , 1 )
554
603
0 commit comments