Github user lvfangmin commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/588#discussion_r207604144
--- Diff: src/java/main/org/apache/zookeeper/server/quorum/Leader.java ---
@@ -1165,6 +1165,58 @@ synchronized public long
startForwarding(LearnerHandler handler,
}
// VisibleForTesting
protected final Set<Long> connectingFollowers = new HashSet<Long>();
+
+ private volatile boolean quitWaitForEpoch = false;
+ private volatile long timeStartWaitForEpoch = -1;
+ private volatile SyncedLearnerTracker voteSet;
+
+ public static final String MIN_TIME_WAIT_FOR_EPOCH =
"zookeeper.leader.minTimeToWaitForEpoch";
+ private static int minTimeToWaitForEpoch;
+ static {
+ minTimeToWaitForEpoch =
Integer.getInteger(MIN_TIME_WAIT_FOR_EPOCH, -1);
+ LOG.info(MIN_TIME_WAIT_FOR_EPOCH + " = " + minTimeToWaitForEpoch);
+ }
+
+ // visible for test
+ public static void setMinTimeToWaitForEpoch(int minTimeToWaitForEpoch)
{
+ Leader.minTimeToWaitForEpoch = minTimeToWaitForEpoch;
+ LOG.info(MIN_TIME_WAIT_FOR_EPOCH + " set to " +
minTimeToWaitForEpoch);
+ }
+
+ /**
+ * Quit condition:
+ *
+ * 1 voter goes to looking again and time waitForEpoch >
minTimeToWaitForEpoch
+ *
+ * Note: the voter may go to looking again due to:
+ * 1. change mind in the last minute when received a different
notifications
+ * 2. the leader hadn't started leading when it tried to connect to it.
+ */
+ private void quitLeading() {
+ synchronized(connectingFollowers) {
+ quitWaitForEpoch = true;
+ connectingFollowers.notifyAll();
+ }
+ LOG.info("Quit leading due to disloyal voter.");
--- End diff --
It's one of the expected case which might happen based on the current
FastLeaderElection code, but I think change to warning would catch more
attention, I'll do that.
---