Modified:
branches/branch_5_1/CHANGES
branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java
branches/branch_5_1/src/com/mysql/jdbc/NonRegisteringDriver.java
branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java
Log:
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)
Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES 2007-11-19 02:54:31 UTC (rev 6684)
+++ branches/branch_5_1/CHANGES 2007-11-21 23:31:56 UTC (rev 6685)
@@ -36,6 +36,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: branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java 2007-11-19 02:54:31 UTC (rev 6684)
+++ branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java 2007-11-21 23:31:56 UTC (rev 6685)
@@ -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: branches/branch_5_1/src/com/mysql/jdbc/NonRegisteringDriver.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/NonRegisteringDriver.java 2007-11-19 02:54:31 UTC (rev 6684)
+++ branches/branch_5_1/src/com/mysql/jdbc/NonRegisteringDriver.java 2007-11-21 23:31:56 UTC (rev 6685)
@@ -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: branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java
===================================================================
--- branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java 2007-11-19 02:54:31 UTC (rev 6684)
+++ branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java 2007-11-21 23:31:56 UTC (rev 6685)
@@ -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();
+ }
+ }
}
| Thread |
|---|
| • Connector/J commit: r6685 - in branches/branch_5_1: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 22 Nov |