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
org.apache.derby.impl.store.raw.log.LogAccessFile
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | |
| private int | |
| private long | |
| private int | |
| 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). |
| 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[] |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected byte[] | Returns: The byte[] containing data+optional_data of the log record read by the last call to next(). Only returns meaningful information if isLogRecord() returns true.Method to get the data byte[] read by the last call to next(). |
| protected int | Returns: The number of bytes in the byte[] returned by getData() for the log record read by the last call to next(). Only returns meaningful information if isLogRecord() returns true.
|
| protected long | Returns: The instant of the log record read by the last call to next(). Only returns meaningful information if isLogRecord() returns true.
|
| protected boolean | Returns: true if next() has been called and the end of the log chunk has not yet been reached. Returns the same answer as the last call to next() did. Use isLogFileSwitch() and isLogRecord() to find out if the current log record indicates a log file switch or is a normal log record.Used to determine whether or not the last call to next() was successful. |
| protected void | init(byte[]
A chunk of log records received from the
master logToScan)Set all variables to default values, and makes logToScan the byte[] that will be scanned for log records. |
| protected boolean | Returns: true if the last call to next() found a log record indicating a log file switch has taken place on the master.Used to determine whether the last call to next() found a log file switch |
| protected boolean | Returns: true if the last call to next() found a normal log record.Used to determine whether the last call to next() read a log record |
| protected boolean | Returns: true if a log record was successfully read, false if end of logToScan has been reached.Read the next log record in logToScan. |
| private void | retrieveBytes(byte[]
The byte[] copied to readInto, int The number of bytes copied from logToScan to readInto length)Copy length number of bytes from logToScan into readInto. |
| private int | |
| private long |
| currentData | back to summary |
|---|---|
| private byte[] currentData | |
| currentDataOffset | back to summary |
|---|---|
| private int currentDataOffset | |
| currentInstant | back to summary |
|---|---|
| private long currentInstant | |
| currentPosition | back to summary |
|---|---|
| private int currentPosition | |
| hasInfo | back to summary |
|---|---|
| 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. when next() has thrown a StandardException) | |
| isLogSwitch | back to summary |
|---|---|
| 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; | |
| logToScan | back to summary |
|---|---|
| private byte[] logToScan | |
| ReplicationLogScan | back to summary |
|---|---|
| protected ReplicationLogScan() | |
| getData | back to summary |
|---|---|
| protected byte[] getData() throws NoSuchElementException Method to get the data byte[] read by the last call to next(). Note that this byte[] contains both byte[] data and byte[] optional_data from LogAccessFile. To split this byte[] into data and optional_data, we would need to create a Loggable object from it because the log does not provide information on where to split. There is no need to split since this byte[] will only be written to the slave log anyway. If it was split, LogAccessFile would simply merge them when writing to file.
| |
| getDataLength | back to summary |
|---|---|
protected int getDataLength() throws NoSuchElementException
| |
| getInstant | back to summary |
|---|---|
protected long getInstant() throws NoSuchElementException
| |
| hasValidInformation | back to summary |
|---|---|
| protected boolean hasValidInformation() Used to determine whether or not the last call to next() was successful.
| |
| init | back to summary |
|---|---|
| protected void init(byte[] logToScan) Set all variables to default values, and makes logToScan the byte[] that will be scanned for log records.
| |
| isLogFileSwitch | back to summary |
|---|---|
| protected boolean isLogFileSwitch() throws NoSuchElementException Used to determine whether the last call to next() found a log file switch
| |
| isLogRecord | back to summary |
|---|---|
| protected boolean isLogRecord() throws NoSuchElementException Used to determine whether the last call to next() read a log record
| |
| next | back to summary |
|---|---|
| protected 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: If there are no more log records in logToScan (returns false) or a problem occurs (throws StandardException): setting hasInfo = false
| |
| retrieveBytes | back to summary |
|---|---|
| private void retrieveBytes(byte[] readInto, int length) throws StandardException Copy length number of bytes from logToScan into readInto. Starts to copy from currentPosition. Also increments currentPosition by length.
| |
| retrieveInt | back to summary |
|---|---|
| private int retrieveInt() throws StandardException Read an int from logToScan. Also increments currentPosition by 4 (the number of bytes in an int).
| |
| retrieveLong | back to summary |
|---|---|
| private long retrieveLong() throws StandardException Read a long from logToScan. Also increments currentPosition by 8 (the number of bytes in a long).
| |