org.apache.zookeeper.server.persistence
Class FileTxnSnapLog

java.lang.Object
  extended by org.apache.zookeeper.server.persistence.FileTxnSnapLog

public class FileTxnSnapLog
extends Object

This is a helper class above the implementations of txnlog and snapshot classes


Nested Class Summary
static interface FileTxnSnapLog.PlayBackListener
          This listener helps the external apis calling restore to gather information while the data is being restored.
 
Field Summary
static String version
           
static int VERSION
           
 
Constructor Summary
FileTxnSnapLog(File dataDir, File snapDir)
          the constructor which takes the datadir and snapdir.
 
Method Summary
 boolean append(Request si)
          append the request to the transaction logs
 void close()
          close the transaction log files
 void commit()
          commit the transaction of logs
 File findMostRecentSnapshot()
          the most recent snapshot in the snapshot directory
 List<File> findNRecentSnapshots(int n)
          the n most recent snapshots
 File getDataDir()
          get the datadir used by this filetxn snap log
 long getLastLoggedZxid()
          the last logged zxid on the transaction logs
 File getSnapDir()
          get the snap dir used by this filetxn snap log
 File[] getSnapshotLogs(long zxid)
          get the snapshot logs that are greater than the given zxid
 void processTransaction(TxnHeader hdr, DataTree dt, Map<Long,Integer> sessions, org.apache.jute.Record txn)
          process the transaction on the datatree
 long restore(DataTree dt, Map<Long,Integer> sessions, FileTxnSnapLog.PlayBackListener listener)
          this function restores the server database after reading from the snapshots and transaction logs
 void rollLog()
          roll the transaction logs
 void save(DataTree dataTree, ConcurrentHashMap<Long,Integer> sessionsWithTimeouts)
          save the datatree and the sessions into a snapshot
 boolean truncateLog(long zxid)
          truncate the transaction logs the zxid specified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
See Also:
Constant Field Values

version

public static final String version
See Also:
Constant Field Values
Constructor Detail

FileTxnSnapLog

public FileTxnSnapLog(File dataDir,
                      File snapDir)
               throws IOException
the constructor which takes the datadir and snapdir.

Parameters:
dataDir - the trasaction directory
snapDir - the snapshot directory
Throws:
IOException
Method Detail

getDataDir

public File getDataDir()
get the datadir used by this filetxn snap log

Returns:
the data dir

getSnapDir

public File getSnapDir()
get the snap dir used by this filetxn snap log

Returns:
the snap dir

restore

public long restore(DataTree dt,
                    Map<Long,Integer> sessions,
                    FileTxnSnapLog.PlayBackListener listener)
             throws IOException
this function restores the server database after reading from the snapshots and transaction logs

Parameters:
dt - the datatree to be restored
sessions - the sessions to be restored
listener - the playback listener to run on the database restoration
Returns:
the highest zxid restored
Throws:
IOException

processTransaction

public void processTransaction(TxnHeader hdr,
                               DataTree dt,
                               Map<Long,Integer> sessions,
                               org.apache.jute.Record txn)
                        throws KeeperException.NoNodeException
process the transaction on the datatree

Parameters:
hdr - the hdr of the transaction
dt - the datatree to apply transaction to
sessions - the sessions to be restored
txn - the transaction to be applied
Throws:
KeeperException.NoNodeException

getLastLoggedZxid

public long getLastLoggedZxid()
the last logged zxid on the transaction logs

Returns:
the last logged zxid

save

public void save(DataTree dataTree,
                 ConcurrentHashMap<Long,Integer> sessionsWithTimeouts)
          throws IOException
save the datatree and the sessions into a snapshot

Parameters:
dataTree - the datatree to be serialized onto disk
sessionsWithTimeouts - the sesssion timeouts to be serialized onto disk
Throws:
IOException

truncateLog

public boolean truncateLog(long zxid)
                    throws IOException
truncate the transaction logs the zxid specified

Parameters:
zxid - the zxid to truncate the logs to
Returns:
true if able to truncate the log, false if not
Throws:
IOException

findMostRecentSnapshot

public File findMostRecentSnapshot()
                            throws IOException
the most recent snapshot in the snapshot directory

Returns:
the file that contains the most recent snapshot
Throws:
IOException

findNRecentSnapshots

public List<File> findNRecentSnapshots(int n)
                                throws IOException
the n most recent snapshots

Parameters:
n - the number of recent snapshots
Returns:
the list of n most recent snapshots, with the most recent in front
Throws:
IOException

getSnapshotLogs

public File[] getSnapshotLogs(long zxid)
get the snapshot logs that are greater than the given zxid

Parameters:
zxid - the zxid that contains logs greater than zxid
Returns:

append

public boolean append(Request si)
               throws IOException
append the request to the transaction logs

Parameters:
si - the request to be appended returns true iff something appended, otw false
Throws:
IOException

commit

public void commit()
            throws IOException
commit the transaction of logs

Throws:
IOException

rollLog

public void rollLog()
             throws IOException
roll the transaction logs

Throws:
IOException

close

public void close()
           throws IOException
close the transaction log files

Throws:
IOException


Copyright © 2011 The Apache Software Foundation