From d1c3f8eef58b29eb8760eeb1ac03852a2387f927 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 31 Mar 2014 11:53:12 +0300 Subject: Added assets service method AssetsExist(), which returns whether the given list of assets exist. This method is used to optimize sending assets with embedded assets: e.g., when a Hypergrid visitor takes an item into the inventory. --- .../Region/CoreModules/Asset/FlotsamAssetCache.cs | 12 ++++ .../Framework/InventoryAccess/HGAssetMapper.cs | 69 +++++++++++++++------- .../ServiceConnectorsOut/Asset/HGAssetBroker.cs | 17 ++++++ .../Asset/LocalAssetServiceConnector.cs | 5 ++ 4 files changed, 83 insertions(+), 20 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index c7bd3d0..f06d70d 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -1038,6 +1038,18 @@ namespace OpenSim.Region.CoreModules.Asset return true; } + public bool[] AssetsExist(string[] ids) + { + bool[] exist = new bool[ids.Length]; + + for (int i = 0; i < ids.Length; i++) + { + exist[i] = Check(ids[i]); + } + + return exist; + } + public string Store(AssetBase asset) { if (asset.FullID == UUID.Zero) diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index d4fb1ba..532bc74 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs @@ -145,11 +145,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess string id = m_scene.AssetService.Store(asset1); if (id == string.Empty) { - m_log.DebugFormat("[HG ASSET MAPPER]: Asset server {0} did not accept {1}", url, asset.ID); + m_log.DebugFormat("[HG ASSET MAPPER]: Failed to post asset {0} to asset server {1}: the server did not accept the asset", asset.ID, url); success = false; } else - m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); + m_log.DebugFormat("[HG ASSET MAPPER]: Posted asset {0} to asset server {1}", asset1.ID, url); } return success; } @@ -279,36 +279,65 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess public void Post(UUID assetID, UUID ownerID, string userAssetURL) { - // Post the item from the local AssetCache onto the remote asset server - // and place an entry in m_assetMap + m_log.DebugFormat("[HG ASSET MAPPER]: Starting to send asset {0} with children to asset server {1}", assetID, userAssetURL); + + // Find all the embedded assets - m_log.Debug("[HG ASSET MAPPER]: Posting object " + assetID + " to asset server " + userAssetURL); AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); - if (asset != null) + if (asset == null) { - Dictionary ids = new Dictionary(); - HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty); - uuidGatherer.GatherAssetUuids(asset.FullID, asset.Type, ids); - bool success = false; - foreach (UUID uuid in ids.Keys) + m_log.DebugFormat("[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID); + return; + } + + Dictionary ids = new Dictionary(); + HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty); + uuidGatherer.GatherAssetUuids(asset.FullID, asset.Type, ids); + + // Check which assets already exist in the destination server + + string url = userAssetURL; + if (!url.EndsWith("/") && !url.EndsWith("=")) + url = url + "/"; + + string[] remoteAssetIDs = new string[ids.Count]; + int i = 0; + foreach (UUID id in ids.Keys) + remoteAssetIDs[i++] = url + id.ToString(); + + bool[] exist = m_scene.AssetService.AssetsExist(remoteAssetIDs); + + var existSet = new HashSet(); + i = 0; + foreach (UUID id in ids.Keys) + { + if (exist[i]) + existSet.Add(id.ToString()); + ++i; + } + + // Send only those assets which don't already exist in the destination server + + bool success = true; + + foreach (UUID uuid in ids.Keys) + { + if (!existSet.Contains(uuid.ToString())) { asset = m_scene.AssetService.Get(uuid.ToString()); if (asset == null) m_log.DebugFormat("[HG ASSET MAPPER]: Could not find asset {0}", uuid); else - success = PostAsset(userAssetURL, asset); + success &= PostAsset(userAssetURL, asset); } - - // maybe all pieces got there... - if (!success) - m_log.DebugFormat("[HG ASSET MAPPER]: Problems posting item {0} to asset server {1}", assetID, userAssetURL); else - m_log.DebugFormat("[HG ASSET MAPPER]: Successfully posted item {0} to asset server {1}", assetID, userAssetURL); - + m_log.DebugFormat("[HG ASSET MAPPER]: Didn't post asset {0} because it already exists in asset server {1}", uuid, userAssetURL); } - else - m_log.DebugFormat("[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID); + if (!success) + m_log.DebugFormat("[HG ASSET MAPPER]: Problems sending asset {0} with children to asset server {1}", assetID, userAssetURL); + else + m_log.DebugFormat("[HG ASSET MAPPER]: Successfully sent asset {0} with children to asset server {1}", assetID, userAssetURL); } #endregion diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs index 9f58175..ff8b051 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs @@ -312,6 +312,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset } } + public virtual bool[] AssetsExist(string[] ids) + { + int numHG = 0; + foreach (string id in ids) + { + if (IsHG(id)) + ++numHG; + } + + if (numHG == 0) + return m_GridService.AssetsExist(ids); + else if (numHG == ids.Length) + return m_HGService.AssetsExist(ids); + else + throw new Exception("[HG ASSET CONNECTOR]: AssetsExist: all the assets must be either local or foreign"); + } + public string Store(AssetBase asset) { bool isHG = IsHG(asset.ID); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs index 52b1039..97b7559 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs @@ -253,6 +253,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset }); } + public bool[] AssetsExist(string[] ids) + { + return m_AssetService.AssetsExist(ids); + } + public string Store(AssetBase asset) { if (m_Cache != null) -- cgit v1.1