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

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


The following commit(s) were added to refs/heads/master by this push:
     new b712ab5be RATIS-1903. Fix parameter number warning in 
RaftClientRequest. (#934)
b712ab5be is described below

commit b712ab5beb699852c3c220befcb2e695302bbd6c
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Sat Oct 14 10:24:54 2023 -0700

    RATIS-1903. Fix parameter number warning in RaftClientRequest. (#934)
---
 .../apache/ratis/client/impl/RaftClientImpl.java   |  4 +-
 .../apache/ratis/protocol/GroupInfoRequest.java    |  2 +-
 .../apache/ratis/protocol/GroupListRequest.java    |  2 +-
 .../ratis/protocol/GroupManagementRequest.java     |  2 +-
 .../protocol/LeaderElectionManagementRequest.java  |  2 +-
 .../apache/ratis/protocol/RaftClientRequest.java   | 74 +++++++++++++++-------
 .../java/org/apache/ratis/protocol/RaftPeer.java   |  9 ++-
 .../ratis/protocol/SetConfigurationRequest.java    |  2 +-
 8 files changed, 65 insertions(+), 32 deletions(-)

diff --git 
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java 
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
index 579c2f56b..e11490570 100644
--- 
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
+++ 
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
@@ -388,8 +388,8 @@ public final class RaftClientImpl implements RaftClient {
     final boolean reconnect = changeLeader || clientRpc.shouldReconnect(ioe);
     if (reconnect) {
       if (changeLeader && oldLeader.equals(getLeaderId())) {
-        LOG.debug("{} {}: client change Leader from {} to {} ex={}", groupId,
-            clientId, oldLeader, newLeader, ioe.getClass().getName());
+        LOG.debug("{} changes Leader from {} to {} for {}",
+            clientId, oldLeader, newLeader, groupId, ioe);
         this.leaderId = newLeader;
       }
       clientRpc.handleException(oldLeader, ioe, true);
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoRequest.java 
b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoRequest.java
index a62495e31..567c2beff 100644
--- a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoRequest.java
+++ b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoRequest.java
@@ -23,6 +23,6 @@ package org.apache.ratis.protocol;
  */
 public class GroupInfoRequest extends RaftClientRequest {
   public GroupInfoRequest(ClientId clientId, RaftPeerId serverId, RaftGroupId 
groupId, long callId) {
-    super(clientId, serverId, groupId, callId, false, readRequestType());
+    super(clientId, serverId, groupId, callId, readRequestType());
   }
 }
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupListRequest.java 
b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupListRequest.java
index e28e7b181..af38b6a77 100644
--- a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupListRequest.java
+++ b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupListRequest.java
@@ -23,6 +23,6 @@ package org.apache.ratis.protocol;
  */
 public class GroupListRequest extends RaftClientRequest {
   public GroupListRequest(ClientId clientId, RaftPeerId serverId, RaftGroupId 
groupId, long callId) {
-    super(clientId, serverId, groupId, callId, false, readRequestType());
+    super(clientId, serverId, groupId, callId, readRequestType());
   }
 }
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupManagementRequest.java
 
b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupManagementRequest.java
index 6aaee8e6e..a7e43ebc1 100644
--- 
a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupManagementRequest.java
+++ 
b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupManagementRequest.java
@@ -104,7 +104,7 @@ public final class GroupManagementRequest extends 
RaftClientRequest {
   private final Op op;
 
   private GroupManagementRequest(ClientId clientId, RaftPeerId serverId, long 
callId, Op op) {
-    super(clientId, serverId, op.getGroupId(), callId, false, 
writeRequestType());
+    super(clientId, serverId, op.getGroupId(), callId, writeRequestType());
     this.op = op;
   }
 
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/LeaderElectionManagementRequest.java
 
b/ratis-common/src/main/java/org/apache/ratis/protocol/LeaderElectionManagementRequest.java
index 6ca6f5094..39f9b26b5 100644
--- 
a/ratis-common/src/main/java/org/apache/ratis/protocol/LeaderElectionManagementRequest.java
+++ 
b/ratis-common/src/main/java/org/apache/ratis/protocol/LeaderElectionManagementRequest.java
@@ -53,7 +53,7 @@ public final class LeaderElectionManagementRequest extends 
RaftClientRequest{
 
   public LeaderElectionManagementRequest(
       ClientId clientId, RaftPeerId serverId, RaftGroupId groupId, long 
callId, Op op) {
-    super(clientId, serverId, groupId, callId, false, readRequestType());
+    super(clientId, serverId, groupId, callId, readRequestType());
     this.op = op;
   }
 
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java 
b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java
index 220694ce0..7c55a1822 100644
--- 
a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java
+++ 
b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java
@@ -86,7 +86,7 @@ public class RaftClientRequest extends RaftClientMessage {
     return new 
Type(WatchRequestTypeProto.newBuilder().setIndex(index).setReplication(replication).build());
   }
 
-  /** The type of a request (oneof write, read, staleRead, watch; see the 
message RaftClientRequestProto). */
+  /** The type of {@link RaftClientRequest} corresponding to {@link 
RaftClientRequestProto.TypeCase}. */
   public static final class Type {
     public static Type valueOf(WriteRequestTypeProto write) {
       return WRITE_DEFAULT;
@@ -160,8 +160,24 @@ public class RaftClientRequest extends RaftClientMessage {
       this(WATCH, watch);
     }
 
-    public boolean is(RaftClientRequestProto.TypeCase tCase) {
-      return getTypeCase().equals(tCase);
+    public boolean is(RaftClientRequestProto.TypeCase t) {
+      return getTypeCase() == t;
+    }
+
+    public boolean isReadOnly() {
+      switch (getTypeCase()) {
+        case READ:
+        case STALEREAD:
+        case WATCH:
+          return true;
+        case WRITE:
+        case MESSAGESTREAM:
+        case DATASTREAM:
+        case FORWARD:
+          return false;
+        default:
+          throw new IllegalStateException("Unexpected type case: " + 
getTypeCase());
+      }
     }
 
     public RaftClientRequestProto.TypeCase getTypeCase() {
@@ -258,8 +274,7 @@ public class RaftClientRequest extends RaftClientMessage {
     private long timeoutMs;
 
     public RaftClientRequest build() {
-      return new RaftClientRequest(
-          clientId, serverId, groupId, callId, toLeader, message, type, 
slidingWindowEntry, routingTable, timeoutMs);
+      return new RaftClientRequest(this);
     }
 
     public Builder setClientId(ClientId clientId) {
@@ -343,29 +358,38 @@ public class RaftClientRequest extends RaftClientMessage {
 
   private final boolean toLeader;
 
-  protected RaftClientRequest(ClientId clientId, RaftPeerId serverId, 
RaftGroupId groupId, long callId,
-      boolean toLeader, Type type) {
-    this(clientId, serverId, groupId, callId, toLeader, null, type, null, 
null, 0);
+  /** Construct a request for sending to the given server. */
+  protected RaftClientRequest(ClientId clientId, RaftPeerId serverId, 
RaftGroupId groupId, long callId, Type type) {
+    this(newBuilder()
+        .setClientId(clientId)
+        .setServerId(serverId)
+        .setGroupId(groupId)
+        .setCallId(callId)
+        .setType(type));
   }
 
-  protected RaftClientRequest(ClientId clientId, RaftPeerId serverId, 
RaftGroupId groupId, long callId, Type type,
+  /** Construct a request for sending to the Leader. */
+  protected RaftClientRequest(ClientId clientId, RaftPeerId leaderId, 
RaftGroupId groupId, long callId, Type type,
       long timeoutMs) {
-    this(clientId, serverId, groupId, callId, true, null, type, null, null, 
timeoutMs);
+    this(newBuilder()
+        .setClientId(clientId)
+        .setLeaderId(leaderId)
+        .setGroupId(groupId)
+        .setCallId(callId)
+        .setType(type)
+        .setTimeoutMs(timeoutMs));
   }
 
-  @SuppressWarnings("parameternumber")
-  private RaftClientRequest(
-      ClientId clientId, RaftPeerId serverId, RaftGroupId groupId,
-      long callId, boolean toLeader, Message message, Type type, 
SlidingWindowEntry slidingWindowEntry,
-      RoutingTable routingTable, long timeoutMs) {
-    super(clientId, serverId, groupId, callId);
-    this.toLeader = toLeader;
-
-    this.message = message;
-    this.type = type;
-    this.slidingWindowEntry = slidingWindowEntry != null? slidingWindowEntry: 
SlidingWindowEntry.getDefaultInstance();
-    this.routingTable = routingTable;
-    this.timeoutMs = timeoutMs;
+  private RaftClientRequest(Builder b) {
+    super(b.clientId, b.serverId, b.groupId, b.callId);
+    this.toLeader = b.toLeader;
+
+    this.message = b.message;
+    this.type = b.type;
+    this.slidingWindowEntry = b.slidingWindowEntry != null ? 
b.slidingWindowEntry
+        : SlidingWindowEntry.getDefaultInstance();
+    this.routingTable = b.routingTable;
+    this.timeoutMs = b.timeoutMs;
   }
 
   @Override
@@ -393,6 +417,10 @@ public class RaftClientRequest extends RaftClientMessage {
     return getType().is(typeCase);
   }
 
+  public boolean isReadOnly() {
+    return getType().isReadOnly();
+  }
+
   public RoutingTable getRoutingTable() {
     return routingTable;
   }
diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeer.java 
b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeer.java
index b3cea81a6..e7bfee3cd 100644
--- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeer.java
+++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeer.java
@@ -236,7 +236,12 @@ public final class RaftPeer {
 
   @Override
   public String toString() {
-    final String rpc = address != null? "|rpc:" + address: "";
+    final String rpc = address != null? "|" + address: "";
+    return id + rpc;
+  }
+
+  public String getDetails() {
+    final String prefix = toString();
     final String admin = adminAddress != null && !Objects.equals(address, 
adminAddress)
         ? "|admin:" + adminAddress : "";
     final String client = clientAddress != null && !Objects.equals(address, 
clientAddress)
@@ -244,7 +249,7 @@ public final class RaftPeer {
     final String data = dataStreamAddress != null? "|dataStream:" + 
dataStreamAddress: "";
     final String p = "|priority:" + priority;
     final String role = "|startupRole:" + startupRole;
-    return id + rpc + admin + client + data + p + role;
+    return prefix + admin + client + data + p + role;
   }
 
   @Override
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java
 
b/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java
index 4f78c2b94..8234b4c43 100644
--- 
a/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java
+++ 
b/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java
@@ -167,7 +167,7 @@ public class SetConfigurationRequest extends 
RaftClientRequest {
 
   public SetConfigurationRequest(ClientId clientId, RaftPeerId serverId,
       RaftGroupId groupId, long callId, Arguments arguments) {
-    super(clientId, serverId, groupId, callId, true, writeRequestType());
+    super(clientId, serverId, groupId, callId, writeRequestType(), 0);
     this.arguments = arguments;
   }
 

Reply via email to