db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r614514 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/replication/master/ engine/org/apache/derby/impl/services/replication/master/ engine/org/apache/derby/impl/services/replication/slave/ engine/org/apache/derby/imp...
Date Wed, 23 Jan 2008 12:12:27 GMT
Author: oysteing
Date: Wed Jan 23 04:12:24 2008
New Revision: 614514

URL: http://svn.apache.org/viewvc?rev=614514&view=rev
Log:
DERBY-3254: Implement the replication failover functionality.  Contributed by V Narayanan

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.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/services/replication/slave/SlaveController.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java

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=614514&r1=614513&r2=614514&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
Wed Jan 23 04:12:24 2008
@@ -119,6 +119,14 @@
      * Will perform all work that is needed to shut down replication
      */
     public void stopMaster();
+    
+    /**
+     * Will perform all work needed to failover
+     * @throws StandardException 1) If the failover succeeds
+     *                           2) If a failure occurs during network 
+     *                              communication with slave.
+     */
+    public void startFailover() throws StandardException;
 
     /**
      * Append a chunk of log records to the log buffer.

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=614514&r1=614513&r2=614514&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
Wed Jan 23 04:12:24 2008
@@ -227,6 +227,84 @@
     }
 
     /**
+     * Will perform all work needed to failover.
+     *
+     * @throws StandardException 1) If the failover succeeds
+     *                           2) If a failure occurs during network 
+     *                              communication with slave.
+     */
+    public void startFailover() throws StandardException {
+        //acknowledgment returned from the slave containing
+        //the status of the failover performed.
+        ReplicationMessage ack = null;
+        
+        stopMasterController = true;
+        
+        //freeze the database to stop clients when this command is received
+        rawStoreFactory.freeze();
+        
+        try {
+            //Flush the log buffer of any remaining log records.
+            logShipper.flushBuffer();
+            
+            //Send the failover message to the slave and wait for 
+            //acknowledgement.
+            ReplicationMessage mesg = new ReplicationMessage(
+                        ReplicationMessage.TYPE_FAILOVER, null);
+            transmitter.sendMessage(mesg);
+            ack = transmitter.readMessage();
+        } catch (IOException ioe) {
+            handleFailoverFailure(ioe);
+        } catch (StandardException se) {
+            handleFailoverFailure(se);
+        } catch (ClassNotFoundException cnfe) {
+            handleFailoverFailure(cnfe);
+        }
+        
+        //check the contents of the acknowledgement received from the slave
+        //and perform appropriate actions.
+        if (ack == null) {
+            //ack can be null if the wait on the socket stream timed out
+            handleFailoverFailure(null);
+        } else if (ack.getType() == ReplicationMessage.TYPE_ACK) {
+            //An exception is thrown to indicate the successful completion 
+            //of failover. Also the AsynchronousLogShipper thread is terminated.
+            //The exception thrown is of Database Severity, this shuts
+            //down the master database.
+            logShipper.stopLogShipment();
+            throw StandardException.newException
+                    (SQLState.REPLICATION_FAILOVER_SUCCESSFUL, dbname);  
+        } else {
+            //TYPE_ACK is the only type that is returned. ack can
+            //ideally not contain any other type. The program should
+            //ideally not come here.
+           handleFailoverFailure(null);
+        }
+    }
+    
+    /**
+     * used to handle the case when an attempt to failover the database
+     * fails.
+     *
+     * @param t        The throwable which resulted in the aborted failover
+     *                 attempt.
+     * 
+     * @throws StandardException Indicating the reason for the aborted
+     *                          failover attempt. 
+     */
+    private void handleFailoverFailure(Throwable t) 
+    throws StandardException {
+        rawStoreFactory.unfreeze();
+        if (t != null) {
+            throw StandardException.newException
+                        (SQLState.REPLICATION_FAILOVER_UNSUCCESSFUL, t, dbname);
+        } else {
+            throw StandardException.newException
+                        (SQLState.REPLICATION_FAILOVER_UNSUCCESSFUL, dbname);
+        }
+    }
+    
+    /**
      * Append a chunk of log records to the log buffer.
      *
      * @param greatestInstant   the instant of the log record that was

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java?rev=614514&r1=614513&r2=614514&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java
Wed Jan 23 04:12:24 2008
@@ -255,16 +255,10 @@
      * @see org.apache.derby.impl.services.replication.master.MasterController#flushedTo
      */
     public void failover() {
-        // Apply all received log records, thus completing the boot of
-        // this database. The database can be connected to after this.
-
-        // // complete recovery of the database 
-        // logToFile.setReplicationMode(false);
-
-        // Added when Network Service has been committed to trunk:
-        // connection.shutdown();
-
-        System.out.println("SlaveController failover");
+        inReplicationSlaveMode = false;
+        logToFile.stopReplicationSlaveRole();
+        Monitor.logTextMessage
+                (MessageId.REPLICATION_FAILOVER_SUCCESSFUL, dbname);
     }
 
     ////////////////////////////////////////////////////////////
@@ -406,6 +400,12 @@
                     case ReplicationMessage.TYPE_LOG:
                         byte[] logChunk = (byte[])message.getMessage();
                         handleLogChunk(logChunk);
+                        break;
+                    case ReplicationMessage.TYPE_FAILOVER:
+                        failover();
+                        ReplicationMessage ack = new ReplicationMessage
+                            (ReplicationMessage.TYPE_ACK, "failover succeeded");
+                        receiver.sendMessage(ack);
                         break;
                     case ReplicationMessage.TYPE_STOP:
                         stopSlave();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=614514&r1=614513&r2=614514&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java Wed
Jan 23 04:12:24 2008
@@ -5180,6 +5180,14 @@
                 (SQLState.REPLICATION_UNEXPECTED_EXCEPTION, ioe);
         }
     }
+    
+    /**
+     * Used to make the slave stop appending log records, complete recovery 
+     * and boot the database.
+     */
+    public void stopReplicationSlaveRole() {
+        inReplicationSlaveMode = false;
+    }
 
 	/**
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=614514&r1=614513&r2=614514&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Wed Jan 23 04:12:24
2008
@@ -4780,6 +4780,18 @@
                 <text>Conflicting attributes specified. See reference manual for attributes
allowed in combination with replication attribute '{0}'.</text>
                 <arg>attribute</arg>
             </msg>
+            
+            <msg>
+                <name>XRE20.D</name>
+                <text>Failover performed successfully for database '{0}', the database
has been shutdown.</text>
+                <arg>dbname</arg>
+            </msg>
+            
+            <msg>
+                <name>XRE21</name>
+                <text>Error occurred while performing failover for database '{0}',
Failover attempt was aborted.</text>
+                <arg>dbname</arg>
+            </msg>
 
         </family>
 
@@ -7619,6 +7631,12 @@
             <msg>
                 <name>R010</name>
                 <text>Replication master trying to reconnect to slave for database
'{0}'.</text>
+                <arg>dbname</arg>
+            </msg>
+            
+            <msg>
+                <name>R020</name>
+                <text>Failover perfomed successfully for database '{0}'.</text>
                 <arg>dbname</arg>
             </msg>
         </family>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=614514&r1=614513&r2=614514&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
Wed Jan 23 04:12:24 2008
@@ -183,5 +183,6 @@
     String REPLICATION_MASTER_STOPPED                    = "R008";
     String REPLICATION_LOGSHIPPER_EXCEPTION              = "R009";
     String REPLICATION_MASTER_RECONN                     = "R010";
+    String REPLICATION_FAILOVER_SUCCESSFUL               = "R020";
 
 }

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=614514&r1=614513&r2=614514&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Wed Jan 23 04:12:24 2008
@@ -1768,5 +1768,7 @@
     String REPLICATION_SLAVE_STARTED_OK                            = "XRE08";
     String CANNOT_START_SLAVE_ALREADY_BOOTED                       = "XRE09";
     String REPLICATION_CONFLICTING_ATTRIBUTES                      = "XRE10";
+    String REPLICATION_FAILOVER_SUCCESSFUL                         = "XRE20.D";
+    String REPLICATION_FAILOVER_UNSUCCESSFUL                       = "XRE21";
 }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java?rev=614514&r1=614513&r2=614514&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
Wed Jan 23 04:12:24 2008
@@ -187,6 +187,7 @@
         		{"XJ05B","JDBC attribute '{0}' has an invalid value '{1}', valid values are '{2}'.","40000"},
         		{"XJ081","Conflicting create/restore/recovery attributes specified.","40000"},
         		{"XJ213","The traceLevel connection property does not have a valid format for a
number.","40000"},
+        		{"XRE20","Failover performed successfully for database '{0}', the database has
been shutdown.","45000"},
         		{"XSDB0","Unexpected exception on in-memory page {0}","45000"},
         		{"XSDB1","Unknown page format at page {0}","45000"},
         		{"XSDB2","Unknown container format at container {0} : {1}","45000"},



Mime
View raw message