aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs70
1 files changed, 35 insertions, 35 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index 84e13a0..187f090 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -25,7 +25,7 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// Uncomment to make asset Get requests for existing 28// Uncomment to make asset Get requests for existing
29// #define WAIT_ON_INPROGRESS_REQUESTS 29// #define WAIT_ON_INPROGRESS_REQUESTS
30 30
31using System; 31using System;
@@ -113,7 +113,7 @@ namespace OpenSim.Region.CoreModules.Asset
113 private IAssetService m_AssetService; 113 private IAssetService m_AssetService;
114 private List<Scene> m_Scenes = new List<Scene>(); 114 private List<Scene> m_Scenes = new List<Scene>();
115 private object timerLock = new object(); 115 private object timerLock = new object();
116 116
117 private Dictionary<string,WeakReference> weakAssetReferences = new Dictionary<string, WeakReference>(); 117 private Dictionary<string,WeakReference> weakAssetReferences = new Dictionary<string, WeakReference>();
118 private object weakAssetReferencesLock = new object(); 118 private object weakAssetReferencesLock = new object();
119 private bool m_updateFileTimeOnCacheHit = false; 119 private bool m_updateFileTimeOnCacheHit = false;
@@ -124,7 +124,7 @@ namespace OpenSim.Region.CoreModules.Asset
124 m_InvalidChars.AddRange(Path.GetInvalidFileNameChars()); 124 m_InvalidChars.AddRange(Path.GetInvalidFileNameChars());
125 } 125 }
126 126
127 public Type ReplaceableInterface 127 public Type ReplaceableInterface
128 { 128 {
129 get { return null; } 129 get { return null; }
130 } 130 }
@@ -137,7 +137,7 @@ namespace OpenSim.Region.CoreModules.Asset
137 public void Initialise(IConfigSource source) 137 public void Initialise(IConfigSource source)
138 { 138 {
139 IConfig moduleConfig = source.Configs["Modules"]; 139 IConfig moduleConfig = source.Configs["Modules"];
140 140
141 if (moduleConfig != null) 141 if (moduleConfig != null)
142 { 142 {
143 string name = moduleConfig.GetString("AssetCaching", String.Empty); 143 string name = moduleConfig.GetString("AssetCaching", String.Empty);
@@ -169,11 +169,11 @@ namespace OpenSim.Region.CoreModules.Asset
169 m_negativeExpiration = assetConfig.GetInt("NegativeCacheTimeout", m_negativeExpiration); 169 m_negativeExpiration = assetConfig.GetInt("NegativeCacheTimeout", m_negativeExpiration);
170 m_negativeCacheSliding = assetConfig.GetBoolean("NegativeCacheSliding", m_negativeCacheSliding); 170 m_negativeCacheSliding = assetConfig.GetBoolean("NegativeCacheSliding", m_negativeCacheSliding);
171 m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit); 171 m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit);
172 172
173 #if WAIT_ON_INPROGRESS_REQUESTS 173 #if WAIT_ON_INPROGRESS_REQUESTS
174 m_WaitOnInprogressTimeout = assetConfig.GetInt("WaitOnInprogressTimeout", 3000); 174 m_WaitOnInprogressTimeout = assetConfig.GetInt("WaitOnInprogressTimeout", 3000);
175 #endif 175 #endif
176 176
177 m_LogLevel = assetConfig.GetInt("LogLevel", m_LogLevel); 177 m_LogLevel = assetConfig.GetInt("LogLevel", m_LogLevel);
178 m_HitRateDisplay = (ulong)assetConfig.GetLong("HitRateDisplay", (long)m_HitRateDisplay); 178 m_HitRateDisplay = (ulong)assetConfig.GetLong("HitRateDisplay", (long)m_HitRateDisplay);
179 179
@@ -266,7 +266,7 @@ namespace OpenSim.Region.CoreModules.Asset
266 { 266 {
267 m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds); 267 m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds);
268 m_CacheCleanTimer.AutoReset = false; 268 m_CacheCleanTimer.AutoReset = false;
269 m_CacheCleanTimer.Elapsed += CleanupExpiredFiles; 269 m_CacheCleanTimer.Elapsed += CleanupExpiredFiles;
270 m_CacheCleanTimer.Start(); 270 m_CacheCleanTimer.Start();
271 m_timerRunning = true; 271 m_timerRunning = true;
272 } 272 }
@@ -274,7 +274,7 @@ namespace OpenSim.Region.CoreModules.Asset
274 } 274 }
275 if (m_MemoryCacheEnabled) 275 if (m_MemoryCacheEnabled)
276 m_MemoryCache = new ExpiringCache<string, AssetBase>(); 276 m_MemoryCache = new ExpiringCache<string, AssetBase>();
277 277
278 lock(weakAssetReferencesLock) 278 lock(weakAssetReferencesLock)
279 weakAssetReferences = new Dictionary<string, WeakReference>(); 279 weakAssetReferences = new Dictionary<string, WeakReference>();
280 } 280 }
@@ -306,11 +306,11 @@ namespace OpenSim.Region.CoreModules.Asset
306 if (File.Exists(filename)) 306 if (File.Exists(filename))
307 { 307 {
308 UpdateFileLastAccessTime(filename); 308 UpdateFileLastAccessTime(filename);
309 } 309 }
310 else 310 else
311 { 311 {
312 // Once we start writing, make sure we flag that we're writing 312 // Once we start writing, make sure we flag that we're writing
313 // that object to the cache so that we don't try to write the 313 // that object to the cache so that we don't try to write the
314 // same file multiple times. 314 // same file multiple times.
315 lock (m_CurrentlyWriting) 315 lock (m_CurrentlyWriting)
316 { 316 {
@@ -439,7 +439,7 @@ namespace OpenSim.Region.CoreModules.Asset
439 /// <param name="id"></param> 439 /// <param name="id"></param>
440 /// <returns>An asset retrieved from the file cache. null if there was a problem retrieving an asset.</returns> 440 /// <returns>An asset retrieved from the file cache. null if there was a problem retrieving an asset.</returns>
441 private AssetBase GetFromFileCache(string id) 441 private AssetBase GetFromFileCache(string id)
442 { 442 {
443 string filename = GetFileName(id); 443 string filename = GetFileName(id);
444 444
445#if WAIT_ON_INPROGRESS_REQUESTS 445#if WAIT_ON_INPROGRESS_REQUESTS
@@ -649,7 +649,7 @@ namespace OpenSim.Region.CoreModules.Asset
649 m_MemoryCache = new ExpiringCache<string, AssetBase>(); 649 m_MemoryCache = new ExpiringCache<string, AssetBase>();
650 if (m_negativeCacheEnabled) 650 if (m_negativeCacheEnabled)
651 m_negativeCache = new ExpiringCache<string, object>(); 651 m_negativeCache = new ExpiringCache<string, object>();
652 652
653 lock(weakAssetReferencesLock) 653 lock(weakAssetReferencesLock)
654 weakAssetReferences = new Dictionary<string, WeakReference>(); 654 weakAssetReferences = new Dictionary<string, WeakReference>();
655 } 655 }
@@ -659,7 +659,7 @@ namespace OpenSim.Region.CoreModules.Asset
659 if (m_LogLevel >= 2) 659 if (m_LogLevel >= 2)
660 m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration); 660 m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration);
661 661
662 lock(timerLock) 662 lock(timerLock)
663 { 663 {
664 if(!m_timerRunning || m_cleanupRunning) 664 if(!m_timerRunning || m_cleanupRunning)
665 return; 665 return;
@@ -687,8 +687,8 @@ namespace OpenSim.Region.CoreModules.Asset
687 } 687 }
688 688
689 /// <summary> 689 /// <summary>
690 /// Recurses through specified directory checking for asset files last 690 /// Recurses through specified directory checking for asset files last
691 /// accessed prior to the specified purge line and deletes them. Also 691 /// accessed prior to the specified purge line and deletes them. Also
692 /// removes empty tier directories. 692 /// removes empty tier directories.
693 /// </summary> 693 /// </summary>
694 /// <param name="dir"></param> 694 /// <param name="dir"></param>
@@ -720,7 +720,7 @@ namespace OpenSim.Region.CoreModules.Asset
720 else if (dirSize >= m_CacheWarnAt) 720 else if (dirSize >= m_CacheWarnAt)
721 { 721 {
722 m_log.WarnFormat( 722 m_log.WarnFormat(
723 "[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", 723 "[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration",
724 dir, dirSize); 724 dir, dirSize);
725 } 725 }
726 } 726 }
@@ -760,7 +760,7 @@ namespace OpenSim.Region.CoreModules.Asset
760 } 760 }
761 761
762 /// <summary> 762 /// <summary>
763 /// Writes a file to the file cache, creating any nessesary 763 /// Writes a file to the file cache, creating any nessesary
764 /// tier directories along the way 764 /// tier directories along the way
765 /// </summary> 765 /// </summary>
766 /// <param name="filename"></param> 766 /// <param name="filename"></param>
@@ -772,7 +772,7 @@ namespace OpenSim.Region.CoreModules.Asset
772 // Make sure the target cache directory exists 772 // Make sure the target cache directory exists
773 string directory = Path.GetDirectoryName(filename); 773 string directory = Path.GetDirectoryName(filename);
774 774
775 // Write file first to a temp name, so that it doesn't look 775 // Write file first to a temp name, so that it doesn't look
776 // like it's already cached while it's still writing. 776 // like it's already cached while it's still writing.
777 string tempname = Path.Combine(directory, Path.GetRandomFileName()); 777 string tempname = Path.Combine(directory, Path.GetRandomFileName());
778 778
@@ -784,7 +784,7 @@ namespace OpenSim.Region.CoreModules.Asset
784 { 784 {
785 Directory.CreateDirectory(directory); 785 Directory.CreateDirectory(directory);
786 } 786 }
787 787
788 stream = File.Open(tempname, FileMode.Create); 788 stream = File.Open(tempname, FileMode.Create);
789 BinaryFormatter bformatter = new BinaryFormatter(); 789 BinaryFormatter bformatter = new BinaryFormatter();
790 bformatter.Serialize(stream, asset); 790 bformatter.Serialize(stream, asset);
@@ -818,7 +818,7 @@ namespace OpenSim.Region.CoreModules.Asset
818 // This situation occurs fairly rarely anyway. We assume in this that moves are atomic on the 818 // This situation occurs fairly rarely anyway. We assume in this that moves are atomic on the
819 // filesystem. 819 // filesystem.
820 File.Move(tempname, filename); 820 File.Move(tempname, filename);
821 821
822 if (m_LogLevel >= 2) 822 if (m_LogLevel >= 2)
823 m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID); 823 m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID);
824 } 824 }
@@ -875,7 +875,7 @@ namespace OpenSim.Region.CoreModules.Asset
875 { 875 {
876 string RegionCacheStatusFile = Path.Combine(m_CacheDirectory, "RegionStatus_" + regionID.ToString() + ".fac"); 876 string RegionCacheStatusFile = Path.Combine(m_CacheDirectory, "RegionStatus_" + regionID.ToString() + ".fac");
877 877
878 try 878 try
879 { 879 {
880 if (File.Exists(RegionCacheStatusFile)) 880 if (File.Exists(RegionCacheStatusFile))
881 { 881 {
@@ -884,7 +884,7 @@ namespace OpenSim.Region.CoreModules.Asset
884 else 884 else
885 { 885 {
886 File.WriteAllText( 886 File.WriteAllText(
887 RegionCacheStatusFile, 887 RegionCacheStatusFile,
888 "Please do not delete this file unless you are manually clearing your Flotsam Asset Cache."); 888 "Please do not delete this file unless you are manually clearing your Flotsam Asset Cache.");
889 } 889 }
890 } 890 }
@@ -892,14 +892,14 @@ namespace OpenSim.Region.CoreModules.Asset
892 { 892 {
893 m_log.Warn( 893 m_log.Warn(
894 string.Format( 894 string.Format(
895 "[FLOTSAM ASSET CACHE]: Could not stamp region status file for region {0}. Exception ", 895 "[FLOTSAM ASSET CACHE]: Could not stamp region status file for region {0}. Exception ",
896 regionID), 896 regionID),
897 e); 897 e);
898 } 898 }
899 } 899 }
900 900
901 /// <summary> 901 /// <summary>
902 /// Iterates through all Scenes, doing a deep scan through assets 902 /// Iterates through all Scenes, doing a deep scan through assets
903 /// to update the access time of all assets present in the scene or referenced by assets 903 /// to update the access time of all assets present in the scene or referenced by assets
904 /// in the scene. 904 /// in the scene.
905 /// </summary> 905 /// </summary>
@@ -918,7 +918,7 @@ namespace OpenSim.Region.CoreModules.Asset
918 StampRegionStatusFile(s.RegionInfo.RegionID); 918 StampRegionStatusFile(s.RegionInfo.RegionID);
919 919
920 s.ForEachSOG(delegate(SceneObjectGroup e) 920 s.ForEachSOG(delegate(SceneObjectGroup e)
921 { 921 {
922 if(!m_timerRunning && !storeUncached) 922 if(!m_timerRunning && !storeUncached)
923 return; 923 return;
924 924
@@ -1012,7 +1012,7 @@ namespace OpenSim.Region.CoreModules.Asset
1012 1012
1013 double weakHitRate = m_weakRefHits * invReq; 1013 double weakHitRate = m_weakRefHits * invReq;
1014 int weakEntries = weakAssetReferences.Count; 1014 int weakEntries = weakAssetReferences.Count;
1015 1015
1016 double fileHitRate = m_DiskHits * invReq; 1016 double fileHitRate = m_DiskHits * invReq;
1017 double TotalHitRate = weakHitRate + fileHitRate; 1017 double TotalHitRate = weakHitRate + fileHitRate;
1018 1018
@@ -1073,9 +1073,9 @@ namespace OpenSim.Region.CoreModules.Asset
1073 if (m_FileCacheEnabled) 1073 if (m_FileCacheEnabled)
1074 { 1074 {
1075 con.Output("Deep scans have previously been performed on the following regions:"); 1075 con.Output("Deep scans have previously been performed on the following regions:");
1076 1076
1077 foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac")) 1077 foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac"))
1078 { 1078 {
1079 string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac",""); 1079 string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac","");
1080 DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s); 1080 DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s);
1081 con.OutputFormat("Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss")); 1081 con.OutputFormat("Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss"));
@@ -1118,7 +1118,7 @@ namespace OpenSim.Region.CoreModules.Asset
1118 con.Output("Memory cache not enabled."); 1118 con.Output("Memory cache not enabled.");
1119 } 1119 }
1120 } 1120 }
1121 1121
1122 if (clearFile) 1122 if (clearFile)
1123 { 1123 {
1124 if (m_FileCacheEnabled) 1124 if (m_FileCacheEnabled)
@@ -1147,7 +1147,7 @@ namespace OpenSim.Region.CoreModules.Asset
1147 1147
1148 con.Output("FloatSam Ensuring assets are cached for all scenes."); 1148 con.Output("FloatSam Ensuring assets are cached for all scenes.");
1149 1149
1150 WorkManager.RunInThread(delegate 1150 WorkManager.RunInThread(delegate
1151 { 1151 {
1152 bool wasRunning= false; 1152 bool wasRunning= false;
1153 lock(timerLock) 1153 lock(timerLock)
@@ -1167,7 +1167,7 @@ namespace OpenSim.Region.CoreModules.Asset
1167 if(wasRunning) 1167 if(wasRunning)
1168 { 1168 {
1169 m_CacheCleanTimer.Start(); 1169 m_CacheCleanTimer.Start();
1170 m_timerRunning = true; 1170 m_timerRunning = true;
1171 } 1171 }
1172 m_cleanupRunning = false; 1172 m_cleanupRunning = false;
1173 } 1173 }
@@ -1247,12 +1247,12 @@ namespace OpenSim.Region.CoreModules.Asset
1247 public bool[] AssetsExist(string[] ids) 1247 public bool[] AssetsExist(string[] ids)
1248 { 1248 {
1249 bool[] exist = new bool[ids.Length]; 1249 bool[] exist = new bool[ids.Length];
1250 1250
1251 for (int i = 0; i < ids.Length; i++) 1251 for (int i = 0; i < ids.Length; i++)
1252 { 1252 {
1253 exist[i] = Check(ids[i]); 1253 exist[i] = Check(ids[i]);
1254 } 1254 }
1255 1255
1256 return exist; 1256 return exist;
1257 } 1257 }
1258 1258