mirror of
https://github.com/opensim/opensim.git
synced 2026-06-29 18:55:37 +08:00
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.
This commit is contained in:
committed by
John Hurliman
parent
5f1f5c29e9
commit
e1b5c61247
@@ -40,12 +40,16 @@ namespace OpenSim.Data.MySQL
|
||||
/// </summary>
|
||||
public class MySqlFramework
|
||||
{
|
||||
protected MySqlConnection m_Connection;
|
||||
private static readonly log4net.ILog m_log =
|
||||
log4net.LogManager.GetLogger(
|
||||
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected string m_connectionString;
|
||||
protected object m_dbLock = new object();
|
||||
|
||||
protected MySqlFramework(string connectionString)
|
||||
{
|
||||
m_Connection = new MySqlConnection(connectionString);
|
||||
m_Connection.Open();
|
||||
m_connectionString = connectionString;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
@@ -55,64 +59,24 @@ namespace OpenSim.Data.MySQL
|
||||
//
|
||||
protected int ExecuteNonQuery(MySqlCommand cmd)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
cmd.Connection = m_Connection;
|
||||
|
||||
bool errorSeen = false;
|
||||
|
||||
while (true)
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
cmd.Connection = dbcon;
|
||||
|
||||
try
|
||||
{
|
||||
return cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
if (errorSeen)
|
||||
throw;
|
||||
|
||||
// This is "Server has gone away" and "Server lost"
|
||||
//
|
||||
if (e.Number == 2006 || e.Number == 2013)
|
||||
{
|
||||
errorSeen = true;
|
||||
|
||||
m_Connection.Close();
|
||||
MySqlConnection newConnection =
|
||||
(MySqlConnection)((ICloneable)m_Connection).Clone();
|
||||
m_Connection.Dispose();
|
||||
m_Connection = newConnection;
|
||||
m_Connection.Open();
|
||||
|
||||
cmd.Connection = m_Connection;
|
||||
}
|
||||
else
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.Message, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected IDataReader ExecuteReader(MySqlCommand cmd)
|
||||
{
|
||||
MySqlConnection newConnection =
|
||||
(MySqlConnection)((ICloneable)m_Connection).Clone();
|
||||
newConnection.Open();
|
||||
|
||||
cmd.Connection = newConnection;
|
||||
return cmd.ExecuteReader();
|
||||
}
|
||||
|
||||
protected void CloseReaderCommand(MySqlCommand cmd)
|
||||
{
|
||||
cmd.Connection.Close();
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user