Class FlushedScan
- java.lang.Object
-
- org.apache.derby.impl.store.raw.log.FlushedScan
-
- All Implemented Interfaces:
LogScan,StreamLogScan
public class FlushedScan 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 (package private) longcurrentInstant(package private) longcurrentLogFileFirstUnflushedPosition(package private) longcurrentLogFileNumber(package private) longfirstUnflushed(package private) longfirstUnflushedFileNumber(package private) longfirstUnflushedFilePosition(package private) static intLOG_REC_LEN_BYTE_LENGTH(package private) LogToFilelogFactory(package private) intnextRecordLengthThe length of the next record.(package private) booleanopen(package private) booleanreadNextRecordLengthFlag to indicate that the length of the next log record has been read by currentLogFileHasUnflushedRecord.private StorageRandomAccessFilescan
-
Constructor Summary
Constructors Constructor Description FlushedScan(LogToFile logFactory, long startAt)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the scan.private booleancurrentLogFileHasUnflushedRecord()longgetInstant()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.LogInstantgetLogInstant()Return the log instant the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.longgetLogRecordEnd()Get the log instant that is right after the record just retrivedLogRecordgetNextRecord(ArrayInputStream input, TransactionId tranId, int groupmask)Read a log record into the byte array provided.booleanisLogEndFuzzy()returns true if there is partially writen log records before the crash in the last log file.private booleanpositionToNextRecord()voidresetPosition(LogInstant instant)Reset the scan to the given LogInstant.private voidsetCurrentLogFileFirstUnflushedPosition()private voidsetFirstUnflushed()private voidswitchLogFile()
-
-
-
Field Detail
-
scan
private StorageRandomAccessFile scan
-
logFactory
LogToFile logFactory
-
open
boolean open
-
currentLogFileNumber
long currentLogFileNumber
-
currentLogFileFirstUnflushedPosition
long currentLogFileFirstUnflushedPosition
-
currentInstant
long currentInstant
-
firstUnflushed
long firstUnflushed
-
firstUnflushedFileNumber
long firstUnflushedFileNumber
-
firstUnflushedFilePosition
long firstUnflushedFilePosition
-
LOG_REC_LEN_BYTE_LENGTH
static final int LOG_REC_LEN_BYTE_LENGTH
- See Also:
- Constant Field Values
-
nextRecordLength
int nextRecordLength
The length of the next record. Read from scan and set by currentLogFileHasUnflushedRecord. This is used to retain the length of a log record in the case currentLogFileHasUnflushedRecord reads the length and determines that some bytes in the log record are not yet flushed.
-
readNextRecordLength
boolean readNextRecordLength
Flag to indicate that the length of the next log record has been read by currentLogFileHasUnflushedRecord. This flag gets reset in two ways:- currentLogFileHasUnflushedRecord determines that the entire log record is flushed and returns true. In this case getNextRecord reads and returns the log record.
- we switch log files --due to a partial log record at the end of an old log file.
-
-
Constructor Detail
-
FlushedScan
public FlushedScan(LogToFile logFactory, long startAt) throws StandardException
- Throws:
StandardException
-
-
Method Detail
-
getNextRecord
public LogRecord getNextRecord(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException
Read a log record into the byte array provided. Resize the input stream byte array if necessary.- Specified by:
getNextRecordin 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 length of the data written into data, or -1 if the end of the scan has been reached.
- Throws:
StandardException- Standard Derby error policy
-
resetPosition
public void resetPosition(LogInstant instant) throws java.io.IOException
Reset the scan to the given LogInstant.- Specified by:
resetPositionin interfaceStreamLogScan- Parameters:
instant- the position to reset to- Throws:
java.io.IOException- scan cannot access the log at the new position.
-
getLogRecordEnd
public long getLogRecordEnd()
Get the log instant that is right after the record just retrived- Specified by:
getLogRecordEndin 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 scans for log recovery.- Specified by:
isLogEndFuzzyin interfaceStreamLogScan- Returns:
- true if fuzzy log end found during forward scan, this happens if there was a partially written log records before the crash.
-
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:
getInstantin interfaceStreamLogScan- Returns:
- INVALID_LOG_INSTANT if no records have been returned yet or the scan has completed.
-
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:
getLogInstantin interfaceStreamLogScan- Returns:
- null if no records have been returned yet or the scan has completed.
-
close
public void close()
Close the scan.- Specified by:
closein interfaceStreamLogScan
-
setFirstUnflushed
private void setFirstUnflushed() throws StandardException, java.io.IOException- Throws:
StandardExceptionjava.io.IOException
-
setCurrentLogFileFirstUnflushedPosition
private void setCurrentLogFileFirstUnflushedPosition() throws java.io.IOException- Throws:
java.io.IOException
-
switchLogFile
private void switchLogFile() throws StandardException- Throws:
StandardException
-
currentLogFileHasUnflushedRecord
private boolean currentLogFileHasUnflushedRecord() throws java.io.IOException- Throws:
java.io.IOException
-
positionToNextRecord
private boolean positionToNextRecord() throws StandardException, java.io.IOException- Throws:
StandardExceptionjava.io.IOException
-
-