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

org.apache.zookeeper.server.quorum

## Class LearnerSessionTracker

- java.lang.Object
- - org.apache.zookeeper.server.quorum.UpgradeableSessionTracker
  - - org.apache.zookeeper.server.quorum.LearnerSessionTracker

- All Implemented Interfaces:
    SessionTracker

      public class LearnerSessionTracker
      extends UpgradeableSessionTracker

  The learner session tracker is used by learners (followers and observers) to track zookeeper sessions which may or may not be echoed to the leader. When a new session is created it is saved locally in a wrapped LocalSessionTracker. It can subsequently be upgraded to a global session as required. If an upgrade is requested the session is removed from local collections while keeping the same session ID. It is up to the caller to queue a session creation request for the leader. A secondary function of the learner session tracker is to remember sessions which have been touched in this service. This information is passed along to the leader with a ping.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.zookeeper.server.SessionTracker

      `SessionTracker.Session, SessionTracker.SessionExpirer`

  - ### Field Summary

    - ### Fields inherited from class org.apache.zookeeper.server.quorum.UpgradeableSessionTracker

      `localSessionsEnabled, localSessionTracker`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LearnerSessionTracker(SessionTracker.SessionExpirer expirer, ConcurrentMap<Long,Integer> sessionsWithTimeouts, int tickTime, long id, boolean localSessionsEnabled, ZooKeeperServerListener listener)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkSession(long sessionId, Object owner)` Checks whether the SessionTracker is aware of this session, the session is still active, and the owner matches.
    `boolean` | `commitSession(long sessionId, int sessionTimeout)` Synchronized on this to avoid race condition of adding a local session after committed global session, which may cause the same session being tracked on this server and leader.
    `long` | `createSession(int sessionTimeout)`
    `void` | `dumpSessions(PrintWriter pwriter)` Text dump of session information, suitable for debugging.
    `Map<Long,Set<Long>>` | `getSessionExpiryMap()` Returns a mapping of time to session IDs that expire at that time.
    `boolean` | `isGlobalSession(long sessionId)`
    `void` | `removeSession(long sessionId)`
    `void` | `setOwner(long sessionId, Object owner)`
    `void` | `setSessionClosing(long sessionId)` Mark that the session is in the process of closing.
    `void` | `shutdown()`
    `Map<Long,Integer>` | `snapshot()`
    `void` | `start()`
    `boolean` | `touchSession(long sessionId, int sessionTimeout)`
    `boolean` | `trackSession(long sessionId, int sessionTimeout)` Track the session expire, not add to ZkDb.

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

      `checkGlobalSession, createLocalSessionTracker, finishedUpgrading, getLocalSessionCount, isLocalSession, isLocalSessionsEnabled, isTrackingSession, isUpgradingSession, removeLocalSession, upgradeSession`

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

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

- - ### Constructor Detail

    - #### LearnerSessionTracker

          public LearnerSessionTracker(SessionTracker.SessionExpirer expirer,
                                       ConcurrentMap<Long,Integer> sessionsWithTimeouts,
                                       int tickTime,
                                       long id,
                                       boolean localSessionsEnabled,
                                       ZooKeeperServerListener listener)

  - ### Method Detail

    - #### removeSession

          public void removeSession(long sessionId)

    - #### start

          public void start()

      Overrides:
        `start` in class `UpgradeableSessionTracker`

    - #### shutdown

          public void shutdown()

    - #### isGlobalSession

          public boolean isGlobalSession(long sessionId)

      Specified by:
        `isGlobalSession` in class `UpgradeableSessionTracker`

    - #### trackSession

          public boolean trackSession(long sessionId,
                                      int sessionTimeout)

      Description copied from interface: `SessionTracker`
      Track the session expire, not add to ZkDb.
      Parameters:
        `sessionId` - sessionId
        `sessionTimeout` - sessionTimeout
      Returns:
        whether the session was newly tracked (if false, already tracked)

    - #### commitSession

          public boolean commitSession(long sessionId,
                                       int sessionTimeout)

      Synchronized on this to avoid race condition of adding a local session after committed global session, which may cause the same session being tracked on this server and leader.
      Parameters:
        `sessionId` - sessionId
        `sessionTimeout` - sessionTimeout
      Returns:
        whether the session was newly added (if false, already existed)

    - #### touchSession

          public boolean touchSession(long sessionId,
                                      int sessionTimeout)

      Returns:
        false if session is no longer active

    - #### snapshot

          public Map<Long,Integer> snapshot()

    - #### createSession

          public long createSession(int sessionTimeout)

    - #### checkSession

          public void checkSession(long sessionId,
                                   Object owner)
                            throws KeeperException.SessionExpiredException,
                                   KeeperException.SessionMovedException

      Description copied from interface: `SessionTracker`
      Checks whether the SessionTracker is aware of this session, the session is still active, and the owner matches. If the owner wasn't previously set, this sets the owner of the session. UnknownSessionException should never been thrown to the client. It is only used internally to deal with possible local session from other machine
      Throws:
        `KeeperException.SessionExpiredException`
        `KeeperException.SessionMovedException`

    - #### setOwner

          public void setOwner(long sessionId,
                               Object owner)
                        throws KeeperException.SessionExpiredException

      Throws:
        `KeeperException.SessionExpiredException`

    - #### dumpSessions

          public void dumpSessions(PrintWriter pwriter)

      Description copied from interface: `SessionTracker`
      Text dump of session information, suitable for debugging.
      Parameters:
        `pwriter` - the output writer

    - #### setSessionClosing

          public void setSessionClosing(long sessionId)

      Description copied from interface: `SessionTracker`
      Mark that the session is in the process of closing.

    - #### getSessionExpiryMap

          public Map<Long,Set<Long>> getSessionExpiryMap()

      Description copied from interface: `SessionTracker`
      Returns a mapping of time to session IDs that expire at that time.

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