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.
This commit is contained in:
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

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