aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs
diff options
context:
space:
mode:
authorSean Dague2008-09-03 18:11:44 +0000
committerSean Dague2008-09-03 18:11:44 +0000
commitaf5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e (patch)
treefcc52c0f3e20f005873def97e3be5cd9ca16270e /OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs
parentwhite space fixes (diff)
downloadopensim-SC-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.zip
opensim-SC-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.tar.gz
opensim-SC-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.tar.bz2
opensim-SC-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.tar.xz
narrange to do basic cleanup of the CMS module
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs467
1 files changed, 247 insertions, 220 deletions
diff --git a/OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs b/OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs
index e1f519b..680cefbd 100644
--- a/OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs
+++ b/OpenSim/Region/Environment/Modules/ContentManagementSystem/FileSystemDatabase.cs
@@ -1,159 +1,132 @@
1#region Header
2
1// FileSystemDatabase.cs 3// FileSystemDatabase.cs
2// User: bongiojp 4// User: bongiojp
3 5
6#endregion Header
7
4using System; 8using System;
5using System.Collections.Generic; 9using System.Collections.Generic;
10using System.Diagnostics;
6using System.IO; 11using System.IO;
12using Slash = System.IO.Path;
7using System.Reflection; 13using System.Reflection;
8using System.Xml; 14using System.Xml;
15
9using libsecondlife; 16using libsecondlife;
17
10using Nini.Config; 18using Nini.Config;
19
11using OpenSim.Framework; 20using OpenSim.Framework;
12using OpenSim.Region.Environment.Interfaces; 21using OpenSim.Region.Environment.Interfaces;
13using OpenSim.Region.Environment.Modules.World.Serialiser; 22using OpenSim.Region.Environment.Modules.World.Serialiser;
14using OpenSim.Region.Environment.Modules.World.Terrain; 23using OpenSim.Region.Environment.Modules.World.Terrain;
15using OpenSim.Region.Environment.Scenes; 24using OpenSim.Region.Environment.Scenes;
16using log4net;
17using OpenSim.Region.Physics.Manager; 25using OpenSim.Region.Physics.Manager;
26
27using log4net;
28
18using Axiom.Math; 29using Axiom.Math;
19using Slash=System.IO.Path;
20using System.Diagnostics;
21 30
22namespace OpenSim.Region.Environment.Modules.ContentManagement 31namespace OpenSim.Region.Environment.Modules.ContentManagement
23{ 32{
24 public class FileSystemDatabase : IContentDatabase 33 public class FileSystemDatabase : IContentDatabase
25 { 34 {
26 public static float TimeToDownload = 0; 35 #region Static Fields
27 public static float TimeToSave = 0; 36
28 37 public static float TimeToDownload = 0;
29 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 38 public static float TimeToSave = 0;
30 39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
31 private string m_repodir = null; 40
32 private Dictionary<LLUUID, IRegionSerialiser> m_serialiser = new Dictionary<LLUUID, IRegionSerialiser>(); 41 #endregion Static Fields
33 private Dictionary<LLUUID, Scene> m_scenes = new Dictionary<LLUUID, Scene>(); 42
34 43 #region Fields
35 public FileSystemDatabase() 44
36 { 45 private string m_repodir = null;
37 } 46 private Dictionary<LLUUID, Scene> m_scenes = new Dictionary<LLUUID, Scene>();
38 47 private Dictionary<LLUUID, IRegionSerialiser> m_serialiser = new Dictionary<LLUUID, IRegionSerialiser>();
39 public void Initialise(Scene scene, string dir) 48
40 { 49 #endregion Fields
41 lock(this) 50
42 { 51 #region Constructors
43 if (m_repodir == null) 52
44 m_repodir = dir; 53 public FileSystemDatabase()
45 } 54 {
46 lock(m_scenes) 55 }
47 m_scenes.Add(scene.RegionInfo.RegionID, scene); 56
48 } 57 #endregion Constructors
49 58
50 59 #region Private Methods
51 // Run once and only once. 60
52 public void PostInitialise() 61 // called by postinitialise
53 { 62 private void CreateDirectory()
54 SetupSerialiser(); 63 {
55 64 string scenedir;
56 m_log.Info("[FSDB]: Creating repository in " + m_repodir + "."); 65 if (!Directory.Exists(m_repodir))
57 CreateDirectory(); 66 Directory.CreateDirectory(m_repodir);
58 } 67
59 68 foreach (LLUUID region in m_scenes.Keys)
60 // called by postinitialise 69 {
61 private void SetupSerialiser() 70 scenedir = m_repodir + Slash.DirectorySeparatorChar + region + Slash.DirectorySeparatorChar;
71 if (!Directory.Exists(scenedir))
72 Directory.CreateDirectory(scenedir);
73 }
74 }
75
76 // called by postinitialise
77 private void SetupSerialiser()
62 { 78 {
63 if (m_serialiser.Count == 0) 79 if (m_serialiser.Count == 0)
64 foreach(LLUUID region in m_scenes.Keys) 80 foreach(LLUUID region in m_scenes.Keys)
65 m_serialiser.Add(region, 81 m_serialiser.Add(region,
66 m_scenes[region].RequestModuleInterface<IRegionSerialiser>() 82 m_scenes[region].RequestModuleInterface<IRegionSerialiser>()
67 ); 83 );
84 }
85
86 #endregion Private Methods
87
88 #region Public Methods
89
90 public int GetMostRecentRevision(LLUUID regionid)
91 {
92 return NumOfRegionRev(regionid);
93 }
94
95 public string GetRegionObjectHeightMap(LLUUID regionid)
96 {
97 String filename = m_repodir + Slash.DirectorySeparatorChar + regionid +
98 Slash.DirectorySeparatorChar + "heightmap.r32";
99 FileStream fs = new FileStream( filename, FileMode.Open);
100 StreamReader sr = new StreamReader(fs);
101 String result = sr.ReadToEnd();
102 sr.Close();
103 fs.Close();
104 return result;
105 }
106
107 public string GetRegionObjectHeightMap(LLUUID regionid, int revision)
108 {
109 String filename = m_repodir + Slash.DirectorySeparatorChar + regionid +
110 Slash.DirectorySeparatorChar + "heightmap.r32";
111 FileStream fs = new FileStream( filename, FileMode.Open);
112 StreamReader sr = new StreamReader(fs);
113 String result = sr.ReadToEnd();
114 sr.Close();
115 fs.Close();
116 return result;
68 } 117 }
69 118
70 // called by postinitialise 119 public System.Collections.ArrayList GetRegionObjectXMLList(LLUUID regionid, int revision)
71 private void CreateDirectory() 120 {
72 { 121 System.Collections.ArrayList objectList = new System.Collections.ArrayList();
73 string scenedir; 122 string filename = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar +
74 if (!Directory.Exists(m_repodir)) 123 + revision + Slash.DirectorySeparatorChar + "objects.xml";
75 Directory.CreateDirectory(m_repodir); 124 XmlDocument doc = new XmlDocument();
76
77 foreach (LLUUID region in m_scenes.Keys)
78 {
79 scenedir = m_repodir + Slash.DirectorySeparatorChar + region + Slash.DirectorySeparatorChar;
80 if (!Directory.Exists(scenedir))
81 Directory.CreateDirectory(scenedir);
82 }
83 }
84
85 public int NumOfRegionRev(LLUUID regionid)
86 {
87 string scenedir = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar;
88 m_log.Info("[FSDB]: Reading scene dir: " + scenedir);
89 string[] directories = Directory.GetDirectories(scenedir);
90 return directories.Length;
91 }
92
93 public int GetMostRecentRevision(LLUUID regionid)
94 {
95 return NumOfRegionRev(regionid);
96 }
97
98 public void SaveRegion(LLUUID regionid, string regionName, string logMessage)
99 {
100 m_log.Info("[FSDB]: ...............................");
101 string scenedir = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar;
102
103 m_log.Info("[FSDB]: checking if scene directory exists: " + scenedir);
104 if (!Directory.Exists(scenedir))
105 Directory.CreateDirectory(scenedir);
106
107 int newRevisionNum = GetMostRecentRevision(regionid)+1;
108 string revisiondir = scenedir + newRevisionNum + Slash.DirectorySeparatorChar;
109
110 m_log.Info("[FSDB]: checking if revision directory exists: " + revisiondir);
111 if (!Directory.Exists(revisiondir))
112 Directory.CreateDirectory(revisiondir);
113
114 try {
115 Stopwatch x = new Stopwatch();
116 x.Start();
117 if (m_scenes.ContainsKey(regionid))
118 {
119 m_serialiser[regionid].SerialiseRegion(m_scenes[regionid], revisiondir);
120 }
121 x.Stop();
122 TimeToSave += x.ElapsedMilliseconds;
123 m_log.Info("[FileSystemDatabase] Time spent serialising regions to files on disk for " + regionName + ": " + x.ElapsedMilliseconds);
124 m_log.Info("[FileSystemDatabase] Time spent serialising regions to files on disk so far: " + TimeToSave);
125 }
126 catch (Exception e)
127 {
128 m_log.ErrorFormat("[FSDB]: Serialisation of region failed: " + e);
129 return;
130 }
131
132 try {
133 // Finish by writing log message.
134 FileStream file = new FileStream(revisiondir + "log", FileMode.Create, FileAccess.ReadWrite);
135 StreamWriter sw = new StreamWriter(file);
136 sw.Write(logMessage);
137 sw.Close();
138 }
139 catch (Exception e)
140 {
141 m_log.ErrorFormat("[FSDB]: Failed trying to save log file " + e);
142 return;
143 }
144 }
145
146 public System.Collections.ArrayList GetRegionObjectXMLList(LLUUID regionid, int revision)
147 {
148 System.Collections.ArrayList objectList = new System.Collections.ArrayList();
149 string filename = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar +
150 + revision + Slash.DirectorySeparatorChar + "objects.xml";
151 XmlDocument doc = new XmlDocument();
152 XmlNode rootNode; 125 XmlNode rootNode;
153 //int primCount = 0; 126 //int primCount = 0;
154 //SceneObjectGroup obj = null; 127 //SceneObjectGroup obj = null;
155 128
156 if(File.Exists(filename)) 129 if(File.Exists(filename))
157 { 130 {
158 XmlTextReader reader = new XmlTextReader(filename); 131 XmlTextReader reader = new XmlTextReader(filename);
159 reader.WhitespaceHandling = WhitespaceHandling.None; 132 reader.WhitespaceHandling = WhitespaceHandling.None;
@@ -162,99 +135,153 @@ namespace OpenSim.Region.Environment.Modules.ContentManagement
162 rootNode = doc.FirstChild; 135 rootNode = doc.FirstChild;
163 foreach (XmlNode aPrimNode in rootNode.ChildNodes) 136 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
164 { 137 {
165 objectList.Add(aPrimNode.OuterXml); 138 objectList.Add(aPrimNode.OuterXml);
166 } 139 }
167 return objectList; 140 return objectList;
168 } 141 }
169 return null; 142 return null;
170 } 143 }
171 144
172 public System.Collections.ArrayList GetRegionObjectXMLList(LLUUID regionid) 145 public System.Collections.ArrayList GetRegionObjectXMLList(LLUUID regionid)
173 { 146 {
174 int revision = NumOfRegionRev(regionid); 147 int revision = NumOfRegionRev(regionid);
175 m_log.Info("[FSDB]: found revisions:" + revision); 148 m_log.Info("[FSDB]: found revisions:" + revision);
176 System.Collections.ArrayList xmlList = new System.Collections.ArrayList(); 149 System.Collections.ArrayList xmlList = new System.Collections.ArrayList();
177 string filename = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar + 150 string filename = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar +
178 + revision + Slash.DirectorySeparatorChar + "objects.xml"; 151 + revision + Slash.DirectorySeparatorChar + "objects.xml";
179 XmlDocument doc = new XmlDocument(); 152 XmlDocument doc = new XmlDocument();
180 XmlNode rootNode; 153 XmlNode rootNode;
181 154
182 155
183 m_log.Info("[FSDB]: Checking if " + filename + " exists."); 156 m_log.Info("[FSDB]: Checking if " + filename + " exists.");
184 if(File.Exists(filename)) 157 if(File.Exists(filename))
185 { 158 {
186 Stopwatch x = new Stopwatch(); 159 Stopwatch x = new Stopwatch();
187 x.Start(); 160 x.Start();
188 161
189 XmlTextReader reader = new XmlTextReader(filename); 162 XmlTextReader reader = new XmlTextReader(filename);
190 reader.WhitespaceHandling = WhitespaceHandling.None; 163 reader.WhitespaceHandling = WhitespaceHandling.None;
191 doc.Load(reader); 164 doc.Load(reader);
192 reader.Close(); 165 reader.Close();
193 rootNode = doc.FirstChild; 166 rootNode = doc.FirstChild;
194 167
195 foreach (XmlNode aPrimNode in rootNode.ChildNodes) 168 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
196 xmlList.Add(aPrimNode.OuterXml); 169 xmlList.Add(aPrimNode.OuterXml);
197 170
198 x.Stop(); 171 x.Stop();
199 TimeToDownload += x.ElapsedMilliseconds; 172 TimeToDownload += x.ElapsedMilliseconds;
200 m_log.Info("[FileSystemDatabase] Time spent retrieving xml files so far: " + TimeToDownload); 173 m_log.Info("[FileSystemDatabase] Time spent retrieving xml files so far: " + TimeToDownload);
201 174
202 return xmlList; 175 return xmlList;
203 } 176 }
204 return null; 177 return null;
205 } 178 }
206 179
207 public string GetRegionObjectHeightMap(LLUUID regionid) 180 public void Initialise(Scene scene, string dir)
208 { 181 {
209 String filename = m_repodir + Slash.DirectorySeparatorChar + regionid + 182 lock(this)
210 Slash.DirectorySeparatorChar + "heightmap.r32"; 183 {
211 FileStream fs = new FileStream( filename, FileMode.Open); 184 if (m_repodir == null)
212 StreamReader sr = new StreamReader(fs); 185 m_repodir = dir;
213 String result = sr.ReadToEnd(); 186 }
214 sr.Close(); 187 lock(m_scenes)
215 fs.Close(); 188 m_scenes.Add(scene.RegionInfo.RegionID, scene);
216 return result; 189 }
217 } 190
218 191 public System.Collections.Generic.SortedDictionary<string, string> ListOfRegionRevisions(LLUUID regionid)
219 public string GetRegionObjectHeightMap(LLUUID regionid, int revision) 192 {
220 { 193 SortedDictionary<string, string> revisionDict = new SortedDictionary<string,string>();
221 String filename = m_repodir + Slash.DirectorySeparatorChar + regionid + 194
222 Slash.DirectorySeparatorChar + "heightmap.r32"; 195 string scenedir = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar;
223 FileStream fs = new FileStream( filename, FileMode.Open); 196 string[] directories = Directory.GetDirectories(scenedir);
224 StreamReader sr = new StreamReader(fs); 197
225 String result = sr.ReadToEnd(); 198 FileStream fs = null;
226 sr.Close(); 199 StreamReader sr = null;
227 fs.Close(); 200 String logMessage = "";
228 return result; 201 String logLocation = "";
229 } 202 foreach(string revisionDir in directories)
230 203 {
231 public System.Collections.Generic.SortedDictionary<string, string> ListOfRegionRevisions(LLUUID regionid) 204 try {
232 { 205 logLocation = revisionDir + Slash.DirectorySeparatorChar + "log";
233 SortedDictionary<string, string> revisionDict = new SortedDictionary<string,string>(); 206 fs = new FileStream( logLocation, FileMode.Open);
234 207 sr = new StreamReader(fs);
235 string scenedir = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar; 208 logMessage = sr.ReadToEnd();
236 string[] directories = Directory.GetDirectories(scenedir); 209 sr.Close();
237 210 fs.Close();
238 FileStream fs = null; 211 revisionDict.Add(revisionDir, logMessage);
239 StreamReader sr = null; 212 }
240 String logMessage = ""; 213 catch (Exception)
241 String logLocation = ""; 214 {}
242 foreach(string revisionDir in directories) 215 }
243 { 216
244 try { 217 return revisionDict;
245 logLocation = revisionDir + Slash.DirectorySeparatorChar + "log"; 218 }
246 fs = new FileStream( logLocation, FileMode.Open); 219
247 sr = new StreamReader(fs); 220 public int NumOfRegionRev(LLUUID regionid)
248 logMessage = sr.ReadToEnd(); 221 {
249 sr.Close(); 222 string scenedir = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar;
250 fs.Close(); 223 m_log.Info("[FSDB]: Reading scene dir: " + scenedir);
251 revisionDict.Add(revisionDir, logMessage); 224 string[] directories = Directory.GetDirectories(scenedir);
252 } 225 return directories.Length;
253 catch (Exception) 226 }
254 {} 227
255 } 228 // Run once and only once.
256 229 public void PostInitialise()
257 return revisionDict; 230 {
258 } 231 SetupSerialiser();
259 } 232
260} 233 m_log.Info("[FSDB]: Creating repository in " + m_repodir + ".");
234 CreateDirectory();
235 }
236
237 public void SaveRegion(LLUUID regionid, string regionName, string logMessage)
238 {
239 m_log.Info("[FSDB]: ...............................");
240 string scenedir = m_repodir + Slash.DirectorySeparatorChar + regionid + Slash.DirectorySeparatorChar;
241
242 m_log.Info("[FSDB]: checking if scene directory exists: " + scenedir);
243 if (!Directory.Exists(scenedir))
244 Directory.CreateDirectory(scenedir);
245
246 int newRevisionNum = GetMostRecentRevision(regionid)+1;
247 string revisiondir = scenedir + newRevisionNum + Slash.DirectorySeparatorChar;
248
249 m_log.Info("[FSDB]: checking if revision directory exists: " + revisiondir);
250 if (!Directory.Exists(revisiondir))
251 Directory.CreateDirectory(revisiondir);
252
253 try {
254 Stopwatch x = new Stopwatch();
255 x.Start();
256 if (m_scenes.ContainsKey(regionid))
257 {
258 m_serialiser[regionid].SerialiseRegion(m_scenes[regionid], revisiondir);
259 }
260 x.Stop();
261 TimeToSave += x.ElapsedMilliseconds;
262 m_log.Info("[FileSystemDatabase] Time spent serialising regions to files on disk for " + regionName + ": " + x.ElapsedMilliseconds);
263 m_log.Info("[FileSystemDatabase] Time spent serialising regions to files on disk so far: " + TimeToSave);
264 }
265 catch (Exception e)
266 {
267 m_log.ErrorFormat("[FSDB]: Serialisation of region failed: " + e);
268 return;
269 }
270
271 try {
272 // Finish by writing log message.
273 FileStream file = new FileStream(revisiondir + "log", FileMode.Create, FileAccess.ReadWrite);
274 StreamWriter sw = new StreamWriter(file);
275 sw.Write(logMessage);
276 sw.Close();
277 }
278 catch (Exception e)
279 {
280 m_log.ErrorFormat("[FSDB]: Failed trying to save log file " + e);
281 return;
282 }
283 }
284
285 #endregion Public Methods
286 }
287} \ No newline at end of file