Class LearnerHandler
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.zookeeper.server.ZooKeeperThread
-
- org.apache.zookeeper.server.quorum.LearnerHandler
-
- All Implemented Interfaces:
java.lang.Runnable
public class LearnerHandler extends ZooKeeperThread
There will be an instance of this class created by the Leader for each learner. All communication with a learner is handled by this class.
-
-
Field Summary
Fields Modifier and Type Field Description static booleancloseSocketAsyncprotected java.util.Dateestablishedstatic java.lang.StringFORCE_SNAP_SYNCFor testing purpose, force learnerMaster to use snapshot to sync with followersprotected longlastZxidstatic java.lang.StringLEADER_CLOSE_SOCKET_ASYNCprotected MessageTrackermessageTrackerprotected java.util.concurrent.atomic.AtomicLongpacketsReceivedprotected java.util.concurrent.atomic.AtomicLongpacketsSentprotected java.util.concurrent.atomic.AtomicLongrequestsReceivedprotected longsidZooKeeper server identifier of this learnerprotected java.net.Socketsockprotected intversion
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.DategetEstablished()longgetLastZxid()java.util.Map<java.lang.String,java.lang.Object>getLearnerHandlerInfo()QuorumPeer.LearnerTypegetLearnerType()java.util.Queue<QuorumPacket>getQueuedPackets()For testing, return packet queuejava.net.SocketgetSocket()static java.lang.StringpacketToString(QuorumPacket p)voidping()ping calls from the learnerMaster to the peersprotected longqueueCommittedProposals(java.util.Iterator<Leader.Proposal> itr, long peerLastZxid, java.lang.Long maxZxid, java.lang.Long lastCommittedZxid)Queue committed proposals into packet queue.voidresetObserverConnectionStats()voidrun()This thread will receive packets from the peer and process them and also listen to new connections from new peers.protected voidsetBufferedOutput(java.io.BufferedOutputStream bufferedOutput)voidsetFirstPacket(boolean value)For testing, we need to reset this valueprotected voidsetOutputArchive(BinaryOutputArchive oa)protected booleanshouldSendMarkerPacketForLogging()Tests need not send marker packets as they are only needed to log quorum packet delaysvoidshutdown()protected voidstartSendingPackets()Start thread that will forward any packet in the queue to the followerbooleansynced()longtickOfNextAckDeadline()java.lang.StringtoString()-
Methods inherited from class org.apache.zookeeper.server.ZooKeeperThread
handleException
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
-
-
-
-
Field Detail
-
LEADER_CLOSE_SOCKET_ASYNC
public static final java.lang.String LEADER_CLOSE_SOCKET_ASYNC
- See Also:
- Constant Field Values
-
closeSocketAsync
public static final boolean closeSocketAsync
-
sock
protected final java.net.Socket sock
-
sid
protected long sid
ZooKeeper server identifier of this learner
-
version
protected int version
-
packetsReceived
protected final java.util.concurrent.atomic.AtomicLong packetsReceived
-
packetsSent
protected final java.util.concurrent.atomic.AtomicLong packetsSent
-
requestsReceived
protected final java.util.concurrent.atomic.AtomicLong requestsReceived
-
lastZxid
protected volatile long lastZxid
-
established
protected final java.util.Date established
-
messageTracker
protected final MessageTracker messageTracker
-
FORCE_SNAP_SYNC
public static final java.lang.String FORCE_SNAP_SYNC
For testing purpose, force learnerMaster to use snapshot to sync with followers- See Also:
- Constant Field Values
-
-
Method Detail
-
getSocket
public java.net.Socket getSocket()
-
getLastZxid
public long getLastZxid()
-
getEstablished
public java.util.Date getEstablished()
-
setOutputArchive
protected void setOutputArchive(BinaryOutputArchive oa)
-
setBufferedOutput
protected void setBufferedOutput(java.io.BufferedOutputStream bufferedOutput)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Thread
-
getLearnerType
public QuorumPeer.LearnerType getLearnerType()
-
packetToString
public static java.lang.String packetToString(QuorumPacket p)
-
run
public void run()
This thread will receive packets from the peer and process them and also listen to new connections from new peers.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
startSendingPackets
protected void startSendingPackets()
Start thread that will forward any packet in the queue to the follower
-
shouldSendMarkerPacketForLogging
protected boolean shouldSendMarkerPacketForLogging()
Tests need not send marker packets as they are only needed to log quorum packet delays
-
queueCommittedProposals
protected long queueCommittedProposals(java.util.Iterator<Leader.Proposal> itr, long peerLastZxid, java.lang.Long maxZxid, java.lang.Long lastCommittedZxid)
Queue committed proposals into packet queue. The range of packets which is going to be queued are (peerLaxtZxid, maxZxid]- Parameters:
itr- iterator point to the proposalspeerLastZxid- last zxid seen by the followermaxZxid- max zxid of the proposal to queue, null if no limitlastCommittedZxid- when sending diff, we need to send lastCommittedZxid on the leader to follow Zab 1.0 protocol.- Returns:
- last zxid of the queued proposal
-
shutdown
public void shutdown()
-
tickOfNextAckDeadline
public long tickOfNextAckDeadline()
-
ping
public void ping()
ping calls from the learnerMaster to the peers
-
synced
public boolean synced()
-
getLearnerHandlerInfo
public java.util.Map<java.lang.String,java.lang.Object> getLearnerHandlerInfo()
-
resetObserverConnectionStats
public void resetObserverConnectionStats()
-
getQueuedPackets
public java.util.Queue<QuorumPacket> getQueuedPackets()
For testing, return packet queue
-
setFirstPacket
public void setFirstPacket(boolean value)
For testing, we need to reset this value
-
-