public class JournalImpl extends Object implements TestableJournal, JournalRecordProvider
A circular log implementation.
Look at load(LoaderCallback) for the file layout
Journal.JournalState| Modifier and Type | Field and Description |
|---|---|
static byte |
ADD_RECORD |
static byte |
ADD_RECORD_TX |
static byte |
COMMIT_RECORD |
static byte |
DELETE_RECORD |
static byte |
DELETE_RECORD_TX |
protected int |
fileSize |
protected static byte |
FILL_CHARACTER |
static int |
FORMAT_VERSION |
protected ExecutorFactory |
ioExecutorFactory |
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(ExecutorFactory ioExecutors,
int fileSize,
int minFiles,
int poolSize,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
String filePrefix,
String fileExtension,
int maxAIO,
int userVersion) |
JournalImpl(int fileSize,
int minFiles,
int poolSize,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
String filePrefix,
String fileExtension,
int maxAIO) |
JournalImpl(int fileSize,
int minFiles,
int poolSize,
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,
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)
Regarding the number of operations in a given file see
JournalCompleteRecordTX. |
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,
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,
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.
|
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) |
Map<Long,JournalFile> |
createFilesForBackupSync(long[] fileIds)
Returns Map with a
JournalFile for all existing files. |
String |
debug() |
void |
debugWait()
Method for use on testcases.
|
protected void |
deleteControlFile(SequentialFile controlFile) |
void |
flush()
It will make sure there are no more pending operations on the Executors.
|
void |
forceMoveNextFile()
Force the usage of a new
JournalFile. |
int |
getAlignment() |
int |
getCompactCount()
For tests only
|
JournalCompactor |
getCompactor() |
JournalFile |
getCurrentFile() |
JournalFile[] |
getDataFiles()
Returns the
JournalFiles in use. |
int |
getDataFilesCount() |
String |
getFileExtension() |
SequentialFileFactory |
getFileFactory() |
String |
getFilePrefix() |
int |
getFileSize() |
int |
getFreeFilesCount() |
int |
getIDMapSize() |
int |
getMaxAIO() |
int |
getMinFiles() |
int |
getNumberOfRecords() |
int |
getOpenedFilesCount() |
Map<Long,JournalRecord> |
getRecords() |
protected SyncIOCompletion |
getSyncCallback(boolean sync) |
int |
getUserVersion() |
static int |
initFileHeader(SequentialFileFactory fileFactory,
SequentialFile sequentialFile,
int userVersion,
long fileID) |
boolean |
isAutoReclaim() |
boolean |
isStarted() |
void |
lineUpContext(IOCompletion callback) |
JournalLoadInformation |
load(List<RecordInfo> committedRecords,
List<PreparedTransactionInfo> preparedTransactions,
TransactionFailureCallback failureCallback) |
JournalLoadInformation |
load(List<RecordInfo> committedRecords,
List<PreparedTransactionInfo> preparedTransactions,
TransactionFailureCallback failureCallback,
boolean fixBadTX) |
JournalLoadInformation |
load(LoaderCallback loadManager)
Load data accordingly to the record layouts
|
JournalLoadInformation |
loadInternalOnly()
Load internal data structures and not expose any data.
|
JournalLoadInformation |
loadSyncOnly(Journal.JournalState syncState)
Load internal data structures, and remain waiting for synchronization to complete.
|
protected void |
onCompactDone()
This is an interception point for testcases, when the compacted files are written, before replacing the data structures
|
protected void |
onCompactLockingTheJournal()
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 |
replicationSyncFinished()
Restarts file reclaim and compacting on the journal.
|
void |
replicationSyncPreserveOldFiles()
Stops any operation that may delete or modify old (stale) data.
|
void |
runDirectJournalBlast() |
void |
scheduleCompactAndBlock(int timeout)
This method will start compact using the compactorExecutor and block up to timeout seconds
|
void |
setAutoReclaim(boolean autoReclaim) |
protected JournalFile |
setUpCurrentFile(int lastDataPos) |
void |
start() |
void |
stop() |
protected JournalFile |
switchFileIfNecessary(int size) |
void |
synchronizationLock()
Write lock the Journal and write lock the compacting process.
|
void |
synchronizationUnlock()
Unlock the Journal and the compacting process.
|
void |
testCompact() |
String |
toString() |
protected SequentialFile |
writeControlFile(SequentialFileFactory fileFactory,
List<JournalFile> files,
List<JournalFile> newFiles,
List<Pair<String,String>> renames) |
static void |
writeHeader(ActiveMQBuffer buffer,
int userVersion,
long fileID) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitappendAddRecord, appendAddRecord, appendAddRecordTransactional, appendCommitRecord, appendCommitRecord, appendDeleteRecord, appendDeleteRecordTransactional, appendDeleteRecordTransactional, appendPrepareRecord, appendPrepareRecord, appendRollbackRecord, appendUpdateRecord, appendUpdateRecord, appendUpdateRecordTransactionalpublic static final int FORMAT_VERSION
public static final int MIN_FILE_SIZE
public static final int SIZE_HEADER
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
protected static final byte FILL_CHARACTER
protected ExecutorFactory ioExecutorFactory
protected final int fileSize
public JournalImpl(int fileSize,
int minFiles,
int poolSize,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
String filePrefix,
String fileExtension,
int maxAIO)
public JournalImpl(int fileSize,
int minFiles,
int poolSize,
int compactMinFiles,
int compactPercentage,
SequentialFileFactory fileFactory,
String filePrefix,
String fileExtension,
int maxAIO,
int userVersion)
public JournalImpl(ExecutorFactory ioExecutors, int fileSize, int minFiles, int poolSize, 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,
EncodingSupport record,
boolean sync,
IOCompletion callback)
throws Exception
appendAddRecord 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,
IOCompletion callback)
throws Exception
appendDeleteRecord 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,
EncodingSupport record)
throws Exception
appendUpdateRecordTransactional in interface JournalExceptionpublic void appendDeleteRecordTransactional(long txID,
long id,
EncodingSupport record)
throws Exception
appendDeleteRecordTransactional in interface JournalExceptionpublic 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 JournalBase.appendCommitRecord(long, boolean)
appendPrepareRecord in interface JournaltxID - transactionData - extra user data for the prepareExceptionpublic void lineUpContext(IOCompletion callback)
lineUpContext in interface Journalpublic void appendCommitRecord(long txID,
boolean sync,
IOCompletion callback,
boolean lineUpContext)
throws Exception
JournalCompleteRecordTX.appendCommitRecord in interface JournallineUpContext - if appendCommitRecord should call a storeLineUp. This is because the
caller may have already taken into accountExceptionpublic 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 loadSyncOnly(Journal.JournalState syncState) throws Exception
JournalloadSyncOnly in interface JournalsyncState - the current state of the journal, this parameter ensures consistency.Exceptionpublic JournalLoadInformation load(List<RecordInfo> committedRecords, List<PreparedTransactionInfo> preparedTransactions, TransactionFailureCallback failureCallback) throws Exception
public JournalLoadInformation load(List<RecordInfo> committedRecords, List<PreparedTransactionInfo> preparedTransactions, TransactionFailureCallback failureCallback, boolean fixBadTX) throws Exception
Exceptionload(LoaderCallback)public void scheduleCompactAndBlock(int timeout)
throws Exception
JournalscheduleCompactAndBlock in interface Journaltimeout - the timeout in seconds or block forever if <= 0Exceptionpublic 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 final boolean checkReclaimStatus()
throws Exception
TestableJournalIt will among other things, remove stale files and make them available for reuse.
This method locks the journal.
checkReclaimStatus in interface TestableJournalExceptionpublic final void setAutoReclaim(boolean autoReclaim)
setAutoReclaim in interface TestableJournalpublic final boolean isAutoReclaim()
isAutoReclaim in interface TestableJournalpublic String debug() throws Exception
debug in interface TestableJournalExceptionpublic void debugWait()
throws InterruptedException
debugWait in interface TestableJournalInterruptedExceptionpublic void flush()
throws Exception
Journalpublic int getDataFilesCount()
getDataFilesCount in interface TestableJournalpublic JournalFile[] getDataFiles()
JournalJournalFiles in use.getDataFiles in interface JournalgetDataFiles in interface TestableJournalJournalFiles in usepublic int getFreeFilesCount()
getFreeFilesCount in interface TestableJournalpublic int getOpenedFilesCount()
getOpenedFilesCount in interface TestableJournalpublic int getIDMapSize()
getIDMapSize in interface TestableJournalpublic int getFileSize()
getFileSize in interface JournalgetFileSize 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
JournalJournalFile.forceMoveNextFile in interface JournalforceMoveNextFile in interface TestableJournalExceptionpublic boolean isStarted()
isStarted in interface ActiveMQComponentpublic void start()
start in interface ActiveMQComponentpublic void stop()
throws Exception
stop in interface ActiveMQComponentExceptionpublic int getNumberOfRecords()
getNumberOfRecords in interface Journalprotected SequentialFile createControlFile(List<JournalFile> files, List<JournalFile> newFiles, Pair<String,String> cleanupRename) throws Exception
Exceptionprotected SequentialFile writeControlFile(SequentialFileFactory fileFactory, List<JournalFile> files, List<JournalFile> newFiles, List<Pair<String,String>> renames) 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 onCompactLockingTheJournal()
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(ActiveMQBuffer buffer, int userVersion, long fileID)
buffer - userVersion - fileID - public final void synchronizationLock()
JournalsynchronizationLock in interface Journalpublic final void synchronizationUnlock()
JournalsynchronizationUnlock in interface JournalJournal.synchronizationLock()public Map<Long,JournalFile> createFilesForBackupSync(long[] fileIds) throws Exception
JournalFile for all existing files.
These are the files needed to be sent to a backup in order to synchronize it.createFilesForBackupSync in interface JournalfileIds - JournalFilesExceptionpublic SequentialFileFactory getFileFactory()
getFileFactory in interface Journalprotected JournalFile setUpCurrentFile(int lastDataPos) throws Exception
lastDataPos - Exceptionprotected JournalFile switchFileIfNecessary(int size) throws Exception
size - Exceptionpublic void replicationSyncPreserveOldFiles()
JournalMeant to be used during synchronization of data between a live server and its replicating (remote) backup. Old files must not be compacted or deleted during synchronization.
replicationSyncPreserveOldFiles in interface Journalpublic void replicationSyncFinished()
Journal
Meant to be used to revert the effect of Journal.replicationSyncPreserveOldFiles(). it should
only be called once the synchronization of the backup and live servers is completed.
replicationSyncFinished in interface Journalpublic void testCompact()
testCompact in interface TestableJournalpublic int getCompactCount()
public void appendAddRecord(long id,
byte recordType,
byte[] record,
boolean sync)
throws Exception
appendAddRecord in interface JournalExceptionpublic void appendAddRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync)
throws Exception
appendAddRecord in interface JournalExceptionpublic void appendCommitRecord(long txID,
boolean sync)
throws Exception
appendCommitRecord in interface JournalExceptionpublic void appendCommitRecord(long txID,
boolean sync,
IOCompletion callback)
throws Exception
appendCommitRecord in interface JournalExceptionpublic void appendUpdateRecord(long id,
byte recordType,
byte[] record,
boolean sync)
throws Exception
appendUpdateRecord in interface JournalExceptionpublic void appendUpdateRecordTransactional(long txID,
long id,
byte recordType,
byte[] record)
throws Exception
appendUpdateRecordTransactional in interface JournalExceptionpublic void appendAddRecordTransactional(long txID,
long id,
byte recordType,
byte[] record)
throws Exception
appendAddRecordTransactional in interface JournalExceptionpublic void appendDeleteRecordTransactional(long txID,
long id)
throws Exception
appendDeleteRecordTransactional 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 appendDeleteRecordTransactional(long txID,
long id,
byte[] record)
throws Exception
appendDeleteRecordTransactional in interface JournalExceptionpublic void appendUpdateRecord(long id,
byte recordType,
EncodingSupport record,
boolean sync)
throws Exception
appendUpdateRecord in interface JournalExceptionpublic void appendRollbackRecord(long txID,
boolean sync)
throws Exception
appendRollbackRecord in interface JournalExceptionpublic void appendDeleteRecord(long id,
boolean sync)
throws Exception
appendDeleteRecord in interface JournalExceptionprotected SyncIOCompletion getSyncCallback(boolean sync)
Copyright © 2018 JBoss by Red Hat. All rights reserved.