List:Commits« Previous MessageNext Message »
From:mmatthews Date:February 15 2008 9:30pm
Subject:Connector/J commit: r6733 - in branches/branch_5_1: . src/com/mysql/jdbc src/com/mysql/jdbc/exceptions/jdbc4
View as plain text  
Modified:
   branches/branch_5_1/CHANGES
   branches/branch_5_1/src/com/mysql/jdbc/CommunicationsException.java
   branches/branch_5_1/src/com/mysql/jdbc/ConnectionFeatureNotAvailableException.java
   branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
   branches/branch_5_1/src/com/mysql/jdbc/ExportControlled.java
   branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties
   branches/branch_5_1/src/com/mysql/jdbc/MysqlIO.java
   branches/branch_5_1/src/com/mysql/jdbc/SQLError.java
   branches/branch_5_1/src/com/mysql/jdbc/exceptions/jdbc4/CommunicationsException.java
Log:
CommunicationExceptions now carry information about the last time a packet
      was received from the MySQL server, as well as when the last packet was sent
      to one, in an effort to make it easier to debug communications errors caused
      by network timeouts.

Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/CHANGES	2008-02-15 21:30:33 UTC (rev 6733)
@@ -118,6 +118,11 @@
       now be used, for tools such as Oracle JDeveloper ADF that issue statements such as 
       DDL through CallableStatements.
       
+    - CommunicationExceptions now carry information about the last time a packet
+      was received from the MySQL server, as well as when the last packet was sent
+      to one, in an effort to make it easier to debug communications errors caused
+      by network timeouts.
+      
 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/CommunicationsException.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/CommunicationsException.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/CommunicationsException.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -46,10 +46,10 @@
 	private boolean streamingResultSetInPlay = false;
 
 	public CommunicationsException(ConnectionImpl conn, long lastPacketSentTimeMs,
-			Exception underlyingException) {
+			long lastPacketReceivedTimeMs, Exception underlyingException) {
 
 		this.exceptionMessage = SQLError.createLinkFailureMessageBasedOnHeuristics(conn,
-				lastPacketSentTimeMs, underlyingException, this.streamingResultSetInPlay);
+				lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException, this.streamingResultSetInPlay);
 		
 		if (underlyingException != null) {
 			initCause(underlyingException);

Modified: branches/branch_5_1/src/com/mysql/jdbc/ConnectionFeatureNotAvailableException.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ConnectionFeatureNotAvailableException.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/ConnectionFeatureNotAvailableException.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -44,7 +44,7 @@
 	 */
 	public ConnectionFeatureNotAvailableException(ConnectionImpl conn,
 			long lastPacketSentTimeMs, Exception underlyingException) {
-		super(conn, lastPacketSentTimeMs, underlyingException);
+		super(conn, lastPacketSentTimeMs, 0, underlyingException);
 	}
 
 	/*

Modified: branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -2109,6 +2109,8 @@
 								throw SQLError.createCommunicationsException(this,
 										(this.io != null) ? this.io
 												.getLastPacketSentTimeMs() : 0,
+										(this.io != null) ? this.io
+												 .getLastPacketReceivedTimeMs() : 0,
 												EEE);
 							}
 						}

Modified: branches/branch_5_1/src/com/mysql/jdbc/ExportControlled.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ExportControlled.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/ExportControlled.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -102,7 +102,8 @@
 			mysqlIO.mysqlOutput.flush();
 		} catch (IOException ioEx) {
 			throw SQLError.createCommunicationsException(mysqlIO.connection,
-					mysqlIO.lastPacketSentTimeMs, ioEx);
+					mysqlIO.getLastPacketSentTimeMs(), mysqlIO.getLastPacketReceivedTimeMs(),
+					ioEx);
 		}
 	}
 

Modified: branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties	2008-02-15 21:30:33 UTC (rev 6733)
@@ -162,7 +162,9 @@
 CommunicationsException.6=(the driver was unable to determine the value of either the 
 CommunicationsException.7='wait_timeout' or 'interactive_timeout' configuration values from 
 CommunicationsException.8=the server.
-CommunicationsException.9=The last communications with the server was 
+CommunicationsException.9_1=The last packet successfully received from the server was
+CommunicationsException.9_2=\ seconds ago.
+CommunicationsException.9=The last packet sent successfully to the server was 
 CommunicationsException.10=\ seconds ago, which 
 CommunicationsException.11=. You should consider either expiring and/or testing connection validity 
 CommunicationsException.12=before use in your application, increasing the server configured values for client timeouts, 

Modified: branches/branch_5_1/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/MysqlIO.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/MysqlIO.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -221,6 +221,7 @@
     private int warningCount = 0;
     protected long clientParam = 0;
     protected long lastPacketSentTimeMs = 0;
+    protected long lastPacketReceivedTimeMs = 0;
     private boolean traceProtocol = false;
     private boolean enablePacketDebug = false;
     private Calendar sessionCalendar;
@@ -347,7 +348,7 @@
             return this.mysqlInput.available() > 0;
         } catch (IOException ioEx) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, ioEx);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         }
     }
 
@@ -359,6 +360,10 @@
     protected long getLastPacketSentTimeMs() {
         return this.lastPacketSentTimeMs;
     }
+    
+    protected long getLastPacketReceivedTimeMs() {
+        return this.lastPacketReceivedTimeMs;
+    }
 
     /**
      * Build a result set. Delegates to buildResultSetWithRows() to build a
@@ -560,7 +565,7 @@
 			skipFully(this.mysqlInput, packetLength);
 		} catch (IOException ioEx) {
 			throw SQLError.createCommunicationsException(this.connection,
-					this.lastPacketSentTimeMs, ioEx);
+					this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
 		} catch (OutOfMemoryError oom) {
 			try {
 				this.connection.realClose(false, false, true, oom);
@@ -651,10 +656,14 @@
                     this.packetHeaderBuf, packet);
             }
 
+            if (this.connection.getMaintainTimeStats()) {
+				this.lastPacketReceivedTimeMs = System.currentTimeMillis();
+			}
+            
             return packet;
         } catch (IOException ioEx) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, ioEx);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         } catch (OutOfMemoryError oom) {
         	try {
     			this.connection.realClose(false, false, true, oom);
@@ -931,7 +940,7 @@
             }
         } catch (IOException ioEx) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, ioEx);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         }
     }
 
@@ -1335,7 +1344,7 @@
         try {
         	this.mysqlConnection = this.socketFactory.afterHandshake();
         } catch (IOException ioEx) {
-        	throw SQLError.createCommunicationsException(this.connection, this.lastPacketSentTimeMs, ioEx);
+        	throw SQLError.createCommunicationsException(this.connection, this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         }
     }
 
@@ -1354,7 +1363,7 @@
 				sendCommand(MysqlDefs.INIT_DB, database, null, false, null);
 			} else {
 				throw SQLError.createCommunicationsException(this.connection,
-						this.lastPacketSentTimeMs, ex);
+						this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ex);
 			}
 		}
 	}
@@ -1610,7 +1619,7 @@
 
 					if (bytesRead != len) {
 						throw SQLError.createCommunicationsException(this.connection,
-			    				this.lastPacketSentTimeMs,
+			    				this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs,
 			    				new IOException(Messages.getString("MysqlIO.43")));
 					}
 
@@ -1625,7 +1634,7 @@
 			return new ByteArrayRow(rowData);
 		} catch (IOException ioEx) {
 			throw SQLError.createCommunicationsException(this.connection,
-    				this.lastPacketSentTimeMs, ioEx);
+    				this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
 		}
 	}
 
@@ -1905,7 +1914,7 @@
                 throw sqlEx;
             } catch (Exception ex) {
                 throw SQLError.createCommunicationsException(this.connection,
-                    this.lastPacketSentTimeMs, ex);
+                    this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ex);
             }
 
             Buffer returnPacket = null;
@@ -1923,7 +1932,7 @@
             return returnPacket;
         } catch (IOException ioEx) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, ioEx);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         }
     }
 
@@ -2955,10 +2964,14 @@
     			reuse.getByteBuffer()[packetLength] = 0; // Null-termination
     		}
 
+    		if (this.connection.getMaintainTimeStats()) {
+ 				this.lastPacketReceivedTimeMs = System.currentTimeMillis();
+ 			}
+    		 
     		return reuse;
     	} catch (IOException ioEx) {
     		throw SQLError.createCommunicationsException(this.connection,
-    				this.lastPacketSentTimeMs, ioEx);
+    				this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
     	} catch (OutOfMemoryError oom) {
     		try {
     			// _Try_ this
@@ -3040,7 +3053,7 @@
 
 				if (bytesRead != lengthToWrite) {
 					throw SQLError.createCommunicationsException(this.connection,
-							this.lastPacketSentTimeMs,
+							this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs,
 							SQLError.createSQLException(Messages.getString(
 							"MysqlIO.50") //$NON-NLS-1$
 							+lengthToWrite +
@@ -3080,7 +3093,7 @@
 
 			if (bytesRead != lengthToWrite) {
 				throw SQLError.createCommunicationsException(this.connection,
-						this.lastPacketSentTimeMs,
+						this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs,
 						SQLError.createSQLException(Messages.getString(
 						"MysqlIO.54") //$NON-NLS-1$
 						+lengthToWrite +
@@ -3106,14 +3119,14 @@
         throws SQLException {
         if ((multiPacketSeq == -128) && (this.readPacketSequence != 127)) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs,
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs,
                 new IOException("Packets out of order, expected packet # -128, but received packet # " +
                     multiPacketSeq));
         }
 
         if ((this.readPacketSequence == -1) && (multiPacketSeq != 0)) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs,
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs,
                 new IOException("Packets out of order, expected packet # -1, but received packet # " +
                     multiPacketSeq));
         }
@@ -3121,7 +3134,7 @@
         if ((multiPacketSeq != -128) && (this.readPacketSequence != -1) &&
                 (multiPacketSeq != (this.readPacketSequence + 1))) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs,
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs,
                 new IOException("Packets out of order, expected packet # " +
                     (this.readPacketSequence + 1) + ", but received packet # " +
                     multiPacketSeq));
@@ -3153,10 +3166,6 @@
                 throw new PacketTooBigException(packetLen, this.maxAllowedPacket);
             }
 
-			if (this.connection.getMaintainTimeStats()) {
-				this.lastPacketSentTimeMs = System.currentTimeMillis();
-			}
-
             if ((this.serverMajorVersion >= 4) &&
                     (packetLen >= this.maxThreeBytes)) {
                 sendSplitPackets(packet);
@@ -3217,9 +3226,13 @@
             if (packet == this.sharedSendPacket) {
                 reclaimLargeSharedSendPacket();
             }
+            
+            if (this.connection.getMaintainTimeStats()) {
+				this.lastPacketSentTimeMs = System.currentTimeMillis();
+			}
         } catch (IOException ioEx) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, ioEx);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         }
     }
 
@@ -3392,7 +3405,7 @@
             throw sqlEx;
         } catch (Exception fallThru) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, fallThru);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, fallThru);
         }
 
         checkErrorPacket(resultPacket);
@@ -3639,7 +3652,7 @@
             }
         } catch (IOException ioEx) {
             throw SQLError.createCommunicationsException(this.connection,
-                this.lastPacketSentTimeMs, ioEx);
+                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
         }
     }
 

Modified: branches/branch_5_1/src/com/mysql/jdbc/SQLError.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/SQLError.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/SQLError.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -1061,17 +1061,18 @@
 		}
 	}
 	
-	public static SQLException createCommunicationsException(ConnectionImpl conn, long lastPacketSentTimeMs,
+	public static SQLException createCommunicationsException(ConnectionImpl conn, long lastPacketSentTimeMs, 
+			long lastPacketReceivedTimeMs,
 			Exception underlyingException) {
 		SQLException exToReturn = null;
 		
 		if (!Util.isJdbc4()) {
-			exToReturn = new CommunicationsException(conn, lastPacketSentTimeMs, underlyingException);
+			exToReturn = new CommunicationsException(conn, lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException);
 		} else {
 		
 			try {
 				exToReturn = (SQLException) Util.handleNewInstance(JDBC_4_COMMUNICATIONS_EXCEPTION_CTOR, new Object[] {
-					conn, Constants.longValueOf(lastPacketSentTimeMs), underlyingException});
+					conn, Constants.longValueOf(lastPacketSentTimeMs), Constants.longValueOf(lastPacketReceivedTimeMs), underlyingException});
 			} catch (SQLException sqlEx) {
 				// We should _never_ get this, but let's not swallow it either
 				
@@ -1104,7 +1105,9 @@
 	 */
 	public static String createLinkFailureMessageBasedOnHeuristics(
 			ConnectionImpl conn,
-			long lastPacketSentTimeMs, Exception underlyingException,
+			long lastPacketSentTimeMs, 
+			long lastPacketReceivedTimeMs,
+			Exception underlyingException,
 			boolean streamingResultSetInPlay) {
 		long serverTimeoutSeconds = 0;
 		boolean isInteractiveClient = false;
@@ -1139,7 +1142,8 @@
 		}
 
 		long timeSinceLastPacket = (System.currentTimeMillis() - lastPacketSentTimeMs) / 1000;
-
+		long timeSinceLastPacketReceived = (System.currentTimeMillis() - lastPacketReceivedTimeMs) / 1000;
+		
 		int dueToTimeout = DUE_TO_TIMEOUT_FALSE;
 
 		StringBuffer timeoutMessageBuf = null;
@@ -1185,6 +1189,12 @@
 					|| dueToTimeout == DUE_TO_TIMEOUT_MAYBE) {
 
 				exceptionMessageBuf.append(Messages
+						.getString("CommunicationsException.9_1")); //$NON-NLS-1$
+				exceptionMessageBuf.append(timeSinceLastPacketReceived);
+				exceptionMessageBuf.append(Messages
+						.getString("CommunicationsException.9_2")); //$NON-NLS-1$
+				
+				exceptionMessageBuf.append(Messages
 						.getString("CommunicationsException.9")); //$NON-NLS-1$
 				exceptionMessageBuf.append(timeSinceLastPacket);
 				exceptionMessageBuf.append(Messages

Modified: branches/branch_5_1/src/com/mysql/jdbc/exceptions/jdbc4/CommunicationsException.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/exceptions/jdbc4/CommunicationsException.java	2008-02-13 14:06:48 UTC (rev 6732)
+++ branches/branch_5_1/src/com/mysql/jdbc/exceptions/jdbc4/CommunicationsException.java	2008-02-15 21:30:33 UTC (rev 6733)
@@ -51,10 +51,11 @@
 	private boolean streamingResultSetInPlay = false;
 
 	public CommunicationsException(ConnectionImpl conn, long lastPacketSentTimeMs,
+			long lastPacketReceivedTimeMs,
 			Exception underlyingException) {
 
 		this.exceptionMessage = SQLError.createLinkFailureMessageBasedOnHeuristics(conn,
-				lastPacketSentTimeMs, underlyingException, this.streamingResultSetInPlay);
+				lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException, this.streamingResultSetInPlay);
 		
 		if (underlyingException != null) {
 			initCause(underlyingException);

Thread
Connector/J commit: r6733 - in branches/branch_5_1: . src/com/mysql/jdbc src/com/mysql/jdbc/exceptions/jdbc4mmatthews15 Feb