java.lang.Runnable
, LogShipper
public class AsynchronousLogShipper extends java.lang.Thread implements LogShipper
Does asynchronous shipping of log records from the master to the slave being replicated to. The implementation does not ship log records as soon as they become available in the log buffer (synchronously), instead it does log shipping in the following two-fold scenarios 1) Periodically (i.e.) at regular intervals of time. 2) when a request is sent from the master controller (force flushing of the log buffer). 3) when a notification is received from the log shipper about a log buffer element becoming full and the load on the log buffer so warrants a ship.
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_FORCEFLUSH_TIMEOUT |
The number of millis a call to forceFlush will wait before giving
up sending a chunk of log to the slave
|
private ReplicationMessage |
failedChunk |
Store the log chunk that failed during a previous shipping attempt
so that it can be re-shipped to the slave.
|
private long |
failedChunkHighestInstant |
The highest log instant in failedChunk
|
private static int |
FI_HIGH |
Fill information value indicative of a high load in the log buffer.
|
private static int |
FI_LOW |
Fill information value indicative of a low load in the log buffer.
|
private java.lang.Object |
forceFlushSemaphore |
Used to synchronize forceFlush calls
|
private long |
highestShippedInstant |
The highest log instant shipped so far
|
private long |
lastShippingTime |
Will store the time at which the last shipping happened.
|
private ReplicationLogBuffer |
logBuffer |
Replication log buffer that contains the log records that need to
be transmitted to the slave.
|
private MasterController |
masterController |
The master controller that initialized this log shipper.
|
private static long |
MAX |
If the fill information is less than FI_LOW the log shipper will ship
with a MAX ms delay or when a buffer becomes full whichever comes
first.
|
private long |
maxShippingInterval |
Minimum interval (in milliseconds) between log shipping.
|
private static long |
MIN |
If the fill information (obtained from the log buffer) is less than
FI_HIGH but greater than FI_LOW the log shipper will ship with a MIN ms delay.
|
private long |
minShippingInterval |
Minimum interval (in milliseconds) between log shipping.
|
private java.lang.Object |
objLSTSync |
Object used to synchronize on while the log shipper thread
is moved into the wait state, or while notifying it.
|
private ReplicationLogger |
repLogger |
|
private long |
shippingInterval |
Time interval (in milliseconds) at which the log shipping takes place.
|
private boolean |
stopShipping |
Indicates whether a stop shipping request has been sent.
|
private ReplicationMessageTransmit |
transmitter |
Replication message transmitter that is used for the network
transmission of the log records retrieved from the log buffer
(on the master) to the slave being replicated to.
|
Constructor | Description |
---|---|
AsynchronousLogShipper(ReplicationLogBuffer logBuffer,
ReplicationMessageTransmit transmitter,
MasterController masterController,
ReplicationLogger repLogger) |
Constructor initializes the log buffer, the replication message
transmitter, the shipping interval and the master controller.
|
Modifier and Type | Method | Description |
---|---|---|
private long |
calculateSIfromFI() |
Will be used to calculate the shipping interval based on the fill
information obtained from the log buffer.
|
void |
flushBuffer() |
Transmits all the log records in the log buffer to the slave.
|
void |
flushedInstance(long latestInstanceFlushedToDisk) |
updates the information about the latest instance of the log record
that has been flushed to the disk.
|
void |
forceFlush() |
Transmits a chunk of log record from the log buffer to the slave, used
by the master controller when the log buffer is full and some space
needs to be freed for further log records.
|
long |
getHighestShippedInstant() |
Get the highest log instant shipped so far
|
private void |
getLogShipperProperties() |
Load relevant system properties: max and min log shipping interval
|
void |
run() |
Ships log records from the log buffer to the slave being replicated to.
|
private boolean |
shipALogChunk() |
Retrieves a chunk of log records, if available, from the log buffer and
transmits them to the slave.
|
void |
stopLogShipment() |
Stop shipping log records.
|
void |
workToDo() |
Used to notify the log shipper that a log buffer element is full.
|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
private final ReplicationLogBuffer logBuffer
private ReplicationMessageTransmit transmitter
private long shippingInterval
private long minShippingInterval
MIN
private long maxShippingInterval
MAX
private long lastShippingTime
private volatile boolean stopShipping
private MasterController masterController
private java.lang.Object objLSTSync
private java.lang.Object forceFlushSemaphore
public static final int DEFAULT_FORCEFLUSH_TIMEOUT
private ReplicationMessage failedChunk
private long failedChunkHighestInstant
private long highestShippedInstant
private static final int FI_LOW
private static final int FI_HIGH
private static final long MIN
private static final long MAX
private final ReplicationLogger repLogger
public AsynchronousLogShipper(ReplicationLogBuffer logBuffer, ReplicationMessageTransmit transmitter, MasterController masterController, ReplicationLogger repLogger)
logBuffer
- the replication log buffer that contains the log record
chunks to be transmitted to the slave.transmitter
- the replication message transmitter that is used for
network transmission of retrieved log records.masterController
- The master controller that initialized this log
shipper.repLogger
- The replication logger that will write messages to
the log file (typically derby.log)public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
private boolean shipALogChunk() throws java.io.IOException, StandardException
java.io.IOException
- If an exception occurs while trying to ship the
replication message (containing the log records)
across the network.StandardException
- If an exception occurs while trying to read
log records from the log buffer.public void flushBuffer() throws java.io.IOException, StandardException
flushBuffer
in interface LogShipper
java.io.IOException
- If an exception occurs while trying to ship the
replication message (containing the log records)
across the network.StandardException
- If an exception occurs while trying to read
log records from the log buffer.public void forceFlush() throws java.io.IOException, StandardException
forceFlush
in interface LogShipper
java.io.IOException
- If an exception occurs while trying to ship the
replication message (containing the log records)
across the network.StandardException
- If an exception occurs while trying to read
log records from the log buffer.public long getHighestShippedInstant()
public void flushedInstance(long latestInstanceFlushedToDisk)
flushedInstance
in interface LogShipper
latestInstanceFlushedToDisk
- a long that contains the latest
instance of the log record that has been flushed to the disk.public void stopLogShipment()
public void workToDo()
workToDo
in interface LogShipper
private long calculateSIfromFI()
private void getLogShipperProperties()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.