ModuleControl
, ModuleSupportable
, MasterFactory
public class MasterController extends java.lang.Object implements MasterFactory, ModuleControl, ModuleSupportable
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 | Description |
---|---|---|
private boolean |
active |
|
private DataFactory |
dataFactory |
|
private java.lang.String |
dbname |
|
private static int |
DEFAULT_LOG_BUFFER_SIZE |
|
private static int |
LOG_BUFFER_SIZE_MAX |
|
private static int |
LOG_BUFFER_SIZE_MIN |
|
private ReplicationLogBuffer |
logBuffer |
|
private int |
logBufferSize |
|
private LogFactory |
logFactory |
|
private AsynchronousLogShipper |
logShipper |
|
private RawStoreFactory |
rawStoreFactory |
|
private java.lang.String |
replicationMode |
|
private ReplicationLogger |
repLogger |
|
private static int |
SLAVE_CONNECTION_ATTEMPT_TIMEOUT |
|
private SlaveAddress |
slaveAddr |
|
private ReplicationMessageTransmit |
transmitter |
ASYNCHRONOUS_MODE, MODULE, REPLICATION_MODE
Constructor | Description |
---|---|
MasterController() |
Empty constructor required by Monitor.bootServiceModule
|
Modifier and Type | Method | Description |
---|---|---|
void |
appendLog(long greatestInstant,
byte[] log,
int logOffset,
int logLength) |
Append a chunk of log records to the log buffer.
|
void |
boot(boolean create,
java.util.Properties properties) |
Used by Monitor.bootServiceModule to start the service.
|
boolean |
canSupport(java.util.Properties startParams) |
Used by Monitor.bootServiceModule to check if this class is
usable for replication.
|
void |
flushedTo(long instant) |
Used by the LogFactory to notify the replication master
controller that the log records up to this instant have been
flushed to disk.
|
(package private) java.lang.String |
getDbName() |
Returns a name of a database associated with this master
controller.
|
private java.lang.String |
getHostName() |
Used to return the host name of the slave being connected to.
|
private void |
getMasterProperties() |
Load relevant system property: replication log buffer size
|
private int |
getPortNumber() |
Used to return the port number of the slave being connected to.
|
(package private) ReplicationMessageTransmit |
handleExceptions(java.lang.Exception exception) |
Used to handle the exceptions (IOException and StandardException) from
the log shipper.
|
private void |
handleFailoverFailure(java.lang.Throwable t) |
used to handle the case when an attempt to failover the database
fails.
|
private void |
printStackAndStopMaster(java.lang.Exception e) |
used to print the error stack for the given exception and
stop the master.
|
private void |
setupConnection() |
Connects to the slave being replicated to.
|
void |
startFailover() |
Will perform all work needed to failover
|
void |
startMaster(RawStoreFactory rawStore,
DataFactory dataFac,
LogFactory logFac,
java.lang.String slavehost,
int slaveport,
java.lang.String dbname) |
Will perform all the work that is needed to set up replication.
|
void |
stop() |
Will stop the replication master service.
|
void |
stopMaster() |
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.
|
void |
workToDo() |
Used to notify the log shipper that a log buffer element is full.
|
private static final int DEFAULT_LOG_BUFFER_SIZE
private static final int LOG_BUFFER_SIZE_MIN
private static final int LOG_BUFFER_SIZE_MAX
private RawStoreFactory rawStoreFactory
private DataFactory dataFactory
private LogFactory logFactory
private ReplicationLogBuffer logBuffer
private AsynchronousLogShipper logShipper
private ReplicationMessageTransmit transmitter
private ReplicationLogger repLogger
private java.lang.String replicationMode
private SlaveAddress slaveAddr
private java.lang.String dbname
private int logBufferSize
private boolean active
private static final int SLAVE_CONNECTION_ATTEMPT_TIMEOUT
public MasterController()
public void boot(boolean create, java.util.Properties properties) throws StandardException
boot
in interface ModuleControl
create
- Currently ignoredproperties
- Properties used to start the service in the
correct mode. Currently initializes only the
replicationMode property.StandardException
- Standard Derby exception policy,
thrown on error.Monitor
,
ModuleFactory
public boolean canSupport(java.util.Properties startParams)
canSupport
in interface ModuleSupportable
startParams
- The properties used to boot replicationModuleSupportable.canSupport(java.util.Properties)
public void stop()
stop
in interface ModuleControl
Monitor
,
ModuleFactory
public void startMaster(RawStoreFactory rawStore, DataFactory dataFac, LogFactory logFac, java.lang.String slavehost, int slaveport, java.lang.String dbname) throws StandardException
startMaster
in interface MasterFactory
rawStore
- The RawStoreFactory for the databasedataFac
- The DataFactory for this databaselogFac
- The LogFactory ensuring recoverability for this databaseslavehost
- The hostname of the slaveslaveport
- The port the slave is listening ondbname
- The master database that is being replicated.StandardException
- Standard Derby exception policy,
1) thrown on replication startup error
2) thrown if the master has already been
booted.
3) thrown if the specified replication mode
is not supported.public void stopMaster() throws StandardException
stopMaster
in interface MasterFactory
StandardException
- If the replication master has been stopped
already.public void startFailover() throws StandardException
MasterFactory
startFailover
in interface MasterFactory
StandardException
- 1) If the failover succeeds, an exception is
thrown to indicate that the master database
was shutdown after a successful failover
2) If a failure occurs during network
communication with slave.MasterFactory.startFailover()
private void getMasterProperties()
private void handleFailoverFailure(java.lang.Throwable t) throws StandardException
t
- The throwable which resulted in the aborted failover
attempt.StandardException
- Indicating the reason for the aborted
failover attempt.public void appendLog(long greatestInstant, byte[] log, int logOffset, int logLength)
appendLog
in interface MasterFactory
greatestInstant
- the instant of the log record that was
added last to this chunk of loglog
- the chunk of log recordslogOffset
- offset in log to start copy fromlogLength
- number of bytes to copy, starting
from logOffsetpublic void flushedTo(long instant)
flushedTo
in interface MasterFactory
instant
- The highest log instant that has been flushed to
diskMasterFactory.flushedTo(long)
,
LogFactory.flush(org.apache.derby.iapi.store.raw.log.LogInstant)
private void setupConnection() throws StandardException
StandardException
- If a failure occurs while trying to open
the connection to the slave.ReplicationMessageTransmit handleExceptions(java.lang.Exception exception)
exception
- the exception which caused the log shipper to terminate
in an unexcepted manner.private void printStackAndStopMaster(java.lang.Exception e)
e
- the exception that needs to be handled.public void workToDo()
workToDo
in interface MasterFactory
private void teardownNetwork()
java.lang.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.
private java.lang.String getHostName()
private int getPortNumber()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.