org.exist.storage.journal
Class Journal

java.lang.Object
  extended by org.exist.storage.journal.Journal

public class Journal
extends Object

Manages the journalling log. The database uses one central journal for all data files. If the journal exceeds the predefined maximum size, a new file is created. Every journal file has a unique number, which keeps growing during the lifetime of the db. The name of the file corresponds to the file number. The file with the highest number will be used for recovery. A buffer is used to temporarily buffer journal entries. To guarantee consistency, the buffer will be flushed and the journal is synched after every commit or whenever a db page is written to disk. Each entry has the structure:

[byte: entryType, long: transactionId, short length, byte[] data, short backLink]

Author:
wolf

Field Summary
static String BAK_FILE_SUFFIX
           
static int DEFAULT_MAX_SIZE
          default maximum journal size
static String LCK_FILE
           
static int LOG_ENTRY_BASE_LEN
          header length + trailing back link
static int LOG_ENTRY_HEADER_LEN
          the length of the header of each entry: entryType + transactionId + length
static String LOG_FILE_SUFFIX
           
static String PROPERTY_RECOVERY_JOURNAL_DIR
           
static String PROPERTY_RECOVERY_SIZE_LIMIT
           
static String PROPERTY_RECOVERY_SYNC_ON_COMMIT
           
static String RECOVERY_JOURNAL_DIR_ATTRIBUTE
           
static String RECOVERY_SIZE_LIMIT_ATTRIBUTE
           
static String RECOVERY_SYNC_ON_COMMIT_ATTRIBUTE
           
 
Constructor Summary
Journal(BrokerPool pool, File directory)
           
 
Method Summary
 void checkpoint(long txnId, boolean switchLogFiles)
          Write a checkpoint record to the journal and flush it.
 void close()
           
static int findLastFile(File[] files)
          Find the journal file with the highest file number.
 void flushToLog(boolean fsync)
          Flush the current buffer to disk.
 void flushToLog(boolean fsync, boolean forceSync)
          Flush the current buffer to disk.
 File getFile(int fileNum)
          Returns the file corresponding to the specified file number.
 File[] getFiles()
          Returns all journal files found in the data directory.
 void initialize()
           
 long lastWrittenLsn()
          Returns the last LSN physically written to the journal.
 void setCurrentFileNum(int fileNum)
          Set the file number of the last file used.
 void setInRecovery(boolean value)
          Called to signal that the db is currently in recovery phase, so no output should be written.
 void shutdown(long txnId, boolean checkpoint)
          Shut down the journal.
 void switchFiles()
          Create a new journal with a larger file number than the previous file.
 void writeToLog(Loggable loggable)
          Write a log entry to the journalling log.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECOVERY_SYNC_ON_COMMIT_ATTRIBUTE

public static final String RECOVERY_SYNC_ON_COMMIT_ATTRIBUTE
See Also:
Constant Field Values

RECOVERY_JOURNAL_DIR_ATTRIBUTE

public static final String RECOVERY_JOURNAL_DIR_ATTRIBUTE
See Also:
Constant Field Values

RECOVERY_SIZE_LIMIT_ATTRIBUTE

public static final String RECOVERY_SIZE_LIMIT_ATTRIBUTE
See Also:
Constant Field Values

PROPERTY_RECOVERY_SIZE_LIMIT

public static final String PROPERTY_RECOVERY_SIZE_LIMIT
See Also:
Constant Field Values

PROPERTY_RECOVERY_JOURNAL_DIR

public static final String PROPERTY_RECOVERY_JOURNAL_DIR
See Also:
Constant Field Values

PROPERTY_RECOVERY_SYNC_ON_COMMIT

public static final String PROPERTY_RECOVERY_SYNC_ON_COMMIT
See Also:
Constant Field Values

LOG_FILE_SUFFIX

public static final String LOG_FILE_SUFFIX
See Also:
Constant Field Values

BAK_FILE_SUFFIX

public static final String BAK_FILE_SUFFIX
See Also:
Constant Field Values

LCK_FILE

public static final String LCK_FILE
See Also:
Constant Field Values

LOG_ENTRY_HEADER_LEN

public static final int LOG_ENTRY_HEADER_LEN
the length of the header of each entry: entryType + transactionId + length

See Also:
Constant Field Values

LOG_ENTRY_BASE_LEN

public static final int LOG_ENTRY_BASE_LEN
header length + trailing back link

See Also:
Constant Field Values

DEFAULT_MAX_SIZE

public static final int DEFAULT_MAX_SIZE
default maximum journal size

See Also:
Constant Field Values
Constructor Detail

Journal

public Journal(BrokerPool pool,
               File directory)
        throws EXistException
Throws:
EXistException
Method Detail

initialize

public void initialize()
                throws EXistException,
                       ReadOnlyException
Throws:
EXistException
ReadOnlyException

writeToLog

public void writeToLog(Loggable loggable)
                throws TransactionException
Write a log entry to the journalling log.

Parameters:
loggable -
Throws:
TransactionException

lastWrittenLsn

public long lastWrittenLsn()
Returns the last LSN physically written to the journal.

Returns:
last written LSN

flushToLog

public void flushToLog(boolean fsync)
Flush the current buffer to disk. If fsync is true, a sync will be called on the file to force all changes to disk.

Parameters:
fsync - forces all changes to disk if true and syncMode is set to SYNC_ON_COMMIT.

flushToLog

public void flushToLog(boolean fsync,
                       boolean forceSync)
Flush the current buffer to disk. If fsync is true, a sync will be called on the file to force all changes to disk.

Parameters:
fsync - forces all changes to disk if true and syncMode is set to SYNC_ON_COMMIT.
forceSync - force changes to disk even if syncMode doesn't require it.

checkpoint

public void checkpoint(long txnId,
                       boolean switchLogFiles)
                throws TransactionException
Write a checkpoint record to the journal and flush it. If switchLogFiles is true, a new journal will be started, but only if the file is larger than MIN_REPLACE. The old log is removed.

Parameters:
txnId -
switchLogFiles -
Throws:
TransactionException

setCurrentFileNum

public void setCurrentFileNum(int fileNum)
Set the file number of the last file used.

Parameters:
fileNum - the log file number

switchFiles

public void switchFiles()
                 throws LogException
Create a new journal with a larger file number than the previous file.

Throws:
LogException

close

public void close()

findLastFile

public static final int findLastFile(File[] files)
Find the journal file with the highest file number.

Parameters:
files -

getFiles

public File[] getFiles()
Returns all journal files found in the data directory.

Returns:
all journal files

getFile

public File getFile(int fileNum)
Returns the file corresponding to the specified file number.

Parameters:
fileNum -

shutdown

public void shutdown(long txnId,
                     boolean checkpoint)
Shut down the journal. This will write a checkpoint record to the log, so recovery manager knows the file has been closed in a clean way.

Parameters:
txnId -

setInRecovery

public void setInRecovery(boolean value)
Called to signal that the db is currently in recovery phase, so no output should be written.

Parameters:
value -


Copyright (C) Wolfgang Meier. All rights reserved.