Top Description Fields Constructors Methods
org.apache.derby.impl.store.raw.log

public Class FileLogger

extends Object
implements Logger
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.store.raw.log.Logger
Imports
org.apache.derby.shared.common.reference.SQLState, .MessageId, org.apache.derby.impl.store.raw.log.LogCounter, .LogRecord, .StreamLogScan, org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.iapi.store.raw.RawStoreFactory, .Compensation, .ContainerHandle, .LockingPolicy, .Loggable, .Page, .RePreparable, .Undoable, org.apache.derby.iapi.store.raw.log.LogInstant, .Logger, .LogScan, org.apache.derby.iapi.store.raw.xact.RawTransaction, .TransactionFactory, .TransactionId, org.apache.derby.iapi.services.io.FormatIdOutputStream, .ArrayInputStream, .ArrayOutputStream, .DynamicByteArrayOutputStream, .LimitObjectInput, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.iapi.util.ByteArray, java.io.IOException, org.apache.derby.impl.store.raw.data.InitPageOperation

Write log records to a log file as a stream (ie. log records added to the end of the file, no concept of pages).

The format of a log record that is not a compensation operation is

See Also
LogRecord

Field Summary

Modifier and TypeField and Description
protected byte[]
private LogToFile
private FormatIdOutputStream
private ArrayInputStream
private DynamicByteArrayOutputStream
private LogRecord

Constructor Summary

AccessConstructor and Description
public
FileLogger(LogToFile logFactory)

Make a new Logger with its own log record buffers MT - not needed for constructor

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the logger.

public void
flush(LogInstant
flush log up to here
where
)

Implements org.apache.derby.iapi.store.raw.log.Logger.flush.

Flush the log up to the given log instant.

public void
flushAll()

Implements org.apache.derby.iapi.store.raw.log.Logger.flushAll.

Flush all outstanding log to disk.

public synchronized LogInstant

Returns:

the instant in the log that can be used to identify the log record
logAndDo
(RawTransaction
the transaction logging the change
xact
,
Loggable
the log operation
operation
)

Implements org.apache.derby.iapi.store.raw.log.Logger.logAndDo.

Writes out a log record to the log stream, and call its doMe method to apply the change to the rawStore.

public LogInstant

Returns:

the instant in the log that can be used to identify the log record
logAndUndo
(RawTransaction
the transaction logging the change
xact
,
Compensation
the compensation log operation
compensation
,
LogInstant
the log instant of the operation that is to be rolled back
undoInstant
,
LimitObjectInput
optional data input for the compenastion doMe method
in
)

Implements org.apache.derby.iapi.store.raw.log.Logger.logAndUndo.

Writes out a compensation log record to the log stream, and call its doMe method to undo the change of a previous log operation.

protected Loggable

Returns:

the log operation that is the next in the scan, or null if no more log operation in the log scan
readLogRecord
(StreamLogScan
an opened log scan
scan
,
int
estimated size of the log record
size
)

Read the next log record from the scan.

protected long

Returns:

the log instant of the next log record (or the instant just after the last log record). This is used to determine where the log truly ends
redo
(RawTransaction recoveryTransaction, TransactionFactory
- the transaction factory
transFactory
,
StreamLogScan redoScan, long
- if checkpoint seen, starting from this point on, apply redo if necessary
redoLWM
,
long ttabInstant)

Recovery Redo loop.

public void
reprepare(RawTransaction
is the transaction performing the re-prepare
t
,
TransactionId
is the transaction ID to be re-prepared
prepareId
,
LogInstant
is where the log instant (inclusive) where the re-prepare should stop.
prepareStopAt
,
LogInstant
is the log instant (inclusive) where re-prepare should begin, this is normally the log instant of the last log record of the transaction that is to be re-prepare. If null, then re-prepare starts from the end of the log.
prepareStartAt
)

Implements org.apache.derby.iapi.store.raw.log.Logger.reprepare.

During recovery re-prepare a transaction.

public void
undo(RawTransaction
the transaction that needs to be rolled back
t
,
TransactionId
the transaction ID
undoId
,
LogInstant
the last log record that should be rolled back
undoStopAt
,
LogInstant
the first log record that should be rolled back
undoStartAt
)

Implements org.apache.derby.iapi.store.raw.log.Logger.undo.

Undo a part of or the entire transaction.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

encryptionBufferback to summary
protected byte[] encryptionBuffer
logFactoryback to summary
private LogToFile logFactory
logicalOutback to summary
private FormatIdOutputStream logicalOut
logInback to summary
private ArrayInputStream logIn
logOutputBufferback to summary
private DynamicByteArrayOutputStream logOutputBuffer
logRecordback to summary
private LogRecord logRecord

Constructor Detail

FileLoggerback to summary
public FileLogger(LogToFile logFactory)

Make a new Logger with its own log record buffers MT - not needed for constructor

Method Detail

closeback to summary
public void close() throws IOException

Close the logger. MT - caller provide synchronization (RESOLVE: not called by anyone ??)

flushback to summary
public void flush(LogInstant where) throws StandardException

Implements org.apache.derby.iapi.store.raw.log.Logger.flush.

Flush the log up to the given log instant.

MT - not needed, wrapper method

Parameters
where:LogInstant

Doc from org.apache.derby.iapi.store.raw.log.Logger.flush.

flush log up to here

Exceptions
StandardException:
cannot sync log file
flushAllback to summary
public void flushAll() throws StandardException

Implements org.apache.derby.iapi.store.raw.log.Logger.flushAll.

Flush all outstanding log to disk.

MT - not needed, wrapper method

Exceptions
StandardException:
cannot sync log file
logAndDoback to summary
public synchronized LogInstant logAndDo(RawTransaction xact, Loggable operation) throws StandardException

Implements org.apache.derby.iapi.store.raw.log.Logger.logAndDo.

Writes out a log record to the log stream, and call its doMe method to apply the change to the rawStore.
Any optional data the doMe method need is first written to the log stream using operation.writeOptionalData, then whatever is written to the log stream is passed back to the operation for the doMe method.

MT - there could be multiple threads running in the same raw transactions and they can be calling the same logger to log different log operations. This whole method is synchronized to make sure log records are logged one at a time.

Parameters
xact:RawTransaction

the transaction logging the change

operation:Loggable

the log operation

Returns:LogInstant

the instant in the log that can be used to identify the log record

Exceptions
StandardException:
Derby Standard error policy
logAndUndoback to summary
public LogInstant logAndUndo(RawTransaction xact, Compensation compensation, LogInstant undoInstant, LimitObjectInput in) throws StandardException

Implements org.apache.derby.iapi.store.raw.log.Logger.logAndUndo.

Writes out a compensation log record to the log stream, and call its doMe method to undo the change of a previous log operation.

MT - Not needed. A transaction must be single threaded thru undo, each RawTransaction has its own logger, therefore no need to synchronize. The RawTransaction must handle synchronizing with multiple threads during rollback.

Parameters
xact:RawTransaction

the transaction logging the change

compensation:Compensation

the compensation log operation

undoInstant:LogInstant

the log instant of the operation that is to be rolled back

in:LimitObjectInput

optional data input for the compenastion doMe method

Returns:LogInstant

the instant in the log that can be used to identify the log record

Exceptions
StandardException:
Derby Standard error policy
readLogRecordback to summary
protected Loggable readLogRecord(StreamLogScan scan, int size) throws IOException, StandardException, ClassNotFoundException

Read the next log record from the scan.

MT - caller must provide synchronization (right now, it is only called in recovery to find the checkpoint log record. When this method is called by a more general audience, MT must be revisited).

Parameters
scan:StreamLogScan

an opened log scan

size:int

estimated size of the log record

Returns:Loggable

the log operation that is the next in the scan, or null if no more log operation in the log scan

Exceptions
IOException:
Error reading the log file
StandardException:
Standard Derby error policy
ClassNotFoundException:
log corrupted
redoback to summary
protected long redo(RawTransaction recoveryTransaction, TransactionFactory transFactory, StreamLogScan redoScan, long redoLWM, long ttabInstant) throws IOException, StandardException, ClassNotFoundException

Recovery Redo loop.

The log stream is scanned from the beginning (or from the undo low water mark of a checkpoint) forward until the end. The purpose of the redo pass is to repeat history, i.e, to repeat exactly the same set of changes the rawStore went thru right before it stopped. With each log record that is encountered in the redo pass:

  1. if it isFirst(), then the transaction factory is called upon to create a new transaction object.
  2. if it needsRedo(), its doMe() is called (if it is a compensation operation, then the undoable operation needs to be created first before the doMe is called).
  3. if it isComplete(), then the transaction object is closed.

MT - caller provides synchronization

Parameters
transFactory:TransactionFactory

- the transaction factory

redoLWM:long

- if checkpoint seen, starting from this point on, apply redo if necessary

Returns:long

the log instant of the next log record (or the instant just after the last log record). This is used to determine where the log truly ends

Exceptions
IOException:
error reading log file
StandardException:
Standard Derby error policy
ClassNotFoundException:
log file corrupted
See Also
LogToFile#recover
reprepareback to summary
public void reprepare(RawTransaction t, TransactionId prepareId, LogInstant prepareStopAt, LogInstant prepareStartAt) throws StandardException

Implements org.apache.derby.iapi.store.raw.log.Logger.reprepare.

During recovery re-prepare a transaction.

After redo() and undo(), this routine is called on all outstanding in-doubt (prepared) transactions. This routine re-acquires all logical write locks for operations in the xact, and then modifies the transaction table entry to make the transaction look as if it had just been prepared following startup after recovery.

Parameters
t:RawTransaction

is the transaction performing the re-prepare

prepareId:TransactionId

is the transaction ID to be re-prepared

prepareStopAt:LogInstant

is where the log instant (inclusive) where the re-prepare should stop.

prepareStartAt:LogInstant

is the log instant (inclusive) where re-prepare should begin, this is normally the log instant of the last log record of the transaction that is to be re-prepare. If null, then re-prepare starts from the end of the log.

Exceptions
StandardException:
Standard exception policy.
undoback to summary
public void undo(RawTransaction t, TransactionId undoId, LogInstant undoStopAt, LogInstant undoStartAt) throws StandardException

Implements org.apache.derby.iapi.store.raw.log.Logger.undo.

Undo a part of or the entire transaction. Begin rolling back the log record at undoStartAt and stopping at (inclusive) the log record at undoStopAt.

MT - Not needed. A transaction must be single threaded thru undo, each RawTransaction has its own logger, therefore no need to synchronize. The RawTransaction must handle synchronizing with multiple threads during rollback.

Parameters
t:RawTransaction

the transaction that needs to be rolled back

undoId:TransactionId

the transaction ID

undoStopAt:LogInstant

the last log record that should be rolled back

undoStartAt:LogInstant

the first log record that should be rolled back

Exceptions
StandardException:
Standard Derby error policy
See Also
Logger#undo