Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 12540 invoked from network); 4 Apr 2008 15:52:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Apr 2008 15:52:28 -0000 Received: (qmail 43888 invoked by uid 500); 4 Apr 2008 15:52:28 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 43856 invoked by uid 500); 4 Apr 2008 15:52:28 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 43845 invoked by uid 99); 4 Apr 2008 15:52:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 08:52:28 -0700 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 15:51:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 85F211A9832; Fri, 4 Apr 2008 08:52:06 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r644742 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication: master/MasterController.java net/ReplicationMessageReceive.java net/ReplicationMessageTransmit.java slave/SlaveController.java Date: Fri, 04 Apr 2008 15:52:05 -0000 To: derby-commits@db.apache.org From: oysteing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080404155206.85F211A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oysteing Date: Fri Apr 4 08:51:58 2008 New Revision: 644742 URL: http://svn.apache.org/viewvc?rev=644742&view=rev Log: DERBY-3489: Error message XRE04 does not include the right port number. Contributed by V Narayanan * java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageTransmit.java The constructor has been modified to accept the SlaveAddress object instead of a host name and port number as was happening previously. * java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java Modified the constructor to accept a SlaveAddress object instead of a host name and port number. Removed the getHostName() and getPort() functions, these functions seemed superfluous. They are no longer used in the SlaveController, they are used in only once place in the receiver when an exception was being thrown. * java/engine/org/apache/derby/impl/store/replication/slave/SlaveController.java slavehost and slaveport are no longer used (SlaveAddress object is instead used). introduced two functions getHostName and getPortNumber here that return the hostName and portNumber from SlaveAddress. * java/engine/org/apache/derby/impl/store/replication/master/MasterController.java slavehost and slaveport are no longer used (SlaveAddress object is instead used). introduced two functions getHostName and getPortNumber here that return the hostName and portNumber from SlaveAddress. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/master/MasterController.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageTransmit.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/slave/SlaveController.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/master/MasterController.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/master/MasterController.java?rev=644742&r1=644741&r2=644742&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/master/MasterController.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/master/MasterController.java Fri Apr 4 08:51:58 2008 @@ -24,6 +24,7 @@ import java.io.IOException; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.reference.MessageId; import org.apache.derby.iapi.reference.SQLState; @@ -47,6 +48,7 @@ import org.apache.derby.impl.store.replication.buffer.LogBufferFullException; import java.util.Properties; +import org.apache.derby.impl.store.replication.net.SlaveAddress; /** *

@@ -78,8 +80,7 @@ private ReplicationLogger repLogger; private String replicationMode; - private String slavehost; - private int slaveport; + private SlaveAddress slaveAddr; private String dbname; private int logBufferSize = 0; @@ -202,8 +203,15 @@ (SQLState.REPLICATION_MASTER_ALREADY_BOOTED, dbname); } - this.slavehost = slavehost; - this.slaveport = new Integer(slaveport).intValue(); + try { + slaveAddr = new SlaveAddress(slavehost, + (new Integer(slaveport)).intValue()); + } catch (UnknownHostException uhe) { + throw StandardException.newException + (SQLState.REPLICATION_CONNECTION_EXCEPTION, uhe, + dbname, getHostName(), String.valueOf(getPortNumber())); + } + this.dbname = dbname; rawStoreFactory = rawStore; @@ -468,9 +476,8 @@ if (transmitter != null) { transmitter.tearDown(); } - transmitter = new ReplicationMessageTransmit(slavehost, - slaveport, - dbname); + transmitter = new ReplicationMessageTransmit(slaveAddr); + // getHighestShippedInstant is -1 until the first log // chunk has been shipped to the slave. If a log chunk has // been shipped, use the instant of the latest shipped log @@ -493,13 +500,13 @@ } catch (IOException ioe) { throw StandardException.newException (SQLState.REPLICATION_CONNECTION_EXCEPTION, ioe, - dbname, slavehost, String.valueOf(slaveport)); + dbname, getHostName(), String.valueOf(getPortNumber())); } catch (StandardException se) { throw se; } catch (Exception e) { throw StandardException.newException (SQLState.REPLICATION_CONNECTION_EXCEPTION, e, - dbname, slavehost, String.valueOf(slaveport)); + dbname, getHostName(), String.valueOf(getPortNumber())); } } @@ -521,13 +528,7 @@ while (active) { try { - if (transmitter != null) { - transmitter.tearDown(); - } - transmitter = new ReplicationMessageTransmit(slavehost, - slaveport, - dbname); - + transmitter = new ReplicationMessageTransmit(slaveAddr); // see comment in setupConnection if (logShipper != null && logShipper.getHighestShippedInstant() != -1) { @@ -623,5 +624,25 @@ */ String getDbName() { return this.dbname; + } + + /** + * Used to return the host name of the slave being connected to. + * + * @return a String containing the host name of the slave being + * connected to. + */ + private String getHostName() { + return slaveAddr.getHostAddress().getHostName(); + } + + /** + * Used to return the port number of the slave being connected to. + * + * @return an Integer that represents the port number of the slave + * being connected to. + */ + private int getPortNumber() { + return slaveAddr.getPortNumber(); } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java?rev=644742&r1=644741&r2=644742&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java Fri Apr 4 08:51:58 2008 @@ -25,7 +25,6 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -import java.net.UnknownHostException; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -93,36 +92,17 @@ * the host name and port number that constitute the slave address as * parameters. * - * @param hostName a String that contains the host name of - * the slave to replicate to. - * @param portNumber an integer that contains the port number of the - * slave to replicate to. - * @param dbname the name of the database - * - * @throws StandardException If an exception occurs while trying to - * resolve the host name. - */ - public ReplicationMessageReceive(String hostName, int portNumber, - String dbname) - throws StandardException { - try { - slaveAddress = new SlaveAddress(hostName, portNumber); - Monitor.logTextMessage(MessageId.REPLICATION_SLAVE_NETWORK_LISTEN, - dbname, getHostName(), - String.valueOf(getPort())); - } catch (UnknownHostException uhe) { - // cannot use getPort because SlaveAddress creator threw - // exception and has therefore not been initialized - String port; - if (portNumber > 0) { - port = String.valueOf(portNumber); - } else { - port = String.valueOf(SlaveAddress.DEFAULT_PORT_NO); - } - throw StandardException.newException - (SQLState.REPLICATION_CONNECTION_EXCEPTION, uhe, - dbname, hostName, port); - } + * @param slaveAddress the address (host name and port number) of the slave + * to connect to. + * @param dbname the name of the database. + */ + public ReplicationMessageReceive(SlaveAddress slaveAddress, + String dbname) { + this.slaveAddress = slaveAddress; + Monitor.logTextMessage(MessageId.REPLICATION_SLAVE_NETWORK_LISTEN, + dbname, + slaveAddress.getHostAddress().getHostName(), + String.valueOf(slaveAddress.getPortNumber())); } /** @@ -440,26 +420,6 @@ return msg; } } - - /** - * Used to get the host name the slave listens for master - * connections on - * - * @return the host name - */ - public String getHostName() { - return slaveAddress.getHostAddress().getHostName(); - } - - /** - * Used to get the port number the slave listens for master - * connections on - * - * @return the port number - */ - public int getPort() { - return slaveAddress.getPortNumber(); - } /** * Verifies if the SocketConnection is valid. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageTransmit.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageTransmit.java?rev=644742&r1=644741&r2=644742&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageTransmit.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageTransmit.java Fri Apr 4 08:51:58 2008 @@ -24,7 +24,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketTimeoutException; -import java.net.UnknownHostException; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -80,20 +79,11 @@ /** * Constructor initializes the slave address used in replication. * - * @param hostName a String that contains the host name of - * the slave to replicate to. - * @param portNumber an integer that contains the port number of the - * slave to replicate to. - * @param dbname The name of the replicated database - * - * @throws UnknownHostException If an exception occurs while trying to - * resolve the host name. + * @param slaveAddress contains the address (host name and port number) + * of the slave to connect to. */ - public ReplicationMessageTransmit(String hostName, int portNumber, - String dbname) - throws UnknownHostException { - this.dbname = dbname; - slaveAddress = new SlaveAddress(hostName, portNumber); + public ReplicationMessageTransmit(SlaveAddress slaveAddress) { + this.slaveAddress = slaveAddress; } /** Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/slave/SlaveController.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/slave/SlaveController.java?rev=644742&r1=644741&r2=644742&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/slave/SlaveController.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/slave/SlaveController.java Fri Apr 4 08:51:58 2008 @@ -34,6 +34,7 @@ import org.apache.derby.impl.store.raw.log.LogCounter; import org.apache.derby.iapi.store.raw.log.LogFactory; import org.apache.derby.impl.store.raw.log.LogToFile; +import org.apache.derby.impl.store.replication.net.SlaveAddress; import org.apache.derby.impl.store.replication.ReplicationLogger; import org.apache.derby.impl.store.replication.net.ReplicationMessage; @@ -43,6 +44,7 @@ import java.io.EOFException; import java.io.IOException; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.util.Properties; /** @@ -76,8 +78,7 @@ private ReplicationMessageReceive receiver; private ReplicationLogger repLogger; - private String slavehost; - private int slaveport; + private SlaveAddress slaveAddr; private String dbname; // The name of the replicated database /** The instant of the latest log record received from the master @@ -130,11 +131,22 @@ public void boot(boolean create, Properties properties) throws StandardException { - slavehost = properties.getProperty(Attribute.REPLICATION_SLAVE_HOST); - String port = properties.getProperty(Attribute.REPLICATION_SLAVE_PORT); - if (port != null) { - slaveport = new Integer(port).intValue(); + + try { + //if slavePort is -1 the default port + //value will be used. + int slavePort = -1; + if (port != null) { + slavePort = (new Integer(port)).intValue(); + } + slaveAddr = new SlaveAddress( + properties.getProperty(Attribute.REPLICATION_SLAVE_HOST), + slavePort); + } catch (UnknownHostException uhe) { + throw StandardException.newException + (SQLState.REPLICATION_CONNECTION_EXCEPTION, uhe, + dbname, getHostName(), String.valueOf(getPortNumber())); } dbname = properties.getProperty(SlaveFactory.SLAVE_DB); @@ -222,11 +234,7 @@ // Retry to setup a connection with the master until a // connection has been established or until we are no longer // in replication slave mode - receiver = new ReplicationMessageReceive(slavehost, slaveport, dbname); - // If slaveport was not specified when starting the slave, the - // receiver will use the default port. Set slaveport to the port - // actually used by the receiver - slaveport = receiver.getPort(); + receiver = new ReplicationMessageReceive(slaveAddr, dbname); while (!setupConnection()) { if (!inReplicationSlaveMode) { // If we get here, another thread has called @@ -351,7 +359,7 @@ } else { throw StandardException.newException (SQLState.REPLICATION_CONNECTION_EXCEPTION, e, - dbname, slavehost, String.valueOf(slaveport)); + dbname, getHostName(), String.valueOf(getPortNumber())); } } } @@ -463,6 +471,24 @@ } catch (IOException ioe) { repLogger.logError(null, ioe); } + } + + /** + * Used to return the host name of the slave. + * + * @return a String containing the host name of the slave. + */ + private String getHostName() { + return slaveAddr.getHostAddress().getHostName(); + } + + /** + * Used to return the port number of the slave. + * + * @return an Integer that represents the port number of the slave. + */ + private int getPortNumber() { + return slaveAddr.getPortNumber(); } ///////////////////////////////////////////////////////////////////////////