org.apache.derby.impl.store.logical.log
Class LogicalLog

java.lang.Object
  extended byorg.apache.derby.impl.store.logical.log.LogicalLog
All Implemented Interfaces:
java.lang.Cloneable, org.apache.derby.iapi.store.raw.log.LogicalLog, java.io.Serializable

public class LogicalLog
extends java.lang.Object
implements org.apache.derby.iapi.store.raw.log.LogicalLog, java.lang.Cloneable

A class implementing a classical linked list of log elements. It is serializable so that it can be sent through a outputstream and cloneable because of the need to avoid race conditions. The Logical Log Records are encased in LogElements to add the support of nextElement needed in the linked list. The logical log has a fixed maximum size and functions as a circular buffer

Author:
Egil S¿rensen
See Also:
Serialized Form

Constructor Summary
LogicalLog()
          Standard constructor, creates an empty LogicalLog with no elements.
LogicalLog(LogicalLogRecord lr)
          Constructor with a logical log record as a parameter.
 
Method Summary
 void add(LogicalLogRecord lr)
          Adds a Logical Log Record to the Logical Log.
 void addElements(org.apache.derby.iapi.store.raw.log.LogicalLog log)
          Adds an entire logical log to this log, used in LogReceiver when an entire log is received and then added to the current log.
 java.util.ArrayList divide()
          Divide the log into an ArrayList with logs with a maximum size of 3000.
 LogicalLog flush()
          flush() is a method added to remove race conditions between the add() method and the need to empty the Logical Log after it has been sent using the LogShipper.
 void flushLogToDisk()
          Flushes the logical log to disk.
 LogicalLogRecord getFirst()
          Get the first log element of the Logical Log
 LogicalLogRecord getLast()
          Get the last log element of the Logical Log
 LogicalLogRecord getNext()
          Get the next (if any) log element of the Logical Log
 boolean hasMoreElements()
          Checks if this Logical Log has more elements
static LogicalLog readFromDisk()
          Read the log from disk.
 void reset()
          Reset pointers in the log, moving the currentElement-pointer to firstElement
 LogicalLogRecord rewind(int lsn)
          Rewind the log to a selected lsn and returns this log record.
 int size()
          Gets the size of this Logical Log
 LogicalLog split(int lsn)
          Split the log around a chosen lsn.
 java.lang.String toString()
          Writes the log to screen, written for debug purposes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogicalLog

public LogicalLog()
Standard constructor, creates an empty LogicalLog with no elements.


LogicalLog

public LogicalLog(LogicalLogRecord lr)
Constructor with a logical log record as a parameter. Creates a LogicalLog with the provided log record as the first and last object. Using this constructor is the same as doing: LogicalLog log = new LogicalLog(); log.add(lr);

Parameters:
lr - The Logical Log Record to be added to the new Logical Log
Method Detail

flush

public LogicalLog flush()
flush() is a method added to remove race conditions between the add() method and the need to empty the Logical Log after it has been sent using the LogShipper. The current Logical Log is cloned and returned and this Logical Log is then emptied and ready for further use.

Returns:
Returns a clone of the current Logical Log
See Also:
LogShipper

add

public void add(LogicalLogRecord lr)
Adds a Logical Log Record to the Logical Log. If the lsn of the log to be added is <= than the last lsn recorded in the log it is not added. This is to ensure that the log is written in a strict incremental way

Specified by:
add in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Parameters:
lr - The Logical Log Record to be added.

addElements

public void addElements(org.apache.derby.iapi.store.raw.log.LogicalLog log)
Adds an entire logical log to this log, used in LogReceiver when an entire log is received and then added to the current log. The log is traversed and each log record is added one by one.

Specified by:
addElements in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Parameters:
log - The logical log to be added to this logical log
See Also:
LogReceiver

getFirst

public LogicalLogRecord getFirst()
Get the first log element of the Logical Log

Specified by:
getFirst in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Returns:
The first LogicalLogRecord of this log

getLast

public LogicalLogRecord getLast()
Get the last log element of the Logical Log

Specified by:
getLast in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Returns:
The last LogicalLogRecord of this log

getNext

public LogicalLogRecord getNext()
Get the next (if any) log element of the Logical Log

Specified by:
getNext in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Returns:
The next LogicalLogRecord of this log

rewind

public LogicalLogRecord rewind(int lsn)
Rewind the log to a selected lsn and returns this log record. Added to enhance the scan needed during a transaction-abort.

Parameters:
lsn - The lsn of the log to be found
Returns:
The log record corresponding to the lsn

hasMoreElements

public boolean hasMoreElements()
Checks if this Logical Log has more elements

Specified by:
hasMoreElements in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Returns:
boolean

size

public int size()
Gets the size of this Logical Log

Specified by:
size in interface org.apache.derby.iapi.store.raw.log.LogicalLog
Returns:
The size of the log

toString

public java.lang.String toString()
Writes the log to screen, written for debug purposes


flushLogToDisk

public void flushLogToDisk()
Flushes the logical log to disk. Every flush writes to a new log file with the lsn of the first log record as the files extension


reset

public void reset()
Reset pointers in the log, moving the currentElement-pointer to firstElement

Specified by:
reset in interface org.apache.derby.iapi.store.raw.log.LogicalLog

split

public LogicalLog split(int lsn)
Split the log around a chosen lsn. Returns a log with all log records newer than (with a higher lsn than) the lsn provided.

Parameters:
lsn - The lsn to split the log on
Returns:
The last part of the splitted list

divide

public java.util.ArrayList divide()
Divide the log into an ArrayList with logs with a maximum size of 3000. This method is needed by the catchupservice to ensure that the logs sent to the new HotStandby are not too large.

Returns:
An ArrayList of logs with a max size of 3000

readFromDisk

public static LogicalLog readFromDisk()
Read the log from disk. The log to be read needs to be located in the folder logicallog/logical.log

Returns:
The logical log read from disk