From f6ce87c96d037787963d203346c5cb1a1dd52747 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 28 Jun 2013 18:50:33 +0100 Subject: [PATCH 1/3] Reinsert code for gathering uuids reference by materials back directly into UuidGatherer for now. This cannot be triggered as an event from Scene.EventManager since some invocations of UuidGatherer (e.g. IAR saving) use scene objects which are not in scenes. There needs to be some way for modules to register for events which are not connected with a particular scene. --- .../Region/Framework/Scenes/EventManager.cs | 58 ++++---- .../Region/Framework/Scenes/UuidGatherer.cs | 71 ++++++++- .../Materials/MaterialsDemoModule.cs | 136 +++++++++--------- 3 files changed, 168 insertions(+), 97 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 720bfa9481..61b0ebdc65 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -1021,15 +1021,15 @@ namespace OpenSim.Region.Framework.Scenes /// public event TeleportFail OnTeleportFail; - public delegate void GatherUuids(SceneObjectPart sop, IDictionary assetUuids); - - /// - /// Triggered when UUIDs referenced by a scene object are being gathered for archiving, hg transfer, etc. - /// - /// - /// The listener should add references to the IDictionary as appropriate. - /// - public event GatherUuids OnGatherUuids; +// public delegate void GatherUuids(SceneObjectPart sop, IDictionary assetUuids); +// +// /// +// /// Triggered when UUIDs referenced by a scene object are being gathered for archiving, hg transfer, etc. +// /// +// /// +// /// The listener should add references to the IDictionary as appropriate. +// /// +// public event GatherUuids OnGatherUuids; public class MoneyTransferArgs : EventArgs { @@ -3248,25 +3248,25 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerGatherUuids(SceneObjectPart sop, IDictionary assetUuids) - { - GatherUuids handler = OnGatherUuids; - - if (handler != null) - { - foreach (GatherUuids d in handler.GetInvocationList()) - { - try - { - d(sop, assetUuids); - } - catch (Exception e) - { - m_log.ErrorFormat("[EVENT MANAGER]: Delegate for TriggerUuidGather failed - continuing {0} - {1}", - e.Message, e.StackTrace); - } - } - } - } +// public void TriggerGatherUuids(SceneObjectPart sop, IDictionary assetUuids) +// { +// GatherUuids handler = OnGatherUuids; +// +// if (handler != null) +// { +// foreach (GatherUuids d in handler.GetInvocationList()) +// { +// try +// { +// d(sop, assetUuids); +// } +// catch (Exception e) +// { +// m_log.ErrorFormat("[EVENT MANAGER]: Delegate for TriggerUuidGather failed - continuing {0} - {1}", +// e.Message, e.StackTrace); +// } +// } +// } +// } } } diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 3492813115..4e5fb8e683 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -186,7 +186,13 @@ namespace OpenSim.Region.Framework.Scenes GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); } - part.ParentGroup.Scene.EventManager.TriggerGatherUuids(part, assetUuids); + // FIXME: We need to make gathering modular but we cannot yet, since gatherers are not guaranteed + // to be called with scene objects that are in a scene (e.g. in the case of hg asset mapping and + // inventory transfer. There needs to be a way for a module to register a method without assuming a + // Scene.EventManager is present. +// part.ParentGroup.Scene.EventManager.TriggerGatherUuids(part, assetUuids); + + GatherMaterialsUuids(part, assetUuids); } catch (Exception e) { @@ -210,6 +216,69 @@ namespace OpenSim.Region.Framework.Scenes // Monitor.Pulse(this); // } // } + + /// + /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps + /// + /// + /// + public void GatherMaterialsUuids(SceneObjectPart part, IDictionary assetUuids) + { + // scan thru the dynAttrs map of this part for any textures used as materials + OSD osdMaterials = null; + + lock (part.DynAttrs) + { + if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) + { + OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); + materialsStore.TryGetValue("Materials", out osdMaterials); + } + + if (osdMaterials != null) + { + //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); + + if (osdMaterials is OSDArray) + { + OSDArray matsArr = osdMaterials as OSDArray; + foreach (OSDMap matMap in matsArr) + { + try + { + if (matMap.ContainsKey("Material")) + { + OSDMap mat = matMap["Material"] as OSDMap; + if (mat.ContainsKey("NormMap")) + { + UUID normalMapId = mat["NormMap"].AsUUID(); + if (normalMapId != UUID.Zero) + { + assetUuids[normalMapId] = AssetType.Texture; + //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); + } + } + if (mat.ContainsKey("SpecMap")) + { + UUID specularMapId = mat["SpecMap"].AsUUID(); + if (specularMapId != UUID.Zero) + { + assetUuids[specularMapId] = AssetType.Texture; + //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); + } + } + } + + } + catch (Exception e) + { + m_log.Warn("[UUID Gatherer]: exception getting materials: " + e.Message); + } + } + } + } + } + } /// /// Get an asset synchronously, potentially using an asynchronous callback. If the diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs index 34dc552d2e..1cfbab069b 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs @@ -125,7 +125,7 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule m_scene = scene; m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; m_scene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene; - m_scene.EventManager.OnGatherUuids += GatherMaterialsUuids; +// m_scene.EventManager.OnGatherUuids += GatherMaterialsUuids; } void EventManager_OnObjectAddedToScene(SceneObjectGroup obj) @@ -161,7 +161,7 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps; m_scene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene; - m_scene.EventManager.OnGatherUuids -= GatherMaterialsUuids; +// m_scene.EventManager.OnGatherUuids -= GatherMaterialsUuids; m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName); } @@ -579,70 +579,72 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule output.Flush(); } - /// - /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps - /// - /// - /// - private void GatherMaterialsUuids(SceneObjectPart part, IDictionary assetUuids) - { - // scan thru the dynAttrs map of this part for any textures used as materials - OSD osdMaterials = null; - - lock (part.DynAttrs) - { - if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) - { - OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); - if (materialsStore == null) - return; - - materialsStore.TryGetValue("Materials", out osdMaterials); - } - - if (osdMaterials != null) - { - //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); - - if (osdMaterials is OSDArray) - { - OSDArray matsArr = osdMaterials as OSDArray; - foreach (OSDMap matMap in matsArr) - { - try - { - if (matMap.ContainsKey("Material")) - { - OSDMap mat = matMap["Material"] as OSDMap; - if (mat.ContainsKey("NormMap")) - { - UUID normalMapId = mat["NormMap"].AsUUID(); - if (normalMapId != UUID.Zero) - { - assetUuids[normalMapId] = AssetType.Texture; - //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); - } - } - if (mat.ContainsKey("SpecMap")) - { - UUID specularMapId = mat["SpecMap"].AsUUID(); - if (specularMapId != UUID.Zero) - { - assetUuids[specularMapId] = AssetType.Texture; - //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); - } - } - } - - } - catch (Exception e) - { - m_log.Warn("[MaterialsDemoModule]: exception getting materials: " + e.Message); - } - } - } - } - } - } + // FIXME: This code is currently still in UuidGatherer since we cannot use Scene.EventManager as some + // calls to the gatherer are done for objects with no scene. +// /// +// /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps +// /// +// /// +// /// +// private void GatherMaterialsUuids(SceneObjectPart part, IDictionary assetUuids) +// { +// // scan thru the dynAttrs map of this part for any textures used as materials +// OSD osdMaterials = null; +// +// lock (part.DynAttrs) +// { +// if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) +// { +// OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); +// if (materialsStore == null) +// return; +// +// materialsStore.TryGetValue("Materials", out osdMaterials); +// } +// +// if (osdMaterials != null) +// { +// //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); +// +// if (osdMaterials is OSDArray) +// { +// OSDArray matsArr = osdMaterials as OSDArray; +// foreach (OSDMap matMap in matsArr) +// { +// try +// { +// if (matMap.ContainsKey("Material")) +// { +// OSDMap mat = matMap["Material"] as OSDMap; +// if (mat.ContainsKey("NormMap")) +// { +// UUID normalMapId = mat["NormMap"].AsUUID(); +// if (normalMapId != UUID.Zero) +// { +// assetUuids[normalMapId] = AssetType.Texture; +// //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); +// } +// } +// if (mat.ContainsKey("SpecMap")) +// { +// UUID specularMapId = mat["SpecMap"].AsUUID(); +// if (specularMapId != UUID.Zero) +// { +// assetUuids[specularMapId] = AssetType.Texture; +// //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); +// } +// } +// } +// +// } +// catch (Exception e) +// { +// m_log.Warn("[MaterialsDemoModule]: exception getting materials: " + e.Message); +// } +// } +// } +// } +// } +// } } } \ No newline at end of file From dc0455e217b8da3fc8bd49e959b57d6021312b77 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 28 Jun 2013 19:11:44 +0100 Subject: [PATCH 2/3] In XAssetService, on a delete asset request also delete the asset in any chained service. This eliminates the async migration since it causes a race condition with the "delete asset" console command --- OpenSim/Data/MySQL/MySQLXAssetData.cs | 2 ++ OpenSim/Services/AssetService/XAssetService.cs | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs index 8c938254f2..91389cef7d 100644 --- a/OpenSim/Data/MySQL/MySQLXAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs @@ -199,6 +199,8 @@ namespace OpenSim.Data.MySQL /// On failure : Throw an exception and attempt to reconnect to database public void StoreAsset(AssetBase asset) { +// m_log.DebugFormat("[XASSETS DB]: Storing asset {0} {1}", asset.Name, asset.ID); + lock (m_dbLock) { using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) diff --git a/OpenSim/Services/AssetService/XAssetService.cs b/OpenSim/Services/AssetService/XAssetService.cs index 8a2ca7cf6d..6047616f65 100644 --- a/OpenSim/Services/AssetService/XAssetService.cs +++ b/OpenSim/Services/AssetService/XAssetService.cs @@ -205,15 +205,16 @@ namespace OpenSim.Services.AssetService if (!UUID.TryParse(id, out assetID)) return false; - // Don't bother deleting from a chained asset service. This isn't a big deal since deleting happens - // very rarely. + if (HasChainedAssetService) + m_ChainedAssetService.Delete(id); return m_Database.Delete(id); } private void MigrateFromChainedService(AssetBase asset) { - Util.FireAndForget(o => { Store(asset); m_ChainedAssetService.Delete(asset.ID); }); + Store(asset); + m_ChainedAssetService.Delete(asset.ID); } } } \ No newline at end of file From e26e8b882965430f66c6459987a8b219d68e5da1 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 28 Jun 2013 19:19:38 +0100 Subject: [PATCH 3/3] Remove "Asset deletion not supported by database" message from "delete asset" robust/standalone console command since it actually was implemented and performed. Improve other associated messages. --- .../Server/Handlers/Asset/AssetServerConnector.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index ff45d94b7a..cc4325ac4c 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -119,16 +119,14 @@ namespace OpenSim.Server.Handlers.Asset if (asset == null || asset.Data.Length == 0) { - MainConsole.Instance.Output("Asset not found"); + MainConsole.Instance.OutputFormat("Could not find asset with ID {0}", args[2]); return; } - m_AssetService.Delete(args[2]); - - //MainConsole.Instance.Output("Asset deleted"); - // TODO: Implement this - - MainConsole.Instance.Output("Asset deletion not supported by database"); + if (!m_AssetService.Delete(asset.ID)) + MainConsole.Instance.OutputFormat("ERROR: Could not delete asset {0} {1}", asset.ID, asset.Name); + else + MainConsole.Instance.OutputFormat("Deleted asset {0} {1}", asset.ID, asset.Name); } void HandleDumpAsset(string module, string[] args)