From f605d59136ef5a6ada9f332fb775f58adc1ec36a Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 24 Nov 2009 18:27:31 +0000 Subject: [PATCH] Make load/save iar slightly better in the face of io failures by always attempting to close the streams --- .../Archiver/InventoryArchiveReadRequest.cs | 68 ++++++++++-------- .../Archiver/InventoryArchiveWriteRequest.cs | 72 ++++++++++--------- 2 files changed, 77 insertions(+), 63 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 9e76d79313..8532d03122 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -121,45 +121,51 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver byte[] data; TarArchiveReader.TarEntryType entryType; - while ((data = archive.ReadEntry(out filePath, out entryType)) != null) + + try { - if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) + while ((data = archive.ReadEntry(out filePath, out entryType)) != null) { - if (LoadAsset(filePath, data)) - successfulAssetRestores++; - else - failedAssetRestores++; - - if ((successfulAssetRestores) % 50 == 0) - m_log.DebugFormat( - "[INVENTORY ARCHIVER]: Loaded {0} assets...", - successfulAssetRestores); - } - else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) - { - InventoryFolderBase foundFolder - = ReplicateArchivePathToUserInventory( - filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType, - rootDestinationFolder, foldersCreated, nodesLoaded); - - if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) + if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) { - InventoryItemBase item = LoadItem(data, foundFolder); - - if (item != null) + if (LoadAsset(filePath, data)) + successfulAssetRestores++; + else + failedAssetRestores++; + + if ((successfulAssetRestores) % 50 == 0) + m_log.DebugFormat( + "[INVENTORY ARCHIVER]: Loaded {0} assets...", + successfulAssetRestores); + } + else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) + { + InventoryFolderBase foundFolder + = ReplicateArchivePathToUserInventory( + filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType, + rootDestinationFolder, foldersCreated, nodesLoaded); + + if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) { - successfulItemRestores++; - - // If we're loading an item directly into the given destination folder then we need to record - // it separately from any loaded root folders - if (rootDestinationFolder == foundFolder) - nodesLoaded.Add(item); + InventoryItemBase item = LoadItem(data, foundFolder); + + if (item != null) + { + successfulItemRestores++; + + // If we're loading an item directly into the given destination folder then we need to record + // it separately from any loaded root folders + if (rootDestinationFolder == foundFolder) + nodesLoaded.Add(item); + } } } } } - - archive.Close(); + finally + { + archive.Close(); + } m_log.DebugFormat( "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 6e11f3625e..c85d974646 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -117,19 +117,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver } protected void ReceivedAllAssets(ICollection assetsFoundUuids, ICollection assetsNotFoundUuids) - { - // We're almost done. Just need to write out the control file now - m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile()); - m_log.InfoFormat("[ARCHIVER]: Added control file to archive."); - + { Exception reportedException = null; bool succeeded = true; - + try - { + { + // We're almost done. Just need to write out the control file now + m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile()); + m_log.InfoFormat("[ARCHIVER]: Added control file to archive."); + m_archiveWriter.Close(); } - catch (IOException e) + catch (Exception e) { m_saveStream.Close(); reportedException = e; @@ -261,39 +261,47 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath); } - m_archiveWriter = new TarArchiveWriter(m_saveStream); - - if (inventoryFolder != null) - { - m_log.DebugFormat( - "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}", - inventoryFolder.Name, inventoryFolder.ID, m_invPath); - - //recurse through all dirs getting dirs and files - SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !foundStar); - } - else if (inventoryItem != null) - { - m_log.DebugFormat( - "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}", - inventoryItem.Name, inventoryItem.ID, m_invPath); - - SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH); - } - else + if (null == inventoryFolder && null == inventoryItem) { // We couldn't find the path indicated - m_saveStream.Close(); string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath); m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", errorMessage); m_module.TriggerInventoryArchiveSaved( m_id, false, m_userInfo, m_invPath, m_saveStream, new Exception(errorMessage)); - return; + return; } + + m_archiveWriter = new TarArchiveWriter(m_saveStream); - // Don't put all this profile information into the archive right now. - //SaveUsers(); + try + { + if (inventoryFolder != null) + { + m_log.DebugFormat( + "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}", + inventoryFolder.Name, inventoryFolder.ID, m_invPath); + + //recurse through all dirs getting dirs and files + SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !foundStar); + } + else if (inventoryItem != null) + { + m_log.DebugFormat( + "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}", + inventoryItem.Name, inventoryItem.ID, m_invPath); + + SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH); + } + + // Don't put all this profile information into the archive right now. + //SaveUsers(); + } + catch (Exception) + { + m_archiveWriter.Close(); + throw; + } new AssetsRequest( new AssetsArchiver(m_archiveWriter), m_assetUuids.Keys,