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 class
static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
This message is used by the follow to ack a proposed epoch.protected boolean
static final int
This message is the first that a follower receives from the leader.static final String
protected final Leader.Proposal
static final int
This message type is sent by a leader to propose a mutation.protected boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLearnerHandler
(LearnerHandler learner) Adds peer to the leader.static QuorumPacket
buildInformAndActivePacket
(long zxid, long designatedLeader, byte[] proposalData) void
commit
(long zxid) Create a commit packet and send it to all the members of the quorumvoid
commitAndActivate
(long zxid, long designatedLeader) static int
long
int
long
getEpoch()
Returns the current epoch of the leader.long
getEpochToPropose
(long sid, long lastAcceptedEpoch) Returns a copy of the current forwarding follower snapshotlong
Returns a copy of the current learner snapshotint
Returns a copy of the current observer snapshotstatic String
getPacketType
(int packetType) Get string representation of a given packet typegetPeerInfo
(long sid) byte[]
long
int
int
long
void
inform
(Leader.Proposal proposal) Create an inform packet and send it to all observers.void
informAndActivate
(Leader.Proposal proposal, long designatedLeader) Create an inform and activate packet and send it to all observers.boolean
Returns true if a quorum in qv is connected and synced with the leader and false otherwisevoid
processAck
(long sid, long zxid, SocketAddress followerAddr) Keep a count of acks that are received by the leader for a particular proposalvoid
Process sync requestscreate a proposal and send it out to all the membersvoid
registerLearnerHandlerBean
(LearnerHandler learnerHandler, Socket socket) void
Remove the learner from the learner listvoid
reportLookingSid
(long sid) void
void
revalidateSession
(QuorumPacket qp, LearnerHandler learnerHandler) void
Sends a sync message to the appropriate serverstatic void
setAckLoggingFrequency
(int frequency) void
setLeadingVoteSet
(SyncedLearnerTracker voteSet) static void
setMaxTimeToWaitForEpoch
(int maxTimeToWaitForEpoch) long
startForwarding
(LearnerHandler handler, long lastSeenZxid) lets the leader know that a follower is capable of following and is done syncingvoid
int
void
touch
(long sess, int to) boolean
tryToCommit
(Leader.Proposal p, long zxid, SocketAddress followerAddr) void
unregisterLearnerHandlerBean
(LearnerHandler learnerHandler) void
waitForEpochAck
(long id, StateSummary ss) void
waitForNewLeaderAck
(long sid, long zxid) Process NEWLEADER ack of a given sid and wait until the leader receives sufficient acks.void
Methods 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:
InterruptedException
IOException
-
getZKDatabase
-
waitForEpochAck
- Throws:
IOException
InterruptedException
-
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
-