This is an implementation of the replication slave controller service. The service is booted when this instance of Derby will have the replication slave role for this database.
Note
The current version of the class is far from complete. Code to control the replication slave behavior will be added as more parts of the replication functionality is added to Derby.
SlaveFactory
| Modifier and Type | Class and Description |
|---|---|
| private class | SlaveController.
Thread that listens for incoming messages from the master and applies chunks of log records to the local log files. |
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private static final int | |
| private volatile long | highestLogInstant
The instant of the latest log record received from the master and processed so far. |
| private volatile boolean | inReplicationSlaveMode
Whether or not replication slave mode is still on. |
| private SlaveController. | |
| private ReplicationLogScan | |
| private LogToFile | |
| private RawStoreFactory | |
| private ReplicationMessageReceive | |
| private ReplicationLogger | |
| private SlaveAddress | |
| private volatile boolean | startupSuccessful
Whether or not this SlaveController has been successfully started, including setting up a connection with the master and starting the log receiver thread. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | boot(boolean
Currently ignored create, Properties Properties used to start the service in the
correct mode properties)Implements org. Used by Monitor.bootServiceModule to start the service. |
| public boolean | Returns: true if slave repliation is specified, meaning that this MasterController is a suitable implementation for the SlaveFactory service. False otherwise.The properties used to start replication startParams)Implements org. Used by Monitor.bootServiceModule to check if this class is usable for replication. |
| private void | |
| public void | failover()
Implements org. Used to turn this slave instance of the database into a normal instance that clients can connect to, assuming that the connection with the master is down. |
| private String | Returns: a String containing the host name of the slave.Used to return the host name of the slave. |
| private int | Returns: an Integer that represents the port number of the slave.Used to return the port number of the slave. |
| private void | handleDisconnect(Exception
The reason the connection to the master was lost e)Write the reason for the lost connection to the log (derby.log) and reconnect with the master. |
| private void | handleFatalException(Exception
The fatal exception that is the reason for calling
this method e)Handles fatal errors for slave replication functionality. |
| private boolean | Returns: true if the network connection is working, false otherwiseCheck if the repliation network connection to the master is working |
| public boolean | isStarted()
Implements org. Check whether or not slave replication mode has been successfully started. |
| private boolean | Returns: true if a connection has been set up with the master, false if the connection attempt timed out.Establish a connection with the replication master. |
| private void | startLogReceiverThread()
Starts the LogReceiverThread that will listen for chunks of log records from the master and apply the log records to the local log file. |
| public void | startSlave(RawStoreFactory
The RawStoreFactory for the database rawStore, LogFactory The LogFactory ensuring recoverability for this
database logFac)Implements org. Start slave replication. |
| public void | stop()
Implements org. Will tear down the replication slave service. |
| private void | |
| public void | stopSlave(boolean
Determines whether or not an exception should
be thrown when this method is called while the network
connection to the master is up. forcedStop)Implements org. Stop replication slave mode. |
| private void |
| dbname | back to summary |
|---|---|
| private String dbname | |
| DEFAULT_SOCKET_TIMEOUT | back to summary |
|---|---|
| private static final int DEFAULT_SOCKET_TIMEOUT | |
| highestLogInstant | back to summary |
|---|---|
| private volatile long highestLogInstant The instant of the latest log record received from the master and processed so far. Used to check that master and slave log files are in synch | |
| inReplicationSlaveMode | back to summary |
|---|---|
| private volatile boolean inReplicationSlaveMode Whether or not replication slave mode is still on. Will be set to false when slave replication is shut down. The value of this variable is checked after every timeout when trying to set up a connection to the master, and by the thread that applies log chunks received from the master. | |
| logReceiverThread | back to summary |
|---|---|
| private SlaveController. | |
| logScan | back to summary |
|---|---|
| private ReplicationLogScan logScan | |
| logToFile | back to summary |
|---|---|
| private LogToFile logToFile | |
| rawStoreFactory | back to summary |
|---|---|
| private RawStoreFactory rawStoreFactory | |
| receiver | back to summary |
|---|---|
| private ReplicationMessageReceive receiver | |
| repLogger | back to summary |
|---|---|
| private ReplicationLogger repLogger | |
| slaveAddr | back to summary |
|---|---|
| private SlaveAddress slaveAddr | |
| startupSuccessful | back to summary |
|---|---|
| private volatile boolean startupSuccessful Whether or not this SlaveController has been successfully started, including setting up a connection with the master and starting the log receiver thread. The client connection that initiated slave replication mode on this database will not report that slave mode was successfully started (i.e., it will hang) until startupSuccessful has been set to true | |
| SlaveController | back to summary |
|---|---|
| public SlaveController() Empty constructor required by Monitor.bootServiceModule | |
| boot | back to summary |
|---|---|
| public void boot(boolean create, Properties properties) throws StandardException Implements org. Used by Monitor.bootServiceModule to start the service. It will set up basic variables
| |
| 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 slave replication mode is specified in startParams by checking that a property with key SlaveFactory.REPLICATION_MODE has the value SlaveFactory.SLAVE_MODE.
| |
| doFailover | back to summary |
|---|---|
| private void doFailover() Performs failover on this database. May be called because a failover command has been received from the master, or because a client has requested a failover after the network connection with the master has been lost.
| |
| failover | back to summary |
|---|---|
| public void failover() throws StandardException Implements org. Doc from org. Used to turn this slave instance of the database into a normal instance that clients can connect to, assuming that the connection with the master is down. This is typically done in cases where a fatal error has happened on the master instance of the database, or when the master database is unreachable due to network problems. By calling failover, this slave instance of the database will be recovered so that all committed operations that have been received from the master are reflected here. On the other hand, operations from transactions where the commit log record has not been received from the master will not be reflected. Note that even though an operation has been executed (and even committed) on the master, it is not neccessarily reflected in the slave instance of the database. This depends on the replication strategy used by the MasterFactory.
| |
| getHostName | back to summary |
|---|---|
| private String getHostName() Used to return the host name of the slave.
| |
| getPortNumber | back to summary |
|---|---|
| private int getPortNumber() Used to return the port number of the slave.
| |
| handleDisconnect | back to summary |
|---|---|
| private void handleDisconnect(Exception e) Write the reason for the lost connection to the log (derby.log) and reconnect with the master. Once the network is up and running, a new LogReceiverThread is started. The method returns without doing anything if inReplicationSlaveMode=false, which means that stopSlave() has been called by another thread.
| |
| handleFatalException | back to summary |
|---|---|
| private void handleFatalException(Exception e) Handles fatal errors for slave replication functionality. These are errors that requires us to stop replication. Calling this method has the following effects: 1) Debug messages are written to the log file (usually derby.log) if ReplicationLogger#LOG_REPLICATION_MESSAGES is true. 2) If the network connection is up, the master is notified of the problem. 3) All slave replication functionality is stopped, and the database is then shut down without being booted. The method will return without doing anything if inReplicationSlaveMode=false, meaning that stopSlave has been called.
| |
| isConnectedToMaster | back to summary |
|---|---|
| private boolean isConnectedToMaster() Check if the repliation network connection to the master is working
| |
| isStarted | back to summary |
|---|---|
| public boolean isStarted() Implements org. Doc from org. Check whether or not slave replication mode has been successfully started.
| |
| setupConnection | back to summary |
|---|---|
| private boolean setupConnection() throws StandardException Establish a connection with the replication master. Listens for a connection on the slavehost/port for DEFAULT_SOCKET_TIMEOUT milliseconds.
| |
| startLogReceiverThread | back to summary |
|---|---|
| private void startLogReceiverThread() Starts the LogReceiverThread that will listen for chunks of log records from the master and apply the log records to the local log file. | |
| startSlave | back to summary |
|---|---|
| public void startSlave(RawStoreFactory rawStore, LogFactory logFac) throws StandardException Implements org. Start slave replication. This method establishes a network connection with the associated replication master and starts a thread that applies operations received from the master (in the form of log records) to the local slave database.
| |
| stop | back to summary |
|---|---|
| public void stop() Implements org. Will tear down the replication slave service. | |
| stopSlave | back to summary |
|---|---|
| private void stopSlave() throws StandardException Will perform all work that is needed to stop replication | |
| stopSlave | back to summary |
|---|---|
| public void stopSlave(boolean forcedStop) throws StandardException Implements org. Doc from org. Stop replication slave mode. Causes the database to abort the boot process, and should only be used when shutting down this database. If forcedStop is false, the method will fail with an exception if connected with the master. If forcedStop is true, the slave will be shut down even if connected to the master. A forcedStop value of true should only be used by system shutdown.
| |
| teardownNetwork | back to summary |
|---|---|
| private void teardownNetwork() | |
| Access | Constructor and Description |
|---|---|
| pack-priv | SlaveLogReceiverThread()
Creates a new instance of SlaveLogReceiverThread with a debugging-friendly thread name. |
| Modifier and Type | Method and Description |
|---|---|
| private void | handleLogChunk(byte[]
A chunk of log records received from the
master logChunk)Parses a chunk of log received from the master, and applies the individual log records to the local log file. |
| public void | run()
Overrides java. Implements java. This method is run by the thread when it executes. |
| SlaveLogReceiverThread | back to summary |
|---|---|
| pack-priv SlaveLogReceiverThread() Creates a new instance of SlaveLogReceiverThread with a debugging-friendly thread name. | |
| handleLogChunk | back to summary |
|---|---|
| private void handleLogChunk(byte[] logChunk) throws StandardException Parses a chunk of log received from the master, and applies the individual log records to the local log file.
| |
| run | back to summary |
|---|---|
| public void run() Overrides java. Implements java. Doc from java. This method is run by the thread when it executes. Subclasses of This method is not intended to be invoked directly. If this thread is a
platform thread created with a | |