List:Commits« Previous MessageNext Message »
From:rburnett Date:January 11 2007 5:58pm
Subject:Connector/NET commit: r546 - in branches/1.0: . mysqlclient
View as plain text  
Modified:
   branches/1.0/CHANGES
   branches/1.0/mysqlclient/Connection.cs
   branches/1.0/mysqlclient/Driver.cs
   branches/1.0/mysqlclient/MySqlPool.cs
   branches/1.0/mysqlclient/command.cs
   branches/1.0/mysqlclient/nativedriver.cs
Log:
Fixed problem where pooled connections that are added back to the idle pool may be still
in the closed state.



Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES	2007-01-09 17:15:20 UTC (rev 545)
+++ branches/1.0/CHANGES	2007-01-11 16:58:18 UTC (rev 546)
@@ -31,6 +31,8 @@
     Return parameters created with DeriveParameters now have the name RETURN_VALUE
     Fixed problem with parameter name hashing where the hashes were not getting updated
          or removed in certain situations.
+    Fixed problem where pooled connections that are added back to the idle pool may be
+         still in the closed state.
     
 Version 1.0.8 RC
 

Modified: branches/1.0/mysqlclient/Connection.cs
===================================================================
--- branches/1.0/mysqlclient/Connection.cs	2007-01-09 17:15:20 UTC (rev 545)
+++ branches/1.0/mysqlclient/Connection.cs	2007-01-11 16:58:18 UTC (rev 546)
@@ -258,7 +258,10 @@
 			if (state != ConnectionState.Open)
 				throw new InvalidOperationException(Resources.ConnectionNotOpen);
 
-			driver.SetDatabase(databaseName);
+            MySqlCommand cmd = new MySqlCommand(String.Format("USE {0}", databaseName),
this);
+            cmd.ExecuteNonQuery();
+
+			//driver.SetDatabase(databaseName);
 			settings.Database = databaseName;
 		}
 

Modified: branches/1.0/mysqlclient/Driver.cs
===================================================================
--- branches/1.0/mysqlclient/Driver.cs	2007-01-09 17:15:20 UTC (rev 545)
+++ branches/1.0/mysqlclient/Driver.cs	2007-01-11 16:58:18 UTC (rev 546)
@@ -55,6 +55,11 @@
 
 		#region Properties
 
+        internal bool IsOpen
+        {
+            get { return isOpen; }
+        }
+
 		internal long MaxPacketSize
 		{
 			get { return maxPacketSize; }
@@ -99,13 +104,16 @@
 			return (string)serverProps[key];
 		}
 
-		public bool IsTooOld()
+		public bool IsTooOld
 		{
-			TimeSpan ts = DateTime.Now.Subtract(creationTime);
-            if (Settings.ConnectionLifetime != 0 && 
-                ts.TotalSeconds > Settings.ConnectionLifetime)
-				return true;
-			return false;
+            get
+            {
+                TimeSpan ts = DateTime.Now.Subtract(creationTime);
+                if (Settings.ConnectionLifetime != 0 &&
+                    ts.TotalSeconds > Settings.ConnectionLifetime)
+                    return true;
+                return false;
+            }
 		}
 
 		public static Driver Create(MySqlConnectionString settings)
@@ -136,7 +144,7 @@
 		public virtual void Close()
 		{
 			isOpen = false;
-		}
+        }
 
 		/// <summary>
 		/// I don't like this setup but can't think of a better way of doing

Modified: branches/1.0/mysqlclient/MySqlPool.cs
===================================================================
--- branches/1.0/mysqlclient/MySqlPool.cs	2007-01-09 17:15:20 UTC (rev 545)
+++ branches/1.0/mysqlclient/MySqlPool.cs	2007-01-11 16:58:18 UTC (rev 546)
@@ -57,6 +57,15 @@
 			set { settings = value; }
 		}
 
+        private bool NeedConnections
+        {
+            get
+            {
+                int connections = idlePool.Count + inUsePool.Count;
+                return idlePool.Count == 0 || connections < minSize;
+            }
+        }
+
 		public ProcedureCache ProcedureCache
 		{
 			get { return procedureCache; }
@@ -139,15 +148,20 @@
 
 		public void ReleaseConnection(Driver driver)
 		{
-			lock (idlePool.SyncRoot)
-				lock (inUsePool.SyncRoot)
-				{
-					inUsePool.Remove(driver);
-					if (driver.IsTooOld())
-						driver.Close();
-					else
-						idlePool.Enqueue(driver);
-				}
+            lock (idlePool.SyncRoot)
+                lock (inUsePool.SyncRoot)
+                {
+                    inUsePool.Remove(driver);
+
+                    if (driver.IsTooOld && driver.IsOpen)
+                        driver.Close();
+
+                    if (!NeedConnections) return;
+
+                    if (!driver.IsOpen)
+                        driver.Open();
+                    idlePool.Enqueue(driver);
+                }
 		}
 
 		public Driver GetConnection()

Modified: branches/1.0/mysqlclient/command.cs
===================================================================
--- branches/1.0/mysqlclient/command.cs	2007-01-09 17:15:20 UTC (rev 545)
+++ branches/1.0/mysqlclient/command.cs	2007-01-11 16:58:18 UTC (rev 546)
@@ -355,15 +355,20 @@
 			else
 				preparedStatement.ExecutionCount = 0;
 
-			try
-			{
-				Consume();
-			}
-			catch (MySqlException ex)
-			{
-				if (ex.IsFatal) connection.Terminate();
-				throw;
-			}
+            try
+            {
+                Consume();
+            }
+            catch (MySqlException mex)
+            {
+                if (mex.IsFatal) connection.Terminate();
+                throw;
+            }
+            catch (Exception ex)
+            {
+                connection.Terminate();
+                throw;
+            }
 
 			return (int)updateCount;
 		}

Modified: branches/1.0/mysqlclient/nativedriver.cs
===================================================================
--- branches/1.0/mysqlclient/nativedriver.cs	2007-01-09 17:15:20 UTC (rev 545)
+++ branches/1.0/mysqlclient/nativedriver.cs	2007-01-11 16:58:18 UTC (rev 546)
@@ -88,16 +88,28 @@
 
 		private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
 		{
-			SequenceByte = 0;
-			int len = 1;
-			if (bytes != null)
-				len += length;
-			writer.StartPacket(len);
-			writer.WriteByte((byte)cmd);
-			if (bytes != null)
-				writer.Write(bytes, 0, length);
-			writer.Flush();
-		}
+            try
+            {
+                SequenceByte = 0;
+                int len = 1;
+                if (bytes != null)
+                    len += length;
+                writer.StartPacket(len);
+                writer.WriteByte((byte)cmd);
+                if (bytes != null)
+                    writer.Write(bytes, 0, length);
+                writer.Flush();
+            }
+            catch (MySqlException ex)
+            {
+                if (ex.IsFatal)
+                {
+                    isOpen = false;
+                    Close();
+                }
+                throw;
+            }
+        }
 
 		/// <summary>
 		/// Sets the current database for the this connection

Thread
Connector/NET commit: r546 - in branches/1.0: . mysqlclientrburnett11 Jan