db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r595591 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/t...
Date Fri, 16 Nov 2007 08:42:32 GMT
Author: kahatlen
Date: Fri Nov 16 00:42:26 2007
New Revision: 595591

URL: http://svn.apache.org/viewvc?rev=595591&view=rev
Log:
DERBY-3189: Replication: Add connection url command options for
starting and stopping master

Attaching patch v1a, handling startMaster and startSlave url commands
in EmbedConnection. Waiting for DERBY-2954 before stopMaster can be
activated (a single code line has been commented out).

Patch contributed by Jørgen Løland.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java?rev=595591&r1=595590&r2=595591&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java Fri Nov
16 00:42:26 2007
@@ -101,7 +101,30 @@
 
 	String NEW_BOOT_PASSWORD = "newBootPassword";
 
+    /**
+     * Attribute name to start replication master mode for a database.
+     * If used, REPLICATION_SLAVE_HOST is a required attribute.
+     */
+    String REPLICATION_START_MASTER = "startMaster";
 
+    /**
+     * Attribute name to stop replication master mode for a database.
+     */
+    String REPLICATION_STOP_MASTER = "stopMaster";
+
+    /**
+     * If startMaster is true, this attribute is used to specify the
+     * host name the master should connect to. This is a required
+     * attribute.
+     */
+    String REPLICATION_SLAVE_HOST = "slaveHost";
+
+    /**
+     * If startMaster is true, this attribute is used to specify the
+     * port the master should connect to. This is an optional
+     * attribute
+     */
+    String REPLICATION_SLAVE_PORT = "slavePort";
 
 	/**
 		The attribute that is used for the database name, from

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=595591&r1=595590&r2=595591&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 Nov
16 00:42:26 2007
@@ -304,6 +304,14 @@
 			// the rest.
 			tr.startTransaction();
 
+			if (isStartReplicationMasterBoot(info) && !shutdown) {
+				handleStartReplicationMaster(tr, info);
+			} else if (isStopReplicationMasterBoot(info)) {
+				// Stopping replication master can be done
+				// simultaneously with a database shutdown operation
+				handleStopReplicationMaster(tr, info);
+			}
+
 			if (isTwoPhaseEncryptionBoot || isTwoPhaseUpgradeBoot) {
 
 				// DERBY-2264: shutdown and boot again with encryption or
@@ -474,6 +482,86 @@
 			p.getProperty(Attribute.UPGRADE_ATTR)).booleanValue();
 	}
 
+    private boolean isStartReplicationMasterBoot(Properties p) {
+        return ((Boolean.valueOf(
+                 p.getProperty(Attribute.REPLICATION_START_MASTER)).
+                 booleanValue()));
+    }
+
+    private boolean isStopReplicationMasterBoot(Properties p) {
+        return ((Boolean.valueOf(
+                 p.getProperty(Attribute.REPLICATION_STOP_MASTER)).
+                 booleanValue()));
+    }
+
+    private void handleStartReplicationMaster(TransactionResourceImpl tr,
+                                              Properties p)
+        throws SQLException {
+
+        // If authorization is turned on, we need to check if this
+        // user is database owner.
+        if (!usingNoneAuth &&
+            getLanguageConnection().usesSqlAuthorization()) {
+            checkIsDBOwner(OP_REPLICATION);
+        }
+        // TODO: If system privileges is turned on, we need to check
+        // that the user has the replication privilege. Waiting for
+        // Derby-2109
+
+        // At this point, the user is properly authenticated,
+        // authorized and has the correct system privilege to start
+        // replication - depending on the security mechanisms
+        // Derby is running under.
+
+        String slavehost =
+            p.getProperty(Attribute.REPLICATION_SLAVE_HOST);
+
+        if (slavehost == null) {
+            // slavehost is required attribute.
+            SQLException wrappedExc =
+                newSQLException(SQLState.PROPERTY_MISSING,
+                                Attribute.REPLICATION_SLAVE_HOST);
+            throw newSQLException(SQLState.LOGIN_FAILED, wrappedExc);
+        }
+
+        String portString =
+            p.getProperty(Attribute.REPLICATION_SLAVE_PORT);
+        int slaveport = -1; // slaveport < 0 will use the default port
+        if (portString != null) {
+            slaveport = Integer.valueOf(portString).intValue();
+        }
+
+        tr.getDatabase().startReplicationMaster(slavehost,
+                                                slaveport,
+                                                org.apache.derby.iapi.
+                                                services.replication.
+                                                master.MasterFactory.
+                                                ASYNCHRONOUS_MODE);
+    }
+
+    private void handleStopReplicationMaster(TransactionResourceImpl tr,
+                                             Properties p)
+        throws SQLException {
+
+        // If authorization is turned on, we need to check if this
+        // user is database owner.
+        if (!usingNoneAuth &&
+            getLanguageConnection().usesSqlAuthorization()) {
+            checkIsDBOwner(OP_REPLICATION);
+        }
+        // TODO: If system privileges is turned on, we need to check
+        // that the user has the replication privilege. Waiting for
+        // Derby-2109
+
+        // At this point, the user is properly authenticated,
+        // authorized and has the correct system privilege to start
+        // replication - depending on the security mechanisms
+        // Derby is running under.
+
+        // Waiting for Derby-2954:
+        // tr.getDatabase().stopReplicationMaster();
+    }
+
 	/**
 	 * Remove any encryption or upgarde properties from the given properties
 	 *
@@ -601,6 +689,7 @@
 	private static final int OP_ENCRYPT = 0;
 	private static final int OP_SHUTDOWN = 1;
 	private static final int OP_HARD_UPGRADE = 2;
+	private static final int OP_REPLICATION = 3;
 	/**
 	 * Check if actual authenticationId is equal to the database owner's.
 	 *
@@ -624,6 +713,9 @@
 									  actualId, tr.getDBName());
 			case OP_HARD_UPGRADE:
 				throw newSQLException(SQLState.AUTH_HARD_UPGRADE_NOT_DB_OWNER,
+									  actualId, tr.getDBName());
+			case OP_REPLICATION:
+				throw newSQLException(SQLState.AUTH_REPLICATION_NOT_DB_OWNER,
 									  actualId, tr.getDBName());
 			default:
 				if (SanityManager.DEBUG) {

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=595591&r1=595590&r2=595591&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 Fri Nov 16 00:42:26
2007
@@ -383,6 +383,14 @@
                 <text>Connection refused to database '{0}' because it is in replication
slave mode.</text>
                 <arg>databaseName</arg>
             </msg>
+
+            <msg>
+                <name>08004.C.8</name>
+                <text>User '{0}' cannot issue a replication operation on database '{1}'.
Only the database owner can perform this operation.</text>
+                <arg>authorizationID</arg>
+                <arg>databaseName</arg>
+            </msg>
+
             <msg>
                 <name>08006.C</name>
                 <text>A network protocol error was encountered and the connection has
been terminated: {0}</text>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java?rev=595591&r1=595590&r2=595591&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/Attribute.java
Fri Nov 16 00:42:26 2007
@@ -92,6 +92,31 @@
     String BOOT_PASSWORD = "bootPassword";
 
     /**
+     * Attribute name to start replication master mode for a database.
+     * If used, REPLICATION_SLAVE_HOST is a required attribute.
+     */
+    String REPLICATION_START_MASTER = "startMaster";
+
+    /**
+     * Attribute name to stop replication master mode for a database.
+     */
+    String REPLICATION_STOP_MASTER = "stopMaster";
+
+    /**
+     * If startMaster is true, this attribute is used to specify the
+     * host name the master should connect to. This is a required
+     * attribute.
+     */
+    String REPLICATION_SLAVE_HOST = "slaveHost";
+
+    /**
+     * If startMaster is true, this attribute is used to specify the
+     * port the master should connect to. This is an optional
+     * attribute.
+     */
+    String REPLICATION_SLAVE_PORT = "slavePort";
+
+    /**
      * The attribute that is used for the database name, from the JDBC notion of
      * jdbc:<subprotocol>:<subname>
      */

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=595591&r1=595590&r2=595591&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Fri Nov 16 00:42:26 2007
@@ -1590,6 +1590,7 @@
     String AUTH_HARD_UPGRADE_NOT_DB_OWNER                   = "08004.C.6";
     //DERBY-1828: AUTH_x_NOT_DB_OWNER used to be "2850H/I/J.C";
     String CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE               = "08004.C.7";
+    String AUTH_REPLICATION_NOT_DB_OWNER                    = "08004.C.8";
 
     // There can be multiple causes for 08003, which according
     // to SQL2003 spec means "connection does not exist"

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java?rev=595591&r1=595590&r2=595591&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
Fri Nov 16 00:42:26 2007
@@ -123,6 +123,7 @@
         		{"08004","User '{0}' cannot (re)encrypt database '{1}'. Only the database owner
can perform this operation.","40000"},
         		{"08004","User '{0}' cannot hard upgrade database '{1}'. Only the database owner
can perform this operation.","40000"},
         		{"08004","Connection refused to database '{0}' because it is in replication slave
mode.","40000"},
+        		{"08004","User '{0}' cannot issue a replication operation on database '{1}'. Only
the database owner can perform this operation.","40000"},
         		{"08006","An error occurred during connect reset and the connection has been terminated.
 See chained exceptions for details.","40000"},
         		{"08006","SocketException: '{0}'","40000"},
         		{"08006","A communications error has been detected: {0}.","40000"},



Mime
View raw message