org.apache.zookeeper.server
Class DataTree

java.lang.Object
  extended by 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 Summary
static class DataTree.ProcessTxnResult
           
 
Field Summary
 long lastProcessedZxid
           
 
Constructor Summary
DataTree()
           
 
Method Summary
 long approximateDataSize()
          Get the size of the nodes based on path and data length.
 Long convertAcls(List<ACL> acls)
          converts the list of acls to a list of longs.
 List<ACL> convertLong(Long longVal)
          converts a list of longs to a list of acls.
static void copyStat(Stat from, Stat to)
           
static void copyStatPersisted(StatPersisted from, StatPersisted to)
           
 void createNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time)
           
 void deleteNode(String path, long zxid)
          remove the path from the datatree
 void deserialize(org.apache.jute.InputArchive ia, String tag)
           
 void dumpEphemerals(PrintWriter pwriter)
          Write a text dump of all the ephemerals in the datatree.
 void dumpWatches(PrintWriter pwriter, boolean byPath)
          Write a text dump of all the watches on the datatree.
 void dumpWatchesSummary(PrintWriter pwriter)
          Summary of the watches on the datatree.
 List<ACL> getACL(String path, Stat stat)
           
 List<String> getChildren(String path, Stat stat, Watcher watcher)
           
 byte[] getData(String path, Stat stat, Watcher watcher)
           
 Set<String> getEphemerals(long sessionId)
           
 String getMaxPrefixWithQuota(String path)
          If there is a quota set, return the appropriate prefix for that quota Else return null
 DataNode getNode(String path)
           
 int getNodeCount()
           
 Collection<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, String tag)
           
 Stat setACL(String path, List<ACL> acl, int version)
           
 void setCversionPzxid(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(String path, byte[] data, int version, long zxid, long time)
           
 void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher)
           
 Stat statNode(String path, Watcher watcher)
           
 void updateBytes(String lastPrefix, long diff)
          update the count of bytes of this stat datanode
 void updateCount(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 Set<String> getEphemerals(long sessionId)

convertAcls

public Long convertAcls(List<ACL> acls)
converts the list of acls to a list of longs.

Parameters:
acls -
Returns:
a list of longs that map to the acls

convertLong

public List<ACL> convertLong(Long longVal)
converts a list of longs to a list of acls.

Parameters:
longVal - the list of longs
Returns:
a list of ACLs that map to longs

getSessions

public Collection<Long> getSessions()

getNode

public DataNode getNode(String path)

getNodeCount

public int getNodeCount()

getWatchCount

public int getWatchCount()

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)

copyStat

public static void copyStat(Stat from,
                            Stat to)

updateCount

public void updateCount(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(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:
IOException - if path is not found

createNode

public void createNode(String path,
                       byte[] data,
                       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 -
Throws:
KeeperException
KeeperException.NoNodeException
KeeperException.NodeExistsException

deleteNode

public 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

setData

public Stat setData(String path,
                    byte[] data,
                    int version,
                    long zxid,
                    long time)
             throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

getMaxPrefixWithQuota

public 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

getData

public byte[] getData(String path,
                      Stat stat,
                      Watcher watcher)
               throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

statNode

public Stat statNode(String path,
                     Watcher watcher)
              throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

getChildren

public List<String> getChildren(String path,
                                Stat stat,
                                Watcher watcher)
                         throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

setACL

public Stat setACL(String path,
                   List<ACL> acl,
                   int version)
            throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

getACL

public List<ACL> getACL(String path,
                        Stat stat)
                 throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

processTxn

public DataTree.ProcessTxnResult processTxn(TxnHeader header,
                                            org.apache.jute.Record txn)

serialize

public void serialize(org.apache.jute.OutputArchive oa,
                      String tag)
               throws IOException
Throws:
IOException

deserialize

public void deserialize(org.apache.jute.InputArchive ia,
                        String tag)
                 throws IOException
Throws:
IOException

dumpWatchesSummary

public void dumpWatchesSummary(PrintWriter pwriter)
Summary of the watches on the datatree.

Parameters:
pwriter - the output to write to

dumpWatches

public 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

dumpEphemerals

public void dumpEphemerals(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)

setWatches

public void setWatches(long relativeZxid,
                       List<String> dataWatches,
                       List<String> existWatches,
                       List<String> childWatches,
                       Watcher watcher)

setCversionPzxid

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


Copyright © 2011 The Apache Software Foundation