From 7ca61e01742b53033009f10c45e3ea0d0ef91315 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 4 Sep 2009 21:10:56 +0100 Subject: Add ids to iar requests Stop save iar test wrongly relying on thread pulsing (still disabled though) --- .../Archiver/InventoryArchiveWriteRequest.cs | 16 ++++++--- .../Inventory/Archiver/InventoryArchiverModule.cs | 41 ++++++++++++++++------ .../Archiver/Tests/InventoryArchiverTests.cs | 19 +++++----- .../Interfaces/IInventoryArchiverModule.cs | 8 +++-- 4 files changed, 56 insertions(+), 28 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 12c9dcf..18728c6 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -60,6 +60,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver protected UuidGatherer m_assetGatherer; /// + /// ID of this request + /// + protected Guid m_id; + + /// /// Used to collect the uuids of the assets that we need to save into the archive /// protected Dictionary m_assetUuids = new Dictionary(); @@ -78,8 +83,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// Constructor /// public InventoryArchiveWriteRequest( - InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath) + Guid id, InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath) : this( + id, module, userInfo, invPath, @@ -91,8 +97,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// Constructor /// public InventoryArchiveWriteRequest( - InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream) + Guid id, InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream) { + m_id = id; m_module = module; m_userInfo = userInfo; m_invPath = invPath; @@ -116,7 +123,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver succeeded = false; } - m_module.TriggerInventoryArchiveSaved(succeeded, m_userInfo, m_invPath, m_saveStream, reportedException); + m_module.TriggerInventoryArchiveSaved( + m_id, succeeded, m_userInfo, m_invPath, m_saveStream, reportedException); } protected void SaveInvItem(InventoryItemBase inventoryItem, string path) @@ -272,7 +280,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver // We couldn't find the path indicated m_saveStream.Close(); m_module.TriggerInventoryArchiveSaved( - false, m_userInfo, m_invPath, m_saveStream, + m_id, false, m_userInfo, m_invPath, m_saveStream, new Exception(string.Format("Could not find inventory entry at path {0}", m_invPath))); return; } diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index c495e02..55d7997 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs @@ -57,7 +57,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// /// The file to load and save inventory if no filename has been specified /// - protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz"; + protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz"; + + /// + /// Pending save completions initiated from the console + /// + protected List m_pendingConsoleSaves = new List(); /// /// All scenes that this module knows about @@ -106,32 +111,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// Trigger the inventory archive saved event. /// protected internal void TriggerInventoryArchiveSaved( - bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException) + Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, + Exception reportedException) { InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved; if (handlerInventoryArchiveSaved != null) - handlerInventoryArchiveSaved(succeeded, userInfo, invPath, saveStream, reportedException); + handlerInventoryArchiveSaved(id, succeeded, userInfo, invPath, saveStream, reportedException); } - public void ArchiveInventory(string firstName, string lastName, string invPath, Stream saveStream) + public void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream) { if (m_scenes.Count > 0) { CachedUserInfo userInfo = GetUserInfo(firstName, lastName); if (userInfo != null) - new InventoryArchiveWriteRequest(this, userInfo, invPath, saveStream).Execute(); + new InventoryArchiveWriteRequest(id, this, userInfo, invPath, saveStream).Execute(); } } - public void ArchiveInventory(string firstName, string lastName, string invPath, string savePath) + public void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, string savePath) { if (m_scenes.Count > 0) { CachedUserInfo userInfo = GetUserInfo(firstName, lastName); if (userInfo != null) - new InventoryArchiveWriteRequest(this, userInfo, invPath, savePath).Execute(); + new InventoryArchiveWriteRequest(id, this, userInfo, invPath, savePath).Execute(); } } @@ -215,13 +221,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver m_log.InfoFormat( "[INVENTORY ARCHIVER]: Saving archive {0} from inventory path {1} for {2} {3}", savePath, invPath, firstName, lastName); - - ArchiveInventory(firstName, lastName, invPath, savePath); - } + + Guid id = Guid.NewGuid(); + ArchiveInventory(id, firstName, lastName, invPath, savePath); + + lock (m_pendingConsoleSaves) + m_pendingConsoleSaves.Add(id); + } private void SaveInvConsoleCommandCompleted( - bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException) + Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, + Exception reportedException) { + lock (m_pendingConsoleSaves) + { + if (m_pendingConsoleSaves.Contains(id)) + m_pendingConsoleSaves.Remove(id); + else + return; + } + if (succeeded) { m_log.InfoFormat("[INVENTORY ARCHIVER]: Saved archive for {0}", userInfo.UserProfile.Name); diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 066c5d3..a151c9d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -55,6 +55,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests [TestFixture] public class InventoryArchiverTests { + protected ManualResetEvent mre = new ManualResetEvent(false); + private void InventoryReceived(UUID userId) { lock (this) @@ -64,12 +66,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests } private void SaveCompleted( - bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException) + Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, + Exception reportedException) { - lock (this) - { - Monitor.PulseAll(this); - } + mre.Set(); } /// @@ -152,11 +152,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests MemoryStream archiveWriteStream = new MemoryStream(); archiverModule.OnInventoryArchiveSaved += SaveCompleted; - lock (this) - { - archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream); - Monitor.Wait(this, 60000); - } + mre.Reset(); + archiverModule.ArchiveInventory( + Guid.NewGuid(), userFirstName, userLastName, "Objects", archiveWriteStream); + mre.WaitOne(); byte[] archive = archiveWriteStream.ToArray(); MemoryStream archiveReadStream = new MemoryStream(archive); diff --git a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs index df6650f..457b5b8 100644 --- a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs @@ -34,13 +34,14 @@ namespace OpenSim.Region.Framework.Interfaces /// /// Used for the OnInventoryArchiveSaved event. /// + /// Request id /// true if the save succeeded, false otherwise /// The user for whom the save was conducted /// The inventory path saved /// The stream to which the archive was saved /// Contains the exception generated if the save did not succeed public delegate void InventoryArchiveSaved( - bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException); + Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException); public interface IInventoryArchiverModule { @@ -61,10 +62,11 @@ namespace OpenSim.Region.Framework.Interfaces /// /// Archive a user's inventory folder to the given stream /// + /// ID representing this request. This will later be returned in the save event /// /// /// The inventory path from which the inventory should be saved. - /// The stream to which the inventory archive will be saved - void ArchiveInventory(string firstName, string lastName, string invPath, Stream saveStream); + /// The stream to which the inventory archive will be saved + void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream); } } -- cgit v1.1