Class FileTxnLog
- java.lang.Object
-
- org.apache.zookeeper.server.persistence.FileTxnLog
-
- All Implemented Interfaces:
TxnLog
public class FileTxnLog extends java.lang.Object implements TxnLog
This class implements the TxnLog interface. It provides api's to access the txnlogs and add entries to it.The format of a Transactional log is as follows:
LogFile: FileHeader TxnList ZeroPad FileHeader: { magic 4bytes (ZKLG) version 4bytes dbid 8bytes } TxnList: Txn || Txn TxnList Txn: checksum Txnlen TxnHeader Record 0x42 checksum: 8bytes Adler32 is currently used calculated across payload -- Txnlen, TxnHeader, Record and 0x42 Txnlen: len 4bytes TxnHeader: { sessionid 8bytes cxid 4bytes zxid 8bytes time 8bytes type 4bytes } Record: See Jute definition file for details on the various record types ZeroPad: 0 padded to EOF (filled during preallocation stage)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileTxnLog.FileTxnIteratorthis 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
Fields Modifier and Type Field Description static java.lang.StringLOG_FILE_PREFIXstatic intTXNLOG_MAGICstatic intVERSION
-
Constructor Summary
Constructors Constructor Description FileTxnLog(java.io.File logDir)constructor for FileTxnLog.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanappend(TxnHeader hdr, org.apache.jute.Record txn)append an entry to the transaction logvoidclose()close all the open file handlesvoidcommit()commit the logs.longgetDbId()the dbid of this transaction databaselonggetLastLoggedZxid()get the last zxid that was logged in the transaction logsstatic java.io.File[]getLogFiles(java.io.File[] logDirList, long snapshotZxid)Find the log file that starts at, or just before, the snapshot.booleanisForceSync()the forceSync value.protected java.util.zip.ChecksummakeChecksumAlgorithm()creates a checksum algorithm to be usedTxnLog.TxnIteratorread(long zxid)start reading all the transactions from the given zxidvoidrollLog()rollover the current log file to a new one.static voidsetPreallocSize(long size)method to allow setting preallocate size of log file to pad the file.voidsetServerStats(ServerStats serverStats)Setter for ServerStats to monitor fsync threshold exceedbooleantruncate(long zxid)truncate the current transaction logs
-
-
-
Field Detail
-
TXNLOG_MAGIC
public static final int TXNLOG_MAGIC
-
VERSION
public static final int VERSION
- See Also:
- Constant Field Values
-
LOG_FILE_PREFIX
public static final java.lang.String LOG_FILE_PREFIX
- See Also:
- Constant Field Values
-
-
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
-
setServerStats
public void setServerStats(ServerStats serverStats)
Setter for ServerStats to monitor fsync threshold exceed- Specified by:
setServerStatsin interfaceTxnLog- Parameters:
serverStats- used to update fsyncThresholdExceedCount
-
makeChecksumAlgorithm
protected java.util.zip.Checksum makeChecksumAlgorithm()
creates a checksum algorithm to be used- Returns:
- the checksum used for this txnlog
-
rollLog
public void rollLog() throws java.io.IOExceptionrollover the current log file to a new one.
-
close
public void close() throws java.io.IOExceptionclose all the open file handles
-
append
public boolean append(TxnHeader hdr, org.apache.jute.Record txn) throws java.io.IOException
append an entry to the transaction log
-
getLogFiles
public static java.io.File[] getLogFiles(java.io.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 filessnapshotZxid- 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:
getLastLoggedZxidin interfaceTxnLog- Returns:
- the last zxid logged in the transaction logs
-
commit
public void commit() throws java.io.IOExceptioncommit the logs. make sure that evertyhing hits the disk
-
read
public TxnLog.TxnIterator read(long zxid) throws java.io.IOException
start reading all the transactions from the given zxid
-
truncate
public boolean truncate(long zxid) throws java.io.IOExceptiontruncate the current transaction logs
-
getDbId
public long getDbId() throws java.io.IOExceptionthe dbid of this transaction database
-
isForceSync
public boolean isForceSync()
the forceSync value. true if forceSync is enabled, false otherwise.- Returns:
- the forceSync value
-
-