org.jboss.messaging.core.journal.impl
Class JournalImpl

java.lang.Object
  extended by org.jboss.messaging.core.journal.impl.JournalImpl
All Implemented Interfaces:
Journal, TestableJournal, MessagingComponent

public class JournalImpl
extends java.lang.Object
implements TestableJournal

A JournalImpl

WIKI Page: http://wiki.jboss.org/wiki/JBossMessaging2Journal

Look at load(LoadManager) for the file layout

Author:
Tim Fox, Clebert Suconic

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, 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, boolean sync)
           
 void appendAddRecordTransactional(long txID, long id, byte recordType, EncodingSupport record, boolean sync)
           
 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, boolean sync)
           
 void appendDeleteRecordTransactional(long txID, long id, byte[] record, boolean sync)
           
 void appendDeleteRecordTransactional(long txID, long id, EncodingSupport record, 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 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, boolean sync)
           
 void appendUpdateRecordTransactional(long txID, long id, byte recordType, EncodingSupport record, boolean sync)
           
 void checkAndReclaimFiles()
           
 java.lang.String debug()
           
 void debugWait()
          Method for use on testcases.
 void forceMoveNextFile()
           
 int getAlignment()
           
 int getDataFilesCount()
           
 java.lang.String getFileExtension()
           
 java.lang.String getFilePrefix()
           
 int getFileSize()
           
 int getFreeFilesCount()
           
 int getIDMapSize()
           
 int getMaxAIO()
           
 int getMinFiles()
           
 int getOpenedFilesCount()
           
 boolean isAutoReclaim()
           
 boolean isStarted()
           
 long load(java.util.List<RecordInfo> committedRecords, java.util.List<PreparedTransactionInfo> preparedTransactions)
           
 long load(LoadManager loadManager)
          Load data accordingly to the record layouts
 ChannelBuffer newBuffer(int size)
           
 void perfBlast(int pages)
           
 void setAutoReclaim(boolean autoReclaim)
           
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_FILE_SIZE

public static final int MIN_FILE_SIZE
See Also:
Constant Field Values

SIZE_HEADER

public static final int SIZE_HEADER
See Also:
Constant Field Values

BASIC_SIZE

public static final int BASIC_SIZE
See Also:
Constant Field Values

SIZE_ADD_RECORD

public static final int SIZE_ADD_RECORD
See Also:
Constant Field Values

ADD_RECORD

public static final byte ADD_RECORD
See Also:
Constant Field Values

SIZE_UPDATE_RECORD

public static final byte SIZE_UPDATE_RECORD
See Also:
Constant Field Values

UPDATE_RECORD

public static final byte UPDATE_RECORD
See Also:
Constant Field Values

SIZE_ADD_RECORD_TX

public static final int SIZE_ADD_RECORD_TX
See Also:
Constant Field Values

ADD_RECORD_TX

public static final byte ADD_RECORD_TX
See Also:
Constant Field Values

SIZE_UPDATE_RECORD_TX

public static final int SIZE_UPDATE_RECORD_TX
See Also:
Constant Field Values

UPDATE_RECORD_TX

public static final byte UPDATE_RECORD_TX
See Also:
Constant Field Values

SIZE_DELETE_RECORD_TX

public static final int SIZE_DELETE_RECORD_TX
See Also:
Constant Field Values

DELETE_RECORD_TX

public static final byte DELETE_RECORD_TX
See Also:
Constant Field Values

SIZE_DELETE_RECORD

public static final int SIZE_DELETE_RECORD
See Also:
Constant Field Values

DELETE_RECORD

public static final byte DELETE_RECORD
See Also:
Constant Field Values

SIZE_COMPLETE_TRANSACTION_RECORD

public static final int SIZE_COMPLETE_TRANSACTION_RECORD
See Also:
Constant Field Values

SIZE_PREPARE_RECORD

public static final int SIZE_PREPARE_RECORD
See Also:
Constant Field Values

PREPARE_RECORD

public static final byte PREPARE_RECORD
See Also:
Constant Field Values

SIZE_COMMIT_RECORD

public static final int SIZE_COMMIT_RECORD
See Also:
Constant Field Values

COMMIT_RECORD

public static final byte COMMIT_RECORD
See Also:
Constant Field Values

SIZE_ROLLBACK_RECORD

public static final int SIZE_ROLLBACK_RECORD
See Also:
Constant Field Values

ROLLBACK_RECORD

public static final byte ROLLBACK_RECORD
See Also:
Constant Field Values

FILL_CHARACTER

public static final byte FILL_CHARACTER
See Also:
Constant Field Values

filePrefix

public final java.lang.String filePrefix

fileExtension

public final java.lang.String fileExtension
Constructor Detail

JournalImpl

public JournalImpl(int fileSize,
                   int minFiles,
                   SequentialFileFactory fileFactory,
                   java.lang.String filePrefix,
                   java.lang.String fileExtension,
                   int maxAIO)
Method Detail

appendAddRecord

public void appendAddRecord(long id,
                            byte recordType,
                            byte[] record,
                            boolean sync)
                     throws java.lang.Exception
Specified by:
appendAddRecord in interface Journal
Throws:
java.lang.Exception

appendAddRecord

public void appendAddRecord(long id,
                            byte recordType,
                            EncodingSupport record,
                            boolean sync)
                     throws java.lang.Exception
Specified by:
appendAddRecord in interface Journal
Throws:
java.lang.Exception

appendUpdateRecord

public void appendUpdateRecord(long id,
                               byte recordType,
                               byte[] record,
                               boolean sync)
                        throws java.lang.Exception
Specified by:
appendUpdateRecord in interface Journal
Throws:
java.lang.Exception

appendUpdateRecord

public void appendUpdateRecord(long id,
                               byte recordType,
                               EncodingSupport record,
                               boolean sync)
                        throws java.lang.Exception
Specified by:
appendUpdateRecord in interface Journal
Throws:
java.lang.Exception

appendDeleteRecord

public void appendDeleteRecord(long id,
                               boolean sync)
                        throws java.lang.Exception
Specified by:
appendDeleteRecord in interface Journal
Throws:
java.lang.Exception

appendAddRecordTransactional

public void appendAddRecordTransactional(long txID,
                                         long id,
                                         byte recordType,
                                         byte[] record,
                                         boolean sync)
                                  throws java.lang.Exception
Specified by:
appendAddRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendAddRecordTransactional

public void appendAddRecordTransactional(long txID,
                                         long id,
                                         byte recordType,
                                         EncodingSupport record,
                                         boolean sync)
                                  throws java.lang.Exception
Specified by:
appendAddRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendUpdateRecordTransactional

public void appendUpdateRecordTransactional(long txID,
                                            long id,
                                            byte recordType,
                                            byte[] record,
                                            boolean sync)
                                     throws java.lang.Exception
Specified by:
appendUpdateRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendUpdateRecordTransactional

public void appendUpdateRecordTransactional(long txID,
                                            long id,
                                            byte recordType,
                                            EncodingSupport record,
                                            boolean sync)
                                     throws java.lang.Exception
Specified by:
appendUpdateRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendDeleteRecordTransactional

public void appendDeleteRecordTransactional(long txID,
                                            long id,
                                            byte[] record,
                                            boolean sync)
                                     throws java.lang.Exception
Specified by:
appendDeleteRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendDeleteRecordTransactional

public void appendDeleteRecordTransactional(long txID,
                                            long id,
                                            EncodingSupport record,
                                            boolean sync)
                                     throws java.lang.Exception
Specified by:
appendDeleteRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendDeleteRecordTransactional

public void appendDeleteRecordTransactional(long txID,
                                            long id,
                                            boolean sync)
                                     throws java.lang.Exception
Specified by:
appendDeleteRecordTransactional in interface Journal
Throws:
java.lang.Exception

appendPrepareRecord

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)

Specified by:
appendPrepareRecord in interface Journal
Parameters:
txID -
transactionData - - extra user data for the prepare
Throws:
java.lang.Exception

appendCommitRecord

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 records on each file. (What could happen if there are too many records, or if an user event delayed records 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 records spread across the files as originally written.

If for any reason there are missing records, 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

Specified by:
appendCommitRecord in interface Journal
Throws:
java.lang.Exception
See Also:
writeTransaction(byte, long, org.jboss.messaging.core.journal.impl.JournalImpl.JournalTransaction, EncodingSupport)

appendRollbackRecord

public void appendRollbackRecord(long txID,
                                 boolean sync)
                          throws java.lang.Exception
Specified by:
appendRollbackRecord in interface Journal
Throws:
java.lang.Exception

load

public long load(java.util.List<RecordInfo> committedRecords,
                 java.util.List<PreparedTransactionInfo> preparedTransactions)
          throws java.lang.Exception
Specified by:
load in interface Journal
Throws:
java.lang.Exception
See Also:
load(LoadManager)

load

public long load(LoadManager loadManager)
          throws java.lang.Exception

Load data accordingly to the record layouts

Basic record layout:

Field NameSize
RecordTypeByte (1)
FileIDInteger (4 bytes)
TransactionID (if record is transactional)Long (8 bytes)
RecordIDLong (8 bytes)
BodySize(Add, update and delete)Integer (4 bytes)
UserDefinedRecordType (If add/update only)Byte (1)
RecordBodyByte Array (size=BodySize)
Check SizeInteger (4 bytes)

The check-size is used to validate if the record is valid and complete

Commit/Prepare record layout:

Field NameSize
RecordTypeByte (1)
FileIDInteger (4 bytes)
TransactionID (if record is transactional)Long (8 bytes)
ExtraDataLength (Prepares only)Integer (4 bytes)
Number Of Files (N)Integer (4 bytes)
ExtraDataBytesBytes (sized by ExtraDataLength)
* FileID(n)Integer (4 bytes)
* NumberOfElements(n)Integer (4 bytes)
CheckSizeInteger (4 bytes)

* FileID and NumberOfElements are the transaction summary, and they will be repeated (N)umberOfFiles times

Specified by:
load in interface TestableJournal
Throws:
java.lang.Exception

getAlignment

public int getAlignment()
                 throws java.lang.Exception
Specified by:
getAlignment in interface Journal
Throws:
java.lang.Exception

setAutoReclaim

public void setAutoReclaim(boolean autoReclaim)
Specified by:
setAutoReclaim in interface TestableJournal

isAutoReclaim

public boolean isAutoReclaim()
Specified by:
isAutoReclaim in interface TestableJournal

debug

public java.lang.String debug()
                       throws java.lang.Exception
Specified by:
debug in interface TestableJournal
Throws:
java.lang.Exception

debugWait

public void debugWait()
               throws java.lang.Exception
Method for use on testcases. It will call waitComplete on every transaction, so any assertions on the file system will be correct after this

Specified by:
debugWait in interface TestableJournal
Throws:
java.lang.Exception

checkAndReclaimFiles

public void checkAndReclaimFiles()
                          throws java.lang.Exception
Specified by:
checkAndReclaimFiles in interface TestableJournal
Throws:
java.lang.Exception

getDataFilesCount

public int getDataFilesCount()
Specified by:
getDataFilesCount in interface TestableJournal

getFreeFilesCount

public int getFreeFilesCount()
Specified by:
getFreeFilesCount in interface TestableJournal

getOpenedFilesCount

public int getOpenedFilesCount()
Specified by:
getOpenedFilesCount in interface TestableJournal

getIDMapSize

public int getIDMapSize()
Specified by:
getIDMapSize in interface TestableJournal

getFileSize

public int getFileSize()
Specified by:
getFileSize in interface TestableJournal

getMinFiles

public int getMinFiles()
Specified by:
getMinFiles in interface TestableJournal

getFilePrefix

public java.lang.String getFilePrefix()
Specified by:
getFilePrefix in interface TestableJournal

getFileExtension

public java.lang.String getFileExtension()
Specified by:
getFileExtension in interface TestableJournal

getMaxAIO

public int getMaxAIO()
Specified by:
getMaxAIO in interface TestableJournal

forceMoveNextFile

public void forceMoveNextFile()
                       throws java.lang.Exception
Specified by:
forceMoveNextFile in interface TestableJournal
Throws:
java.lang.Exception

perfBlast

public void perfBlast(int pages)
               throws java.lang.Exception
Specified by:
perfBlast in interface Journal
Throws:
java.lang.Exception

isStarted

public boolean isStarted()
Specified by:
isStarted in interface MessagingComponent

start

public void start()
Specified by:
start in interface MessagingComponent

stop

public void stop()
          throws java.lang.Exception
Specified by:
stop in interface MessagingComponent
Throws:
java.lang.Exception

newBuffer

public ChannelBuffer newBuffer(int size)


Copyright © 2006 JBoss Inc. All Rights Reserved.