db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r605556 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/replication/master/ impl/services/replication/master/ impl/services/replication/slave/
Date Wed, 19 Dec 2007 14:49:10 GMT
Author: oysteing
Date: Wed Dec 19 06:49:09 2007
New Revision: 605556

URL: http://svn.apache.org/viewvc?rev=605556&view=rev
Log:
DERBY-3235: Implement the replication stop functionality.
Contributed by 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/AsynchronousLogShipper.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/LogShipper.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

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=605556&r1=605555&r2=605556&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 Dec 19 06:49:09 2007
@@ -117,6 +117,9 @@
 
     /**
      * Will perform all work that is needed to shut down replication
+     *
+     * @throws StandardException Standard Derby exception policy,
+     *                           thrown on replication stop failure.
      */
     public void stopMaster();
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/AsynchronousLogShipper.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/AsynchronousLogShipper.java?rev=605556&r1=605555&r2=605556&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/AsynchronousLogShipper.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/AsynchronousLogShipper.java
Wed Dec 19 06:49:09 2007
@@ -152,8 +152,11 @@
      *                     across the network.
      * @throws StandardException If an exception occurs while trying to read
      *                           log records from the log buffer.
+     * 
+     * @return true if a chunk of log records was shipped.
+     *         false if no log records were shipped because log buffer is empty.
      */
-    private synchronized void shipALogChunk()
+    private synchronized boolean shipALogChunk()
     throws IOException, StandardException {
         byte [] logRecords = null;
         ReplicationMessage mesg = null;
@@ -175,7 +178,8 @@
                     ReplicationMessage.TYPE_LOG, logRecords);
                 
                 transmitter.sendMessage(mesg);
-            }
+                return true;
+            } 
         } catch (NoSuchElementException nse) {
             //Although next() returns true a request for data on the buffer
             //fails implying that there has been a fatal exception in the
@@ -188,6 +192,21 @@
             failedChunk = (mesg==null) ? failedChunk : mesg;
             throw ioe;
         }
+        return false;
+    }
+    
+    /**
+     *
+     * Transmits all the log records in the log buffer to the slave.
+     *
+     * @throws IOException If an exception occurs while trying to ship the
+     *                     replication message (containing the log records)
+     *                     across the network.
+     * @throws StandardException If an exception occurs while trying to read
+     *                           log records from the log buffer.
+     */
+    public void flushBuffer() throws IOException, StandardException {
+        while (shipALogChunk());
     }
     
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/LogShipper.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/LogShipper.java?rev=605556&r1=605555&r2=605556&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/LogShipper.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/master/LogShipper.java
Wed Dec 19 06:49:09 2007
@@ -57,4 +57,17 @@
      *                           log records from the log buffer.
      */
     public void forceFlush() throws IOException, StandardException;
+    
+    /**
+     *
+     * Transmits all the log records in the log buffer to the slave.
+     *
+     * @throws IOException If an exception occurs while trying to ship the
+     *                     replication message (containing the log records)
+     *                     across the network.
+     * @throws StandardException If an exception occurs while trying to read
+     *                           log records from the log buffer.
+     *
+     */
+    public void flushBuffer() throws IOException, StandardException;
 }

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=605556&r1=605555&r2=605556&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 Dec 19 06:49:09 2007
@@ -37,6 +37,7 @@
 
 import org.apache.derby.iapi.services.replication.master.MasterFactory;
 
+import org.apache.derby.impl.services.replication.net.ReplicationMessage;
 import org.apache.derby.impl.services.replication.ReplicationLogger;
 import org.apache.derby.impl.services.replication.net.ReplicationMessageTransmit;
 import org.apache.derby.impl.services.replication.buffer.ReplicationLogBuffer;
@@ -207,10 +208,19 @@
      */
     public void stopMaster() {
         stopMasterController = true;
-        //interrupt the periodic shipper first
-        logShipper.interrupt();
-        //This would ensure that any further call to forceFlush fails.
-        logShipper.stopLogShipment();
+        logFactory.stopReplicationMasterRole();
+        try {
+            logShipper.flushBuffer();
+
+            ReplicationMessage mesg = new ReplicationMessage(
+                        ReplicationMessage.TYPE_STOP, null);
+
+            transmitter.sendMessage(mesg);
+        } catch (IOException ioe) {
+            logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, ioe, dbname);
+        } catch(StandardException se) {
+            logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, se, dbname);
+        }
         Monitor.logTextMessage(MessageId.REPLICATION_MASTER_STOPPED, dbname);
     }
 

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=605556&r1=605555&r2=605556&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 Dec 19 06:49:09 2007
@@ -406,6 +406,9 @@
                         byte[] logChunk = (byte[])message.getMessage();
                         handleLogChunk(logChunk);
                         break;
+                    case ReplicationMessage.TYPE_STOP:
+                        stopSlave();
+                        break;
                     default:
                         // debug; will be removed
                         System.out.println("Not handling non-log messages yet "



Mime
View raw message