This is an implementation of the replication master controller service. The service is booted when this instance of Derby will have the replication master role for this database.
Note
The current version of the class is far from complete. Code to control the replication master behavior will be added as more parts of the replication functionality is added to Derby.
MasterFactory
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private DataFactory | |
| private String | |
| private static final int | |
| private static final int | |
| private static final int | |
| private ReplicationLogBuffer | |
| private int | |
| private LogFactory | |
| private AsynchronousLogShipper | |
| private RawStoreFactory | |
| private String | |
| private ReplicationLogger | |
| private static final int | |
| private SlaveAddress | |
| private ReplicationMessageTransmit |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | appendLog(long
the instant of the log record that was
added last to this chunk of log greatestInstant, byte[] the chunk of log records log, int offset in log to start copy from logOffset, int number of bytes to copy, starting
from logOffset logLength)Implements org. Append a chunk of log records to the log buffer. |
| public void | boot(boolean
Currently ignored create, Properties Properties used to start the service in the
correct mode. Currently initializes only the
replicationMode property. properties)Implements org. Used by Monitor.bootServiceModule to start the service. |
| public boolean | Returns: true if asynchronous replication is requested, meaning that this MasterController is a suitable implementation for the MasterFactory service. False otherwiseThe properties used to boot replication startParams)Implements org. Used by Monitor.bootServiceModule to check if this class is usable for replication. |
| public void | flushedTo(long
The highest log instant that has been flushed to
disk instant)Implements org. Used by the LogFactory to notify the replication master controller that the log records up to this instant have been flushed to disk. |
| pack-priv String | Returns: a master database nameReturns a name of a database associated with this master controller. |
| private String | Returns: a String containing the host name of the slave being connected to.Used to return the host name of the slave being connected to. |
| private void | |
| private int | Returns: an Integer that represents the port number of the slave being connected to.Used to return the port number of the slave being connected to. |
| pack-priv ReplicationMessageTransmit | Returns: an instance of the transmitter used to transmit messages to the slave.the exception which caused the log shipper to terminate
in an unexcepted manner. exception)Used to handle the exceptions (IOException and StandardException) from the log shipper. |
| private void | handleFailoverFailure(Throwable
The throwable which resulted in the aborted failover
attempt. t)used to handle the case when an attempt to failover the database fails. |
| private void | printStackAndStopMaster(Exception
the exception that needs to be handled. e)used to print the error stack for the given exception and stop the master. |
| private void | |
| public void | startFailover()
Implements org. Will perform all work needed to failover |
| public void | startMaster(RawStoreFactory
The RawStoreFactory for the database rawStore, DataFactory The DataFactory for this database dataFac, LogFactory The LogFactory ensuring recoverability for this database logFac, String The hostname of the slave slavehost, int The port the slave is listening on slaveport, String The master database that is being replicated. dbname)Implements org. Will perform all the work that is needed to set up replication. |
| public void | stop()
Implements org. Will stop the replication master service. |
| public void | stopMaster()
Implements org. Will perform all work that is needed to shut down replication. |
| private void | teardownNetwork()
Stop log shipping, notify slave that replication is stopped and tear down network connection with slave. |
| public void | workToDo()
Implements org. Used to notify the log shipper that a log buffer element is full. |
| active | back to summary |
|---|---|
| private boolean active | |
| dataFactory | back to summary |
|---|---|
| private DataFactory dataFactory | |
| dbname | back to summary |
|---|---|
| private String dbname | |
| DEFAULT_LOG_BUFFER_SIZE | back to summary |
|---|---|
| private static final int DEFAULT_LOG_BUFFER_SIZE | |
| LOG_BUFFER_SIZE_MAX | back to summary |
|---|---|
| private static final int LOG_BUFFER_SIZE_MAX | |
| LOG_BUFFER_SIZE_MIN | back to summary |
|---|---|
| private static final int LOG_BUFFER_SIZE_MIN | |
| logBuffer | back to summary |
|---|---|
| private ReplicationLogBuffer logBuffer | |
| logBufferSize | back to summary |
|---|---|
| private int logBufferSize | |
| logFactory | back to summary |
|---|---|
| private LogFactory logFactory | |
| logShipper | back to summary |
|---|---|
| private AsynchronousLogShipper logShipper | |
| rawStoreFactory | back to summary |
|---|---|
| private RawStoreFactory rawStoreFactory | |
| replicationMode | back to summary |
|---|---|
| private String replicationMode | |
| repLogger | back to summary |
|---|---|
| private ReplicationLogger repLogger | |
| SLAVE_CONNECTION_ATTEMPT_TIMEOUT | back to summary |
|---|---|
| private static final int SLAVE_CONNECTION_ATTEMPT_TIMEOUT | |
| slaveAddr | back to summary |
|---|---|
| private SlaveAddress slaveAddr | |
| transmitter | back to summary |
|---|---|
| private ReplicationMessageTransmit transmitter | |
| MasterController | back to summary |
|---|---|
| public MasterController() Empty constructor required by Monitor.bootServiceModule | |
| appendLog | back to summary |
|---|---|
| public void appendLog(long greatestInstant, byte[] log, int logOffset, int logLength) Implements org. Append a chunk of log records to the log buffer. The method is not threadsafe; only one thread should access this method at a time.
| |
| boot | back to summary |
|---|---|
| public void boot(boolean create, Properties properties) throws StandardException Implements org. Used by Monitor.bootServiceModule to start the service. Currently only used to set up the replication mode.
| |
| canSupport | back to summary |
|---|---|
| public boolean canSupport(Properties startParams) Implements org. Used by Monitor.bootServiceModule to check if this class is usable for replication. To be usable, we require that asynchronous replication is specified in startParams by checking that a property with key MasterFactory.REPLICATION_MODE has the value MasterFactory.ASYNCHRONOUS_MODE.
| |
| flushedTo | back to summary |
|---|---|
| public void flushedTo(long instant) Implements org. Used by the LogFactory to notify the replication master controller that the log records up to this instant have been flushed to disk. The master controller takes action according to the current replication strategy when this method is called. When the asynchronous replication strategy is used, the method does not force log shipping to the slave; the log records may be shipped now or later at the MasterController's discretion. However, if another strategy like 2-safe replication is implemented in the future, a call to this method may force log shipment before returning control to the caller. Currently, only asynchronous replication is supported. Not implemented yet
| |
| getDbName | back to summary |
|---|---|
| pack-priv String getDbName() Returns a name of a database associated with this master controller. Note The only purpose of the method as of now is to give a meaningful name to a log shipper thread. The log shipper thread name should contain a name of a corresponding master database, and this method is used to access it.
| |
| getHostName | back to summary |
|---|---|
| private String getHostName() Used to return the host name of the slave being connected to.
| |
| getMasterProperties | back to summary |
|---|---|
| private void getMasterProperties() Load relevant system property: replication log buffer size | |
| getPortNumber | back to summary |
|---|---|
| private int getPortNumber() Used to return the port number of the slave being connected to.
| |
| handleExceptions | back to summary |
|---|---|
| pack-priv ReplicationMessageTransmit handleExceptions(Exception exception) Used to handle the exceptions (IOException and StandardException) from the log shipper.
| |
| handleFailoverFailure | back to summary |
|---|---|
| private void handleFailoverFailure(Throwable t) throws StandardException used to handle the case when an attempt to failover the database fails.
| |
| printStackAndStopMaster | back to summary |
|---|---|
| private void printStackAndStopMaster(Exception e) used to print the error stack for the given exception and stop the master.
| |
| setupConnection | back to summary |
|---|---|
| private void setupConnection() throws StandardException Connects to the slave being replicated to.
| |
| startFailover | back to summary |
|---|---|
| public void startFailover() throws StandardException Implements org. Doc from org. Will perform all work needed to failover
| |
| startMaster | back to summary |
|---|---|
| public void startMaster(RawStoreFactory rawStore, DataFactory dataFac, LogFactory logFac, String slavehost, int slaveport, String dbname) throws StandardException Implements org. Will perform all the work that is needed to set up replication.
| |
| stop | back to summary |
|---|---|
| public void stop() Implements org. Will stop the replication master service. | |
| stopMaster | back to summary |
|---|---|
| public void stopMaster() throws StandardException Implements org. Will perform all work that is needed to shut down replication.
| |
| teardownNetwork | back to summary |
|---|---|
| private void teardownNetwork() Stop log shipping, notify slave that replication is stopped and tear down network connection with slave. | |
| workToDo | back to summary |
|---|---|
| public void workToDo() Implements org. Used to notify the log shipper that a log buffer element is full. | |