Class Scan
java.lang.Object
org.apache.derby.impl.store.raw.log.Scan
- All Implemented Interfaces:
LogScan
,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
FieldsModifier and TypeFieldDescriptionstatic final byte
static final byte
private long
private long
private long
static final byte
private boolean
private long
private LogToFile
private StorageRandomAccessFile
private byte
private long
-
Constructor Summary
ConstructorsConstructorDescriptionScan
(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
Modifier and TypeMethodDescriptionvoid
close()
Close the scan.long
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.Return the log instant the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.long
Return the log instant at the end of the log record on the current LogFile in the form of a log instant.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
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 Details
-
FORWARD
public static final byte FORWARD- See Also:
-
BACKWARD
public static final byte BACKWARD- See Also:
-
BACKWARD_FROM_LOG_END
public static final byte BACKWARD_FROM_LOG_END- See Also:
-
scan
-
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 Details
-
Scan
public Scan(LogToFile logFactory, long startAt, LogInstant stopAt, byte direction) throws 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 policyIOException
- cannot access the log at the new position.
-
-
Method Details
-
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:
-
getNextRecordBackward
private LogRecord getNextRecordBackward(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException, IOException, 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
IOException
ClassNotFoundException
- See Also:
-
getNextRecordForward
private LogRecord getNextRecordForward(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException, IOException, 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
IOException
ClassNotFoundException
- See Also:
-
resetPosition
Reset the scan to the given LogInstant.- Specified by:
resetPosition
in interfaceStreamLogScan
- Parameters:
instant
- the position to reset to- Throws:
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
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
-