Class ZooKeeperServer

java.lang.Object
org.apache.zookeeper.server.ZooKeeperServer
All Implemented Interfaces:
ServerStats.Provider, SessionTracker.SessionExpirer
Direct Known Subclasses:
QuorumZooKeeperServer, ReadOnlyZooKeeperServer

public class ZooKeeperServer extends Object implements SessionTracker.SessionExpirer, ServerStats.Provider
This class implements a simple standalone ZooKeeperServer. It sets up the following chain of RequestProcessors to process requests: PrepRequestProcessor -> SyncRequestProcessor -> FinalRequestProcessor
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • GLOBAL_OUTSTANDING_LIMIT

      public static final String GLOBAL_OUTSTANDING_LIMIT
      See Also:
    • ENABLE_EAGER_ACL_CHECK

      public static final String ENABLE_EAGER_ACL_CHECK
      See Also:
    • SKIP_ACL

      public static final String SKIP_ACL
      See Also:
    • ENFORCE_QUOTA

      public static final String ENFORCE_QUOTA
      See Also:
    • enforceQuota

      public static final boolean enforceQuota
    • SASL_SUPER_USER

      public static final String SASL_SUPER_USER
      See Also:
    • ALLOW_SASL_FAILED_CLIENTS

      public static final String ALLOW_SASL_FAILED_CLIENTS
      See Also:
    • ZOOKEEPER_DIGEST_ENABLED

      public static final String ZOOKEEPER_DIGEST_ENABLED
      See Also:
    • ZOOKEEPER_SERIALIZE_LAST_PROCESSED_ZXID_ENABLED

      public static final String ZOOKEEPER_SERIALIZE_LAST_PROCESSED_ZXID_ENABLED
      See Also:
    • CLOSE_SESSION_TXN_ENABLED

      public static final String CLOSE_SESSION_TXN_ENABLED
      See Also:
    • jmxServerBean

      protected ZooKeeperServerBean jmxServerBean
    • jmxDataTreeBean

      protected DataTreeBean jmxDataTreeBean
    • DEFAULT_TICK_TIME

      public static final int DEFAULT_TICK_TIME
      See Also:
    • tickTime

      protected int tickTime
    • DEFAULT_THROTTLED_OP_WAIT_TIME

      public static final int DEFAULT_THROTTLED_OP_WAIT_TIME
      See Also:
    • throttledOpWaitTime

      protected static volatile int throttledOpWaitTime
    • minSessionTimeout

      protected int minSessionTimeout
      value of -1 indicates unset, use default
    • maxSessionTimeout

      protected int maxSessionTimeout
      value of -1 indicates unset, use default
    • listenBacklog

      protected int listenBacklog
      Socket listen backlog. Value of -1 indicates unset
    • sessionTracker

      protected SessionTracker sessionTracker
    • ok

      public static final Exception ok
    • firstProcessor

      protected RequestProcessor firstProcessor
    • jvmPauseMonitor

      protected JvmPauseMonitor jvmPauseMonitor
    • state

      protected volatile ZooKeeperServer.State state
    • initialConfig

      protected String initialConfig
    • reconfigEnabled

      protected boolean reconfigEnabled
    • serverCnxnFactory

      protected ServerCnxnFactory serverCnxnFactory
    • secureServerCnxnFactory

      protected ServerCnxnFactory secureServerCnxnFactory
    • INT_BUFFER_STARTING_SIZE_BYTES

      public static final String INT_BUFFER_STARTING_SIZE_BYTES
      Starting size of read and write ByteArrayOutputBuffers. Default is 32 bytes. Flag not used for small transfers like connectResponses.
      See Also:
    • DEFAULT_STARTING_BUFFER_SIZE

      public static final int DEFAULT_STARTING_BUFFER_SIZE
      See Also:
    • intBufferStartingSizeBytes

      public static final int intBufferStartingSizeBytes
    • GET_DATA_RESPONSE_CACHE_SIZE

      public static final String GET_DATA_RESPONSE_CACHE_SIZE
      See Also:
    • GET_CHILDREN_RESPONSE_CACHE_SIZE

      public static final String GET_CHILDREN_RESPONSE_CACHE_SIZE
      See Also:
    • SNAP_COUNT

      public static final String SNAP_COUNT
      See Also:
  • Constructor Details

    • ZooKeeperServer

      public ZooKeeperServer()
      Creates a ZooKeeperServer instance. Nothing is setup, use the setX methods to prepare the instance (eg datadir, datalogdir, ticktime, builder, etc...)
    • ZooKeeperServer

      public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig)
      Keeping this constructor for backward compatibility
    • ZooKeeperServer

      public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig, boolean reconfigEnabled)
      * Creates a ZooKeeperServer instance. It sets everything up, but doesn't actually start listening for clients until run() is invoked.
    • ZooKeeperServer

      public ZooKeeperServer(JvmPauseMonitor jvmPauseMonitor, FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig)
    • ZooKeeperServer

      public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, String initialConfig)
      creates a zookeeperserver instance.
      Parameters:
      txnLogFactory - the file transaction snapshot logging class
      tickTime - the ticktime for the server
      Throws:
      IOException
    • ZooKeeperServer

      public ZooKeeperServer(File snapDir, File logDir, int tickTime) throws IOException
      This constructor is for backward compatibility with the existing unit test code. It defaults to FileLogProvider persistence provider.
      Throws:
      IOException
    • ZooKeeperServer

      public ZooKeeperServer(FileTxnSnapLog txnLogFactory) throws IOException
      Default constructor, relies on the config for its argument values
      Throws:
      IOException
  • Method Details

    • isEnableEagerACLCheck

      public static boolean isEnableEagerACLCheck()
    • setEnableEagerACLCheck

      public static void setEnableEagerACLCheck(boolean enabled)
    • isCloseSessionTxnEnabled

      public static boolean isCloseSessionTxnEnabled()
    • setCloseSessionTxnEnabled

      public static void setCloseSessionTxnEnabled(boolean enabled)
    • getInitialConfig

      public String getInitialConfig()
    • serverStats

      public ServerStats serverStats()
    • getRequestPathMetricsCollector

      public RequestPathMetricsCollector getRequestPathMetricsCollector()
    • connThrottle

      public BlueThrottle connThrottle()
    • dumpConf

      public void dumpConf(PrintWriter pwriter)
    • getConf

      public ZooKeeperServerConf getConf()
    • getZKDatabase

      public ZKDatabase getZKDatabase()
      get the zookeeper database for this server
      Returns:
      the zookeeper database for this server
    • setZKDatabase

      public void setZKDatabase(ZKDatabase zkDb)
      set the zkdatabase for this zookeeper server
      Parameters:
      zkDb -
    • loadData

      public void loadData() throws IOException, InterruptedException
      Restore sessions and data
      Throws:
      IOException
      InterruptedException
    • takeSnapshot

      public File takeSnapshot() throws IOException
      Throws:
      IOException
    • takeSnapshot

      public File takeSnapshot(boolean syncSnap) throws IOException
      Throws:
      IOException
    • takeSnapshot

      public File takeSnapshot(boolean syncSnap, boolean isSevere, boolean fastForwardFromEdits) throws IOException
      Takes a snapshot on the server.
      Parameters:
      syncSnap - syncSnap sync the snapshot immediately after write
      isSevere - if true system exist, otherwise throw IOException
      fastForwardFromEdits - whether fast forward database to the latest recorded transactions
      Returns:
      file snapshot file object
      Throws:
      IOException
    • restoreFromSnapshot

      public long restoreFromSnapshot(InputStream inputStream) throws IOException
      Restores database from a snapshot. It is used by the restore admin server command.
      Parameters:
      inputStream - input stream of snapshot
      Throws:
      IOException
    • shouldForceWriteInitialSnapshotAfterLeaderElection

      public boolean shouldForceWriteInitialSnapshotAfterLeaderElection()
    • getDataDirSize

      public long getDataDirSize()
      Specified by:
      getDataDirSize in interface ServerStats.Provider
    • getLogDirSize

      public long getLogDirSize()
      Specified by:
      getLogDirSize in interface ServerStats.Provider
    • getZxid

      public long getZxid()
    • getSessionTracker

      public SessionTracker getSessionTracker()
    • setZxid

      public void setZxid(long zxid)
    • closeSession

      public void closeSession(long sessionId)
    • killSession

      protected void killSession(long sessionId, long zxid)
    • expire

      public void expire(SessionTracker.Session session)
      Specified by:
      expire in interface SessionTracker.SessionExpirer
    • expire

      public void expire(long sessionId)
    • registerJMX

      protected void registerJMX()
    • startdata

      public void startdata() throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • startup

      public void startup()
    • startJvmPauseMonitor

      protected void startJvmPauseMonitor()
    • startRequestThrottler

      protected void startRequestThrottler()
    • createRequestThrottler

      protected RequestThrottler createRequestThrottler()
    • setupRequestProcessors

      protected void setupRequestProcessors()
    • getZooKeeperServerListener

      public ZooKeeperServerListener getZooKeeperServerListener()
    • setCreateSessionTrackerServerId

      public void setCreateSessionTrackerServerId(int newId)
      Change the server ID used by createSessionTracker(). Must be called prior to startup() being called
      Parameters:
      newId - ID to use
    • createSessionTracker

      protected void createSessionTracker()
    • startSessionTracker

      protected void startSessionTracker()
    • setState

      protected void setState(ZooKeeperServer.State state)
      Sets the state of ZooKeeper server. After changing the state, it notifies the server state change to a registered shutdown handler, if any.

      The following are the server state transitions:

      • During startup the server will be in the INITIAL state.
      • After successfully starting, the server sets the state to RUNNING.
      • The server transitions to the ERROR state if it hits an internal error. ZooKeeperServerListenerImpl notifies any critical resource error events, e.g., SyncRequestProcessor not being able to write a txn to disk.
      • During shutdown the server sets the state to SHUTDOWN, which corresponds to the server not running.
    • During maintenance (e.g. restore) the server sets the state to MAINTENANCE