public class ZooKeeperServer extends Object implements SessionTracker.SessionExpirer, ServerStats.Provider
Modifier and Type | Class and Description |
---|---|
static class |
ZooKeeperServer.MissingSessionException |
protected static class |
ZooKeeperServer.State |
Constructor and Description |
---|
ZooKeeperServer()
Creates a ZooKeeperServer instance.
|
ZooKeeperServer(File snapDir,
File logDir,
int tickTime)
This constructor is for backward compatibility with the existing unit
test code.
|
ZooKeeperServer(FileTxnSnapLog txnLogFactory)
Default constructor, relies on the config for its argument values
|
ZooKeeperServer(FileTxnSnapLog txnLogFactory,
int tickTime,
int minSessionTimeout,
int maxSessionTimeout,
int clientPortListenBacklog,
ZKDatabase zkDb,
String initialConfig)
Keeping this constructor for backward compatibility
|
ZooKeeperServer(FileTxnSnapLog txnLogFactory,
int tickTime,
int minSessionTimeout,
int maxSessionTimeout,
int clientPortListenBacklog,
ZKDatabase zkDb,
String initialConfig,
boolean reconfigEnabled)
* Creates a ZooKeeperServer instance.
|
ZooKeeperServer(FileTxnSnapLog txnLogFactory,
int tickTime,
String initialConfig)
creates a zookeeperserver instance.
|
ZooKeeperServer(JvmPauseMonitor jvmPauseMonitor,
FileTxnSnapLog txnLogFactory,
int tickTime,
int minSessionTimeout,
int maxSessionTimeout,
int clientPortListenBacklog,
ZKDatabase zkDb,
String initialConfig)
Adds JvmPauseMonitor and calls
ZooKeeperServer(FileTxnSnapLog, int, int, int, int, ZKDatabase, String) |
Modifier and Type | Method and Description |
---|---|
boolean |
authWriteRequest(Request request)
Check Write Requests for Potential Access Restrictions
Before a request is being proposed to the quorum, lets check it
against local ACLs.
|
protected boolean |
canShutdown()
This can be used while shutting down the server to see whether the server
is already shutdown or not.
|
void |
checkACL(ServerCnxn cnxn,
List<ACL> acl,
int perm,
List<Id> ids,
String path,
List<ACL> setAcls)
Grant or deny authorization to an operation on a node as a function of:
|
protected boolean |
checkPasswd(long sessionId,
byte[] passwd) |
void |
checkQuota(String path,
byte[] lastData,
byte[] data,
int type)
check a path whether exceeded the quota.
|
boolean |
checkRequestSizeWhenReceivingMessage(int length) |
void |
closeSession(long sessionId) |
void |
closeSession(ServerCnxn cnxn,
RequestHeader requestHeader) |
BlueThrottle |
connThrottle() |
protected void |
createSessionTracker() |
void |
decInProcess() |
void |
dumpConf(PrintWriter pwriter) |
void |
dumpEphemerals(PrintWriter pwriter) |
void |
dumpMonitorValues(BiConsumer<String,Object> response)
Hook into admin server, useful to expose additional data
that do not represent metrics.
|
void |
enqueueRequest(Request si) |
void |
expire(SessionTracker.Session session) |
void |
finishSessionInit(ServerCnxn cnxn,
boolean valid) |
int |
getClientPort() |
int |
getClientPortListenBacklog() |
ZooKeeperServerConf |
getConf() |
double |
getConnectionDropChance() |
long |
getDataDirSize() |
Map<Long,Set<String>> |
getEphemerals() |
ResponseCache |
getGetChildrenResponseCache() |
int |
getGlobalOutstandingLimit() |
int |
getInflight() |
String |
getInitialConfig() |
int |
getInProcess() |
int |
getLargeRequestBytes() |
int |
getLargeRequestMaxBytes() |
int |
getLargeRequestThreshold() |
long |
getLastProcessedZxid()
return the last proceesed id from the
datatree
|
long |
getLogDirSize() |
int |
getMaxClientCnxnsPerHost()
Maximum number of connections allowed from particular host (ip)
|
int |
getMaxSessionTimeout() |
int |
getMinSessionTimeout() |
int |
getNumAliveConnections()
return the total number of client connections that are alive
to this server
|
int |
getOutstandingHandshakeNum() |
long |
getOutstandingRequests()
return the outstanding requests
in the queue, which havent been
processed yet
|
ResponseCache |
getReadResponseCache() |
RequestPathMetricsCollector |
getRequestPathMetricsCollector() |
int |
getSecureClientPort() |
ServerCnxnFactory |
getSecureServerCnxnFactory() |
ServerCnxnFactory |
getServerCnxnFactory() |
long |
getServerId() |
Map<Long,Set<Long>> |
getSessionExpiryMap() |
SessionTracker |
getSessionTracker() |
static int |
getSnapCount() |
static long |
getSnapSizeInBytes() |
String |
getState() |
static int |
getThrottledOpWaitTime() |
int |
getTickTime() |
long |
getTxnLogElapsedSyncTime()
Returns the elapsed sync of time of transaction log in milliseconds.
|
FileTxnSnapLog |
getTxnLogFactory() |
ZKDatabase |
getZKDatabase()
get the zookeeper database for this server
|
ZooKeeperServerShutdownHandler |
getZkShutdownHandler() |
ZooKeeperServerListener |
getZooKeeperServerListener() |
long |
getZxid() |
void |
incInProcess() |
static boolean |
isCloseSessionTxnEnabled() |
static boolean |
isDigestEnabled() |
boolean |
isReconfigEnabled() |
boolean |
isResponseCachingEnabled() |
boolean |
isRunning() |
protected void |
killSession(long sessionId,
long zxid) |
void |
loadData()
Restore sessions and data
|
void |
processConnectRequest(ServerCnxn cnxn,
ByteBuffer incomingBuffer) |
void |
processPacket(ServerCnxn cnxn,
ByteBuffer incomingBuffer) |
DataTree.ProcessTxnResult |
processTxn(Request request) |
DataTree.ProcessTxnResult |
processTxn(TxnHeader hdr,
Record txn) |
protected void |
registerJMX() |
protected void |
registerMetrics() |
void |
reopenSession(ServerCnxn cnxn,
long sessionId,
byte[] passwd,
int sessionTimeout) |
void |
requestFinished(Request request) |
protected void |
revalidateSession(ServerCnxn cnxn,
long sessionId,
int sessionTimeout) |
ServerStats |
serverStats() |
void |
setClientPortListenBacklog(int backlog) |
static void |
setCloseSessionTxnEnabled(boolean enabled) |
void |
setCreateSessionTrackerServerId(int newId)
Change the server ID used by
createSessionTracker() . |
static void |
setDigestEnabled(boolean digestEnabled) |
void |
setLargeRequestMaxBytes(int bytes) |
void |
setLargeRequestThreshold(int threshold) |
protected void |
setLocalSessionFlag(Request si)
If the underlying Zookeeper server support local session, this method
will set a isLocalSession to true if a request is associated with
a local session.
|
void |
setMaxSessionTimeout(int max) |
void |
setMinSessionTimeout(int min) |
void |
setOwner(long id,
Object owner)
set the owner of this session as owner
|
void |
setResponseCachingEnabled(boolean isEnabled) |
void |
setSecureServerCnxnFactory(ServerCnxnFactory factory) |
void |
setServerCnxnFactory(ServerCnxnFactory factory) |
protected void |
setState(ZooKeeperServer.State state)
Sets the state of ZooKeeper server.
|
static void |
setThrottledOpWaitTime(int time) |
void |
setTickTime(int tickTime) |
void |
setTxnLogFactory(FileTxnSnapLog txnLog) |
protected void |
setupRequestProcessors() |
void |
setZKDatabase(ZKDatabase zkDb)
set the zkdatabase for this zookeeper server
|
void |
setZxid(long zxid) |
boolean |
shouldForceWriteInitialSnapshotAfterLeaderElection() |
boolean |
shouldThrottle(long outStandingCount) |
void |
shutdown() |
void |
shutdown(boolean fullyShutDown)
Shut down the server instance
|
void |
startdata() |
protected void |
startJvmPauseMonitor() |
protected void |
startRequestThrottler() |
void |
startServing() |
protected void |
startSessionTracker() |
void |
startup() |
void |
startupWithoutServing() |
void |
submitRequest(Request si) |
void |
submitRequestNow(Request si) |
void |
takeSnapshot() |
void |
takeSnapshot(boolean syncSnap) |
void |
truncateLog(long zxid)
trunccate the log to get in sync with others
if in a quorum
|
protected void |
unregisterJMX() |
protected void |
unregisterMetrics() |
protected void |
validateSession(ServerCnxn cnxn,
long sessionId)
Validate if a particular session can be reestablished.
|
protected static final org.slf4j.Logger LOG
public static final String GLOBAL_OUTSTANDING_LIMIT
public static final String ENABLE_EAGER_ACL_CHECK
public static final String SKIP_ACL
public static final String ENFORCE_QUOTA
public static final boolean enforceQuota
public static final String SASL_SUPER_USER
public static final String ALLOW_SASL_FAILED_CLIENTS
public static final String ZOOKEEPER_DIGEST_ENABLED
public static final String CLOSE_SESSION_TXN_ENABLED
protected ZooKeeperServerBean jmxServerBean
protected DataTreeBean jmxDataTreeBean
public static final int DEFAULT_TICK_TIME
protected int tickTime
public static final int DEFAULT_THROTTLED_OP_WAIT_TIME
protected static volatile int throttledOpWaitTime
protected int minSessionTimeout
protected int maxSessionTimeout
protected int listenBacklog
protected SessionTracker sessionTracker
public static final Exception ok
protected RequestProcessor firstProcessor
protected JvmPauseMonitor jvmPauseMonitor
protected volatile ZooKeeperServer.State state
protected String initialConfig
protected boolean reconfigEnabled
protected ServerCnxnFactory serverCnxnFactory
protected ServerCnxnFactory secureServerCnxnFactory
public static final String INT_BUFFER_STARTING_SIZE_BYTES
public static final int DEFAULT_STARTING_BUFFER_SIZE
public static final int intBufferStartingSizeBytes
public static final String GET_DATA_RESPONSE_CACHE_SIZE
public static final String GET_CHILDREN_RESPONSE_CACHE_SIZE
public static final String SNAP_COUNT
public ZooKeeperServer()
public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig)
public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig, boolean reconfigEnabled)
public ZooKeeperServer(JvmPauseMonitor jvmPauseMonitor, FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig)
ZooKeeperServer(FileTxnSnapLog, int, int, int, int, ZKDatabase, String)
public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, String initialConfig)
txnLogFactory
- the file transaction snapshot logging classtickTime
- the ticktime for the serverIOException
public ZooKeeperServer(File snapDir, File logDir, int tickTime) throws IOException
IOException
public ZooKeeperServer(FileTxnSnapLog txnLogFactory) throws IOException
IOException
public static boolean isCloseSessionTxnEnabled()
public static void setCloseSessionTxnEnabled(boolean enabled)
public String getInitialConfig()
public ServerStats serverStats()
public RequestPathMetricsCollector getRequestPathMetricsCollector()
public BlueThrottle connThrottle()
public void dumpConf(PrintWriter pwriter)
public ZooKeeperServerConf getConf()
public ZKDatabase getZKDatabase()
public void setZKDatabase(ZKDatabase zkDb)
zkDb
- public void loadData() throws IOException, InterruptedException
IOException
InterruptedException
public void takeSnapshot()
public void takeSnapshot(boolean syncSnap)
public boolean shouldForceWriteInitialSnapshotAfterLeaderElection()
public long getDataDirSize()
getDataDirSize
in interface ServerStats.Provider
public long getLogDirSize()
getLogDirSize
in interface ServerStats.Provider
public long getZxid()
public SessionTracker getSessionTracker()
public void setZxid(long zxid)
public void closeSession(long sessionId)
protected void killSession(long sessionId, long zxid)
public void expire(SessionTracker.Session session)
expire
in interface SessionTracker.SessionExpirer
protected void registerJMX()
public void startdata() throws IOException, InterruptedException
IOException
InterruptedException
public void startup()
public void startupWithoutServing()
public void startServing()
protected void startJvmPauseMonitor()
protected void startRequestThrottler()
protected void setupRequestProcessors()
public ZooKeeperServerListener getZooKeeperServerListener()
public void setCreateSessionTrackerServerId(int newId)
createSessionTracker()
. Must be called prior to
startup()
being callednewId
- ID to useprotected void createSessionTracker()
protected void startSessionTracker()
protected void setState(ZooKeeperServer.State state)
The following are the server state transitions:
ZooKeeperServerListenerImpl
notifies any critical resource
error events, e.g., SyncRequestProcessor not being able to write a txn to
disk.state
- new server state.protected boolean canShutdown()
public boolean isRunning()
public void shutdown()
public void shutdown(boolean fullyShutDown)
fullyShutDown
- true if another server using the same database will not replace this one in the same processprotected void unregisterJMX()
public void incInProcess()
public void decInProcess()
public int getInProcess()
public int getInflight()
protected boolean checkPasswd(long sessionId, byte[] passwd)
public void setOwner(long id, Object owner) throws KeeperException.SessionExpiredException
id
- the session idowner
- the owner of the sessionKeeperException.SessionExpiredException
protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException
IOException
public void reopenSession(ServerCnxn cnxn, long sessionId, byte[] passwd, int sessionTimeout) throws IOException
IOException
public void finishSessionInit(ServerCnxn cnxn, boolean valid)
public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader)
public long getServerId()
getServerId
in interface SessionTracker.SessionExpirer
protected void setLocalSessionFlag(Request si)
si
- public void submitRequest(Request si)
public void enqueueRequest(Request si)
public void submitRequestNow(Request si)
public static int getSnapCount()
public int getGlobalOutstandingLimit()
public static long getSnapSizeInBytes()
public void setServerCnxnFactory(ServerCnxnFactory factory)
public ServerCnxnFactory getServerCnxnFactory()
public ServerCnxnFactory getSecureServerCnxnFactory()
public void setSecureServerCnxnFactory(ServerCnxnFactory factory)
public long getLastProcessedZxid()
getLastProcessedZxid
in interface ServerStats.Provider
public long getOutstandingRequests()
getOutstandingRequests
in interface ServerStats.Provider
public int getNumAliveConnections()
getNumAliveConnections
in interface ServerStats.Provider
public void truncateLog(long zxid) throws IOException
zxid
- the zxid that it needs to get in sync
with othersIOException
public int getTickTime()
public void setTickTime(int tickTime)
public static int getThrottledOpWaitTime()
public static void setThrottledOpWaitTime(int time)
public int getMinSessionTimeout()
public void setMinSessionTimeout(int min)
public int getMaxSessionTimeout()
public void setMaxSessionTimeout(int max)
public int getClientPortListenBacklog()
public void setClientPortListenBacklog(int backlog)
public int getClientPort()
public int getSecureClientPort()
public int getMaxClientCnxnsPerHost()
public void setTxnLogFactory(FileTxnSnapLog txnLog)
public FileTxnSnapLog getTxnLogFactory()
public long getTxnLogElapsedSyncTime()
public String getState()
getState
in interface ServerStats.Provider
public void dumpEphemerals(PrintWriter pwriter)
public double getConnectionDropChance()
public void processConnectRequest(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException, ClientCnxnLimitException
IOException
ClientCnxnLimitException
protected void validateSession(ServerCnxn cnxn, long sessionId) throws IOException
cnxn
- sessionId
- IOException
public boolean shouldThrottle(long outStandingCount)
public int getLargeRequestMaxBytes()
public void setLargeRequestMaxBytes(int bytes)
public int getLargeRequestThreshold()
public void setLargeRequestThreshold(int threshold)
public int getLargeRequestBytes()
public boolean checkRequestSizeWhenReceivingMessage(int length) throws IOException
IOException
public void requestFinished(Request request)
public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException
IOException
public DataTree.ProcessTxnResult processTxn(TxnHeader hdr, Record txn)
public DataTree.ProcessTxnResult processTxn(Request request)
public boolean isResponseCachingEnabled()
public void setResponseCachingEnabled(boolean isEnabled)
public ResponseCache getReadResponseCache()
public ResponseCache getGetChildrenResponseCache()
protected void registerMetrics()
protected void unregisterMetrics()
public void dumpMonitorValues(BiConsumer<String,Object> response)
response
- a sink which collects the data.public void checkACL(ServerCnxn cnxn, List<ACL> acl, int perm, List<Id> ids, String path, List<ACL> setAcls) throws KeeperException.NoAuthException
cnxn
- : the server connectionacl
- : set of ACLs for the nodeperm
- : the permission that the client is requestingids
- : the credentials supplied by the clientpath
- : the ZNode pathsetAcls
- : for set ACL operations, the list of ACLs being set. Otherwise null.KeeperException.NoAuthException
public void checkQuota(String path, byte[] lastData, byte[] data, int type) throws KeeperException.QuotaExceededException
path
- the path of the node, used for the quota prefix checklastData
- the current node data, null
for nonedata
- the data to be set, or null
for nonetype
- currently, create and setData need to check quotaKeeperException.QuotaExceededException
public static boolean isDigestEnabled()
public static void setDigestEnabled(boolean digestEnabled)
public boolean authWriteRequest(Request request)
request
- IOException
public int getOutstandingHandshakeNum()
public boolean isReconfigEnabled()
public ZooKeeperServerShutdownHandler getZkShutdownHandler()
Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.