Class Scan
- java.lang.Object
-
- org.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
Fields Modifier and Type Field Description 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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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 Derby error policyjava.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 interfaceStreamLogScan
- Parameters:
input
- the ArrayInputStream to put the log recordtranId
- if non-null, only log record that equals tranId will be returned. If null, log records are not filtered on transaction Id.groupmask
- if non-zero, only log record whose Loggable's group value is included in the groupmask is returned. groupmask can be a bit wise OR of many Loggable groups. If zero, log records are not filtered on the Loggable's group.- Returns:
- the next LogRecord, or null if the end of the scan has been reached.
- Throws:
StandardException
- Standard Derby 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 interfaceStreamLogScan
- Parameters:
instant
- the position to reset to- Throws:
java.io.IOException
- scan cannot access the log at the new position.StandardException
- standard Derby 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 interfaceStreamLogScan
- 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. After the scan has been closed, the end of the last log record will be returned except when the scan ended in an empty log file. In that case, the start of this empty log file will be returned. (This is done to make sure new log records are inserted into the newest log file.)- Specified by:
getLogRecordEnd
in interfaceStreamLogScan
- 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 interfaceStreamLogScan
- 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 interfaceStreamLogScan
- 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 interfaceStreamLogScan
-
-