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
JournalFile s 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() |
static void |
writeHeader(ActiveMQBuffer buffer,
int userVersion,
long fileID) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
appendAddRecord, appendAddRecord, appendAddRecordTransactional, appendCommitRecord, appendCommitRecord, appendDeleteRecord, appendDeleteRecordTransactional, appendDeleteRecordTransactional, appendPrepareRecord, appendPrepareRecord, appendRollbackRecord, appendUpdateRecord, appendUpdateRecord, appendUpdateRecordTransactional
public 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 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, EncodingSupport record, boolean sync, IOCompletion callback) throws Exception
appendAddRecord
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, IOCompletion callback) throws Exception
appendDeleteRecord
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, EncodingSupport record) throws Exception
appendUpdateRecordTransactional
in interface Journal
Exception
public void appendDeleteRecordTransactional(long txID, long id, EncodingSupport record) throws Exception
appendDeleteRecordTransactional
in interface Journal
Exception
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 JournalBase.appendCommitRecord(long, boolean)
appendPrepareRecord
in interface Journal
txID
- transactionData
- extra user data for the prepareException
public void lineUpContext(IOCompletion callback)
lineUpContext
in interface Journal
public void appendCommitRecord(long txID, boolean sync, IOCompletion callback, boolean lineUpContext) throws Exception
JournalCompleteRecordTX
.appendCommitRecord
in interface Journal
lineUpContext
- if appendCommitRecord should call a storeLineUp. This is because the
caller may have already taken into accountException
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 loadSyncOnly(Journal.JournalState syncState) throws Exception
Journal
loadSyncOnly
in interface Journal
syncState
- the current state of the journal, this parameter ensures consistency.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 fixBadTX) throws Exception
Exception
load(LoaderCallback)
public void scheduleCompactAndBlock(int timeout) throws Exception
Journal
scheduleCompactAndBlock
in interface Journal
timeout
- the timeout in seconds or block forever if <= 0
Exception
public 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 final boolean checkReclaimStatus() throws Exception
TestableJournal
It will among other things, remove stale files and make them available for reuse.
This method locks the journal.
checkReclaimStatus
in interface TestableJournal
Exception
public final void setAutoReclaim(boolean autoReclaim)
setAutoReclaim
in interface TestableJournal
public final boolean isAutoReclaim()
isAutoReclaim
in interface TestableJournal
public String debug() throws Exception
debug
in interface TestableJournal
Exception
public void debugWait() throws InterruptedException
debugWait
in interface TestableJournal
InterruptedException
public void flush() throws Exception
Journal
public int getDataFilesCount()
getDataFilesCount
in interface TestableJournal
public JournalFile[] getDataFiles()
Journal
JournalFile
s in use.getDataFiles
in interface Journal
getDataFiles
in interface TestableJournal
JournalFile
s in usepublic 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 Journal
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
Journal
JournalFile
.forceMoveNextFile
in interface Journal
forceMoveNextFile
in interface TestableJournal
Exception
public boolean isStarted()
isStarted
in interface ActiveMQComponent
public void start()
start
in interface ActiveMQComponent
public void stop() throws Exception
stop
in interface ActiveMQComponent
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 onCompactLockingTheJournal() 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(ActiveMQBuffer buffer, int userVersion, long fileID)
buffer
- userVersion
- fileID
- public final void synchronizationLock()
Journal
synchronizationLock
in interface Journal
public final void synchronizationUnlock()
Journal
synchronizationUnlock
in interface Journal
Journal.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 Journal
fileIds
- JournalFile
sException
public SequentialFileFactory getFileFactory()
getFileFactory
in interface Journal
protected JournalFile setUpCurrentFile(int lastDataPos) throws Exception
lastDataPos
- Exception
protected JournalFile switchFileIfNecessary(int size) throws Exception
size
- Exception
public void replicationSyncPreserveOldFiles()
Journal
Meant 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 Journal
public 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 Journal
public void testCompact()
testCompact
in interface TestableJournal
public int getCompactCount()
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, EncodingSupport record, boolean sync) throws Exception
appendAddRecord
in interface Journal
Exception
public void appendCommitRecord(long txID, boolean sync) throws Exception
appendCommitRecord
in interface Journal
Exception
public void appendCommitRecord(long txID, boolean sync, IOCompletion callback) throws Exception
appendCommitRecord
in interface Journal
Exception
public void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync) throws Exception
appendUpdateRecord
in interface Journal
Exception
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception
appendUpdateRecordTransactional
in interface Journal
Exception
public void appendAddRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception
appendAddRecordTransactional
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) 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 appendDeleteRecordTransactional(long txID, long id, byte[] record) throws Exception
appendDeleteRecordTransactional
in interface Journal
Exception
public void appendUpdateRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws Exception
appendUpdateRecord
in interface Journal
Exception
public void appendRollbackRecord(long txID, boolean sync) throws Exception
appendRollbackRecord
in interface Journal
Exception
public void appendDeleteRecord(long id, boolean sync) throws Exception
appendDeleteRecord
in interface Journal
Exception
protected SyncIOCompletion getSyncCallback(boolean sync)
Copyright © 2017 JBoss by Red Hat. All rights reserved.