diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index c4abc99..9413598 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | |||
@@ -62,6 +62,7 @@ namespace OpenSim.Region.CoreModules.Asset | |||
62 | MethodBase.GetCurrentMethod().DeclaringType); | 62 | MethodBase.GetCurrentMethod().DeclaringType); |
63 | 63 | ||
64 | private bool m_Enabled; | 64 | private bool m_Enabled; |
65 | private bool m_Running; | ||
65 | 66 | ||
66 | private const string m_ModuleName = "FlotsamAssetCache"; | 67 | private const string m_ModuleName = "FlotsamAssetCache"; |
67 | private const string m_DefaultCacheDirectory = "./assetcache"; | 68 | private const string m_DefaultCacheDirectory = "./assetcache"; |
@@ -94,7 +95,7 @@ namespace OpenSim.Region.CoreModules.Asset | |||
94 | private const double m_DefaultFileExpiration = 48; | 95 | private const double m_DefaultFileExpiration = 48; |
95 | private TimeSpan m_MemoryExpiration = TimeSpan.FromHours(m_DefaultMemoryExpiration); | 96 | private TimeSpan m_MemoryExpiration = TimeSpan.FromHours(m_DefaultMemoryExpiration); |
96 | private TimeSpan m_FileExpiration = TimeSpan.FromHours(m_DefaultFileExpiration); | 97 | private TimeSpan m_FileExpiration = TimeSpan.FromHours(m_DefaultFileExpiration); |
97 | private TimeSpan m_FileExpirationCleanupTimer = TimeSpan.FromHours(0.166); | 98 | private TimeSpan m_FileExpirationCleanupTimer = TimeSpan.FromHours(1.0); |
98 | 99 | ||
99 | private static int m_CacheDirectoryTiers = 1; | 100 | private static int m_CacheDirectoryTiers = 1; |
100 | private static int m_CacheDirectoryTierLen = 3; | 101 | private static int m_CacheDirectoryTierLen = 3; |
@@ -104,7 +105,8 @@ namespace OpenSim.Region.CoreModules.Asset | |||
104 | 105 | ||
105 | private IAssetService m_AssetService; | 106 | private IAssetService m_AssetService; |
106 | private List<Scene> m_Scenes = new List<Scene>(); | 107 | private List<Scene> m_Scenes = new List<Scene>(); |
107 | 108 | private object timerLock = new object(); | |
109 | |||
108 | public FlotsamAssetCache() | 110 | public FlotsamAssetCache() |
109 | { | 111 | { |
110 | m_InvalidChars.AddRange(Path.GetInvalidPathChars()); | 112 | m_InvalidChars.AddRange(Path.GetInvalidPathChars()); |
@@ -170,14 +172,6 @@ namespace OpenSim.Region.CoreModules.Asset | |||
170 | 172 | ||
171 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory); | 173 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory); |
172 | 174 | ||
173 | if (m_FileCacheEnabled && (m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero)) | ||
174 | { | ||
175 | m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds); | ||
176 | m_CacheCleanTimer.AutoReset = true; | ||
177 | m_CacheCleanTimer.Elapsed += CleanupExpiredFiles; | ||
178 | lock (m_CacheCleanTimer) | ||
179 | m_CacheCleanTimer.Start(); | ||
180 | } | ||
181 | 175 | ||
182 | if (m_CacheDirectoryTiers < 1) | 176 | if (m_CacheDirectoryTiers < 1) |
183 | { | 177 | { |
@@ -219,7 +213,6 @@ namespace OpenSim.Region.CoreModules.Asset | |||
219 | { | 213 | { |
220 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); | 214 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); |
221 | m_Scenes.Add(scene); | 215 | m_Scenes.Add(scene); |
222 | |||
223 | } | 216 | } |
224 | } | 217 | } |
225 | 218 | ||
@@ -229,13 +222,39 @@ namespace OpenSim.Region.CoreModules.Asset | |||
229 | { | 222 | { |
230 | scene.UnregisterModuleInterface<IImprovedAssetCache>(this); | 223 | scene.UnregisterModuleInterface<IImprovedAssetCache>(this); |
231 | m_Scenes.Remove(scene); | 224 | m_Scenes.Remove(scene); |
225 | lock(timerLock) | ||
226 | { | ||
227 | if(m_Running && m_Scenes.Count <= 0) | ||
228 | { | ||
229 | m_Running = false; | ||
230 | m_CacheCleanTimer.Stop(); | ||
231 | m_CacheCleanTimer.Close(); | ||
232 | } | ||
233 | } | ||
232 | } | 234 | } |
233 | } | 235 | } |
234 | 236 | ||
235 | public void RegionLoaded(Scene scene) | 237 | public void RegionLoaded(Scene scene) |
236 | { | 238 | { |
237 | if (m_Enabled && m_AssetService == null) | 239 | if (m_Enabled) |
238 | m_AssetService = scene.RequestModuleInterface<IAssetService>(); | 240 | { |
241 | if(m_AssetService == null) | ||
242 | m_AssetService = scene.RequestModuleInterface<IAssetService>(); | ||
243 | lock(timerLock) | ||
244 | { | ||
245 | if(!m_Running) | ||
246 | { | ||
247 | if (m_FileCacheEnabled && (m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero)) | ||
248 | { | ||
249 | m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds); | ||
250 | m_CacheCleanTimer.AutoReset = false; | ||
251 | m_CacheCleanTimer.Elapsed += CleanupExpiredFiles; | ||
252 | m_CacheCleanTimer.Start(); | ||
253 | m_Running = true; | ||
254 | } | ||
255 | } | ||
256 | } | ||
257 | } | ||
239 | } | 258 | } |
240 | 259 | ||
241 | //////////////////////////////////////////////////////////// | 260 | //////////////////////////////////////////////////////////// |
@@ -542,6 +561,8 @@ namespace OpenSim.Region.CoreModules.Asset | |||
542 | if (m_LogLevel >= 2) | 561 | if (m_LogLevel >= 2) |
543 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration); | 562 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration); |
544 | 563 | ||
564 | if(!m_Running) | ||
565 | return; | ||
545 | // Purge all files last accessed prior to this point | 566 | // Purge all files last accessed prior to this point |
546 | DateTime purgeLine = DateTime.Now - m_FileExpiration; | 567 | DateTime purgeLine = DateTime.Now - m_FileExpiration; |
547 | 568 | ||
@@ -554,6 +575,12 @@ namespace OpenSim.Region.CoreModules.Asset | |||
554 | { | 575 | { |
555 | CleanExpiredFiles(dir, purgeLine); | 576 | CleanExpiredFiles(dir, purgeLine); |
556 | } | 577 | } |
578 | |||
579 | lock(timerLock) | ||
580 | { | ||
581 | if(m_Running) | ||
582 | m_CacheCleanTimer.Start(); | ||
583 | } | ||
557 | } | 584 | } |
558 | 585 | ||
559 | /// <summary> | 586 | /// <summary> |
@@ -789,9 +816,15 @@ namespace OpenSim.Region.CoreModules.Asset | |||
789 | 816 | ||
790 | s.ForEachSOG(delegate(SceneObjectGroup e) | 817 | s.ForEachSOG(delegate(SceneObjectGroup e) |
791 | { | 818 | { |
819 | if(!m_Running && !storeUncached) | ||
820 | return; | ||
821 | |||
792 | gatherer.AddForInspection(e); | 822 | gatherer.AddForInspection(e); |
793 | gatherer.GatherAll(); | 823 | gatherer.GatherAll(); |
794 | 824 | ||
825 | if(!m_Running && !storeUncached) | ||
826 | return; | ||
827 | |||
795 | foreach (UUID assetID in gatherer.GatheredUuids.Keys) | 828 | foreach (UUID assetID in gatherer.GatheredUuids.Keys) |
796 | { | 829 | { |
797 | if (!assetsFound.ContainsKey(assetID)) | 830 | if (!assetsFound.ContainsKey(assetID)) |
@@ -801,6 +834,7 @@ namespace OpenSim.Region.CoreModules.Asset | |||
801 | if (File.Exists(filename)) | 834 | if (File.Exists(filename)) |
802 | { | 835 | { |
803 | UpdateFileLastAccessTime(filename); | 836 | UpdateFileLastAccessTime(filename); |
837 | assetsFound[assetID] = true; | ||
804 | } | 838 | } |
805 | else if (storeUncached) | 839 | else if (storeUncached) |
806 | { | 840 | { |
@@ -820,7 +854,14 @@ namespace OpenSim.Region.CoreModules.Asset | |||
820 | } | 854 | } |
821 | 855 | ||
822 | gatherer.GatheredUuids.Clear(); | 856 | gatherer.GatheredUuids.Clear(); |
857 | if(!m_Running && !storeUncached) | ||
858 | return; | ||
859 | |||
860 | if(!storeUncached) | ||
861 | Thread.Sleep(50); | ||
823 | }); | 862 | }); |
863 | if(!m_Running && !storeUncached) | ||
864 | break; | ||
824 | } | 865 | } |
825 | 866 | ||
826 | return assetsFound.Count; | 867 | return assetsFound.Count; |
@@ -982,7 +1023,27 @@ namespace OpenSim.Region.CoreModules.Asset | |||
982 | 1023 | ||
983 | WorkManager.RunInThread(delegate | 1024 | WorkManager.RunInThread(delegate |
984 | { | 1025 | { |
1026 | bool wasRunning= false; | ||
1027 | lock(timerLock) | ||
1028 | { | ||
1029 | if(m_Running) | ||
1030 | { | ||
1031 | m_CacheCleanTimer.Stop(); | ||
1032 | m_Running = false; | ||
1033 | wasRunning = true; | ||
1034 | Thread.Sleep(100); | ||
1035 | } | ||
1036 | } | ||
985 | int assetReferenceTotal = TouchAllSceneAssets(true); | 1037 | int assetReferenceTotal = TouchAllSceneAssets(true); |
1038 | GC.Collect(); | ||
1039 | lock(timerLock) | ||
1040 | { | ||
1041 | if(wasRunning) | ||
1042 | { | ||
1043 | m_CacheCleanTimer.Start(); | ||
1044 | m_Running = true; | ||
1045 | } | ||
1046 | } | ||
986 | con.OutputFormat("Completed check with {0} assets.", assetReferenceTotal); | 1047 | con.OutputFormat("Completed check with {0} assets.", assetReferenceTotal); |
987 | }, null, "TouchAllSceneAssets"); | 1048 | }, null, "TouchAllSceneAssets"); |
988 | 1049 | ||