remove diva's inventory cache since it seems to cause mantis 7720, broken items UUID. Guess it doesn't cover all paths

avinationmerge
UbitUmarov 2015-09-11 04:46:15 +01:00
parent 2bd8fb6b5a
commit 6a0465b70a
2 changed files with 87 additions and 240 deletions

View File

@ -898,33 +898,33 @@ namespace OpenSim.Region.Framework.Scenes
} }
if (remoteClient.AgentId == oldAgentID if (remoteClient.AgentId == oldAgentID
|| (LibraryService != null || (LibraryService != null
&& LibraryService.LibraryRootFolder != null && LibraryService.LibraryRootFolder != null
&& oldAgentID == LibraryService.LibraryRootFolder.Owner)) && oldAgentID == LibraryService.LibraryRootFolder.Owner))
{
CreateNewInventoryItem(
remoteClient, item.CreatorId, item.CreatorData, newFolderID,
newName, item.Description, item.Flags, callbackID, item.AssetID, (sbyte)item.AssetType, (sbyte)item.InvType,
item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions,
item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch(), false);
}
else
{
// If item is transfer or permissions are off or calling agent is allowed to copy item owner's inventory item.
if (((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0)
&& (m_permissions.BypassPermissions()
|| m_permissions.CanCopyUserInventory(remoteClient.AgentId, oldItemID)))
{ {
CreateNewInventoryItem( CreateNewInventoryItem(
remoteClient, item.CreatorId, item.CreatorData, newFolderID, newName, item.Description, item.Flags, callbackID, remoteClient, item.CreatorId, item.CreatorData, newFolderID,
item.AssetID, (sbyte)item.AssetType, (sbyte) item.InvType, newName, item.Description, item.Flags, callbackID, item.AssetID, (sbyte)item.AssetType, (sbyte)item.InvType,
item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions,
item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch(), false); item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch(), false);
} }
else
{
// If item is transfer or permissions are off or calling agent is allowed to copy item owner's inventory item.
if (((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0)
&& (m_permissions.BypassPermissions()
|| m_permissions.CanCopyUserInventory(remoteClient.AgentId, oldItemID)))
{
CreateNewInventoryItem(
remoteClient, item.CreatorId, item.CreatorData, newFolderID, newName, item.Description, item.Flags, callbackID,
item.AssetID, (sbyte)item.AssetType, (sbyte)item.InvType,
item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions,
item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch(), false);
}
}
} }
} else
else
{ {
m_log.ErrorFormat( m_log.ErrorFormat(
"[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found", "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",

View File

@ -33,37 +33,22 @@ using System.Reflection;
using Nini.Config; using Nini.Config;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Monitoring;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
using OpenSim.Server.Base; using OpenSim.Server.Base;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Services.Connectors namespace OpenSim.Services.Connectors
{ {
public class XInventoryServicesConnector : BaseServiceConnector, IInventoryService public class XInventoryServicesConnector : IInventoryService
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger( LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType); MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Number of requests made to the remote inventory service.
/// </summary>
public int RequestsMade { get; private set; }
private string m_ServerURI = String.Empty; private string m_ServerURI = String.Empty;
/// <summary> private object m_Lock = new object();
/// Timeout for remote requests.
/// </summary>
/// <remarks>
/// In this case, -1 is default timeout (100 seconds), not infinite.
/// </remarks>
private int m_requestTimeoutSecs = -1;
private const double CACHE_EXPIRATION_SECONDS = 20.0;
private static ExpiringCache<UUID, InventoryItemBase> m_ItemCache = new ExpiringCache<UUID,InventoryItemBase>();
public XInventoryServicesConnector() public XInventoryServicesConnector()
{ {
@ -75,21 +60,20 @@ namespace OpenSim.Services.Connectors
} }
public XInventoryServicesConnector(IConfigSource source) public XInventoryServicesConnector(IConfigSource source)
: base(source, "InventoryService")
{ {
Initialise(source); Initialise(source);
} }
public virtual void Initialise(IConfigSource source) public virtual void Initialise(IConfigSource source)
{ {
IConfig config = source.Configs["InventoryService"]; IConfig assetConfig = source.Configs["InventoryService"];
if (config == null) if (assetConfig == null)
{ {
m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
throw new Exception("Inventory connector init error"); throw new Exception("Inventory connector init error");
} }
string serviceURI = config.GetString("InventoryServerURI", string serviceURI = assetConfig.GetString("InventoryServerURI",
String.Empty); String.Empty);
if (serviceURI == String.Empty) if (serviceURI == String.Empty)
@ -98,21 +82,6 @@ namespace OpenSim.Services.Connectors
throw new Exception("Inventory connector init error"); throw new Exception("Inventory connector init error");
} }
m_ServerURI = serviceURI; m_ServerURI = serviceURI;
m_requestTimeoutSecs = config.GetInt("RemoteRequestTimeout", m_requestTimeoutSecs);
StatsManager.RegisterStat(
new Stat(
"RequestsMade",
"Requests made",
"Number of requests made to the remove inventory service",
"requests",
"inventory",
serviceURI,
StatType.Pull,
MeasuresOfInterest.AverageChangeOverTime,
s => s.Value = RequestsMade,
StatVerbosity.Debug));
} }
private bool CheckReturn(Dictionary<string, object> ret) private bool CheckReturn(Dictionary<string, object> ret)
@ -189,7 +158,7 @@ namespace OpenSim.Services.Connectors
return BuildFolder((Dictionary<string, object>)ret["folder"]); return BuildFolder((Dictionary<string, object>)ret["folder"]);
} }
public InventoryFolderBase GetFolderForType(UUID principalID, FolderType type) public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
{ {
Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE", Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE",
new Dictionary<string,object> { new Dictionary<string,object> {
@ -208,7 +177,7 @@ namespace OpenSim.Services.Connectors
InventoryCollection inventory = new InventoryCollection(); InventoryCollection inventory = new InventoryCollection();
inventory.Folders = new List<InventoryFolderBase>(); inventory.Folders = new List<InventoryFolderBase>();
inventory.Items = new List<InventoryItemBase>(); inventory.Items = new List<InventoryItemBase>();
inventory.OwnerID = principalID; inventory.UserID = principalID;
try try
{ {
@ -221,17 +190,15 @@ namespace OpenSim.Services.Connectors
if (!CheckReturn(ret)) if (!CheckReturn(ret))
return null; return null;
Dictionary<string,object> folders = ret.ContainsKey("FOLDERS") ? Dictionary<string,object> folders =
(Dictionary<string,object>)ret["FOLDERS"] : null; (Dictionary<string,object>)ret["FOLDERS"];
Dictionary<string,object> items = ret.ContainsKey("ITEMS") ? Dictionary<string,object> items =
(Dictionary<string, object>)ret["ITEMS"] : null; (Dictionary<string,object>)ret["ITEMS"];
if (folders != null) foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
if (items != null) inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
} }
catch (Exception e) catch (Exception e)
{ {
@ -241,87 +208,6 @@ namespace OpenSim.Services.Connectors
return inventory; return inventory;
} }
public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
{
InventoryCollection[] inventoryArr = new InventoryCollection[folderIDs.Length];
// m_log.DebugFormat("[XXX]: In GetMultipleFoldersContent {0}", String.Join(",", folderIDs));
try
{
Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEFOLDERSCONTENT",
new Dictionary<string, object> {
{ "PRINCIPAL", principalID.ToString() },
{ "FOLDERS", String.Join(",", folderIDs) },
{ "COUNT", folderIDs.Length.ToString() }
});
if (!CheckReturn(resultSet))
return null;
int i = 0;
foreach (KeyValuePair<string, object> kvp in resultSet)
{
InventoryCollection inventory = new InventoryCollection();
if (kvp.Key.StartsWith("F_"))
{
UUID fid = UUID.Zero;
if (UUID.TryParse(kvp.Key.Substring(2), out fid) && fid == folderIDs[i])
{
inventory.Folders = new List<InventoryFolderBase>();
inventory.Items = new List<InventoryItemBase>();
Dictionary<string, object> ret = (Dictionary<string, object>)kvp.Value;
if (ret.ContainsKey("FID"))
{
if (!UUID.TryParse(ret["FID"].ToString(), out inventory.FolderID))
m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Could not parse folder id {0}", ret["FID"].ToString());
}
else
m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: FID key not present in response");
inventory.Version = -1;
if (ret.ContainsKey("VERSION"))
Int32.TryParse(ret["VERSION"].ToString(), out inventory.Version);
if (ret.ContainsKey("OWNER"))
UUID.TryParse(ret["OWNER"].ToString(), out inventory.OwnerID);
//m_log.DebugFormat("[XXX]: Received {0} ({1}) {2} {3}", inventory.FolderID, fid, inventory.Version, inventory.OwnerID);
Dictionary<string, object> folders =
(Dictionary<string, object>)ret["FOLDERS"];
Dictionary<string, object> items =
(Dictionary<string, object>)ret["ITEMS"];
foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
{
inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
}
foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
{
inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
}
inventoryArr[i] = inventory;
}
else
{
m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Folder id does not match. Expected {0} got {1}",
folderIDs[i], fid);
m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: {0} {1}", String.Join(",", folderIDs), String.Join(",", resultSet.Keys));
}
i += 1;
}
}
}
catch (Exception e)
{
m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleFoldersContent: {0}", e.Message);
}
return inventoryArr;
}
public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
{ {
Dictionary<string,object> ret = MakeRequest("GETFOLDERITEMS", Dictionary<string,object> ret = MakeRequest("GETFOLDERITEMS",
@ -411,13 +297,9 @@ namespace OpenSim.Services.Connectors
public bool AddItem(InventoryItemBase item) public bool AddItem(InventoryItemBase item)
{ {
if (item.Description == null)
item.Description = String.Empty;
if (item.CreatorData == null) if (item.CreatorData == null)
item.CreatorData = String.Empty; item.CreatorData = String.Empty;
if (item.CreatorId == null) Dictionary<string,object> ret = MakeRequest("ADDITEM",
item.CreatorId = String.Empty;
Dictionary<string, object> ret = MakeRequest("ADDITEM",
new Dictionary<string,object> { new Dictionary<string,object> {
{ "AssetID", item.AssetID.ToString() }, { "AssetID", item.AssetID.ToString() },
{ "AssetType", item.AssetType.ToString() }, { "AssetType", item.AssetType.ToString() },
@ -516,10 +398,6 @@ namespace OpenSim.Services.Connectors
public InventoryItemBase GetItem(InventoryItemBase item) public InventoryItemBase GetItem(InventoryItemBase item)
{ {
InventoryItemBase retrieved = null;
if (m_ItemCache.TryGetValue(item.ID, out retrieved))
return retrieved;
try try
{ {
Dictionary<string, object> ret = MakeRequest("GETITEM", Dictionary<string, object> ret = MakeRequest("GETITEM",
@ -530,78 +408,14 @@ namespace OpenSim.Services.Connectors
if (!CheckReturn(ret)) if (!CheckReturn(ret))
return null; return null;
retrieved = BuildItem((Dictionary<string, object>)ret["item"]); return BuildItem((Dictionary<string, object>)ret["item"]);
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e);
} }
m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS); return null;
return retrieved;
}
public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
{
//m_log.DebugFormat("[XXX]: In GetMultipleItems {0}", String.Join(",", itemIDs));
InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length];
// Try to get them from the cache
List<UUID> pending = new List<UUID>();
InventoryItemBase item = null;
int i = 0;
foreach (UUID id in itemIDs)
{
if (m_ItemCache.TryGetValue(id, out item))
itemArr[i++] = item;
else
pending.Add(id);
}
if (pending.Count == 0) // we're done, everything was in the cache
return itemArr;
try
{
Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS",
new Dictionary<string, object> {
{ "PRINCIPAL", principalID.ToString() },
{ "ITEMS", String.Join(",", pending.ToArray()) },
{ "COUNT", pending.Count.ToString() }
});
if (!CheckReturn(resultSet))
{
if (i == 0)
return null;
else
return itemArr;
}
// carry over index i where we left above
foreach (KeyValuePair<string, object> kvp in resultSet)
{
InventoryCollection inventory = new InventoryCollection();
if (kvp.Key.StartsWith("item_"))
{
if (kvp.Value is Dictionary<string, object>)
{
item = BuildItem((Dictionary<string, object>)kvp.Value);
m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
itemArr[i++] = item;
}
else
itemArr[i++] = null;
}
}
}
catch (Exception e)
{
m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message);
}
return itemArr;
} }
public InventoryFolderBase GetFolder(InventoryFolderBase folder) public InventoryFolderBase GetFolder(InventoryFolderBase folder)
@ -670,6 +484,45 @@ namespace OpenSim.Services.Connectors
return 0; return 0;
} }
public InventoryCollection GetUserInventory(UUID principalID)
{
InventoryCollection inventory = new InventoryCollection();
inventory.Folders = new List<InventoryFolderBase>();
inventory.Items = new List<InventoryItemBase>();
inventory.UserID = principalID;
try
{
Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY",
new Dictionary<string, object> {
{ "PRINCIPAL", principalID.ToString() }
});
if (!CheckReturn(ret))
return null;
Dictionary<string, object> folders =
(Dictionary<string, object>)ret["FOLDERS"];
Dictionary<string, object> items =
(Dictionary<string, object>)ret["ITEMS"];
foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
}
catch (Exception e)
{
m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetUserInventory: ", e);
}
return inventory;
}
public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback)
{
}
public bool HasInventoryForUser(UUID principalID) public bool HasInventoryForUser(UUID principalID)
{ {
return false; return false;
@ -680,19 +533,13 @@ namespace OpenSim.Services.Connectors
private Dictionary<string,object> MakeRequest(string method, private Dictionary<string,object> MakeRequest(string method,
Dictionary<string,object> sendData) Dictionary<string,object> sendData)
{ {
// Add "METHOD" as the first key in the dictionary. This ensures that it will be sendData["METHOD"] = method;
// visible even when using partial logging ("debug http all 5").
Dictionary<string, object> temp = sendData;
sendData = new Dictionary<string,object>{ { "METHOD", method } };
foreach (KeyValuePair<string, object> kvp in temp)
sendData.Add(kvp.Key, kvp.Value);
RequestsMade++; string reply = string.Empty;
lock (m_Lock)
string reply reply = SynchronousRestFormsRequester.MakeRequest("POST",
= SynchronousRestFormsRequester.MakeRequest( m_ServerURI + "/xinventory",
"POST", m_ServerURI + "/xinventory", ServerUtils.BuildQueryString(sendData));
ServerUtils.BuildQueryString(sendData), m_requestTimeoutSecs, m_Auth);
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
reply); reply);