aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLFramework.cs
diff options
context:
space:
mode:
authorMaster ScienceSim2010-02-04 13:19:30 -0800
committerJohn Hurliman2010-02-05 18:07:59 -0800
commite1b5c612472b9d1acf47383c0bf75b555daff2e6 (patch)
tree083896698038fbdad59c2bd3adeba9b290c5ce1b /OpenSim/Data/MySQL/MySQLFramework.cs
parentFixing an incorrect logging message in insertUserRow (diff)
downloadopensim-SC-e1b5c612472b9d1acf47383c0bf75b555daff2e6.zip
opensim-SC-e1b5c612472b9d1acf47383c0bf75b555daff2e6.tar.gz
opensim-SC-e1b5c612472b9d1acf47383c0bf75b555daff2e6.tar.bz2
opensim-SC-e1b5c612472b9d1acf47383c0bf75b555daff2e6.tar.xz
Updated MySQL connection management to use the MySQL connection pooling. This should accommodate various timeout problems that exist with the current connection pool code in a more general and standard way.
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLFramework.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLFramework.cs62
1 files changed, 13 insertions, 49 deletions
diff --git a/OpenSim/Data/MySQL/MySQLFramework.cs b/OpenSim/Data/MySQL/MySQLFramework.cs
index fca0ca5..3fdcf1e 100644
--- a/OpenSim/Data/MySQL/MySQLFramework.cs
+++ b/OpenSim/Data/MySQL/MySQLFramework.cs
@@ -40,12 +40,16 @@ namespace OpenSim.Data.MySQL
40 /// </summary> 40 /// </summary>
41 public class MySqlFramework 41 public class MySqlFramework
42 { 42 {
43 protected MySqlConnection m_Connection; 43 private static readonly log4net.ILog m_log =
44 log4net.LogManager.GetLogger(
45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected string m_connectionString;
48 protected object m_dbLock = new object();
44 49
45 protected MySqlFramework(string connectionString) 50 protected MySqlFramework(string connectionString)
46 { 51 {
47 m_Connection = new MySqlConnection(connectionString); 52 m_connectionString = connectionString;
48 m_Connection.Open();
49 } 53 }
50 54
51 ////////////////////////////////////////////////////////////// 55 //////////////////////////////////////////////////////////////
@@ -55,64 +59,24 @@ namespace OpenSim.Data.MySQL
55 // 59 //
56 protected int ExecuteNonQuery(MySqlCommand cmd) 60 protected int ExecuteNonQuery(MySqlCommand cmd)
57 { 61 {
58 lock (m_Connection) 62 lock (m_dbLock)
59 { 63 {
60 cmd.Connection = m_Connection; 64 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
61
62 bool errorSeen = false;
63
64 while (true)
65 { 65 {
66 dbcon.Open();
67 cmd.Connection = dbcon;
68
66 try 69 try
67 { 70 {
68 return cmd.ExecuteNonQuery(); 71 return cmd.ExecuteNonQuery();
69 } 72 }
70 catch (MySqlException e)
71 {
72 if (errorSeen)
73 throw;
74
75 // This is "Server has gone away" and "Server lost"
76 //
77 if (e.Number == 2006 || e.Number == 2013)
78 {
79 errorSeen = true;
80
81 m_Connection.Close();
82 MySqlConnection newConnection =
83 (MySqlConnection)((ICloneable)m_Connection).Clone();
84 m_Connection.Dispose();
85 m_Connection = newConnection;
86 m_Connection.Open();
87
88 cmd.Connection = m_Connection;
89 }
90 else
91 throw;
92 }
93 catch (Exception e) 73 catch (Exception e)
94 { 74 {
75 m_log.Error(e.Message, e);
95 return 0; 76 return 0;
96 } 77 }
97 } 78 }
98 } 79 }
99 } 80 }
100
101 protected IDataReader ExecuteReader(MySqlCommand cmd)
102 {
103 MySqlConnection newConnection =
104 (MySqlConnection)((ICloneable)m_Connection).Clone();
105 newConnection.Open();
106
107 cmd.Connection = newConnection;
108 return cmd.ExecuteReader();
109 }
110
111 protected void CloseReaderCommand(MySqlCommand cmd)
112 {
113 cmd.Connection.Close();
114 cmd.Connection.Dispose();
115 cmd.Dispose();
116 }
117 } 81 }
118} 82}