Package org.apache.zookeeper.server
Class DataTree
- java.lang.Object
-
- org.apache.zookeeper.server.DataTree
-
public class DataTree extends java.lang.Object
This class maintains the tree data structure. It doesn't have any networking or client connection code in it so that it can be tested in a stand alone way.The tree maintains two parallel data structures: a hashtable that maps from full paths to DataNodes and a tree of DataNodes. All accesses to a path is through the hashtable. The tree is traversed only when serializing to disk.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataTree.ProcessTxnResult
-
Field Summary
Fields Modifier and Type Field Description long
lastProcessedZxid
-
Constructor Summary
Constructors Constructor Description DataTree()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
aclCacheSize()
void
addConfigNode()
create a /zookeeper/config node for maintaining the configuration (membership and quorum system) info for zookeeperlong
approximateDataSize()
Get the size of the nodes based on path and data length.boolean
containsWatcher(java.lang.String path, Watcher.WatcherType type, Watcher watcher)
static void
copyStat(org.apache.zookeeper.data.Stat from, org.apache.zookeeper.data.Stat to)
static void
copyStatPersisted(org.apache.zookeeper.data.StatPersisted from, org.apache.zookeeper.data.StatPersisted to)
void
createNode(java.lang.String path, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time)
Add a new node to the DataTree.void
createNode(java.lang.String path, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, org.apache.zookeeper.data.Stat outputStat)
Add a new node to the DataTree.void
deleteNode(java.lang.String path, long zxid)
remove the path from the datatreevoid
deserialize(org.apache.jute.InputArchive ia, java.lang.String tag)
void
dumpEphemerals(java.io.PrintWriter pwriter)
Write a text dump of all the ephemerals in the datatree.void
dumpWatches(java.io.PrintWriter pwriter, boolean byPath)
Write a text dump of all the watches on the datatree.void
dumpWatchesSummary(java.io.PrintWriter pwriter)
Summary of the watches on the datatree.java.util.List<org.apache.zookeeper.data.ACL>
getACL(java.lang.String path, org.apache.zookeeper.data.Stat stat)
java.util.List<org.apache.zookeeper.data.ACL>
getACL(DataNode node)
java.util.List<java.lang.String>
getChildren(java.lang.String path, org.apache.zookeeper.data.Stat stat, Watcher watcher)
java.util.Set<java.lang.String>
getContainers()
byte[]
getData(java.lang.String path, org.apache.zookeeper.data.Stat stat, Watcher watcher)
java.util.Map<java.lang.Long,java.util.Set<java.lang.String>>
getEphemerals()
Returns a mapping of session ID to ephemeral znodes.java.util.Set<java.lang.String>
getEphemerals(long sessionId)
int
getEphemeralsCount()
java.lang.String
getMaxPrefixWithQuota(java.lang.String path)
If there is a quota set, return the appropriate prefix for that quota Else return nullDataNode
getNode(java.lang.String path)
int
getNodeCount()
ReferenceCountedACLCache
getReferenceCountedAclCache()
java.util.Collection<java.lang.Long>
getSessions()
java.util.Set<java.lang.String>
getTtls()
int
getWatchCount()
WatchesReport
getWatches()
Returns a watch report.WatchesPathReport
getWatchesByPath()
Returns a watch report by path.WatchesSummary
getWatchesSummary()
Returns a watch summary.DataTree.ProcessTxnResult
processTxn(org.apache.zookeeper.txn.TxnHeader header, org.apache.jute.Record txn)
DataTree.ProcessTxnResult
processTxn(org.apache.zookeeper.txn.TxnHeader header, org.apache.jute.Record txn, boolean isSubTxn)
void
removeCnxn(Watcher watcher)
boolean
removeWatch(java.lang.String path, Watcher.WatcherType type, Watcher watcher)
void
serialize(org.apache.jute.OutputArchive oa, java.lang.String tag)
void
serializeNodeData(org.apache.jute.OutputArchive oa, java.lang.String path, DataNode node)
org.apache.zookeeper.data.Stat
setACL(java.lang.String path, java.util.List<org.apache.zookeeper.data.ACL> acl, int version)
void
setCversionPzxid(java.lang.String path, int newCversion, long zxid)
This method sets the Cversion and Pzxid for the specified node to the values passed as arguments.org.apache.zookeeper.data.Stat
setData(java.lang.String path, byte[] data, int version, long zxid, long time)
void
setWatches(long relativeZxid, java.util.List<java.lang.String> dataWatches, java.util.List<java.lang.String> existWatches, java.util.List<java.lang.String> childWatches, Watcher watcher)
org.apache.zookeeper.data.Stat
statNode(java.lang.String path, Watcher watcher)
void
updateBytes(java.lang.String lastPrefix, long diff)
update the count of bytes of this stat datanodevoid
updateCount(java.lang.String lastPrefix, int diff)
update the count of this stat datanode
-
-
-
Method Detail
-
getEphemerals
public java.util.Set<java.lang.String> getEphemerals(long sessionId)
-
getContainers
public java.util.Set<java.lang.String> getContainers()
-
getTtls
public java.util.Set<java.lang.String> getTtls()
-
getSessions
public java.util.Collection<java.lang.Long> getSessions()
-
getNode
public DataNode getNode(java.lang.String path)
-
getNodeCount
public int getNodeCount()
-
getWatchCount
public int getWatchCount()
-
getEphemeralsCount
public int getEphemeralsCount()
-
approximateDataSize
public long approximateDataSize()
Get the size of the nodes based on path and data length.- Returns:
- size of the data
-
addConfigNode
public void addConfigNode()
create a /zookeeper/config node for maintaining the configuration (membership and quorum system) info for zookeeper
-
copyStatPersisted
public static void copyStatPersisted(org.apache.zookeeper.data.StatPersisted from, org.apache.zookeeper.data.StatPersisted to)
-
copyStat
public static void copyStat(org.apache.zookeeper.data.Stat from, org.apache.zookeeper.data.Stat to)
-
updateCount
public void updateCount(java.lang.String lastPrefix, int diff)
update the count of this stat datanode- Parameters:
lastPrefix
- the path of the node that is quotaed.diff
- the diff to be added to the count
-
updateBytes
public void updateBytes(java.lang.String lastPrefix, long diff)
update the count of bytes of this stat datanode- Parameters:
lastPrefix
- the path of the node that is quotaeddiff
- the diff to added to number of bytes- Throws:
java.io.IOException
- if path is not found
-
createNode
public void createNode(java.lang.String path, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time) throws KeeperException.NoNodeException, KeeperException.NodeExistsException
Add a new node to the DataTree.- Parameters:
path
- Path for the new node.data
- Data to store in the node.acl
- Node aclsephemeralOwner
- the session id that owns this node. -1 indicates this is not an ephemeral node.zxid
- Transaction IDtime
-- Throws:
KeeperException.NodeExistsException
KeeperException.NoNodeException
KeeperException
-
createNode
public void createNode(java.lang.String path, byte[] data, java.util.List<org.apache.zookeeper.data.ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, org.apache.zookeeper.data.Stat outputStat) throws KeeperException.NoNodeException, KeeperException.NodeExistsException
Add a new node to the DataTree.- Parameters:
path
- Path for the new node.data
- Data to store in the node.acl
- Node aclsephemeralOwner
- the session id that owns this node. -1 indicates this is not an ephemeral node.zxid
- Transaction IDtime
-outputStat
- A Stat object to store Stat output results into.- Throws:
KeeperException.NodeExistsException
KeeperException.NoNodeException
KeeperException
-
deleteNode
public void deleteNode(java.lang.String path, long zxid) throws KeeperException.NoNodeException
remove the path from the datatree- Parameters:
path
- the path to of the node to be deletedzxid
- the current zxid- Throws:
KeeperException.NoNodeException
-
setData
public org.apache.zookeeper.data.Stat setData(java.lang.String path, byte[] data, int version, long zxid, long time) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
getMaxPrefixWithQuota
public java.lang.String getMaxPrefixWithQuota(java.lang.String path)
If there is a quota set, return the appropriate prefix for that quota Else return null- Parameters:
path
- The ZK path to check for quota- Returns:
- Max quota prefix, or null if none
-
getData
public byte[] getData(java.lang.String path, org.apache.zookeeper.data.Stat stat, Watcher watcher) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
statNode
public org.apache.zookeeper.data.Stat statNode(java.lang.String path, Watcher watcher) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
getChildren
public java.util.List<java.lang.String> getChildren(java.lang.String path, org.apache.zookeeper.data.Stat stat, Watcher watcher) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
setACL
public org.apache.zookeeper.data.Stat setACL(java.lang.String path, java.util.List<org.apache.zookeeper.data.ACL> acl, int version) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
getACL
public java.util.List<org.apache.zookeeper.data.ACL> getACL(java.lang.String path, org.apache.zookeeper.data.Stat stat) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
getACL
public java.util.List<org.apache.zookeeper.data.ACL> getACL(DataNode node)
-
aclCacheSize
public int aclCacheSize()
-
processTxn
public DataTree.ProcessTxnResult processTxn(org.apache.zookeeper.txn.TxnHeader header, org.apache.jute.Record txn)
-
processTxn
public DataTree.ProcessTxnResult processTxn(org.apache.zookeeper.txn.TxnHeader header, org.apache.jute.Record txn, boolean isSubTxn)
-
serializeNodeData
public void serializeNodeData(org.apache.jute.OutputArchive oa, java.lang.String path, DataNode node) throws java.io.IOException
- Throws:
java.io.IOException
-
serialize
public void serialize(org.apache.jute.OutputArchive oa, java.lang.String tag) throws java.io.IOException
- Throws:
java.io.IOException
-
deserialize
public void deserialize(org.apache.jute.InputArchive ia, java.lang.String tag) throws java.io.IOException
- Throws:
java.io.IOException
-
dumpWatchesSummary
public void dumpWatchesSummary(java.io.PrintWriter pwriter)
Summary of the watches on the datatree.- Parameters:
pwriter
- the output to write to
-
dumpWatches
public void dumpWatches(java.io.PrintWriter pwriter, boolean byPath)
Write a text dump of all the watches on the datatree. Warning, this is expensive, use sparingly!- Parameters:
pwriter
- the output to write to
-
getWatches
public WatchesReport getWatches()
Returns a watch report.- Returns:
- watch report
- See Also:
WatchesReport
-
getWatchesByPath
public WatchesPathReport getWatchesByPath()
Returns a watch report by path.- Returns:
- watch report
- See Also:
WatchesPathReport
-
getWatchesSummary
public WatchesSummary getWatchesSummary()
Returns a watch summary.- Returns:
- watch summary
- See Also:
WatchesSummary
-
dumpEphemerals
public void dumpEphemerals(java.io.PrintWriter pwriter)
Write a text dump of all the ephemerals in the datatree.- Parameters:
pwriter
- the output to write to
-
getEphemerals
public java.util.Map<java.lang.Long,java.util.Set<java.lang.String>> getEphemerals()
Returns a mapping of session ID to ephemeral znodes.- Returns:
- map of session ID to sets of ephemeral znodes
-
removeCnxn
public void removeCnxn(Watcher watcher)
-
setWatches
public void setWatches(long relativeZxid, java.util.List<java.lang.String> dataWatches, java.util.List<java.lang.String> existWatches, java.util.List<java.lang.String> childWatches, Watcher watcher)
-
setCversionPzxid
public void setCversionPzxid(java.lang.String path, int newCversion, long zxid) throws KeeperException.NoNodeException
This method sets the Cversion and Pzxid for the specified node to the values passed as arguments. The values are modified only if newCversion is greater than the current Cversion. A NoNodeException is thrown if a znode for the specified path is not found.- Parameters:
path
- Full path to the znode whose Cversion needs to be modified. A "/" at the end of the path is ignored.newCversion
- Value to be assigned to Cversionzxid
- Value to be assigned to Pzxid- Throws:
KeeperException.NoNodeException
- If znode not found.
-
containsWatcher
public boolean containsWatcher(java.lang.String path, Watcher.WatcherType type, Watcher watcher)
-
removeWatch
public boolean removeWatch(java.lang.String path, Watcher.WatcherType type, Watcher watcher)
-
getReferenceCountedAclCache
public ReferenceCountedACLCache getReferenceCountedAclCache()
-
-