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.
melanie
Melanie Thielker 2017-01-30 13:59:05 +00:00
parent a17db1b3cd
commit 5a18ea31cf
13 changed files with 147 additions and 45 deletions

View File

@ -48,7 +48,7 @@ namespace OpenSim.Framework
/// </summary>
/// <param name='id'></param>
/// <returns>null if the asset does not exist.</returns>
AssetBase Get(string id);
AssetBase Get(string id, out bool negative);
/// <summary>
/// Check whether an asset with the specified id exists in the cache.

View File

@ -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));

View File

@ -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)
{

View File

@ -260,8 +260,10 @@ namespace OpenSim.Region.CoreModules.Asset
/// Cache doesn't guarantee in any situation that asset is stored to it.
/// </para>
/// </remarks>
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))

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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;

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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);