From 6a0465b70ad3ef64d6e71aab2e624bf3bfddf9b2 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 11 Sep 2015 04:46:15 +0100 Subject: remove diva's inventory cache since it seems to cause mantis 7720, broken items UUID. Guess it doesn't cover all paths --- .../Inventory/XInventoryServicesConnector.cs | 285 +++++---------------- 1 file changed, 66 insertions(+), 219 deletions(-) (limited to 'OpenSim/Services/Connectors/Inventory') diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs index f235446..36d4ae2 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs @@ -33,37 +33,22 @@ using System.Reflection; using Nini.Config; using OpenSim.Framework; using OpenSim.Framework.Console; - -using OpenSim.Framework.Monitoring; +using OpenSim.Framework.Communications; using OpenSim.Services.Interfaces; using OpenSim.Server.Base; using OpenMetaverse; namespace OpenSim.Services.Connectors { - public class XInventoryServicesConnector : BaseServiceConnector, IInventoryService + public class XInventoryServicesConnector : IInventoryService { private static readonly ILog m_log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); - /// - /// Number of requests made to the remote inventory service. - /// - public int RequestsMade { get; private set; } - private string m_ServerURI = String.Empty; - /// - /// Timeout for remote requests. - /// - /// - /// In this case, -1 is default timeout (100 seconds), not infinite. - /// - private int m_requestTimeoutSecs = -1; - - private const double CACHE_EXPIRATION_SECONDS = 20.0; - private static ExpiringCache m_ItemCache = new ExpiringCache(); + private object m_Lock = new object(); public XInventoryServicesConnector() { @@ -75,21 +60,20 @@ namespace OpenSim.Services.Connectors } public XInventoryServicesConnector(IConfigSource source) - : base(source, "InventoryService") { Initialise(source); } public virtual void Initialise(IConfigSource source) { - IConfig config = source.Configs["InventoryService"]; - if (config == null) + IConfig assetConfig = source.Configs["InventoryService"]; + if (assetConfig == null) { m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); throw new Exception("Inventory connector init error"); } - string serviceURI = config.GetString("InventoryServerURI", + string serviceURI = assetConfig.GetString("InventoryServerURI", String.Empty); if (serviceURI == String.Empty) @@ -98,21 +82,6 @@ namespace OpenSim.Services.Connectors throw new Exception("Inventory connector init error"); } 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 ret) @@ -189,7 +158,7 @@ namespace OpenSim.Services.Connectors return BuildFolder((Dictionary)ret["folder"]); } - public InventoryFolderBase GetFolderForType(UUID principalID, FolderType type) + public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) { Dictionary ret = MakeRequest("GETFOLDERFORTYPE", new Dictionary { @@ -208,7 +177,7 @@ namespace OpenSim.Services.Connectors InventoryCollection inventory = new InventoryCollection(); inventory.Folders = new List(); inventory.Items = new List(); - inventory.OwnerID = principalID; + inventory.UserID = principalID; try { @@ -221,17 +190,15 @@ namespace OpenSim.Services.Connectors if (!CheckReturn(ret)) return null; - Dictionary folders = ret.ContainsKey("FOLDERS") ? - (Dictionary)ret["FOLDERS"] : null; - Dictionary items = ret.ContainsKey("ITEMS") ? - (Dictionary)ret["ITEMS"] : null; - - if (folders != null) - foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i - inventory.Folders.Add(BuildFolder((Dictionary)o)); - if (items != null) - foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i - inventory.Items.Add(BuildItem((Dictionary)o)); + Dictionary folders = + (Dictionary)ret["FOLDERS"]; + Dictionary items = + (Dictionary)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)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)o)); } catch (Exception e) { @@ -240,87 +207,6 @@ namespace OpenSim.Services.Connectors 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 resultSet = MakeRequest("GETMULTIPLEFOLDERSCONTENT", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "FOLDERS", String.Join(",", folderIDs) }, - { "COUNT", folderIDs.Length.ToString() } - }); - - if (!CheckReturn(resultSet)) - return null; - - int i = 0; - foreach (KeyValuePair 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(); - inventory.Items = new List(); - - Dictionary ret = (Dictionary)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 folders = - (Dictionary)ret["FOLDERS"]; - Dictionary items = - (Dictionary)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)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)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 GetFolderItems(UUID principalID, UUID folderID) { @@ -411,13 +297,9 @@ namespace OpenSim.Services.Connectors public bool AddItem(InventoryItemBase item) { - if (item.Description == null) - item.Description = String.Empty; if (item.CreatorData == null) item.CreatorData = String.Empty; - if (item.CreatorId == null) - item.CreatorId = String.Empty; - Dictionary ret = MakeRequest("ADDITEM", + Dictionary ret = MakeRequest("ADDITEM", new Dictionary { { "AssetID", item.AssetID.ToString() }, { "AssetType", item.AssetType.ToString() }, @@ -516,10 +398,6 @@ namespace OpenSim.Services.Connectors public InventoryItemBase GetItem(InventoryItemBase item) { - InventoryItemBase retrieved = null; - if (m_ItemCache.TryGetValue(item.ID, out retrieved)) - return retrieved; - try { Dictionary ret = MakeRequest("GETITEM", @@ -530,78 +408,14 @@ namespace OpenSim.Services.Connectors if (!CheckReturn(ret)) return null; - retrieved = BuildItem((Dictionary)ret["item"]); + return BuildItem((Dictionary)ret["item"]); } catch (Exception e) { m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); } - m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS); - - 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 pending = new List(); - 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 resultSet = MakeRequest("GETMULTIPLEITEMS", - new Dictionary { - { "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 kvp in resultSet) - { - InventoryCollection inventory = new InventoryCollection(); - if (kvp.Key.StartsWith("item_")) - { - if (kvp.Value is Dictionary) - { - item = BuildItem((Dictionary)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; + return null; } public InventoryFolderBase GetFolder(InventoryFolderBase folder) @@ -670,6 +484,45 @@ namespace OpenSim.Services.Connectors return 0; } + public InventoryCollection GetUserInventory(UUID principalID) + { + InventoryCollection inventory = new InventoryCollection(); + inventory.Folders = new List(); + inventory.Items = new List(); + inventory.UserID = principalID; + + try + { + Dictionary ret = MakeRequest("GETUSERINVENTORY", + new Dictionary { + { "PRINCIPAL", principalID.ToString() } + }); + + if (!CheckReturn(ret)) + return null; + + Dictionary folders = + (Dictionary)ret["FOLDERS"]; + Dictionary items = + (Dictionary)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)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)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) { return false; @@ -680,19 +533,13 @@ namespace OpenSim.Services.Connectors private Dictionary MakeRequest(string method, Dictionary sendData) { - // Add "METHOD" as the first key in the dictionary. This ensures that it will be - // visible even when using partial logging ("debug http all 5"). - Dictionary temp = sendData; - sendData = new Dictionary{ { "METHOD", method } }; - foreach (KeyValuePair kvp in temp) - sendData.Add(kvp.Key, kvp.Value); - - RequestsMade++; + sendData["METHOD"] = method; - string reply - = SynchronousRestFormsRequester.MakeRequest( - "POST", m_ServerURI + "/xinventory", - ServerUtils.BuildQueryString(sendData), m_requestTimeoutSecs, m_Auth); + string reply = string.Empty; + lock (m_Lock) + reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/xinventory", + ServerUtils.BuildQueryString(sendData)); Dictionary replyData = ServerUtils.ParseXmlResponse( reply); @@ -760,4 +607,4 @@ namespace OpenSim.Services.Connectors return item; } } -} +} \ No newline at end of file -- cgit v1.1