List:Commits« Previous MessageNext Message »
From:mmatthews Date:October 10 2006 2:37pm
Subject:Connector/J commit: r5850 - branches/branch_3_1/connector-j branches/branch_3_1/connector-j/src/com/mysql/jdbc branches/branch_3_1/connector-j/src/tes...
View as plain text  
Modified:
   branches/branch_3_1/connector-j/CHANGES
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
   branches/branch_5_0/connector-j/CHANGES
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
   trunk/connector-j/CHANGES
   trunk/connector-j/src/com/mysql/jdbc/Connection.java
   trunk/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
Log:
	  
	- Fixed bug where driver would not advance to next host if 
	  roundRobinLoadBalance=true and the last host in the list is down.

Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES	2006-10-10 00:02:24 UTC (rev 5849)
+++ branches/branch_3_1/connector-j/CHANGES	2006-10-10 14:37:17 UTC (rev 5850)
@@ -53,6 +53,9 @@
 	  
 	- Driver now sends numeric 1 or 0 for client-prepared statement
 	  setBoolean() calls instead of '1' or '0'.
+	  
+	- Fixed bug where driver would not advance to next host if 
+	  roundRobinLoadBalance=true and the last host in the list is down.
 	  	    
 05-26-06 - Version 3.1.13
 

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-10-10 00:02:24 UTC (rev 5849)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-10-10 14:37:17 UTC (rev 5850)
@@ -2623,15 +2623,23 @@
 							throw sqlEx;
 						}
 
-						if ((this.hostListSize - 1) == hostIndex) {
+						// Check next host, it might be up...
+						if (getRoundRobinLoadBalance()) {
+							hostIndex = getNextRoundRobinHostIndex(getURL(),
+									this.hostList);
+						} else if ((this.hostListSize - 1) == hostIndex) {
 							throw sqlEx;
 						}
 					} catch (Exception unknownException) {
 						if (this.io != null) {
 							this.io.forceClose();
 						}
-
-						if ((this.hostListSize - 1) == hostIndex) {
+						
+						// Check next host, it might be up...
+						if (getRoundRobinLoadBalance()) {
+							hostIndex = getNextRoundRobinHostIndex(getURL(),
+									this.hostList);
+						} else if ((this.hostListSize - 1) == hostIndex) {
 							throw new CommunicationsException(this,
 									(this.io != null) ? this.io
 											.getLastPacketSentTimeMs() : 0,
@@ -2746,6 +2754,12 @@
 						} catch (Exception EEE) {
 							connectionException = EEE;
 							connectionGood = false;
+							
+							// Check next host, it might be up...
+							if (getRoundRobinLoadBalance()) {
+								hostIndex = getNextRoundRobinHostIndex(getURL(),
+										this.hostList);
+							}
 						}
 
 						if (connectionGood) {
@@ -3915,9 +3929,10 @@
 				String currentSqlMode = 
 					(String)this.serverVariables.get("sql_mode");
 				
+				boolean strictTransTablesIsSet = StringUtils.indexOfIgnoreCase(currentSqlMode, "STRICT_TRANS_TABLES") != -1;
+				
 				if (currentSqlMode == null ||
-						currentSqlMode.length() == 0 ||
-						StringUtils.indexOfIgnoreCase(currentSqlMode, "STRICT_TRANS_TABLES") == -1) {
+						currentSqlMode.length() == 0 || !strictTransTablesIsSet) {
 					StringBuffer commandBuf = new StringBuffer("SET sql_mode='");
 					
 					if (currentSqlMode != null && currentSqlMode.length() > 0) {
@@ -3932,8 +3947,11 @@
 							java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
 							this.database, true, Statement.USES_VARIABLES_FALSE, false);
 					
+					
 					setJdbcCompliantTruncation(false); // server's handling this for us now
-					setJdbcCompliantTruncationForReads(true);
+				} else if (strictTransTablesIsSet) {
+					// We didn't set it, but someone did, so we piggy back on it
+					setJdbcCompliantTruncation(false); // server's handling this for us now
 				}	
 			}
 		}

Modified: branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
===================================================================
--- branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java	2006-10-10 00:02:24 UTC (rev 5849)
+++ branches/branch_3_1/connector-j/src/testsuite/regression/ConnectionRegressionTest.java	2006-10-10 14:37:17 UTC (rev 5850)
@@ -616,20 +616,24 @@
 					+ newHostBuf.toString() + "/", props);
 			failoverConnection.setAutoCommit(false);
 
+			String originalConnectionId = getSingleIndexedValueWithQuery(
+					failoverConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
 			for (int i = 0; i < 49; i++) {
 				failoverConnection.createStatement().executeQuery("SELECT 1");
 			}
 
-			long begin = System.currentTimeMillis();
-
+			((com.mysql.jdbc.Connection)failoverConnection).clearHasTriedMaster();
+			
 			failoverConnection.setAutoCommit(true);
 
-			long end = System.currentTimeMillis();
+			String newConnectionId = getSingleIndexedValueWithQuery(
+					failoverConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			assertTrue(((com.mysql.jdbc.Connection)failoverConnection).hasTriedMaster());
+			
+			assertTrue(!newConnectionId.equals(originalConnectionId));
 
-			assertTrue(
-					"Probably didn't try failing back to the master....check test",
-					(end - begin) > 500);
-
 			failoverConnection.createStatement().executeQuery("SELECT 1");
 		} finally {
 			if (failoverConnection != null) {
@@ -1659,4 +1663,96 @@
 	    	}
 	    }  
 	}
+	
+	/**
+	 * Tests fix for BUG#6966, connections starting up failed-over (due to down
+	 * master) never retry master.
+	 * 
+	 * @throws Exception
+	 *             if the test fails...Note, test is timing-dependent, but
+	 *             should work in most cases.
+	 */
+	public void testDownedSlave() throws Exception {
+		Properties props = new Driver().parseURL(BaseTestCase.dbUrl, null);
+		props.setProperty("autoReconnect", "true");
+		props.setProperty("roundRobinLoadBalance", "true");
+		props.setProperty("failoverReadOnly", "false");
+		
+		// Re-build the connection information
+		int firstIndexOfHost = BaseTestCase.dbUrl.indexOf("//") + 2;
+		int lastIndexOfHost = BaseTestCase.dbUrl.indexOf("/", firstIndexOfHost);
+
+		String hostPortPair = BaseTestCase.dbUrl.substring(firstIndexOfHost,
+				lastIndexOfHost);
+
+		StringTokenizer st = new StringTokenizer(hostPortPair, ":");
+
+		String host = null;
+		String port = null;
+
+		if (st.hasMoreTokens()) {
+			String possibleHostOrPort = st.nextToken();
+
+			if (Character.isDigit(possibleHostOrPort.charAt(0)) && 
+					(possibleHostOrPort.indexOf(".") == -1 /* IPV4 */)  &&
+					(possibleHostOrPort.indexOf("::") == -1 /* IPV6 */)) {
+				port = possibleHostOrPort;
+				host = "localhost";
+			} else {
+				host = possibleHostOrPort;
+			}
+		}
+
+		if (st.hasMoreTokens()) {
+			port = st.nextToken();
+		}
+
+		if (host == null) {
+			host = "";
+		}
+
+		if (port == null) {
+			port = "3306";
+		}
+
+		StringBuffer newHostBuf = new StringBuffer();
+		
+		newHostBuf.append(host);
+		if (port != null) {
+			newHostBuf.append(":");
+			newHostBuf.append(port);
+		}
+
+		newHostBuf.append(",");
+		newHostBuf.append(host);
+		newHostBuf.append(":65532"); // make sure the slave fails
+		
+		props.remove("PORT");
+		props.remove("HOST");
+
+		Connection failoverConnection = null;
+
+		try {
+			failoverConnection = getConnectionWithProps("jdbc:mysql://"
+					+ newHostBuf.toString() + "/", props);
+		
+			String originalConnectionId = getSingleIndexedValueWithQuery(
+					failoverConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			System.out.println(originalConnectionId);
+			
+			Connection nextConnection = getConnectionWithProps("jdbc:mysql://"
+					+ newHostBuf.toString() + "/", props);
+			
+			String nextId = getSingleIndexedValueWithQuery(
+					nextConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			System.out.println(nextId);
+			
+		} finally {
+			if (failoverConnection != null) {
+				failoverConnection.close();
+			}
+		}
+	}
 }

Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES	2006-10-10 00:02:24 UTC (rev 5849)
+++ branches/branch_5_0/connector-j/CHANGES	2006-10-10 14:37:17 UTC (rev 5850)
@@ -46,6 +46,9 @@
 	  set disregarding whitespace or the "," delimitters to be consistent 
 	  with the ODBC driver.
 	  
+	- Driver now sends numeric 1 or 0 for client-prepared statement
+	  setBoolean() calls instead of '1' or '0'.
+	  	  
 07-26-06 - Version 5.0.3
 
     - Fixed BUG#20650 - Statement.cancel() causes NullPointerException
@@ -269,10 +272,10 @@
     - Fixed BUG#22290 - Driver issues truncation on write exception when
 	  it shouldn't (due to sending big decimal incorrectly to server with
 	  server-side prepared statement).
-	  
-	- Driver now sends numeric 1 or 0 for client-prepared statement
-	  setBoolean() calls instead of '1' or '0'.
-	      	  	  	  	  
+
+	- Fixed bug where driver would not advance to next host if 
+	  roundRobinLoadBalance=true and the last host in the list is down.
+	  	      	  	  	  	  
 05-26-06 - Version 3.1.13
 
     - Fixed BUG#15464 - INOUT parameter does not store IN value.

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2006-10-10 00:02:24 UTC (rev 5849)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2006-10-10 14:37:17 UTC (rev 5850)
@@ -2716,7 +2716,11 @@
 							throw sqlEx;
 						}
 
-						if ((this.hostListSize - 1) == hostIndex) {
+						// Check next host, it might be up...
+						if (getRoundRobinLoadBalance()) {
+							hostIndex = getNextRoundRobinHostIndex(getURL(),
+									this.hostList);
+						} else if ((this.hostListSize - 1) == hostIndex) {
 							throw sqlEx;
 						}
 					} catch (Exception unknownException) {
@@ -2724,7 +2728,11 @@
 							this.io.forceClose();
 						}
 
-						if ((this.hostListSize - 1) == hostIndex) {
+						// Check next host, it might be up...
+						if (getRoundRobinLoadBalance()) {
+							hostIndex = getNextRoundRobinHostIndex(getURL(),
+									this.hostList);
+						} else if ((this.hostListSize - 1) == hostIndex) {
 							throw new CommunicationsException(this,
 									(this.io != null) ? this.io
 											.getLastPacketSentTimeMs() : 0,
@@ -2838,6 +2846,12 @@
 						} catch (Exception EEE) {
 							connectionException = EEE;
 							connectionGood = false;
+							
+							// Check next host, it might be up...
+							if (getRoundRobinLoadBalance()) {
+								hostIndex = getNextRoundRobinHostIndex(getURL(),
+										this.hostList);
+							}
 						}
 
 						if (connectionGood) {

Modified: branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
===================================================================
--- branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java	2006-10-10 00:02:24 UTC (rev 5849)
+++ branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java	2006-10-10 14:37:17 UTC (rev 5850)
@@ -1697,4 +1697,96 @@
 			}
 		}
 	}
+
+	/**
+	 * Tests fix for BUG#6966, connections starting up failed-over (due to down
+	 * master) never retry master.
+	 * 
+	 * @throws Exception
+	 *             if the test fails...Note, test is timing-dependent, but
+	 *             should work in most cases.
+	 */
+	public void testDownedSlave() throws Exception {
+		Properties props = new Driver().parseURL(BaseTestCase.dbUrl, null);
+		props.setProperty("autoReconnect", "true");
+		props.setProperty("roundRobinLoadBalance", "true");
+		props.setProperty("failoverReadOnly", "false");
+		
+		// Re-build the connection information
+		int firstIndexOfHost = BaseTestCase.dbUrl.indexOf("//") + 2;
+		int lastIndexOfHost = BaseTestCase.dbUrl.indexOf("/", firstIndexOfHost);
+	
+		String hostPortPair = BaseTestCase.dbUrl.substring(firstIndexOfHost,
+				lastIndexOfHost);
+	
+		StringTokenizer st = new StringTokenizer(hostPortPair, ":");
+	
+		String host = null;
+		String port = null;
+	
+		if (st.hasMoreTokens()) {
+			String possibleHostOrPort = st.nextToken();
+	
+			if (Character.isDigit(possibleHostOrPort.charAt(0)) && 
+					(possibleHostOrPort.indexOf(".") == -1 /* IPV4 */)  &&
+					(possibleHostOrPort.indexOf("::") == -1 /* IPV6 */)) {
+				port = possibleHostOrPort;
+				host = "localhost";
+			} else {
+				host = possibleHostOrPort;
+			}
+		}
+	
+		if (st.hasMoreTokens()) {
+			port = st.nextToken();
+		}
+	
+		if (host == null) {
+			host = "";
+		}
+	
+		if (port == null) {
+			port = "3306";
+		}
+	
+		StringBuffer newHostBuf = new StringBuffer();
+		
+		newHostBuf.append(host);
+		if (port != null) {
+			newHostBuf.append(":");
+			newHostBuf.append(port);
+		}
+	
+		newHostBuf.append(",");
+		newHostBuf.append(host);
+		newHostBuf.append(":65532"); // make sure the slave fails
+		
+		props.remove("PORT");
+		props.remove("HOST");
+	
+		Connection failoverConnection = null;
+	
+		try {
+			failoverConnection = getConnectionWithProps("jdbc:mysql://"
+					+ newHostBuf.toString() + "/", props);
+		
+			String originalConnectionId = getSingleIndexedValueWithQuery(
+					failoverConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			System.out.println(originalConnectionId);
+			
+			Connection nextConnection = getConnectionWithProps("jdbc:mysql://"
+					+ newHostBuf.toString() + "/", props);
+			
+			String nextId = getSingleIndexedValueWithQuery(
+					nextConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			System.out.println(nextId);
+			
+		} finally {
+			if (failoverConnection != null) {
+				failoverConnection.close();
+			}
+		}
+	}
 }

Modified: trunk/connector-j/CHANGES
===================================================================
--- trunk/connector-j/CHANGES	2006-10-10 00:02:24 UTC (rev 5849)
+++ trunk/connector-j/CHANGES	2006-10-10 14:37:17 UTC (rev 5850)
@@ -272,7 +272,10 @@
     - Fixed BUG#22290 - Driver issues truncation on write exception when
 	  it shouldn't (due to sending big decimal incorrectly to server with
 	  server-side prepared statement).
-	   
+	  
+	- Fixed bug where driver would not advance to next host if 
+	  roundRobinLoadBalance=true and the last host in the list is down.
+	  	   
 05-26-06 - Version 3.1.13
 
     - Fixed BUG#15464 - INOUT parameter does not store IN value.

Modified: trunk/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/Connection.java	2006-10-10 00:02:24 UTC (rev 5849)
+++ trunk/connector-j/src/com/mysql/jdbc/Connection.java	2006-10-10 14:37:17 UTC (rev 5850)
@@ -1844,8 +1844,12 @@
 										.equals(SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE)) {
 							throw sqlEx;
 						}
-
-						if ((this.hostListSize - 1) == hostIndex) {
+						
+						//	Check next host, it might be up...
+						if (getRoundRobinLoadBalance()) {
+							hostIndex = getNextRoundRobinHostIndex(getURL(),
+									this.hostList);
+						} else if ((this.hostListSize - 1) == hostIndex) {
 							throw sqlEx;
 						}
 					} catch (Exception unknownException) {
@@ -1853,7 +1857,11 @@
 							this.io.forceClose();
 						}
 
-						if ((this.hostListSize - 1) == hostIndex) {
+						// Check next host, it might be up...
+						if (getRoundRobinLoadBalance()) {
+							hostIndex = getNextRoundRobinHostIndex(getURL(),
+									this.hostList);
+						} else if ((this.hostListSize - 1) == hostIndex) {
 							throw new CommunicationsException(this,
 									(this.io != null) ? this.io
 											.getLastPacketSentTimeMs() : 0,
@@ -1967,6 +1975,12 @@
 						} catch (Exception EEE) {
 							connectionException = EEE;
 							connectionGood = false;
+							
+							// Check next host, it might be up...
+							if (getRoundRobinLoadBalance()) {
+								hostIndex = getNextRoundRobinHostIndex(getURL(),
+										this.hostList);
+							} 
 						}
 
 						if (connectionGood) {

Modified: trunk/connector-j/src/testsuite/regression/ConnectionRegressionTest.java
===================================================================
--- trunk/connector-j/src/testsuite/regression/ConnectionRegressionTest.java	2006-10-10 00:02:24 UTC (rev 5849)
+++ trunk/connector-j/src/testsuite/regression/ConnectionRegressionTest.java	2006-10-10 14:37:17 UTC (rev 5850)
@@ -1699,4 +1699,96 @@
 			}
 		}
 	}
+
+	/**
+	 * Tests fix for BUG#6966, connections starting up failed-over (due to down
+	 * master) never retry master.
+	 * 
+	 * @throws Exception
+	 *             if the test fails...Note, test is timing-dependent, but
+	 *             should work in most cases.
+	 */
+	public void testDownedSlave() throws Exception {
+		Properties props = new Driver().parseURL(BaseTestCase.dbUrl, null);
+		props.setProperty("autoReconnect", "true");
+		props.setProperty("roundRobinLoadBalance", "true");
+		props.setProperty("failoverReadOnly", "false");
+		
+		// Re-build the connection information
+		int firstIndexOfHost = BaseTestCase.dbUrl.indexOf("//") + 2;
+		int lastIndexOfHost = BaseTestCase.dbUrl.indexOf("/", firstIndexOfHost);
+	
+		String hostPortPair = BaseTestCase.dbUrl.substring(firstIndexOfHost,
+				lastIndexOfHost);
+	
+		StringTokenizer st = new StringTokenizer(hostPortPair, ":");
+	
+		String host = null;
+		String port = null;
+	
+		if (st.hasMoreTokens()) {
+			String possibleHostOrPort = st.nextToken();
+	
+			if (Character.isDigit(possibleHostOrPort.charAt(0)) && 
+					(possibleHostOrPort.indexOf(".") == -1 /* IPV4 */)  &&
+					(possibleHostOrPort.indexOf("::") == -1 /* IPV6 */)) {
+				port = possibleHostOrPort;
+				host = "localhost";
+			} else {
+				host = possibleHostOrPort;
+			}
+		}
+	
+		if (st.hasMoreTokens()) {
+			port = st.nextToken();
+		}
+	
+		if (host == null) {
+			host = "";
+		}
+	
+		if (port == null) {
+			port = "3306";
+		}
+	
+		StringBuffer newHostBuf = new StringBuffer();
+		
+		newHostBuf.append(host);
+		if (port != null) {
+			newHostBuf.append(":");
+			newHostBuf.append(port);
+		}
+	
+		newHostBuf.append(",");
+		newHostBuf.append(host);
+		newHostBuf.append(":65532"); // make sure the slave fails
+		
+		props.remove("PORT");
+		props.remove("HOST");
+	
+		Connection failoverConnection = null;
+	
+		try {
+			failoverConnection = getConnectionWithProps("jdbc:mysql://"
+					+ newHostBuf.toString() + "/", props);
+		
+			String originalConnectionId = getSingleIndexedValueWithQuery(
+					failoverConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			System.out.println(originalConnectionId);
+			
+			Connection nextConnection = getConnectionWithProps("jdbc:mysql://"
+					+ newHostBuf.toString() + "/", props);
+			
+			String nextId = getSingleIndexedValueWithQuery(
+					nextConnection, 1, "SELECT CONNECTION_ID()").toString();
+			
+			System.out.println(nextId);
+			
+		} finally {
+			if (failoverConnection != null) {
+				failoverConnection.close();
+			}
+		}
+	}
 }

Thread
Connector/J commit: r5850 - branches/branch_3_1/connector-j branches/branch_3_1/connector-j/src/com/mysql/jdbc branches/branch_3_1/connector-j/src/tes...mmatthews10 Oct