LearnerHandler (Apache ZooKeeper - Server 3.7.0 API)
Date: 2021-03-17

org.apache.zookeeper.server.quorum

## Class LearnerHandler

- java.lang.Object
- - java.lang.Thread
  - - org.apache.zookeeper.server.ZooKeeperThread
    - - org.apache.zookeeper.server.quorum.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.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `Thread.State, Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `closeSocketAsync`
    `protected Date` | `established`
    `static String` | `FORCE_SNAP_SYNC` For testing purpose, force learnerMaster to use snapshot to sync with followers
    `protected long` | `lastZxid`
    `static String` | `LEADER_CLOSE_SOCKET_ASYNC`
    `protected MessageTracker` | `messageTracker`
    `protected AtomicLong` | `packetsReceived`
    `protected AtomicLong` | `packetsSent`
    `protected AtomicLong` | `requestsReceived`
    `protected long` | `sid` ZooKeeper server identifier of this learner
    `protected 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 and Description
    --- | ---
    `Date` | `getEstablished()`
    `long` | `getLastZxid()`
    `Map<String,Object>` | `getLearnerHandlerInfo()`
    `QuorumPeer.LearnerType` | `getLearnerType()`
    `Queue<QuorumPacket>` | `getQueuedPackets()` For testing, return packet queue
    `Socket` | `getSocket()`
    `static String` | `packetToString(QuorumPacket p)`
    `void` | `ping()` ping calls from the learnerMaster to the peers
    `protected long` | `queueCommittedProposals(Iterator<Leader.Proposal> itr, long peerLastZxid, Long maxZxid, Long lastCommittedZxid)` Queue committed proposals into packet queue.
    `void` | `resetObserverConnectionStats()`
    `void` | `run()` This thread will receive packets from the peer and process them and also listen to new connections from new peers.
    `protected void` | `setBufferedOutput(BufferedOutputStream bufferedOutput)`
    `void` | `setFirstPacket(boolean value)` For testing, we need to reset this value
    `protected void` | `setOutputArchive(BinaryOutputArchive oa)`
    `protected boolean` | `shouldSendMarkerPacketForLogging()` Tests need not send marker packets as they are only needed to log quorum packet delays
    `void` | `shutdown()`
    `protected void` | `startSendingPackets()` Start thread that will forward any packet in the queue to the follower
    `boolean` | `synced()`
    `long` | `tickOfNextAckDeadline()`
    `String` | `toString()`

    - ### Methods inherited from class org.apache.zookeeper.server.ZooKeeperThread

      `handleException`

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### LEADER_CLOSE_SOCKET_ASYNC

          public static final String LEADER_CLOSE_SOCKET_ASYNC

      See Also:
        Constant Field Values

    - #### 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

    - #### messageTracker

          protected final MessageTracker messageTracker

    - #### 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()

    - #### setOutputArchive

          protected void setOutputArchive(BinaryOutputArchive oa)

    - #### setBufferedOutput

          protected void setBufferedOutput(BufferedOutputStream bufferedOutput)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Thread`

    - #### getLearnerType

          public QuorumPeer.LearnerType getLearnerType()

    - #### packetToString

          public static 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:
        `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

Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.