db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r642219 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedConnection.java testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
Date Fri, 28 Mar 2008 13:10:42 GMT
Author: oysteing
Date: Fri Mar 28 06:10:38 2008
New Revision: 642219

URL: http://svn.apache.org/viewvc?rev=642219&view=rev
Log:
DERBY-3549:  Unable to start slave mode after authentication failure on a previous startSlave
attempt
Unboot database if startslave command fails on authentication.
Contributed by Jorgen Loland

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java

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=642219&r1=642218&r2=642219&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 Fri Mar
28 06:10:38 2008
@@ -234,6 +234,10 @@
 			boolean isTwoPhaseUpgradeBoot = (!createBoot &&
 											 isHardUpgradeBoot(info));
 			boolean isStartSlaveBoot = isStartReplicationSlaveBoot(info);
+            // Set to true if startSlave command is attempted on an
+            // already booted database. Will raise an exception when
+            // credentials have been verified
+            boolean slaveDBAlreadyBooted = false;
 
             boolean isFailoverMasterBoot = false;
             boolean isFailoverSlaveBoot = false;
@@ -276,21 +280,26 @@
 
             if (isStartSlaveBoot) {
                 if (database != null) {
-                    throw StandardException.newException(
-                        SQLState.CANNOT_START_SLAVE_ALREADY_BOOTED,
-                        getTR().getDBName());
+                    // If the slave database has already been booted,
+                    // the command should fail. Setting
+                    // slaveDBAlreadyBooted to true will cause an
+                    // exception to be thrown, but not until after
+                    // credentials have been verified so that db boot
+                    // information is not exposed to unauthorized
+                    // users
+                    slaveDBAlreadyBooted = true;
+                } else {
+                    // We need to boot the slave database two times. The
+                    // first boot will check authentication and
+                    // authorization. The second boot will put the
+                    // database in replication slave mode. SLAVE_PRE_MODE
+                    // ensures that log records are not written to disk
+                    // during the first boot. This is necessary because
+                    // the second boot needs a log that is exactly equal
+                    // to the log at the master.
+                    info.setProperty(SlaveFactory.REPLICATION_MODE,
+                                     SlaveFactory.SLAVE_PRE_MODE);
                 }
-
-                // We need to boot the slave database two times. The
-                // first boot will check authentication and
-                // authorization. The second boot will put the
-                // database in replication slave mode. SLAVE_PRE_MODE
-                // ensures that log records are not written to disk
-                // during the first boot. This is necessary because
-                // the second boot needs a log that is exactly equal
-                // to the log at the master.
-                info.setProperty(SlaveFactory.REPLICATION_MODE,
-                                 SlaveFactory.SLAVE_PRE_MODE);
             }
 
             if (isStopReplicationSlaveBoot(info)) {
@@ -374,7 +383,23 @@
 			// Check User's credentials and if it is a valid user of
 			// the database
 			//
-			checkUserCredentials(tr.getDBName(), info);
+            try {
+                checkUserCredentials(tr.getDBName(), info);
+            } catch (SQLException sqle) {
+                if (isStartSlaveBoot && !slaveDBAlreadyBooted) {
+                    // Failing credentials check on a previously
+                    // unbooted db should not leave the db booted
+                    // for startSlave command.
+
+                    // tr.startTransaction is needed to get the
+                    // Database context. Without this context,
+                    // handleException will not shutdown the
+                    // database
+                    tr.startTransaction();
+                    handleException(tr.shutdownDatabaseException());
+                }
+                throw sqle;
+            }
 
 			// Make a real connection into the database, setup lcc, tc and all
 			// the rest.
@@ -437,6 +462,14 @@
 				}
 
 				if (isStartSlaveBoot) {
+					// Throw an exception if the database had been
+					// booted before this startSlave connection attempt.
+					if (slaveDBAlreadyBooted) {
+						throw StandardException.newException(
+						SQLState.CANNOT_START_SLAVE_ALREADY_BOOTED,
+						getTR().getDBName());
+					}
+
 					// Let the next boot of the database be
 					// replication slave mode
 					info.setProperty(SlaveFactory.REPLICATION_MODE,

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java?rev=642219&r1=642218&r2=642219&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
Fri Mar 28 06:10:38 2008
@@ -427,7 +427,7 @@
             String msg = ec + " " + ss + " " + se.getMessage();
             util.DEBUG("3. startSlave No connection as expected: " + msg);
             assertTrue("3. Unexpected SQLException: " + msg, 
-                    SQLState.CANNOT_START_SLAVE_ALREADY_BOOTED.equals(ss));
+                   SQLState.CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE.startsWith(ss));
         }
     }
     



Mime
View raw message