* archive each object as a separate xml file rather than put them all in one single large file

* this is being done for reasons of compositionality
0.6.0-stable
Justin Clarke Casey 2008-06-21 23:45:22 +00:00
parent 5b159e957a
commit ca88e3580b
5 changed files with 42 additions and 74 deletions

View File

@ -50,6 +50,6 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
/// <summary> /// <summary>
/// Path for the prims file /// Path for the prims file
/// </summary> /// </summary>
public static readonly string PRIMS_PATH = "objects/prims.xml"; public static readonly string OBJECTS_PATH = "objects/";
} }
} }

View File

@ -29,6 +29,7 @@ using OpenSim.Framework;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Modules.World.Serialiser; using OpenSim.Region.Environment.Modules.World.Serialiser;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Xml; using System.Xml;
@ -62,9 +63,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
TarArchiveReader archive = new TarArchiveReader(m_loadPath); TarArchiveReader archive = new TarArchiveReader(m_loadPath);
AssetsDearchiver dearchiver = new AssetsDearchiver(m_scene.AssetCache); AssetsDearchiver dearchiver = new AssetsDearchiver(m_scene.AssetCache);
string serializedPrims = string.Empty; List<string> serialisedSceneObjects = new List<string>();
// Just test for now by reading first file
string filePath = "ERROR"; string filePath = "ERROR";
byte[] data; byte[] data;
@ -73,9 +72,9 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
m_log.DebugFormat( m_log.DebugFormat(
"[ARCHIVER]: Successfully read {0} ({1} bytes) from archive {2}", filePath, data.Length, m_loadPath); "[ARCHIVER]: Successfully read {0} ({1} bytes) from archive {2}", filePath, data.Length, m_loadPath);
if (filePath.Equals(ArchiveConstants.PRIMS_PATH)) if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
{ {
serializedPrims = m_asciiEncoding.GetString(data); serialisedSceneObjects.Add(m_asciiEncoding.GetString(data));
} }
else if (filePath.Equals(ArchiveConstants.ASSETS_METADATA_PATH)) else if (filePath.Equals(ArchiveConstants.ASSETS_METADATA_PATH))
{ {
@ -92,35 +91,17 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
archive.Close(); archive.Close();
if (serializedPrims.Equals(string.Empty))
{
m_log.ErrorFormat("[ARCHIVER]: Archive did not contain a {0} file", ArchiveConstants.PRIMS_PATH);
return;
}
// Reload serialized prims // Reload serialized prims
m_log.InfoFormat("[ARCHIVER]: Loading scene objects"); m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects", serialisedSceneObjects.Count);
IRegionSerialiser serialiser = m_scene.RequestModuleInterface<IRegionSerialiser>(); IRegionSerialiser serialiser = m_scene.RequestModuleInterface<IRegionSerialiser>();
// Temporary code to read each sog in the file separately, pending actually having these in separate files
XmlTextReader xtr = new XmlTextReader(new StringReader(serializedPrims));
XmlDocument doc = new XmlDocument();
xtr.WhitespaceHandling = WhitespaceHandling.None;
doc.Load(xtr);
xtr.Close();
XmlNode sceneNode = doc.FirstChild;
int count = 0;
foreach (XmlNode objectNode in sceneNode.ChildNodes) foreach (string serialisedSceneObject in serialisedSceneObjects)
{ {
serialiser.LoadGroupFromXml2(m_scene, objectNode.OuterXml.ToString()); serialiser.LoadGroupFromXml2(m_scene, serialisedSceneObject);
count++;
} }
//serialiser.LoadPrimsFromXml2(m_scene, new StringReader(serializedPrims)); m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive");
m_log.DebugFormat("[ARCHIVER]: Loaded {0} scene objects", count);
} }
} }
} }

View File

@ -25,11 +25,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using libsecondlife; using libsecondlife;
using log4net; using log4net;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Modules.World.Serialiser;
using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment.Modules.World.Archiver namespace OpenSim.Region.Environment.Modules.World.Archiver
{ {
@ -45,12 +49,15 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected IRegionSerialiser m_serialiser;
protected List<EntityBase> m_sceneObjects;
protected string m_savePath; protected string m_savePath;
protected string m_serializedEntities;
public ArchiveWriteRequestExecution(string serializedEntities, string savePath) public ArchiveWriteRequestExecution(
List<EntityBase> sceneObjects, IRegionSerialiser serialiser, string savePath)
{ {
m_serializedEntities = serializedEntities; m_sceneObjects = sceneObjects;
m_serialiser = serialiser;
m_savePath = savePath; m_savePath = savePath;
} }
@ -59,8 +66,23 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
m_log.DebugFormat("[ARCHIVER]: Received all {0} assets required", assets.Count); m_log.DebugFormat("[ARCHIVER]: Received all {0} assets required", assets.Count);
TarArchiveWriter archive = new TarArchiveWriter(); TarArchiveWriter archive = new TarArchiveWriter();
archive.AddFile(ArchiveConstants.PRIMS_PATH, m_serializedEntities); foreach (EntityBase entity in m_sceneObjects)
{
// FIXME: I'm fairly sure that all entities are in fact SceneObjectGroups... must fix this
SceneObjectGroup sceneObject = (SceneObjectGroup)entity;
LLVector3 position = sceneObject.AbsolutePosition;
string serializedObject = m_serialiser.SaveGroupToXml2(sceneObject);
string filename
= string.Format(
"{0}{1}_{2:000}-{3:000}-{4:000}__{5}.xml",
ArchiveConstants.OBJECTS_PATH, sceneObject.Name,
Math.Round(position.X), Math.Round(position.Y), Math.Round(position.Z),
sceneObject.UUID);
archive.AddFile(filename, serializedObject);
}
AssetsArchiver assetsArchiver = new AssetsArchiver(assets); AssetsArchiver assetsArchiver = new AssetsArchiver(assets);
assetsArchiver.Archive(archive); assetsArchiver.Archive(archive);
@ -68,6 +90,6 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
archive.WriteTar(m_savePath); archive.WriteTar(m_savePath);
m_log.InfoFormat("[ARCHIVER]: Wrote out OpenSimulator archive {0}", m_savePath); m_log.InfoFormat("[ARCHIVER]: Wrote out OpenSimulator archive {0}", m_savePath);
} }
} }
} }

View File

@ -172,44 +172,17 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
} }
} }
string serializedEntities = SerializeObjects(entities); if (entities.Count > 0)
if (serializedEntities != null && serializedEntities.Length > 0)
{ {
m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count); m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count);
m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} assets", assetUuids.Count); m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} assets", assetUuids.Count);
// Asynchronously request all the assets required to perform this archive operation // Asynchronously request all the assets required to perform this archive operation
ArchiveWriteRequestExecution awre = new ArchiveWriteRequestExecution(serializedEntities, m_savePath); ArchiveWriteRequestExecution awre
= new ArchiveWriteRequestExecution(
entities, m_scene.RequestModuleInterface<IRegionSerialiser>(), m_savePath);
new AssetsRequest(assetUuids.Keys, m_scene.AssetCache, awre.ReceivedAllAssets).Execute(); new AssetsRequest(assetUuids.Keys, m_scene.AssetCache, awre.ReceivedAllAssets).Execute();
} }
} }
/// <summary>
/// Get an xml representation of the given scene objects.
/// </summary>
/// <param name="scene"></param>
/// <returns></returns>
protected static string SerializeObjects(List<EntityBase> entities)
{
string serialization = "<scene>";
List<string> serObjects = new List<string>();
foreach (EntityBase ent in entities)
{
if (ent is SceneObjectGroup)
{
serObjects.Add(((SceneObjectGroup) ent).ToXmlString2());
}
}
foreach (string serObject in serObjects)
serialization += serObject;
serialization += "</scene>";
return serialization;
}
} }
} }

View File

@ -146,7 +146,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
/// <summary> /// <summary>
/// /// Number of prims in this group
/// </summary> /// </summary>
public int PrimCount public int PrimCount
{ {
@ -164,14 +164,6 @@ namespace OpenSim.Region.Environment.Scenes
set { m_rootPart.GroupID = value; } set { m_rootPart.GroupID = value; }
} }
/// <summary>
///
/// </summary>
public LLVector3 GroupCentrePoint
{
get { return new LLVector3(0, 0, 0); }
}
public Dictionary<LLUUID, SceneObjectPart> Children public Dictionary<LLUUID, SceneObjectPart> Children
{ {
get { return m_parts; } get { return m_parts; }