List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:February 21 2011 8:49pm
Subject:bzr commit into connector-net-trunk branch (reggie.burnett:957)
View as plain text  
#At file:///C:/Users/Reggie/work/connector-net/trunk/ based on revid:reggie.burnett@stripped

  957 Reggie Burnett	2011-02-21
      Implement cache server properties worklog

    modified:
      CHANGES
      MySql.Data/Provider/Source/Driver.cs
      MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs
      MySql.Data/Provider/Source/MySqlPool.cs
      MySql.Data/Provider/Source/docs/MySqlConnection.xml
      MySql.Data/Tests/Source/PoolingTests.cs
      MySql.Data/Tests/Source/Threading.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2011-02-18 15:26:23 +0000
+++ b/CHANGES	2011-02-21 20:49:04 +0000
@@ -1,1 +1,2 @@
 6.4.0
+- Implemented Cache Server Properties connection option
\ No newline at end of file

=== modified file 'MySql.Data/Provider/Source/Driver.cs'
--- a/MySql.Data/Provider/Source/Driver.cs	2010-12-14 15:25:24 +0000
+++ b/MySql.Data/Provider/Source/Driver.cs	2011-02-21 20:49:04 +0000
@@ -209,35 +209,23 @@
         public virtual void Configure(MySqlConnection connection)
         {
             bool firstConfigure = false;
+
             // if we have not already configured our server variables
             // then do so now
             if (serverProps == null)
             {
                 firstConfigure = true;
-                // load server properties
-                serverProps = new Hashtable();
-                MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection);
 
-                using (MySqlDataReader reader = cmd.ExecuteReader())
+                // if we are in a pool and the user has said it's ok to cache the
+                // properties, then grab it from the pool
+                if (Pool != null && Settings.CacheServerProperties)
                 {
-                    try
-                    {
-                        while (reader.Read())
-                        {
-                            string key = reader.GetString(0);
-                            string value = reader.GetString(1);
-                            serverProps[key] = value;
-                        }
-                    }
-                    catch (Exception ex)
-                    {
-                        MySqlTrace.LogError(ThreadID, ex.Message);
-                        throw;
-                    }
+                    if (Pool.ServerProperties == null)
+                        Pool.ServerProperties = LoadServerProperties(connection);
+                    serverProps = Pool.ServerProperties;
                 }
-
-                if (serverProps.Contains("max_allowed_packet"))
-                    maxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]);
+                else
+                    serverProps = LoadServerProperties(connection);
 
                 LoadCharacterSets(connection);
             }
@@ -285,6 +273,40 @@
         }
 
         /// <summary>
+        /// Loads the properties from the connected server into a hashtable
+        /// </summary>
+        /// <param name="connection"></param>
+        /// <returns></returns>
+        private Hashtable LoadServerProperties(MySqlConnection connection)
+        {
+            // load server properties
+            Hashtable hash = new Hashtable();
+            MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection);
+
+            using (MySqlDataReader reader = cmd.ExecuteReader())
+            {
+                try
+                {
+                    while (reader.Read())
+                    {
+                        string key = reader.GetString(0);
+                        string value = reader.GetString(1);
+                        hash[key] = value;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    MySqlTrace.LogError(ThreadID, ex.Message);
+                    throw;
+                }
+            }
+
+            if (hash.Contains("max_allowed_packet"))
+                maxPacketSize = Convert.ToInt64(hash["max_allowed_packet"]);
+            return hash;
+        }
+
+        /// <summary>
         /// Loads all the current character set names and ids for this server 
         /// into the charSets hashtable
         /// </summary>

=== modified file 'MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs'
--- a/MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs	2011-02-15 21:07:24 +0000
+++ b/MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs	2011-02-21 20:49:04 +0000
@@ -671,6 +671,17 @@
             set { SetValue("Connection Reset", value); }
         }
 
+        [Category("Pooling")]
+        [DisplayName("Cache Server Properties")]
+        [Description("When true, server properties will be cached after the first server in the pool is created")]
+        [DefaultValue(false)]
+        [RefreshProperties(RefreshProperties.All)]
+        public bool CacheServerProperties
+        {
+            get { return (bool)values["Cache Server Properties"]; }
+            set { SetValue("Cache Server Properties", value); }
+        }
+
         #endregion
 
         #region Language and Character Set Properties
@@ -763,6 +774,7 @@
             return new Regex(BlobAsUTF8ExcludePattern);
         }
 
+#if !CF
         public override bool ContainsKey(string keyword)
         {
             try
@@ -776,6 +788,7 @@
                 return false;
             }
         }
+#endif
 
         public override object this[string keyword]
         {

=== modified file 'MySql.Data/Provider/Source/MySqlPool.cs'
--- a/MySql.Data/Provider/Source/MySqlPool.cs	2010-08-18 19:48:34 +0000
+++ b/MySql.Data/Provider/Source/MySqlPool.cs	2011-02-21 20:49:04 +0000
@@ -107,6 +107,8 @@
             get { return beingCleared; }
         }
 
+        internal Hashtable ServerProperties { get; set; }
+
         #endregion
 
         /// <summary>

=== modified file 'MySql.Data/Provider/Source/docs/MySqlConnection.xml'
--- a/MySql.Data/Provider/Source/docs/MySqlConnection.xml	2009-04-19 03:32:20 +0000
+++ b/MySql.Data/Provider/Source/docs/MySqlConnection.xml	2011-02-21 20:49:04 +0000
@@ -1154,6 +1154,15 @@
               session not being cleared out.
             </td>
           </tr>
+          <tr>
+            <td>Cache Server Properties</td>
+            <td>false</td>
+            <td>
+              Specifies whether the server variables are cached between pooled connections.
+              On systems where the variables change infrequently and there are lots of
+              connection attempts, this can speed up things dramatically.
+            </td>
+          </tr>
         </table>
       </div>
       <para>

=== modified file 'MySql.Data/Tests/Source/PoolingTests.cs'
--- a/MySql.Data/Tests/Source/PoolingTests.cs	2010-08-30 20:17:30 +0000
+++ b/MySql.Data/Tests/Source/PoolingTests.cs	2011-02-21 20:49:04 +0000
@@ -546,5 +546,35 @@
                 }
             }
         }
+
+        private void CacheServerPropertiesInternal(bool cache)
+        {
+            string connStr = GetPoolingConnectionString() + 
+                String.Format(";logging=true;cache server properties={0}", cache);
+
+            GenericListener listener = new GenericListener();
+            MySqlTrace.Listeners.Add(listener);
+            MySqlTrace.Switch.Level = System.Diagnostics.SourceLevels.All;
+
+            using (MySqlConnection c = new MySqlConnection(connStr))
+            {
+                c.Open();
+                using (MySqlConnection c2 = new MySqlConnection(connStr))
+                {
+                    c2.Open();
+                    KillConnection(c2);
+                }
+                KillConnection(c);
+            }
+            int count = listener.CountLinesContaining("SHOW VARIABLES");
+            Assert.AreEqual(cache ? 1 : 2, count);
+        }
+
+        [Test]
+        public void CacheServerProperties()
+        {
+            CacheServerPropertiesInternal(true);
+            CacheServerPropertiesInternal(false);
+        }
     }
 }

=== modified file 'MySql.Data/Tests/Source/Threading.cs'
--- a/MySql.Data/Tests/Source/Threading.cs	2010-08-18 19:48:34 +0000
+++ b/MySql.Data/Tests/Source/Threading.cs	2011-02-21 20:49:04 +0000
@@ -74,6 +74,14 @@
 			strings.Add(partial.ToString());
 			partial.Remove(0, partial.Length);
 		}
+
+        public int CountLinesContaining(string text)
+        {
+            int count = 0;
+            foreach (string s in strings)
+                if (s.Contains(text)) count++;
+            return count;
+        }
 	}
 
 	/// <summary>


Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20110221204904-wgw6zpxlf1y5vmxe.bundle
Thread
bzr commit into connector-net-trunk branch (reggie.burnett:957) Reggie Burnett21 Feb