Package org.apache.zookeeper.server
Class DataTree
- java.lang.Object
-
- org.apache.zookeeper.server.DataTree
-
public class DataTree extends java.lang.ObjectThis 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 classDataTree.ProcessTxnResult
-
Field Summary
Fields Modifier and Type Field Description booleaninitializedlonglastProcessedZxid
-
Constructor Summary
Constructors Constructor Description DataTree()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intaclCacheSize()voidaddDataNode(java.lang.String path, DataNode node)just an accessor method to allow raw creation of datatree's from a bunch of datanodeslongapproximateDataSize()Get the size of the nodes based on path and data length.voidclear()static voidcopyStat(Stat from, Stat to)static voidcopyStatPersisted(StatPersisted from, StatPersisted to)java.lang.StringcreateNode(java.lang.String path, byte[] data, java.util.List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time)voiddeleteNode(java.lang.String path, long zxid)remove the path from the datatreevoiddeserialize(org.apache.jute.InputArchive ia, java.lang.String tag)voiddumpEphemerals(java.io.PrintWriter pwriter)Write a text dump of all the ephemerals in the datatree.voiddumpWatches(java.io.PrintWriter pwriter, boolean byPath)Write a text dump of all the watches on the datatree.voiddumpWatchesSummary(java.io.PrintWriter pwriter)Summary of the watches on the datatree.java.util.List<ACL>getACL(java.lang.String path, Stat stat)java.util.List<ACL>getACL(DataNode node)java.lang.LonggetACL(DataNodeV1 oldDataNode)java.util.List<java.lang.String>getChildren(java.lang.String path, Stat stat, Watcher watcher)byte[]getData(java.lang.String path, Stat stat, Watcher watcher)java.util.HashSet<java.lang.String>getEphemerals(long sessionId)intgetEphemeralsCount()java.util.Map<java.lang.Long,java.util.HashSet<java.lang.String>>getEphemeralsMap()java.lang.StringgetMaxPrefixWithQuota(java.lang.String path)If there is a quota set, return the appropriate prefix for that quota Else return nullDataNodegetNode(java.lang.String path)intgetNodeCount()java.util.Collection<java.lang.Long>getSessions()intgetWatchCount()DataTree.ProcessTxnResultprocessTxn(TxnHeader header, org.apache.jute.Record txn)voidremoveCnxn(Watcher watcher)voidserialize(org.apache.jute.OutputArchive oa, java.lang.String tag)StatsetACL(java.lang.String path, java.util.List<ACL> acl, int version)voidsetCversionPzxid(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.StatsetData(java.lang.String path, byte[] data, int version, long zxid, long time)voidsetWatches(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)StatstatNode(java.lang.String path, Watcher watcher)voidupdateBytes(java.lang.String lastPrefix, long diff)update the count of bytes of this stat datanodevoidupdateCount(java.lang.String lastPrefix, int diff)update the count of this stat datanode
-
-
-
Method Detail
-
getEphemerals
public java.util.HashSet<java.lang.String> getEphemerals(long sessionId)
-
getEphemeralsMap
public java.util.Map<java.lang.Long,java.util.HashSet<java.lang.String>> getEphemeralsMap()
-
getSessions
public java.util.Collection<java.lang.Long> getSessions()
-
addDataNode
public void addDataNode(java.lang.String path, DataNode node)just an accessor method to allow raw creation of datatree's from a bunch of datanodes- Parameters:
path- the path of the datanodenode- the datanode corresponding to this path
-
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
-
copyStatPersisted
public static void copyStatPersisted(StatPersisted from, StatPersisted 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 java.lang.String createNode(java.lang.String path, byte[] data, java.util.List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time) throws KeeperException.NoNodeException, KeeperException.NodeExistsException- Parameters:
path-data-acl-ephemeralOwner- the session id that owns this node. -1 indicates this is not an ephemeral node.zxid-time-- Returns:
- the patch of the created node
- Throws:
KeeperExceptionKeeperException.NoNodeExceptionKeeperException.NodeExistsException
-
deleteNode
public void deleteNode(java.lang.String path, long zxid) throws KeeperException.NoNodeExceptionremove the path from the datatree- Parameters:
path- the path to of the node to be deletedzxid- the current zxid- Throws:
KeeperException.NoNodeException
-
setData
public 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, Stat stat, Watcher watcher) throws KeeperException.NoNodeException- Throws:
KeeperException.NoNodeException
-
statNode
public 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, Stat stat, Watcher watcher) throws KeeperException.NoNodeException- Throws:
KeeperException.NoNodeException
-
setACL
public Stat setACL(java.lang.String path, java.util.List<ACL> acl, int version) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
getACL
public java.util.List<ACL> getACL(java.lang.String path, Stat stat) throws KeeperException.NoNodeException
- Throws:
KeeperException.NoNodeException
-
getACL
public java.lang.Long getACL(DataNodeV1 oldDataNode)
-
aclCacheSize
public int aclCacheSize()
-
processTxn
public DataTree.ProcessTxnResult processTxn(TxnHeader header, org.apache.jute.Record txn)
-
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
-
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
-
removeCnxn
public void removeCnxn(Watcher watcher)
-
clear
public void clear()
-
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.NoNodeExceptionThis 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.
-
-