You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2021/01/05 11:34:39 UTC

[GitHub] [incubator-ratis] runzhiwang commented on a change in pull request #383: RATIS-1273. Fix split brain by leader lease

runzhiwang commented on a change in pull request #383:
URL: https://github.com/apache/incubator-ratis/pull/383#discussion_r551877531



##########
File path: ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java
##########
@@ -905,6 +906,47 @@ private void yieldLeaderToHigherPriorityPeer() {
     }
   }
 
+  boolean isLeaderLeaseValid() {
+    if (checkLeaderLease()) {
+      return true;
+    }
+
+    updateLeaderLease();
+    return checkLeaderLease();
+  }
+
+  private boolean checkLeaderLease() {
+    return lastLeaderTimestamp.get().elapsedTimeMs() < server.properties().leaderLeaseTimeoutMs();
+  }
+
+  private boolean updateLeaderLease() {
+    Timestamp startLease = Timestamp.currentTime();
+
+    List<RaftPeerId> activePeers = new ArrayList<>();
+    List<FollowerInfo> followerInfos = getFollowerInfos();
+    for (final FollowerInfo info : followerInfos) {
+      if (info.getLastRpcSendTimeWithResponse().elapsedTimeMs() <= server.properties().leaderLeaseTimeoutMs()) {
+        if (startLease.compareTo(info.getLastRpcSendTimeWithResponse()) > 0) {
+          startLease = info.getLastRpcSendTimeWithResponse();
+        }
+        activePeers.add(info.getPeer().getId());
+      }
+    }

Review comment:
       @szetszwo I agree with you. @GlenGeng what do you think ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org