Add --skip-assets option to load oar.

This allows you to load an oar without loading its assets.  This is useful if you know that the required assets are already in the asset service, since loading without assets is quicker.
This option will become more useful when the ability to save oars without assets is added, which should happen fairly soon.  At this point there will also be better documentation.
slimupdates
Justin Clark-Casey (justincc) 2010-04-16 22:29:11 +01:00
parent cf46735856
commit bf3956aeb0
5 changed files with 50 additions and 28 deletions

5
OpenSim/Region/Application/OpenSim.cs Executable file → Normal file
View File

@ -251,8 +251,9 @@ namespace OpenSim
"Save named prim to XML2", SavePrimsXml2); "Save named prim to XML2", SavePrimsXml2);
m_console.Commands.AddCommand("region", false, "load oar", m_console.Commands.AddCommand("region", false, "load oar",
"load oar [--merge] <oar name>", "load oar [--merge] [--skip-assets] <oar name>",
"Load a region's data from OAR archive", LoadOar); "Load a region's data from OAR archive. --merge will merge the oar with the existing scene. --skip-assets will load the oar but ignore the assets it contains",
LoadOar);
m_console.Commands.AddCommand("region", false, "save oar", m_console.Commands.AddCommand("region", false, "save oar",
"save oar <oar name>", "save oar <oar name>",

View File

@ -53,25 +53,30 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
private static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
private Scene m_scene; protected Scene m_scene;
private Stream m_loadStream; protected Stream m_loadStream;
private Guid m_requestId; protected Guid m_requestId;
private string m_errorMessage; protected string m_errorMessage;
/// <value> /// <value>
/// Should the archive being loaded be merged with what is already on the region? /// Should the archive being loaded be merged with what is already on the region?
/// </value> /// </value>
private bool m_merge; protected bool m_merge;
/// <value>
/// Should we ignore any assets when reloading the archive?
/// </value>
protected bool m_skipAssets;
/// <summary> /// <summary>
/// Used to cache lookups for valid uuids. /// Used to cache lookups for valid uuids.
/// </summary> /// </summary>
private IDictionary<UUID, bool> m_validUserUuids = new Dictionary<UUID, bool>(); private IDictionary<UUID, bool> m_validUserUuids = new Dictionary<UUID, bool>();
public ArchiveReadRequest(Scene scene, string loadPath, bool merge, Guid requestId) public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId)
{ {
m_scene = scene; m_scene = scene;
@ -89,14 +94,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_errorMessage = String.Empty; m_errorMessage = String.Empty;
m_merge = merge; m_merge = merge;
m_skipAssets = skipAssets;
m_requestId = requestId; m_requestId = requestId;
} }
public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, Guid requestId) public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId)
{ {
m_scene = scene; m_scene = scene;
m_loadStream = loadStream; m_loadStream = loadStream;
m_merge = merge; m_merge = merge;
m_skipAssets = skipAssets;
m_requestId = requestId; m_requestId = requestId;
} }
@ -135,7 +142,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{ {
serialisedSceneObjects.Add(m_utf8Encoding.GetString(data)); serialisedSceneObjects.Add(m_utf8Encoding.GetString(data));
} }
else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
{ {
if (LoadAsset(filePath, data)) if (LoadAsset(filePath, data))
successfulAssetRestores++; successfulAssetRestores++;
@ -178,6 +185,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
archive.Close(); archive.Close();
} }
if (!m_skipAssets)
{
m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores); m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
if (failedAssetRestores > 0) if (failedAssetRestores > 0)
@ -185,6 +194,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores); m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores); m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
} }
}
if (!m_merge) if (!m_merge)
{ {

View File

@ -94,8 +94,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void HandleLoadOarConsoleCommand(string module, string[] cmdparams) public void HandleLoadOarConsoleCommand(string module, string[] cmdparams)
{ {
bool mergeOar = false; bool mergeOar = false;
bool skipAssets = false;
OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; }); OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; });
options.Add("s|skip-assets", delegate (string v) { skipAssets = v != null; });
List<string> mainParams = options.Parse(cmdparams); List<string> mainParams = options.Parse(cmdparams);
// m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar); // m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar);
@ -105,11 +108,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
if (mainParams.Count > 2) if (mainParams.Count > 2)
{ {
DearchiveRegion(mainParams[2], mergeOar, Guid.Empty); DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty);
} }
else else
{ {
DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, Guid.Empty); DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, Guid.Empty);
} }
} }
@ -154,25 +157,25 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void DearchiveRegion(string loadPath) public void DearchiveRegion(string loadPath)
{ {
DearchiveRegion(loadPath, false, Guid.Empty); DearchiveRegion(loadPath, false, false, Guid.Empty);
} }
public void DearchiveRegion(string loadPath, bool merge, Guid requestId) public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId)
{ {
m_log.InfoFormat( m_log.InfoFormat(
"[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath); "[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath);
new ArchiveReadRequest(m_scene, loadPath, merge, requestId).DearchiveRegion(); new ArchiveReadRequest(m_scene, loadPath, merge, skipAssets, requestId).DearchiveRegion();
} }
public void DearchiveRegion(Stream loadStream) public void DearchiveRegion(Stream loadStream)
{ {
DearchiveRegion(loadStream, false, Guid.Empty); DearchiveRegion(loadStream, false, false, Guid.Empty);
} }
public void DearchiveRegion(Stream loadStream, bool merge, Guid requestId) public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId)
{ {
new ArchiveReadRequest(m_scene, loadStream, merge, requestId).DearchiveRegion(); new ArchiveReadRequest(m_scene, loadStream, merge, skipAssets, requestId).DearchiveRegion();
} }
} }
} }

View File

@ -442,7 +442,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
byte[] archive = archiveWriteStream.ToArray(); byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive); MemoryStream archiveReadStream = new MemoryStream(archive);
m_archiverModule.DearchiveRegion(archiveReadStream, true, Guid.Empty); m_archiverModule.DearchiveRegion(archiveReadStream, true, false, Guid.Empty);
SceneObjectPart object1Existing = m_scene.GetSceneObjectPart(part1.Name); SceneObjectPart object1Existing = m_scene.GetSceneObjectPart(part1.Name);
Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge"); Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge");

View File

@ -90,8 +90,12 @@ namespace OpenSim.Region.Framework.Interfaces
/// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region
/// settings in the archive will be ignored. /// settings in the archive will be ignored.
/// </param> /// </param>
/// <param name="skipAssets">
/// If true, the archive is loaded without loading any assets contained within it. This is useful if the
/// assets are already known to be present in the grid's asset service.
/// </param>
/// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
void DearchiveRegion(string loadPath, bool merge, Guid requestId); void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId);
/// <summary> /// <summary>
/// Dearchive a region from a stream. This replaces the existing scene. /// Dearchive a region from a stream. This replaces the existing scene.
@ -113,7 +117,11 @@ namespace OpenSim.Region.Framework.Interfaces
/// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region
/// settings in the archive will be ignored. /// settings in the archive will be ignored.
/// </param> /// </param>
/// <param name="skipAssets">
/// If true, the archive is loaded without loading any assets contained within it. This is useful if the
/// assets are already known to be present in the grid's asset service.
/// </param
/// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
void DearchiveRegion(Stream loadStream, bool merge, Guid requestId); void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId);
} }
} }