public class FileTxnLog extends Object implements TxnLog, Closeable
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)
| Modifier and Type | Class and Description |
|---|---|
static class |
FileTxnLog.FileTxnIterator
this class implements the txnlog iterator interface
which is used for reading the transaction logs
|
TxnLog.TxnIterator| Modifier and Type | Field and Description |
|---|---|
static String |
LOG_FILE_PREFIX |
static int |
TXNLOG_MAGIC |
static int |
VERSION |
| Constructor and Description |
|---|
FileTxnLog(File logDir)
constructor for FileTxnLog.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
append(TxnHeader hdr,
Record txn)
append an entry to the transaction log
|
boolean |
append(TxnHeader hdr,
Record txn,
TxnDigest digest)
Append a request to the transaction log with a digset
|
void |
close()
close all the open file handles
|
void |
commit()
commit the logs.
|
long |
getCurrentLogSize()
Return the current on-disk size of log size.
|
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.
|
long |
getTotalLogSize()
Gets the total size of all log files
|
long |
getTxnLogSyncElapsedTime() |
boolean |
isForceSync()
the forceSync value.
|
protected Checksum |
makeChecksumAlgorithm()
creates a checksum algorithm to be used
|
TxnLog.TxnIterator |
read(long zxid)
start reading all the transactions from the given zxid
|
TxnLog.TxnIterator |
read(long zxid,
boolean fastForward)
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.
|
void |
setServerStats(ServerStats serverStats)
Setter for ServerStats to monitor fsync threshold exceed
|
void |
setTotalLogSize(long size)
Sets the total size of all log files
|
static void |
setTxnLogSizeLimit(long size)
Set log size limit
|
boolean |
truncate(long zxid)
truncate the current transaction logs
|
public static final int TXNLOG_MAGIC
public static final int VERSION
public static final String LOG_FILE_PREFIX
public FileTxnLog(File logDir)
logDir - the directory where the txnlogs are storedpublic static void setPreallocSize(long size)
size - the size to set to in bytespublic void setServerStats(ServerStats serverStats)
setServerStats in interface TxnLogserverStats - used to update fsyncThresholdExceedCountpublic static void setTxnLogSizeLimit(long size)
public long getCurrentLogSize()
public void setTotalLogSize(long size)
TxnLogsetTotalLogSize in interface TxnLogpublic long getTotalLogSize()
TxnLoggetTotalLogSize in interface TxnLogprotected Checksum makeChecksumAlgorithm()
public void rollLog()
throws IOException
rollLog in interface TxnLogIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface TxnLogIOExceptionpublic boolean append(TxnHeader hdr, Record txn) throws IOException
append in interface TxnLoghdr - the header of the transactiontxn - the transaction part of the entry
returns true iff something appended, otw falseIOExceptionpublic boolean append(TxnHeader hdr, Record txn, TxnDigest digest) throws IOException
TxnLogappend in interface TxnLoghdr - the transaction headertxn - the transaction itselfdigest - transaction digest
returns true iff something appended, otw falseIOExceptionpublic static File[] getLogFiles(File[] logDirList, long snapshotZxid)
logDirList - array of filessnapshotZxid - return files at, or before this zxidpublic long getLastLoggedZxid()
getLastLoggedZxid in interface TxnLogpublic void commit()
throws IOException
commit in interface TxnLogIOExceptionpublic long getTxnLogSyncElapsedTime()
getTxnLogSyncElapsedTime in interface TxnLogpublic TxnLog.TxnIterator read(long zxid) throws IOException
read in interface TxnLogzxid - the zxid to start reading transactions fromIOExceptionpublic TxnLog.TxnIterator read(long zxid, boolean fastForward) throws IOException
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 zxidIOExceptionpublic boolean truncate(long zxid)
throws IOException
truncate in interface TxnLogzxid - the zxid to truncate the logs toIOExceptionpublic long getDbId()
throws IOException
getDbId in interface TxnLogIOExceptionpublic boolean isForceSync()
Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.