public class ZKDatabase extends Object
Modifier and Type | Field and Description |
---|---|
protected static int |
commitLogBuffer |
static int |
commitLogCount |
protected LinkedList<Leader.Proposal> |
committedLog |
protected DataTree |
dataTree
make sure on a clear you take care of
all these members.
|
static double |
DEFAULT_SNAPSHOT_SIZE_FACTOR |
protected ReentrantReadWriteLock |
logLock |
protected long |
maxCommittedLog |
protected long |
minCommittedLog |
protected ConcurrentHashMap<Long,Integer> |
sessionsWithTimeouts |
protected FileTxnSnapLog |
snapLog |
static String |
SNAPSHOT_SIZE_FACTOR
Default value is to use snapshot if txnlog size exceeds 1/3 the size of snapshot
|
Constructor and Description |
---|
ZKDatabase(FileTxnSnapLog snapLog)
the filetxnsnaplog that this zk database
maps to.
|
Modifier and Type | Method and Description |
---|---|
List<ACL> |
aclForNode(DataNode n) |
void |
addCommittedProposal(Request request)
maintains a list of last committedLog
or so committed requests.
|
boolean |
append(Request si)
append to the underlying transaction log
|
long |
calculateTxnLogSizeLimit() |
void |
clear()
clear the zkdatabase.
|
void |
close()
close this database.
|
void |
commit()
commit to the underlying transaction log
|
boolean |
containsWatcher(String path,
Watcher.WatcherType type,
Watcher watcher)
Check whether the given watcher exists in datatree
|
DataTree |
createDataTree() |
void |
deserializeSnapshot(InputArchive ia)
deserialize a snapshot from an input archive
|
void |
dumpEphemerals(PrintWriter pwriter)
write a text dump of all the ephemerals in the datatree
|
long |
fastForwardDataBase()
Fast forward the database adding transactions from the committed log into memory.
|
List<ACL> |
getACL(String path,
Stat stat)
get acl for a path
|
int |
getAclSize()
get the acl size of the datatree
|
List<String> |
getChildren(String path,
Stat stat,
Watcher watcher)
get children list for this path
|
List<Leader.Proposal> |
getCommittedLog() |
byte[] |
getData(String path,
Stat stat,
Watcher watcher)
get data and stat for a path
|
DataTree |
getDataTree()
the datatree for this zkdatabase
|
long |
getDataTreeLastProcessedZxid()
get the last processed zxid from a datatree
|
Map<Long,Set<String>> |
getEphemerals() |
Set<String> |
getEphemerals(long sessionId)
the paths for ephemeral session id
|
ReentrantReadWriteLock |
getLogLock()
Get the lock that controls the committedLog.
|
long |
getmaxCommittedLog()
the committed log for this zk database
|
long |
getminCommittedLog()
the minimum committed transaction log
available in memory
|
DataNode |
getNode(String path)
get the datanode for this path
|
int |
getNodeCount()
the node count of the datatree
|
Iterator<Leader.Proposal> |
getProposalsFromTxnLog(long startZxid,
long sizeLimit)
Get proposals from txnlog.
|
Collection<Long> |
getSessions()
return the sessions in the datatree
|
ConcurrentHashMap<Long,Integer> |
getSessionWithTimeOuts()
get sessions with timeouts
|
void |
initConfigInZKDatabase(QuorumVerifier qv) |
boolean |
isInitialized()
checks to see if the zk database has been
initialized or not.
|
boolean |
isSpecialPath(String path)
check if the path is special or not
|
boolean |
isTxnLogSyncEnabled() |
void |
killSession(long sessionId,
long zxid)
kill a given session in the datatree
|
long |
loadDataBase()
load the database from the disk onto memory and also add
the transactions to the committedlog in memory.
|
DataTree.ProcessTxnResult |
processTxn(TxnHeader hdr,
Record txn)
the process txn on the data
|
void |
removeCnxn(ServerCnxn cnxn)
remove a cnxn from the datatree
|
boolean |
removeWatch(String path,
Watcher.WatcherType type,
Watcher watcher)
Remove watch from the datatree
|
void |
rollLog()
roll the underlying log
|
void |
serializeSnapshot(OutputArchive oa)
serialize the snapshot
|
void |
setlastProcessedZxid(long zxid)
the last processed zxid in the datatree
|
void |
setSnapshotSizeFactor(double snapshotSizeFactor)
Use for unit testing, so we can turn this feature on/off
|
void |
setWatches(long relativeZxid,
List<String> dataWatches,
List<String> existWatches,
List<String> childWatches,
Watcher watcher)
set watches on the datatree
|
Stat |
statNode(String path,
ServerCnxn serverCnxn)
stat the path
|
boolean |
truncateLog(long zxid)
Truncate the ZKDatabase to the specified zxid
|
protected DataTree dataTree
protected ConcurrentHashMap<Long,Integer> sessionsWithTimeouts
protected FileTxnSnapLog snapLog
protected long minCommittedLog
protected long maxCommittedLog
public static final String SNAPSHOT_SIZE_FACTOR
public static final double DEFAULT_SNAPSHOT_SIZE_FACTOR
public static final int commitLogCount
protected static int commitLogBuffer
protected LinkedList<Leader.Proposal> committedLog
protected ReentrantReadWriteLock logLock
public ZKDatabase(FileTxnSnapLog snapLog)
snapLog
- the FileTxnSnapLog mapping this zkdatabasepublic boolean isInitialized()
public void clear()
public DataTree getDataTree()
public long getmaxCommittedLog()
public long getminCommittedLog()
public ReentrantReadWriteLock getLogLock()
public List<Leader.Proposal> getCommittedLog()
public long getDataTreeLastProcessedZxid()
public Collection<Long> getSessions()
public ConcurrentHashMap<Long,Integer> getSessionWithTimeOuts()
public long loadDataBase() throws IOException
IOException
public long fastForwardDataBase() throws IOException
IOException
public void addCommittedProposal(Request request)
request
- committed requestpublic boolean isTxnLogSyncEnabled()
public long calculateTxnLogSizeLimit()
public Iterator<Leader.Proposal> getProposalsFromTxnLog(long startZxid, long sizeLimit)
startZxid
- the starting zxid of the proposalsizeLimit
- maximum on-disk size of txnlog to fetch
0 is unlimited, negative value means disable.public void removeCnxn(ServerCnxn cnxn)
cnxn
- the cnxn to remove from the datatreepublic void killSession(long sessionId, long zxid)
sessionId
- the session id to be killedzxid
- the zxid of kill session transactionpublic void dumpEphemerals(PrintWriter pwriter)
pwriter
- the output to write topublic int getNodeCount()
public Set<String> getEphemerals(long sessionId)
sessionId
- the session id for which paths match topublic void setlastProcessedZxid(long zxid)
zxid
- the last processed zxid in the datatreepublic DataTree.ProcessTxnResult processTxn(TxnHeader hdr, Record txn)
hdr
- the txnheader for the txntxn
- the transaction that needs to be processedpublic Stat statNode(String path, ServerCnxn serverCnxn) throws KeeperException.NoNodeException
path
- the path for which stat is to be doneserverCnxn
- the servercnxn attached to this requestKeeperException.NoNodeException
public DataNode getNode(String path)
path
- the path to lookuppublic byte[] getData(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException
path
- the path being queriedstat
- the stat for this pathwatcher
- the watcher functionKeeperException.NoNodeException
public void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher)
relativeZxid
- the relative zxid that client has seendataWatches
- the data watches the client wants to resetexistWatches
- the exists watches the client wants to resetchildWatches
- the child watches the client wants to resetwatcher
- the watcher functionpublic List<ACL> getACL(String path, Stat stat) throws KeeperException.NoNodeException
path
- the path to query for aclstat
- the stat for the nodeKeeperException.NoNodeException
public List<String> getChildren(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException
path
- the path of the nodestat
- the stat of the nodewatcher
- the watcher function for this pathKeeperException.NoNodeException
public boolean isSpecialPath(String path)
path
- the input pathpublic int getAclSize()
public boolean truncateLog(long zxid) throws IOException
zxid
- the zxid to truncate zk database toIOException
public void deserializeSnapshot(InputArchive ia) throws IOException
ia
- the input archive you want to deserialize fromIOException
public void serializeSnapshot(OutputArchive oa) throws IOException, InterruptedException
oa
- the output archive to which the snapshot needs to be serializedIOException
InterruptedException
public boolean append(Request si) throws IOException
si
- the request to appendIOException
public void rollLog() throws IOException
IOException
public void commit() throws IOException
IOException
public void close() throws IOException
IOException
public void initConfigInZKDatabase(QuorumVerifier qv)
public void setSnapshotSizeFactor(double snapshotSizeFactor)
snapshotSizeFactor
- Set to minus value to turn this off.public boolean containsWatcher(String path, Watcher.WatcherType type, Watcher watcher)
path
- node to check watcher existencetype
- type of watcherwatcher
- watcher functionpublic boolean removeWatch(String path, Watcher.WatcherType type, Watcher watcher)
path
- node to remove watches fromtype
- type of watcher to removewatcher
- watcher function to removepublic DataTree createDataTree()
Copyright © 2008–2019 The Apache Software Foundation. All rights reserved.