Class 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.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FORCE_SNAP_SYNC
      For testing purpose, force leader to use snapshot to sync with followers
      protected long sid
      ZooKeeper server identifier of this learner
      protected java.net.Socket sock  
      protected int version  
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      QuorumPeer.LearnerType getLearnerType()  
      java.util.Queue<org.apache.zookeeper.server.quorum.QuorumPacket> getQueuedPackets()
      For testing, return packet queue
      java.net.Socket getSocket()  
      static java.lang.String packetToString​(org.apache.zookeeper.server.quorum.QuorumPacket p)  
      void ping()
      ping calls from the leader to the peers
      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.
      void run()
      This thread will receive packets from the peer and process them and also listen to new connections from new peers.
      void setFirstPacket​(boolean value)
      For testing, we need to reset this value
      void shutdown()  
      protected void startSendingPackets()
      Start thread that will forward any packet in the queue to the follower
      boolean synced()  
      boolean syncFollower​(long peerLastZxid, ZKDatabase db, Leader leader)
      Determine if we need to sync with follower using DIFF/TRUNC/SNAP and setup follower to receive packets from commit processor
      long tickOfNextAckDeadline()  
      java.lang.String toString()  
      • 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
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sock

        protected final java.net.Socket sock
      • sid

        protected long sid
        ZooKeeper server identifier of this learner
      • version

        protected int version
      • FORCE_SNAP_SYNC

        public static final java.lang.String FORCE_SNAP_SYNC
        For testing purpose, force leader to use snapshot to sync with followers
        See Also:
        Constant Field Values
    • Method Detail

      • getSocket

        public java.net.Socket getSocket()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Thread
      • packetToString

        public static java.lang.String packetToString​(org.apache.zookeeper.server.quorum.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:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • startSendingPackets

        protected void startSendingPackets()
        Start thread that will forward any packet in the queue to the follower
      • syncFollower

        public boolean syncFollower​(long peerLastZxid,
                                    ZKDatabase db,
                                    Leader leader)
        Determine if we need to sync with follower using DIFF/TRUNC/SNAP and setup follower to receive packets from commit processor
        Parameters:
        peerLastZxid -
        db -
        leader -
        Returns:
        true if snapshot transfer is needed.
      • 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 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 leader to the peers
      • synced

        public boolean synced()
      • getQueuedPackets

        public java.util.Queue<org.apache.zookeeper.server.quorum.QuorumPacket> getQueuedPackets()
        For testing, return packet queue
        Returns:
      • setFirstPacket

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