change Async object delete to inventory threading model

master
UbitUmarov 2020-03-01 16:16:09 +00:00
parent e76006aff5
commit 71b5ca95e6
1 changed files with 58 additions and 84 deletions

View File

@ -27,8 +27,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Reflection; using System.Reflection;
using System.Timers; using System.Threading;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
@ -51,24 +52,20 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
public class AsyncSceneObjectGroupDeleter public class AsyncSceneObjectGroupDeleter
{ {
private static readonly ILog m_log private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <value> /// <value>
/// Is the deleter currently enabled? /// Is the deleter currently enabled?
/// </value> /// </value>
public bool Enabled; public bool Enabled;
private Timer m_inventoryTicker = new Timer(2000);
private readonly Queue<DeleteToInventoryHolder> m_inventoryDeletes = new Queue<DeleteToInventoryHolder>();
private Scene m_scene; private Scene m_scene;
static private ConcurrentQueue<DeleteToInventoryHolder> m_inventoryDeletes = new ConcurrentQueue<DeleteToInventoryHolder>();
static private object m_threadLock = new object();
static private bool m_running;
public AsyncSceneObjectGroupDeleter(Scene scene) public AsyncSceneObjectGroupDeleter(Scene scene)
{ {
m_scene = scene; m_scene = scene;
m_inventoryTicker.AutoReset = false;
m_inventoryTicker.Elapsed += InventoryRunDeleteTimer;
} }
/// <summary> /// <summary>
@ -78,21 +75,14 @@ namespace OpenSim.Region.Framework.Scenes
List<SceneObjectGroup> objectGroups, IClientAPI remoteClient, List<SceneObjectGroup> objectGroups, IClientAPI remoteClient,
bool permissionToDelete) bool permissionToDelete)
{ {
if (Enabled) DeleteToInventoryHolder dtis = new DeleteToInventoryHolder();
lock (m_inventoryTicker) dtis.action = action;
m_inventoryTicker.Stop(); dtis.folderID = folderID;
dtis.objectGroups = objectGroups;
dtis.remoteClient = remoteClient;
dtis.permissionToDelete = permissionToDelete;
lock (m_inventoryDeletes) m_inventoryDeletes.Enqueue(dtis);
{
DeleteToInventoryHolder dtis = new DeleteToInventoryHolder();
dtis.action = action;
dtis.folderID = folderID;
dtis.objectGroups = objectGroups;
dtis.remoteClient = remoteClient;
dtis.permissionToDelete = permissionToDelete;
m_inventoryDeletes.Enqueue(dtis);
}
if (permissionToDelete) if (permissionToDelete)
{ {
@ -100,23 +90,22 @@ namespace OpenSim.Region.Framework.Scenes
g.DeleteGroupFromScene(false); g.DeleteGroupFromScene(false);
} }
if (Enabled) if(Monitor.TryEnter(m_threadLock))
lock (m_inventoryTicker)
m_inventoryTicker.Start();
}
private void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e)
{
// m_log.Debug("[ASYNC DELETER]: Starting send to inventory loop");
// We must set appearance parameters in the en_US culture in order to avoid issues where values are saved
// in a culture where decimal points are commas and then reloaded in a culture which just treats them as
// number seperators.
Culture.SetCurrentCulture();
while (InventoryDeQueueAndDelete())
{ {
//m_log.Debug("[ASYNC DELETER]: Sent item successfully to inventory, continuing..."); if(!m_running)
{
if(Enabled)
{
m_running = true;
Util.FireAndForget(x => InventoryDeQueueAndDelete());
}
else
{
m_running = true;
InventoryDeQueueAndDelete();
}
}
Monitor.Exit(m_threadLock);
} }
} }
@ -124,60 +113,45 @@ namespace OpenSim.Region.Framework.Scenes
/// Move the next object in the queue to inventory. Then delete it properly from the scene. /// Move the next object in the queue to inventory. Then delete it properly from the scene.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool InventoryDeQueueAndDelete() public void InventoryDeQueueAndDelete()
{ {
DeleteToInventoryHolder x = null; lock (m_threadLock)
try
{ {
lock (m_inventoryDeletes) IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
if (invAccess == null)
return;
int count = 0;
while (m_inventoryDeletes.TryDequeue(out DeleteToInventoryHolder x))
{ {
int left = m_inventoryDeletes.Count; // m_log.DebugFormat(
if (left > 0) // "[ASYNC DELETER]: Sending object to user's inventory, action {1}, count {2}, {0} item(s) remaining.",
// left, x.action, x.objectGroups.Count);
try
{ {
x = m_inventoryDeletes.Dequeue(); invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient, false);
if (x.permissionToDelete)
// m_log.DebugFormat(
// "[ASYNC DELETER]: Sending object to user's inventory, action {1}, count {2}, {0} item(s) remaining.",
// left, x.action, x.objectGroups.Count);
try
{ {
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>(); foreach (SceneObjectGroup g in x.objectGroups)
if (invAccess != null) m_scene.DeleteSceneObject(g, true);
invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient, false);
if (x.permissionToDelete)
{
foreach (SceneObjectGroup g in x.objectGroups)
m_scene.DeleteSceneObject(g, true);
}
}
catch (Exception e)
{
m_log.ErrorFormat(
"[ASYNC DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace);
} }
return true; count += x.objectGroups.Count;
if(count > 256)
{
Thread.Sleep(50); // throttle
count = 0;
}
}
catch (Exception e)
{
m_log.ErrorFormat(
"[ASYNC OBJECT DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace);
} }
} }
// m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue.");
m_running = false;
} }
catch (Exception e)
{
// We can't put the object group details in here since the root part may have disappeared (which is where these sit).
// FIXME: This needs to be fixed.
m_log.ErrorFormat(
"[ASYNC DELETER]: Queued sending of scene object to agent {0} {1} failed: {2} {3}",
(x != null ? x.remoteClient.Name : "unavailable"),
(x != null ? x.remoteClient.AgentId.ToString() : "unavailable"),
e.Message,
e.StackTrace);
}
// m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue.");
return false;
} }
} }
} }