Class FileLogger
- All Implemented Interfaces:
Logger
The format of a log record that is not a compensation operation is
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]
private LogToFile
private FormatIdOutputStream
private ArrayInputStream
private DynamicByteArrayOutputStream
private LogRecord
-
Constructor Summary
ConstructorsConstructorDescriptionFileLogger
(LogToFile logFactory) Make a new Logger with its own log record buffers MT - not needed for constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.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.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.
-
Field Details
-
logRecord
-
encryptionBuffer
protected byte[] encryptionBuffer -
logOutputBuffer
-
logicalOut
-
logIn
-
logFactory
-
-
Constructor Details
-
FileLogger
Make a new Logger with its own log record buffers MT - not needed for constructor
-
-
Method Details
-
close
Close the logger. MT - caller provide synchronization (RESOLVE: not called by anyone ??)- Throws:
IOException
-
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.
- Specified by:
logAndDo
in interfaceLogger
- Parameters:
xact
- the transaction logging the changeoperation
- the log operation- Returns:
- the instant in the log that can be used to identify the log record
- Throws:
StandardException
- Derby Standard error policy
-
logAndUndo
public LogInstant logAndUndo(RawTransaction xact, Compensation compensation, LogInstant undoInstant, LimitObjectInput in) throws StandardException 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.
- Specified by:
logAndUndo
in interfaceLogger
- Parameters:
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 method- Returns:
- the instant in the log that can be used to identify the log record
- Throws:
StandardException
- Derby Standard error policy
-
flush
Flush the log up to the given log instant.MT - not needed, wrapper method
- Specified by:
flush
in interfaceLogger
- Parameters:
where
- flush log up to here- Throws:
StandardException
- cannot sync log file
-
flushAll
Flush all outstanding log to disk.MT - not needed, wrapper method
- Specified by:
flushAll
in interfaceLogger
- Throws:
StandardException
- cannot sync log file
-
reprepare
public void reprepare(RawTransaction t, TransactionId prepareId, LogInstant prepareStopAt, LogInstant prepareStartAt) throws StandardException 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.
- Specified by:
reprepare
in interfaceLogger
- Parameters:
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.- Throws:
StandardException
- Standard exception policy.
-
undo
public void undo(RawTransaction t, TransactionId undoId, LogInstant undoStopAt, LogInstant undoStartAt) throws StandardException 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.
- Specified by:
undo
in interfaceLogger
- Parameters:
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 back- Throws:
StandardException
- Standard Derby error policy- See Also:
-
redo
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:
- if it isFirst(), then the transaction factory is called upon to create a new transaction object.
- 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).
- if it isComplete(), then the transaction object is closed.
MT - caller provides synchronization
- Parameters:
transFactory
- - the transaction factoryredoLWM
- - if checkpoint seen, starting from this point on, apply redo if necessary- 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
- Throws:
StandardException
- Standard Derby error policyIOException
- error reading log fileClassNotFoundException
- log file corrupted- See Also:
-
readLogRecord
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
- an opened log scansize
- estimated size of the log record- Returns:
- the log operation that is the next in the scan, or null if no more log operation in the log scan
- Throws:
IOException
- Error reading the log fileStandardException
- Standard Derby error policyClassNotFoundException
- log corrupted
-