Make load/save iar slightly better in the face of io failures by always attempting to close the streams

0.6.8-post-fixes
Justin Clark-Casey (justincc) 2009-11-24 18:27:31 +00:00
parent c083ab6824
commit f605d59136
2 changed files with 77 additions and 63 deletions
OpenSim/Region/CoreModules/Avatar/Inventory/Archiver

View File

@ -121,45 +121,51 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
byte[] data; byte[] data;
TarArchiveReader.TarEntryType entryType; 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)) if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
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)
{ {
InventoryItemBase item = LoadItem(data, foundFolder); if (LoadAsset(filePath, data))
successfulAssetRestores++;
else
failedAssetRestores++;
if (item != null) 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++; InventoryItemBase item = LoadItem(data, foundFolder);
// If we're loading an item directly into the given destination folder then we need to record if (item != null)
// it separately from any loaded root folders {
if (rootDestinationFolder == foundFolder) successfulItemRestores++;
nodesLoaded.Add(item);
// 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);
}
} }
} }
} }
} }
finally
archive.Close(); {
archive.Close();
}
m_log.DebugFormat( m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures",

View File

@ -118,18 +118,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids) protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> 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; Exception reportedException = null;
bool succeeded = true; bool succeeded = true;
try 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(); m_archiveWriter.Close();
} }
catch (IOException e) catch (Exception e)
{ {
m_saveStream.Close(); m_saveStream.Close();
reportedException = e; reportedException = e;
@ -261,29 +261,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
//inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath); //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
} }
m_archiveWriter = new TarArchiveWriter(m_saveStream); if (null == inventoryFolder && null == inventoryItem)
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
{ {
// We couldn't find the path indicated // We couldn't find the path indicated
m_saveStream.Close();
string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath); string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath);
m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", errorMessage); m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", errorMessage);
m_module.TriggerInventoryArchiveSaved( m_module.TriggerInventoryArchiveSaved(
@ -292,8 +272,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return; return;
} }
// Don't put all this profile information into the archive right now. m_archiveWriter = new TarArchiveWriter(m_saveStream);
//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 AssetsRequest(
new AssetsArchiver(m_archiveWriter), m_assetUuids.Keys, new AssetsArchiver(m_archiveWriter), m_assetUuids.Keys,