Class ZooKeeperServer

    • Field Detail

      • LOG

        protected static final org.slf4j.Logger LOG
      • enforceQuota

        public static final boolean enforceQuota
      • ZOOKEEPER_SERIALIZE_LAST_PROCESSED_ZXID_ENABLED

        public static final String ZOOKEEPER_SERIALIZE_LAST_PROCESSED_ZXID_ENABLED
        See Also:
        Constant Field Values
      • tickTime

        protected int tickTime
      • DEFAULT_THROTTLED_OP_WAIT_TIME

        public static final int DEFAULT_THROTTLED_OP_WAIT_TIME
        See Also:
        Constant Field Values
      • 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
      • initialConfig

        protected String initialConfig
      • reconfigEnabled

        protected boolean reconfigEnabled
      • INT_BUFFER_STARTING_SIZE_BYTES

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

        public static final int DEFAULT_STARTING_BUFFER_SIZE
        See Also:
        Constant Field Values
      • intBufferStartingSizeBytes

        public static final int intBufferStartingSizeBytes
    • Constructor Detail

      • 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​(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 Detail

      • 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()
      • dumpConf

        public void dumpConf​(PrintWriter pwriter)
      • 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 -
      • 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()
      • getZxid

        public long getZxid()
      • setZxid

        public void setZxid​(long zxid)
      • closeSession

        public void closeSession​(long sessionId)
      • killSession

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

        public void expire​(long sessionId)
      • registerJMX

        protected void registerJMX()
      • startup

        public void startup()
      • startupWithoutServing

        public void startupWithoutServing()
      • startServing

        public void startServing()
      • startJvmPauseMonitor

        protected void startJvmPauseMonitor()
      • startRequestThrottler

        protected void startRequestThrottler()
      • setupRequestProcessors

        protected void setupRequestProcessors()
      • 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
Parameters:
state - new server state.