Class 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.

    • 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 zookeeper
      long 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 datatree
      void 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 null
      DataNode 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 datanode
      void updateCount​(java.lang.String lastPrefix, int diff)
      update the count of this stat datanode
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lastProcessedZxid

        public volatile long lastProcessedZxid
    • Constructor Detail

      • DataTree

        public DataTree()
    • 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 quotaed
        diff - the diff to added to number of bytes
        Throws:
        java.io.IOException - if path is not found
      • 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
      • 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
      • 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 Cversion
        zxid - Value to be assigned to Pzxid
        Throws:
        KeeperException.NoNodeException - If znode not found.