change Async object delete to inventory threading model
parent
e76006aff5
commit
71b5ca95e6
|
@ -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>
|
||||||
|
@ -77,12 +74,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public void DeleteToInventory(DeRezAction action, UUID folderID,
|
public void DeleteToInventory(DeRezAction action, UUID folderID,
|
||||||
List<SceneObjectGroup> objectGroups, IClientAPI remoteClient,
|
List<SceneObjectGroup> objectGroups, IClientAPI remoteClient,
|
||||||
bool permissionToDelete)
|
bool permissionToDelete)
|
||||||
{
|
|
||||||
if (Enabled)
|
|
||||||
lock (m_inventoryTicker)
|
|
||||||
m_inventoryTicker.Stop();
|
|
||||||
|
|
||||||
lock (m_inventoryDeletes)
|
|
||||||
{
|
{
|
||||||
DeleteToInventoryHolder dtis = new DeleteToInventoryHolder();
|
DeleteToInventoryHolder dtis = new DeleteToInventoryHolder();
|
||||||
dtis.action = action;
|
dtis.action = action;
|
||||||
|
@ -92,7 +83,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
dtis.permissionToDelete = permissionToDelete;
|
dtis.permissionToDelete = permissionToDelete;
|
||||||
|
|
||||||
m_inventoryDeletes.Enqueue(dtis);
|
m_inventoryDeletes.Enqueue(dtis);
|
||||||
}
|
|
||||||
|
|
||||||
if (permissionToDelete)
|
if (permissionToDelete)
|
||||||
{
|
{
|
||||||
|
@ -100,23 +90,22 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
g.DeleteGroupFromScene(false);
|
g.DeleteGroupFromScene(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Monitor.TryEnter(m_threadLock))
|
||||||
|
{
|
||||||
|
if(!m_running)
|
||||||
|
{
|
||||||
if(Enabled)
|
if(Enabled)
|
||||||
lock (m_inventoryTicker)
|
{
|
||||||
m_inventoryTicker.Start();
|
m_running = true;
|
||||||
|
Util.FireAndForget(x => InventoryDeQueueAndDelete());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
private void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
{
|
||||||
// m_log.Debug("[ASYNC DELETER]: Starting send to inventory loop");
|
m_running = true;
|
||||||
|
InventoryDeQueueAndDelete();
|
||||||
// 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.
|
Monitor.Exit(m_threadLock);
|
||||||
Culture.SetCurrentCulture();
|
|
||||||
|
|
||||||
while (InventoryDeQueueAndDelete())
|
|
||||||
{
|
|
||||||
//m_log.Debug("[ASYNC DELETER]: Sent item successfully to inventory, continuing...");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
{
|
||||||
|
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
|
||||||
|
if (invAccess == null)
|
||||||
|
return;
|
||||||
|
|
||||||
try
|
int count = 0;
|
||||||
|
while (m_inventoryDeletes.TryDequeue(out DeleteToInventoryHolder x))
|
||||||
{
|
{
|
||||||
lock (m_inventoryDeletes)
|
|
||||||
{
|
|
||||||
int left = m_inventoryDeletes.Count;
|
|
||||||
if (left > 0)
|
|
||||||
{
|
|
||||||
x = m_inventoryDeletes.Dequeue();
|
|
||||||
|
|
||||||
// m_log.DebugFormat(
|
// m_log.DebugFormat(
|
||||||
// "[ASYNC DELETER]: Sending object to user's inventory, action {1}, count {2}, {0} item(s) remaining.",
|
// "[ASYNC DELETER]: Sending object to user's inventory, action {1}, count {2}, {0} item(s) remaining.",
|
||||||
// left, x.action, x.objectGroups.Count);
|
// left, x.action, x.objectGroups.Count);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
|
|
||||||
if (invAccess != null)
|
|
||||||
invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient, false);
|
invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient, false);
|
||||||
|
|
||||||
if (x.permissionToDelete)
|
if (x.permissionToDelete)
|
||||||
{
|
{
|
||||||
foreach (SceneObjectGroup g in x.objectGroups)
|
foreach (SceneObjectGroup g in x.objectGroups)
|
||||||
m_scene.DeleteSceneObject(g, true);
|
m_scene.DeleteSceneObject(g, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count += x.objectGroups.Count;
|
||||||
|
if(count > 256)
|
||||||
|
{
|
||||||
|
Thread.Sleep(50); // throttle
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
m_log.ErrorFormat(
|
m_log.ErrorFormat(
|
||||||
"[ASYNC DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace);
|
"[ASYNC OBJECT DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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.");
|
// m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue.");
|
||||||
|
m_running = false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue