Class SlaveDatabase
- java.lang.Object
-
- org.apache.derby.impl.db.BasicDatabase
-
- org.apache.derby.impl.db.SlaveDatabase
-
- All Implemented Interfaces:
- Database, LocaleFinder, JarReader, ModuleControl, ModuleSupportable, PropertySetCallback
public class SlaveDatabase extends BasicDatabase
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.
-
-
Field Summary
-
Fields inherited from interface org.apache.derby.database.Database
LUCENE_DIR
-
-
Constructor Summary
Constructors Constructor and Description SlaveDatabase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidboot(boolean create, java.util.Properties startParams)Boot this module with the given properties.booleancanSupport(java.util.Properties startParams)Determines whether this Database implementation should be used to boot the database.voidfailover(java.lang.String dbname)Start failover for the given database.AuthenticationServicegetAuthenticationService()This method returns the authentication service handle for the database.booleanisInSlaveMode()Used to indicated whether the database is in the replication slave mode.LanguageConnectionContextsetupConnection(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.voidstop()Called by Monitor when this module is stopped, i.e.voidstopReplicationSlave()Stop replication slave mode if replication slave mode is active and the network connection with the master is downvoidverifyShutdownSlave()Verify that a connection to stop the slave has been made from here.-
Methods inherited from class org.apache.derby.impl.db.BasicDatabase
apply, backup, backupAndEnableLogArchiveMode, checkpoint, disableLogArchiveMode, freeze, getCurrentLocale, getDataDictionary, getDateFormat, getEngineType, getId, getJarFile, getLocale, getResourceAdapter, getTimeFormat, getTimestampFormat, init, isActive, isReadOnly, map, pushDbContext, setLocale, startReplicationMaster, stopReplicationMaster, unfreeze, validate
-
-
-
-
Method Detail
-
canSupport
public boolean canSupport(java.util.Properties startParams)
Determines whether this Database implementation should be used to boot the database.- Specified by:
canSupportin interfaceModuleSupportable- Overrides:
canSupportin classBasicDatabase- Parameters:
startParams- The properties used to decide if SlaveDatabase is the correct implementation of Database for the database to be booted.- Returns:
- true if the database is updatable (not read-only) and replication slave mode is specified in startParams
-
boot
public void boot(boolean create, java.util.Properties startParams) throws StandardExceptionDescription copied from interface:ModuleControlBoot this module with the given properties. Creates a module instance that can be found using the findModule() methods of Monitor. The module can only be found using one of these findModule() methods once this method has returned.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.
- Specified by:
bootin interfaceModuleControl- Overrides:
bootin classBasicDatabase- Throws:
StandardException- Module cannot be started.- See Also:
Monitor,ModuleFactory
-
stop
public void stop()
Called by Monitor when this module is stopped, i.e. when the database is shut down. When the database is shut down using the stopSlave command, the stopReplicationSlave method has already been called when this method is called. In this case, the replication functionality has already been stopped. If the database is shutdown as part of a system shutdown, however, we need to cleanup slave replication as part of database shutdown.- Specified by:
stopin interfaceModuleControl- Overrides:
stopin classBasicDatabase- See Also:
Monitor,ModuleFactory
-
isInSlaveMode
public boolean isInSlaveMode()
Description copied from interface:DatabaseUsed to indicated whether the database is in the replication slave mode.- Overrides:
isInSlaveModein classBasicDatabase- Returns:
- true if this database is in replication slave mode, false otherwise.
-
setupConnection
public LanguageConnectionContext setupConnection(ContextManager cm, java.lang.String user, java.lang.String drdaID, java.lang.String dbname) throws StandardException
Description copied from interface:DatabaseSets up a connection to the Database, owned by the given user. The JDBC version of getConnection takes a URL. The purpose of the URL is to tell the driver where the database system is. By the time we get here, we have found the database system (that's how we're making this method call), so the URL is not necessary to establish the connection here. The driver should remember the URL that was used to establish the connection, so it can implement the DatabaseMetaData.getURL() method.- Overrides:
setupConnectionin classBasicDatabaseuser- The UserID of the user getting the connectiondrdaID- The drda id of the connection (from network server)dbname- The database name- Returns:
- A new LanguageConnectionContext
- Throws:
StandardException- thrown if unable to create the connection.
-
getAuthenticationService
public AuthenticationService getAuthenticationService() throws StandardException
Description copied from interface:DatabaseThis method returns the authentication service handle for the database. NOTE: There is always a Authentication Service per database and at the system level.- Overrides:
getAuthenticationServicein classBasicDatabase- Returns:
- The authentication service handle for the database
- Throws:
StandardException- standard Derby exception policy
-
verifyShutdownSlave
public void verifyShutdownSlave() throws StandardExceptionVerify that a connection to stop the slave has been made from here. If verified, the database context is given to the method caller. This will ensure this database is shutdown when an exception with database severity is thrown. If not verified, an exception is thrown.- Throws:
StandardException- Thrown if a stop slave connection attempt was not made from this class
-
stopReplicationSlave
public void stopReplicationSlave() throws java.sql.SQLExceptionStop replication slave mode if replication slave mode is active and the network connection with the master is down- Overrides:
stopReplicationSlavein classBasicDatabase- Throws:
java.sql.SQLException- Thrown on error, if not in replication slave mode or if the network connection with the master is not down
-
failover
public void failover(java.lang.String dbname) throws StandardExceptionDescription copied from interface:DatabaseStart failover for the given database.- Overrides:
failoverin classBasicDatabase- Parameters:
dbname- the replication database that is being failed over.- Throws:
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.- See Also:
Database.failover(String)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG