Prevent multiple instances of the FSAssets service causing problems. Protect against secondary instances registering duplicate console commands Also prevents multiple instances each starting a writer thread which will cause major file access exceptions as they fight over the contents of the spool directory.

Signed-off-by: Melanie Thielker <melanie@t-data.com>
0.8.2-post-fixes
AliciaRaven 2015-07-13 12:21:10 +01:00 committed by Melanie Thielker
parent e174dc87fb
commit 248c0e18de
1 changed files with 46 additions and 33 deletions

View File

@ -76,6 +76,9 @@ namespace OpenSim.Services.FSAssetService
protected int m_missingAssetsFS = 0; protected int m_missingAssetsFS = 0;
protected string m_FSBase; protected string m_FSBase;
private static bool m_Initialized;
private bool m_MainInstance;
public FSAssetConnector(IConfigSource config) public FSAssetConnector(IConfigSource config)
: this(config, "AssetService") : this(config, "AssetService")
{ {
@ -83,24 +86,30 @@ namespace OpenSim.Services.FSAssetService
public FSAssetConnector(IConfigSource config, string configName) : base(config) public FSAssetConnector(IConfigSource config, string configName) : base(config)
{ {
MainConsole.Instance.Commands.AddCommand("fs", false, if (!m_Initialized)
"show assets", "show assets", "Show asset stats", {
HandleShowAssets); m_Initialized = true;
MainConsole.Instance.Commands.AddCommand("fs", false, m_MainInstance = true;
"show digest", "show digest <ID>", "Show asset digest",
HandleShowDigest); MainConsole.Instance.Commands.AddCommand("fs", false,
MainConsole.Instance.Commands.AddCommand("fs", false, "show assets", "show assets", "Show asset stats",
"delete asset", "delete asset <ID>", HandleShowAssets);
"Delete asset from database", MainConsole.Instance.Commands.AddCommand("fs", false,
HandleDeleteAsset); "show digest", "show digest <ID>", "Show asset digest",
MainConsole.Instance.Commands.AddCommand("fs", false, HandleShowDigest);
"import", "import <conn> <table> [<start> <count>]", MainConsole.Instance.Commands.AddCommand("fs", false,
"Import legacy assets", "delete asset", "delete asset <ID>",
HandleImportAssets); "Delete asset from database",
MainConsole.Instance.Commands.AddCommand("fs", false, HandleDeleteAsset);
"force import", "force import <conn> <table> [<start> <count>]", MainConsole.Instance.Commands.AddCommand("fs", false,
"Import legacy assets, overwriting current content", "import", "import <conn> <table> [<start> <count>]",
HandleImportAssets); "Import legacy assets",
HandleImportAssets);
MainConsole.Instance.Commands.AddCommand("fs", false,
"force import", "force import <conn> <table> [<start> <count>]",
"Import legacy assets, overwriting current content",
HandleImportAssets);
}
IConfig assetConfig = config.Configs[configName]; IConfig assetConfig = config.Configs[configName];
@ -173,24 +182,28 @@ namespace OpenSim.Services.FSAssetService
throw new Exception("Configuration error"); throw new Exception("Configuration error");
} }
string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty); if (m_MainInstance)
if (loader != string.Empty)
{ {
m_AssetLoader = LoadPlugin<IAssetLoader>(loader); string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty);
string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty); if (loader != string.Empty)
m_log.InfoFormat("[FSASSETS]: Loading default asset set from {0}", loaderArgs); {
m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs, m_AssetLoader = LoadPlugin<IAssetLoader>(loader);
delegate(AssetBase a) string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty);
{ m_log.InfoFormat("[FSASSETS]: Loading default asset set from {0}", loaderArgs);
Store(a, false); m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
}); delegate(AssetBase a)
} {
m_log.Info("[FSASSETS]: FS asset service enabled"); Store(a, false);
});
}
m_WriterThread = new Thread(Writer); m_WriterThread = new Thread(Writer);
m_WriterThread.Start(); m_WriterThread.Start();
m_StatsThread = new Thread(Stats); m_StatsThread = new Thread(Stats);
m_StatsThread.Start(); m_StatsThread.Start();
}
m_log.Info("[FSASSETS]: FS asset service enabled");
} }
private void Stats() private void Stats()