org.h2.log
Class LogSystem

java.lang.Object
  extended by org.h2.log.LogSystem

public class LogSystem
extends java.lang.Object

The transaction log system is responsible for the write ahead log mechanism used in this database. A number of LogFile objects are used (one for each file).


Field Summary
static int LOG_WRITTEN
          This special log position means that the log entry has been written.
 
Constructor Summary
LogSystem(Database database, java.lang.String fileNamePrefix, boolean readOnly, java.lang.String accessMode, PageStore pageStore)
          Create new transaction log object.
 
Method Summary
 void add(Session session, DiskFile file, Record record)
          Add an log entry to the last transaction log file.
 void addTruncate(Session session, DiskFile file, int storageId, int recordId, int blockCount)
          Add a truncate entry.
 void checkpoint()
          Flush all data to the transaction log files as well as to the data files and and switch log files.
 void close(boolean checkpoint)
          Close all log files.
 void commit(Session session)
          Commit the current transaction of the given session.
 boolean containsInDoubtTransactions()
          Check if there are any in-doubt transactions.
 void flush()
          Flush all pending changes to the transaction log files.
 ObjectArray<LogFile> getActiveLogFiles()
          Get all active log files.
 boolean getFlushOnEachCommit()
          Check if flush-on-each-commit is enabled.
 ObjectArray<InDoubtTransaction> getInDoubtTransactions()
          Get the list of in-doubt transactions.
 java.lang.String getWritePos()
          Get the write position.
 void invalidateIndexSummary()
          Write a log entry meaning the index summary is invalid.
 void open()
          Open all existing transaction log files and create a new one if required.
 void prepareCommit(Session session, java.lang.String transaction)
          Prepare a transaction.
 boolean recover()
          Roll back any uncommitted transactions if required, and apply committed changed to the data files.
 void setDisabled(boolean disabled)
          Enable or disable the transaction log
 void setFlushOnEachCommit(boolean b)
          Enable or disable-flush-on-each-commit.
 void setMaxLogSize(long maxSize)
          Set the maximum log file size in megabytes.
 void setReadOnly(boolean readOnly)
          Set the read only flag for this log system.
 void sync()
          Flush the transaction log file and sync the data to disk.
 void updateKeepFiles(int incrementDecrement)
          Increment or decrement the flag to keep (not delete) old log files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_WRITTEN

public static final int LOG_WRITTEN
This special log position means that the log entry has been written.

See Also:
Constant Field Values
Constructor Detail

LogSystem

public LogSystem(Database database,
                 java.lang.String fileNamePrefix,
                 boolean readOnly,
                 java.lang.String accessMode,
                 PageStore pageStore)
Create new transaction log object. This will not open or create files yet.

Parameters:
database - the database
fileNamePrefix - the name of the database file
readOnly - if the log should be opened in read-only mode
accessMode - the file access mode (r, rw, rws, rwd)
pageStore - the page store
Method Detail

setMaxLogSize

public void setMaxLogSize(long maxSize)
Set the maximum log file size in megabytes.

Parameters:
maxSize - the new maximum log file size

containsInDoubtTransactions

public boolean containsInDoubtTransactions()
Check if there are any in-doubt transactions.

Returns:
true if there are

close

public void close(boolean checkpoint)
           throws java.sql.SQLException
Close all log files.

Parameters:
checkpoint - if a checkpoint should be written
Throws:
java.sql.SQLException

recover

public boolean recover()
                throws java.sql.SQLException
Roll back any uncommitted transactions if required, and apply committed changed to the data files.

Returns:
if recovery was needed
Throws:
java.sql.SQLException

open

public void open()
          throws java.sql.SQLException
Open all existing transaction log files and create a new one if required.

Throws:
java.sql.SQLException

getInDoubtTransactions

public ObjectArray<InDoubtTransaction> getInDoubtTransactions()
Get the list of in-doubt transactions.

Returns:
the list

prepareCommit

public void prepareCommit(Session session,
                          java.lang.String transaction)
                   throws java.sql.SQLException
Prepare a transaction.

Parameters:
session - the session
transaction - the name of the transaction
Throws:
java.sql.SQLException

commit

public void commit(Session session)
            throws java.sql.SQLException
Commit the current transaction of the given session.

Parameters:
session - the session
Throws:
java.sql.SQLException

flush

public void flush()
           throws java.sql.SQLException
Flush all pending changes to the transaction log files.

Throws:
java.sql.SQLException

addTruncate

public void addTruncate(Session session,
                        DiskFile file,
                        int storageId,
                        int recordId,
                        int blockCount)
                 throws java.sql.SQLException
Add a truncate entry.

Parameters:
session - the session
file - the disk file
storageId - the storage id
recordId - the id of the first record
blockCount - the number of blocks
Throws:
java.sql.SQLException

add

public void add(Session session,
                DiskFile file,
                Record record)
         throws java.sql.SQLException
Add an log entry to the last transaction log file.

Parameters:
session - the session
file - the file
record - the record to log
Throws:
java.sql.SQLException

checkpoint

public void checkpoint()
                throws java.sql.SQLException
Flush all data to the transaction log files as well as to the data files and and switch log files.

Throws:
java.sql.SQLException

getActiveLogFiles

public ObjectArray<LogFile> getActiveLogFiles()
Get all active log files.

Returns:
the list of log files

setFlushOnEachCommit

public void setFlushOnEachCommit(boolean b)
Enable or disable-flush-on-each-commit.

Parameters:
b - the new value

getFlushOnEachCommit

public boolean getFlushOnEachCommit()
Check if flush-on-each-commit is enabled.

Returns:
true if it is

sync

public void sync()
          throws java.sql.SQLException
Flush the transaction log file and sync the data to disk.

Throws:
java.sql.SQLException

setDisabled

public void setDisabled(boolean disabled)
Enable or disable the transaction log

Parameters:
disabled - true if the log should be switched off

setReadOnly

public void setReadOnly(boolean readOnly)
Set the read only flag for this log system.

Parameters:
readOnly - the new value

invalidateIndexSummary

public void invalidateIndexSummary()
                            throws java.sql.SQLException
Write a log entry meaning the index summary is invalid.

Throws:
java.sql.SQLException

updateKeepFiles

public void updateKeepFiles(int incrementDecrement)
Increment or decrement the flag to keep (not delete) old log files.

Parameters:
incrementDecrement - (1 to increment, -1 to decrement)

getWritePos

public java.lang.String getWritePos()
Get the write position.

Returns:
the write position