mantis 9008: add extra lock on FSassets initialization, to be sure only one thread does run main spool thread. Add config option 'SecondaryInstance' to do the same in multiple process instances cases. If there are more than one spool thread there may be file assess collisions that may cause robust crash and or loss of assets. I could not test this. Please to so, and report on mantis 9008, Thanks.

This commit is contained in:
UbitUmarov
2022-06-09 14:42:21 +01:00
parent 9aeb52e3d1
commit 470ab9199c
3 changed files with 63 additions and 42 deletions

View File

@@ -25,25 +25,21 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Threading;
using System.Reflection;
using log4net;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Data;
using OpenSim.Framework;
using OpenSim.Framework.Serialization.External;
using OpenSim.Framework.Console;
using OpenSim.Server.Base;
using OpenSim.Services.Base;
using OpenSim.Services.Interfaces;
using Nini.Config;
using log4net;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
namespace OpenSim.Services.FSAssetService
{
@@ -78,8 +74,10 @@ namespace OpenSim.Services.FSAssetService
protected bool m_useOsgridFormat = false;
protected bool m_showStats = true;
private static bool m_Initialized;
private bool m_MainInstance;
private static bool m_mainInitialized;
private static object m_initLock = new object();
private bool m_isMainInstance;
public FSAssetConnector(IConfigSource config)
: this(config, "AssetService")
@@ -88,29 +86,36 @@ namespace OpenSim.Services.FSAssetService
public FSAssetConnector(IConfigSource config, string configName) : base(config)
{
if (!m_Initialized)
lock(m_initLock)
{
m_Initialized = true;
m_MainInstance = true;
if (!m_mainInitialized)
{
m_mainInitialized = true;
m_isMainInstance = true;
MainConsole.Instance.Commands.AddCommand("fs", false,
"show assets", "show assets", "Show asset stats",
HandleShowAssets);
MainConsole.Instance.Commands.AddCommand("fs", false,
"show digest", "show digest <ID>", "Show asset digest",
HandleShowDigest);
MainConsole.Instance.Commands.AddCommand("fs", false,
"delete asset", "delete asset <ID>",
"Delete asset from database",
HandleDeleteAsset);
MainConsole.Instance.Commands.AddCommand("fs", false,
"import", "import <conn> <table> [<start> <count>]",
"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);
MainConsole.Instance.Commands.AddCommand("fs", false,
"show assets", "show assets", "Show asset stats",
HandleShowAssets);
MainConsole.Instance.Commands.AddCommand("fs", false,
"show digest", "show digest <ID>", "Show asset digest",
HandleShowDigest);
MainConsole.Instance.Commands.AddCommand("fs", false,
"delete asset", "delete asset <ID>",
"Delete asset from database",
HandleDeleteAsset);
MainConsole.Instance.Commands.AddCommand("fs", false,
"import", "import <conn> <table> [<start> <count>]",
"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);
}
else
{
m_isMainInstance = false; // yes redundant...
}
}
IConfig assetConfig = config.Configs[configName];
@@ -118,6 +123,11 @@ namespace OpenSim.Services.FSAssetService
if (assetConfig == null)
throw new Exception("No AssetService configuration");
bool secondary = assetConfig.GetBoolean("SecondaryInstance", false);
lock (m_initLock)
m_isMainInstance = !secondary;
// Get Database Connector from Asset Config (If present)
string dllName = assetConfig.GetString("StorageProvider", string.Empty);
string connectionString = assetConfig.GetString("ConnectionString", string.Empty);
@@ -156,7 +166,7 @@ namespace OpenSim.Services.FSAssetService
// Setup Fallback Service
string str = assetConfig.GetString("FallbackService", string.Empty);
if (str != string.Empty)
if (str.Length > 0)
{
object[] args = new object[] { config };
m_FallbackService = LoadPlugin<IAssetService>(str, args);
@@ -189,7 +199,7 @@ namespace OpenSim.Services.FSAssetService
// Default is to show stats to retain original behaviour
m_showStats = assetConfig.GetBoolean("ShowConsoleStats", m_showStats);
if (m_MainInstance)
if (m_isMainInstance)
{
string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty);
if (loader != string.Empty)
@@ -204,10 +214,13 @@ namespace OpenSim.Services.FSAssetService
});
}
m_WriterThread = new Thread(Writer);
m_WriterThread.Start();
if(m_WriterThread != null)
{
m_WriterThread = new Thread(Writer);
m_WriterThread.Start();
}
if (m_showStats)
if (m_showStats && m_StatsThread != null)
{
m_StatsThread = new Thread(Stats);
m_StatsThread.Start();