db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r614549 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/db/ engine/org/apache/derby/impl/db/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/impl/services/replication/ engine/org/apac...
Date Wed, 23 Jan 2008 14:36:14 GMT
Author: oysteing
Date: Wed Jan 23 06:36:10 2008
New Revision: 614549

URL: http://svn.apache.org/viewvc?rev=614549&view=rev
Log:
DERBY-3184: Add error handling to SlaveDatabase. Contributed by Jorgen Loland


Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/Database.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.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/ReplicationLogger.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/loc/messages.xml

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=614549&r1=614548&r2=614549&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Wed Jan 23
06:36:10 2008
@@ -49,6 +49,7 @@
 import java.util.Vector;
 
 import org.apache.derby.catalog.SystemProcedures;
+import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.error.ExceptionSeverity;
 import org.apache.derby.iapi.reference.Attribute;
 import org.apache.derby.iapi.reference.DRDAConstants;
@@ -8267,9 +8268,16 @@
             // does not exist - we just return security mechanism not
             // supported down below as we could not verify we can handle
             // it.
-            if (databaseObj != null)
-                authenticationService =
+            try {
+                if (databaseObj != null)
+                    authenticationService =
                         databaseObj.getAuthenticationService();
+            } catch (StandardException se) {
+                println2Log(null, session.drdaID, se.getMessage());
+                // Local security service non-retryable error.
+                return CodePoint.SECCHKCD_0A;
+            }
+
         }
 
         // Now we check if the authentication provider is NONE or BUILTIN

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/Database.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/Database.java?rev=614549&r1=614548&r2=614549&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/Database.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/Database.java Wed Jan 23 06:36:10
2008
@@ -102,8 +102,10 @@
 	 * and at the system level.
 	 *
 	 * @return	The authentication service handle for the database
+	 * @exception Standard Derby exception policy
 	 */
-	public AuthenticationService getAuthenticationService();
+	public AuthenticationService getAuthenticationService()
+		throws StandardException;
 
 	/**
 	 * Get a Resource Adapter - only used by XA system.  There is one and only

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=614549&r1=614548&r2=614549&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 Wed Jan 23
06:36:10 2008
@@ -343,7 +343,8 @@
 		DatabaseContext dc = new DatabaseContextImpl(cm, this);
 	}
 
-	public AuthenticationService getAuthenticationService() {
+	public AuthenticationService getAuthenticationService()
+		throws StandardException{
 
 		// Expected to find one - Sanity check being done at
 		// DB boot-up.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java?rev=614549&r1=614548&r2=614549&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java Wed Jan 23
06:36:10 2008
@@ -21,12 +21,14 @@
 
 package org.apache.derby.impl.db;
 
+import org.apache.derby.iapi.reference.MessageId;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.jdbc.AuthenticationService;
 import org.apache.derby.iapi.services.context.ContextManager;
 import org.apache.derby.iapi.services.context.ContextService;
 import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.impl.services.replication.ReplicationLogger;
 import org.apache.derby.iapi.services.replication.slave.SlaveFactory;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.impl.services.monitor.UpdateServiceProperties;
@@ -68,6 +70,7 @@
      * database. Does not happen until the failover command has been
      * executed for this database */
     private volatile boolean inReplicationSlaveMode;
+    private String dbname; // The name of the replicated database
 
     /////////////////////////////
     // ModuleControl interface //
@@ -101,6 +104,7 @@
         throws StandardException {
 
         inReplicationSlaveMode = true;
+        dbname = startParams.getProperty(SlaveFactory.SLAVE_DB);
 
         // SlaveDatabaseBootThread is an internal class
         SlaveDatabaseBootThread dbBootThread =
@@ -154,11 +158,13 @@
         return super.setupConnection(cm, user, drdaID, dbname);
     }
 
-    public AuthenticationService getAuthenticationService() {
+    public AuthenticationService getAuthenticationService()
+        throws StandardException{
         if (inReplicationSlaveMode) {
             // Cannot get authentication service for a database that
             // is currently in replication slave move
-            // Todo: throw exception
+            throw StandardException.newException(
+                SQLState.CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE, dbname);
         }
         return super.getAuthenticationService();
     }
@@ -185,7 +191,7 @@
 
             // The thread needs a ContextManager since two threads
             // cannot share a context
-            ContextManager bootThreadCm;
+            ContextManager bootThreadCm = null;
             try {
 
                 bootThreadCm = ContextService.getFactory().newContextManager();
@@ -195,10 +201,16 @@
                 bootBasicDatabase(create, params); // will be blocked
 
             } catch (StandardException se) {
-                //todo - report exception
+                ReplicationLogger.logError(MessageId.REPLICATION_FATAL_ERROR,
+                                           se, dbname);
+                // todo: shutdown this database
             } finally {
                 inReplicationSlaveMode = false;
-                //todo: tear down context
+                if (bootThreadCm != null) {
+                    ContextService.getFactory().
+                        resetCurrentContextManager(bootThreadCm);
+                    bootThreadCm = null;
+                }
             }
         }
     }

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=614549&r1=614548&r2=614549&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 Wed Jan
23 06:36:10 2008
@@ -729,11 +729,18 @@
 		//
 		AuthenticationService authenticationService = null;
 
-		// Retrieve appropriate authentication service handle
-		if (dbname == null)
-			authenticationService = getLocalDriver().getAuthenticationService();
-		else
-			authenticationService = getTR().getDatabase().getAuthenticationService();
+        try {
+            // Retrieve appropriate authentication service handle
+            if (dbname == null)
+                authenticationService =
+                    getLocalDriver().getAuthenticationService();
+            else
+                authenticationService =
+                    getTR().getDatabase().getAuthenticationService();
+
+        } catch (StandardException se) {
+            throw Util.generateCsSQLException(se);
+        }
 
 		// check that we do have a authentication service
 		// it is _always_ expected.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/ReplicationLogger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/ReplicationLogger.java?rev=614549&r1=614548&r2=614549&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/ReplicationLogger.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/ReplicationLogger.java
Wed Jan 23 06:36:10 2008
@@ -26,7 +26,7 @@
 import org.apache.derby.iapi.services.context.ErrorStringBuilder;
 import org.apache.derby.iapi.services.monitor.Monitor;
 
-public abstract class ReplicationLogger {
+public class ReplicationLogger {
 
     /** Whether or not to print log messages to derby.log. Defaults to
      * true, but can be set to false with derby property
@@ -47,7 +47,7 @@
      * @param t Error trace starts from this error
      * @param dbname The name of the replicated database
      */
-    protected void logError(String msgId, Throwable t, String dbname) {
+    public static void logError(String msgId, Throwable t, String dbname) {
 
         if (LOG_REPLICATION_MESSAGES) {
 

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=614549&r1=614548&r2=614549&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 06:36:10 2008
@@ -59,7 +59,7 @@
  *
  * @see MasterFactory
  */
-public class MasterController extends ReplicationLogger 
+public class MasterController 
         implements MasterFactory, ModuleControl, ModuleSupportable {
 
     private static final int DEFAULT_LOG_BUFFER_SIZE = 32768; //32K
@@ -219,9 +219,13 @@
 
             transmitter.sendMessage(mesg);
         } catch (IOException ioe) {
-            logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, ioe, dbname);
+            ReplicationLogger.
+                logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION,
+                         ioe, dbname);
         } catch(StandardException se) {
-            logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, se, dbname);
+            ReplicationLogger.
+                logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, 
+                         se, dbname);
         }
         Monitor.logTextMessage(MessageId.REPLICATION_MASTER_STOPPED, dbname);
     }
@@ -389,8 +393,9 @@
      */
     void handleExceptions(Exception exception) {
         if (exception instanceof IOException) {
-            logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, 
-                    exception, dbname);
+            ReplicationLogger.
+                logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, 
+                         exception, dbname);
             Monitor.logTextMessage(MessageId.REPLICATION_MASTER_RECONN, dbname);
             
             while (!stopMasterController) {
@@ -420,7 +425,8 @@
      * @param t the throwable that needs to be handled.
      */
     private void printStackAndStopMaster(Throwable t) {
-        logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, t, dbname);
+        ReplicationLogger.
+            logError(MessageId.REPLICATION_LOGSHIPPER_EXCEPTION, t, dbname);
         stopMaster();
     }
 }

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=614549&r1=614548&r2=614549&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 06:36:10 2008
@@ -57,7 +57,7 @@
  *
  * @see SlaveFactory
  */
-public class SlaveController extends ReplicationLogger
+public class SlaveController
     implements SlaveFactory, ModuleControl, ModuleSupportable {
 
 
@@ -313,7 +313,8 @@
             return;
         }
 
-        logError(MessageId.REPLICATION_SLAVE_LOST_CONN, eofe, dbname);
+        ReplicationLogger.
+            logError(MessageId.REPLICATION_SLAVE_LOST_CONN, eofe, dbname);
 
         try {
             while (!setupConnection()) {
@@ -372,7 +373,8 @@
             return;
         }
 
-        logError(MessageId.REPLICATION_FATAL_ERROR, e, dbname);
+        ReplicationLogger.
+            logError(MessageId.REPLICATION_FATAL_ERROR, e, dbname);
 
         // todo: notify master of the problem
         // todo: rawStoreFactory.stopReplicationSlave();

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=614549&r1=614548&r2=614549&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 06:36:10
2008
@@ -4735,7 +4735,7 @@
             </msg>
             <msg>
                 <name>XRE03</name>
-                <text>Unexpected error during replication network communication initiation.</text>
+                <text>Unexpected replication error. See derby.log for details.</text>
             </msg>
 
             <msg>



Mime
View raw message