Selaa lähdekoodia

ZOOKEEPER-3218: Add min notification interval property for fast leader election

…to the new leader is too long,then session expired

Author: Brian Nixon <nixon@fb.com>

Reviewers: fangmin@apache.org, eolivelli@apache.org

Closes #747 from enixon/noti-inter
Brian Nixon 6 vuotta sitten
vanhempi
commit
0b504dec95

+ 18 - 0
zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md

@@ -720,6 +720,24 @@ property, when available, is noted below.
     of the observers on restart. Set to "false" to disable this
     feature. Default is "true"
 
+* *fastleader.minNotificationInterval* :
+    (Java system property: **zookeeper.fastleader.minNotificationInterval**)
+    Lower bound for length of time between two consecutive notification
+    checks on the leader election. This interval determines how long a
+    peer waits to check the set of election votes and effects how
+    quickly an election can resolve. The interval follows a backoff
+    strategy from the configured minimum (this) and the configured maximum
+    (fastleader.maxNotificationInterval) for long elections.
+
+* *fastleader.maxNotificationInterval* :
+    (Java system property: **zookeeper.fastleader.maxNotificationInterval**)
+    Upper bound for length of time between two consecutive notification
+    checks on the leader election. This interval determines how long a
+    peer waits to check the set of election votes and effects how
+    quickly an election can resolve. The interval follows a backoff
+    strategy from the configured minimum (fastleader.minNotificationInterval)
+    and the configured maximum (this) for long elections.
+
 <a name="sc_clusterOptions"></a>
 
 #### Cluster Options

+ 29 - 2
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/FastLeaderElection.java

@@ -68,7 +68,34 @@ public class FastLeaderElection implements Election {
      * the system up again after long partitions. Currently 60 seconds.
      */
 
-    final static int maxNotificationInterval = 60000;
+    private static int maxNotificationInterval = 60000;
+
+    /**
+     * Lower bound for notification check. The observer don't need to use
+     * the same lower bound as participant members
+     */
+    private static int minNotificationInterval = finalizeWait;
+
+    /**
+     * Minimum notification interval, default is equal to finalizeWait
+     */
+    public static final String MIN_NOTIFICATION_INTERVAL =
+            "zookeeper.fastleader.minNotificationInterval";
+
+    /**
+     * Maximum notification interval, default is 60s
+     */
+    public static final String MAX_NOTIFICATION_INTERVAL =
+            "zookeeper.fastleader.maxNotificationInterval";
+
+    static {
+        minNotificationInterval = Integer.getInteger(MIN_NOTIFICATION_INTERVAL,
+                minNotificationInterval);
+        LOG.info("{}={}", MIN_NOTIFICATION_INTERVAL, minNotificationInterval);
+        maxNotificationInterval = Integer.getInteger(MAX_NOTIFICATION_INTERVAL,
+                maxNotificationInterval);
+        LOG.info("{}={}", MAX_NOTIFICATION_INTERVAL, maxNotificationInterval);
+    }
 
     /**
      * Connection manager. Fast leader election uses TCP for
@@ -898,7 +925,7 @@ public class FastLeaderElection implements Election {
 
             Map<Long, Vote> outofelection = new HashMap<Long, Vote>();
 
-            int notTimeout = finalizeWait;
+            int notTimeout = minNotificationInterval;
 
             synchronized(this){
                 logicalclock.incrementAndGet();