org.apache.zookeeper.server
Class ZKDatabase

java.lang.Object
  extended by org.apache.zookeeper.server.ZKDatabase

public class ZKDatabase
extends Object

This class maintains the in memory database of zookeeper server states that includes the sessions, datatree and the committed logs. It is booted up after reading the logs and snapshots from the disk.


Field Summary
protected static int commitLogBuffer
           
static int commitLogCount
           
protected  LinkedList<Leader.Proposal> committedLog
           
protected  DataTree dataTree
          make sure on a clear you take care of all these members.
protected  ReentrantReadWriteLock logLock
           
protected  long maxCommittedLog
           
protected  long minCommittedLog
           
protected  ConcurrentHashMap<Long,Integer> sessionsWithTimeouts
           
protected  FileTxnSnapLog snapLog
           
 
Constructor Summary
ZKDatabase(FileTxnSnapLog snapLog)
          the filetxnsnaplog that this zk database maps to.
 
Method Summary
 void addCommittedProposal(Request request)
          maintains a list of last committedLog or so committed requests.
 boolean append(Request si)
          append to the underlying transaction log
 void clear()
          clear the zkdatabase.
 void close()
          close this database.
 void commit()
          commit to the underlying transaction log
 List<ACL> convertLong(Long aclL)
          convert from long to the acl entry
 void deserializeSnapshot(org.apache.jute.InputArchive ia)
          deserialize a snapshot from an input archive
 void dumpEphemerals(PrintWriter pwriter)
          write a text dump of all the ephemerals in the datatree
 List<ACL> getACL(String path, Stat stat)
          get acl for a path
 int getAclSize()
          get the acl size of the datatree
 List<String> getChildren(String path, Stat stat, Watcher watcher)
          get children list for this path
 List<Leader.Proposal> getCommittedLog()
           
 byte[] getData(String path, Stat stat, Watcher watcher)
          get data and stat for a path
 DataTree getDataTree()
          the datatree for this zkdatabase
 long getDataTreeLastProcessedZxid()
          get the last processed zxid from a datatree
 Set<String> getEphemerals(long sessionId)
          the paths for ephemeral session id
 ReentrantReadWriteLock getLogLock()
          Get the lock that controls the committedLog.
 long getmaxCommittedLog()
          the committed log for this zk database
 long getminCommittedLog()
          the minimum committed transaction log available in memory
 DataNode getNode(String path)
          get the datanode for this path
 int getNodeCount()
          the node count of the datatree
 Collection<Long> getSessions()
          return the sessions in the datatree
 ConcurrentHashMap<Long,Integer> getSessionWithTimeOuts()
          get sessions with timeouts
 boolean isInitialized()
          checks to see if the zk database has been initialized or not.
 boolean isSpecialPath(String path)
          check if the path is special or not
 void killSession(long sessionId, long zxid)
          kill a given session in the datatree
 long loadDataBase()
          load the database from the disk onto memory and also add the transactions to the committedlog in memory.
 DataTree.ProcessTxnResult processTxn(TxnHeader hdr, org.apache.jute.Record txn)
          the process txn on the data
 void removeCnxn(ServerCnxn cnxn)
          remove a cnxn from the datatree
 void rollLog()
          roll the underlying log
 void serializeSnapshot(org.apache.jute.OutputArchive oa)
          serialize the snapshot
 void setlastProcessedZxid(long zxid)
          the last processed zxid in the datatree
 void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher)
          set watches on the datatree
 Stat statNode(String path, ServerCnxn serverCnxn)
          stat the path
 boolean truncateLog(long zxid)
          truncate the zkdatabase to this zxid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataTree

protected DataTree dataTree
make sure on a clear you take care of all these members.


sessionsWithTimeouts

protected ConcurrentHashMap<Long,Integer> sessionsWithTimeouts

snapLog

protected FileTxnSnapLog snapLog

minCommittedLog

protected long minCommittedLog

maxCommittedLog

protected long maxCommittedLog

commitLogCount

public static final int commitLogCount
See Also:
Constant Field Values

commitLogBuffer

protected static int commitLogBuffer

committedLog

protected LinkedList<Leader.Proposal> committedLog

logLock

protected ReentrantReadWriteLock logLock
Constructor Detail

ZKDatabase

public ZKDatabase(FileTxnSnapLog snapLog)
the filetxnsnaplog that this zk database maps to. There is a one to one relationship between a filetxnsnaplog and zkdatabase.

Parameters:
snapLog - the FileTxnSnapLog mapping this zkdatabase
Method Detail

isInitialized

public boolean isInitialized()
checks to see if the zk database has been initialized or not.

Returns:
true if zk database is initialized and false if not

clear

public void clear()
clear the zkdatabase. Note to developers - be careful to see that the clear method does clear out all the data structures in zkdatabase.


getDataTree

public DataTree getDataTree()
the datatree for this zkdatabase

Returns:
the datatree for this zkdatabase

getmaxCommittedLog

public long getmaxCommittedLog()
the committed log for this zk database

Returns:
the committed log for this zkdatabase

getminCommittedLog

public long getminCommittedLog()
the minimum committed transaction log available in memory

Returns:
the minimum committed transaction log available in memory

getLogLock

public ReentrantReadWriteLock getLogLock()
Get the lock that controls the committedLog. If you want to get the pointer to the committedLog, you need to use this lock to acquire a read lock before calling getCommittedLog()

Returns:
the lock that controls the committed log

getCommittedLog

public List<Leader.Proposal> getCommittedLog()

getDataTreeLastProcessedZxid

public long getDataTreeLastProcessedZxid()
get the last processed zxid from a datatree

Returns:
the last processed zxid of a datatree

getSessions

public Collection<Long> getSessions()
return the sessions in the datatree

Returns:
the data tree sessions

getSessionWithTimeOuts

public ConcurrentHashMap<Long,Integer> getSessionWithTimeOuts()
get sessions with timeouts

Returns:
the hashmap of sessions with timeouts

loadDataBase

public long loadDataBase()
                  throws IOException
load the database from the disk onto memory and also add the transactions to the committedlog in memory.

Returns:
the last valid zxid on disk
Throws:
IOException

addCommittedProposal

public void addCommittedProposal(Request request)
maintains a list of last committedLog or so committed requests. This is used for fast follower synchronization.

Parameters:
request - committed request

removeCnxn

public void removeCnxn(ServerCnxn cnxn)
remove a cnxn from the datatree

Parameters:
cnxn - the cnxn to remove from the datatree

killSession

public void killSession(long sessionId,
                        long zxid)
kill a given session in the datatree

Parameters:
sessionId - the session id to be killed
zxid - the zxid of kill session transaction

dumpEphemerals

public void dumpEphemerals(PrintWriter pwriter)
write a text dump of all the ephemerals in the datatree

Parameters:
pwriter - the output to write to

getNodeCount

public int getNodeCount()
the node count of the datatree

Returns:
the node count of datatree

getEphemerals

public Set<String> getEphemerals(long sessionId)
the paths for ephemeral session id

Parameters:
sessionId - the session id for which paths match to
Returns:
the paths for a session id

setlastProcessedZxid

public void setlastProcessedZxid(long zxid)
the last processed zxid in the datatree

Parameters:
zxid - the last processed zxid in the datatree

processTxn

public DataTree.ProcessTxnResult processTxn(TxnHeader hdr,
                                            org.apache.jute.Record txn)
the process txn on the data

Parameters:
hdr - the txnheader for the txn
txn - the transaction that needs to be processed
Returns:
the result of processing the transaction on this datatree/zkdatabase

statNode

public Stat statNode(String path,
                     ServerCnxn serverCnxn)
              throws KeeperException.NoNodeException
stat the path

Parameters:
path - the path for which stat is to be done
serverCnxn - the servercnxn attached to this request
Returns:
the stat of this node
Throws:
KeeperException.NoNodeException

getNode

public DataNode getNode(String path)
get the datanode for this path

Parameters:
path - the path to lookup
Returns:
the datanode for getting the path

convertLong

public List<ACL> convertLong(Long aclL)
convert from long to the acl entry

Parameters:
aclL - the long for which to get the acl
Returns:
the acl corresponding to this long entry

getData

public byte[] getData(String path,
                      Stat stat,
                      Watcher watcher)
               throws KeeperException.NoNodeException
get data and stat for a path

Parameters:
path - the path being queried
stat - the stat for this path
watcher - the watcher function
Returns:
Throws:
KeeperException.NoNodeException

setWatches

public void setWatches(long relativeZxid,
                       List<String> dataWatches,
                       List<String> existWatches,
                       List<String> childWatches,
                       Watcher watcher)
set watches on the datatree

Parameters:
relativeZxid - the relative zxid that client has seen
dataWatches - the data watches the client wants to reset
existWatches - the exists watches the client wants to reset
childWatches - the child watches the client wants to reset
watcher - the watcher function

getACL

public List<ACL> getACL(String path,
                        Stat stat)
                 throws KeeperException.NoNodeException
get acl for a path

Parameters:
path - the path to query for acl
stat - the stat for the node
Returns:
the acl list for this path
Throws:
KeeperException.NoNodeException

getChildren

public List<String> getChildren(String path,
                                Stat stat,
                                Watcher watcher)
                         throws KeeperException.NoNodeException
get children list for this path

Parameters:
path - the path of the node
stat - the stat of the node
watcher - the watcher function for this path
Returns:
the list of children for this path
Throws:
KeeperException.NoNodeException

isSpecialPath

public boolean isSpecialPath(String path)
check if the path is special or not

Parameters:
path - the input path
Returns:
true if path is special and false if not

getAclSize

public int getAclSize()
get the acl size of the datatree

Returns:
the acl size of the datatree

truncateLog

public boolean truncateLog(long zxid)
                    throws IOException
truncate the zkdatabase to this zxid

Parameters:
zxid - the zxid to truncate zk database to
Returns:
true if the truncate is succesful and false if not
Throws:
IOException

deserializeSnapshot

public void deserializeSnapshot(org.apache.jute.InputArchive ia)
                         throws IOException
deserialize a snapshot from an input archive

Parameters:
ia - the input archive you want to deserialize from
Throws:
IOException

serializeSnapshot

public void serializeSnapshot(org.apache.jute.OutputArchive oa)
                       throws IOException,
                              InterruptedException
serialize the snapshot

Parameters:
oa - the output archive to which the snapshot needs to be serialized
Throws:
IOException
InterruptedException

append

public boolean append(Request si)
               throws IOException
append to the underlying transaction log

Parameters:
si - the request to append
Returns:
true if the append was succesfull and false if not
Throws:
IOException

rollLog

public void rollLog()
             throws IOException
roll the underlying log

Throws:
IOException

commit

public void commit()
            throws IOException
commit to the underlying transaction log

Throws:
IOException

close

public void close()
           throws IOException
close this database. free the resources

Throws:
IOException


Copyright © 2011 The Apache Software Foundation