Class FileTxnLog
java.lang.Object
org.apache.zookeeper.server.persistence.FileTxnLog
- All Implemented Interfaces:
Closeable,AutoCloseable,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 ClassesModifier and TypeClassDescriptionstatic classthis class implements the txnlog iterator interface which is used for reading the transaction logsNested classes/interfaces inherited from interface org.apache.zookeeper.server.persistence.TxnLog
TxnLog.TxnIterator -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAppend a request to the transaction log with a digsetvoidclose()close all the open file handlesvoidcommit()commit the logs.longReturn the current on-disk size of log size.longgetDbId()the dbid of this transaction databaselongget the last zxid that was logged in the transaction logsstatic File[]getLogFiles(File[] logDirList, long snapshotZxid) Find the log file that starts at, or just before, the snapshot.longGets the total size of all log fileslongbooleanthe forceSync value.protected Checksumcreates a checksum algorithm to be usedread(long zxid) start reading all the transactions from the given zxidread(long zxid, boolean fastForward) start reading all the transactions from the given zxid.voidrollLog()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 exceedvoidsetTotalLogSize(long size) Sets the total size of all log filesstatic voidsetTxnLogSizeLimit(long size) Set log size limitbooleantruncate(long zxid) truncate the current transaction logs
-
Field Details
-
TXNLOG_MAGIC
public static final int TXNLOG_MAGIC -
VERSION
public static final int VERSION- See Also:
-
LOG_FILE_PREFIX
- See Also:
-
-
Constructor Details
-
FileTxnLog
constructor for FileTxnLog. Take the directory where the txnlogs are stored- Parameters:
logDir- the directory where the txnlogs are stored
-
-
Method Details
-
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
Setter for ServerStats to monitor fsync threshold exceed- Specified by:
setServerStatsin interfaceTxnLog- Parameters:
serverStats- used to update fsyncThresholdExceedCount
-
setTxnLogSizeLimit
public static void setTxnLogSizeLimit(long size) Set log size limit -
getCurrentLogSize
public long getCurrentLogSize()Return the current on-disk size of log size. This will be accurate only after commit() is called. Otherwise, unflushed txns may not be included. -
setTotalLogSize
public void setTotalLogSize(long size) Description copied from interface:TxnLogSets the total size of all log files- Specified by:
setTotalLogSizein interfaceTxnLog
-
getTotalLogSize
public long getTotalLogSize()Description copied from interface:TxnLogGets the total size of all log files- Specified by:
getTotalLogSizein interfaceTxnLog
-
makeChecksumAlgorithm
creates a checksum algorithm to be used- Returns:
- the checksum used for this txnlog
-
rollLog
rollover the current log file to a new one.- Specified by:
rollLogin interfaceTxnLog- Throws:
IOException
-
close
close all the open file handles- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceTxnLog- Throws:
IOException
-
append
Description copied from interface:TxnLogAppend a request to the transaction log with a digset- Specified by:
appendin interfaceTxnLog- Parameters:
request- the request to be appended returns true iff something appended, otw false- Throws:
IOException
-
getLogFiles
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:
- log files that starts at, or just before, the snapshot and subsequent ones
-
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
commit the logs. make sure that everything hits the disk- Specified by:
commitin interfaceTxnLog- Throws:
IOException
-
getTxnLogSyncElapsedTime
public long getTxnLogSyncElapsedTime()- Specified by:
getTxnLogSyncElapsedTimein interfaceTxnLog- Returns:
- elapsed sync time of transaction log in milliseconds
-
read
start reading all the transactions from the given zxid- Specified by:
readin interfaceTxnLog- Parameters:
zxid- the zxid to start reading transactions from- Returns:
- returns an iterator to iterate through the transaction logs
- Throws:
IOException
-
read
start reading all the transactions from the given zxid.- Parameters:
zxid- the zxid to start reading transactions fromfastForward- true if the iterator should be fast forwarded to point to the txn of a given zxid, else the iterator will point to the starting txn of a txnlog that may contain txn of a given zxid- Returns:
- returns an iterator to iterate through the transaction logs
- Throws:
IOException
-
truncate
truncate the current transaction logs- Specified by:
truncatein interfaceTxnLog- Parameters:
zxid- the zxid to truncate the logs to- Returns:
- true if successful false if not
- Throws:
IOException
-
getDbId
the dbid of this transaction database- Specified by:
getDbIdin interfaceTxnLog- Returns:
- the dbid of this database
- Throws:
IOException
-
isForceSync
public boolean isForceSync()the forceSync value. true if forceSync is enabled, false otherwise.- Returns:
- the forceSync value
-