aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
diff options
context:
space:
mode:
authorMelanie2013-04-28 19:03:39 +0200
committerMelanie2013-04-28 19:03:39 +0200
commit4275d7a839d7380ee50aeadc38a31dd467bd891e (patch)
tree1e589fc3b448b580d1cc25b52215ef5ce2d7ae78 /OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
parentMerge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork (diff)
parentController module for dynamic floaters (WIP) (diff)
downloadopensim-SC-4275d7a839d7380ee50aeadc38a31dd467bd891e.zip
opensim-SC-4275d7a839d7380ee50aeadc38a31dd467bd891e.tar.gz
opensim-SC-4275d7a839d7380ee50aeadc38a31dd467bd891e.tar.bz2
opensim-SC-4275d7a839d7380ee50aeadc38a31dd467bd891e.tar.xz
Merge branch 'avination-current' of ssh://3dhosting.de/var/git/careminster into avination-current
Conflicts: bin/Regions/Regions.ini.example
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs177
1 files changed, 108 insertions, 69 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index a0f1e8c..d510d82 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -363,12 +363,37 @@ namespace OpenSim.Region.CoreModules.Asset
363 /// Try to get an asset from the file cache. 363 /// Try to get an asset from the file cache.
364 /// </summary> 364 /// </summary>
365 /// <param name="id"></param> 365 /// <param name="id"></param>
366 /// <returns></returns> 366 /// <returns>An asset retrieved from the file cache. null if there was a problem retrieving an asset.</returns>
367 private AssetBase GetFromFileCache(string id) 367 private AssetBase GetFromFileCache(string id)
368 { 368 {
369 string filename = GetFileName(id);
370
371#if WAIT_ON_INPROGRESS_REQUESTS
372 // Check if we're already downloading this asset. If so, try to wait for it to
373 // download.
374 if (m_WaitOnInprogressTimeout > 0)
375 {
376 m_RequestsForInprogress++;
377
378 ManualResetEvent waitEvent;
379 if (m_CurrentlyWriting.TryGetValue(filename, out waitEvent))
380 {
381 waitEvent.WaitOne(m_WaitOnInprogressTimeout);
382 return Get(id);
383 }
384 }
385#else
386 // Track how often we have the problem that an asset is requested while
387 // it is still being downloaded by a previous request.
388 if (m_CurrentlyWriting.Contains(filename))
389 {
390 m_RequestsForInprogress++;
391 return null;
392 }
393#endif
394
369 AssetBase asset = null; 395 AssetBase asset = null;
370 396
371 string filename = GetFileName(id);
372 if (File.Exists(filename)) 397 if (File.Exists(filename))
373 { 398 {
374 FileStream stream = null; 399 FileStream stream = null;
@@ -383,7 +408,7 @@ namespace OpenSim.Region.CoreModules.Asset
383 } 408 }
384 catch (System.Runtime.Serialization.SerializationException e) 409 catch (System.Runtime.Serialization.SerializationException e)
385 { 410 {
386 m_log.ErrorFormat( 411 m_log.WarnFormat(
387 "[FLOTSAM ASSET CACHE]: Failed to get file {0} for asset {1}. Exception {2} {3}", 412 "[FLOTSAM ASSET CACHE]: Failed to get file {0} for asset {1}. Exception {2} {3}",
388 filename, id, e.Message, e.StackTrace); 413 filename, id, e.Message, e.StackTrace);
389 414
@@ -395,9 +420,10 @@ namespace OpenSim.Region.CoreModules.Asset
395 } 420 }
396 catch (Exception e) 421 catch (Exception e)
397 { 422 {
398 m_log.ErrorFormat( 423 m_log.WarnFormat(
399 "[FLOTSAM ASSET CACHE]: Failed to get file {0} for asset {1}. Exception {2} {3}", 424 "[FLOTSAM ASSET CACHE]: Failed to get file {0} for asset {1}. Exception {2} {3}",
400 filename, id, e.Message, e.StackTrace); 425 filename, id, e.Message, e.StackTrace);
426
401 } 427 }
402 finally 428 finally
403 { 429 {
@@ -406,28 +432,6 @@ namespace OpenSim.Region.CoreModules.Asset
406 } 432 }
407 } 433 }
408 434
409#if WAIT_ON_INPROGRESS_REQUESTS
410 // Check if we're already downloading this asset. If so, try to wait for it to
411 // download.
412 if (m_WaitOnInprogressTimeout > 0)
413 {
414 m_RequestsForInprogress++;
415
416 ManualResetEvent waitEvent;
417 if (m_CurrentlyWriting.TryGetValue(filename, out waitEvent))
418 {
419 waitEvent.WaitOne(m_WaitOnInprogressTimeout);
420 return Get(id);
421 }
422 }
423#else
424 // Track how often we have the problem that an asset is requested while
425 // it is still being downloaded by a previous request.
426 if (m_CurrentlyWriting.Contains(filename))
427 {
428 m_RequestsForInprogress++;
429 }
430#endif
431 return asset; 435 return asset;
432 } 436 }
433 437
@@ -552,7 +556,7 @@ namespace OpenSim.Region.CoreModules.Asset
552 } 556 }
553 catch (Exception e) 557 catch (Exception e)
554 { 558 {
555 m_log.ErrorFormat( 559 m_log.WarnFormat(
556 "[FLOTSAM ASSET CACHE]: Failed to expire cached file {0}. Exception {1} {2}", 560 "[FLOTSAM ASSET CACHE]: Failed to expire cached file {0}. Exception {1} {2}",
557 id, e.Message, e.StackTrace); 561 id, e.Message, e.StackTrace);
558 } 562 }
@@ -603,29 +607,39 @@ namespace OpenSim.Region.CoreModules.Asset
603 /// <param name="purgeLine"></param> 607 /// <param name="purgeLine"></param>
604 private void CleanExpiredFiles(string dir, DateTime purgeLine) 608 private void CleanExpiredFiles(string dir, DateTime purgeLine)
605 { 609 {
606 foreach (string file in Directory.GetFiles(dir)) 610 try
607 { 611 {
608 if (File.GetLastAccessTime(file) < purgeLine) 612 foreach (string file in Directory.GetFiles(dir))
609 { 613 {
610 File.Delete(file); 614 if (File.GetLastAccessTime(file) < purgeLine)
615 {
616 File.Delete(file);
617 }
611 } 618 }
612 }
613 619
614 // Recurse into lower tiers 620 // Recurse into lower tiers
615 foreach (string subdir in Directory.GetDirectories(dir)) 621 foreach (string subdir in Directory.GetDirectories(dir))
616 { 622 {
617 CleanExpiredFiles(subdir, purgeLine); 623 CleanExpiredFiles(subdir, purgeLine);
618 } 624 }
619 625
620 // Check if a tier directory is empty, if so, delete it 626 // Check if a tier directory is empty, if so, delete it
621 int dirSize = Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length; 627 int dirSize = Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length;
622 if (dirSize == 0) 628 if (dirSize == 0)
623 { 629 {
624 Directory.Delete(dir); 630 Directory.Delete(dir);
631 }
632 else if (dirSize >= m_CacheWarnAt)
633 {
634 m_log.WarnFormat(
635 "[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration",
636 dir, dirSize);
637 }
625 } 638 }
626 else if (dirSize >= m_CacheWarnAt) 639 catch (Exception e)
627 { 640 {
628 m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); 641 m_log.Warn(
642 string.Format("[FLOTSAM ASSET CACHE]: Could not complete clean of expired files in {0}, exception ", dir), e);
629 } 643 }
630 } 644 }
631 645
@@ -684,7 +698,7 @@ namespace OpenSim.Region.CoreModules.Asset
684 } 698 }
685 catch (IOException e) 699 catch (IOException e)
686 { 700 {
687 m_log.ErrorFormat( 701 m_log.WarnFormat(
688 "[FLOTSAM ASSET CACHE]: Failed to write asset {0} to temporary location {1} (final {2}) on cache in {3}. Exception {4} {5}.", 702 "[FLOTSAM ASSET CACHE]: Failed to write asset {0} to temporary location {1} (final {2}) on cache in {3}. Exception {4} {5}.",
689 asset.ID, tempname, filename, directory, e.Message, e.StackTrace); 703 asset.ID, tempname, filename, directory, e.Message, e.StackTrace);
690 704
@@ -763,17 +777,31 @@ namespace OpenSim.Region.CoreModules.Asset
763 /// <summary> 777 /// <summary>
764 /// This notes the last time the Region had a deep asset scan performed on it. 778 /// This notes the last time the Region had a deep asset scan performed on it.
765 /// </summary> 779 /// </summary>
766 /// <param name="RegionID"></param> 780 /// <param name="regionID"></param>
767 private void StampRegionStatusFile(UUID RegionID) 781 private void StampRegionStatusFile(UUID regionID)
768 { 782 {
769 string RegionCacheStatusFile = Path.Combine(m_CacheDirectory, "RegionStatus_" + RegionID.ToString() + ".fac"); 783 string RegionCacheStatusFile = Path.Combine(m_CacheDirectory, "RegionStatus_" + regionID.ToString() + ".fac");
770 if (File.Exists(RegionCacheStatusFile)) 784
785 try
771 { 786 {
772 File.SetLastWriteTime(RegionCacheStatusFile, DateTime.Now); 787 if (File.Exists(RegionCacheStatusFile))
788 {
789 File.SetLastWriteTime(RegionCacheStatusFile, DateTime.Now);
790 }
791 else
792 {
793 File.WriteAllText(
794 RegionCacheStatusFile,
795 "Please do not delete this file unless you are manually clearing your Flotsam Asset Cache.");
796 }
773 } 797 }
774 else 798 catch (Exception e)
775 { 799 {
776 File.WriteAllText(RegionCacheStatusFile, "Please do not delete this file unless you are manually clearing your Flotsam Asset Cache."); 800 m_log.Warn(
801 string.Format(
802 "[FLOTSAM ASSET CACHE]: Could not stamp region status file for region {0}. Exception ",
803 regionID),
804 e);
777 } 805 }
778 } 806 }
779 807
@@ -790,32 +818,43 @@ namespace OpenSim.Region.CoreModules.Asset
790 { 818 {
791 UuidGatherer gatherer = new UuidGatherer(m_AssetService); 819 UuidGatherer gatherer = new UuidGatherer(m_AssetService);
792 820
821 HashSet<UUID> uniqueUuids = new HashSet<UUID>();
793 Dictionary<UUID, AssetType> assets = new Dictionary<UUID, AssetType>(); 822 Dictionary<UUID, AssetType> assets = new Dictionary<UUID, AssetType>();
823
794 foreach (Scene s in m_Scenes) 824 foreach (Scene s in m_Scenes)
795 { 825 {
796 StampRegionStatusFile(s.RegionInfo.RegionID); 826 StampRegionStatusFile(s.RegionInfo.RegionID);
797 827
798 s.ForEachSOG(delegate(SceneObjectGroup e) 828 s.ForEachSOG(delegate(SceneObjectGroup e)
799 { 829 {
800 gatherer.GatherAssetUuids(e, assets); 830 gatherer.GatherAssetUuids(e, assets);
801 });
802 }
803 831
804 foreach (UUID assetID in assets.Keys) 832 foreach (UUID assetID in assets.Keys)
805 { 833 {
806 string filename = GetFileName(assetID.ToString()); 834 uniqueUuids.Add(assetID);
807 835
808 if (File.Exists(filename)) 836 string filename = GetFileName(assetID.ToString());
809 { 837
810 File.SetLastAccessTime(filename, DateTime.Now); 838 if (File.Exists(filename))
811 } 839 {
812 else if (storeUncached) 840 File.SetLastAccessTime(filename, DateTime.Now);
813 { 841 }
814 m_AssetService.Get(assetID.ToString()); 842 else if (storeUncached)
815 } 843 {
844 AssetBase cachedAsset = m_AssetService.Get(assetID.ToString());
845 if (cachedAsset == null && assets[assetID] != AssetType.Unknown)
846 m_log.DebugFormat(
847 "[FLOTSAM ASSET CACHE]: Could not find asset {0}, type {1} referenced by object {2} at {3} in scene {4} when pre-caching all scene assets",
848 assetID, assets[assetID], e.Name, e.AbsolutePosition, s.Name);
849 }
850 }
851
852 assets.Clear();
853 });
816 } 854 }
817 855
818 return assets.Keys.Count; 856
857 return uniqueUuids.Count;
819 } 858 }
820 859
821 /// <summary> 860 /// <summary>
@@ -831,7 +870,7 @@ namespace OpenSim.Region.CoreModules.Asset
831 } 870 }
832 catch (Exception e) 871 catch (Exception e)
833 { 872 {
834 m_log.ErrorFormat( 873 m_log.WarnFormat(
835 "[FLOTSAM ASSET CACHE]: Couldn't clear asset cache directory {0} from {1}. Exception {2} {3}", 874 "[FLOTSAM ASSET CACHE]: Couldn't clear asset cache directory {0} from {1}. Exception {2} {3}",
836 dir, m_CacheDirectory, e.Message, e.StackTrace); 875 dir, m_CacheDirectory, e.Message, e.StackTrace);
837 } 876 }
@@ -845,7 +884,7 @@ namespace OpenSim.Region.CoreModules.Asset
845 } 884 }
846 catch (Exception e) 885 catch (Exception e)
847 { 886 {
848 m_log.ErrorFormat( 887 m_log.WarnFormat(
849 "[FLOTSAM ASSET CACHE]: Couldn't clear asset cache file {0} from {1}. Exception {1} {2}", 888 "[FLOTSAM ASSET CACHE]: Couldn't clear asset cache file {0} from {1}. Exception {1} {2}",
850 file, m_CacheDirectory, e.Message, e.StackTrace); 889 file, m_CacheDirectory, e.Message, e.StackTrace);
851 } 890 }