Top Description Fields Constructors Methods
org.apache.derby.impl.store.replication.master

public Class AsynchronousLogShipper

extends Thread
implements LogShipper
Class Inheritance
All Implemented Interfaces
org.apache.derby.impl.store.replication.master.LogShipper
Imports
java.io.IOException, java.util.NoSuchElementException, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.Property, .SQLState, org.apache.derby.iapi.services.property.PropertyUtil, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.impl.store.replication.ReplicationLogger, org.apache.derby.impl.store.replication.buffer.ReplicationLogBuffer, org.apache.derby.impl.store.replication.net.ReplicationMessage, .ReplicationMessageTransmit, org.apache.derby.iapi.util.InterruptStatus

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.

Field Summary

Modifier and TypeField and Description
public static final 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 final int
FI_HIGH

Fill information value indicative of a high load in the log buffer.

private static final int
FI_LOW

Fill information value indicative of a low load in the log buffer.

private 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 final 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 final 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 final 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 Object
objLSTSync

Object used to synchronize on while the log shipper thread is moved into the wait state, or while notifying it.

private final ReplicationLogger
private long
shippingInterval

Time interval (in milliseconds) at which the log shipping takes place.

private volatile 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.

Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
public
AsynchronousLogShipper(ReplicationLogBuffer
the replication log buffer that contains the log record chunks to be transmitted to the slave.
logBuffer
,
ReplicationMessageTransmit
the replication message transmitter that is used for network transmission of retrieved log records.
transmitter
,
MasterController
The master controller that initialized this log shipper.
masterController
,
ReplicationLogger
The replication logger that will write messages to the log file (typically derby.log)
repLogger
)

Constructor initializes the log buffer, the replication message transmitter, the shipping interval and the master controller.

Method Summary

Modifier and TypeMethod and Description
private long

Returns:

the shipping interval based on the fill information.
calculateSIfromFI
()

Will be used to calculate the shipping interval based on the fill information obtained from the log buffer.

public void
flushBuffer()

Implements org.apache.derby.impl.store.replication.master.LogShipper.flushBuffer.

Transmits all the log records in the log buffer to the slave.

public void
flushedInstance(long
a long that contains the latest instance of the log record that has been flushed to the disk.
latestInstanceFlushedToDisk
)

Implements org.apache.derby.impl.store.replication.master.LogShipper.flushedInstance.

updates the information about the latest instance of the log record that has been flushed to the disk.

public void
forceFlush()

Implements org.apache.derby.impl.store.replication.master.LogShipper.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.

public long

Returns:

the highest log instant shipped so far
getHighestShippedInstant
()

Get the highest log instant shipped so far

private void
getLogShipperProperties()

Load relevant system properties: max and min log shipping interval

public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Ships log records from the log buffer to the slave being replicated to.

private synchronized boolean

Returns:

true if a chunk of log records was shipped. false if no log records were shipped because log buffer is empty.
shipALogChunk
()

Retrieves a chunk of log records, if available, from the log buffer and transmits them to the slave.

public void
stopLogShipment()

Stop shipping log records.

public void
workToDo()

Implements org.apache.derby.impl.store.replication.master.LogShipper.workToDo.

Used to notify the log shipper that a log buffer element is full.

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitsetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopthreadIdtoStringyield

Field Detail

DEFAULT_FORCEFLUSH_TIMEOUTback to summary
public static final 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

failedChunkback to summary
private ReplicationMessage failedChunk

Store the log chunk that failed during a previous shipping attempt so that it can be re-shipped to the slave.

failedChunkHighestInstantback to summary
private long failedChunkHighestInstant

The highest log instant in failedChunk

FI_HIGHback to summary
private static final int FI_HIGH

Fill information value indicative of a high load in the log buffer.

FI_LOWback to summary
private static final int FI_LOW

Fill information value indicative of a low load in the log buffer.

forceFlushSemaphoreback to summary
private Object forceFlushSemaphore

Used to synchronize forceFlush calls

highestShippedInstantback to summary
private long highestShippedInstant

The highest log instant shipped so far

lastShippingTimeback to summary
private long lastShippingTime

Will store the time at which the last shipping happened. Will be used to calculate the interval between the log ships upon receiving a notification from the log buffer.

logBufferback to summary
private final ReplicationLogBuffer logBuffer

Replication log buffer that contains the log records that need to be transmitted to the slave.

masterControllerback to summary
private MasterController masterController

The master controller that initialized this log shipper.

MAXback to summary
private static final 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. The delay however will not be smaller than MIN. max(MAX, DEFAULT_NUMBER_LOG_BUFFERS*MIN) is the maximum delay between a log record is committed at the master until it is replicated to the slave. Hence the default latency should be atleast greater than the maximum latency offered by the choice of MIN, hence MAX > DEFAULT_NUMBER_LOG_BUFFERS*MIN.

maxShippingIntervalback to summary
private long maxShippingInterval

Minimum interval (in milliseconds) between log shipping. Defaults to MAX, but can be configured using system property derby.replication.maxLogShippingInterval

See Also
MAX
MINback to summary
private static final 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. MIN is a value that is only as large as not to affect the performance of the master database significantly.

minShippingIntervalback to summary
private long minShippingInterval

Minimum interval (in milliseconds) between log shipping. Defaults to MIN, but can be configured using system property derby.replication.minLogShippingInterval

See Also
MIN
objLSTSyncback to summary
private Object objLSTSync

Object used to synchronize on while the log shipper thread is moved into the wait state, or while notifying it.

repLoggerback to summary
private final ReplicationLogger repLogger
shippingIntervalback to summary
private long shippingInterval

Time interval (in milliseconds) at which the log shipping takes place.

stopShippingback to summary
private volatile boolean stopShipping

Indicates whether a stop shipping request has been sent. true - stop shipping log records false - shipping can continue without interruption.

transmitterback to summary
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 Detail

AsynchronousLogShipperback to summary
public 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.

Parameters
logBuffer:ReplicationLogBuffer

the replication log buffer that contains the log record chunks to be transmitted to the slave.

transmitter:ReplicationMessageTransmit

the replication message transmitter that is used for network transmission of retrieved log records.

masterController:MasterController

The master controller that initialized this log shipper.

repLogger:ReplicationLogger

The replication logger that will write messages to the log file (typically derby.log)

Method Detail

calculateSIfromFIback to summary
private long calculateSIfromFI()

Will be used to calculate the shipping interval based on the fill information obtained from the log buffer. This method uses the following steps to arrive at the shipping interval, a) FI >= FI_HIGH return -1 (signifies that the waiting time should be 0) b) FI > FI_LOW and FI < FI_HIGH return minShippingInterval c) FI <= FI_LOW return maxShippingInterval.

Returns:long

the shipping interval based on the fill information.

flushBufferback to summary
public void flushBuffer() throws IOException, StandardException

Implements org.apache.derby.impl.store.replication.master.LogShipper.flushBuffer.

Transmits all the log records in the log buffer to the slave.

Exceptions
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.
flushedInstanceback to summary
public void flushedInstance(long latestInstanceFlushedToDisk)

Implements org.apache.derby.impl.store.replication.master.LogShipper.flushedInstance.

updates the information about the latest instance of the log record that has been flushed to the disk. Calling this method has no effect in this asynchronous implementation of the log shipper.

Parameters
latestInstanceFlushedToDisk:long

a long that contains the latest instance of the log record that has been flushed to the disk.

forceFlushback to summary
public void forceFlush() throws IOException, StandardException

Implements org.apache.derby.impl.store.replication.master.LogShipper.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.

Exceptions
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.
getHighestShippedInstantback to summary
public long getHighestShippedInstant()

Get the highest log instant shipped so far

Returns:long

the highest log instant shipped so far

getLogShipperPropertiesback to summary
private void getLogShipperProperties()

Load relevant system properties: max and min log shipping interval

runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Ships log records from the log buffer to the slave being replicated to. The log shipping happens between shipping intervals of time, the shipping interval being derived from the fill information (an indicator of load in the log buffer) obtained from the log buffer. The shipping can also be triggered in the following situations, 1) Based on notifications from the log buffer, where the fill information is again used as the basis to decide whether a shipping should happen or not 2) On a forceFlush triggered by the log buffer becoming full and the LogBufferFullException being thrown.

shipALogChunkback to summary
private synchronized boolean shipALogChunk() throws IOException, StandardException

Retrieves a chunk of log records, if available, from the log buffer and transmits them to the slave. Used for both periodic and forced shipping.

Returns:boolean

true if a chunk of log records was shipped. false if no log records were shipped because log buffer is empty.

Exceptions
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.
stopLogShipmentback to summary
public void stopLogShipment()

Stop shipping log records. If a ship is currently in progress it will not be interrupted, shipping will stop only after the current shipment is done.

workToDoback to summary
public void workToDo()

Implements org.apache.derby.impl.store.replication.master.LogShipper.workToDo.

Used to notify the log shipper that a log buffer element is full. This method would basically use the following steps to decide on the action to be taken when a notification from the log shipper is received, a) Get FI from log buffer b) If FI >= FI_HIGH b.1) notify the log shipper thread. c) Else If the time elapsed since last ship is greater than minShippingInterval c.1) notify the log shipper thread.