aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs45
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs50
-rw-r--r--OpenSim/Data/PGSQL/PGSQLSimulationData.cs45
-rw-r--r--OpenSim/Data/SQLite/SQLiteSimulationData.cs52
-rw-r--r--OpenSim/Data/Tests/RegionTests.cs8
5 files changed, 85 insertions, 115 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
index f41f60c..dbfd16c 100644
--- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
@@ -49,6 +49,7 @@ namespace OpenSim.Data.MSSQL
49 49
50 // private static FileSystemDataStore Instance = new FileSystemDataStore(); 50 // private static FileSystemDataStore Instance = new FileSystemDataStore();
51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private static string LogHeader = "[REGION DB MSSQL]";
52 53
53 /// <summary> 54 /// <summary>
54 /// The database manager 55 /// The database manager
@@ -569,15 +570,19 @@ ELSE
569 return terrain; 570 return terrain;
570 } 571 }
571 572
573 // Legacy entry point for when terrain was always a 256x256 hieghtmap
574 public void StoreTerrain(double[,] ter, UUID regionID)
575 {
576 StoreTerrain(new HeightmapTerrainData(ter), regionID);
577 }
578
572 /// <summary> 579 /// <summary>
573 /// Stores the terrain map to DB. 580 /// Stores the terrain map to DB.
574 /// </summary> 581 /// </summary>
575 /// <param name="terrain">terrain map data.</param> 582 /// <param name="terrain">terrain map data.</param>
576 /// <param name="regionID">regionID.</param> 583 /// <param name="regionID">regionID.</param>
577 public void StoreTerrain(double[,] terrain, UUID regionID) 584 public void StoreTerrain(TerrainData terrData, UUID regionID)
578 { 585 {
579 int revision = Util.UnixTimeSinceEpoch();
580
581 //Delete old terrain map 586 //Delete old terrain map
582 string sql = "delete from terrain where RegionUUID=@RegionUUID"; 587 string sql = "delete from terrain where RegionUUID=@RegionUUID";
583 using (SqlConnection conn = new SqlConnection(m_connectionString)) 588 using (SqlConnection conn = new SqlConnection(m_connectionString))
@@ -590,17 +595,21 @@ ELSE
590 595
591 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)"; 596 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
592 597
598 int terrainDBRevision;
599 Array terrainDBblob;
600 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
601
593 using (SqlConnection conn = new SqlConnection(m_connectionString)) 602 using (SqlConnection conn = new SqlConnection(m_connectionString))
594 using (SqlCommand cmd = new SqlCommand(sql, conn)) 603 using (SqlCommand cmd = new SqlCommand(sql, conn))
595 { 604 {
596 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); 605 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
597 cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision)); 606 cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision));
598 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain))); 607 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob));
599 conn.Open(); 608 conn.Open();
600 cmd.ExecuteNonQuery(); 609 cmd.ExecuteNonQuery();
601 } 610 }
602 611
603 _Log.Info("[REGION DB]: Stored terrain revision r " + revision); 612 _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision);
604 } 613 }
605 614
606 /// <summary> 615 /// <summary>
@@ -1345,30 +1354,6 @@ VALUES
1345 #region Private Methods 1354 #region Private Methods
1346 1355
1347 /// <summary> 1356 /// <summary>
1348 /// Serializes the terrain data for storage in DB.
1349 /// </summary>
1350 /// <param name="val">terrain data</param>
1351 /// <returns></returns>
1352 private static Array serializeTerrain(double[,] val)
1353 {
1354 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
1355 BinaryWriter bw = new BinaryWriter(str);
1356
1357 // TODO: COMPATIBILITY - Add byte-order conversions
1358 for (int x = 0; x < (int)Constants.RegionSize; x++)
1359 for (int y = 0; y < (int)Constants.RegionSize; y++)
1360 {
1361 double height = val[x, y];
1362 if (height == 0.0)
1363 height = double.Epsilon;
1364
1365 bw.Write(height);
1366 }
1367
1368 return str.ToArray();
1369 }
1370
1371 /// <summary>
1372 /// Stores new regionsettings. 1357 /// Stores new regionsettings.
1373 /// </summary> 1358 /// </summary>
1374 /// <param name="regionSettings">The region settings.</param> 1359 /// <param name="regionSettings">The region settings.</param>
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index b03a904..4bd8617 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Data.MySQL
48 public class MySQLSimulationData : ISimulationDataStore 48 public class MySQLSimulationData : ISimulationDataStore
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[REGION DB MYSQL]";
51 52
52 private string m_connectionString; 53 private string m_connectionString;
53 private object m_dbLock = new object(); 54 private object m_dbLock = new object();
@@ -91,7 +92,7 @@ namespace OpenSim.Data.MySQL
91 } 92 }
92 catch (Exception e) 93 catch (Exception e)
93 { 94 {
94 m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message); 95 m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e);
95 throw; 96 throw;
96 } 97 }
97 98
@@ -572,10 +573,14 @@ namespace OpenSim.Data.MySQL
572 } 573 }
573 } 574 }
574 575
576 // Legacy entry point for when terrain was always a 256x256 hieghtmap
575 public void StoreTerrain(double[,] ter, UUID regionID) 577 public void StoreTerrain(double[,] ter, UUID regionID)
576 { 578 {
577 m_log.Info("[REGION DB]: Storing terrain"); 579 StoreTerrain(new HeightmapTerrainData(ter), regionID);
580 }
578 581
582 public void StoreTerrain(TerrainData terrData, UUID regionID)
583 {
579 lock (m_dbLock) 584 lock (m_dbLock)
580 { 585 {
581 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 586 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
@@ -589,11 +594,18 @@ namespace OpenSim.Data.MySQL
589 594
590 ExecuteNonQuery(cmd); 595 ExecuteNonQuery(cmd);
591 596
592 cmd.CommandText = "insert into terrain (RegionUUID, " + 597 int terrainDBRevision;
593 "Revision, Heightfield) values (?RegionUUID, " + 598 Array terrainDBblob;
594 "1, ?Heightfield)"; 599 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
595 600
596 cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); 601 m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}",
602 LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision);
603
604 cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)"
605 + "values (?RegionUUID, ?Revision, ?Heightfield)";
606
607 cmd.Parameters.AddWithValue("Revision", terrainDBRevision);
608 cmd.Parameters.AddWithValue("Heightfield", terrainDBblob);
597 609
598 ExecuteNonQuery(cmd); 610 ExecuteNonQuery(cmd);
599 } 611 }
@@ -1525,30 +1537,6 @@ namespace OpenSim.Data.MySQL
1525 } 1537 }
1526 1538
1527 /// <summary> 1539 /// <summary>
1528 ///
1529 /// </summary>
1530 /// <param name="val"></param>
1531 /// <returns></returns>
1532 private static Array SerializeTerrain(double[,] val)
1533 {
1534 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1535 BinaryWriter bw = new BinaryWriter(str);
1536
1537 // TODO: COMPATIBILITY - Add byte-order conversions
1538 for (int x = 0; x < (int)Constants.RegionSize; x++)
1539 for (int y = 0; y < (int)Constants.RegionSize; y++)
1540 {
1541 double height = val[x, y];
1542 if (height == 0.0)
1543 height = double.Epsilon;
1544
1545 bw.Write(height);
1546 }
1547
1548 return str.ToArray();
1549 }
1550
1551 /// <summary>
1552 /// Fill the prim command with prim values 1540 /// Fill the prim command with prim values
1553 /// </summary> 1541 /// </summary>
1554 /// <param name="row"></param> 1542 /// <param name="row"></param>
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
index 69b0beb..433ffe9 100644
--- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Data.PGSQL
46 public class PGSQLSimulationData : ISimulationDataStore 46 public class PGSQLSimulationData : ISimulationDataStore
47 { 47 {
48 private const string _migrationStore = "RegionStore"; 48 private const string _migrationStore = "RegionStore";
49 private const string LogHeader = "[REGION DB PGSQL]";
49 50
50 // private static FileSystemDataStore Instance = new FileSystemDataStore(); 51 // private static FileSystemDataStore Instance = new FileSystemDataStore();
51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 52 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -563,40 +564,54 @@ namespace OpenSim.Data.PGSQL
563 return terrain; 564 return terrain;
564 } 565 }
565 566
567 // Legacy entry point for when terrain was always a 256x256 heightmap
568 public void StoreTerrain(double[,] terrain, UUID regionID)
569 {
570 StoreTerrain(new HeightmapTerrainData(terrain), regionID);
571 }
572
566 /// <summary> 573 /// <summary>
567 /// Stores the terrain map to DB. 574 /// Stores the terrain map to DB.
568 /// </summary> 575 /// </summary>
569 /// <param name="terrain">terrain map data.</param> 576 /// <param name="terrain">terrain map data.</param>
570 /// <param name="regionID">regionID.</param> 577 /// <param name="regionID">regionID.</param>
571 public void StoreTerrain(double[,] terrain, UUID regionID) 578 public void StoreTerrain(TerrainData terrData, UUID regionID)
572 { 579 {
573 int revision = Util.UnixTimeSinceEpoch();
574
575 //Delete old terrain map 580 //Delete old terrain map
576 string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID"; 581 string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID";
577 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 582 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
578 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
579 { 583 {
580 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); 584 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
581 conn.Open(); 585 {
582 cmd.ExecuteNonQuery(); 586 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
587 conn.Open();
588 cmd.ExecuteNonQuery();
589
590 _Log.InfoFormat("{0} Deleted terrain revision id = {1}", LogHeader, regionID);
591 }
583 } 592 }
584 593
585 _Log.Info("[REGION DB]: Deleted terrain revision r " + revision); 594 int terrainDBRevision;
595 Array terrainDBblob;
596 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
586 597
587 sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)"; 598 sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)";
588 599
589 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) 600 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
590 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
591 { 601 {
592 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); 602 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
593 cmd.Parameters.Add(_Database.CreateParameter("Revision", revision)); 603 {
594 cmd.Parameters.Add(_Database.CreateParameter("Heightfield", serializeTerrain(terrain))); 604 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
595 conn.Open(); 605 cmd.Parameters.Add(_Database.CreateParameter("Revision", terrainDBRevision));
596 cmd.ExecuteNonQuery(); 606 cmd.Parameters.Add(_Database.CreateParameter("Heightfield", terrainDBblob));
607 conn.Open();
608 cmd.ExecuteNonQuery();
609
610 _Log.InfoFormat("{0} Stored terrain id = {1}, terrainSize = <{2},{3}>",
611 LogHeader, regionID, terrData.SizeX, terrData.SizeY);
612 }
597 } 613 }
598 614
599 _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
600 } 615 }
601 616
602 /// <summary> 617 /// <summary>
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index d938b6b..cce59c1 100644
--- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs
+++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
@@ -51,6 +51,7 @@ namespace OpenSim.Data.SQLite
51 public class SQLiteSimulationData : ISimulationDataStore 51 public class SQLiteSimulationData : ISimulationDataStore
52 { 52 {
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 private static readonly string LogHeader = "[REGION DB SQLLITE]";
54 55
55 private const string primSelect = "select * from prims"; 56 private const string primSelect = "select * from prims";
56 private const string shapeSelect = "select * from primshapes"; 57 private const string shapeSelect = "select * from primshapes";
@@ -819,45 +820,44 @@ namespace OpenSim.Data.SQLite
819 prim.Inventory.RestoreInventoryItems(inventory); 820 prim.Inventory.RestoreInventoryItems(inventory);
820 } 821 }
821 822
823 // Legacy entry point for when terrain was always a 256x256 hieghtmap
824 public void StoreTerrain(double[,] ter, UUID regionID)
825 {
826 StoreTerrain(new HeightmapTerrainData(ter), regionID);
827 }
828
822 /// <summary> 829 /// <summary>
823 /// Store a terrain revision in region storage 830 /// Store a terrain revision in region storage
824 /// </summary> 831 /// </summary>
825 /// <param name="ter">terrain heightfield</param> 832 /// <param name="ter">terrain heightfield</param>
826 /// <param name="regionID">region UUID</param> 833 /// <param name="regionID">region UUID</param>
827 public void StoreTerrain(double[,] ter, UUID regionID) 834 public void StoreTerrain(TerrainData terrData, UUID regionID)
828 { 835 {
829 lock (ds) 836 lock (ds)
830 { 837 {
831 int revision = Util.UnixTimeSinceEpoch();
832
833 // This is added to get rid of the infinitely growing
834 // terrain databases which negatively impact on SQLite
835 // over time. Before reenabling this feature there
836 // needs to be a limitter put on the number of
837 // revisions in the database, as this old
838 // implementation is a DOS attack waiting to happen.
839
840 using ( 838 using (
841 SqliteCommand cmd = 839 SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn))
842 new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision",
843 m_conn))
844 { 840 {
845 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); 841 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
846 cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
847 cmd.ExecuteNonQuery(); 842 cmd.ExecuteNonQuery();
848 } 843 }
849 844
850 // the following is an work around for .NET. The perf 845 // the following is an work around for .NET. The perf
851 // issues associated with it aren't as bad as you think. 846 // issues associated with it aren't as bad as you think.
852 m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString());
853 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + 847 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
854 " values(:RegionUUID, :Revision, :Heightfield)"; 848 " values(:RegionUUID, :Revision, :Heightfield)";
855 849
850 int terrainDBRevision;
851 Array terrainDBblob;
852 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
853
854 m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision);
855
856 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) 856 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
857 { 857 {
858 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); 858 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
859 cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); 859 cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
860 cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter))); 860 cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
861 cmd.ExecuteNonQuery(); 861 cmd.ExecuteNonQuery();
862 } 862 }
863 } 863 }
@@ -2016,24 +2016,6 @@ namespace OpenSim.Data.SQLite
2016 return entry; 2016 return entry;
2017 } 2017 }
2018 2018
2019 /// <summary>
2020 ///
2021 /// </summary>
2022 /// <param name="val"></param>
2023 /// <returns></returns>
2024 private static Array serializeTerrain(double[,] val)
2025 {
2026 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
2027 BinaryWriter bw = new BinaryWriter(str);
2028
2029 // TODO: COMPATIBILITY - Add byte-order conversions
2030 for (int x = 0; x < (int)Constants.RegionSize; x++)
2031 for (int y = 0; y < (int)Constants.RegionSize; y++)
2032 bw.Write(val[x, y]);
2033
2034 return str.ToArray();
2035 }
2036
2037 // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) 2019 // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
2038 // { 2020 // {
2039 // row["RegionUUID"] = regionUUID; 2021 // row["RegionUUID"] = regionUUID;
diff --git a/OpenSim/Data/Tests/RegionTests.cs b/OpenSim/Data/Tests/RegionTests.cs
index dbed8f6..b4989d1 100644
--- a/OpenSim/Data/Tests/RegionTests.cs
+++ b/OpenSim/Data/Tests/RegionTests.cs
@@ -300,8 +300,8 @@ namespace OpenSim.Data.Tests
300 300
301 RegionInfo regionInfo = new RegionInfo(); 301 RegionInfo regionInfo = new RegionInfo();
302 regionInfo.RegionID = region3; 302 regionInfo.RegionID = region3;
303 regionInfo.RegionLocX = 0; 303 regionInfo.LegacyRegionLocX = 0;
304 regionInfo.RegionLocY = 0; 304 regionInfo.LegacyRegionLocY = 0;
305 305
306 SceneObjectPart sop = new SceneObjectPart(); 306 SceneObjectPart sop = new SceneObjectPart();
307 SceneObjectGroup sog = new SceneObjectGroup(sop); 307 SceneObjectGroup sog = new SceneObjectGroup(sop);
@@ -1066,8 +1066,8 @@ namespace OpenSim.Data.Tests
1066 { 1066 {
1067 RegionInfo regionInfo = new RegionInfo(); 1067 RegionInfo regionInfo = new RegionInfo();
1068 regionInfo.RegionID = regionId; 1068 regionInfo.RegionID = regionId;
1069 regionInfo.RegionLocX = 0; 1069 regionInfo.LegacyRegionLocX = 0;
1070 regionInfo.RegionLocY = 0; 1070 regionInfo.LegacyRegionLocY = 0;
1071 1071
1072 SceneObjectPart sop = new SceneObjectPart(); 1072 SceneObjectPart sop = new SceneObjectPart();
1073 sop.Name = name; 1073 sop.Name = name;