class ReplicationLogScan
extends java.lang.Object
Scan a chunk of log received from the master. The log chunk (byte[] logToScan) is assumed to always contain (an unknown) number of complete log records. If the last log record is incomplete, something is wrong. This will raise a StandardException, and will probably mean that replication has to be aborted. That decision is not made here, though.
When a new chunk of log records is to be scanned, ReplicationLogScan is initialized by calling init(...). Every time next() is called after that, ReplicationLogScan reads a new log record from logToScan. If next() returns true, the next log record was successfully read. The information in this last read log record either indicates that a log file switch has taken place on the master (isLogSwitch() = true) or it is a normal log record which information can be retrieved by using the get-methods (if isLogRecord() = true).
Threads: The class does not provide thread synchronization since it is assumed that only one thread will be receiving and applying log per replicated database when in slave mode. Since a ReplicationLogScan object belongs to only one slave database, this means that only one thread will access the object.
The format of the log chunk byte[] is defined in org.apache.derby.impl.store.raw.log.LogAccessFile
LogAccessFile
Modifier and Type | Field and Description |
---|---|
private byte[] |
currentData |
private int |
currentDataOffset |
private long |
currentInstant |
private int |
currentPosition |
private boolean |
hasInfo
hasInfo = true when the scan will return meaningful
information, either in the form of a log record (in which case
the above variables will be set), or when it has found a log
record indicating that a log file switch has taken place on the
master (isLogSwitch = true). hasInfo = false before next() is
called for the first time, after next() has reached the end of
logToScan and if an error occured when parsing logToScan (i.e.
|
private boolean |
isLogSwitch
true if the last read log record indicates a log switch, false
if it is a normal log record private boolean isLogSwitch;
|
private byte[] |
logToScan |
Modifier | Constructor and Description |
---|---|
protected |
ReplicationLogScan() |
Modifier and Type | Method and Description |
---|---|
protected byte[] |
getData()
Method to get the data byte[] read by the last call to next().
|
protected int |
getDataLength() |
protected long |
getInstant() |
protected boolean |
hasValidInformation()
Used to determine whether or not the last call to next() was
successful.
|
protected void |
init(byte[] logToScan)
Set all variables to default values, and makes logToScan the
byte[] that will be scanned for log records.
|
protected boolean |
isLogFileSwitch()
Used to determine whether the last call to next() found a log
file switch
|
protected boolean |
isLogRecord()
Used to determine whether the last call to next() read a log
record
|
protected boolean |
next()
Read the next log record in logToScan.
|
private void |
retrieveBytes(byte[] readInto,
int length)
Copy length number of bytes from logToScan into readInto.
|
private int |
retrieveInt()
Read an int from logToScan.
|
private long |
retrieveLong()
Read a long from logToScan.
|
private byte[] logToScan
private int currentPosition
private long currentInstant
private int currentDataOffset
private byte[] currentData
private boolean hasInfo
private boolean isLogSwitch
protected void init(byte[] logToScan)
logToScan
- A chunk of log records received from the
masterprotected boolean next() throws StandardException
Read the next log record in logToScan. The information in this log record can be read by using the getXXX methods.
Side effects:
On a successful read (return true): either...
... the scan read a log record indicating that a log file
switch has taken place on the master, in which case
isLogFileSwitch() returns true. In this case, getXXX will not
contain valid data. Asserts handle calls to these methods when
in sane mode. currentPosition is updated to point to the byte
immediately following this log file switch log record.
... or the scan read a normal log record, in which case
isLogRecord() returns true. Also sets currentInstant and
currentData, and updates currentPosition to point to the byte
immediatly following the log record. In this case, getXXX will
return meaningful information about the log record.
If there are no more log records in logToScan (returns false) or a problem occurs (throws StandardException): setting hasInfo = false
StandardException
- if logToScan is found to be corrupted.protected long getInstant() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if next() has not been called or
if there are no more log records in this chunk of log. Should
never be thrown unless ReplicationLogScan is used in a wrong
way.protected int getDataLength() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if next() has not been called or
if there are no more log records in this chunk of log. Should
never be thrown unless ReplicationLogScan is used in a wrong
way.protected byte[] getData() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if next() has not been called or
if there are no more log records in this chunk of log. Should
never be thrown unless ReplicationLogScan is used in a wrong
way.protected boolean hasValidInformation()
protected boolean isLogRecord() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if next() has not been called or
if there are no more log records in this chunk of log. Should
never be thrown unless ReplicationLogScan is used in a wrong
way.protected boolean isLogFileSwitch() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if next() has not been called or
if there are no more log records in this chunk of log. Should
never be thrown unless ReplicationLogScan is used in a wrong
way.private void retrieveBytes(byte[] readInto, int length) throws StandardException
readInto
- The byte[] copied tolength
- The number of bytes copied from logToScan to readIntoStandardException
- if there are less then length bytes
left to read in logToScan, meaning that the chunk of log is
corrupt.private int retrieveInt() throws StandardException
StandardException
- if there are less then 4 bytes left
to read in logToScan, meaning that the chunk of log is corrupt.private long retrieveLong() throws StandardException
StandardException
- if there are less then 8 bytes left
to read in logToScan, meaning that the chunk of log is corrupt.Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.