diff options
author | Sean Dague | 2007-11-13 15:22:54 +0000 |
---|---|---|
committer | Sean Dague | 2007-11-13 15:22:54 +0000 |
commit | 7810b068f46f0aa45e695a7c65a1fd6ed91ceb14 (patch) | |
tree | 8244a30ebb67a2e888b429fe254a63656dfc546a /OpenSim | |
parent | replaced exception when sitting and typing with rather amusing getting up and... (diff) | |
download | opensim-SC-7810b068f46f0aa45e695a7c65a1fd6ed91ceb14.zip opensim-SC-7810b068f46f0aa45e695a7c65a1fd6ed91ceb14.tar.gz opensim-SC-7810b068f46f0aa45e695a7c65a1fd6ed91ceb14.tar.bz2 opensim-SC-7810b068f46f0aa45e695a7c65a1fd6ed91ceb14.tar.xz |
some changes to reduce memory significantly by not keeping all
terrain revisions in memory. Once I'm sure this is working, I'll purge
out some of the crufty code here.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index 59b09d9..4aff606 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs | |||
@@ -44,11 +44,12 @@ namespace OpenSim.DataStore.MonoSqlite | |||
44 | { | 44 | { |
45 | private const string primSelect = "select * from prims"; | 45 | private const string primSelect = "select * from prims"; |
46 | private const string shapeSelect = "select * from primshapes"; | 46 | private const string shapeSelect = "select * from primshapes"; |
47 | private const string terrainSelect = "select * from terrain"; | 47 | private const string terrainSelect = "select * from terrain limit 1"; |
48 | 48 | ||
49 | private DataSet ds; | 49 | private DataSet ds; |
50 | private SqliteDataAdapter primDa; | 50 | private SqliteDataAdapter primDa; |
51 | private SqliteDataAdapter shapeDa; | 51 | private SqliteDataAdapter shapeDa; |
52 | private SqliteConnection conn; | ||
52 | private SqliteDataAdapter terrainDa; | 53 | private SqliteDataAdapter terrainDa; |
53 | 54 | ||
54 | /*********************************************************************** | 55 | /*********************************************************************** |
@@ -64,7 +65,7 @@ namespace OpenSim.DataStore.MonoSqlite | |||
64 | ds = new DataSet(); | 65 | ds = new DataSet(); |
65 | 66 | ||
66 | MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + dbfile); | 67 | MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + dbfile); |
67 | SqliteConnection conn = new SqliteConnection(connectionString); | 68 | conn = new SqliteConnection(connectionString); |
68 | 69 | ||
69 | SqliteCommand primSelectCmd = new SqliteCommand(primSelect, conn); | 70 | SqliteCommand primSelectCmd = new SqliteCommand(primSelect, conn); |
70 | primDa = new SqliteDataAdapter(primSelectCmd); | 71 | primDa = new SqliteDataAdapter(primSelectCmd); |
@@ -245,17 +246,20 @@ namespace OpenSim.DataStore.MonoSqlite | |||
245 | public void StoreTerrain(double[,] ter, LLUUID regionID) | 246 | public void StoreTerrain(double[,] ter, LLUUID regionID) |
246 | { | 247 | { |
247 | int revision = Util.UnixTimeSinceEpoch(); | 248 | int revision = Util.UnixTimeSinceEpoch(); |
248 | |||
249 | MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); | 249 | MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); |
250 | 250 | ||
251 | DataTable terrain = ds.Tables["terrain"]; | 251 | DataTable terrain = ds.Tables["terrain"]; |
252 | lock (ds) | 252 | lock (ds) |
253 | { | 253 | { |
254 | DataRow newrow = terrain.NewRow(); | 254 | SqliteCommand cmd = new SqliteCommand("insert into terrain(RegionUUID, Revision, Heightfield)" + |
255 | fillTerrainRow(newrow, regionID, revision, ter); | 255 | "values(:RegionUUID, :Revision, :Heightfield)", conn); |
256 | terrain.Rows.Add(newrow); | 256 | using(cmd) |
257 | 257 | { | |
258 | Commit(); | 258 | cmd.Parameters.Add(":RegionUUID", regionID); |
259 | cmd.Parameters.Add(":Revision", revision); | ||
260 | cmd.Parameters.Add(":Heightfield", serializeTerrain(ter)); | ||
261 | cmd.ExecuteNonQuery(); | ||
262 | } | ||
259 | } | 263 | } |
260 | } | 264 | } |
261 | 265 | ||
@@ -264,18 +268,15 @@ namespace OpenSim.DataStore.MonoSqlite | |||
264 | double[,] terret = new double[256,256]; | 268 | double[,] terret = new double[256,256]; |
265 | terret.Initialize(); | 269 | terret.Initialize(); |
266 | 270 | ||
267 | DataTable terrain = ds.Tables["terrain"]; | 271 | SqliteCommand cmd = new SqliteCommand("select RegionUUID, Revision, Heightfield from terrain" + |
272 | "where RegionUUID=:RegionUUID order by Revision desc limit 1", conn); | ||
273 | cmd.Parameters.Add(":RegionUUID", regionID); | ||
268 | 274 | ||
269 | lock (ds) | 275 | using (SqliteDataReader row = cmd.ExecuteReader(CommandBehavior.SingleRow)) |
270 | { | 276 | { |
271 | DataRow[] rows = terrain.Select("RegionUUID = '" + regionID.ToString() + "'", "Revision DESC"); | ||
272 | |||
273 | int rev = 0; | 277 | int rev = 0; |
274 | 278 | if (row.Read()) | |
275 | if (rows.Length > 0) | ||
276 | { | 279 | { |
277 | DataRow row = rows[0]; | ||
278 | |||
279 | byte[] heightmap = (byte[]) row["Heightfield"]; | 280 | byte[] heightmap = (byte[]) row["Heightfield"]; |
280 | for (int x = 0; x < 256; x++) | 281 | for (int x = 0; x < 256; x++) |
281 | { | 282 | { |
@@ -284,8 +285,7 @@ namespace OpenSim.DataStore.MonoSqlite | |||
284 | terret[x, y] = BitConverter.ToDouble(heightmap, ((x*256) + y)*8); | 285 | terret[x, y] = BitConverter.ToDouble(heightmap, ((x*256) + y)*8); |
285 | } | 286 | } |
286 | } | 287 | } |
287 | 288 | rev = (int)row["Revision"]; | |
288 | rev = (int) row["Revision"]; | ||
289 | } | 289 | } |
290 | else | 290 | else |
291 | { | 291 | { |
@@ -293,7 +293,6 @@ namespace OpenSim.DataStore.MonoSqlite | |||
293 | return null; | 293 | return null; |
294 | } | 294 | } |
295 | 295 | ||
296 | |||
297 | MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); | 296 | MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); |
298 | } | 297 | } |
299 | 298 | ||
@@ -522,11 +521,8 @@ namespace OpenSim.DataStore.MonoSqlite | |||
522 | return prim; | 521 | return prim; |
523 | } | 522 | } |
524 | 523 | ||
525 | private void fillTerrainRow(DataRow row, LLUUID regionUUID, int rev, double[,] val) | 524 | private Array serializeTerrain(double[,] val) |
526 | { | 525 | { |
527 | row["RegionUUID"] = regionUUID; | ||
528 | row["Revision"] = rev; | ||
529 | |||
530 | MemoryStream str = new MemoryStream(65536*sizeof (double)); | 526 | MemoryStream str = new MemoryStream(65536*sizeof (double)); |
531 | BinaryWriter bw = new BinaryWriter(str); | 527 | BinaryWriter bw = new BinaryWriter(str); |
532 | 528 | ||
@@ -535,9 +531,25 @@ namespace OpenSim.DataStore.MonoSqlite | |||
535 | for (int y = 0; y < 256; y++) | 531 | for (int y = 0; y < 256; y++) |
536 | bw.Write(val[x, y]); | 532 | bw.Write(val[x, y]); |
537 | 533 | ||
538 | row["Heightfield"] = str.ToArray(); | 534 | return str.ToArray(); |
539 | } | 535 | } |
540 | 536 | ||
537 | // private void fillTerrainRow(DataRow row, LLUUID regionUUID, int rev, double[,] val) | ||
538 | // { | ||
539 | // row["RegionUUID"] = regionUUID; | ||
540 | // row["Revision"] = rev; | ||
541 | |||
542 | // MemoryStream str = new MemoryStream(65536*sizeof (double)); | ||
543 | // BinaryWriter bw = new BinaryWriter(str); | ||
544 | |||
545 | // // TODO: COMPATIBILITY - Add byte-order conversions | ||
546 | // for (int x = 0; x < 256; x++) | ||
547 | // for (int y = 0; y < 256; y++) | ||
548 | // bw.Write(val[x, y]); | ||
549 | |||
550 | // row["Heightfield"] = str.ToArray(); | ||
551 | // } | ||
552 | |||
541 | private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) | 553 | private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) |
542 | { | 554 | { |
543 | row["UUID"] = prim.UUID; | 555 | row["UUID"] = prim.UUID; |