You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by oy...@apache.org on 2008/04/02 12:10:00 UTC
svn commit: r643828 - in /db/derby/code/branches/10.4/java:
engine/org/apache/derby/impl/jdbc/EmbedConnection.java
testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
Author: oysteing
Date: Wed Apr 2 03:09:53 2008
New Revision: 643828
URL: http://svn.apache.org/viewvc?rev=643828&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
Merged to 10.4 branch with command:
svn merge -r642218:642219 https://svn.apache.org/repos/asf/db/derby/code/trunk/
Modified:
db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=643828&r1=643827&r2=643828&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Wed Apr 2 03:09:53 2008
@@ -235,6 +235,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;
@@ -277,21 +281,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)) {
@@ -375,7 +384,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.
@@ -438,6 +463,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/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java?rev=643828&r1=643827&r2=643828&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java (original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java Wed Apr 2 03:09:53 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));
}
}