From 98de42eedcb21ecb587be5fb266a580e19dea1a3 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 6 Mar 2020 19:20:12 +0000 Subject: [PATCH] flotsam: add comands deletedefaultassets to delete local default assets (on folder bin/assets) from cache so they can be refreshed from grid and cachedefaultassets to load those local assets into cache. This comands may cause desync with grid or other regions. Viewers will need to clear cache so see effects. Use with care --- .../CoreModules/Asset/FlotsamAssetCache.cs | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index bbf7be745c..b6f9e2e7ce 100755 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -68,6 +68,8 @@ namespace OpenSim.Region.CoreModules.Asset private const string m_ModuleName = "FlotsamAssetCache"; private const string m_DefaultCacheDirectory = "./assetcache"; private string m_CacheDirectory = m_DefaultCacheDirectory; + private string m_assetLoader; + private string m_assetLoaderArgs; private readonly List m_InvalidChars = new List(); @@ -205,14 +207,26 @@ namespace OpenSim.Region.CoreModules.Asset m_CacheDirectoryTierLen = 1; } else if (m_CacheDirectoryTierLen > 4) - { m_CacheDirectoryTierLen = 4; + + assetConfig = source.Configs["AssetService"]; + if(assetConfig != null) + { + m_assetLoader = assetConfig.GetString("DefaultAssetLoader", String.Empty); + m_assetLoaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty); + if (string.IsNullOrWhiteSpace(m_assetLoaderArgs)) + m_assetLoader = string.Empty; } MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache status", "fcache status", "Display cache status", HandleConsoleCommand); MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache clear", "fcache clear [file] [memory]", "Remove all assets in the cache. If file or memory is specified then only this cache is cleared.", HandleConsoleCommand); MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache assets", "fcache assets", "Attempt a deep scan and cache of all assets in all scenes", HandleConsoleCommand); MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache expire", "fcache expire ", "Purge cached assets older then the specified date/time", HandleConsoleCommand); + if (!string.IsNullOrWhiteSpace(m_assetLoader)) + { + MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache cachedefaultassets", "fcache cachedefaultassets", "loads local default assets to cache. This may override grid ones. use with care", HandleConsoleCommand); + MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache deletedefaultassets", "fcache deletedefaultassets", "deletes default local assets from cache so they can be refreshed from grid. use with care", HandleConsoleCommand); + } } } } @@ -1230,6 +1244,12 @@ namespace OpenSim.Region.CoreModules.Asset else con.Output("File cache not active, not clearing."); + break; + case "cachedefaultassets": + HandleLoadDefaultAssets(); + break; + case "deletedefaultassets": + HandleDeleteDefaultAssets(); break; default: con.Output("Unknown command {0}", cmd); @@ -1242,6 +1262,8 @@ namespace OpenSim.Region.CoreModules.Asset con.Output("fcache expire - Purge assets older then the specified date & time"); con.Output("fcache clear [file] [memory] - Remove cached assets"); con.Output("fcache status - Display cache status"); + con.Output("fcache cachedefaultassets - loads default assets to cache replacing existent ones, this may override grid assets. Use with care"); + con.Output("fcache deletedefaultassets - deletes default local assets from cache so they can be refreshed from grid"); } } @@ -1316,6 +1338,59 @@ namespace OpenSim.Region.CoreModules.Asset return true; } + private void HandleLoadDefaultAssets() + { + if (string.IsNullOrWhiteSpace(m_assetLoader)) + { + m_log.Info("[FLOTSAM ASSET CACHE] default assets loader not defined"); + return; + } + + IAssetLoader assetLoader = ServerUtils.LoadPlugin(m_assetLoader, new object[] { }); + if (assetLoader == null) + { + m_log.Info("[FLOTSAM ASSET CACHE] default assets loader not found"); + return; + } + + m_log.Info("[FLOTSAM ASSET CACHE] start loading local default assets"); + int count = 0; + assetLoader.ForEachDefaultXmlAsset( + m_assetLoaderArgs, + delegate (AssetBase a) + { + Cache(a); + ++count; + }); + m_log.InfoFormat("[FLOTSAM ASSET CACHE] loaded {0} local default assets", count); + } + + private void HandleDeleteDefaultAssets() + { + if (string.IsNullOrWhiteSpace(m_assetLoader)) + { + m_log.Info("[FLOTSAM ASSET CACHE] default assets loader not defined"); + return; + } + + IAssetLoader assetLoader = ServerUtils.LoadPlugin(m_assetLoader, new object[] { }); + if (assetLoader == null) + { + m_log.Info("[FLOTSAM ASSET CACHE] default assets loader not found"); + return; + } + + m_log.Info("[FLOTSAM ASSET CACHE] started deleting local default assets"); + int count = 0; + assetLoader.ForEachDefaultXmlAsset( + m_assetLoaderArgs, + delegate (AssetBase a) + { + Expire(a.ID); + ++count; + }); + m_log.InfoFormat("[FLOTSAM ASSET CACHE] deleted {0} local default assets", count); + } #endregion } }