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 addDataNode​(java.lang.String path, DataNode node)
      just an accessor method to allow raw creation of datatree's from a bunch of datanodes
      long approximateDataSize()
      Get the size of the nodes based on path and data length.
      void clear()  
      static void copyStat​(Stat from, Stat to)  
      static void copyStatPersisted​(StatPersisted from, StatPersisted to)  
      java.lang.String createNode​(java.lang.String path, byte[] data, java.util.List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time)  
      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<ACL> getACL​(java.lang.String path, Stat stat)  
      java.util.List<ACL> getACL​(DataNode node)  
      java.lang.Long getACL​(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)  
      int getEphemeralsCount()  
      java.util.Map<java.lang.Long,​java.util.HashSet<java.lang.String>> getEphemeralsMap()  
      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()  
      java.util.Collection<java.lang.Long> getSessions()  
      int getWatchCount()  
      DataTree.ProcessTxnResult processTxn​(TxnHeader header, org.apache.jute.Record txn)  
      void removeCnxn​(Watcher watcher)  
      void serialize​(org.apache.jute.OutputArchive oa, java.lang.String tag)  
      Stat setACL​(java.lang.String path, java.util.List<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.
      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)  
      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
      • initialized

        public boolean initialized
    • Constructor Detail

      • DataTree

        public DataTree()
    • 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 datanode
        node - 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
      • copyStat

        public static void copyStat​(Stat from,
                                    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<ACL> getACL​(DataNode node)
      • getACL

        public java.lang.Long getACL​(DataNodeV1 oldDataNode)
      • aclCacheSize

        public int aclCacheSize()
      • 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.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.