org.apache.zookeeper.server.persistence
Class FileTxnLog

java.lang.Object
  extended by org.apache.zookeeper.server.persistence.FileTxnLog
All Implemented Interfaces:
TxnLog

public class FileTxnLog
extends Object
implements TxnLog

This class implements the TxnLog interface. It provides api's to access the txnlogs and add entries to it.


Nested Class Summary
static class FileTxnLog.FileTxnIterator
          this class implements the txnlog iterator interface which is used for reading the transaction logs
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.server.persistence.TxnLog
TxnLog.TxnIterator
 
Field Summary
static int TXNLOG_MAGIC
           
static int VERSION
           
 
Constructor Summary
FileTxnLog(File logDir)
          constructor for FileTxnLog.
 
Method Summary
 void append(org.apache.zookeeper.txn.TxnHeader hdr, Record txn)
          append an entry to the transaction log
 void commit()
          commit the logs.
 long getDbId()
          the dbid of this transaction database
 long getLastLoggedZxid()
          get the last zxid that was logged in the transaction logs
static File[] getLogFiles(File[] logDirList, long snapshotZxid)
          Find the log file that starts at, or just before, the snapshot.
protected  Checksum makeChecksumAlgorithm()
          creates a checksum alogrithm to be used
 TxnLog.TxnIterator read(long zxid)
          start reading all the transactions from the given zxid
 void rollLog()
          rollover the current log file to a new one.
static void setPreallocSize(long size)
          method to allow setting preallocate size of log file to pad the file.
 boolean truncate(long zxid)
          truncate the current transaction logs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TXNLOG_MAGIC

public static final int TXNLOG_MAGIC

VERSION

public static final int VERSION
See Also:
Constant Field Values
Constructor Detail

FileTxnLog

public FileTxnLog(File logDir)
constructor for FileTxnLog. Take the directory where the txnlogs are stored

Parameters:
logDir - the directory where the txnlogs are stored
Method Detail

setPreallocSize

public static void setPreallocSize(long size)
method to allow setting preallocate size of log file to pad the file.

Parameters:
size - the size to set to in bytes

makeChecksumAlgorithm

protected Checksum makeChecksumAlgorithm()
creates a checksum alogrithm to be used

Returns:
the checksum used for this txnlog

rollLog

public void rollLog()
             throws IOException
rollover the current log file to a new one.

Specified by:
rollLog in interface TxnLog
Throws:
IOException

append

public void append(org.apache.zookeeper.txn.TxnHeader hdr,
                   Record txn)
            throws IOException
append an entry to the transaction log

Specified by:
append in interface TxnLog
Parameters:
hdr - the header of the transaction
txn - the transaction part of the entry
Throws:
IOException

getLogFiles

public static File[] getLogFiles(File[] logDirList,
                                 long snapshotZxid)
Find the log file that starts at, or just before, the snapshot. Return this and all subsequent logs. Results are ordered by zxid of file, ascending order.

Parameters:
logDirList - array of files
snapshotZxid - return files at, or before this zxid
Returns:

getLastLoggedZxid

public long getLastLoggedZxid()
get the last zxid that was logged in the transaction logs

Specified by:
getLastLoggedZxid in interface TxnLog
Returns:
the last zxid logged in the transaction logs

commit

public void commit()
            throws IOException
commit the logs. make sure that evertyhing hits the disk

Specified by:
commit in interface TxnLog
Throws:
IOException

read

public TxnLog.TxnIterator read(long zxid)
                        throws IOException
start reading all the transactions from the given zxid

Specified by:
read in interface TxnLog
Parameters:
zxid - the zxid to start reading transactions from
Returns:
returns an iterator to iterate through the transaction logs
Throws:
IOException

truncate

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

Specified by:
truncate in interface TxnLog
Parameters:
zxid - the zxid to truncate the logs to
Returns:
true if successful false if not
Throws:
IOException

getDbId

public long getDbId()
             throws IOException
the dbid of this transaction database

Specified by:
getDbId in interface TxnLog
Returns:
the dbid of this database
Throws:
IOException