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 bdad0836 RATIS-1574. Add follower information to 
LeaderEventApi.notifyFollowerSlowness(..) (#638)
bdad0836 is described below

commit bdad083683e281b68b386d30be0b82fd529f913f
Author: BHY <[email protected]>
AuthorDate: Tue May 3 15:59:03 2022 +0900

    RATIS-1574. Add follower information to 
LeaderEventApi.notifyFollowerSlowness(..) (#638)
---
 .../main/java/org/apache/ratis/statemachine/StateMachine.java  | 10 ++++++++--
 .../java/org/apache/ratis/server/impl/LeaderStateImpl.java     |  5 ++++-
 .../apache/ratis/statemachine/SimpleStateMachine4Testing.java  |  7 ++++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git 
a/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
 
b/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
index 0fba2e69..3a0ca400 100644
--- 
a/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
+++ 
b/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
@@ -27,6 +27,7 @@ import org.apache.ratis.protocol.Message;
 import org.apache.ratis.protocol.RaftClientRequest;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftGroupMemberId;
+import org.apache.ratis.protocol.RaftPeer;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.server.RaftServer;
 import org.apache.ratis.server.protocol.TermIndex;
@@ -202,11 +203,16 @@ public interface StateMachine extends Closeable {
      * Notify the {@link StateMachine} that the given follower is slow.
      * This notification is based on "raft.server.rpc.slowness.timeout".
      *
-     * @param roleInfoProto information about the current node role and rpc 
delay information
+     * @param leaderInfo information about the current node role and rpc delay 
information
+     * @param slowFollower The follower being slow.
      *
      * @see 
org.apache.ratis.server.RaftServerConfigKeys.Rpc#SLOWNESS_TIMEOUT_KEY
      */
-    default void notifyFollowerSlowness(RoleInfoProto roleInfoProto) {}
+    default void notifyFollowerSlowness(RoleInfoProto leaderInfo, RaftPeer 
slowFollower) {}
+
+    /** @deprecated Use {@link #notifyFollowerSlowness(RoleInfoProto, 
RaftPeer)}. */
+    @Deprecated
+    default void notifyFollowerSlowness(RoleInfoProto leaderInfo) {}
 
     /**
      * Notify {@link StateMachine} that this server is no longer the leader.
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java
index 49ad6849..068c7e5c 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java
@@ -24,6 +24,7 @@ import org.apache.ratis.proto.RaftProtos.LogEntryProto;
 import org.apache.ratis.proto.RaftProtos.LogEntryProto.LogEntryBodyCase;
 import org.apache.ratis.proto.RaftProtos.RaftPeerRole;
 import org.apache.ratis.proto.RaftProtos.ReplicationLevel;
+import org.apache.ratis.proto.RaftProtos.RoleInfoProto;
 import org.apache.ratis.proto.RaftProtos.StartLeaderElectionReplyProto;
 import org.apache.ratis.proto.RaftProtos.StartLeaderElectionRequestProto;
 import org.apache.ratis.protocol.Message;
@@ -1117,7 +1118,9 @@ class LeaderStateImpl implements LeaderState {
   public void checkHealth(FollowerInfo follower) {
     final TimeDuration elapsedTime = 
follower.getLastRpcResponseTime().elapsedTime();
     if (elapsedTime.compareTo(server.properties().rpcSlownessTimeout()) > 0) {
-      
server.getStateMachine().leaderEvent().notifyFollowerSlowness(server.getInfo().getRoleInfoProto());
+      final RoleInfoProto leaderInfo = server.getInfo().getRoleInfoProto();
+      
server.getStateMachine().leaderEvent().notifyFollowerSlowness(leaderInfo);
+      
server.getStateMachine().leaderEvent().notifyFollowerSlowness(leaderInfo, 
follower.getPeer());
     }
     final RaftPeerId followerId = follower.getPeer().getId();
     raftServerMetrics.recordFollowerHeartbeatElapsedTime(followerId, 
elapsedTime.toLong(TimeUnit.NANOSECONDS));
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
 
b/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
index b8882d5e..2b4d2b87 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
@@ -26,6 +26,7 @@ import org.apache.ratis.protocol.Message;
 import org.apache.ratis.protocol.RaftClientRequest;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftGroupMemberId;
+import org.apache.ratis.protocol.RaftPeer;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.protocol.exceptions.StateMachineException;
 import org.apache.ratis.server.RaftServer;
@@ -416,9 +417,9 @@ public class SimpleStateMachine4Testing extends 
BaseStateMachine {
   }
 
   @Override
-  public void notifyFollowerSlowness(RoleInfoProto roleInfoProto) {
-    LOG.info("{}: notifySlowness {}, {}", this, groupId, roleInfoProto);
-    slownessInfo = roleInfoProto;
+  public void notifyFollowerSlowness(RoleInfoProto leaderInfo, RaftPeer 
slowFollower) {
+    LOG.info("{}: notifySlowness {}, {}, {}", this, groupId, leaderInfo, 
slowFollower);
+    slownessInfo = leaderInfo;
   }
 
   @Override

Reply via email to