Package org.apache.zookeeper.server
Class DataTree
- java.lang.Object
- 
- org.apache.zookeeper.server.DataTree
 
- 
 public class DataTree extends 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 SummaryNested Classes Modifier and Type Class Description static classDataTree.ProcessTxnResultclassDataTree.ZxidDigestA helper class to maintain the digest meta associated with specific zxid.
 - 
Field SummaryFields Modifier and Type Field Description static intDIGEST_LOG_INTERVALstatic intDIGEST_LOG_LIMITlonglastProcessedZxidstatic intSTAT_OVERHEAD_BYTESover-the-wire size of znode's stat.
 - 
Constructor SummaryConstructors Constructor Description DataTree()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intaclCacheSize()voidaddConfigNode()create a /zookeeper/config node for maintaining the configuration (membership and quorum system) info for zookeepervoidaddDigestWatcher(DigestWatcher digestWatcher)Add digest mismatch event handler.voidaddWatch(String basePath, Watcher watcher, int mode)longapproximateDataSize()Get the size of the nodes based on path and data length.longcachedApproximateDataSize()booleancompareDigest(TxnHeader header, Record txn, TxnDigest digest)Compares the digest of the tree with the digest present in transaction digest.voidcompareSnapshotDigests(long zxid)Compares the actual tree's digest with that in the snapshot.booleancontainsWatcher(String path, Watcher.WatcherType type, Watcher watcher)static voidcopyStat(Stat from, Stat to)static voidcopyStatPersisted(StatPersisted from, StatPersisted to)voidcreateNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time)Add a new node to the DataTree.voidcreateNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, Stat outputStat)Add a new node to the DataTree.static StatPersistedcreateStat(long zxid, long time, long ephemeralOwner)Create a node stat from the given params.voiddeleteNode(String path, long zxid)remove the path from the datatreevoiddeserialize(InputArchive ia, String tag)booleandeserializeZxidDigest(InputArchive ia, long startZxidOfSnapshot)Deserializing the zxid digest from the input stream and update the digestFromLoadedSnapshot.voiddumpEphemerals(PrintWriter pwriter)Write a text dump of all the ephemerals in the datatree.voiddumpWatches(PrintWriter pwriter, boolean byPath)Write a text dump of all the watches on the datatree.voiddumpWatchesSummary(PrintWriter pwriter)Summary of the watches on the datatree.List<ACL>getACL(String path, Stat stat)List<ACL>getACL(DataNode node)intgetAllChildrenNumber(String path)List<String>getChildren(String path, Stat stat, Watcher watcher)Set<String>getContainers()byte[]getData(String path, Stat stat, Watcher watcher)DataTree.ZxidDigestgetDigestFromLoadedSnapshot()List<DataTree.ZxidDigest>getDigestLog()Return all the digests in the historical digest list.Map<Long,Set<String>>getEphemerals()Returns a mapping of session ID to ephemeral znodes.Set<String>getEphemerals(long sessionId)intgetEphemeralsCount()DataTree.ZxidDigestgetLastProcessedZxidDigest()StringgetMaxPrefixWithQuota(String path)If there is a quota set, return the appropriate prefix for that quota Else return nullDataNodegetNode(String path)intgetNodeCount()ReferenceCountedACLCachegetReferenceCountedAclCache()Collection<Long>getSessions()longgetTreeDigest()Set<String>getTtls()intgetWatchCount()WatchesReportgetWatches()Returns a watch report.WatchesPathReportgetWatchesByPath()Returns a watch report by path.WatchesSummarygetWatchesSummary()Returns a watch summary.DataTree.ProcessTxnResultprocessTxn(TxnHeader header, Record txn)DataTree.ProcessTxnResultprocessTxn(TxnHeader header, Record txn, boolean isSubTxn)DataTree.ProcessTxnResultprocessTxn(TxnHeader header, Record txn, TxnDigest digest)voidremoveCnxn(Watcher watcher)booleanremoveWatch(String path, Watcher.WatcherType type, Watcher watcher)voidreportDigestMismatch(long zxid)Reports any mismatch in the transaction digest.voidserialize(OutputArchive oa, String tag)voidserializeAcls(OutputArchive oa)voidserializeNodeData(OutputArchive oa, String path, DataNode node)voidserializeNodes(OutputArchive oa)booleanserializeZxidDigest(OutputArchive oa)Serializing the digest to snapshot, this is done after the data tree is being serialized, so when we replay the txns and it hits this zxid we know we should be in a non-fuzzy state, and have the same digest.StatsetACL(String path, List<ACL> acl, int version)voidsetCversionPzxid(String path, int newCversion, long zxid)This method sets the Cversion and Pzxid for the specified node to the values passed as arguments.StatsetData(String path, byte[] data, int version, long zxid, long time)voidsetWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, List<String> persistentWatches, List<String> persistentRecursiveWatches, Watcher watcher)voidshutdownWatcher()StatstatNode(String path, Watcher watcher)voidupdateQuotaStat(String lastPrefix, long bytesDiff, int countDiff)update the count/bytes of this stat data node
 
- 
- 
- 
Field Detail- 
STAT_OVERHEAD_BYTESpublic static final int STAT_OVERHEAD_BYTES over-the-wire size of znode's stat. Counting the fields of Stat class- See Also:
- Constant Field Values
 
 - 
DIGEST_LOG_LIMITpublic static final int DIGEST_LOG_LIMIT - See Also:
- Constant Field Values
 
 - 
DIGEST_LOG_INTERVALpublic static final int DIGEST_LOG_INTERVAL - See Also:
- Constant Field Values
 
 - 
lastProcessedZxidpublic volatile long lastProcessedZxid 
 
- 
 - 
Method Detail- 
getSessionspublic Collection<Long> getSessions() 
 - 
getNodeCountpublic int getNodeCount() 
 - 
getWatchCountpublic int getWatchCount() 
 - 
getEphemeralsCountpublic int getEphemeralsCount() 
 - 
approximateDataSizepublic long approximateDataSize() Get the size of the nodes based on path and data length.- Returns:
- size of the data
 
 - 
cachedApproximateDataSizepublic long cachedApproximateDataSize() 
 - 
addConfigNodepublic void addConfigNode() create a /zookeeper/config node for maintaining the configuration (membership and quorum system) info for zookeeper
 - 
copyStatPersistedpublic static void copyStatPersisted(StatPersisted from, StatPersisted to) 
 - 
updateQuotaStatpublic void updateQuotaStat(String lastPrefix, long bytesDiff, int countDiff) update the count/bytes of this stat data node- Parameters:
- lastPrefix- the path of the node that has a quota.
- bytesDiff- the diff to be added to number of bytes
- countDiff- the diff to be added to the count
 
 - 
createNodepublic void createNode(String path, byte[] data, List<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 acls
- ephemeralOwner- the session id that owns this node. -1 indicates this is not an ephemeral node.
- zxid- Transaction ID
- time-
- Throws:
- KeeperException.NodeExistsException
- KeeperException.NoNodeException
 
 - 
createNodepublic void createNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, 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 acls
- ephemeralOwner- the session id that owns this node. -1 indicates this is not an ephemeral node.
- zxid- Transaction ID
- time-
- outputStat- A Stat object to store Stat output results into.
- Throws:
- KeeperException.NodeExistsException
- KeeperException.NoNodeException
 
 - 
deleteNodepublic void deleteNode(String path, long zxid) throws KeeperException.NoNodeException remove the path from the datatree- Parameters:
- path- the path to of the node to be deleted
- zxid- the current zxid
- Throws:
- KeeperException.NoNodeException
 
 - 
setDatapublic Stat setData(String path, byte[] data, int version, long zxid, long time) throws KeeperException.NoNodeException - Throws:
- KeeperException.NoNodeException
 
 - 
getMaxPrefixWithQuotapublic String getMaxPrefixWithQuota(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
 
 - 
getDatapublic byte[] getData(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException - Throws:
- KeeperException.NoNodeException
 
 - 
statNodepublic Stat statNode(String path, Watcher watcher) throws KeeperException.NoNodeException - Throws:
- KeeperException.NoNodeException
 
 - 
getChildrenpublic List<String> getChildren(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException - Throws:
- KeeperException.NoNodeException
 
 - 
getAllChildrenNumberpublic int getAllChildrenNumber(String path) 
 - 
setACLpublic Stat setACL(String path, List<ACL> acl, int version) throws KeeperException.NoNodeException - Throws:
- KeeperException.NoNodeException
 
 - 
getACLpublic List<ACL> getACL(String path, Stat stat) throws KeeperException.NoNodeException - Throws:
- KeeperException.NoNodeException
 
 - 
aclCacheSizepublic int aclCacheSize() 
 - 
processTxnpublic DataTree.ProcessTxnResult processTxn(TxnHeader header, Record txn, TxnDigest digest) 
 - 
processTxnpublic DataTree.ProcessTxnResult processTxn(TxnHeader header, Record txn) 
 - 
processTxnpublic DataTree.ProcessTxnResult processTxn(TxnHeader header, Record txn, boolean isSubTxn) 
 - 
serializeNodeDatapublic void serializeNodeData(OutputArchive oa, String path, DataNode node) throws IOException - Throws:
- IOException
 
 - 
serializeAclspublic void serializeAcls(OutputArchive oa) throws IOException - Throws:
- IOException
 
 - 
serializeNodespublic void serializeNodes(OutputArchive oa) throws IOException - Throws:
- IOException
 
 - 
serializepublic void serialize(OutputArchive oa, String tag) throws IOException - Throws:
- IOException
 
 - 
deserializepublic void deserialize(InputArchive ia, String tag) throws IOException - Throws:
- IOException
 
 - 
dumpWatchesSummarypublic void dumpWatchesSummary(PrintWriter pwriter) Summary of the watches on the datatree.- Parameters:
- pwriter- the output to write to
 
 - 
dumpWatchespublic void dumpWatches(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
 
 - 
getWatchespublic WatchesReport getWatches() Returns a watch report.- Returns:
- watch report
- See Also:
- WatchesReport
 
 - 
getWatchesByPathpublic WatchesPathReport getWatchesByPath() Returns a watch report by path.- Returns:
- watch report
- See Also:
- WatchesPathReport
 
 - 
getWatchesSummarypublic WatchesSummary getWatchesSummary() Returns a watch summary.- Returns:
- watch summary
- See Also:
- WatchesSummary
 
 - 
dumpEphemeralspublic void dumpEphemerals(PrintWriter pwriter) Write a text dump of all the ephemerals in the datatree.- Parameters:
- pwriter- the output to write to
 
 - 
shutdownWatcherpublic void shutdownWatcher() 
 - 
getEphemeralspublic Map<Long,Set<String>> getEphemerals() Returns a mapping of session ID to ephemeral znodes.- Returns:
- map of session ID to sets of ephemeral znodes
 
 - 
removeCnxnpublic void removeCnxn(Watcher watcher) 
 - 
setWatchespublic void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, List<String> persistentWatches, List<String> persistentRecursiveWatches, Watcher watcher)
 - 
setCversionPzxidpublic void setCversionPzxid(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 Cversion
- zxid- Value to be assigned to Pzxid
- Throws:
- KeeperException.NoNodeException- If znode not found.
 
 - 
containsWatcherpublic boolean containsWatcher(String path, Watcher.WatcherType type, Watcher watcher) 
 - 
removeWatchpublic boolean removeWatch(String path, Watcher.WatcherType type, Watcher watcher) 
 - 
getReferenceCountedAclCachepublic ReferenceCountedACLCache getReferenceCountedAclCache() 
 - 
serializeZxidDigestpublic boolean serializeZxidDigest(OutputArchive oa) throws IOException Serializing the digest to snapshot, this is done after the data tree is being serialized, so when we replay the txns and it hits this zxid we know we should be in a non-fuzzy state, and have the same digest.- Parameters:
- oa- the output stream to write to
- Returns:
- true if the digest is serialized successfully
- Throws:
- IOException
 
 - 
deserializeZxidDigestpublic boolean deserializeZxidDigest(InputArchive ia, long startZxidOfSnapshot) throws IOException Deserializing the zxid digest from the input stream and update the digestFromLoadedSnapshot.- Parameters:
- ia- the input stream to read from
- startZxidOfSnapshot- the zxid of snapshot file
- Returns:
- the true if it deserialized successfully
- Throws:
- IOException
 
 - 
compareSnapshotDigestspublic void compareSnapshotDigests(long zxid) Compares the actual tree's digest with that in the snapshot. Resets digestFromLoadedSnapshot after comparision.- Parameters:
- zxid- zxid
 
 - 
compareDigestpublic boolean compareDigest(TxnHeader header, Record txn, TxnDigest digest) Compares the digest of the tree with the digest present in transaction digest. If there is any error, logs and alerts the watchers.- Parameters:
- header- transaction header being applied
- txn- transaction
- digest- transaction digest
- Returns:
- false if digest in the txn doesn't match what we have now in the data tree
 
 - 
reportDigestMismatchpublic void reportDigestMismatch(long zxid) Reports any mismatch in the transaction digest.- Parameters:
- zxid- zxid for which the error is being reported.
 
 - 
getTreeDigestpublic long getTreeDigest() 
 - 
getLastProcessedZxidDigestpublic DataTree.ZxidDigest getLastProcessedZxidDigest() 
 - 
getDigestFromLoadedSnapshotpublic DataTree.ZxidDigest getDigestFromLoadedSnapshot() 
 - 
addDigestWatcherpublic void addDigestWatcher(DigestWatcher digestWatcher) Add digest mismatch event handler.- Parameters:
- digestWatcher- the handler to add
 
 - 
getDigestLogpublic List<DataTree.ZxidDigest> getDigestLog() Return all the digests in the historical digest list.
 - 
createStatpublic static StatPersisted createStat(long zxid, long time, long ephemeralOwner) Create a node stat from the given params.- Parameters:
- zxid- the zxid associated with the txn
- time- the time when the txn is created
- ephemeralOwner- the owner if the node is an ephemeral
- Returns:
- the stat
 
 
- 
 
-