You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by ru...@apache.org on 2020/12/25 01:31:18 UTC

[incubator-ratis] branch master updated: RATIS-1264. Move routingTable to RaftRpcRequestProto (#375)

This is an automated email from the ASF dual-hosted git repository.

runzhiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 5cb7e31  RATIS-1264. Move routingTable to RaftRpcRequestProto (#375)
5cb7e31 is described below

commit 5cb7e31fba285fc729826b7086795c9e3682aa9a
Author: runzhiwang <51...@users.noreply.github.com>
AuthorDate: Fri Dec 25 09:31:11 2020 +0800

    RATIS-1264. Move routingTable to RaftRpcRequestProto (#375)
    
    * RATIS-1264. Move routingTable to RaftRpcRequestProto
    
    * fix code review
---
 .../apache/ratis/client/impl/ClientProtoUtils.java | 30 ++++++++++++----------
 ratis-proto/src/main/proto/Raft.proto              |  3 +--
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java b/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java
index 102e294..92459fd 100644
--- a/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java
+++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java
@@ -63,28 +63,35 @@ public interface ClientProtoUtils {
 
   static RaftRpcRequestProto.Builder toRaftRpcRequestProtoBuilder(RaftGroupMemberId requestorId, RaftPeerId replyId) {
     return toRaftRpcRequestProtoBuilder(requestorId.getPeerId().toByteString(),
-        replyId.toByteString(), requestorId.getGroupId(), null, null);
+        replyId.toByteString(), requestorId.getGroupId(), null, null, null);
   }
 
   static RaftRpcRequestProto.Builder toRaftRpcRequestProtoBuilder(
       ByteString requesterId, ByteString replyId, RaftGroupId groupId, Long callId,
-      SlidingWindowEntry slidingWindowEntry) {
+      SlidingWindowEntry slidingWindowEntry, RoutingTable routingTable) {
     if (slidingWindowEntry == null) {
       slidingWindowEntry = SlidingWindowEntry.getDefaultInstance();
     }
-    return RaftRpcRequestProto.newBuilder()
+
+    RaftRpcRequestProto.Builder b = RaftRpcRequestProto.newBuilder()
         .setRequestorId(requesterId)
         .setReplyId(replyId)
         .setRaftGroupId(ProtoUtils.toRaftGroupIdProtoBuilder(groupId))
         .setCallId(Optional.ofNullable(callId).orElseGet(CallId::getDefault))
         .setSlidingWindowEntry(slidingWindowEntry);
+
+    if (routingTable != null) {
+      b.setRoutingTable(routingTable.toProto());
+    }
+
+    return b;
   }
 
   static RaftRpcRequestProto.Builder toRaftRpcRequestProtoBuilder(
       ClientId requesterId, RaftPeerId replyId, RaftGroupId groupId, long callId,
-      SlidingWindowEntry slidingWindowEntry) {
+      SlidingWindowEntry slidingWindowEntry, RoutingTable routingTable) {
     return toRaftRpcRequestProtoBuilder(
-        requesterId.toByteString(), replyId.toByteString(), groupId, callId, slidingWindowEntry);
+        requesterId.toByteString(), replyId.toByteString(), groupId, callId, slidingWindowEntry, routingTable);
   }
 
   static RaftRpcRequestProto.Builder toRaftRpcRequestProtoBuilder(
@@ -94,7 +101,8 @@ public interface ClientProtoUtils {
         request.getServerId(),
         request.getRaftGroupId(),
         request.getCallId(),
-        request.getSlidingWindowEntry());
+        request.getSlidingWindowEntry(),
+        request.getRoutingTable());
   }
 
   static RaftClientRequest.Type toRaftClientRequestType(RaftClientRequestProto p) {
@@ -119,7 +127,7 @@ public interface ClientProtoUtils {
     }
   }
 
-  static RoutingTable getRoutingTable(RaftClientRequestProto p) {
+  static RoutingTable getRoutingTable(RaftRpcRequestProto p) {
     if (!p.hasRoutingTable()) {
       return null;
     }
@@ -147,7 +155,7 @@ public interface ClientProtoUtils {
         .setMessage(toMessage(p.getMessage()))
         .setType(type)
         .setSlidingWindowEntry(request.getSlidingWindowEntry())
-        .setRoutingTable(getRoutingTable(p))
+        .setRoutingTable(getRoutingTable(request))
         .build();
   }
 
@@ -162,10 +170,6 @@ public interface ClientProtoUtils {
       b.setMessage(toClientMessageEntryProtoBuilder(request.getMessage()));
     }
 
-    if (request.getRoutingTable() != null) {
-      b.setRoutingTable(request.getRoutingTable().toProto());
-    }
-
     final RaftClientRequest.Type type = request.getType();
     switch (type.getTypeCase()) {
       case WRITE:
@@ -202,7 +206,7 @@ public interface ClientProtoUtils {
       long seqNum, ByteString content) {
     return RaftClientRequestProto.newBuilder()
         .setRpcRequest(toRaftRpcRequestProtoBuilder(
-            clientId, serverId, groupId, callId, ProtoUtils.toSlidingWindowEntry(seqNum, false)))
+            clientId, serverId, groupId, callId, ProtoUtils.toSlidingWindowEntry(seqNum, false), null))
         .setWrite(WriteRequestTypeProto.getDefaultInstance())
         .setMessage(toClientMessageEntryProtoBuilder(content))
         .build();
diff --git a/ratis-proto/src/main/proto/Raft.proto b/ratis-proto/src/main/proto/Raft.proto
index 16c26c0..468c458 100644
--- a/ratis-proto/src/main/proto/Raft.proto
+++ b/ratis-proto/src/main/proto/Raft.proto
@@ -111,6 +111,7 @@ message RaftRpcRequestProto {
   RaftGroupIdProto raftGroupId = 3;
   uint64 callId = 4;
 
+  RoutingTableProto routingTable = 14;
   SlidingWindowEntry slidingWindowEntry = 15;
 }
 
@@ -307,8 +308,6 @@ message RaftClientRequestProto {
     DataStreamRequestTypeProto dataStream = 8;
     ForwardRequestTypeProto forward = 9;
   }
-
-  RoutingTableProto routingTable = 10;
 }
 
 message DataStreamPacketHeaderProto {