Top Description Fields Constructors Methods
org.apache.derby.impl.store.raw.log

public Class Scan

extends Object
implements StreamLogScan
Class Inheritance
All Implemented Interfaces
org.apache.derby.impl.store.raw.log.StreamLogScan, org.apache.derby.iapi.store.raw.log.LogScan
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.io.ArrayInputStream, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.raw.xact.TransactionId, org.apache.derby.impl.store.raw.log.LogCounter, .LogRecord, .StreamLogScan, org.apache.derby.io.StorageRandomAccessFile, java.io.IOException, org.apache.derby.iapi.store.raw.Loggable

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

Modifier and TypeField and Description
public static final byte
public static final byte
private long
private long
private long
public static final byte
private boolean
private long
private LogToFile
private StorageRandomAccessFile
private byte
private long

Constructor Summary

AccessConstructor and Description
public
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

Modifier and TypeMethod and Description
public void
public long
getInstant()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.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.

public LogInstant
getLogInstant()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.getLogInstant.

Return the log instant the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.

public long
getLogRecordEnd()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.getLogRecordEnd.

Return the log instant at the end of the log record on the current LogFile in the form of a log instant.

public LogRecord

Returns:

the next LogRecord, or null if the end of the scan has been reached.
getNextRecord
(ArrayInputStream
the ArrayInputStream to put the log record
input
,
TransactionId
if non-null, only log record that equals tranId will be returned. If null, log records are not filtered on transaction Id.
tranId
,
int
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.
groupmask
)

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.getNextRecord.

Read the next log record.

private LogRecord

Returns:

the previous LogRecord, or null if the end of the scan has been reached.
getNextRecordBackward
(ArrayInputStream input, TransactionId tranId, int groupmask)

Read the previous log record.

private LogRecord

Returns:

the next LogRecord, or null if the end of the scan has been reached.
getNextRecordForward
(ArrayInputStream input, TransactionId tranId, int groupmask)

Read the next log record.

public boolean
isLogEndFuzzy()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.isLogEndFuzzy.

returns true if there is partially writen log records before the crash in the last log file.

public void
resetPosition(LogInstant
the position to reset to
instant
)

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.resetPosition.

Reset the scan to the given LogInstant.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BACKWARDback to summary
public static final byte BACKWARD
BACKWARD_FROM_LOG_ENDback to summary
public static final byte BACKWARD_FROM_LOG_END
currentInstantback to summary
private long currentInstant
currentLogFileLengthback to summary
private long currentLogFileLength
currentLogFileNumberback to summary
private long currentLogFileNumber
FORWARDback to summary
public static final byte FORWARD
fuzzyLogEndback to summary
private boolean fuzzyLogEnd
knownGoodLogEndback to summary
private long knownGoodLogEnd
logFactoryback to summary
private LogToFile logFactory
scanback to summary
private StorageRandomAccessFile scan
scanDirectionback to summary
private byte scanDirection
stopAtback to summary
private long stopAt

Constructor Detail

Scanback to summary
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.

Exceptions
IOException:
cannot access the log at the new position.
StandardException:
Standard Derby error policy

Method Detail

closeback to summary
public void close()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.close.

Close the scan.

getInstantback to summary
public long getInstant()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.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.

Returns:long

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.getInstant.

INVALID_LOG_INSTANT if no records have been returned yet or the scan has completed.

getLogInstantback to summary
public LogInstant getLogInstant()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.getLogInstant.

Return the log instant the scan is currently on - this is the log instant of the log record that was returned by getNextRecord.

Returns:LogInstant

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.getLogInstant.

null if no records have been returned yet or the scan has completed.

getLogRecordEndback to summary
public long getLogRecordEnd()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.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.)

Returns:long

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.getLogRecordEnd.

INVALID_LOG_INSTANT if this is not a FORWARD scan or, no record have been returned yet or the scan has completed.

getNextRecordback to summary
public LogRecord getNextRecord(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.getNextRecord.

Read the next log record. Switching log to a previous log file if necessary, Resize the input stream byte array if necessary.

Parameters
input:ArrayInputStream

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.getNextRecord.

the ArrayInputStream to put the log record

tranId:TransactionId

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.getNextRecord.

if non-null, only log record that equals tranId will be returned. If null, log records are not filtered on transaction Id.

groupmask:int

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.getNextRecord.

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:LogRecord

the next LogRecord, or null if the end of the scan has been reached.

Exceptions
StandardException:
Standard Derby error policy
See Also
StreamLogScan#getNextRecord
getNextRecordBackwardback to summary
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:LogRecord

the previous LogRecord, or null if the end of the scan has been reached.

See Also
Side effects include: on a successful read, setting currentInstant. on a log file switch, setting currentLogFileNumber.
getNextRecordForwardback to summary
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:LogRecord

the next LogRecord, or null if the end of the scan has been reached.

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.
isLogEndFuzzyback to summary
public boolean isLogEndFuzzy()

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.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.

Returns:boolean

Doc from org.apache.derby.impl.store.raw.log.StreamLogScan.isLogEndFuzzy.

true if fuzzy log end found during forward scan, this happens if there was a partially written log records before the crash.

resetPositionback to summary
public void resetPosition(LogInstant instant) throws IOException, StandardException

Implements org.apache.derby.impl.store.raw.log.StreamLogScan.resetPosition.

Reset the scan to the given LogInstant.

Parameters
instant:LogInstant

the position to reset to

Exceptions
IOException:
scan cannot access the log at the new position.
StandardException:
standard Derby error policy