public class JournalImpl extends Object implements TestableJournal, JournalRecordProvider
A circular log implementation.
Look atload(LoaderCallback)
for the file layoutModifier and Type | Field and Description |
---|---|
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 |
static byte |
FILL_CHARACTER |
static int |
FORMAT_VERSION |
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 |
UPDATE_RECORD |
static byte |
UPDATE_RECORD_TX |
Constructor and Description |
---|
JournalImpl(int fileSize,
int minFiles,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
String filePrefix,
String fileExtension,
int maxAIO) |
JournalImpl(int fileSize,
int minFiles,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
String filePrefix,
String fileExtension,
int maxAIO,
int userVersion) |
Modifier and Type | Method and Description |
---|---|
void |
appendAddRecord(long id,
byte recordType,
byte[] record,
boolean sync) |
void |
appendAddRecord(long id,
byte recordType,
byte[] record,
boolean sync,
IOCompletion callback) |
void |
appendAddRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync) |
void |
appendAddRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync,
IOCompletion callback) |
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) |
void |
appendCommitRecord(long txID,
boolean sync,
IOCompletion callback) |
void |
appendCommitRecord(long txID,
boolean sync,
IOCompletion callback,
boolean lineUpContext)
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 |
appendDeleteRecord(long id,
boolean sync,
IOCompletion callback) |
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,
byte[] transactionData,
boolean sync) |
void |
appendPrepareRecord(long txID,
byte[] transactionData,
boolean sync,
IOCompletion completion) |
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 |
appendPrepareRecord(long txID,
EncodingSupport transactionData,
boolean sync,
IOCompletion callback)
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 |
appendRollbackRecord(long txID,
boolean sync,
IOCompletion callback) |
void |
appendUpdateRecord(long id,
byte recordType,
byte[] record,
boolean sync) |
void |
appendUpdateRecord(long id,
byte recordType,
byte[] record,
boolean sync,
IOCompletion callback) |
void |
appendUpdateRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync) |
void |
appendUpdateRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync,
IOCompletion callback) |
void |
appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
byte[] record) |
void |
appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
EncodingSupport record) |
boolean |
checkReclaimStatus()
This method is called automatically when a new file is opened.
|
protected 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(List<JournalFile> files,
List<JournalFile> newFiles,
Pair<String,String> cleanupRename) |
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() |
String |
getFileExtension() |
String |
getFilePrefix() |
int |
getFileSize() |
int |
getFreeFilesCount() |
int |
getIDMapSize() |
int |
getMaxAIO() |
int |
getMinFiles() |
int |
getNumberOfRecords() |
int |
getOpenedFilesCount() |
Map<Long,JournalRecord> |
getRecords() |
int |
getUserVersion() |
static int |
initFileHeader(SequentialFileFactory fileFactory,
SequentialFile sequentialFile,
int userVersion,
long fileID) |
boolean |
isAutoReclaim() |
boolean |
isStarted() |
void |
lineUpContex(IOCompletion callback) |
JournalLoadInformation |
load(List<RecordInfo> committedRecords,
List<PreparedTransactionInfo> preparedTransactions,
TransactionFailureCallback failureCallback) |
JournalLoadInformation |
load(List<RecordInfo> committedRecords,
List<PreparedTransactionInfo> preparedTransactions,
TransactionFailureCallback failureCallback,
boolean changeData) |
JournalLoadInformation |
load(LoaderCallback loadManager)
Load data accordingly to the record layouts
|
JournalLoadInformation |
load(LoaderCallback loadManager,
boolean changeData) |
JournalLoadInformation |
loadInternalOnly()
Load internal data structures and not expose any data.
|
protected void |
onCompactDone()
This is an interception point for testcases, when the compacted files are written, before replacing the data structures
|
protected void |
onCompactLock()
This is an interception point for testcases, when the compacted files are written, to be called
as soon as the compactor gets a writeLock
|
protected void |
onCompactStart()
This is an interception point for testcases, when the compacted files are written, before replacing the data structures
|
List<JournalFile> |
orderFiles()
this method is used internally only however tools may use it to maintenance.
|
void |
perfBlast(int pages) |
static int |
readJournalFile(SequentialFileFactory fileFactory,
JournalFile file,
JournalReaderCallback reader)
this method is used internally only however tools may use it to maintenance.
|
protected static String |
renameExtensionFile(String name,
String extension) |
protected void |
renameFiles(List<JournalFile> oldFiles,
List<JournalFile> newFiles)
being protected as testcases can override this method
|
void |
runDirectJournalBlast() |
void |
setAutoReclaim(boolean autoReclaim) |
void |
start() |
void |
stop() |
void |
testCompact() |
static void |
writeHeader(HornetQBuffer buffer,
int userVersion,
long fileID) |
public static final int FORMAT_VERSION
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 UPDATE_RECORD
public static final int SIZE_ADD_RECORD_TX
public static final byte ADD_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 JournalImpl(int fileSize, int minFiles, int compactMinFiles, int compactPercentage, SequentialFileFactory fileFactory, String filePrefix, String fileExtension, int maxAIO)
public JournalImpl(int fileSize, int minFiles, int compactMinFiles, int compactPercentage, SequentialFileFactory fileFactory, String filePrefix, String fileExtension, int maxAIO, int userVersion)
public void runDirectJournalBlast() throws Exception
runDirectJournalBlast
in interface Journal
Exception
public Map<Long,JournalRecord> getRecords()
getRecords
in interface JournalRecordProvider
public JournalFile getCurrentFile()
getCurrentFile
in interface TestableJournal
public JournalCompactor getCompactor()
getCompactor
in interface JournalRecordProvider
public List<JournalFile> orderFiles() throws Exception
Exception
public static int readJournalFile(SequentialFileFactory fileFactory, JournalFile file, JournalReaderCallback reader) throws Exception
Exception
public void appendAddRecord(long id, byte recordType, byte[] record, boolean sync) throws Exception
appendAddRecord
in interface Journal
Exception
public void appendAddRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion callback) throws Exception
appendAddRecord
in interface Journal
Exception
public void appendAddRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws Exception
appendAddRecord
in interface Journal
Exception
public void appendAddRecord(long id, byte recordType, EncodingSupport record, boolean sync, IOCompletion callback) throws Exception
appendAddRecord
in interface Journal
Exception
public void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync) throws Exception
appendUpdateRecord
in interface Journal
Exception
public void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion callback) throws Exception
appendUpdateRecord
in interface Journal
Exception
public void appendUpdateRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws Exception
appendUpdateRecord
in interface Journal
Exception
public void appendUpdateRecord(long id, byte recordType, EncodingSupport record, boolean sync, IOCompletion callback) throws Exception
appendUpdateRecord
in interface Journal
Exception
public void appendDeleteRecord(long id, boolean sync) throws Exception
appendDeleteRecord
in interface Journal
Exception
public void appendDeleteRecord(long id, boolean sync, IOCompletion callback) throws Exception
appendDeleteRecord
in interface Journal
Exception
public void appendAddRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception
appendAddRecordTransactional
in interface Journal
Exception
public void appendAddRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws Exception
appendAddRecordTransactional
in interface Journal
Exception
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception
appendUpdateRecordTransactional
in interface Journal
Exception
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws Exception
appendUpdateRecordTransactional
in interface Journal
Exception
public void appendDeleteRecordTransactional(long txID, long id, byte[] record) throws Exception
appendDeleteRecordTransactional
in interface Journal
Exception
public void appendDeleteRecordTransactional(long txID, long id, EncodingSupport record) throws Exception
appendDeleteRecordTransactional
in interface Journal
Exception
public void appendDeleteRecordTransactional(long txID, long id) throws Exception
appendDeleteRecordTransactional
in interface Journal
Exception
public void appendPrepareRecord(long txID, byte[] transactionData, boolean sync, IOCompletion completion) throws Exception
appendPrepareRecord
in interface Journal
Exception
public void appendPrepareRecord(long txID, byte[] transactionData, boolean sync) throws Exception
appendPrepareRecord
in interface Journal
Exception
public void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync) throws Exception
Journal
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
appendPrepareRecord
in interface Journal
transactionData
- - extra user data for the prepareException
public void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync, IOCompletion callback) throws 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 appendCommitRecord(long, boolean)
appendPrepareRecord
in interface Journal
txID
- transactionData
- extra user data for the prepareException
public void appendCommitRecord(long txID, boolean sync) throws Exception
appendCommitRecord
in interface Journal
Exception
public void lineUpContex(IOCompletion callback)
lineUpContex
in interface Journal
public void appendCommitRecord(long txID, boolean sync, IOCompletion callback) throws Exception
appendCommitRecord
in interface Journal
Exception
public void appendCommitRecord(long txID, boolean sync, IOCompletion callback, boolean lineUpContext) throws 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
Exception
public void appendRollbackRecord(long txID, boolean sync) throws Exception
appendRollbackRecord
in interface Journal
Exception
public void appendRollbackRecord(long txID, boolean sync, IOCompletion callback) throws Exception
appendRollbackRecord
in interface Journal
Exception
public int getAlignment() throws Exception
getAlignment
in interface Journal
Exception
public JournalLoadInformation loadInternalOnly() throws Exception
Journal
loadInternalOnly
in interface Journal
Exception
public JournalLoadInformation load(List<RecordInfo> committedRecords, List<PreparedTransactionInfo> preparedTransactions, TransactionFailureCallback failureCallback) throws Exception
public JournalLoadInformation load(List<RecordInfo> committedRecords, List<PreparedTransactionInfo> preparedTransactions, TransactionFailureCallback failureCallback, boolean changeData) throws Exception
Exception
load(LoaderCallback)
public void testCompact() throws Exception
testCompact
in interface TestableJournal
Exception
protected void compact() throws Exception
Exception
public JournalLoadInformation load(LoaderCallback loadManager) throws Exception
Load data accordingly to the record layouts
Basic record layout:
Field Name | Size |
RecordType | Byte (1) |
FileID | Integer (4 bytes) |
Compactor Counter | 1 byte |
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) |
Compactor Counter | 1 byte |
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
public JournalLoadInformation load(LoaderCallback loadManager, boolean changeData) throws Exception
Exception
public boolean checkReclaimStatus() throws Exception
TestableJournal
checkReclaimStatus
in interface TestableJournal
Exception
public void setAutoReclaim(boolean autoReclaim)
setAutoReclaim
in interface TestableJournal
public boolean isAutoReclaim()
isAutoReclaim
in interface TestableJournal
public String debug() throws Exception
debug
in interface TestableJournal
Exception
public void debugWait() throws Exception
debugWait
in interface TestableJournal
Exception
public int getDataFilesCount()
getDataFilesCount
in interface TestableJournal
public JournalFile[] getDataFiles()
getDataFiles
in interface TestableJournal
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 String getFilePrefix()
getFilePrefix
in interface TestableJournal
public String getFileExtension()
getFileExtension
in interface TestableJournal
public int getMaxAIO()
getMaxAIO
in interface TestableJournal
public int getUserVersion()
getUserVersion
in interface Journal
public void forceMoveNextFile() throws Exception
forceMoveNextFile
in interface TestableJournal
Exception
public void perfBlast(int pages) throws Exception
public boolean isStarted()
isStarted
in interface HornetQComponent
public void start()
start
in interface HornetQComponent
public void stop() throws Exception
stop
in interface HornetQComponent
Exception
public int getNumberOfRecords()
getNumberOfRecords
in interface Journal
protected SequentialFile createControlFile(List<JournalFile> files, List<JournalFile> newFiles, Pair<String,String> cleanupRename) throws Exception
Exception
protected void deleteControlFile(SequentialFile controlFile) throws Exception
Exception
protected void renameFiles(List<JournalFile> oldFiles, List<JournalFile> newFiles) throws Exception
Exception
protected static String renameExtensionFile(String name, String extension)
name
- protected void onCompactStart() throws Exception
Exception
protected void onCompactLock() throws Exception
Exception
protected void onCompactDone()
public static int initFileHeader(SequentialFileFactory fileFactory, SequentialFile sequentialFile, int userVersion, long fileID) throws Exception
fileID
- sequentialFile
- Exception
public static void writeHeader(HornetQBuffer buffer, int userVersion, long fileID)
buffer
- userVersion
- fileID
- Copyright © 2012 JBoss by Red Hat. All Rights Reserved.