|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.store.replication.slave.SlaveController
public class SlaveController
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
Nested Class Summary | |
---|---|
private class |
SlaveController.SlaveLogReceiverThread
Thread that listens for incoming messages from the master and applies chunks of log records to the local log files. |
Field Summary | |
---|---|
private java.lang.String |
dbname
|
private static int |
DEFAULT_SOCKET_TIMEOUT
|
private long |
highestLogInstant
The instant of the latest log record received from the master and processed so far. |
private boolean |
inReplicationSlaveMode
Whether or not replication slave mode is still on. |
private SlaveController.SlaveLogReceiverThread |
logReceiverThread
|
private ReplicationLogScan |
logScan
|
private LogToFile |
logToFile
|
private RawStoreFactory |
rawStoreFactory
|
private ReplicationMessageReceive |
receiver
|
private ReplicationLogger |
repLogger
|
private SlaveAddress |
slaveAddr
|
private 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. |
Fields inherited from interface org.apache.derby.iapi.store.replication.slave.SlaveFactory |
---|
MODULE, REPLICATION_MODE, SLAVE_DB, SLAVE_MODE, SLAVE_PRE_MODE |
Constructor Summary | |
---|---|
SlaveController()
Empty constructor required by Monitor.bootServiceModule |
Method Summary | |
---|---|
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. |
private void |
doFailover()
Performs failover on this database. |
void |
failover()
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 java.lang.String |
getHostName()
Used to return the host name of the slave. |
private int |
getPortNumber()
Used to return the port number of the slave. |
private void |
handleDisconnect(java.lang.Exception e)
Write the reason for the lost connection to the log (derby.log) and reconnect with the master. |
private void |
handleFatalException(java.lang.Exception e)
Handles fatal errors for slave replication functionality. |
private boolean |
isConnectedToMaster()
Check if the repliation network connection to the master is working |
boolean |
isStarted()
Check whether or not slave replication mode has been successfully started. |
private boolean |
setupConnection()
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. |
void |
startSlave(RawStoreFactory rawStore,
LogFactory logFac)
Start slave replication. |
void |
stop()
Will tear down the replication slave service. |
private void |
stopSlave()
Will perform all work that is needed to stop replication |
void |
stopSlave(boolean forcedStop)
Stop replication slave mode. |
private void |
teardownNetwork()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int DEFAULT_SOCKET_TIMEOUT
private RawStoreFactory rawStoreFactory
private LogToFile logToFile
private ReplicationMessageReceive receiver
private ReplicationLogger repLogger
private SlaveAddress slaveAddr
private java.lang.String dbname
private volatile long highestLogInstant
private volatile boolean inReplicationSlaveMode
private volatile boolean startupSuccessful
private ReplicationLogScan logScan
private SlaveController.SlaveLogReceiverThread logReceiverThread
Constructor Detail |
---|
public SlaveController()
Method Detail |
---|
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
StandardException
- Standard Derby exception policy,
thrown on error.Monitor
,
ModuleFactory
public void stop()
stop
in interface ModuleControl
Monitor
,
ModuleFactory
public boolean canSupport(java.util.Properties startParams)
canSupport
in interface ModuleSupportable
startParams
- The properties used to start replication
ModuleSupportable.canSupport(java.util.Properties)
public void startSlave(RawStoreFactory rawStore, LogFactory logFac) throws StandardException
startSlave
in interface SlaveFactory
rawStore
- The RawStoreFactory for the databaselogFac
- The LogFactory ensuring recoverability for this
database
StandardException
- Thrown if the slave could not be
started.private void stopSlave() throws StandardException
StandardException
public void stopSlave(boolean forcedStop) throws StandardException
SlaveFactory
stopSlave
in interface SlaveFactory
forcedStop
- Determines whether or not an exception should
be thrown when this method is called while the network
connection to the master is up.
StandardException
- Thrown if slave is connected with
master and forcedStop is false.SlaveFactory.stopSlave(boolean)
public void failover() throws StandardException
SlaveFactory
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.
failover
in interface SlaveFactory
StandardException
- Thrown if slave is connected with
masterMasterFactory
,
MasterController.flushedTo(long)
private void doFailover()
SlaveFactory.failover()
public boolean isStarted()
SlaveFactory
isStarted
in interface SlaveFactory
SlaveFactory.isStarted()
private boolean setupConnection() throws StandardException
StandardException
- if an unexpected exception occured
that prevented a connection with the master.private void handleDisconnect(java.lang.Exception e)
e
- The reason the connection to the master was lostprivate boolean isConnectedToMaster()
private void startLogReceiverThread()
private void handleFatalException(java.lang.Exception e)
e
- The fatal exception that is the reason for calling
this methodprivate void teardownNetwork()
private java.lang.String getHostName()
private int getPortNumber()
|
Built on Thu 2011-03-10 11:54:14+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |