Class FastLeaderElection

  • All Implemented Interfaces:
    Election

    public class FastLeaderElection
    extends Object
    implements Election
    Implementation of leader election using TCP. It uses an object of the class QuorumCnxManager to manage connections. Otherwise, the algorithm is push-based as with the other UDP implementations. There are a few parameters that can be tuned to change its behavior. First, finalizeWait determines the amount of time to wait until deciding upon a leader. This is part of the leader election algorithm.
    • Field Detail

      • MIN_NOTIFICATION_INTERVAL

        public static final String MIN_NOTIFICATION_INTERVAL
        Minimum notification interval, default is equal to finalizeWait
        See Also:
        Constant Field Values
      • MAX_NOTIFICATION_INTERVAL

        public static final String MAX_NOTIFICATION_INTERVAL
        Maximum notification interval, default is 60s
        See Also:
        Constant Field Values
    • Constructor Detail

      • FastLeaderElection

        public FastLeaderElection​(QuorumPeer self,
                                  QuorumCnxManager manager)
        Constructor of FastLeaderElection. It takes two parameters, one is the QuorumPeer object that instantiated this object, and the other is the connection manager. Such an object should be created only once by each peer during an instance of the ZooKeeper service.
        Parameters:
        self - QuorumPeer that created this object
        manager - Connection manager
    • Method Detail

      • getLogicalClock

        public long getLogicalClock()
        Returns the current value of the logical clock counter
      • start

        public void start()
        This method starts the sender and receiver threads.
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface Election
      • totalOrderPredicate

        protected boolean totalOrderPredicate​(long newId,
                                              long newZxid,
                                              long newEpoch,
                                              long curId,
                                              long curZxid,
                                              long curEpoch)
        Check if a pair (server id, zxid) succeeds our current vote.
      • getVoteTracker

        protected SyncedLearnerTracker getVoteTracker​(Map<Long,​Vote> votes,
                                                      Vote vote)
        Given a set of votes, return the SyncedLearnerTracker which is used to determines if have sufficient to declare the end of the election round.
        Parameters:
        votes - Set of votes
        vote - Identifier of the vote received last
        Returns:
        the SyncedLearnerTracker with vote details
      • checkLeader

        protected boolean checkLeader​(Map<Long,​Vote> votes,
                                      long leader,
                                      long electionEpoch)
        In the case there is a leader elected, and a quorum supporting this leader, we have to check if the leader has voted and acked that it is leading. We need this check to avoid that peers keep electing over and over a peer that has crashed and it is no longer leading.
        Parameters:
        votes - set of votes
        leader - leader id
        electionEpoch - epoch id
      • getVote

        public Vote getVote()