Class FastLeaderElection
java.lang.Object
org.apache.zookeeper.server.quorum.FastLeaderElection
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
Multi-threaded implementation of message handler.static class
Notifications are messages that let other peers know that a given peer has changed its vote, either because it has joined leader election or because it learned of another peer with higher zxid or same zxid and higher server idstatic class
Messages that a peer wants to send to other peers. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFastLeaderElection
(QuorumPeer self, QuorumCnxManager manager) Constructor of FastLeaderElection. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.long
Returns the current value of the logical clock countergetVote()
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.Starts a new round of leader election.void
shutdown()
void
start()
This method starts the sender and receiver threads.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.
-
Field Details
-
MIN_NOTIFICATION_INTERVAL
Minimum notification interval, default is equal to finalizeWait- See Also:
-
MAX_NOTIFICATION_INTERVAL
Maximum notification interval, default is 60s- See Also:
-
-
Constructor Details
-
FastLeaderElection
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 objectmanager
- Connection manager
-
-
Method Details
-
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. -
getCnxManager
-
shutdown
public void shutdown() -
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
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 votesvote
- Identifier of the vote received last- Returns:
- the SyncedLearnerTracker with vote details
-
checkLeader
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 votesleader
- leader idelectionEpoch
- epoch id
-
getVote
-
lookForLeader
Starts a new round of leader election. Whenever our QuorumPeer changes its state to LOOKING, this method is invoked, and it sends notifications to all other peers.- Specified by:
lookForLeader
in interfaceElection
- Throws:
InterruptedException
-