org.apache.derby.impl.store.raw.log
Class Scan

java.lang.Object
  extended byorg.apache.derby.impl.store.raw.log.Scan
All Implemented Interfaces:
LogScan, StreamLogScan

public class Scan
extends java.lang.Object
implements StreamLogScan

Scan the the log which is implemented by a series of log files.n This log scan knows how to move across log file if it is positioned at the boundary of a log file and needs to getNextRecord.

        4 bytes - length of user data, i.e. N
        8 bytes - long representing log instant
        N bytes of supplied data
        4 bytes - length of user data, i.e. N
        


Field Summary
static byte BACKWARD
           
static byte BACKWARD_FROM_LOG_END
           
private  long currentInstant
           
private  long currentLogFileLength
           
private  long currentLogFileNumber
           
static byte FORWARD
           
private  boolean fuzzyLogEnd
           
private  long knownGoodLogEnd
           
private  LogToFile logFactory
           
private  StorageRandomAccessFile scan
           
private  byte scanDirection
           
private  long stopAt
           
 
Constructor Summary
Scan(LogToFile logFactory, long startAt, LogInstant stopAt, byte direction)
          For backward scan, we expect a scan positioned at the end of the next log record.
 
Method Summary
 void close()
          Close the scan.
 long getInstant()
          Return the log instant (as an integer) the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.
 LogInstant getLogInstant()
          Return the log instant the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.
 long getLogRecordEnd()
          Return the log instant at the end of the log record on the current LogFile in the form of a log instant
 LogRecord getNextRecord(ArrayInputStream input, TransactionId tranId, int groupmask)
          Read the next log record.
private  LogRecord getNextRecordBackward(ArrayInputStream input, TransactionId tranId, int groupmask)
          Read the previous log record.
private  LogRecord getNextRecordForward(ArrayInputStream input, TransactionId tranId, int groupmask)
          Read the next log record.
 boolean isLogEndFuzzy()
          returns true if there is partially writen log records before the crash in the last log file.
 void resetPosition(LogInstant instant)
          Reset the scan to the given LogInstant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORWARD

public static final byte FORWARD
See Also:
Constant Field Values

BACKWARD

public static final byte BACKWARD
See Also:
Constant Field Values

BACKWARD_FROM_LOG_END

public static final byte BACKWARD_FROM_LOG_END
See Also:
Constant Field Values

scan

private StorageRandomAccessFile scan

logFactory

private LogToFile logFactory

currentLogFileNumber

private long currentLogFileNumber

currentLogFileLength

private long currentLogFileLength

knownGoodLogEnd

private long knownGoodLogEnd

currentInstant

private long currentInstant

stopAt

private long stopAt

scanDirection

private byte scanDirection

fuzzyLogEnd

private boolean fuzzyLogEnd
Constructor Detail

Scan

public Scan(LogToFile logFactory,
            long startAt,
            LogInstant stopAt,
            byte direction)
     throws java.io.IOException,
            StandardException
For backward scan, we expect a scan positioned at the end of the next log record. For forward scan, we expect a scan positioned at the beginning of the next log record. For forward flushed scan, we expect stopAt to be the instant for the first not-flushed log record. Like any forward scan, we expect a scan positioned at the beginning of the next log record.

Throws:
StandardException - Standard Cloudscape error policy
java.io.IOException - cannot access the log at the new position.
Method Detail

getNextRecord

public LogRecord getNextRecord(ArrayInputStream input,
                               TransactionId tranId,
                               int groupmask)
                        throws StandardException
Read the next log record. Switching log to a previous log file if necessary, Resize the input stream byte array if necessary.

Specified by:
getNextRecord in interface StreamLogScan
Parameters:
input - the ArrayInputStream to put the log record
tranId - if non-null, only log record that equals tranId will be returned. If null, log records are not filtered on transaction Id.
Returns:
the next LogRecord, or null if the end of the scan has been reached.
Throws:
StandardException - Standard Cloudscape error policy
See Also:
StreamLogScan.getNextRecord(org.apache.derby.iapi.services.io.ArrayInputStream, org.apache.derby.iapi.store.raw.xact.TransactionId, int)

getNextRecordBackward

private LogRecord getNextRecordBackward(ArrayInputStream input,
                                        TransactionId tranId,
                                        int groupmask)
                                 throws StandardException,
                                        java.io.IOException,
                                        java.lang.ClassNotFoundException
Read the previous log record. Switching log to a previous log file if necessary, Resize the input stream byte array if necessary.

Returns:
the previous LogRecord, or null if the end of the scan has been reached.
Throws:
StandardException
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Side effects include: on a successful read, setting currentInstant. on a log file switch, setting currentLogFileNumber.

getNextRecordForward

private LogRecord getNextRecordForward(ArrayInputStream input,
                                       TransactionId tranId,
                                       int groupmask)
                                throws StandardException,
                                       java.io.IOException,
                                       java.lang.ClassNotFoundException
Read the next log record. Switching log to a previous log file if necessary, Resize the input stream byte array if necessary.

Returns:
the next LogRecord, or null if the end of the scan has been reached.
Throws:
StandardException
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Side effects include: on a successful read, setting currentInstant, knownGoodLogEnd on a log file switch, setting currentLogFileNumber, currentLogFileLength. on detecting a fuzzy log end that needs clearing, it will call logFactory to clear the fuzzy log end.

resetPosition

public void resetPosition(LogInstant instant)
                   throws java.io.IOException,
                          StandardException
Reset the scan to the given LogInstant.

Specified by:
resetPosition in interface StreamLogScan
Parameters:
instant - the position to reset to
Throws:
java.io.IOException - scan cannot access the log at the new position.
StandardException - cloudscape standard error policy

getInstant

public long getInstant()
Return the log instant (as an integer) the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.

Specified by:
getInstant in interface StreamLogScan
Returns:
INVALID_LOG_INSTANT if no records have been returned yet or the scan has completed.

getLogRecordEnd

public long getLogRecordEnd()
Return the log instant at the end of the log record on the current LogFile in the form of a log instant

Specified by:
getLogRecordEnd in interface StreamLogScan
Returns:
INVALID_LOG_INSTANT if this is not a FORWARD scan or, no record have been returned yet or the scan has completed.

isLogEndFuzzy

public boolean isLogEndFuzzy()
returns true if there is partially writen log records before the crash in the last log file. Partiall wrires are identified during forward redo scans for log recovery.

Specified by:
isLogEndFuzzy in interface StreamLogScan
Returns:
true if fuzzy log end found during forward scan, this happens if there was a partially written log records before the crash.

getLogInstant

public LogInstant getLogInstant()
Return the log instant the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.

Specified by:
getLogInstant in interface StreamLogScan
Returns:
null if no records have been returned yet or the scan has completed.

close

public void close()
Close the scan.

Specified by:
close in interface StreamLogScan


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.