Class LearnerHandler

  • All Implemented Interfaces:
    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 Detail

      • closeSocketAsync

        public static final boolean closeSocketAsync
      • sock

        protected final Socket sock
      • sid

        protected long sid
        ZooKeeper server identifier of this learner
      • version

        protected int version
      • packetsReceived

        protected final AtomicLong packetsReceived
      • packetsSent

        protected final AtomicLong packetsSent
      • requestsReceived

        protected final AtomicLong requestsReceived
      • lastZxid

        protected volatile long lastZxid
      • established

        protected final Date established
      • FORCE_SNAP_SYNC

        public static final 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 Socket getSocket()
      • getLastZxid

        public long getLastZxid()
      • getEstablished

        public Date getEstablished()
      • 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:
        run in interface Runnable
        Overrides:
        run in class 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​(Iterator<Leader.Proposal> itr,
                                               long peerLastZxid,
                                               Long maxZxid,
                                               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 proposals
        peerLastZxid - last zxid seen by the follower
        maxZxid - max zxid of the proposal to queue, null if no limit
        lastCommittedZxid - 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 Map<String,​Object> getLearnerHandlerInfo()
      • resetObserverConnectionStats

        public void resetObserverConnectionStats()
      • getQueuedPackets

        public Queue<QuorumPacket> getQueuedPackets()
        For testing, return packet queue
      • setFirstPacket

        public void setFirstPacket​(boolean value)
        For testing, we need to reset this value