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 2020/07/17 10:41:03 UTC

[GitHub] [incubator-ratis] lokeshj1703 commented on a change in pull request #150: RATIS-981: Step-down stale leader in case of split-brain

lokeshj1703 commented on a change in pull request #150:
URL: https://github.com/apache/incubator-ratis/pull/150#discussion_r456362723



##########
File path: ratis-examples/src/test/java/org/apache/ratis/examples/ParameterizedBaseTest.java
##########
@@ -123,6 +126,11 @@ public boolean hasNext() {
     final RaftProperties prop = new RaftProperties();
     prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY,
         stateMachineClass, StateMachine.class);
+
+    // make sure leadership check won't affect the test
+    RaftServerConfigKeys.Rpc.setTimeoutMin(prop, TimeDuration.valueOf(2, TimeUnit.SECONDS));
+    RaftServerConfigKeys.Rpc.setTimeoutMax(prop, TimeDuration.valueOf(4, TimeUnit.SECONDS));

Review comment:
       We should not ideally require setting timeout in the tests. Are we experiencing flakiness in the tests due to the change?

##########
File path: ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderState.java
##########
@@ -787,6 +789,46 @@ private void replicateNewConf() {
     return lists;
   }
 
+  /**
+   * See the thesis section 6.2: A leader in Raft steps down
+   * if an election timeout elapses without a successful
+   * round of heartbeats to a majority of its cluster.
+   */
+  private void checkLeadership() {
+    // The initial value of lastRpcResponseTime in FollowerInfo is set by
+    // LeaderState::addSenders(), which is fake and used to trigger an
+    // immediate round of AppendEntries request. To ensure that leader
+    // is stable, just ignore the check if become leader soon.
+    if (server.getRole().getRoleElapsedTimeMs() < 3 * server.getMaxTimeoutMs()) {
+      return;
+    }
+
+    final List<RaftPeerId> activePeers = senders.stream()
+        .filter(sender -> sender.getFollower()
+                                .getLastRpcResponseTime()
+                                .elapsedTimeMs() <= server.getMaxTimeoutMs())

Review comment:
       Should we have a separate config for the timeout value? I think it might be better to have a separate config.

##########
File path: ratis-server/src/main/java/org/apache/ratis/server/impl/PeerConfiguration.java
##########
@@ -90,11 +90,8 @@ boolean hasMajority(Collection<RaftPeerId> others, RaftPeerId selfId) {
       if (contains(other)) {
         num++;
       }
-      if (num > size() / 2) {
-        return true;
-      }
     }
-    return false;
+    return num > size() / 2;

Review comment:
       `if (contains(selfId)) {
         num++;
     }`
   This check should handle single server case.




----------------------------------------------------------------
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