From 6309fcc5b4b42102b5bb901dbbdf44846f5643f2 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 2 Nov 2009 11:19:55 -0800 Subject: Reverting the memory leak patch for MySQL. Problems have been reported with the grid server after running for several hours --- OpenSim/Data/MySQL/MySQLEstateData.cs | 310 +++++++++++++++++----------------- 1 file changed, 158 insertions(+), 152 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLEstateData.cs') diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs index 7166b29..e8694fc 100644 --- a/OpenSim/Data/MySQL/MySQLEstateData.cs +++ b/OpenSim/Data/MySQL/MySQLEstateData.cs @@ -95,17 +95,21 @@ namespace OpenSim.Data.MySQL protected void GetWaitTimeout() { - using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, m_connection)) + MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, + m_connection); + + using (MySqlDataReader dbReader = + cmd.ExecuteReader(CommandBehavior.SingleRow)) { - using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) + if (dbReader.Read()) { - if (dbReader.Read()) - { - m_waitTimeout - = Convert.ToInt32(dbReader["@@wait_timeout"]) * - TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; - } + m_waitTimeout + = Convert.ToInt32(dbReader["@@wait_timeout"]) * + TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; } + + dbReader.Close(); + cmd.Dispose(); } m_lastConnectionUse = DateTime.Now.Ticks; @@ -143,103 +147,110 @@ namespace OpenSim.Data.MySQL CheckConnection(); - bool migration = true; + MySqlCommand cmd = m_connection.CreateCommand(); - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = sql; - cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + cmd.CommandText = sql; + cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + + IDataReader r = cmd.ExecuteReader(); - using (IDataReader r = cmd.ExecuteReader()) + if (r.Read()) + { + foreach (string name in FieldList) { - if (r.Read()) + if (m_FieldMap[name].GetValue(es) is bool) { - migration = false; - - foreach (string name in FieldList) - { - if (m_FieldMap[name].GetValue(es) is bool) - { - int v = Convert.ToInt32(r[name]); - if (v != 0) - m_FieldMap[name].SetValue(es, true); - else - m_FieldMap[name].SetValue(es, false); - } - else if (m_FieldMap[name].GetValue(es) is UUID) - { - UUID uuid = UUID.Zero; - - UUID.TryParse(r[name].ToString(), out uuid); - m_FieldMap[name].SetValue(es, uuid); - } - else - { - m_FieldMap[name].SetValue(es, r[name]); - } - } + int v = Convert.ToInt32(r[name]); + if (v != 0) + m_FieldMap[name].SetValue(es, true); + else + m_FieldMap[name].SetValue(es, false); + } + else if (m_FieldMap[name].GetValue(es) is UUID) + { + UUID uuid = UUID.Zero; + + UUID.TryParse(r[name].ToString(), out uuid); + m_FieldMap[name].SetValue(es, uuid); + } + else + { + m_FieldMap[name].SetValue(es, r[name]); } } + r.Close(); } - - if (migration) + else { // Migration case + // + r.Close(); + List names = new List(FieldList); names.Remove("EstateID"); sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = sql; - cmd.Parameters.Clear(); + cmd.CommandText = sql; + cmd.Parameters.Clear(); - foreach (string name in FieldList) + foreach (string name in FieldList) + { + if (m_FieldMap[name].GetValue(es) is bool) { - if (m_FieldMap[name].GetValue(es) is bool) - { - if ((bool)m_FieldMap[name].GetValue(es)) - cmd.Parameters.AddWithValue("?" + name, "1"); - else - cmd.Parameters.AddWithValue("?" + name, "0"); - } + if ((bool)m_FieldMap[name].GetValue(es)) + cmd.Parameters.AddWithValue("?" + name, "1"); else - { - cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); - } + cmd.Parameters.AddWithValue("?" + name, "0"); } + else + { + cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); + } + } - cmd.ExecuteNonQuery(); + cmd.ExecuteNonQuery(); - cmd.CommandText = "select LAST_INSERT_ID() as id"; - cmd.Parameters.Clear(); + cmd.CommandText = "select LAST_INSERT_ID() as id"; + cmd.Parameters.Clear(); - using (IDataReader r = cmd.ExecuteReader()) - { - r.Read(); - es.EstateID = Convert.ToUInt32(r["id"]); - } + r = cmd.ExecuteReader(); + + r.Read(); - cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; - cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); - cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); + es.EstateID = Convert.ToUInt32(r["id"]); - // This will throw on dupe key - try { cmd.ExecuteNonQuery(); } - catch (Exception) { } + r.Close(); + + cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; + cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); - // Munge and transfer the ban list - cmd.Parameters.Clear(); - cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID"; - cmd.Parameters.AddWithValue("?UUID", regionID.ToString()); + // This will throw on dupe key + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception) + { + } - try { cmd.ExecuteNonQuery(); } - catch (Exception) { } + // Munge and transfer the ban list + // + cmd.Parameters.Clear(); + cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID"; + cmd.Parameters.AddWithValue("?UUID", regionID.ToString()); - es.Save(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception) + { } + + es.Save(); } LoadBanList(es); @@ -256,28 +267,27 @@ namespace OpenSim.Data.MySQL CheckConnection(); - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = sql; + MySqlCommand cmd = m_connection.CreateCommand(); - foreach (string name in FieldList) + cmd.CommandText = sql; + + foreach (string name in FieldList) + { + if (m_FieldMap[name].GetValue(es) is bool) { - if (m_FieldMap[name].GetValue(es) is bool) - { - if ((bool)m_FieldMap[name].GetValue(es)) - cmd.Parameters.AddWithValue("?" + name, "1"); - else - cmd.Parameters.AddWithValue("?" + name, "0"); - } + if ((bool)m_FieldMap[name].GetValue(es)) + cmd.Parameters.AddWithValue("?" + name, "1"); else - { - cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); - } + cmd.Parameters.AddWithValue("?" + name, "0"); + } + else + { + cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); } - - cmd.ExecuteNonQuery(); } + cmd.ExecuteNonQuery(); + SaveBanList(es); SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess); @@ -290,52 +300,50 @@ namespace OpenSim.Data.MySQL CheckConnection(); - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID"; - cmd.Parameters.AddWithValue("?EstateID", es.EstateID); + MySqlCommand cmd = m_connection.CreateCommand(); - using (IDataReader r = cmd.ExecuteReader()) - { - while (r.Read()) - { - EstateBan eb = new EstateBan(); + cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID"; + cmd.Parameters.AddWithValue("?EstateID", es.EstateID); - UUID uuid = new UUID(); - UUID.TryParse(r["bannedUUID"].ToString(), out uuid); + IDataReader r = cmd.ExecuteReader(); - eb.BannedUserID = uuid; - eb.BannedHostAddress = "0.0.0.0"; - eb.BannedHostIPMask = "0.0.0.0"; - es.AddBan(eb); - } - } + while (r.Read()) + { + EstateBan eb = new EstateBan(); + + UUID uuid = new UUID(); + UUID.TryParse(r["bannedUUID"].ToString(), out uuid); + + eb.BannedUserID = uuid; + eb.BannedHostAddress = "0.0.0.0"; + eb.BannedHostIPMask = "0.0.0.0"; + es.AddBan(eb); } + r.Close(); } private void SaveBanList(EstateSettings es) { CheckConnection(); - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = "delete from estateban where EstateID = ?EstateID"; - cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); + MySqlCommand cmd = m_connection.CreateCommand(); - cmd.ExecuteNonQuery(); + cmd.CommandText = "delete from estateban where EstateID = ?EstateID"; + cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); - cmd.Parameters.Clear(); + cmd.ExecuteNonQuery(); - cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )"; + cmd.Parameters.Clear(); - foreach (EstateBan b in es.EstateBans) - { - cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); - cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString()); + cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )"; - cmd.ExecuteNonQuery(); - cmd.Parameters.Clear(); - } + foreach (EstateBan b in es.EstateBans) + { + cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); + cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString()); + + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); } } @@ -343,25 +351,24 @@ namespace OpenSim.Data.MySQL { CheckConnection(); - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID"; - cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString()); + MySqlCommand cmd = m_connection.CreateCommand(); - cmd.ExecuteNonQuery(); + cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID"; + cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString()); - cmd.Parameters.Clear(); + cmd.ExecuteNonQuery(); - cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )"; + cmd.Parameters.Clear(); - foreach (UUID uuid in data) - { - cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString()); - cmd.Parameters.AddWithValue("?uuid", uuid.ToString()); + cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )"; - cmd.ExecuteNonQuery(); - cmd.Parameters.Clear(); - } + foreach (UUID uuid in data) + { + cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString()); + cmd.Parameters.AddWithValue("?uuid", uuid.ToString()); + + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); } } @@ -371,24 +378,23 @@ namespace OpenSim.Data.MySQL CheckConnection(); - using (MySqlCommand cmd = m_connection.CreateCommand()) - { - cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID"; - cmd.Parameters.AddWithValue("?EstateID", EstateID); + MySqlCommand cmd = m_connection.CreateCommand(); - using (IDataReader r = cmd.ExecuteReader()) - { - while (r.Read()) - { - // EstateBan eb = new EstateBan(); + cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID"; + cmd.Parameters.AddWithValue("?EstateID", EstateID); - UUID uuid = new UUID(); - UUID.TryParse(r["uuid"].ToString(), out uuid); + IDataReader r = cmd.ExecuteReader(); - uuids.Add(uuid); - } - } + while (r.Read()) + { + // EstateBan eb = new EstateBan(); + + UUID uuid = new UUID(); + UUID.TryParse(r["uuid"].ToString(), out uuid); + + uuids.Add(uuid); } + r.Close(); return uuids.ToArray(); } -- cgit v1.1