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
protected  long aclIndex
          these are the number of acls that we have in the datatree
 Map<List<org.apache.zookeeper.data.ACL>,Long> aclKeyMap
          this a map from acls to long.
 boolean initialized
           
 long lastProcessedZxid
           
 Map<Long,List<org.apache.zookeeper.data.ACL>> longKeyMap
          this is map from longs to acl's.
 
Constructor Summary
DataTree()
           
 
Method Summary
 void addDataNode(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()
           
 Long convertAcls(List<org.apache.zookeeper.data.ACL> acls)
          converts the list of acls to a list of longs.
 List<org.apache.zookeeper.data.ACL> convertLong(Long longVal)
          converts a list of longs to a list of acls.
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)
           
 String createNode(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, long ephemeralOwner, long zxid, long time)
           
 void deleteNode(String path, long zxid)
          remove the path from the datatree
 void deserialize(InputArchive ia, String tag)
           
 String dumpEphemerals()
           
 List<org.apache.zookeeper.data.ACL> getACL(String path, org.apache.zookeeper.data.Stat stat)
           
 List<String> getChildren(String path, org.apache.zookeeper.data.Stat stat, Watcher watcher)
           
 byte[] getData(String path, org.apache.zookeeper.data.Stat stat, Watcher watcher)
           
 HashSet<String> getEphemerals(long sessionId)
           
 Map<Long,HashSet<String>> getEphemeralsMap()
           
 DataNode getNode(String path)
           
 int getNodeCount()
           
 Collection<Long> getSessions()
           
 int getWatchCount()
           
 DataTree.ProcessTxnResult processTxn(org.apache.zookeeper.txn.TxnHeader header, Record txn)
           
 void removeCnxn(Watcher watcher)
           
 void serialize(OutputArchive oa, String tag)
           
 org.apache.zookeeper.data.Stat setACL(String path, List<org.apache.zookeeper.data.ACL> acl, int version)
           
 org.apache.zookeeper.data.Stat setData(String path, byte[] data, int version, long zxid, long time)
           
 void setEphemerals(Map<Long,HashSet<String>> ephemerals)
           
 void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher)
           
 org.apache.zookeeper.data.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

longKeyMap

public Map<Long,List<org.apache.zookeeper.data.ACL>> longKeyMap
this is map from longs to acl's. It saves acl's being stored for each datanode.


aclKeyMap

public Map<List<org.apache.zookeeper.data.ACL>,Long> aclKeyMap
this a map from acls to long.


aclIndex

protected long aclIndex
these are the number of acls that we have in the datatree


lastProcessedZxid

public volatile long lastProcessedZxid

initialized

public boolean initialized
Constructor Detail

DataTree

public DataTree()
Method Detail

getEphemerals

public HashSet<String> getEphemerals(long sessionId)

getEphemeralsMap

public Map<Long,HashSet<String>> getEphemeralsMap()

setEphemerals

public void setEphemerals(Map<Long,HashSet<String>> ephemerals)

convertAcls

public Long convertAcls(List<org.apache.zookeeper.data.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<org.apache.zookeeper.data.ACL> convertLong(Long longVal)
converts a list of longs to a list of acls.

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

getSessions

public Collection<Long> getSessions()

addDataNode

public void addDataNode(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(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(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(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 String createNode(String path,
                         byte[] data,
                         List<org.apache.zookeeper.data.ACL> acl,
                         long ephemeralOwner,
                         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:
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 org.apache.zookeeper.data.Stat setData(String path,
                                              byte[] data,
                                              int version,
                                              long zxid,
                                              long time)
                                       throws KeeperException.NoNodeException
Throws:
KeeperException.NoNodeException

getData

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

statNode

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

getChildren

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

setACL

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

getACL

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

processTxn

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

serialize

public void serialize(OutputArchive oa,
                      String tag)
               throws IOException
Throws:
IOException

deserialize

public void deserialize(InputArchive ia,
                        String tag)
                 throws IOException
Throws:
IOException

dumpEphemerals

public String dumpEphemerals()

removeCnxn

public void removeCnxn(Watcher watcher)

clear

public void clear()

setWatches

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