Class Leader
java.lang.Object
org.apache.zookeeper.server.quorum.LearnerMaster
org.apache.zookeeper.server.quorum.Leader
This class has the control logic for the Leader.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThis message is used by the follow to ack a proposed epoch.protected booleanstatic final intThis message is the first that a follower receives from the leader.static final Stringprotected final Leader.Proposalstatic final intThis message type is sent by a leader to propose a mutation.protected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLearnerHandler(LearnerHandler learner) Adds peer to the leader.static QuorumPacketbuildInformAndActivePacket(long zxid, long designatedLeader, byte[] proposalData) voidcommit(long zxid) Create a commit packet and send it to all the members of the quorumvoidcommitAndActivate(long zxid, long designatedLeader) static intlongintlonggetEpoch()Returns the current epoch of the leader.longgetEpochToPropose(long sid, long lastAcceptedEpoch) Returns a copy of the current forwarding follower snapshotlongReturns a copy of the current learner snapshotintReturns a copy of the current observer snapshotstatic StringgetPacketType(int packetType) Get string representation of a given packet typegetPeerInfo(long sid) byte[]longintintlongvoidinform(Leader.Proposal proposal) Create an inform packet and send it to all observers.voidinformAndActivate(Leader.Proposal proposal, long designatedLeader) Create an inform and activate packet and send it to all observers.booleanReturns true if a quorum in qv is connected and synced with the leader and false otherwisevoidprocessAck(long sid, long zxid, SocketAddress followerAddr) Keep a count of acks that are received by the leader for a particular proposalvoidProcess sync requestscreate a proposal and send it out to all the membersvoidregisterLearnerHandlerBean(LearnerHandler learnerHandler, Socket socket) voidRemove the learner from the learner listvoidreportLookingSid(long sid) voidvoidrevalidateSession(QuorumPacket qp, LearnerHandler learnerHandler) voidSends a sync message to the appropriate serverstatic voidsetAckLoggingFrequency(int frequency) voidsetLeadingVoteSet(SyncedLearnerTracker voteSet) static voidsetMaxTimeToWaitForEpoch(int maxTimeToWaitForEpoch) longstartForwarding(LearnerHandler handler, long lastSeenZxid) lets the leader know that a follower is capable of following and is done syncingvoidintvoidtouch(long sess, int to) booleantryToCommit(Leader.Proposal p, long zxid, SocketAddress followerAddr) voidunregisterLearnerHandlerBean(LearnerHandler learnerHandler) voidwaitForEpochAck(long id, StateSummary ss) voidwaitForNewLeaderAck(long sid, long zxid) Process NEWLEADER ack of a given sid and wait until the leader receives sufficient acks.voidMethods inherited from class org.apache.zookeeper.server.quorum.LearnerMaster
getLearnerDiffSyncThrottler, getLearnerSnapSyncThrottler, getMaxConcurrentDiffSyncs, getMaxConcurrentSnapSyncs, setMaxConcurrentDiffSyncs, setMaxConcurrentSnapSyncs
-
Field Details
-
quorumFormed
protected boolean quorumFormed -
LEADERINFO
public static final int LEADERINFOThis message is the first that a follower receives from the leader. It has the protocol version and the epoch of the leader.- See Also:
-
ACKEPOCH
public static final int ACKEPOCHThis message is used by the follow to ack a proposed epoch.- See Also:
-
PROPOSAL
public static final int PROPOSALThis message type is sent by a leader to propose a mutation.- See Also:
-
newLeaderProposal
-
connectingFollowers
-
MAX_TIME_TO_WAIT_FOR_EPOCH
- See Also:
-
electingFollowers
-
electionFinished
protected boolean electionFinished
-
-
Constructor Details
-
Leader
- Throws:
IOException
-
-
Method Details
-
setAckLoggingFrequency
public static void setAckLoggingFrequency(int frequency) -
getAckLoggingFrequency
public static int getAckLoggingFrequency() -
getProposalStats
-
getLearners
Returns a copy of the current learner snapshot -
getForwardingFollowers
Returns a copy of the current forwarding follower snapshot -
getNonVotingFollowers
-
getObservingLearners
Returns a copy of the current observer snapshot -
getObservingLearnersInfo
-
resetObserverConnectionStats
public void resetObserverConnectionStats() -
getNumPendingSyncs
public int getNumPendingSyncs() -
addLearnerHandler
Adds peer to the leader.- Parameters:
learner- instance of learner handle
-
removeLearnerHandler
Remove the learner from the learner list- Parameters:
peer-
-
isQuorumSynced
Returns true if a quorum in qv is connected and synced with the leader and false otherwise- Parameters:
qv- is a QuorumVerifier
-
getUptime
public long getUptime() -
tryToCommit
- Returns:
- True if committed, otherwise false.
-
processAck
Keep a count of acks that are received by the leader for a particular proposal- Parameters:
sid- is the id of the server that sent the ackzxid- is the zxid of the proposal sent outfollowerAddr-
-
commit
public void commit(long zxid) Create a commit packet and send it to all the members of the quorum- Parameters:
zxid-
-
commitAndActivate
public void commitAndActivate(long zxid, long designatedLeader) -
inform
Create an inform packet and send it to all observers. -
buildInformAndActivePacket
public static QuorumPacket buildInformAndActivePacket(long zxid, long designatedLeader, byte[] proposalData) -
informAndActivate
Create an inform and activate packet and send it to all observers. -
getLastProposed
public long getLastProposed() -
getEpoch
public long getEpoch()Returns the current epoch of the leader. -
propose
create a proposal and send it out to all the members- Parameters:
request-- Returns:
- the proposal that is queued to send to all the members
- Throws:
Leader.XidRolloverException
-
processSync
Process sync requests- Parameters:
r- the request
-
sendSync
Sends a sync message to the appropriate server -
startForwarding
lets the leader know that a follower is capable of following and is done syncing- Parameters:
handler- handler of the follower- Returns:
- last proposed zxid
-
waitForStartup
- Throws:
InterruptedException
-
setMaxTimeToWaitForEpoch
public static void setMaxTimeToWaitForEpoch(int maxTimeToWaitForEpoch) -
setLeadingVoteSet
-
reportLookingSid
public void reportLookingSid(long sid) -
getEpochToPropose
public long getEpochToPropose(long sid, long lastAcceptedEpoch) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
getZKDatabase
-
waitForEpochAck
- Throws:
IOExceptionInterruptedException
-
waitForNewLeaderAck
Process NEWLEADER ack of a given sid and wait until the leader receives sufficient acks.- Parameters:
sid-- Throws:
InterruptedException
-
getPacketType
Get string representation of a given packet type- Parameters:
packetType-- Returns:
- string representing the packet type
-
getCurrentTick
public int getCurrentTick() -
syncTimeout
public int syncTimeout() -
getTickOfNextAckDeadline
public int getTickOfNextAckDeadline() -
getTickOfInitialAckDeadline
public int getTickOfInitialAckDeadline() -
getAndDecrementFollowerCounter
public long getAndDecrementFollowerCounter() -
touch
public void touch(long sess, int to) -
submitLearnerRequest
-
getQuorumVerifierVersion
public long getQuorumVerifierVersion() -
getPeerInfo
-
getQuorumVerifierBytes
public byte[] getQuorumVerifierBytes() -
getQuorumAuthServer
-
revalidateSession
- Throws:
IOException
-
registerLearnerHandlerBean
-
unregisterLearnerHandlerBean
-