|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.messaging.core.journal.impl.JournalImpl
public class JournalImpl
A JournalImpl
WIKI Page: http://wiki.jboss.org/wiki/JBossMessaging2JournalLook at load(LoaderCallback)
for the file layout
Nested Class Summary | |
---|---|
static class |
JournalImpl.ByteArrayEncoding
|
static class |
JournalImpl.JournalRecord
This holds the relationship a record has with other files in regard to reference counting. |
Field Summary | |
---|---|
static byte |
ADD_RECORD
|
static byte |
ADD_RECORD_TX
|
static int |
BASIC_SIZE
|
static byte |
COMMIT_RECORD
|
static byte |
DELETE_RECORD
|
static byte |
DELETE_RECORD_TX
|
java.lang.String |
fileExtension
|
java.lang.String |
filePrefix
|
static byte |
FILL_CHARACTER
|
static int |
MIN_FILE_SIZE
|
static byte |
PREPARE_RECORD
|
static byte |
ROLLBACK_RECORD
|
static int |
SIZE_ADD_RECORD
|
static int |
SIZE_ADD_RECORD_TX
|
static int |
SIZE_COMMIT_RECORD
|
static int |
SIZE_COMPLETE_TRANSACTION_RECORD
|
static int |
SIZE_DELETE_RECORD
|
static int |
SIZE_DELETE_RECORD_TX
|
static int |
SIZE_HEADER
|
static int |
SIZE_PREPARE_RECORD
|
static int |
SIZE_ROLLBACK_RECORD
|
static byte |
SIZE_UPDATE_RECORD
|
static int |
SIZE_UPDATE_RECORD_TX
|
static byte |
UPDATE_RECORD
|
static byte |
UPDATE_RECORD_TX
|
Constructor Summary | |
---|---|
JournalImpl(int fileSize,
int minFiles,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
java.lang.String filePrefix,
java.lang.String fileExtension,
int maxAIO)
|
Method Summary | |
---|---|
void |
appendAddRecord(long id,
byte recordType,
byte[] record,
boolean sync)
|
void |
appendAddRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync)
|
void |
appendAddRecordTransactional(long txID,
long id,
byte recordType,
byte[] record)
|
void |
appendAddRecordTransactional(long txID,
long id,
byte recordType,
EncodingSupport record)
|
void |
appendCommitRecord(long txID,
boolean sync)
A transaction record (Commit or Prepare), will hold the number of elements the transaction has on each file. |
void |
appendDeleteRecord(long id,
boolean sync)
|
void |
appendDeleteRecordTransactional(long txID,
long id)
|
void |
appendDeleteRecordTransactional(long txID,
long id,
byte[] record)
|
void |
appendDeleteRecordTransactional(long txID,
long id,
EncodingSupport record)
|
void |
appendPrepareRecord(long txID,
EncodingSupport transactionData,
boolean sync)
If the system crashed after a prepare was called, it should store information that is required to bring the transaction back to a state it could be committed. |
void |
appendRollbackRecord(long txID,
boolean sync)
|
void |
appendUpdateRecord(long id,
byte recordType,
byte[] record,
boolean sync)
|
void |
appendUpdateRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync)
|
void |
appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
byte[] record)
|
void |
appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
EncodingSupport record)
|
void |
checkAndReclaimFiles()
This method is called automatically when a new file is opened |
void |
checkCompact()
This method check for the need of compacting based on the minCompactPercentage This method is usually called automatically when new files are opened |
void |
compact()
Note: This method can't be called from the main executor, as it will invoke other methods depending on it. |
protected SequentialFile |
createControlFile(java.util.List<JournalFile> files,
java.util.List<JournalFile> newFiles)
|
java.lang.String |
debug()
|
void |
debugWait()
Method for use on testcases. |
protected void |
deleteControlFile(SequentialFile controlFile)
|
void |
forceMoveNextFile()
|
int |
getAlignment()
|
JournalCompactor |
getCompactor()
|
JournalFile |
getCurrentFile()
|
JournalFile[] |
getDataFiles()
|
int |
getDataFilesCount()
|
java.lang.String |
getFileExtension()
|
java.lang.String |
getFilePrefix()
|
int |
getFileSize()
|
int |
getFreeFilesCount()
|
int |
getIDMapSize()
|
int |
getMaxAIO()
|
int |
getMinFiles()
|
int |
getOpenedFilesCount()
|
java.util.Map<java.lang.Long,JournalImpl.JournalRecord> |
getRecords()
|
boolean |
isAutoReclaim()
|
boolean |
isStarted()
|
long |
load(java.util.List<RecordInfo> committedRecords,
java.util.List<PreparedTransactionInfo> preparedTransactions)
|
long |
load(LoaderCallback loadManager)
Load data accordingly to the record layouts |
protected void |
onCompactDone()
This is an interception point for testcases, when the compacted files are written, before replacing the data structures |
void |
perfBlast(int pages)
|
static int |
readJournalFile(SequentialFileFactory fileFactory,
JournalFile file,
JournalReaderCallback reader)
|
protected void |
renameFiles(java.util.List<JournalFile> oldFiles,
java.util.List<JournalFile> newFiles)
being protected as testcases can override this method |
void |
setAutoReclaim(boolean autoReclaim)
|
void |
start()
|
void |
stop()
|
static void |
writeAddRecord(int fileId,
long id,
byte recordType,
EncodingSupport record,
int size,
ChannelBuffer bb)
|
static void |
writeAddRecordTX(int fileID,
long txID,
long id,
byte recordType,
EncodingSupport record,
int size,
ChannelBuffer bb)
|
static void |
writeDeleteRecordTransactional(int fileID,
long txID,
long id,
EncodingSupport record,
int size,
ChannelBuffer bb)
|
static void |
writeTransaction(int fileID,
byte recordType,
long txID,
JournalTransaction tx,
EncodingSupport transactionData,
int size,
int numberOfRecords,
ChannelBuffer bb)
A transaction record (Commit or Prepare), will hold the number of elements the transaction has on each file. |
static void |
writeUpdateRecord(int fileId,
long id,
byte recordType,
EncodingSupport record,
int size,
ChannelBuffer bb)
|
static void |
writeUpdateRecordTX(int fileID,
long txID,
long id,
byte recordType,
EncodingSupport record,
int size,
ChannelBuffer bb)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MIN_FILE_SIZE
public static final int SIZE_HEADER
public static final int BASIC_SIZE
public static final int SIZE_ADD_RECORD
public static final byte ADD_RECORD
public static final byte SIZE_UPDATE_RECORD
public static final byte UPDATE_RECORD
public static final int SIZE_ADD_RECORD_TX
public static final byte ADD_RECORD_TX
public static final int SIZE_UPDATE_RECORD_TX
public static final byte UPDATE_RECORD_TX
public static final int SIZE_DELETE_RECORD_TX
public static final byte DELETE_RECORD_TX
public static final int SIZE_DELETE_RECORD
public static final byte DELETE_RECORD
public static final int SIZE_COMPLETE_TRANSACTION_RECORD
public static final int SIZE_PREPARE_RECORD
public static final byte PREPARE_RECORD
public static final int SIZE_COMMIT_RECORD
public static final byte COMMIT_RECORD
public static final int SIZE_ROLLBACK_RECORD
public static final byte ROLLBACK_RECORD
public static final byte FILL_CHARACTER
public final java.lang.String filePrefix
public final java.lang.String fileExtension
Constructor Detail |
---|
public JournalImpl(int fileSize, int minFiles, int compactMinFiles, int compactPercentage, SequentialFileFactory fileFactory, java.lang.String filePrefix, java.lang.String fileExtension, int maxAIO)
Method Detail |
---|
public static void writeTransaction(int fileID, byte recordType, long txID, JournalTransaction tx, EncodingSupport transactionData, int size, int numberOfRecords, ChannelBuffer bb) throws java.lang.Exception
A transaction record (Commit or Prepare), will hold the number of elements the transaction has on each file.
For example, a transaction was spread along 3 journal files with 10 pendingTransactions on each file. (What could happen if there are too many pendingTransactions, or if an user event delayed pendingTransactions to come in time to a single file).
The element-summary will then have
FileID1, 10
FileID2, 10
FileID3, 10
During the load, the transaction needs to have 30 pendingTransactions spread across the files as originally written.
If for any reason there are missing pendingTransactions, that means the transaction was not completed and we should ignore the whole transaction
We can't just use a global counter as reclaiming could delete files after the transaction was successfully committed. That also means not having a whole file on journal-reload doesn't mean we have to invalidate the transaction
recordType
- txID
- tx
- transactionData
-
java.lang.Exception
public static void writeUpdateRecordTX(int fileID, long txID, long id, byte recordType, EncodingSupport record, int size, ChannelBuffer bb)
txID
- id
- recordType
- record
- size
- bb
- public static void writeUpdateRecord(int fileId, long id, byte recordType, EncodingSupport record, int size, ChannelBuffer bb)
id
- recordType
- record
- size
- bb
- public static void writeAddRecord(int fileId, long id, byte recordType, EncodingSupport record, int size, ChannelBuffer bb)
id
- recordType
- record
- size
- bb
- public static void writeDeleteRecordTransactional(int fileID, long txID, long id, EncodingSupport record, int size, ChannelBuffer bb)
txID
- id
- record
- size
- bb
- public static void writeAddRecordTX(int fileID, long txID, long id, byte recordType, EncodingSupport record, int size, ChannelBuffer bb)
txID
- id
- recordType
- record
- recordLength
- size
- bb
- public java.util.Map<java.lang.Long,JournalImpl.JournalRecord> getRecords()
public JournalFile getCurrentFile()
public JournalCompactor getCompactor()
public static int readJournalFile(SequentialFileFactory fileFactory, JournalFile file, JournalReaderCallback reader) throws java.lang.Exception
java.lang.Exception
public void appendAddRecord(long id, byte recordType, byte[] record, boolean sync) throws java.lang.Exception
appendAddRecord
in interface Journal
java.lang.Exception
public void appendAddRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws java.lang.Exception
appendAddRecord
in interface Journal
java.lang.Exception
public void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync) throws java.lang.Exception
appendUpdateRecord
in interface Journal
java.lang.Exception
public void appendUpdateRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws java.lang.Exception
appendUpdateRecord
in interface Journal
java.lang.Exception
public void appendDeleteRecord(long id, boolean sync) throws java.lang.Exception
appendDeleteRecord
in interface Journal
java.lang.Exception
public void appendAddRecordTransactional(long txID, long id, byte recordType, byte[] record) throws java.lang.Exception
appendAddRecordTransactional
in interface Journal
java.lang.Exception
public void appendAddRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws java.lang.Exception
appendAddRecordTransactional
in interface Journal
java.lang.Exception
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, byte[] record) throws java.lang.Exception
appendUpdateRecordTransactional
in interface Journal
java.lang.Exception
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws java.lang.Exception
appendUpdateRecordTransactional
in interface Journal
java.lang.Exception
public void appendDeleteRecordTransactional(long txID, long id, byte[] record) throws java.lang.Exception
appendDeleteRecordTransactional
in interface Journal
java.lang.Exception
public void appendDeleteRecordTransactional(long txID, long id, EncodingSupport record) throws java.lang.Exception
appendDeleteRecordTransactional
in interface Journal
java.lang.Exception
public void appendDeleteRecordTransactional(long txID, long id) throws java.lang.Exception
appendDeleteRecordTransactional
in interface Journal
java.lang.Exception
public void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync) throws java.lang.Exception
If the system crashed after a prepare was called, it should store information that is required to bring the transaction back to a state it could be committed.
transactionData allows you to store any other supporting user-data related to the transaction
This method also uses the same logic applied on JournalImpl#appendCommitRecord(long)
appendPrepareRecord
in interface Journal
txID
- transactionData
- - extra user data for the prepare
java.lang.Exception
public void appendCommitRecord(long txID, boolean sync) throws java.lang.Exception
A transaction record (Commit or Prepare), will hold the number of elements the transaction has on each file.
For example, a transaction was spread along 3 journal files with 10 pendingTransactions on each file. (What could happen if there are too many pendingTransactions, or if an user event delayed pendingTransactions to come in time to a single file).
The element-summary will then have
FileID1, 10
FileID2, 10
FileID3, 10
During the load, the transaction needs to have 30 pendingTransactions spread across the files as originally written.
If for any reason there are missing pendingTransactions, that means the transaction was not completed and we should ignore the whole transaction
We can't just use a global counter as reclaiming could delete files after the transaction was successfully committed. That also means not having a whole file on journal-reload doesn't mean we have to invalidate the transaction
appendCommitRecord
in interface Journal
java.lang.Exception
JournalImpl#writeTransaction(byte, long, org.jboss.messaging.core.journal.impl.JournalImpl.JournalTransaction, EncodingSupport)
public void appendRollbackRecord(long txID, boolean sync) throws java.lang.Exception
appendRollbackRecord
in interface Journal
java.lang.Exception
public int getAlignment() throws java.lang.Exception
getAlignment
in interface Journal
java.lang.Exception
public long load(java.util.List<RecordInfo> committedRecords, java.util.List<PreparedTransactionInfo> preparedTransactions) throws java.lang.Exception
load
in interface Journal
java.lang.Exception
load(LoaderCallback)
public void compact() throws java.lang.Exception
compact
in interface Journal
java.lang.Exception
public long load(LoaderCallback loadManager) throws java.lang.Exception
Load data accordingly to the record layouts
Basic record layout:
Field Name | Size |
RecordType | Byte (1) |
FileID | Integer (4 bytes) |
TransactionID (if record is transactional) | Long (8 bytes) |
RecordID | Long (8 bytes) |
BodySize(Add, update and delete) | Integer (4 bytes) |
UserDefinedRecordType (If add/update only) | Byte (1) |
RecordBody | Byte Array (size=BodySize) |
Check Size | Integer (4 bytes) |
The check-size is used to validate if the record is valid and complete
Commit/Prepare record layout:
Field Name | Size |
RecordType | Byte (1) |
FileID | Integer (4 bytes) |
TransactionID (if record is transactional) | Long (8 bytes) |
ExtraDataLength (Prepares only) | Integer (4 bytes) |
Number Of Files (N) | Integer (4 bytes) |
ExtraDataBytes | Bytes (sized by ExtraDataLength) |
* FileID(n) | Integer (4 bytes) |
* NumberOfElements(n) | Integer (4 bytes) |
CheckSize | Integer (4 bytes) |
* FileID and NumberOfElements are the transaction summary, and they will be repeated (N)umberOfFiles times
load
in interface TestableJournal
java.lang.Exception
public void checkAndReclaimFiles() throws java.lang.Exception
Journal
checkAndReclaimFiles
in interface Journal
java.lang.Exception
public void checkCompact() throws java.lang.Exception
Journal
checkCompact
in interface Journal
java.lang.Exception
public void setAutoReclaim(boolean autoReclaim)
setAutoReclaim
in interface TestableJournal
public boolean isAutoReclaim()
isAutoReclaim
in interface TestableJournal
public java.lang.String debug() throws java.lang.Exception
debug
in interface TestableJournal
java.lang.Exception
public void debugWait() throws java.lang.Exception
debugWait
in interface TestableJournal
java.lang.Exception
public int getDataFilesCount()
getDataFilesCount
in interface TestableJournal
public JournalFile[] getDataFiles()
getDataFiles
in interface Journal
public int getFreeFilesCount()
getFreeFilesCount
in interface TestableJournal
public int getOpenedFilesCount()
getOpenedFilesCount
in interface TestableJournal
public int getIDMapSize()
getIDMapSize
in interface TestableJournal
public int getFileSize()
getFileSize
in interface TestableJournal
public int getMinFiles()
getMinFiles
in interface TestableJournal
public java.lang.String getFilePrefix()
getFilePrefix
in interface TestableJournal
public java.lang.String getFileExtension()
getFileExtension
in interface TestableJournal
public int getMaxAIO()
getMaxAIO
in interface TestableJournal
public void forceMoveNextFile() throws java.lang.Exception
forceMoveNextFile
in interface TestableJournal
java.lang.Exception
public void perfBlast(int pages) throws java.lang.Exception
perfBlast
in interface Journal
java.lang.Exception
public boolean isStarted()
isStarted
in interface MessagingComponent
public void start()
start
in interface MessagingComponent
public void stop() throws java.lang.Exception
stop
in interface MessagingComponent
java.lang.Exception
protected void deleteControlFile(SequentialFile controlFile) throws java.lang.Exception
java.lang.Exception
protected void renameFiles(java.util.List<JournalFile> oldFiles, java.util.List<JournalFile> newFiles) throws java.lang.Exception
java.lang.Exception
protected void onCompactDone()
protected SequentialFile createControlFile(java.util.List<JournalFile> files, java.util.List<JournalFile> newFiles) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |