org.exist.storage.journal
Class Journal

java.lang.Object
  extended byorg.exist.storage.journal.Journal

public class Journal
extends java.lang.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 java.lang.String BAK_FILE_SUFFIX
           
static int DEFAULT_MAX_SIZE
          default maximum journal size
static java.lang.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 java.lang.String LOG_FILE_SUFFIX
           
 
Constructor Summary
Journal(BrokerPool pool, java.io.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(java.io.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.
 java.io.File getFile(int fileNum)
          Returns the file corresponding to the specified file number.
 java.io.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)
          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

LOG_FILE_SUFFIX

public static final java.lang.String LOG_FILE_SUFFIX
See Also:
Constant Field Values

BAK_FILE_SUFFIX

public static final java.lang.String BAK_FILE_SUFFIX
See Also:
Constant Field Values

LCK_FILE

public static final java.lang.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,
               java.io.File directory)
        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.
Throws:
TransactionException

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.
Throws:
TransactionException

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(java.io.File[] files)
Find the journal file with the highest file number.

Parameters:
files -

getFiles

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

Returns:
all journal files

getFile

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

Parameters:
fileNum -

shutdown

public void shutdown(long txnId)
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.