From 38380def178150d66a307702bcc4484f21934bba Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 30 Nov 2008 05:20:19 +0000 Subject: More changes to the MySQL adapter. take advantage of pooling and run lock-free. This should finally kill the "There is already an open data reader associated with this connection, which must be closed first" error that makes people's builds not save --- OpenSim/Data/MySQL/MySQLRegionData.cs | 979 ++++++++++++++++------------------ 1 file changed, 472 insertions(+), 507 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index 33e005b..3fb0a8a 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -72,69 +72,10 @@ namespace OpenSim.Data.MySQL cmd.CommandText = "delete from prims, primshapes using prims " + "left join primshapes on prims.uuid = primshapes.uuid " + "where PCode = 9 and State <> 0"; - ExecuteNonQuery(cmd); + cmd.ExecuteNonQuery(); cmd.Dispose(); - } - - private IDataReader ExecuteReader(MySqlCommand c) - { - IDataReader r = null; - bool errorSeen = false; - - while (true) - { - try - { - r = c.ExecuteReader(); - } - catch (MySqlException) - { - System.Threading.Thread.Sleep(500); - - m_Connection.Close(); - m_Connection.Open(); - - if (!errorSeen) - { - errorSeen = true; - continue; - } - throw; - } - - break; - } - - return r; - } - - private void ExecuteNonQuery(MySqlCommand c) - { - bool errorSeen = false; - - while (true) - { - try - { - c.ExecuteNonQuery(); - } - catch (MySqlException) - { - System.Threading.Thread.Sleep(500); - - m_Connection.Close(); - m_Connection.Open(); - if (!errorSeen) - { - errorSeen = true; - continue; - } - throw; - } - - break; - } + m_Connection.Close(); } public void Dispose() {} @@ -150,115 +91,116 @@ namespace OpenSim.Data.MySQL if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) return; - lock (m_Connection) + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); + + MySqlCommand cmd = c.CreateCommand(); + + foreach (SceneObjectPart prim in obj.Children.Values) { - MySqlCommand cmd = m_Connection.CreateCommand(); + cmd.Parameters.Clear(); - foreach (SceneObjectPart prim in obj.Children.Values) - { - cmd.Parameters.Clear(); - - cmd.CommandText = "replace into prims ("+ - "UUID, ParentID, CreationDate, "+ - "Name, Text, Description, "+ - "SitName, TouchName, ObjectFlags, "+ - "OwnerMask, NextOwnerMask, GroupMask, "+ - "EveryoneMask, BaseMask, PositionX, "+ - "PositionY, PositionZ, GroupPositionX, "+ - "GroupPositionY, GroupPositionZ, VelocityX, "+ - "VelocityY, VelocityZ, AngularVelocityX, "+ - "AngularVelocityY, AngularVelocityZ, "+ - "AccelerationX, AccelerationY, "+ - "AccelerationZ, RotationX, "+ - "RotationY, RotationZ, "+ - "RotationW, SitTargetOffsetX, "+ - "SitTargetOffsetY, SitTargetOffsetZ, "+ - "SitTargetOrientW, SitTargetOrientX, "+ - "SitTargetOrientY, SitTargetOrientZ, "+ - "RegionUUID, CreatorID, "+ - "OwnerID, GroupID, "+ - "LastOwnerID, SceneGroupID, "+ - "PayPrice, PayButton1, "+ - "PayButton2, PayButton3, "+ - "PayButton4, LoopedSound, "+ - "LoopedSoundGain, TextureAnimation, "+ - "OmegaX, OmegaY, OmegaZ, "+ - "CameraEyeOffsetX, CameraEyeOffsetY, "+ - "CameraEyeOffsetZ, CameraAtOffsetX, "+ - "CameraAtOffsetY, CameraAtOffsetZ, "+ - "ForceMouselook, ScriptAccessPin, "+ - "AllowedDrop, DieAtEdge, "+ - "SalePrice, SaleType, "+ - "ColorR, ColorG, ColorB, ColorA, "+ - "ParticleSystem, ClickAction, Material, "+ - "CollisionSound, CollisionSoundVolume, "+ - "LinkNumber) values (" + "?UUID, ?ParentID, "+ - "?CreationDate, ?Name, ?Text, "+ - "?Description, ?SitName, ?TouchName, "+ - "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, "+ - "?GroupMask, ?EveryoneMask, ?BaseMask, "+ - "?PositionX, ?PositionY, ?PositionZ, "+ - "?GroupPositionX, ?GroupPositionY, "+ - "?GroupPositionZ, ?VelocityX, "+ - "?VelocityY, ?VelocityZ, ?AngularVelocityX, "+ - "?AngularVelocityY, ?AngularVelocityZ, "+ - "?AccelerationX, ?AccelerationY, "+ - "?AccelerationZ, ?RotationX, "+ - "?RotationY, ?RotationZ, "+ - "?RotationW, ?SitTargetOffsetX, "+ - "?SitTargetOffsetY, ?SitTargetOffsetZ, "+ - "?SitTargetOrientW, ?SitTargetOrientX, "+ - "?SitTargetOrientY, ?SitTargetOrientZ, "+ - "?RegionUUID, ?CreatorID, ?OwnerID, "+ - "?GroupID, ?LastOwnerID, ?SceneGroupID, "+ - "?PayPrice, ?PayButton1, ?PayButton2, "+ - "?PayButton3, ?PayButton4, ?LoopedSound, "+ - "?LoopedSoundGain, ?TextureAnimation, "+ - "?OmegaX, ?OmegaY, ?OmegaZ, "+ - "?CameraEyeOffsetX, ?CameraEyeOffsetY, "+ - "?CameraEyeOffsetZ, ?CameraAtOffsetX, "+ - "?CameraAtOffsetY, ?CameraAtOffsetZ, "+ - "?ForceMouselook, ?ScriptAccessPin, "+ - "?AllowedDrop, ?DieAtEdge, ?SalePrice, "+ - "?SaleType, ?ColorR, ?ColorG, "+ - "?ColorB, ?ColorA, ?ParticleSystem, "+ - "?ClickAction, ?Material, ?CollisionSound, "+ - "?CollisionSoundVolume, ?LinkNumber)"; - - FillPrimCommand(cmd, prim, obj.UUID, regionUUID); - - ExecuteNonQuery(cmd); - - cmd.Parameters.Clear(); - - cmd.CommandText = "replace into primshapes ("+ - "UUID, Shape, ScaleX, ScaleY, "+ - "ScaleZ, PCode, PathBegin, PathEnd, "+ - "PathScaleX, PathScaleY, PathShearX, "+ - "PathShearY, PathSkew, PathCurve, "+ - "PathRadiusOffset, PathRevolutions, "+ - "PathTaperX, PathTaperY, PathTwist, "+ - "PathTwistBegin, ProfileBegin, ProfileEnd, "+ - "ProfileCurve, ProfileHollow, Texture, "+ - "ExtraParams, State) values (?UUID, "+ - "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, "+ - "?PCode, ?PathBegin, ?PathEnd, "+ - "?PathScaleX, ?PathScaleY, "+ - "?PathShearX, ?PathShearY, "+ - "?PathSkew, ?PathCurve, ?PathRadiusOffset, "+ - "?PathRevolutions, ?PathTaperX, "+ - "?PathTaperY, ?PathTwist, "+ - "?PathTwistBegin, ?ProfileBegin, "+ - "?ProfileEnd, ?ProfileCurve, "+ - "?ProfileHollow, ?Texture, ?ExtraParams, "+ - "?State)"; - - FillShapeCommand(cmd, prim); - - ExecuteNonQuery(cmd); - } - cmd.Dispose(); + cmd.CommandText = "replace into prims ("+ + "UUID, ParentID, CreationDate, "+ + "Name, Text, Description, "+ + "SitName, TouchName, ObjectFlags, "+ + "OwnerMask, NextOwnerMask, GroupMask, "+ + "EveryoneMask, BaseMask, PositionX, "+ + "PositionY, PositionZ, GroupPositionX, "+ + "GroupPositionY, GroupPositionZ, VelocityX, "+ + "VelocityY, VelocityZ, AngularVelocityX, "+ + "AngularVelocityY, AngularVelocityZ, "+ + "AccelerationX, AccelerationY, "+ + "AccelerationZ, RotationX, "+ + "RotationY, RotationZ, "+ + "RotationW, SitTargetOffsetX, "+ + "SitTargetOffsetY, SitTargetOffsetZ, "+ + "SitTargetOrientW, SitTargetOrientX, "+ + "SitTargetOrientY, SitTargetOrientZ, "+ + "RegionUUID, CreatorID, "+ + "OwnerID, GroupID, "+ + "LastOwnerID, SceneGroupID, "+ + "PayPrice, PayButton1, "+ + "PayButton2, PayButton3, "+ + "PayButton4, LoopedSound, "+ + "LoopedSoundGain, TextureAnimation, "+ + "OmegaX, OmegaY, OmegaZ, "+ + "CameraEyeOffsetX, CameraEyeOffsetY, "+ + "CameraEyeOffsetZ, CameraAtOffsetX, "+ + "CameraAtOffsetY, CameraAtOffsetZ, "+ + "ForceMouselook, ScriptAccessPin, "+ + "AllowedDrop, DieAtEdge, "+ + "SalePrice, SaleType, "+ + "ColorR, ColorG, ColorB, ColorA, "+ + "ParticleSystem, ClickAction, Material, "+ + "CollisionSound, CollisionSoundVolume, "+ + "LinkNumber) values (" + "?UUID, ?ParentID, "+ + "?CreationDate, ?Name, ?Text, "+ + "?Description, ?SitName, ?TouchName, "+ + "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, "+ + "?GroupMask, ?EveryoneMask, ?BaseMask, "+ + "?PositionX, ?PositionY, ?PositionZ, "+ + "?GroupPositionX, ?GroupPositionY, "+ + "?GroupPositionZ, ?VelocityX, "+ + "?VelocityY, ?VelocityZ, ?AngularVelocityX, "+ + "?AngularVelocityY, ?AngularVelocityZ, "+ + "?AccelerationX, ?AccelerationY, "+ + "?AccelerationZ, ?RotationX, "+ + "?RotationY, ?RotationZ, "+ + "?RotationW, ?SitTargetOffsetX, "+ + "?SitTargetOffsetY, ?SitTargetOffsetZ, "+ + "?SitTargetOrientW, ?SitTargetOrientX, "+ + "?SitTargetOrientY, ?SitTargetOrientZ, "+ + "?RegionUUID, ?CreatorID, ?OwnerID, "+ + "?GroupID, ?LastOwnerID, ?SceneGroupID, "+ + "?PayPrice, ?PayButton1, ?PayButton2, "+ + "?PayButton3, ?PayButton4, ?LoopedSound, "+ + "?LoopedSoundGain, ?TextureAnimation, "+ + "?OmegaX, ?OmegaY, ?OmegaZ, "+ + "?CameraEyeOffsetX, ?CameraEyeOffsetY, "+ + "?CameraEyeOffsetZ, ?CameraAtOffsetX, "+ + "?CameraAtOffsetY, ?CameraAtOffsetZ, "+ + "?ForceMouselook, ?ScriptAccessPin, "+ + "?AllowedDrop, ?DieAtEdge, ?SalePrice, "+ + "?SaleType, ?ColorR, ?ColorG, "+ + "?ColorB, ?ColorA, ?ParticleSystem, "+ + "?ClickAction, ?Material, ?CollisionSound, "+ + "?CollisionSoundVolume, ?LinkNumber)"; + + FillPrimCommand(cmd, prim, obj.UUID, regionUUID); + + cmd.ExecuteNonQuery(); + + cmd.Parameters.Clear(); + + cmd.CommandText = "replace into primshapes ("+ + "UUID, Shape, ScaleX, ScaleY, "+ + "ScaleZ, PCode, PathBegin, PathEnd, "+ + "PathScaleX, PathScaleY, PathShearX, "+ + "PathShearY, PathSkew, PathCurve, "+ + "PathRadiusOffset, PathRevolutions, "+ + "PathTaperX, PathTaperY, PathTwist, "+ + "PathTwistBegin, ProfileBegin, ProfileEnd, "+ + "ProfileCurve, ProfileHollow, Texture, "+ + "ExtraParams, State) values (?UUID, "+ + "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, "+ + "?PCode, ?PathBegin, ?PathEnd, "+ + "?PathScaleX, ?PathScaleY, "+ + "?PathShearX, ?PathShearY, "+ + "?PathSkew, ?PathCurve, ?PathRadiusOffset, "+ + "?PathRevolutions, ?PathTaperX, "+ + "?PathTaperY, ?PathTwist, "+ + "?PathTwistBegin, ?ProfileBegin, "+ + "?ProfileEnd, ?ProfileCurve, "+ + "?ProfileHollow, ?Texture, ?ExtraParams, "+ + "?State)"; + + FillShapeCommand(cmd, prim); + + cmd.ExecuteNonQuery(); } + cmd.Dispose(); + c.Close(); } public void RemoveObject(UUID obj, UUID regionUUID) @@ -271,43 +213,51 @@ namespace OpenSim.Data.MySQL // cause the loss of a prim, but is cleaner. // It's also faster because it uses the primary key. // - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - cmd.CommandText = "select UUID from prims where "+ - "SceneGroupID= ?UUID"; + MySqlCommand cmd = c.CreateCommand(); - cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(obj)); + cmd.CommandText = "select UUID from prims where "+ + "SceneGroupID= ?UUID"; - List uuids = new List(); + cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(obj)); - IDataReader reader = ExecuteReader(cmd); + List uuids = new List(); - try - { - while (reader.Read()) - { - uuids.Add(new UUID(reader["UUID"].ToString())); - } - } - finally + IDataReader reader = cmd.ExecuteReader(); + + try + { + while(reader.Read()) { - reader.Close(); + uuids.Add(new UUID(reader["UUID"].ToString())); } + } + finally + { + reader.Close(); + } - foreach (UUID uuid in uuids) - RemoveItems(uuid); + cmd.CommandText = "delete from prims where SceneGroupID= ?UUID"; - cmd.CommandText = "delete from prims where SceneGroupID= ?UUID"; + cmd.ExecuteNonQuery(); - ExecuteNonQuery(cmd); + cmd.CommandText = "delete from primshapes where UUID = ?UUID"; - cmd.CommandText = "delete from primshapes where UUID = ?UUID"; + foreach (UUID uuid in uuids) + { + cmd.Parameters.Clear(); + cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(uuid)); - ExecuteNonQuery(cmd); - cmd.Dispose(); + cmd.ExecuteNonQuery(); } + + cmd.Dispose(); + c.Close(); + + foreach (UUID uuid in uuids) + RemoveItems(uuid); } /// @@ -317,18 +267,19 @@ namespace OpenSim.Data.MySQL /// the Item UUID private void RemoveItems(UUID uuid) { - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - cmd.CommandText = "delete from primitems where " + - "PrimID = ?PrimID"; + MySqlCommand cmd = c.CreateCommand(); - cmd.Parameters.AddWithValue("PrimID", uuid.ToString()); + cmd.CommandText = "delete from primitems where " + + "PrimID = ?PrimID"; - ExecuteNonQuery(cmd); - cmd.Dispose(); - } + cmd.Parameters.AddWithValue("PrimID", uuid.ToString()); + + cmd.ExecuteNonQuery(); + cmd.Dispose(); + c.Close(); } public List LoadObjects(UUID regionUUID) @@ -338,71 +289,72 @@ namespace OpenSim.Data.MySQL List prims = new List(); SceneObjectGroup grp = null; - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - cmd.CommandText = "select *, " + - "case when prims.UUID = SceneGroupID " + - "then 0 else 1 end as sort from prims " + - "left join primshapes on prims.UUID = primshapes.UUID "+ - "where RegionUUID = ?RegionUUID " + - "order by SceneGroupID asc, sort asc, LinkNumber asc"; - - cmd.Parameters.AddWithValue("RegionUUID", - Util.ToRawUuidString(regionUUID)); + MySqlCommand cmd = c.CreateCommand(); - IDataReader reader = ExecuteReader(cmd); + cmd.CommandText = "select *, " + + "case when prims.UUID = SceneGroupID " + + "then 0 else 1 end as sort from prims " + + "left join primshapes on prims.UUID = primshapes.UUID "+ + "where RegionUUID = ?RegionUUID " + + "order by SceneGroupID asc, sort asc, LinkNumber asc"; + + cmd.Parameters.AddWithValue("RegionUUID", + Util.ToRawUuidString(regionUUID)); - try + IDataReader reader = cmd.ExecuteReader(); + + try + { + while (reader.Read()) { - while (reader.Read()) - { - SceneObjectPart prim = BuildPrim(reader); - if (reader["Shape"] is DBNull) - prim.Shape = PrimitiveBaseShape.Default; - else - prim.Shape = BuildShape(reader); + SceneObjectPart prim = BuildPrim(reader); + if (reader["Shape"] is DBNull) + prim.Shape = PrimitiveBaseShape.Default; + else + prim.Shape = BuildShape(reader); - prim.FolderID = prim.UUID; // A relic from when we - // we thought prims contained - // folder objects. In - // reality, prim == folder - prims.Add(prim); + prim.FolderID = prim.UUID; // A relic from when we + // we thought prims contained + // folder objects. In + // reality, prim == folder + prims.Add(prim); - UUID groupID = new UUID(reader["SceneGroupID"].ToString()); + UUID groupID = new UUID(reader["SceneGroupID"].ToString()); - if (groupID != lastGroupID) // New SOG - { - if (grp != null) - objects.Add(grp); + if (groupID != lastGroupID) // New SOG + { + if (grp != null) + objects.Add(grp); - lastGroupID = groupID; + lastGroupID = groupID; - grp = new SceneObjectGroup(prim); - } - else - { - // Black magic to preserve link numbers - // - int link = prim.LinkNum; + grp = new SceneObjectGroup(prim); + } + else + { + // Black magic to preserve link numbers + // + int link = prim.LinkNum; - grp.AddPart(prim); + grp.AddPart(prim); - if (link != 0) - prim.LinkNum = link; - } + if (link != 0) + prim.LinkNum = link; } } - finally - { - reader.Close(); - } - - if (grp != null) - objects.Add(grp); - cmd.Dispose(); } + finally + { + reader.Close(); + } + + if (grp != null) + objects.Add(grp); + cmd.Dispose(); + c.Close(); foreach (SceneObjectPart part in prims) LoadItems(part); @@ -418,65 +370,67 @@ namespace OpenSim.Data.MySQL /// The prim private void LoadItems(SceneObjectPart prim) { - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - cmd.CommandText = "select * from primitems where "+ - "PrimID = ?PrimID"; + MySqlCommand cmd = c.CreateCommand(); - cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString()); + cmd.CommandText = "select * from primitems where "+ + "PrimID = ?PrimID"; - IDataReader reader = ExecuteReader(cmd); - List inventory = - new List(); + cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString()); - try - { - while (reader.Read()) - { - TaskInventoryItem item = BuildItem(reader); + IDataReader reader = cmd.ExecuteReader(); + List inventory = + new List(); - item.ParentID = prim.UUID; // Values in database are - // often wrong - inventory.Add(item); - } - } - finally + try + { + while (reader.Read()) { - reader.Close(); - } + TaskInventoryItem item = BuildItem(reader); - cmd.Dispose(); - prim.Inventory.RestoreInventoryItems(inventory); + item.ParentID = prim.UUID; // Values in database are + // often wrong + inventory.Add(item); + } } + finally + { + reader.Close(); + } + + cmd.Dispose(); + c.Close(); + prim.Inventory.RestoreInventoryItems(inventory); } public void StoreTerrain(double[,] ter, UUID regionID) { m_log.Info("[REGION DB]: Storing terrain"); - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); - - cmd.CommandText = "delete from terrain where " + - "RegionUUID = ?RegionUUID"; - cmd.Parameters.AddWithValue("RegionUUID", - Util.ToRawUuidString(regionID)); - - ExecuteNonQuery(cmd); - - cmd.CommandText = "insert into terrain (RegionUUID, " + - "Revision, Heightfield) values (?RegionUUID, " + - "1, ?Heightfield)"; - - cmd.Parameters.AddWithValue("Heightfield", - SerializeTerrain(ter)); - - ExecuteNonQuery(cmd); - cmd.Dispose(); - } + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); + + MySqlCommand cmd = c.CreateCommand(); + + cmd.CommandText = "delete from terrain where " + + "RegionUUID = ?RegionUUID"; + cmd.Parameters.AddWithValue("RegionUUID", + Util.ToRawUuidString(regionID)); + + cmd.ExecuteNonQuery(); + + cmd.CommandText = "insert into terrain (RegionUUID, " + + "Revision, Heightfield) values (?RegionUUID, " + + "1, ?Heightfield)"; + + cmd.Parameters.AddWithValue("Heightfield", + SerializeTerrain(ter)); + + cmd.ExecuteNonQuery(); + cmd.Dispose(); + c.Close(); } public double[,] LoadTerrain(UUID regionID) @@ -484,254 +438,264 @@ namespace OpenSim.Data.MySQL double[,] terrain = new double[256,256]; terrain.Initialize(); - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); - cmd.CommandText = "select RegionUUID, Revision, Heightfield " + - "from terrain where RegionUUID = ?RegionUUID "+ - "order by Revision desc limit 1"; - cmd.Parameters.AddWithValue("RegionUUID", Util.ToRawUuidString(regionID)); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - IDataReader reader = ExecuteReader(cmd); + MySqlCommand cmd = c.CreateCommand(); - try + cmd.CommandText = "select RegionUUID, Revision, Heightfield " + + "from terrain where RegionUUID = ?RegionUUID "+ + "order by Revision desc limit 1"; + cmd.Parameters.AddWithValue("RegionUUID", Util.ToRawUuidString(regionID)); + + IDataReader reader = cmd.ExecuteReader(); + + try + { + while (reader.Read()) { - while (reader.Read()) - { - MemoryStream mstr = new MemoryStream((byte[]) reader["Heightfield"]); - int rev = 0; + MemoryStream mstr = new MemoryStream((byte[]) reader["Heightfield"]); + int rev = 0; - BinaryReader br = new BinaryReader(mstr); - for (int x = 0; x < 256; x++) + BinaryReader br = new BinaryReader(mstr); + for (int x = 0; x < 256; x++) + { + for (int y = 0; y < 256; y++) { - for (int y = 0; y < 256; y++) - { - terrain[x, y] = br.ReadDouble(); - } - rev = Convert.ToInt32(reader["Revision"]); + terrain[x, y] = br.ReadDouble(); } - m_log.InfoFormat("[REGION DB]: Loaded terrain " + - "revision r{0}", rev); - - return terrain; + rev = Convert.ToInt32(reader["Revision"]); } - } - finally - { + m_log.InfoFormat("[REGION DB]: Loaded terrain " + + "revision r{0}", rev); + reader.Close(); + cmd.Dispose(); + c.Close(); + return terrain; } - cmd.Dispose(); } + catch (Exception) + { + } + reader.Close(); + cmd.Dispose(); + c.Close(); return null; } public void RemoveLandObject(UUID globalID) { - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - cmd.CommandText = "delete from land where UUID = ?UUID"; + MySqlCommand cmd = c.CreateCommand(); - cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(globalID)); + cmd.CommandText = "delete from land where UUID = ?UUID"; - ExecuteNonQuery(cmd); - cmd.Dispose(); - } + cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(globalID)); + + cmd.ExecuteNonQuery(); + cmd.Dispose(); + c.Close(); } public void StoreLandObject(ILandObject parcel) { - lock (m_Connection) + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); + + MySqlCommand cmd = c.CreateCommand(); + + cmd.CommandText = "replace into land (UUID, RegionUUID, " + + "LocalLandID, Bitmap, Name, Description, " + + "OwnerUUID, IsGroupOwned, Area, AuctionID, " + + "Category, ClaimDate, ClaimPrice, GroupUUID, " + + "SalePrice, LandStatus, LandFlags, LandingType, " + + "MediaAutoScale, MediaTextureUUID, MediaURL, " + + "MusicURL, PassHours, PassPrice, SnapshotUUID, " + + "UserLocationX, UserLocationY, UserLocationZ, " + + "UserLookAtX, UserLookAtY, UserLookAtZ, " + + "AuthbuyerID, OtherCleanTime, Dwell) values (" + + "?UUID, ?RegionUUID, " + + "?LocalLandID, ?Bitmap, ?Name, ?Description, " + + "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " + + "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " + + "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " + + "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " + + "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " + + "?UserLocationX, ?UserLocationY, ?UserLocationZ, " + + "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " + + "?AuthbuyerID, ?OtherCleanTime, ?Dwell)"; + + FillLandCommand(cmd, parcel.landData, parcel.regionUUID); + + cmd.ExecuteNonQuery(); + + cmd.CommandText = "delete from landaccesslist where " + + "LandUUID = ?UUID"; + + cmd.ExecuteNonQuery(); + + cmd.Parameters.Clear(); + cmd.CommandText = "insert into landaccesslist (LandUUID, " + + "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " + + "?Flags)"; + + foreach (ParcelManager.ParcelAccessEntry entry in + parcel.landData.ParcelAccessList) { - MySqlCommand cmd = m_Connection.CreateCommand(); - - cmd.CommandText = "replace into land (UUID, RegionUUID, " + - "LocalLandID, Bitmap, Name, Description, " + - "OwnerUUID, IsGroupOwned, Area, AuctionID, " + - "Category, ClaimDate, ClaimPrice, GroupUUID, " + - "SalePrice, LandStatus, LandFlags, LandingType, " + - "MediaAutoScale, MediaTextureUUID, MediaURL, " + - "MusicURL, PassHours, PassPrice, SnapshotUUID, " + - "UserLocationX, UserLocationY, UserLocationZ, " + - "UserLookAtX, UserLookAtY, UserLookAtZ, " + - "AuthbuyerID, OtherCleanTime, Dwell) values (" + - "?UUID, ?RegionUUID, " + - "?LocalLandID, ?Bitmap, ?Name, ?Description, " + - "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " + - "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " + - "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " + - "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " + - "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " + - "?UserLocationX, ?UserLocationY, ?UserLocationZ, " + - "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " + - "?AuthbuyerID, ?OtherCleanTime, ?Dwell)"; - - FillLandCommand(cmd, parcel.landData, parcel.regionUUID); - - ExecuteNonQuery(cmd); - - cmd.CommandText = "delete from landaccesslist where " + - "LandUUID = ?UUID"; - - ExecuteNonQuery(cmd); - + FillLandAccessCommand(cmd, entry, parcel.landData.GlobalID); + cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); - cmd.CommandText = "insert into landaccesslist (LandUUID, " + - "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " + - "?Flags)"; - - foreach (ParcelManager.ParcelAccessEntry entry in - parcel.landData.ParcelAccessList) - { - FillLandAccessCommand(cmd, entry, parcel.landData.GlobalID); - ExecuteNonQuery(cmd); - cmd.Parameters.Clear(); - } - cmd.Dispose(); } + cmd.Dispose(); + c.Close(); } public RegionSettings LoadRegionSettings(UUID regionUUID) { RegionSettings rs = null; - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); - cmd.CommandText = "select * from regionsettings where " + - "regionUUID = ?RegionUUID"; - cmd.Parameters.AddWithValue("regionUUID", regionUUID); + MySqlCommand cmd = c.CreateCommand(); - IDataReader reader = ExecuteReader(cmd); + cmd.CommandText = "select * from regionsettings where " + + "regionUUID = ?RegionUUID"; + cmd.Parameters.AddWithValue("regionUUID", regionUUID); - try - { - if (reader.Read()) - { - rs = BuildRegionSettings(reader); - rs.OnSave += StoreRegionSettings; - } - else - { - rs = new RegionSettings(); - rs.RegionUUID = regionUUID; - rs.OnSave += StoreRegionSettings; + IDataReader reader = cmd.ExecuteReader(); - StoreRegionSettings(rs); - } + try + { + if (reader.Read()) + { + rs = BuildRegionSettings(reader); + rs.OnSave += StoreRegionSettings; } - finally + else { - reader.Close(); + rs = new RegionSettings(); + rs.RegionUUID = regionUUID; + rs.OnSave += StoreRegionSettings; + + StoreRegionSettings(rs); } - cmd.Dispose(); } + finally + { + reader.Close(); + } + cmd.Dispose(); + c.Close(); return rs; } public void StoreRegionSettings(RegionSettings rs) { - lock (m_Connection) - { - MySqlCommand cmd = m_Connection.CreateCommand(); - - cmd.CommandText = "replace into regionsettings (regionUUID, " + - "block_terraform, block_fly, allow_damage, " + - "restrict_pushing, allow_land_resell, " + - "allow_land_join_divide, block_show_in_search, " + - "agent_limit, object_bonus, maturity, " + - "disable_scripts, disable_collisions, " + - "disable_physics, terrain_texture_1, " + - "terrain_texture_2, terrain_texture_3, " + - "terrain_texture_4, elevation_1_nw, " + - "elevation_2_nw, elevation_1_ne, " + - "elevation_2_ne, elevation_1_se, "+ - "elevation_2_se, elevation_1_sw, "+ - "elevation_2_sw, water_height, " + - "terrain_raise_limit, terrain_lower_limit, " + - "use_estate_sun, fixed_sun, sun_position, " + - "covenant, Sandbox, sunvectorx, sunvectory, " + - "sunvectorz) values ( ?RegionUUID, ?BlockTerraform, " + - "?BlockFly, ?AllowDamage, ?RestrictPushing, " + - "?AllowLandResell, ?AllowLandJoinDivide, " + - "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " + - "?Maturity, ?DisableScripts, ?DisableCollisions, " + - "?DisablePhysics, ?TerrainTexture1, " + - "?TerrainTexture2, ?TerrainTexture3, " + - "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " + - "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " + - "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " + - "?WaterHeight, ?TerrainRaiseLimit, " + - "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " + - "?SunPosition, ?Covenant, ?Sandbox, " + - "?SunVectorX, ?SunVectorY, ?SunVectorZ)"; - - FillRegionSettingsCommand(cmd, rs); - - ExecuteNonQuery(cmd); - cmd.Dispose(); - } + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); + + MySqlCommand cmd = c.CreateCommand(); + + cmd.CommandText = "replace into regionsettings (regionUUID, " + + "block_terraform, block_fly, allow_damage, " + + "restrict_pushing, allow_land_resell, " + + "allow_land_join_divide, block_show_in_search, " + + "agent_limit, object_bonus, maturity, " + + "disable_scripts, disable_collisions, " + + "disable_physics, terrain_texture_1, " + + "terrain_texture_2, terrain_texture_3, " + + "terrain_texture_4, elevation_1_nw, " + + "elevation_2_nw, elevation_1_ne, " + + "elevation_2_ne, elevation_1_se, "+ + "elevation_2_se, elevation_1_sw, "+ + "elevation_2_sw, water_height, " + + "terrain_raise_limit, terrain_lower_limit, " + + "use_estate_sun, fixed_sun, sun_position, " + + "covenant, Sandbox, sunvectorx, sunvectory, " + + "sunvectorz) values ( ?RegionUUID, ?BlockTerraform, " + + "?BlockFly, ?AllowDamage, ?RestrictPushing, " + + "?AllowLandResell, ?AllowLandJoinDivide, " + + "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " + + "?Maturity, ?DisableScripts, ?DisableCollisions, " + + "?DisablePhysics, ?TerrainTexture1, " + + "?TerrainTexture2, ?TerrainTexture3, " + + "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " + + "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " + + "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " + + "?WaterHeight, ?TerrainRaiseLimit, " + + "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " + + "?SunPosition, ?Covenant, ?Sandbox, " + + "?SunVectorX, ?SunVectorY, ?SunVectorZ)"; + + FillRegionSettingsCommand(cmd, rs); + + cmd.ExecuteNonQuery(); + cmd.Dispose(); + c.Close(); } public List LoadLandObjects(UUID regionUUID) { List landData = new List(); - lock (m_Connection) + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); + + MySqlCommand cmd = c.CreateCommand(); + + cmd.CommandText = "select * from land where " + + "RegionUUID = ?RegionUUID"; + + cmd.Parameters.AddWithValue("RegionUUID", + Util.ToRawUuidString(regionUUID)); + + IDataReader reader = cmd.ExecuteReader(); + + try + { + while (reader.Read()) + { + LandData newLand = BuildLandData(reader); + landData.Add(newLand); + } + } + finally { - MySqlCommand cmd = m_Connection.CreateCommand(); + reader.Close(); + } - cmd.CommandText = "select * from land where " + - "RegionUUID = ?RegionUUID"; + foreach (LandData land in landData) + { + cmd.Parameters.Clear(); - cmd.Parameters.AddWithValue("RegionUUID", - Util.ToRawUuidString(regionUUID)); + cmd.CommandText = "select * from landaccesslist " + + "where LandUUID = ?LandUUID"; - IDataReader reader = ExecuteReader(cmd); + cmd.Parameters.AddWithValue("LandUUID", + Util.ToRawUuidString(land.GlobalID)); + + reader = cmd.ExecuteReader(); try { while (reader.Read()) { - LandData newLand = BuildLandData(reader); - landData.Add(newLand); + land.ParcelAccessList.Add(BuildLandAccessData(reader)); } } finally { reader.Close(); } - - foreach (LandData land in landData) - { - cmd.Parameters.Clear(); - - cmd.CommandText = "select * from landaccesslist " + - "where LandUUID = ?LandUUID"; - - cmd.Parameters.AddWithValue("LandUUID", - Util.ToRawUuidString(land.GlobalID)); - - reader = ExecuteReader(cmd); - - try - { - while (reader.Read()) - { - land.ParcelAccessList.Add(BuildLandAccessData(reader)); - } - } - finally - { - reader.Close(); - } - } - cmd.Dispose(); } + cmd.Dispose(); + c.Close(); return landData; } @@ -1415,41 +1379,42 @@ byte[] textureEntry = (byte[]) row["Texture"]; public void StorePrimInventory(UUID primID, ICollection items) { - lock (m_Connection) + RemoveItems(primID); + + MySqlConnection c = (MySqlConnection) ((ICloneable)m_Connection).Clone(); + c.Open(); + + MySqlCommand cmd = c.CreateCommand(); + + if (items.Count == 0) + return; + + cmd.CommandText = "insert into primitems ("+ + "invType, assetType, name, "+ + "description, creationDate, nextPermissions, "+ + "currentPermissions, basePermissions, "+ + "everyonePermissions, groupPermissions, "+ + "flags, itemID, primID, assetID, "+ + "parentFolderID, creatorID, ownerID, "+ + "groupID, lastOwnerID) values (?invType, "+ + "?assetType, ?name, ?description, "+ + "?creationDate, ?nextPermissions, "+ + "?currentPermissions, ?basePermissions, "+ + "?everyonePermissions, ?groupPermissions, "+ + "?flags, ?itemID, ?primID, ?assetID, "+ + "?parentFolderID, ?creatorID, ?ownerID, "+ + "?groupID, ?lastOwnerID)"; + + foreach (TaskInventoryItem item in items) { - RemoveItems(primID); - - MySqlCommand cmd = m_Connection.CreateCommand(); - - if (items.Count == 0) - return; - - cmd.CommandText = "insert into primitems ("+ - "invType, assetType, name, "+ - "description, creationDate, nextPermissions, "+ - "currentPermissions, basePermissions, "+ - "everyonePermissions, groupPermissions, "+ - "flags, itemID, primID, assetID, "+ - "parentFolderID, creatorID, ownerID, "+ - "groupID, lastOwnerID) values (?invType, "+ - "?assetType, ?name, ?description, "+ - "?creationDate, ?nextPermissions, "+ - "?currentPermissions, ?basePermissions, "+ - "?everyonePermissions, ?groupPermissions, "+ - "?flags, ?itemID, ?primID, ?assetID, "+ - "?parentFolderID, ?creatorID, ?ownerID, "+ - "?groupID, ?lastOwnerID)"; - - foreach (TaskInventoryItem item in items) - { - cmd.Parameters.Clear(); + cmd.Parameters.Clear(); - FillItemCommand(cmd, item); + FillItemCommand(cmd, item); - ExecuteNonQuery(cmd); - } - cmd.Dispose(); + cmd.ExecuteNonQuery(); } + cmd.Dispose(); + c.Close(); } } } -- cgit v1.1