public class Scan extends java.lang.Object implements StreamLogScan
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
Modifier and Type | Field and 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 and 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.
|
Modifier and Type | Method and 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.
|
public static final byte FORWARD
public static final byte BACKWARD
public static final byte BACKWARD_FROM_LOG_END
private StorageRandomAccessFile scan
private LogToFile logFactory
private long currentLogFileNumber
private long currentLogFileLength
private long knownGoodLogEnd
private long currentInstant
private long stopAt
private byte scanDirection
private boolean fuzzyLogEnd
public Scan(LogToFile logFactory, long startAt, LogInstant stopAt, byte direction) throws java.io.IOException, StandardException
StandardException
- Standard Derby error policyjava.io.IOException
- cannot access the log at the new position.public LogRecord getNextRecord(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException
getNextRecord
in interface StreamLogScan
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.StandardException
- Standard Derby error policyStreamLogScan.getNextRecord(org.apache.derby.iapi.services.io.ArrayInputStream, org.apache.derby.iapi.store.raw.xact.TransactionId, int)
private LogRecord getNextRecordBackward(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException, java.io.IOException, java.lang.ClassNotFoundException
StandardException
java.io.IOException
java.lang.ClassNotFoundException
Side effects include:
on a successful read, setting currentInstant.
on a log file switch, setting currentLogFileNumber.
private LogRecord getNextRecordForward(ArrayInputStream input, TransactionId tranId, int groupmask) throws StandardException, java.io.IOException, java.lang.ClassNotFoundException
StandardException
java.io.IOException
java.lang.ClassNotFoundException
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.
public void resetPosition(LogInstant instant) throws java.io.IOException, StandardException
resetPosition
in interface StreamLogScan
instant
- the position to reset tojava.io.IOException
- scan cannot access the log at the new position.StandardException
- standard Derby error policypublic long getInstant()
getInstant
in interface StreamLogScan
public long getLogRecordEnd()
getLogRecordEnd
in interface StreamLogScan
public boolean isLogEndFuzzy()
isLogEndFuzzy
in interface StreamLogScan
public LogInstant getLogInstant()
getLogInstant
in interface StreamLogScan
public void close()
close
in interface StreamLogScan
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.