db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r634218 - 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/store/raw/ engine/org/apache/derby/loc/ shared/org/apac...
Date Thu, 06 Mar 2008 10:53:11 GMT
Author: oysteing
Date: Thu Mar  6 02:53:07 2008
New Revision: 634218

URL: http://svn.apache.org/viewvc?rev=634218&view=rev
Log:
DERBY-3358: After an incorrect(unsuccesfull) startMaster comand, further correct startMaster
attempts also fail.
Contributed by V Narayanan.
M java/engine/org/apache/derby/impl/services/replication/master/MasterController.java
* Added a variable boolean that indicates whether the master controller is currently running
or has
  been stopped. I thought I could manage with the earlier boolean variable stopMasterController
but
  decided against it because it seemed more tied with the stopMaster operation.
* moved start up parameter initialization from boot to startMaster method. 
* changed the startMaster, stopMaster and the startFailover methods to take into account the
boolean
  active.
* replaced the earlier uses of stopMasterController with active.
  
M java/engine/org/apache/derby/impl/store/raw/RawStore.java
* The replication properties that are part of the bootServiceModule call no longer contain
the
  startup parameters. These have instead been moved to the startMaster method.
* The replicationProps are empty and not null because a null passed to a bootServiceModule
call
  results in a NullPointerException.

M java/engine/org/apache/derby/iapi/services/replication/master/MasterFactory.java
* Changed the startMaster declaration to now accept the startup parameters as the method arguments.

M java/engine/org/apache/derby/loc/messages.xml
M java/shared/org/apache/derby/shared/common/reference/SQLState.java
* Added a new messages for the case when the master has already been booted.

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/store/raw/RawStore.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/SQLState.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=634218&r1=634217&r2=634218&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
Thu Mar  6 02:53:07 2008
@@ -73,19 +73,7 @@
         "org.apache.derby.iapi.services.replication.master.MasterFactory";
 
     /* Property names that are used as key values in the Properties objects*/
-
-    /** Property key used to specify which slave host to connect to */
-    public static final String SLAVE_HOST =
-        Property.PROPERTY_RUNTIME_PREFIX + "replication.master.slavehost";
-
-    /** Property key to specify which slave port to connect to */
-    public static final String SLAVE_PORT =
-        Property.PROPERTY_RUNTIME_PREFIX + "replication.master.slaveport";
     
-    /** Property key to specify the name of the database */
-    public static final String MASTER_DB =
-        Property.PROPERTY_RUNTIME_PREFIX + "replication.master.dbname";
-
     /** Property key to specify replication mode */
     public static final String REPLICATION_MODE =
         Property.PROPERTY_RUNTIME_PREFIX + "replication.master.mode";
@@ -108,17 +96,27 @@
      * @param rawStore The RawStoreFactory for the database
      * @param dataFac The DataFactory for this database
      * @param logFac The LogFactory ensuring recoverability for this database
+     * @param slavehost The hostname for the slave
+     * @param slaveport The port the slave is listening on
+     * @param dbname The master database that is being replicated.
      * @exception StandardException Standard Derby exception policy,
      * thrown on replication startup error. 
      */
     public void startMaster(RawStoreFactory rawStore,
-                            DataFactory dataFac, LogFactory logFac)
-        throws StandardException;
+                            DataFactory dataFac,
+                            LogFactory logFac,
+                            String slavehost,
+                            int slaveport,
+                            String dbname)
+                            throws StandardException;
 
     /**
-     * Will perform all work that is needed to shut down replication
+     * Will perform all work that is needed to shut down replication.
+     *
+     * @throws StandardException If the replication master has been stopped
+     *                           already.
      */
-    public void stopMaster();
+    public void stopMaster() throws StandardException;
     
     /**
      * Will perform all work needed to failover

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=634218&r1=634217&r2=634218&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
Thu Mar  6 02:53:07 2008
@@ -76,8 +76,9 @@
     private int slaveport;
     private String dbname;
     
-    //Set to true when stopMaster is called
-    private boolean stopMasterController = false;
+    //Indicates whether the Master Controller is currently
+    //active
+    private boolean active = false;
 
     //How long to wait before reporting the failure to
     //establish a connection with the slave.
@@ -95,33 +96,26 @@
     ////////////////////////////////////////////////////////////
 
     /**
-     * Used by Monitor.bootServiceModule to start the service. Will:
-     *
-     * Set up basic variables
-     * Connect to the slave using the network service (DERBY-2921)
-     *
-     * Not implemented yet
+     * Used by Monitor.bootServiceModule to start the service. Currently
+     * only used to set up the replication mode.
      *
      * @param create Currently ignored
      * @param properties Properties used to start the service in the
-     * correct mode
+     *                   correct mode. Currently initializes only the
+     *                   replicationMode property.
      * @exception StandardException Standard Derby exception policy,
      * thrown on error.
      */
     public void boot(boolean create, Properties properties)
         throws StandardException {
-
+        //The boot method is loaded only once, because of that the
+        //boot time parameters once wrong would result in repeated
+        //startMaster attempts failing. In order to allow for
+        //multiple start master attempts the slave host name, port
+        //number and the dbname have been moved to the startMaster
+        //method.
         replicationMode =
             properties.getProperty(MasterFactory.REPLICATION_MODE);
-
-        slavehost = properties.getProperty(MasterFactory.SLAVE_HOST);
-
-        String port = properties.getProperty(MasterFactory.SLAVE_PORT);
-        if (port != null) {
-            slaveport = new Integer(port).intValue();
-        }
-
-        dbname = properties.getProperty(MasterFactory.MASTER_DB);
     }
 
     ////////////////////////////////////////////////////////////////
@@ -171,13 +165,34 @@
      * @param rawStore The RawStoreFactory for the database
      * @param dataFac The DataFactory for this database
      * @param logFac The LogFactory ensuring recoverability for this database
+     * @param slavehost The hostname of the slave
+     * @param slaveport The port the slave is listening on
+     * @param dbname The master database that is being replicated.
      * @exception StandardException Standard Derby exception policy,
-     * thrown on replication startup error. 
+     *                              1) thrown on replication startup error
+     *                              2) thrown if the master has already been
+     *                                 booted.
+     *                              3) thrown if the specified replication mode
+     *                                 is not supported.
      */
     public void startMaster(RawStoreFactory rawStore,
-                            DataFactory dataFac, LogFactory logFac) 
+                            DataFactory dataFac,
+                            LogFactory logFac,
+                            String slavehost,
+                            int slaveport,
+                            String dbname)
                             throws StandardException {
-        stopMasterController = false;
+        if (active) {
+            //It is wrong to attempt startMaster on a already
+            //started master.
+            throw StandardException.newException
+                    (SQLState.REPLICATION_MASTER_ALREADY_BOOTED, dbname);
+        }
+
+        this.slavehost = slavehost;
+        this.slaveport = new Integer(slaveport).intValue();
+        this.dbname = dbname;
+
         rawStoreFactory = rawStore;
         dataFactory = dataFac;
         logFactory = logFac;
@@ -206,6 +221,9 @@
             throw se;
         }
 
+        //The master has been started successfully.
+        active = true;
+
         // Add code that initializes replication by sending the
         // database to the slave, making logFactory add logrecords to
         // the buffer etc. Repliation should be up and running when
@@ -215,10 +233,17 @@
     }
 
     /**
-     * Will perform all work that is needed to shut down replication
+     * Will perform all work that is needed to shut down replication.
+     *
+     * @throws StandardException If the replication master has been stopped
+     *                           already.
      */
-    public void stopMaster() {
-        stopMasterController = true;
+    public void stopMaster() throws StandardException {
+        if (!active) {
+            throw StandardException.newException
+                    (SQLState.REPLICATION_NOT_IN_MASTER_MODE);
+        }
+        active = false;
         logFactory.stopReplicationMasterRole();
         try {
             logShipper.flushBuffer();
@@ -240,11 +265,22 @@
      * @see org.apache.derby.iapi.services.replication.master.MasterFactory#startFailover()
      */
     public void startFailover() throws StandardException {
+        if (!active) {
+            //It is not correct to stop the master and then attempt a failover.
+            //The control would come here because the master module is already
+            //loaded and a findService for the master module will not fail. But
+            //since this module has been stopped failover does not suceed.
+            throw StandardException.newException
+                    (SQLState.REPLICATION_NOT_IN_MASTER_MODE);
+        }
+
         //acknowledgment returned from the slave containing
         //the status of the failover performed.
         ReplicationMessage ack = null;
         
-        stopMasterController = true;
+        //A failover stops the master controller and shuts down
+        //the master database.
+        active = false;
         
         //freeze the database to stop clients when this command is received
         rawStoreFactory.freeze();
@@ -431,7 +467,7 @@
                          exception, dbname);
             Monitor.logTextMessage(MessageId.REPLICATION_MASTER_RECONN, dbname);
             
-            while (!stopMasterController) {
+            while (active) {
                 try {
                     transmitter = new ReplicationMessageTransmit
                             (slavehost, slaveport);
@@ -473,7 +509,14 @@
     private void printStackAndStopMaster(Throwable t) {
         ReplicationLogger.
             logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, t, dbname);
-        stopMaster();
+        try {
+            stopMaster();
+        } catch (Throwable t_stopmaster) {
+            //The stop master threw an exception saying the replication
+            //has been stopped already.
+            ReplicationLogger.
+                logError(MessageId.REPLICATION_MASTER_STOPPED, t, dbname);
+        }
     }
     
     /**

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=634218&r1=634217&r2=634218&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 Thu Mar
 6 02:53:07 2008
@@ -487,10 +487,6 @@
         }
 
         Properties replicationProps = new Properties();
-        replicationProps.setProperty(MasterFactory.MASTER_DB, dbmaster);
-        replicationProps.setProperty(MasterFactory.SLAVE_HOST, host);
-        replicationProps.setProperty(MasterFactory.SLAVE_PORT,
-                                     new Integer(port).toString());
 
         replicationProps.setProperty(MasterFactory.REPLICATION_MODE,
                                      replicationMode);
@@ -498,7 +494,8 @@
         MasterFactory masterFactory = (MasterFactory)
             Monitor.bootServiceModule(true, this, getMasterFactoryModule(),
                                       replicationProps);
-        masterFactory.startMaster(this, dataFactory, logFactory);
+        masterFactory.startMaster(this, dataFactory, logFactory,
+                host, port, dbmaster);
 
     }
     

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=634218&r1=634217&r2=634218&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 Thu Mar  6 02:53:07
2008
@@ -4847,6 +4847,12 @@
             </msg>
 
             <msg>
+                <name>XRE22</name>
+                <text>Replication master has already been booted for database '{0}'</text>
+                <arg>dbname</arg>
+            </msg>
+
+            <msg>
                 <name>XRE40</name>
                 <text>Could not perform operation because the database is not in replication
slave mode.</text>
             </msg>

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=634218&r1=634217&r2=634218&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
Thu Mar  6 02:53:07 2008
@@ -1785,6 +1785,7 @@
     String REPLICATION_UNEXPECTED_MESSAGEID                        = "XRE12";
     String REPLICATION_FAILOVER_SUCCESSFUL                         = "XRE20.D";
     String REPLICATION_FAILOVER_UNSUCCESSFUL                       = "XRE21";
+    String REPLICATION_MASTER_ALREADY_BOOTED                       = "XRE22";
     String REPLICATION_NOT_IN_SLAVE_MODE                           = "XRE40";
     String SLAVE_OPERATION_DENIED_WHILE_CONNECTED                  = "XRE41";
     String REPLICATION_SLAVE_SHUTDOWN_OK                           = "XRE42";



Mime
View raw message