From 16f8f19a541ab2b32751dbc4307efe419443988a Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 8 Feb 2008 23:42:19 +0000 Subject: * Stop asset transactions hanging around after they've completed * Still not enough to solve the memory leak, though hopefully this is another step on the path * All these changes are pretty temporary - this will be addressed with a more fundamental refactor in the future --- .../Cache/AssetTransactionManager.cs | 20 ++++++- .../Communications/Cache/AssetTransactions.cs | 70 +++++++++++++++++++--- 2 files changed, 79 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs index c9c9541..b458b18 100644 --- a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs +++ b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs @@ -25,13 +25,19 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ + +using System; using System.Collections.Generic; + using libsecondlife; namespace OpenSim.Framework.Communications.Cache { public class AssetTransactionManager { + private static readonly log4net.ILog m_log + = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + // Fields public CommunicationsManager CommsManager; @@ -92,7 +98,17 @@ namespace OpenSim.Framework.Communications.Cache AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction); if (uploader != null) { - uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); + // Upload has already compelted uploading... + if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile)) + { + lock (transactions.XferUploaders) + { + // XXX Weak ass way of doing this by directly manipulating this public dictionary, purely temporary + transactions.XferUploaders.Remove(uploader.TransactionID); + + m_log.Info(String.Format("[ASSET TRANSACTIONS] Current uploaders: {0}", transactions.XferUploaders.Count)); + } + } } } } @@ -106,4 +122,4 @@ namespace OpenSim.Framework.Communications.Cache } } } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs index 4a75f52..c54dd7d 100644 --- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs +++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs @@ -37,6 +37,9 @@ namespace OpenSim.Framework.Communications.Cache { public class AgentAssetTransactions { + private static readonly log4net.ILog m_log + = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + // Fields public List CapsUploaders = new List(); public List NotecardUpdaters = new List(); @@ -73,7 +76,11 @@ namespace OpenSim.Framework.Communications.Cache { AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile); - XferUploaders.Add(transactionID, uploader); + lock (XferUploaders) + { + XferUploaders.Add(transactionID, uploader); + } + return uploader; } return null; @@ -81,13 +88,35 @@ namespace OpenSim.Framework.Communications.Cache public void HandleXfer(ulong xferID, uint packetID, byte[] data) { - foreach (AssetXferUploader uploader in XferUploaders.Values) + AssetXferUploader uploaderFound = null; + + lock (XferUploaders) { - if (uploader.XferID == xferID) + foreach (AssetXferUploader uploader in XferUploaders.Values) { - uploader.HandleXferPacket(xferID, packetID, data); - break; + if (uploader.XferID == xferID) + { + if (uploader.HandleXferPacket(xferID, packetID, data)) + { + uploaderFound = uploader; + } + + break; + } } + + // Remove the uploader once the uploader is complete + if (uploaderFound != null) + { + m_log.Info( + String.Format( + "[ASSET TRANSACTIONS] Removing asset xfer uploader with transfer id {0}, transaction {1}", + xferID, uploaderFound.TransactionID)); + + XferUploaders.Remove(uploaderFound.TransactionID); + + m_log.Info(String.Format("[ASSET TRANSACTIONS] Current uploaders: {0}", XferUploaders.Count)); + } } } @@ -114,7 +143,11 @@ namespace OpenSim.Framework.Communications.Cache { AssetXferUploader uploader = XferUploaders[transactionID]; AssetBase asset = uploader.GetAssetData(); - XferUploaders.Remove(transactionID); + + lock (XferUploaders) + { + XferUploaders.Remove(transactionID); + } return asset; } @@ -150,8 +183,14 @@ namespace OpenSim.Framework.Communications.Cache m_dumpAssetToFile = dumpAssetToFile; } - // Methods - public void HandleXferPacket(ulong xferID, uint packetID, byte[] data) + /// + /// Process transfer data received from the client. + /// + /// + /// + /// + /// True if the transfer is complete, false otherwise or if the xferID was not valid + public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) { if (XferID == xferID) { @@ -175,11 +214,21 @@ namespace OpenSim.Framework.Communications.Cache if ((packetID & 0x80000000) != 0) { SendCompleteMessage(); + return true; } } + + return false; } - public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, + /// + /// Initialise asset transfer from the client + /// + /// + /// + /// + /// True if the transfer is complete, false otherwise + public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, bool storeLocal, bool tempFile) { ourClient = remoteClient; @@ -198,11 +247,14 @@ namespace OpenSim.Framework.Communications.Cache if (Asset.Data.Length > 2) { SendCompleteMessage(); + return true; } else { ReqestStartXfer(); } + + return false; } protected void ReqestStartXfer() -- cgit v1.1