org.apache.derby.impl.store.replication.master
Class AsynchronousLogShipper
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.derby.impl.store.replication.master.AsynchronousLogShipper
-
- All Implemented Interfaces:
- java.lang.Runnable
public class AsynchronousLogShipper extends java.lang.ThreadDoes 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
Fields Modifier and Type Field and Description static intDEFAULT_FORCEFLUSH_TIMEOUTThe number of millis a call to forceFlush will wait before giving up sending a chunk of log to the slave
-
Constructor Summary
Constructors Constructor and 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidflushBuffer()Transmits all the log records in the log buffer to the slave.voidflushedInstance(long latestInstanceFlushedToDisk)updates the information about the latest instance of the log record that has been flushed to the disk.voidforceFlush()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.longgetHighestShippedInstant()Get the highest log instant shipped so farvoidrun()Ships log records from the log buffer to the slave being replicated to.voidstopLogShipment()Stop shipping log records.voidworkToDo()Used to notify the log shipper that a log buffer element is full.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
DEFAULT_FORCEFLUSH_TIMEOUT
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- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AsynchronousLogShipper
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- 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)
-
-
Method Detail
-
run
public void 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.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
flushBuffer
public void flushBuffer() throws java.io.IOException, StandardExceptionTransmits all the log records in the log buffer to the slave.- Throws:
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.
-
forceFlush
public void forceFlush() throws java.io.IOException, StandardExceptionTransmits 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.- Throws:
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.
-
getHighestShippedInstant
public long getHighestShippedInstant()
Get the highest log instant shipped so far- Returns:
- the highest log instant shipped so far
-
flushedInstance
public void flushedInstance(long latestInstanceFlushedToDisk)
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- a long that contains the latest instance of the log record that has been flushed to the disk.
-
stopLogShipment
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.
-
workToDo
public void 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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG