diff --git a/OpenSim/Framework/IAssetCache.cs b/OpenSim/Framework/IAssetCache.cs index 8477116403..1e6d19d529 100644 --- a/OpenSim/Framework/IAssetCache.cs +++ b/OpenSim/Framework/IAssetCache.cs @@ -48,7 +48,7 @@ namespace OpenSim.Framework /// /// /// null if the asset does not exist. - AssetBase Get(string id); + AssetBase Get(string id, out bool negative); /// /// Check whether an asset with the specified id exists in the cache. diff --git a/OpenSim/Framework/WearableCacheItem.cs b/OpenSim/Framework/WearableCacheItem.cs index ccaf69edfd..f181c3943b 100644 --- a/OpenSim/Framework/WearableCacheItem.cs +++ b/OpenSim/Framework/WearableCacheItem.cs @@ -113,7 +113,8 @@ namespace OpenSim.Framework { if (dataCache.Check(item.TextureID.ToString())) { - AssetBase assetItem = dataCache.Get(item.TextureID.ToString()); + bool negative; + AssetBase assetItem = dataCache.Get(item.TextureID.ToString(), out negative); if (assetItem != null) { itemmap.Add("assetdata", OSD.FromBinary(assetItem.Data)); diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index 2242e421c4..594b6bbecc 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs @@ -369,7 +369,8 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender else if (Cache != null) { string assetName = "j2kCache_" + AssetId.ToString(); - AssetBase layerDecodeAsset = Cache.Get(assetName); + bool negative; + AssetBase layerDecodeAsset = Cache.Get(assetName, out negative); if (layerDecodeAsset != null) { diff --git a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs index 23c1f035b8..136134fc03 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 51fc3d1d7b..d655509cc7 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 187f090ec5..b183a75216 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 208963d1f4..342d4d9e99 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); diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index fb408a402d..3e47782321 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -299,7 +299,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory if (bakedTextureFace == null) continue; - AssetBase asset = cache.Get(bakedTextureFace.TextureID.ToString()); + bool negative; + AssetBase asset = cache.Get(bakedTextureFace.TextureID.ToString(), out negative); if (asset != null && asset.Local) { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs index f5aa9716d9..ce61ff0b4b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs @@ -209,7 +209,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset if (m_Cache != null) { - asset = m_Cache.Get(id); + bool negative; + asset = m_Cache.Get(id, out negative); + + if (negative) + return null; if (asset != null) return asset; @@ -238,8 +242,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset public AssetBase GetCached(string id) { + bool negative; if (m_Cache != null) - return m_Cache.Get(id); + return m_Cache.Get(id, out negative); return null; } @@ -250,8 +255,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset if (m_Cache != null) { - if (m_Cache != null) - m_Cache.Get(id); + bool negative; + asset = m_Cache.Get(id, out negative); + + if (negative) + return null; if (asset != null) return asset.Metadata; @@ -273,8 +281,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset if (m_Cache != null) { - if (m_Cache != null) - m_Cache.Get(id); + bool negative; + asset = m_Cache.Get(id, out negative); + + if (negative) + return null; if (asset != null) return asset.Data; @@ -292,7 +303,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset AssetBase asset = null; if (m_Cache != null) - asset = m_Cache.Get(id); + { + bool negative; + asset = m_Cache.Get(id, out negative); + + if (negative) + return false; + } if (asset != null) { @@ -381,8 +398,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset { AssetBase asset = null; + bool negative; if (m_Cache != null) - asset = m_Cache.Get(id); + asset = m_Cache.Get(id, out negative); if (asset != null) { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs index 7190aa09ed..bbaed21d31 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs @@ -158,7 +158,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset AssetBase asset = null; if (m_Cache != null) - asset = m_Cache.Get(id); + { + bool negative; + asset = m_Cache.Get(id, out negative); + + if (negative) + return null; + } if (asset == null) { @@ -178,7 +184,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset // m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Cache request for {0}", id); if (m_Cache != null) - return m_Cache.Get(id); + { + bool negative; + return m_Cache.Get(id, out negative); + } return null; } @@ -187,7 +196,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset { AssetBase asset = null; if (m_Cache != null) - asset = m_Cache.Get(id); + { + bool negative; + asset = m_Cache.Get(id, out negative); + if (negative) + return null; + } if (asset != null) return asset.Metadata; @@ -210,7 +224,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset AssetBase asset = null; if (m_Cache != null) - asset = m_Cache.Get(id); + { + bool negative; + asset = m_Cache.Get(id, out negative); + if (negative) + return null; + } if (asset != null) return asset.Data; @@ -232,7 +251,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset if (m_Cache != null) { - AssetBase asset = m_Cache.Get(id); + bool negative; + AssetBase asset = m_Cache.Get(id, out negative); + + if (negative) + return false; if (asset != null) { @@ -286,8 +309,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset public bool UpdateContent(string id, byte[] data) { AssetBase asset = null; + bool negative; if (m_Cache != null) - m_Cache.Get(id); + m_Cache.Get(id, out negative); if (asset != null) { asset.Data = data; diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs index 3d2de82d62..e8cb052263 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs @@ -329,8 +329,7 @@ namespace OpenSim.Region.OptionalModules.Materials AssetBase matAsset = m_scene.AssetService.Get(id.ToString()); if (matAsset == null || matAsset.Data == null || matAsset.Data.Length == 0 ) { - if (id != UUID.Zero) - m_log.WarnFormat("[Materials]: Prim \"{0}\" ({1}) contains unknown material ID {2}", part.Name, part.UUID, id); + //m_log.WarnFormat("[Materials]: Prim \"{0}\" ({1}) contains unknown material ID {2}", part.Name, part.UUID, id); return; } diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs index 3fa8b54d73..9595e7bc18 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs @@ -243,8 +243,16 @@ namespace OpenSim.Services.Connectors string uri = MapServer(id) + "/assets/" + id; AssetBase asset = null; + if (m_Cache != null) - asset = m_Cache.Get(id); + { + bool negative; + + asset = m_Cache.Get(id, out negative); + + if (negative) + return null; + } if (asset == null || asset.Data == null || asset.Data.Length == 0) { @@ -275,8 +283,9 @@ namespace OpenSim.Services.Connectors { // m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Cache request for {0}", id); + bool negative; if (m_Cache != null) - return m_Cache.Get(id); + return m_Cache.Get(id, out negative); return null; } @@ -285,7 +294,11 @@ namespace OpenSim.Services.Connectors { if (m_Cache != null) { - AssetBase fullAsset = m_Cache.Get(id); + bool negative; + AssetBase fullAsset = m_Cache.Get(id, out negative); + + if (negative) + return null; if (fullAsset != null) return fullAsset.Metadata; @@ -301,7 +314,11 @@ namespace OpenSim.Services.Connectors { if (m_Cache != null) { - AssetBase fullAsset = m_Cache.Get(id); + bool negative; + AssetBase fullAsset = m_Cache.Get(id, out negative); + + if (negative) + return null; if (fullAsset != null) return fullAsset.Data; @@ -389,7 +406,14 @@ namespace OpenSim.Services.Connectors AssetBase asset = null; if (m_Cache != null) - asset = m_Cache.Get(id); + { + bool negative; + + asset = m_Cache.Get(id, out negative); + + if (negative) + return false; + } if (asset == null || asset.Data == null || asset.Data.Length == 0) { @@ -589,8 +613,9 @@ namespace OpenSim.Services.Connectors { AssetBase asset = null; + bool negative; if (m_Cache != null) - asset = m_Cache.Get(id); + asset = m_Cache.Get(id, out negative); if (asset == null) { diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs index 121e8636e4..af5f69aa0e 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs @@ -136,7 +136,10 @@ namespace OpenSim.Services.Connectors.SimianGrid // Cache fetch if (m_cache != null) { - AssetBase asset = m_cache.Get(id); + bool negative; + AssetBase asset = m_cache.Get(id, out negative); + if (negative) + return null; if (asset != null) return asset; } @@ -147,8 +150,9 @@ namespace OpenSim.Services.Connectors.SimianGrid public AssetBase GetCached(string id) { + bool negative; if (m_cache != null) - return m_cache.Get(id); + return m_cache.Get(id, out negative); return null; } @@ -169,7 +173,10 @@ namespace OpenSim.Services.Connectors.SimianGrid // Cache fetch if (m_cache != null) { - AssetBase asset = m_cache.Get(id); + bool negative; + AssetBase asset = m_cache.Get(id, out negative); + if (negative) + return null; if (asset != null) return asset.Metadata; } @@ -212,7 +219,12 @@ namespace OpenSim.Services.Connectors.SimianGrid // Cache fetch if (m_cache != null) { - AssetBase asset = m_cache.Get(id); + bool negative; + AssetBase asset = m_cache.Get(id, out negative); + + if (negative) + return false; + if (asset != null) { handler(id, sender, asset);