db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r576835 - in /db/derby/code/trunk: java/engine/org/apache/derby/iapi/services/replication/master/ java/engine/org/apache/derby/iapi/store/raw/log/ java/engine/org/apache/derby/impl/services/replication/master/ java/engine/org/apache/derby/i...
Date Tue, 18 Sep 2007 10:54:24 GMT
Author: oysteing
Date: Tue Sep 18 03:54:23 2007
New Revision: 576835

URL: http://svn.apache.org/viewvc?rev=576835&view=rev
Log:
DERBY-3051: Modify logging subsystem to append log records to the replication buffer when
in replication master mode
Contributed by Jorgen Loland

Added:
    db/derby/code/trunk/tools/testing/derby/
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/iapi/store/raw/log/LogFactory.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/log/LogToFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.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=576835&r1=576834&r2=576835&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 Sep 18 03:54:23 2007
@@ -104,9 +104,12 @@
      * @param rawStore The RawStoreFactory for the database
      * @param dataFac The DataFactory for this database
      * @param logFac The LogFactory ensuring recoverability for this database
+     * @exception StandardException Standard Derby exception policy,
+     * thrown on replication startup error. 
      */
     public void startMaster(RawStoreFactory rawStore,
-                            DataFactory dataFac, LogFactory logFac);
+                            DataFactory dataFac, LogFactory logFac)
+        throws StandardException;
 
     /**
      * Will perform all work that is needed to shut down replication
@@ -116,18 +119,22 @@
     /**
      * Append a single log record to the replication log buffer.
      *
-     * @param instant               the log address of this log record.
      * @param dataLength            number of bytes in data[]
-     * @param dataOffset            offset in data[] to start copying from.
-     * @param optionalDataLength    number of bytes in optionalData[]
-     * @param optionalDataOffset    offset in optionalData[] to start copy from
+     * @param instant               the log address of this log record.
      * @param data                  "from" array to copy "data" portion of rec
+     * @param dataOffset            offset in data[] to start copying from.
      * @param optionalData          "from" array to copy "optional data" from
+     * @param optionalDataOffset    offset in optionalData[] to start copy from
+     * @param optionalDataLength    number of bytes in optionalData[]
+     *
      **/
-    public void appendLogRecord(long instant, int dataLength,
-                                int dataOffset, int optionalDataLength,
+    public void appendLogRecord(int dataLength,
+                                long instant,
+                                byte[] data,
+                                int dataOffset,
+                                byte[] optionalData, 
                                 int optionalDataOffset,
-                                byte[] data, byte[] optionalData);
+                                int optionalDataLength);
 
     /**
      * Used by the LogFactory to notify the replication master

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java?rev=576835&r1=576834&r2=576835&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java Tue
Sep 18 03:54:23 2007
@@ -23,6 +23,7 @@
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.property.PersistentSet;
+import org.apache.derby.iapi.services.replication.master.MasterFactory;
 import org.apache.derby.iapi.store.raw.data.DataFactory;
 import org.apache.derby.iapi.store.raw.Corruptable;
 import org.apache.derby.iapi.store.raw.RawStoreFactory;
@@ -349,6 +350,27 @@
                                 int requiredMinorVersion, 
                                 String feature) 
         throws StandardException;
+
+    /**
+     * Make this LogFactory pass log records to the MasterFactory
+     * every time a log record is appended to the log on disk, and
+     * notify the MasterFactory when a log disk flush has taken place.
+     * Not implemented by ReadOnly.
+     * @param masterFactory The MasterFactory service responsible for
+     * controlling the master side replication behaviour.
+     * @exception StandardException Standard Derby exception policy,
+     * thrown on replication startup error. Will only be thrown if
+     * replication is attempted started on a readonly database.
+     */
+    public void startReplicationMasterRole(MasterFactory masterFactory)
+        throws StandardException;
+
+    /**
+     * Stop this LogFactory from passing log records to the
+     * MasterFactory and from notifying the MasterFactory when a log
+     * disk flush has taken place. Not implemented by ReadOnly.
+     */
+    public void stopReplicationMasterRole();
 
 }
 

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=576835&r1=576834&r2=576835&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 Sep 18 03:54:23 2007
@@ -161,9 +161,12 @@
      * @param rawStore The RawStoreFactory for the database
      * @param dataFac The DataFactory for this database
      * @param logFac The LogFactory ensuring recoverability for this database
+     * @exception StandardException Standard Derby exception policy,
+     * thrown on replication startup error. 
      */
     public void startMaster(RawStoreFactory rawStore,
-                            DataFactory dataFac, LogFactory logFac) {
+                            DataFactory dataFac, LogFactory logFac)
+        throws StandardException{
         // Added when Network Service has been committed to trunk:
         // connection.connect(); // sets up a network connection to the slave
 
@@ -173,6 +176,8 @@
         logBuffer = new ReplicationLogBuffer(DEFAULT_LOG_BUFFER_SIZE);
         //  logFactory.setReplicationMaster(this); //added later
 
+        logFactory.startReplicationMasterRole(this);
+
         if (replicationMode.equals(MasterFactory.ASYNCHRONOUS_MODE)) {
             System.out.println("MasterController would now " +
                                "start asynchronous log shipping");
@@ -208,22 +213,22 @@
     /**
      * Append a single log record to the replication log buffer.
      *
-     * @param instant               the log address of this log record.
      * @param dataLength            number of bytes in data[]
-     * @param dataOffset            offset in data[] to start copying from.
-     * @param optionalDataLength    number of bytes in optionalData[]
-     * @param optionalDataOffset    offset in optionalData[] to start copy from
+     * @param instant               the log address of this log record.
      * @param data                  "from" array to copy "data" portion of rec
+     * @param dataOffset            offset in data[] to start copying from.
      * @param optionalData          "from" array to copy "optional data" from
+     * @param optionalDataOffset    offset in optionalData[] to start copy from
+     * @param optionalDataLength    number of bytes in optionalData[]
      *
      **/
-    public void appendLogRecord(long instant,
-                                int dataLength,
+    public void appendLogRecord(int dataLength,
+                                long instant,
+                                byte[] data,
                                 int dataOffset,
-                                int optionalDataLength,
+                                byte[] optionalData, 
                                 int optionalDataOffset,
-                                byte[] data,
-                                byte[] optionalData) {
+                                int optionalDataLength) {
         try {
             logBuffer.appendLogRecord(instant, dataLength, dataOffset,
                                       optionalDataLength, optionalDataOffset,

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=576835&r1=576834&r2=576835&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 Tue
Sep 18 03:54:23 2007
@@ -38,8 +38,6 @@
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.SQLState;
 
-import org.apache.derby.iapi.services.replication.slave.SlaveFactory;
-
 import org.apache.derby.iapi.services.daemon.DaemonService;
 import org.apache.derby.iapi.services.daemon.Serviceable;
 import org.apache.derby.iapi.services.context.ContextManager;
@@ -74,6 +72,8 @@
 import org.apache.derby.iapi.store.raw.xact.TransactionFactory;
 import org.apache.derby.iapi.store.raw.data.DataFactory;
 import org.apache.derby.iapi.services.property.PersistentSet;
+import org.apache.derby.iapi.services.replication.master.MasterFactory;
+import org.apache.derby.iapi.services.replication.slave.SlaveFactory;
 
 import org.apache.derby.iapi.store.access.DatabaseInstant;
 import org.apache.derby.catalog.UUID;
@@ -373,6 +373,12 @@
 	protected boolean	ReadOnlyDB;	// true if this db is read only, i.e, cannot
 								// append log records
 
+    // REPLICATION 
+    // initialized if this Derby has the master role for this database
+    private MasterFactory masterFactory; 
+    private boolean inReplicationMasterMode = false;
+    // initialized if this Derby has the slave role for this database
+    private boolean inReplicationSlaveMode = false;
 
 	// DEBUG DEBUG - do not truncate log files
 	private boolean keepAllLogs;
@@ -476,8 +482,6 @@
     private volatile boolean backupInProgress = false; 
    
 
-    private boolean inSlaveMode = false;
-
 	/**
 		MT- not needed for constructor
 	*/
@@ -2850,7 +2854,7 @@
         // Is the database booted in replication slave mode?
         String mode = startParams.getProperty(SlaveFactory.REPLICATION_MODE);
         if (mode != null && mode.equals(SlaveFactory.SLAVE_MODE)) {
-            inSlaveMode = true; 
+            inReplicationSlaveMode = true; 
             // will be used when slave functionality is added to this class
         }
 
@@ -3560,6 +3564,22 @@
                     length, instant, data, offset, 
                     optionalData, optionalDataOffset, optionalDataLength);
 
+                if (inReplicationMasterMode) {
+                    // Append this log record to the replication log
+                    // buffer so that it can be shipped to the slave.
+                    // Note that the length field is not the same as
+                    // used by writeLogRecord which uses the length of
+                    // data+optionalData - masterFactory needs the
+                    // length of data alone.
+                    masterFactory.appendLogRecord(length - optionalDataLength,
+                                                  instant,
+                                                  data, 
+                                                  offset,
+                                                  optionalData,
+                                                  optionalDataOffset,
+                                                  optionalDataLength);
+                }
+
 				if (optionalDataLength != 0) 
                 {
 					if (SanityManager.DEBUG)
@@ -3761,7 +3781,21 @@
 						// once logBeingFlushed is set, need to release
 						// the logBeingFlushed flag in finally block.
 						logBeingFlushed = true;	
-					}
+
+                        // If in Replication Master mode - Notify the
+                        // MasterFactory that log has been flushed to
+                        // disk. At this point, we know that this is a
+                        // "real" flush, not just a call to check
+                        // whether the database is frozen/corrupted
+                        // (i.e., wherePosition ==
+                        // LogCounter.INVALID_LOG_INSTANT has already
+                        // been checked)
+                        if (inReplicationMasterMode) {
+                            masterFactory.flushedTo(LogCounter.
+                                       makeLogInstantAsLong(fileNumber,
+                                                            wherePosition));
+                        }
+                    }
 
 				} while (waited) ;
 				// if I have waited, go down do loop again - hopefully,
@@ -4845,6 +4879,32 @@
 		
 	}
 
+    /**
+     * Make this LogFactory pass log records to the MasterFactory
+     * every time a log record is appended to the log on disk, and
+     * notify the MasterFactory when a log disk flush has taken place.
+     * @param masterFactory The MasterFactory service responsible for
+     * controlling the master side replication behaviour.
+     * @exception StandardException Standard Derby exception policy,
+     * thrown on replication startup error. Will only be thrown if
+     * replication is attempted started on a readonly database, i.e,
+     * never thrown here.
+     */
+    public void startReplicationMasterRole(MasterFactory masterFactory) 
+        throws StandardException {
+        this.masterFactory = masterFactory;
+        inReplicationMasterMode = true;
+    }
+
+    /**
+     * Stop this LogFactory from passing log records to the
+     * MasterFactory and from notifying the MasterFactory when a log
+     * disk flush has taken place.
+     */
+    public void stopReplicationMasterRole() {
+        inReplicationMasterMode = false;
+        masterFactory = null;
+    }
 
 	/**
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java?rev=576835&r1=576834&r2=576835&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java Tue
Sep 18 03:54:23 2007
@@ -37,6 +37,7 @@
 import org.apache.derby.iapi.store.raw.log.LogInstant;
 import org.apache.derby.iapi.store.raw.log.Logger;
 import org.apache.derby.iapi.store.raw.log.LogScan;
+import org.apache.derby.iapi.services.replication.master.MasterFactory;
 
 import org.apache.derby.iapi.store.raw.data.DataFactory;
 import org.apache.derby.iapi.store.raw.xact.TransactionFactory;
@@ -445,4 +446,19 @@
         throw StandardException.newException(
                   SQLState.STORE_FEATURE_NOT_IMPLEMENTED);
     }
+
+    /** Replication not applicable on readonly databases 
+     * @exception StandardException always thrown, indicating that
+     * ReadOnly databases can not be replicated
+     */
+    public void startReplicationMasterRole(MasterFactory masterFactory)
+        throws StandardException {
+        throw StandardException.newException(
+                  SQLState.CANNOT_REPLICATE_READONLY_DATABASE);
+    }
+
+    /** Replication not applicable on readonly databases */
+    public void stopReplicationMasterRole() {
+    }
+
 }



Mime
View raw message