From 5a18ea31cf9d9a97fc1a65f8623b633c244221c2 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 30 Jan 2017 13:59:05 +0000 Subject: Make negative asset caching actually work Also fixes some merge artefacts in HGAssetBroker where cached assets were requested but not actually used and completely squelch a materials debug message because there is nothing the user can do to fix it anyway. --- .../Region/CoreModules/Asset/CenomeAssetCache.cs | 4 ++- OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs | 6 ++-- .../Region/CoreModules/Asset/FlotsamAssetCache.cs | 37 +++++++++++++++------- .../CoreModules/Asset/GlynnTuckerAssetCache.cs | 4 ++- 4 files changed, 36 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region/CoreModules/Asset') diff --git a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs index 23c1f03..136134f 100644 --- a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs @@ -260,8 +260,10 @@ namespace OpenSim.Region.CoreModules.Asset /// Cache doesn't guarantee in any situation that asset is stored to it. /// /// - public AssetBase Get(string id) + public AssetBase Get(string id, out bool negative) { + negative = false; + m_getCount++; AssetBase assetBase; if (m_cache.TryGetValue(id, out assetBase)) diff --git a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs index 51fc3d1..d655509 100644 --- a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs @@ -115,7 +115,8 @@ namespace OpenSim.Region.CoreModules.Asset public bool Check(string id) { // XXX This is probably not an efficient implementation. - return Get(id) != null; + bool negative; + return Get(id, out negative) != null; } public void Cache(AssetBase asset) @@ -129,8 +130,9 @@ namespace OpenSim.Region.CoreModules.Asset // We don't do negative caching } - public AssetBase Get(string id) + public AssetBase Get(string id, out bool negative) { + negative = false; return (AssetBase)m_Cache.Get(id); } diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 187f090..b183a75 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -474,6 +474,8 @@ namespace OpenSim.Region.CoreModules.Asset { using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { + if (stream.Length == 0) // Empty file will trigger exception below + return null; BinaryFormatter bformatter = new BinaryFormatter(); asset = (AssetBase)bformatter.Deserialize(stream); @@ -531,13 +533,25 @@ namespace OpenSim.Region.CoreModules.Asset return found; } + // For IAssetService public AssetBase Get(string id) { + bool negative; + return Get(id, out negative); + } + + public AssetBase Get(string id, out bool negative) + { + negative = false; + m_Requests++; object dummy; if (m_negativeCache.TryGetValue(id, out dummy)) + { + negative = true; return null; + } AssetBase asset = null; asset = GetFromWeakReference(id); @@ -578,12 +592,6 @@ namespace OpenSim.Region.CoreModules.Asset GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l)); } - if(asset == null) - { - - - } - return asset; } @@ -599,7 +607,8 @@ namespace OpenSim.Region.CoreModules.Asset public AssetBase GetCached(string id) { - return Get(id); + bool negative; + return Get(id, out negative); } public void Expire(string id) @@ -1227,19 +1236,24 @@ namespace OpenSim.Region.CoreModules.Asset public AssetMetadata GetMetadata(string id) { - AssetBase asset = Get(id); + bool negative; + AssetBase asset = Get(id, out negative); return asset.Metadata; } public byte[] GetData(string id) { - AssetBase asset = Get(id); + bool negative; + AssetBase asset = Get(id, out negative); return asset.Data; } public bool Get(string id, object sender, AssetRetrieved handler) { - AssetBase asset = Get(id); + bool negative; + AssetBase asset = Get(id, out negative); + if (negative) + return false; handler(id, sender, asset); return true; } @@ -1270,7 +1284,8 @@ namespace OpenSim.Region.CoreModules.Asset public bool UpdateContent(string id, byte[] data) { - AssetBase asset = Get(id); + bool negative; + AssetBase asset = Get(id, out negative); asset.Data = data; Cache(asset); return true; diff --git a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs index 208963d..342d4d9 100644 --- a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs @@ -131,8 +131,10 @@ namespace OpenSim.Region.CoreModules.Asset // We don't do negative caching } - public AssetBase Get(string id) + public AssetBase Get(string id, out bool negative) { + negative = false; + Object asset = null; m_Cache.TryGet(id, out asset); -- cgit v1.1 From a5151bb337cfee14dff6045d7f8e293201ae94ac Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Wed, 1 Feb 2017 16:31:01 +0000 Subject: Refactor asset handling as per Ubit's suggestion --- .../Region/CoreModules/Asset/CenomeAssetCache.cs | 7 ++-- OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs | 12 ++++--- .../Region/CoreModules/Asset/FlotsamAssetCache.cs | 38 +++++++++++----------- .../CoreModules/Asset/GlynnTuckerAssetCache.cs | 13 ++++---- 4 files changed, 34 insertions(+), 36 deletions(-) (limited to 'OpenSim/Region/CoreModules/Asset') diff --git a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs index 136134f..403236c 100644 --- a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs @@ -260,12 +260,9 @@ namespace OpenSim.Region.CoreModules.Asset /// Cache doesn't guarantee in any situation that asset is stored to it. /// /// - public AssetBase Get(string id, out bool negative) + public bool Get(string id, out AssetBase assetBase) { - negative = false; - m_getCount++; - AssetBase assetBase; if (m_cache.TryGetValue(id, out assetBase)) m_hitCount++; @@ -286,7 +283,7 @@ namespace OpenSim.Region.CoreModules.Asset // if (null == assetBase) // m_log.DebugFormat("[CENOME ASSET CACHE]: Asset {0} not in cache", id); - return assetBase; + return true; } #endregion diff --git a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs index d655509..10c0e85 100644 --- a/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/CoreAssetCache.cs @@ -115,8 +115,10 @@ namespace OpenSim.Region.CoreModules.Asset public bool Check(string id) { // XXX This is probably not an efficient implementation. - bool negative; - return Get(id, out negative) != null; + AssetBase asset; + if (!Get(id, out asset)) + return false; + return asset != null; } public void Cache(AssetBase asset) @@ -130,10 +132,10 @@ namespace OpenSim.Region.CoreModules.Asset // We don't do negative caching } - public AssetBase Get(string id, out bool negative) + public bool Get(string id, out AssetBase asset) { - negative = false; - return (AssetBase)m_Cache.Get(id); + asset = (AssetBase)m_Cache.Get(id); + return true; } public void Expire(string id) diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index b183a75..f8a4461 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -536,24 +536,23 @@ namespace OpenSim.Region.CoreModules.Asset // For IAssetService public AssetBase Get(string id) { - bool negative; - return Get(id, out negative); + AssetBase asset; + Get(id, out asset); + return asset; } - public AssetBase Get(string id, out bool negative) + public bool Get(string id, out AssetBase asset) { - negative = false; + asset = null; m_Requests++; object dummy; if (m_negativeCache.TryGetValue(id, out dummy)) { - negative = true; - return null; + return false; } - AssetBase asset = null; asset = GetFromWeakReference(id); if (asset != null && m_updateFileTimeOnCacheHit) { @@ -592,7 +591,7 @@ namespace OpenSim.Region.CoreModules.Asset GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l)); } - return asset; + return true; } public bool Check(string id) @@ -607,8 +606,9 @@ namespace OpenSim.Region.CoreModules.Asset public AssetBase GetCached(string id) { - bool negative; - return Get(id, out negative); + AssetBase asset; + Get(id, out asset); + return asset; } public void Expire(string id) @@ -1236,23 +1236,22 @@ namespace OpenSim.Region.CoreModules.Asset public AssetMetadata GetMetadata(string id) { - bool negative; - AssetBase asset = Get(id, out negative); + AssetBase asset; + Get(id, out asset); return asset.Metadata; } public byte[] GetData(string id) { - bool negative; - AssetBase asset = Get(id, out negative); + AssetBase asset; + Get(id, out asset); return asset.Data; } public bool Get(string id, object sender, AssetRetrieved handler) { - bool negative; - AssetBase asset = Get(id, out negative); - if (negative) + AssetBase asset; + if (!Get(id, out asset)) return false; handler(id, sender, asset); return true; @@ -1284,8 +1283,9 @@ namespace OpenSim.Region.CoreModules.Asset public bool UpdateContent(string id, byte[] data) { - bool negative; - AssetBase asset = Get(id, out negative); + AssetBase asset; + if (!Get(id, out asset)) + return false; asset.Data = data; Cache(asset); return true; diff --git a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs index 342d4d9..abe9b23 100644 --- a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs @@ -131,16 +131,15 @@ namespace OpenSim.Region.CoreModules.Asset // We don't do negative caching } - public AssetBase Get(string id, out bool negative) + public bool Get(string id, out AssetBase asset) { - negative = false; + Object a = null; + m_Cache.TryGet(id, out a); - Object asset = null; - m_Cache.TryGet(id, out asset); - - Debug(asset); + Debug(a); - return (AssetBase)asset; + asset = (AssetBase)a; + return true; } public void Expire(string id) -- cgit v1.1 From caaf9f7fc19d6c272f9cab669ed78c486b11fded Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Thu, 9 Feb 2017 23:13:37 +0000 Subject: Squelch an error that happens when the asset cache was mounted RO. Nothing we can do about that, blame Docker. --- OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenSim/Region/CoreModules/Asset') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index f8a4461..610e279 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -806,6 +806,9 @@ namespace OpenSim.Region.CoreModules.Asset return; } + catch (UnauthorizedAccessException e) + { + } finally { if (stream != null) -- cgit v1.1