From: Date: November 22 2007 12:44am Subject: Connector/J commit: r6686 - in trunk: . src/com/mysql/jdbc src/testsuite/regression List-Archive: http://lists.mysql.com/commits/38251 X-Bug: 31053 Message-Id: <200711212344.lALNiYBF013420@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: trunk/ trunk/CHANGES trunk/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java trunk/src/com/mysql/jdbc/NonRegisteringDriver.java trunk/src/testsuite/regression/ConnectionRegressionTest.java Log: Merged revisions 6585-6586,6593-6597,6599-6602,6605,6607-6609,6612,6614-6617,6619-6620,6623-6627,6632,6636-6638,6641,6649,6658-6659,6663,6665-6673,6676,6681-6682,6684-6685 via svnmerge from svn+ssh://mmatthews@stripped/connectors-svnroot/connector-j/branches/branch_5_1 ....... r6685 | mmatthews | 2007-11-21 17:31:56 -0600 (Wed, 21 Nov 2007) | 3 lines More applicable fix for the "random" load balance strategy in the face of node non-responsive, it re-tries a *different* random node, rather than waiting for the node to recover (for BUG#31053) ....... Property changes on: trunk ___________________________________________________________________ Name: svnmerge-integrated - /branches/branch_5_0:1-6636,6638-6670 /branches/branch_5_1:1-6582,6584-6678,6680-6683 + /branches/branch_5_0:1-6636,6638-6670 /branches/branch_5_1:1-6582,6584-6678,6680-6685 Modified: trunk/CHANGES =================================================================== --- trunk/CHANGES 2007-11-21 23:31:56 UTC (rev 6685) +++ trunk/CHANGES 2007-11-21 23:44:34 UTC (rev 6686) @@ -48,6 +48,10 @@ Statement.getGeneratedKeys() - it was returning null instead of "GENERATED_KEY" as in 5.0.x. + - More applicable fix for the "random" load balance strategy in the face + of node non-responsive, it re-tries a *different* random node, rather + than waiting for the node to recover (for BUG#31053) + 10-09-07 - Version 5.1.5 - Released instead of 5.1.4 to pickup patch for BUG#31053 Modified: trunk/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java =================================================================== --- trunk/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java 2007-11-21 23:31:56 UTC (rev 6685) +++ trunk/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java 2007-11-21 23:44:34 UTC (rev 6686) @@ -181,17 +181,18 @@ class RandomBalanceStrategy implements BalanceStrategy { public Connection pickConnection() throws SQLException { - int random = (int) (Math.random() * hostList.size()); + + SQLException ex = null; + + for (int attempts = 0; attempts < 1200 /* 5 minutes */; attempts++) { + int random = (int) (Math.random() * hostList.size()); - if (random == hostList.size()) { - random--; - } + if (random == hostList.size()) { + random--; + } - String hostPortSpec = (String) hostList.get(random); + String hostPortSpec = (String) hostList.get(random); - SQLException ex = null; - - for (int attempts = 0; attempts < 1200 /* 5 minutes */; attempts++) { Connection conn = (Connection) liveConnections.get(hostPortSpec); if (conn == null) { Modified: trunk/src/com/mysql/jdbc/NonRegisteringDriver.java =================================================================== --- trunk/src/com/mysql/jdbc/NonRegisteringDriver.java 2007-11-21 23:31:56 UTC (rev 6685) +++ trunk/src/com/mysql/jdbc/NonRegisteringDriver.java 2007-11-21 23:44:34 UTC (rev 6686) @@ -301,6 +301,9 @@ throws SQLException { Properties parsedProps = parseURL(url, info); + // People tend to drop this in, it doesn't make sense + parsedProps.remove("roundRobinLoadBalance"); + if (parsedProps == null) { return null; } Modified: trunk/src/testsuite/regression/ConnectionRegressionTest.java =================================================================== --- trunk/src/testsuite/regression/ConnectionRegressionTest.java 2007-11-21 23:31:56 UTC (rev 6685) +++ trunk/src/testsuite/regression/ConnectionRegressionTest.java 2007-11-21 23:44:34 UTC (rev 6686) @@ -2174,7 +2174,7 @@ lbConn.close(); } - private Connection getLoadBalancedConnection() throws SQLException { + private Connection getLoadBalancedConnection(String secondHost, Properties props) throws SQLException { int indexOfHostStart = dbUrl.indexOf("://") + 3; int indexOfHostEnd = dbUrl.indexOf("/", indexOfHostStart); @@ -2186,10 +2186,24 @@ String dbAndConfigs = dbUrl.substring(indexOfHostEnd); - Connection lbConn = DriverManager.getConnection("jdbc:mysql:loadbalance://" + backHalf + "," + backHalf + dbAndConfigs); - return lbConn; + if (secondHost != null) { + secondHost = secondHost + ","; + } + + Connection lbConn = DriverManager.getConnection("jdbc:mysql:loadbalance://" + backHalf + "," + secondHost + backHalf + dbAndConfigs, props); + + return lbConn; } + private Connection getLoadBalancedConnection() throws SQLException { + return getLoadBalancedConnection("", null); + } + + private Connection getLoadBalancedConnection(Properties props) throws SQLException { + return getLoadBalancedConnection("", props); + } + + /** * Test of a new feature to fix BUG 22643, specifying a * "validation query" in your connection pool that starts @@ -2256,4 +2270,18 @@ closeMemberJDBCResources(); } } + + public void testBug31053() throws Exception { + Properties props = new Properties(); + props.setProperty("connectTimeout", "2000"); + props.setProperty("loadBalanceStrategy", "random"); + + Connection lbConn = getLoadBalancedConnection("localhost:23", props); + + lbConn.setAutoCommit(false); + + for (int i = 0; i < 10; i++) { + lbConn.commit(); + } + } }