public class FileLogger extends java.lang.Object implements Logger
The format of a log record that is not a compensation operation is
LogRecord
Format ID | no formatId, format is implied by the log file format and the log record content. |
Purpose | the log record and optional data |
Upgrade | |
Disk Layout | Log Record (see org.apache.derby.impl.store.raw.log.LogRecord) length(int) length of optional data optionalData(byte[length]) optional data written by the log record |
Modifier and Type | Field and Description |
---|---|
protected byte[] |
encryptionBuffer |
private LogToFile |
logFactory |
private FormatIdOutputStream |
logicalOut |
private ArrayInputStream |
logIn |
private DynamicByteArrayOutputStream |
logOutputBuffer |
private LogRecord |
logRecord |
Constructor and Description |
---|
FileLogger(LogToFile logFactory)
Make a new Logger with its own log record buffers
MT - not needed for constructor
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the logger.
|
void |
flush(LogInstant where)
Flush the log up to the given log instant.
|
void |
flushAll()
Flush all outstanding log to disk.
|
LogInstant |
logAndDo(RawTransaction xact,
Loggable operation)
Writes out a log record to the log stream, and call its doMe method to
apply the change to the rawStore.
|
LogInstant |
logAndUndo(RawTransaction xact,
Compensation compensation,
LogInstant undoInstant,
LimitObjectInput in)
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 |
readLogRecord(StreamLogScan scan,
int size)
Read the next log record from the scan.
|
protected long |
redo(RawTransaction recoveryTransaction,
TransactionFactory transFactory,
StreamLogScan redoScan,
long redoLWM,
long ttabInstant)
Recovery Redo loop.
|
void |
reprepare(RawTransaction t,
TransactionId prepareId,
LogInstant prepareStopAt,
LogInstant prepareStartAt)
During recovery re-prepare a transaction.
|
void |
undo(RawTransaction t,
TransactionId undoId,
LogInstant undoStopAt,
LogInstant undoStartAt)
Undo a part of or the entire transaction.
|
private LogRecord logRecord
protected byte[] encryptionBuffer
private DynamicByteArrayOutputStream logOutputBuffer
private FormatIdOutputStream logicalOut
private ArrayInputStream logIn
private LogToFile logFactory
public FileLogger(LogToFile logFactory)
public void close() throws java.io.IOException
java.io.IOException
public LogInstant logAndDo(RawTransaction xact, Loggable operation) throws StandardException
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.
logAndDo
in interface Logger
xact
- the transaction logging the changeoperation
- the log operationStandardException
- Derby Standard error policypublic LogInstant logAndUndo(RawTransaction xact, Compensation compensation, LogInstant undoInstant, LimitObjectInput in) throws StandardException
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.
logAndUndo
in interface Logger
xact
- the transaction logging the changecompensation
- the compensation log operationundoInstant
- the log instant of the operation that is to be
rolled backin
- optional data input for the compenastion doMe methodStandardException
- Derby Standard error policypublic void flush(LogInstant where) throws StandardException
MT - not needed, wrapper method
flush
in interface Logger
where
- flush log up to hereStandardException
- cannot sync log filepublic void flushAll() throws StandardException
MT - not needed, wrapper method
flushAll
in interface Logger
StandardException
- cannot sync log filepublic void reprepare(RawTransaction t, TransactionId prepareId, LogInstant prepareStopAt, LogInstant prepareStartAt) throws StandardException
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.
reprepare
in interface Logger
t
- is the transaction performing the re-prepareprepareId
- is the transaction ID to be re-preparedprepareStopAt
- is where the log instant (inclusive) where the
re-prepare should stop.prepareStartAt
- 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.StandardException
- Standard exception policy.public void undo(RawTransaction t, TransactionId undoId, LogInstant undoStopAt, LogInstant undoStartAt) throws StandardException
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.
undo
in interface Logger
t
- the transaction that needs to be rolled backundoId
- the transaction IDundoStopAt
- the last log record that should be rolled backundoStartAt
- the first log record that should be rolled backStandardException
- Standard Derby error policyLogger.undo(org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.iapi.store.raw.xact.TransactionId, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.raw.log.LogInstant)
protected long redo(RawTransaction recoveryTransaction, TransactionFactory transFactory, StreamLogScan redoScan, long redoLWM, long ttabInstant) throws java.io.IOException, StandardException, java.lang.ClassNotFoundException
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:
MT - caller provides synchronization
transFactory
- - the transaction factoryredoLWM
- - if checkpoint seen, starting from this point
on, apply redo if necessaryStandardException
- Standard Derby error policyjava.io.IOException
- error reading log filejava.lang.ClassNotFoundException
- log file corruptedLogToFile.recover(org.apache.derby.iapi.store.raw.data.DataFactory, org.apache.derby.iapi.store.raw.xact.TransactionFactory)
protected Loggable readLogRecord(StreamLogScan scan, int size) throws java.io.IOException, StandardException, java.lang.ClassNotFoundException
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).
scan
- an opened log scansize
- estimated size of the log recordjava.io.IOException
- Error reading the log fileStandardException
- Standard Derby error policyjava.lang.ClassNotFoundException
- log corruptedApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.