|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbitronix.tm.journal.TransactionLogRecord
public class TransactionLogRecord
Representation of a transaction log record on disk.
On-disk format has been implemented following Mike Spille's recommendations. Quoting him:
[RECORD_TYPE :4] [RECORD_LEN :4] [HEADER_LEN :4] [System.currentTimeMillis :8] [Sequence number :4]
[Checksum :4] [Payload :X] [END_RECORD_INDICATOR :4]
Where [RECORD_TYPE] is a passed-in record type from the TM. [RECORD_LEN] is the overall record length (sans [RECORD_TYPE and [RECORD_LEN]). [HEADER_LEN] is the length of the remainder of the header - important if you want to support easy upgrades of your format. The remaining pieces are the rest of the header, and the payload. The header at least should have [System.currentTimeMillis] and [Sequence number], with the [sequence number] coming from some monotically increasing sequence generator unique to the process. The [checksum] is optional for the paranoid among us. The time information can be very useful for profiling and tracking down problems in production, and in conjunction with the sequence number it can give you precise ordering. This doesn't give you much in this solution, but can be priceless if you ever move to a system with multiple dual log file pairs to lessen single-threading on a single log file pair. Finally, I like having an [END_RECORD_INDICATOR] as an extra corruption detector device - I'm a suspenders and belt kind of guy. Actually, the END_RECORD_INDICATOR and [RECORD_LEN] in conjunction are very useful in development, as well, to catch programming mistakes in the log system early.
Payload contains [GTRID LENGTH :1] [GTRID :A] [UNIQUE NAMES COUNT :4] ([UNIQUE NAME LENGTH :2] [UNIQUE NAME :Y] ...)
which makes a major difference with Mike's proposed format because here a record can vary in length: the GTRID size
is A bytes long (A being the GTRID length) and there can be X unique names that are Y characters long, Y being eventually
different for each name.
Constructor Summary | |
---|---|
TransactionLogRecord(int status,
int recordLength,
int headerLength,
long time,
int sequenceNumber,
int crc32,
Uid gtrid,
Set<String> uniqueNames,
int endRecord)
Use this constructor when restoring a log from the disk. |
|
TransactionLogRecord(int status,
Uid gtrid,
Set<String> uniqueNames)
Create a new transaction log ready to be stored. |
Method Summary | |
---|---|
int |
calculateCrc32()
Calculate the CRC32 value of this record. |
int |
getCrc32()
|
int |
getEndRecord()
|
Uid |
getGtrid()
|
int |
getHeaderLength()
|
int |
getRecordLength()
|
int |
getSequenceNumber()
|
int |
getStatus()
|
long |
getTime()
|
Set<String> |
getUniqueNames()
|
boolean |
isCrc32Correct()
Recalculate the CRC32 value of this record (using calculateCrc32() ) and compare it with the stored value. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TransactionLogRecord(int status, int recordLength, int headerLength, long time, int sequenceNumber, int crc32, Uid gtrid, Set<String> uniqueNames, int endRecord)
status
- record typerecordLength
- record length excluding status and recordLengthheaderLength
- length of all fields except gtrid, uniqueNames and endRecordtime
- current time in millisecondssequenceNumber
- atomically generated sequence number during a JVM's lifespancrc32
- checksum of the full recordgtrid
- global transaction iduniqueNames
- unique names of XA data sources used in this transactionendRecord
- end of record markerpublic TransactionLogRecord(int status, Uid gtrid, Set<String> uniqueNames)
status
- record typegtrid
- global transaction iduniqueNames
- unique names of XA data sources used in this transactionMethod Detail |
---|
public int getStatus()
public int getRecordLength()
public int getHeaderLength()
public long getTime()
public int getSequenceNumber()
public int getCrc32()
public Uid getGtrid()
public Set<String> getUniqueNames()
public int getEndRecord()
public boolean isCrc32Correct()
calculateCrc32()
) and compare it with the stored value.
public int calculateCrc32()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |