db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r618632 - in /db/derby/code/trunk/java: engine/org/apache/derby/database/ engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/iapi/services/replication/master/ engine/org/apache/derby/iapi/store/access/ engine/org/apache/derby/i...
Date Tue, 05 Feb 2008 12:41:48 GMT
Author: oysteing
Date: Tue Feb  5 04:41:45 2008
New Revision: 618632

URL: http://svn.apache.org/viewvc?rev=618632&view=rev
Log:
DERBY-3205 :Replication: Add connection url command option for failove. Contributed by Narayanan.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/database/Database.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/MasterController.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/database/Database.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/database/Database.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/database/Database.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/database/Database.java Tue Feb  5 04:41:45
2008
@@ -99,6 +99,19 @@
     boolean deleteOnlineArchivedLogFiles,
     boolean wait) 
         throws SQLException;
+    
+    /**
+     * Start failover for the given database.
+     * 
+     * @param dbname the replication database that is being failed over.
+     *
+     * @exception SQLException   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.
+     */
+    public void failover(String dbname) throws SQLException;
 
     /**
      * Stop the replication slave role for the given database.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java Tue Feb
 5 04:41:45 2008
@@ -134,6 +134,11 @@
      * attribute.
      */
     String REPLICATION_SLAVE_HOST = "slaveHost";
+    
+    /**
+     * Attribute name to start failover for a given database..
+     */
+    String REPLICATION_FAILOVER = "failover";
 
     /**
      * If startMaster is true, this attribute is used to specify the

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.java
Tue Feb  5 04:41:45 2008
@@ -122,7 +122,10 @@
     
     /**
      * Will perform all work needed to failover
-     * @throws StandardException 1) If the failover succeeds
+     *
+     * @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.
      */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java
Tue Feb  5 04:41:45 2008
@@ -236,6 +236,21 @@
      * thrown on error.
      */
     public void stopReplicationMaster() throws StandardException;
+        
+    /**
+     * Start the failover for this database.
+     *
+     * @param dbname the replication database that is being failed over.
+     * 
+     * @exception StandardException Standard Derby exception policy,
+     *                           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.
+     */
+    public void failover(String dbname) throws StandardException;
+    
 
 	/**
 	  * Freeze the database temporarily so a backup can be taken.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java Tue
Feb  5 04:41:45 2008
@@ -703,6 +703,20 @@
      * thrown on error.
      */
     public void stopReplicationMaster() throws StandardException;
+        
+    /**
+     * Start failover for this database.
+     *
+     * @param dbname the replication database that is being failed over.
+     * 
+     * @exception StandardException Standard Derby exception policy,
+     *                           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.
+     */
+    public void failover(String dbname) throws StandardException;
 
 	/**
 	  * Freeze the database temporarily so a backup can be taken.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java Tue Feb  5
04:41:45 2008
@@ -404,6 +404,17 @@
             newException(SQLState.REPLICATION_NOT_IN_SLAVE_MODE);
         throw PublicAPI.wrapStandardException(se);
     }
+    
+    /**
+     * @see org.apache.derby.database.Database#failover(String dbname).
+     */
+    public void failover(String dbname) throws SQLException {
+        try {
+            af.failover(dbname);
+        } catch (StandardException se) {
+            throw PublicAPI.wrapStandardException(se);
+        }
+    }
 
 	public void freeze() throws SQLException
 	{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Tue Feb
 5 04:41:45 2008
@@ -343,6 +343,8 @@
 				// Stopping replication master can be done
 				// simultaneously with a database shutdown operation
 				handleStopReplicationMaster(tr, info);
+			} else if (isReplicationFailover(info)) {
+				handleFailover(tr, info);
 			}
 
 			if (isTwoPhaseEncryptionBoot ||
@@ -580,6 +582,19 @@
                  p.getProperty(Attribute.REPLICATION_START_MASTER)).
                  booleanValue()));
     }
+    
+    /**
+     * used to verify if the failover attribute has been set.
+     * 
+     * @param p The attribute set.
+     * @return true if the failover attribute has been set.
+     *         false otherwise.
+     */
+    private boolean isReplicationFailover(Properties p) {
+        return ((Boolean.valueOf(
+                 p.getProperty(Attribute.REPLICATION_FAILOVER)).
+                 booleanValue()));
+    }
 
     private boolean isStopReplicationMasterBoot(Properties p) {
         return ((Boolean.valueOf(
@@ -766,6 +781,42 @@
             // REPLICATION_SLAVE_SHUTDOWN_OK will be reported anyway
             handleException(tr.shutdownDatabaseException());
         }
+    }
+    
+    /**
+     * Used to authorize and verify the privileges of the user and
+     * initiate failover.
+     * 
+     * @param tr an instance of TransactionResourceImpl Links the connection 
+     *           to the database.
+     * @param p The Attribute set.
+     * @throws java.sql.SQLException 1) Thrown upon a authorization failure 
+     *                           2) If the failover succeeds, an exception is
+     *                              thrown to indicate that the master database
+     *                              was shutdown after a successful failover
+     *                           3) If a failure occurs during network 
+     *                              communication with slave.
+     */
+    private void handleFailover(TransactionResourceImpl tr,
+                                             Properties p)
+        throws SQLException {
+
+        // If authorization is turned on, we need to check if this
+        // user is database owner.
+        if (!usingNoneAuth &&
+            getLanguageConnection().usesSqlAuthorization()) {
+            checkIsDBOwner(OP_REPLICATION);
+        }
+        // TODO: If system privileges is turned on, we need to check
+        // that the user has the replication privilege. Waiting for
+        // Derby-2109
+
+        // At this point, the user is properly authenticated,
+        // authorized and has the correct system privilege to initiate 
+        // failover - depending on the security mechanisms
+        // Derby is running under.
+
+        tr.getDatabase().failover(tr.getDBName());
     }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/MasterController.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/MasterController.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/MasterController.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/MasterController.java
Tue Feb  5 04:41:45 2008
@@ -231,11 +231,7 @@
     }
 
     /**
-     * Will perform all work needed to failover.
-     *
-     * @throws StandardException 1) If the failover succeeds
-     *                           2) If a failure occurs during network 
-     *                              communication with slave.
+     * @see org.apache.derby.iapi.services.replication.master.MasterFactory#startFailover()
      */
     public void startFailover() throws StandardException {
         //acknowledgment returned from the slave containing

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
Tue Feb  5 04:41:45 2008
@@ -928,6 +928,13 @@
         throws StandardException {
         rawstore.startReplicationMaster(dbmaster, host, port, replicationMode);
     }
+    
+    /**
+     * @see org.apache.derby.iapi.store.access.AccessFactory#failover(String dbname).
+     */
+    public void failover(String dbname) throws StandardException {
+        rawstore.failover(dbname);
+    }
 
     /**
      * Stop the replication master role for this database.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Tue Feb
 5 04:41:45 2008
@@ -527,6 +527,29 @@
         }
         masterFactory.stopMaster();
     }
+    
+        
+    /**
+     * @see org.apache.derby.iapi.store.raw.RawStoreFactory#failover(String dbname).
+     */
+    public void failover(String dbname) throws StandardException {
+        MasterFactory masterFactory = null;
+        
+        if (isReadOnly()) {
+            throw StandardException.newException(
+                      SQLState.LOGMODULE_DOES_NOT_SUPPORT_REPLICATION);
+        }
+
+        try {
+            masterFactory = (MasterFactory) 
+                Monitor.findServiceModule(this, getMasterFactoryModule());
+        }
+        catch (StandardException se) {
+            throw StandardException.newException
+                    (SQLState.REPLICATION_FAILOVER_UNSUCCESSFUL, se, dbname);
+        }
+        masterFactory.startFailover();
+    }
 
 	public void freeze() throws StandardException
 	{

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java?rev=618632&r1=618631&r2=618632&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
Tue Feb  5 04:41:45 2008
@@ -126,6 +126,11 @@
     String REPLICATION_SLAVE_HOST = "slaveHost";
 
     /**
+     * Attribute name to start failover for a given database..
+     */
+    String REPLICATION_FAILOVER = "failover";
+
+    /**
      * If startMaster is true, this attribute is used to specify the
      * port the master should connect to. This is an optional
      * attribute.



Mime
View raw message