@@ -601,18 +601,47 @@ impl RaftNetworkV2<TypeConfig> for Network {
601601 ) -> Result < VoteResponse , RPCError > {
602602 info ! ( id = self . id, target = self . target, rpc = rpc. summary( ) ; "send_vote" ) ;
603603
604- let raft_req = GrpcHelper :: encode_raft_request ( & rpc) . map_err ( |e| Unreachable :: new ( & e) ) ?;
604+ let mut client = self
605+ . take_client ( )
606+ . log_elapsed_debug ( "Raft NetworkConnection vote take_client()" )
607+ . await ?;
608+
609+ // First, try VoteV001 with native protobuf types
610+ let vote_req_pb = pb:: VoteRequest :: from ( rpc. clone ( ) ) ;
611+ let req_v001 = GrpcHelper :: traced_req ( vote_req_pb) ;
612+
613+ let grpc_res_v001 = client. vote_v001 ( req_v001) . await ;
614+ info ! (
615+ "vote_v001: resp from target={} {:?}" ,
616+ self . target, grpc_res_v001
617+ ) ;
618+
619+ match grpc_res_v001 {
620+ Ok ( response) => {
621+ // VoteV001 succeeded, parse the VoteResponse directly
622+ self . client . lock ( ) . await . replace ( client) ;
623+ let vote_response = response. into_inner ( ) ;
624+ let vote_resp: VoteResponse = vote_response. into ( ) ;
625+ return Ok ( vote_resp) ;
626+ }
627+ Err ( e) => {
628+ // Only fall back for specific status codes indicating method not implemented
629+ if matches ! ( e. code( ) , tonic:: Code :: Unimplemented | tonic:: Code :: NotFound ) {
630+ warn ! ( target = self . target, rpc = rpc. summary( ) ; "vote_v001 not implemented, falling back to vote: {}" , e) ;
631+ } else {
632+ // For other errors, don't fall back - return the error
633+ return Err ( RPCError :: Unreachable ( self . status_to_unreachable ( e. clone ( ) ) ) ) ;
634+ }
635+ }
636+ }
605637
638+ // Fallback to old Vote RPC using RaftRequest
639+ let raft_req = GrpcHelper :: encode_raft_request ( & rpc) . map_err ( |e| Unreachable :: new ( & e) ) ?;
606640 let req = GrpcHelper :: traced_req ( raft_req) ;
607641
608642 let bytes = req. get_ref ( ) . data . len ( ) as u64 ;
609643 raft_metrics:: network:: incr_sendto_bytes ( & self . target , bytes) ;
610644
611- let mut client = self
612- . take_client ( )
613- . log_elapsed_debug ( "Raft NetworkConnection vote take_client()" )
614- . await ?;
615-
616645 let grpc_res = client. vote ( req) . await ;
617646 info ! ( "vote: resp from target={} {:?}" , self . target, grpc_res) ;
618647
0 commit comments