mantis 8675: flotsam cache only log missing files if log level >= 2 (thanks mewtwo0641 ) this log will include things that may not even be assets due to how gatherer works; change a bit filename composition

master
UbitUmarov 2020-07-09 16:27:11 +01:00
parent 28fcbc65f9
commit af6fa37cc2
1 changed files with 27 additions and 24 deletions

View File

@ -60,8 +60,7 @@ namespace OpenSim.Region.CoreModules.Asset
private bool m_cleanupRunning; private bool m_cleanupRunning;
private const string m_ModuleName = "FlotsamAssetCache"; private const string m_ModuleName = "FlotsamAssetCache";
private const string m_DefaultCacheDirectory = "./assetcache"; private string m_CacheDirectory = "assetcache";
private string m_CacheDirectory = m_DefaultCacheDirectory;
private string m_assetLoader; private string m_assetLoader;
private string m_assetLoaderArgs; private string m_assetLoaderArgs;
@ -154,7 +153,8 @@ namespace OpenSim.Region.CoreModules.Asset
else else
{ {
m_FileCacheEnabled = assetConfig.GetBoolean("FileCacheEnabled", m_FileCacheEnabled); m_FileCacheEnabled = assetConfig.GetBoolean("FileCacheEnabled", m_FileCacheEnabled);
m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_CacheDirectory);
m_CacheDirectory = Path.GetFullPath(m_CacheDirectory);
m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled); m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled);
m_MemoryExpiration = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration); m_MemoryExpiration = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration);
@ -593,19 +593,19 @@ namespace OpenSim.Region.CoreModules.Asset
lock (weakAssetReferencesLock) lock (weakAssetReferencesLock)
weakAssetReferences.Remove(id); weakAssetReferences.Remove(id);
if (m_MemoryCacheEnabled)
m_MemoryCache.Remove(id);
if (m_FileCacheEnabled) if (m_FileCacheEnabled)
{ {
string filename = GetFileName(id); string filename = GetFileName(id);
File.Delete(filename); File.Delete(filename);
} }
if (m_MemoryCacheEnabled)
m_MemoryCache.Remove(id);
} }
catch (Exception e) catch (Exception e)
{ {
m_log.WarnFormat( if (m_LogLevel >= 2)
"[FLOTSAM ASSET CACHE]: Failed to expire cached file {0}. Exception {1} {2}", m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Failed to expire cached file {0}. Exception {1} {2}",
id, e.Message, e.StackTrace); id, e.Message, e.StackTrace);
} }
} }
@ -671,7 +671,6 @@ namespace OpenSim.Region.CoreModules.Asset
heap = GC.GetTotalMemory(false) - heap; heap = GC.GetTotalMemory(false) - heap;
double fheap = Math.Round((double)(heap / (1024 * 1024)),3); double fheap = Math.Round((double)(heap / (1024 * 1024)),3);
m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Finished automatic Check for expired files heap delta: {0}MB.", fheap); m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Finished automatic Check for expired files heap delta: {0}MB.", fheap);
heap = GC.GetTotalMemory(false);
} }
} }
@ -731,8 +730,7 @@ namespace OpenSim.Region.CoreModules.Asset
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Warn( m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Could not complete clean of expired files in {0}, exception {1}", dir, e.Message);
string.Format("[FLOTSAM ASSET CACHE]: Could not complete clean of expired files in {0}, exception ", dir), e);
} }
} }
@ -743,26 +741,34 @@ namespace OpenSim.Region.CoreModules.Asset
/// <returns></returns> /// <returns></returns>
private string GetFileName(string id) private string GetFileName(string id)
{ {
StringBuilder sb = osStringBuilderCache.Acquire();
int indx = id.IndexOfAny(m_InvalidChars); int indx = id.IndexOfAny(m_InvalidChars);
if (indx >= 0) if (indx >= 0)
{ {
int sublen = id.Length - indx; int sublen = id.Length - indx;
StringBuilder sb = new StringBuilder(id);
for(int i = 0; i < m_InvalidChars.Length; ++i) for(int i = 0; i < m_InvalidChars.Length; ++i)
{ {
sb.Replace(m_InvalidChars[i], '_', indx, sublen); sb.Replace(m_InvalidChars[i], '_', indx, sublen);
} }
id = sb.ToString(); id = sb.ToString();
sb.Clear();
} }
if(m_CacheDirectoryTiers == 1)
string path = m_CacheDirectory;
for (int p = 1; p <= m_CacheDirectoryTiers; p++)
{ {
string pathPart = id.Substring((p - 1) * m_CacheDirectoryTierLen, m_CacheDirectoryTierLen); sb.Append(id.Substring(0, m_CacheDirectoryTierLen));
path = Path.Combine(path, pathPart); sb.Append(Path.DirectorySeparatorChar);
} }
else
{
for (int p = 0; p < m_CacheDirectoryTiers * m_CacheDirectoryTierLen; p += m_CacheDirectoryTierLen)
{
sb.Append(id.Substring(p, m_CacheDirectoryTierLen));
sb.Append(Path.DirectorySeparatorChar);
}
}
sb.Append(id);
return Path.Combine(path, id); return Path.Combine(m_CacheDirectory, osStringBuilderCache.GetStringAndRelease(sb));
} }
/// <summary> /// <summary>
@ -876,11 +882,8 @@ namespace OpenSim.Region.CoreModules.Asset
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Warn( m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Could not stamp region status file for region {0}. Exception {1}",
string.Format( regionID, e. Message);
"[FLOTSAM ASSET CACHE]: Could not stamp region status file for region {0}. Exception ",
regionID),
e);
} }
} }