public class JournalImpl extends Object implements TestableJournal, JournalRecordProvider
A circular log implementation.
Look atload(LoaderCallback) for the file layout| Modifier 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 JournalExceptionpublic Map<Long,JournalRecord> getRecords()
getRecords in interface JournalRecordProviderpublic JournalFile getCurrentFile()
getCurrentFile in interface TestableJournalpublic JournalCompactor getCompactor()
getCompactor in interface JournalRecordProviderpublic List<JournalFile> orderFiles() throws Exception
Exceptionpublic static int readJournalFile(SequentialFileFactory fileFactory, JournalFile file, JournalReaderCallback reader) throws Exception
Exceptionpublic void appendAddRecord(long id,
byte recordType,
byte[] record,
boolean sync)
throws Exception
appendAddRecord in interface JournalExceptionpublic void appendAddRecord(long id,
byte recordType,
byte[] record,
boolean sync,
IOCompletion callback)
throws Exception
appendAddRecord in interface JournalExceptionpublic void appendAddRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync)
throws Exception
appendAddRecord in interface JournalExceptionpublic void appendAddRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync,
IOCompletion callback)
throws Exception
appendAddRecord in interface JournalExceptionpublic void appendUpdateRecord(long id,
byte recordType,
byte[] record,
boolean sync)
throws Exception
appendUpdateRecord in interface JournalExceptionpublic void appendUpdateRecord(long id,
byte recordType,
byte[] record,
boolean sync,
IOCompletion callback)
throws Exception
appendUpdateRecord in interface JournalExceptionpublic void appendUpdateRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync)
throws Exception
appendUpdateRecord in interface JournalExceptionpublic void appendUpdateRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync,
IOCompletion callback)
throws Exception
appendUpdateRecord in interface JournalExceptionpublic void appendDeleteRecord(long id,
boolean sync)
throws Exception
appendDeleteRecord in interface JournalExceptionpublic void appendDeleteRecord(long id,
boolean sync,
IOCompletion callback)
throws Exception
appendDeleteRecord in interface JournalExceptionpublic void appendAddRecordTransactional(long txID,
long id,
byte recordType,
byte[] record)
throws Exception
appendAddRecordTransactional in interface JournalExceptionpublic void appendAddRecordTransactional(long txID,
long id,
byte recordType,
EncodingSupport record)
throws Exception
appendAddRecordTransactional in interface JournalExceptionpublic void appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
byte[] record)
throws Exception
appendUpdateRecordTransactional in interface JournalExceptionpublic void appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
EncodingSupport record)
throws Exception
appendUpdateRecordTransactional in interface JournalExceptionpublic void appendDeleteRecordTransactional(long txID,
long id,
byte[] record)
throws Exception
appendDeleteRecordTransactional in interface JournalExceptionpublic void appendDeleteRecordTransactional(long txID,
long id,
EncodingSupport record)
throws Exception
appendDeleteRecordTransactional in interface JournalExceptionpublic void appendDeleteRecordTransactional(long txID,
long id)
throws Exception
appendDeleteRecordTransactional in interface JournalExceptionpublic void appendPrepareRecord(long txID,
byte[] transactionData,
boolean sync,
IOCompletion completion)
throws Exception
appendPrepareRecord in interface JournalExceptionpublic void appendPrepareRecord(long txID,
byte[] transactionData,
boolean sync)
throws Exception
appendPrepareRecord in interface JournalExceptionpublic void appendPrepareRecord(long txID,
EncodingSupport transactionData,
boolean sync)
throws Exception
JournalIf 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 JournaltransactionData - - extra user data for the prepareExceptionpublic 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 JournaltxID - transactionData - extra user data for the prepareExceptionpublic void appendCommitRecord(long txID,
boolean sync)
throws Exception
appendCommitRecord in interface JournalExceptionpublic void lineUpContex(IOCompletion callback)
lineUpContex in interface Journalpublic void appendCommitRecord(long txID,
boolean sync,
IOCompletion callback)
throws Exception
appendCommitRecord in interface JournalExceptionpublic 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 JournalExceptionpublic void appendRollbackRecord(long txID,
boolean sync)
throws Exception
appendRollbackRecord in interface JournalExceptionpublic void appendRollbackRecord(long txID,
boolean sync,
IOCompletion callback)
throws Exception
appendRollbackRecord in interface JournalExceptionpublic int getAlignment()
throws Exception
getAlignment in interface JournalExceptionpublic JournalLoadInformation loadInternalOnly() throws Exception
JournalloadInternalOnly in interface JournalExceptionpublic 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
Exceptionload(LoaderCallback)public void testCompact()
throws Exception
testCompact in interface TestableJournalExceptionprotected void compact()
throws Exception
Exceptionpublic 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
Exceptionpublic boolean checkReclaimStatus()
throws Exception
TestableJournalcheckReclaimStatus in interface TestableJournalExceptionpublic void setAutoReclaim(boolean autoReclaim)
setAutoReclaim in interface TestableJournalpublic boolean isAutoReclaim()
isAutoReclaim in interface TestableJournalpublic String debug() throws Exception
debug in interface TestableJournalExceptionpublic void debugWait()
throws Exception
debugWait in interface TestableJournalExceptionpublic int getDataFilesCount()
getDataFilesCount in interface TestableJournalpublic JournalFile[] getDataFiles()
getDataFiles in interface TestableJournalpublic int getFreeFilesCount()
getFreeFilesCount in interface TestableJournalpublic int getOpenedFilesCount()
getOpenedFilesCount in interface TestableJournalpublic int getIDMapSize()
getIDMapSize in interface TestableJournalpublic int getFileSize()
getFileSize in interface TestableJournalpublic int getMinFiles()
getMinFiles in interface TestableJournalpublic String getFilePrefix()
getFilePrefix in interface TestableJournalpublic String getFileExtension()
getFileExtension in interface TestableJournalpublic int getMaxAIO()
getMaxAIO in interface TestableJournalpublic int getUserVersion()
getUserVersion in interface Journalpublic void forceMoveNextFile()
throws Exception
forceMoveNextFile in interface TestableJournalExceptionpublic void perfBlast(int pages)
throws Exception
public boolean isStarted()
isStarted in interface HornetQComponentpublic void start()
start in interface HornetQComponentpublic void stop()
throws Exception
stop in interface HornetQComponentExceptionpublic int getNumberOfRecords()
getNumberOfRecords in interface Journalprotected SequentialFile createControlFile(List<JournalFile> files, List<JournalFile> newFiles, Pair<String,String> cleanupRename) throws Exception
Exceptionprotected void deleteControlFile(SequentialFile controlFile) throws Exception
Exceptionprotected void renameFiles(List<JournalFile> oldFiles, List<JournalFile> newFiles) throws Exception
Exceptionprotected static String renameExtensionFile(String name, String extension)
name - protected void onCompactStart()
throws Exception
Exceptionprotected void onCompactLock()
throws Exception
Exceptionprotected void onCompactDone()
public static int initFileHeader(SequentialFileFactory fileFactory, SequentialFile sequentialFile, int userVersion, long fileID) throws Exception
fileID - sequentialFile - Exceptionpublic static void writeHeader(HornetQBuffer buffer, int userVersion, long fileID)
buffer - userVersion - fileID - Copyright © 2012 JBoss by Red Hat. All Rights Reserved.