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

org.apache.zookeeper.server.quorum

## Class ObserverMaster

- java.lang.Object
- - org.apache.zookeeper.server.quorum.LearnerMaster
  - - org.apache.zookeeper.server.quorum.ObserverMaster

- All Implemented Interfaces:
    Runnable

      public class ObserverMaster
      extends LearnerMaster
      implements Runnable

  Used by Followers to host Observers. This reduces the network load on the Leader process by pushing the responsibility for keeping Observers in sync off the leading peer. It is expected that Observers will continue to perform the initial vetting of clients and requests. Observers send the request to the follower where it is received by an ObserverMaster. The ObserverMaster forwards a copy of the request to the ensemble Leader and inserts it into its own request processor pipeline where it can be matched with the response comes back. All commits received from the Leader will be forwarded along to every Learner connected to the ObserverMaster. New Learners connecting to a Follower will receive a LearnerHandler object and be party to its syncing logic to be brought up to date. The logic is quite a bit simpler than the corresponding logic in Leader because it only hosts observers.

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addLearnerHandler(LearnerHandler learnerHandler)` start tracking a learner handler
    `Iterable<Map<String,Object>>` | `getActiveObservers()`
    `long` | `getAndDecrementFollowerCounter()` decrement follower count
    `int` | `getCurrentTick()` the current tick
    `long` | `getEpochToPropose(long sid, long lastAcceptedEpoch)` get the first zxid of the next epoch
    `long` | `getLastProposed()` last proposed zxid
    `String` | `getPeerInfo(long sid)`
    `QuorumAuthServer` | `getQuorumAuthServer()`
    `byte[]` | `getQuorumVerifierBytes()` identifier of current quorum verifier for new leader
    `long` | `getQuorumVerifierVersion()` version of current quorum verifier
    `int` | `getTickOfInitialAckDeadline()` next deadline tick marking observer sync (steady state)
    `int` | `getTickOfNextAckDeadline()` deadline tick marking observer sync (initial)
    `ZKDatabase` | `getZKDatabase()` ZKDatabase
    `void` | `processAck(long sid, long zxid, SocketAddress localSocketAddress)` handle ack packet
    `void` | `registerLearnerHandlerBean(LearnerHandler learnerHandler, Socket socket)` registers the handler's bean
    `void` | `removeLearnerHandler(LearnerHandler learnerHandler)` stop tracking a learner handler
    `void` | `resetObserverConnectionStats()`
    `void` | `revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler)` handle revalidate packet
    `void` | `run()`
    `void` | `start()`
    `long` | `startForwarding(LearnerHandler learnerHandler, long lastSeenZxid)` begin forwarding packets to learner handler
    `void` | `stop()`
    `void` | `submitLearnerRequest(Request si)` proxy request from learner to server
    `int` | `syncTimeout()` time allowed for sync response
    `void` | `touch(long sess, int to)` mark session as alive
    `void` | `unregisterLearnerHandlerBean(LearnerHandler learnerHandler)` unregisters the handler's bean
    `void` | `waitForEpochAck(long sid, StateSummary ss)` wait for the leader of the new epoch to be confirmed by followers
    `void` | `waitForNewLeaderAck(long sid, long zxid)` wait for new leader to settle
    `void` | `waitForStartup()` wait for server to start

    - ### Methods inherited from class org.apache.zookeeper.server.quorum.LearnerMaster

      `getLearnerDiffSyncThrottler, getLearnerSnapSyncThrottler, getMaxConcurrentDiffSyncs, getMaxConcurrentSnapSyncs, setMaxConcurrentDiffSyncs, setMaxConcurrentSnapSyncs`

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

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

- - ### Method Detail

    - #### addLearnerHandler

          public void addLearnerHandler(LearnerHandler learnerHandler)

      Description copied from class: `LearnerMaster`
      start tracking a learner handler
      Parameters:
        `learnerHandler` - to track

    - #### removeLearnerHandler

          public void removeLearnerHandler(LearnerHandler learnerHandler)

      Description copied from class: `LearnerMaster`
      stop tracking a learner handler
      Parameters:
        `learnerHandler` - to drop

    - #### syncTimeout

          public int syncTimeout()

      Description copied from class: `LearnerMaster`
      time allowed for sync response
      Returns:
        time allowed for sync response

    - #### getTickOfNextAckDeadline

          public int getTickOfNextAckDeadline()

      Description copied from class: `LearnerMaster`
      deadline tick marking observer sync (initial)
      Returns:
        deadline tick marking observer sync (initial)

    - #### getTickOfInitialAckDeadline

          public int getTickOfInitialAckDeadline()

      Description copied from class: `LearnerMaster`
      next deadline tick marking observer sync (steady state)
      Returns:
        next deadline tick marking observer sync (steady state)

    - #### getAndDecrementFollowerCounter

          public long getAndDecrementFollowerCounter()

      Description copied from class: `LearnerMaster`
      decrement follower count
      Returns:
        previous follower count

    - #### waitForEpochAck

          public void waitForEpochAck(long sid,
                                      StateSummary ss)
                               throws IOException,
                                      InterruptedException

      Description copied from class: `LearnerMaster`
      wait for the leader of the new epoch to be confirmed by followers
      Parameters:
        `sid` - learner id
      Throws:
        `IOException`
        `InterruptedException`

    - #### waitForStartup

          public void waitForStartup()
                              throws InterruptedException

      Description copied from class: `LearnerMaster`
      wait for server to start
      Throws:
        `InterruptedException`

    - #### getLastProposed

          public long getLastProposed()

      Description copied from class: `LearnerMaster`
      last proposed zxid
      Returns:
        last proposed zxid

    - #### getEpochToPropose

          public long getEpochToPropose(long sid,
                                        long lastAcceptedEpoch)
                                 throws InterruptedException,
                                        IOException

      Description copied from class: `LearnerMaster`
      get the first zxid of the next epoch
      Parameters:
        `sid` - learner id
      Returns:
        the first zxid of the next epoch
      Throws:
        `InterruptedException`
        `IOException`

    - #### getZKDatabase

          public ZKDatabase getZKDatabase()

      Description copied from class: `LearnerMaster`
      ZKDatabase
      Returns:
        ZKDatabase

    - #### waitForNewLeaderAck

          public void waitForNewLeaderAck(long sid,
                                          long zxid)
                                   throws InterruptedException

      Description copied from class: `LearnerMaster`
      wait for new leader to settle
      Parameters:
        `sid` - id of learner
        `zxid` - zxid at learner
      Throws:
        `InterruptedException`

    - #### getCurrentTick

          public int getCurrentTick()

      Description copied from class: `LearnerMaster`
      the current tick
      Returns:
        the current tick

    - #### processAck

          public void processAck(long sid,
                                 long zxid,
                                 SocketAddress localSocketAddress)

      Description copied from class: `LearnerMaster`
      handle ack packet
      Parameters:
        `sid` - leader id
        `zxid` - packet zxid
        `localSocketAddress` - forwarder's address

    - #### touch

          public void touch(long sess,
                            int to)

      Description copied from class: `LearnerMaster`
      mark session as alive
      Parameters:
        `sess` - session id
        `to` - timeout

    - #### revalidateSession

          public void revalidateSession(QuorumPacket qp,
                                        LearnerHandler learnerHandler)
                                 throws IOException

      Description copied from class: `LearnerMaster`
      handle revalidate packet
      Parameters:
        `qp` - session packet
        `learnerHandler` - learner
      Throws:
        `IOException`

    - #### submitLearnerRequest

          public void submitLearnerRequest(Request si)

      Description copied from class: `LearnerMaster`
      proxy request from learner to server
      Parameters:
        `si` - request

    - #### startForwarding

          public long startForwarding(LearnerHandler learnerHandler,
                                      long lastSeenZxid)

      Description copied from class: `LearnerMaster`
      begin forwarding packets to learner handler
      Parameters:
        `learnerHandler` - learner
        `lastSeenZxid` - zxid of learner
      Returns:
        last zxid forwarded

    - #### getQuorumVerifierVersion

          public long getQuorumVerifierVersion()

      Description copied from class: `LearnerMaster`
      version of current quorum verifier
      Returns:
        version of current quorum verifier

    - #### getPeerInfo

          public String getPeerInfo(long sid)

      Parameters:
        `sid` - server id
      Returns:
        server information in the view

    - #### getQuorumVerifierBytes

          public byte[] getQuorumVerifierBytes()

      Description copied from class: `LearnerMaster`
      identifier of current quorum verifier for new leader
      Returns:
        identifier of current quorum verifier for new leader

    - #### getQuorumAuthServer

          public QuorumAuthServer getQuorumAuthServer()

    - #### start

          public void start()
                     throws IOException

      Throws:
        `IOException`

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### stop

          public void stop()

    - #### getActiveObservers

          public Iterable<Map<String,Object>> getActiveObservers()

    - #### resetObserverConnectionStats

          public void resetObserverConnectionStats()

    - #### registerLearnerHandlerBean

          public void registerLearnerHandlerBean(LearnerHandler learnerHandler,
                                                 Socket socket)

      Description copied from class: `LearnerMaster`
      registers the handler's bean
      Parameters:
        `learnerHandler` - handler
        `socket` - connection to learner

    - #### unregisterLearnerHandlerBean

          public void unregisterLearnerHandlerBean(LearnerHandler learnerHandler)

      Description copied from class: `LearnerMaster`
      unregisters the handler's bean
      Parameters:
        `learnerHandler` - handler

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