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 |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TICK_TIME |
protected RequestProcessor |
firstProcessor |
protected DataTreeBean |
jmxDataTreeBean |
protected ZooKeeperServerBean |
jmxServerBean |
protected static org.slf4j.Logger |
LOG |
protected int |
maxSessionTimeout
value of -1 indicates unset, use default
|
protected int |
minSessionTimeout
value of -1 indicates unset, use default
|
static Exception |
ok |
protected ServerCnxnFactory |
secureServerCnxnFactory |
protected ServerCnxnFactory |
serverCnxnFactory |
protected SessionTracker |
sessionTracker |
protected ZooKeeperServer.State |
state |
protected int |
tickTime |
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)
creates a zookeeperserver instance.
|
ZooKeeperServer(FileTxnSnapLog txnLogFactory,
int tickTime,
int minSessionTimeout,
int maxSessionTimeout,
ZKDatabase zkDb)
Creates a ZooKeeperServer instance.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canShutdown()
This can be used while shutting down the server to see whether the server
is already shutdown or not.
|
protected boolean |
checkPasswd(long sessionId,
byte[] passwd) |
void |
closeSession(long sessionId) |
void |
closeSession(ServerCnxn cnxn,
RequestHeader requestHeader) |
protected void |
createSessionTracker() |
void |
decInProcess() |
void |
dumpConf(PrintWriter pwriter) |
void |
dumpEphemerals(PrintWriter pwriter) |
void |
expire(SessionTracker.Session session) |
void |
finishSessionInit(ServerCnxn cnxn,
boolean valid) |
int |
getClientPort() |
ZooKeeperServerConf |
getConf() |
long |
getDataDirSize() |
Map<Long,Set<String>> |
getEphemerals() |
int |
getGlobalOutstandingLimit() |
int |
getInProcess() |
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
|
long |
getOutstandingRequests()
return the outstanding requests
in the queue, which havent been
processed yet
|
int |
getSecureClientPort() |
ServerCnxnFactory |
getSecureServerCnxnFactory() |
ServerCnxnFactory |
getServerCnxnFactory() |
long |
getServerId() |
Map<Long,Set<Long>> |
getSessionExpiryMap() |
SessionTracker |
getSessionTracker() |
static int |
getSnapCount() |
String |
getState() |
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
|
ZooKeeperServerListener |
getZooKeeperServerListener() |
long |
getZxid() |
void |
incInProcess() |
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() |
void |
reopenSession(ServerCnxn cnxn,
long sessionId,
byte[] passwd,
int sessionTimeout) |
protected void |
revalidateSession(ServerCnxn cnxn,
long sessionId,
int sessionTimeout) |
ServerStats |
serverStats() |
void |
setCreateSessionTrackerServerId(int newId)
Change the server ID used by
createSessionTracker() . |
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 |
setSecureServerCnxnFactory(ServerCnxnFactory factory) |
void |
setServerCnxnFactory(ServerCnxnFactory factory) |
protected void |
setState(ZooKeeperServer.State state)
Sets the state of ZooKeeper server.
|
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 |
shouldThrottle(long outStandingCount) |
void |
shutdown() |
void |
shutdown(boolean fullyShutDown)
Shut down the server instance
|
void |
startdata() |
protected void |
startSessionTracker() |
void |
startup() |
void |
submitRequest(Request si) |
void |
takeSnapshot() |
void |
truncateLog(long zxid)
trunccate the log to get in sync with others
if in a quorum
|
protected void |
unregisterJMX() |
protected static final org.slf4j.Logger LOG
protected ZooKeeperServerBean jmxServerBean
protected DataTreeBean jmxDataTreeBean
public static final int DEFAULT_TICK_TIME
protected int tickTime
protected int minSessionTimeout
protected int maxSessionTimeout
protected SessionTracker sessionTracker
public static final Exception ok
protected RequestProcessor firstProcessor
protected volatile ZooKeeperServer.State state
protected ServerCnxnFactory serverCnxnFactory
protected ServerCnxnFactory secureServerCnxnFactory
public ZooKeeperServer()
IOException
public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, ZKDatabase zkDb)
dataDir
- the directory to put the datapublic ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime) throws IOException
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 ServerStats serverStats()
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 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()
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()
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 static int getSnapCount()
public int getGlobalOutstandingLimit()
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 int getMinSessionTimeout()
public void setMinSessionTimeout(int min)
public int getMaxSessionTimeout()
public void setMaxSessionTimeout(int max)
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 void processConnectRequest(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException
IOException
public boolean shouldThrottle(long outStandingCount)
public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException
IOException
public DataTree.ProcessTxnResult processTxn(TxnHeader hdr, Record txn)
public DataTree.ProcessTxnResult processTxn(Request request)
Copyright © 2008–2019 The Apache Software Foundation. All rights reserved.