|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.db.BasicDatabase
org.apache.derby.impl.db.SlaveDatabase
public class SlaveDatabase
SlaveDatabase is an instance of Database, and is booted instead of BasicDatabase if this database will have the replication slave role. SlaveDatabase differs from BasicDatabase in the following ways: 1: When starting a non-replicated database (i.e., BasicDatabase), only one thread is used to start all modules of the database. When booted in slave mode, the thread that boots the store module will be blocked during log recovery. To remedy this, SlaveDatabase runs the boot method of BasicDatabase in a separate thread. This ensures that the connection attempt that started slave replication mode will not hang. 2: While the database is in replication slave mode, the authentication services are not available because these require that the store module has been booted first. Calling getAuthenticationService when in slave mode will raise an exception. 3: While the database is in replication slave mode, connections are not accepted since the database cannot process transaction requests. Calling setupConnection when in slave mode will raise an exception. 4: If the failover command has been executed for this database, it is no longer in replication slave mode. When this has happened, SlaveDatabase works exactly as BasicDatabase.
Nested Class Summary | |
---|---|
private class |
SlaveDatabase.SlaveDatabaseBootThread
Thread that boots the slave database. |
Field Summary | |
---|---|
private StandardException |
bootException
Set by the database boot thread if it fails before slave mode has been started properly (i.e., if inBoot is true). |
private java.lang.String |
dbname
|
private boolean |
inBoot
True until this database has been successfully booted. |
private boolean |
inReplicationSlaveMode
True until SlaveDatabaseBootThread has successfully booted the database. |
private boolean |
shutdownInitiated
|
private SlaveFactory |
slaveFac
|
Fields inherited from class org.apache.derby.impl.db.BasicDatabase |
---|
active, af, cfDB, lastToBoot, lcf, lf, pf, resourceAdapter |
Constructor Summary | |
---|---|
SlaveDatabase()
|
Method Summary | |
---|---|
void |
boot(boolean create,
java.util.Properties startParams)
Boot this module with the given properties. |
private void |
bootBasicDatabase(boolean create,
java.util.Properties params)
|
boolean |
canSupport(java.util.Properties startParams)
Determines whether this Database implementation should be used to boot the database. |
void |
failover(java.lang.String dbname)
Start failover for the given database. |
AuthenticationService |
getAuthenticationService()
This method returns the authentication service handle for the database. |
private void |
handleShutdown(StandardException shutdownCause)
Used to shutdown this database. |
boolean |
isInSlaveMode()
Used to indicated whether the database is in the replication slave mode. |
private boolean |
isSlaveFactorySet()
If slaveFac (the reference to the SlaveFactory) has not already been set, this method will try to set it by calling Monitor.findServiceModule. |
LanguageConnectionContext |
setupConnection(ContextManager cm,
java.lang.String user,
java.lang.String drdaID,
java.lang.String dbname)
Sets up a connection to the Database, owned by the given user. |
void |
stop()
Called by Monitor when this module is stopped, i.e. when the database is shut down. |
void |
stopReplicationSlave()
Stop replication slave mode if replication slave mode is active and the network connection with the master is down |
void |
verifyShutdownSlave()
Verify that a connection to stop the slave has been made from here. |
private void |
verifySuccessfulBoot()
Verify that the slave functionality has been properly started. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private volatile boolean inReplicationSlaveMode
private volatile boolean shutdownInitiated
private volatile boolean inBoot
private volatile StandardException bootException
private java.lang.String dbname
private volatile SlaveFactory slaveFac
Constructor Detail |
---|
public SlaveDatabase()
Method Detail |
---|
public boolean canSupport(java.util.Properties startParams)
canSupport
in interface ModuleSupportable
canSupport
in class BasicDatabase
startParams
- The properties used to decide if
SlaveDatabase is the correct implementation of Database for the
database to be booted.
public void boot(boolean create, java.util.Properties startParams) throws StandardException
ModuleControl
An implementation's boot method can throw StandardException. If it is thrown the module is not registered by the monitor and therefore cannot be found through a findModule(). In this case the module's stop() method is not called, thus throwing this exception must free up any resources.
When create is true the contents of the properties object
will be written to the service.properties of the persistent
service. Thus any code that requires an entry in service.properties
must explicitly place the value in this properties set
using the put method.
Typically the properties object contains one or more default
properties sets, which are not written out to service.properties.
These default sets are how callers modify the create process. In a
JDBC connection database create the first set of defaults is a properties
object that contains the attributes that were set on the jdbc:derby: URL.
This attributes properties set has the second default properties set as
its default. This set (which could be null) contains the properties
that the user set on their DriverManager.getConnection() call, and are thus
not owned by Derby code, and thus must not be modified by Derby
code.
When create is false the properties object contains all the properties set in the service.properties file plus a limited number of attributes from the JDBC URL attributes or connection properties set. This avoids properties set by the user compromising the boot process. An example of a property passed in from the JDBC world is the bootPassword for encrypted databases.
Code should not hold onto the passed in properties reference after boot time as its contents may change underneath it. At least after the complete boot is completed, the links to all the default sets will be removed.
boot
in interface ModuleControl
boot
in class BasicDatabase
StandardException
- Module cannot be started.Monitor
,
ModuleFactory
public void stop()
stop
in interface ModuleControl
stop
in class BasicDatabase
Monitor
,
ModuleFactory
public boolean isInSlaveMode()
Database
isInSlaveMode
in class BasicDatabase
public LanguageConnectionContext setupConnection(ContextManager cm, java.lang.String user, java.lang.String drdaID, java.lang.String dbname) throws StandardException
Database
setupConnection
in class BasicDatabase
user
- The UserID of the user getting the connectiondrdaID
- The drda id of the connection (from network server)dbname
- The database name
StandardException
- thrown if unable to create the connection.public AuthenticationService getAuthenticationService() throws StandardException
Database
getAuthenticationService
in class BasicDatabase
StandardException
public void verifyShutdownSlave() throws StandardException
StandardException
- Thrown if a stop slave connection
attempt was not made from this classpublic void stopReplicationSlave() throws java.sql.SQLException
stopReplicationSlave
in class BasicDatabase
java.sql.SQLException
- Thrown on error, if not in replication
slave mode or if the network connection with the master is not downpublic void failover(java.lang.String dbname) throws StandardException
Database
failover
in class BasicDatabase
dbname
- the replication database that is being failed over.
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.Database.failover(String)
private void verifySuccessfulBoot() throws StandardException
StandardException
private boolean isSlaveFactorySet()
private void handleShutdown(StandardException shutdownCause)
shutdownCause
- the reason why the database needs to be
shutdownprivate void bootBasicDatabase(boolean create, java.util.Properties params) throws StandardException
StandardException
|
Built on Thu 2010-12-23 20:49:13+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |